:root {
  --bg: #f4f6f7;
  --text: #1d2327;
  --muted: #5d676f;
  --accent: #2c6e8f;
  --accent-soft: #e2eef4;
  --card: #ffffff;
  --line: #dde3e7;
  --danger: #b3413a;
  --danger-soft: #f8e5e3;
  --warn: #8a6100;
  --warn-soft: #fbf1d8;
  --ok: #2f7a4f;
  --ok-soft: #e1f1e7;
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181b;
    --text: #e7eaec;
    --muted: #9aa4ab;
    --accent: #7bbcdb;
    --accent-soft: #1d3340;
    --card: #1e2428;
    --line: #2f373d;
    --danger: #ef8b82;
    --danger-soft: #3b2423;
    --warn: #e6b450;
    --warn-soft: #3a3220;
    --ok: #7fcf9d;
    --ok-soft: #1f3528;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

a { color: var(--accent); }

/* ---------- 上と下のメニュー ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { color: var(--text); font-weight: 700; font-size: 17px; text-decoration: none; }
.topbar-link { color: var(--muted); text-decoration: none; font-size: 14px; padding: 6px 10px; border-radius: 8px; }
.topbar-link.active { color: var(--accent); background: var(--accent-soft); }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: var(--tabbar-h);
  color: var(--muted);
  font-size: 11px;
  text-decoration: none;
  white-space: nowrap;
}

.tab-icon { font-size: 20px; line-height: 1.2; }
.tabbar a.active { color: var(--accent); font-weight: 700; }

.view {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom));
}

body.show-mode .topbar,
body.show-mode .tabbar { display: none; }
body.show-mode .view { max-width: none; padding: 0; }

/* ---------- 共通の部品 ---------- */

h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 24px 0 8px; }
h3 { font-size: 15px; margin: 0 0 4px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.page-head h1 { margin-bottom: 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.pre { white-space: pre-line; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-decoration: none;
  cursor: pointer;
}

.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.danger { color: var(--danger); }
.btn.danger.armed { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }

@media (prefers-color-scheme: dark) {
  .btn.primary { color: #10232d; }
}

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-size: 14px;
  min-height: 36px;
  cursor: pointer;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }

.tag {
  display: inline-block;
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  vertical-align: 2px;
}
.tag.symptom { background: var(--danger-soft); color: var(--danger); }
.tag.question { background: var(--accent-soft); color: var(--accent); }
.tag.request { background: var(--warn-soft); color: var(--warn); }
.tag.other { background: var(--bg); color: var(--muted); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }

/* ---------- 入力 ---------- */

label.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

input[type="text"], input[type="tel"], input[type="url"], input[type="date"], input[type="time"],
input[type="search"], select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px 未満だと iPhone で勝手に拡大される */
}

textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.check { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.hint {
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 14px;
}

.level { display: flex; flex-wrap: wrap; gap: 4px; }
.level button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.level button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }

details.more { margin-bottom: 12px; }
details.more summary { cursor: pointer; color: var(--accent); padding: 6px 0; }

/* ---------- ホーム ---------- */

.home-show {
  display: block;
  padding: 18px 16px;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  margin-bottom: 12px;
}
.home-show strong { display: block; font-size: 19px; }
.home-show span { font-size: 14px; opacity: 0.9; }
@media (prefers-color-scheme: dark) { .home-show { color: #10232d; } }

.appt { display: flex; gap: 12px; align-items: center; }
.appt-days {
  min-width: 64px;
  text-align: center;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 6px 4px;
  font-size: 12px;
  line-height: 1.3;
}
.appt-days b { display: block; font-size: 20px; }
.appt-days.soon { background: var(--warn-soft); color: var(--warn); }

.links { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.links a { justify-content: flex-start; }

/* ---------- お薬のチェック ---------- */

.dose-grid { display: grid; gap: 8px; }
.dose-time { display: flex; gap: 8px; align-items: flex-start; }
.dose-time > b { min-width: 56px; padding-top: 8px; font-size: 14px; }
.dose-list { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.dose {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  min-height: 40px;
  cursor: pointer;
}
.dose.taken { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.dose.taken::before { content: "✓ "; font-weight: 700; }

.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 6px 0 12px; }
.progress > i { display: block; height: 100%; background: var(--ok); }

/* ---------- 一覧 ---------- */

.item { display: flex; gap: 10px; align-items: flex-start; }
.item-main { flex: 1; min-width: 0; }
.item-text { font-size: 16px; overflow-wrap: anywhere; }
.item-meta { font-size: 13px; color: var(--muted); }
.item-actions { display: flex; flex-direction: column; gap: 4px; }
.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}
.star { color: var(--warn); }
.done-text { text-decoration: line-through; color: var(--muted); }

.tweet-day { font-size: 13px; color: var(--muted); margin: 18px 0 6px; font-weight: 700; }
.tweet { display: flex; gap: 10px; }
.tweet-mood { font-size: 24px; line-height: 1.2; }
.tweet-time { font-size: 12px; color: var(--muted); }

.moods { display: flex; gap: 6px; margin: 8px 0; }
.moods button {
  flex: 1;
  font-size: 24px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  cursor: pointer;
}
.moods button.on { border-color: var(--accent); background: var(--accent-soft); }
.mood-caption { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }

.mood-bars { display: flex; align-items: flex-end; gap: 3px; height: 56px; margin: 8px 0 2px; }
.mood-bars i { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: 0.85; }
.mood-bars i.none { background: var(--line); }

.place-name { font-size: 17px; font-weight: 700; }
.place-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.kv { display: grid; grid-template-columns: 5.5em 1fr; gap: 2px 8px; font-size: 14px; margin-top: 6px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }

/* ---------- 先生に見せる画面（白地・大きな文字） ---------- */

.show {
  min-height: 100vh;
  background: #fff;
  color: #111;
  padding: 16px 18px 120px;
  font-size: var(--show-size, 22px);
  line-height: 1.55;
}
.show-inner { max-width: 900px; margin: 0 auto; }
.show-bar {
  position: sticky;
  top: 0;
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  padding: 8px 0 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 2px solid #111;
  margin-bottom: 14px;
  font-size: 15px;
}
.show-bar .btn { background: #fff; color: #111; border-color: #999; }
.show-title { font-size: 1.15em; font-weight: 700; margin: 0 0 4px; }
.show-who { font-size: 0.75em; color: #444; margin-bottom: 8px; }
.show h2 { font-size: 0.85em; margin: 22px 0 6px; padding: 2px 10px; background: #111; color: #fff; border-radius: 6px; display: inline-block; }
.show ol { margin: 0; padding-left: 1.5em; }
.show li { margin: 0 0 12px; padding: 4px 6px; border-radius: 8px; cursor: pointer; }
.show li.told { color: #888; }
.show li.told .show-main::after { content: "  ✓ 伝えた"; font-size: 0.6em; color: #2f7a4f; font-weight: 700; }
.show .show-main { font-weight: 700; }
.show .show-sub { display: block; font-size: 0.72em; color: #333; font-weight: 400; }
.show .imp { color: #b3413a; }
.show table { border-collapse: collapse; width: 100%; font-size: 0.8em; }
.show td { border-bottom: 1px solid #ccc; padding: 6px 4px; vertical-align: top; }
.show .show-foot { margin-top: 28px; }
.show .show-foot .btn { background: #2c6e8f; border-color: #2c6e8f; color: #fff; font-size: 17px; }
.show .alert { border: 2px solid #b3413a; color: #b3413a; border-radius: 10px; padding: 6px 12px; font-size: 0.8em; margin: 8px 0; }

/* ---------- 緊急情報カード ---------- */

.emergency { border: 2px solid var(--danger); }
.emergency .kv { font-size: 16px; grid-template-columns: 6.5em 1fr; }

/* ---------- 下から出る画面 ---------- */

.sheet { position: fixed; inset: 0; z-index: 30; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.4); }
.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
}
.sheet-panel h2 { margin-top: 0; }
.sheet-foot {
  position: sticky;
  bottom: calc(-18px - env(safe-area-inset-bottom));
  background: var(--bg);
  padding: 10px 0 4px;
  display: flex;
  gap: 8px;
}
.sheet-foot .btn { flex: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  margin: 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: #222;
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  width: max-content;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.visible { opacity: 0.95; }
