/* ============================================================
   PT国試ヘルパー  スタイル
   - スマホ優先（学生はスマホで使う想定）
   - ライト/ダーク自動対応
   - 文字の大きさは --font-scale で全体をまとめて変える
   ============================================================ */

:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-2: #eef1f4;
  --text: #171c21;
  --text-dim: #5b6672;
  --line: #dde2e7;
  --accent: #17786a;
  --accent-soft: #e2f2ef;
  --ok: #14713f;
  --ok-soft: #e3f3e9;
  --ng: #a92318;
  --ng-soft: #fbe9e6;
  --warn: #8a6100;
  --warn-soft: #fdf3dd;
  --lv-a: #a8410f;
  --lv-a-soft: #fdeee4;
  --lv-b: #1a5f9c;
  --lv-b-soft: #e6f0fa;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.05);
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-scale: 1;
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121517;
    --panel: #1b1f22;
    --panel-2: #232830;
    --text: #e8ecef;
    --text-dim: #9aa5b0;
    --line: #333a42;
    --accent: #55d6b6;
    --accent-soft: #16332d;
    --ok: #63d18e;
    --ok-soft: #143021;
    --ng: #ff9086;
    --ng-soft: #37211f;
    --warn: #e5bf6a;
    --warn-soft: #302716;
    --lv-a: #ffb083;
    --lv-a-soft: #3a2417;
    --lv-b: #86c0f0;
    --lv-b-soft: #16283a;
    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 6px 20px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP",
               "Yu Gothic UI", Meiryo, sans-serif;
  font-size: calc(16px * var(--font-scale));
  line-height: 1.8;
  padding-bottom: calc(var(--tabbar-h) + 20px);
}

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

/* ---------- ヘッダ ---------- */

header.site {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.site-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand { font-weight: 700; font-size: 1rem; letter-spacing: .01em; white-space: nowrap; }
.brand small { display: block; font-weight: 400; font-size: .66rem; color: var(--text-dim); }

.site-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.modebtn {
  font: inherit;
  font-size: .78rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  white-space: nowrap;
}

.iconbtn {
  border: 0; background: transparent; color: var(--text-dim);
  padding: 5px; border-radius: 8px; cursor: pointer; display: flex;
}
.iconbtn:hover { background: var(--panel-2); color: var(--text); }

.backbtn { margin-left: -4px; color: var(--accent); }
.backbtn[hidden] { display: none; }

/* ---------- 学習の進め方 ---------- */

.course { margin-top: 10px; }

.course-step { display: flex; gap: 12px; padding-bottom: 16px; position: relative; }
.course-step:not(:last-child)::before {
  content: ""; position: absolute; left: 13px; top: 30px; bottom: 2px;
  width: 2px; background: var(--line);
}

.course-num {
  flex: 0 0 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .82rem; font-weight: 700; position: relative; z-index: 1;
}
.course-step.done .course-num { background: var(--ok); }

.course-body { flex: 1; min-width: 0; }
.course-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.course-head b { font-size: 1rem; }
.course-why { font-size: .82rem; color: var(--text-dim); margin: 4px 0 8px; line-height: 1.7; }

.course-bar { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.course-bar > div { height: 100%; background: var(--accent); border-radius: 99px; }
.course-step.done .course-bar > div { background: var(--ok); }

.course-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 7px; }
.course-foot .btn { padding: 5px 12px; font-size: .8rem; }

/* ---------- 下のタブ ---------- */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabbar-inner { max-width: 860px; margin: 0 auto; display: flex; }

.tabbar button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: .68rem;
  padding: 7px 2px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.tabbar button svg { width: 22px; height: 22px; }
.tabbar button[aria-current="true"] { color: var(--accent); font-weight: 700; }

/* ---------- レイアウト ---------- */

.wrap { max-width: 860px; margin: 0 auto; padding: 14px 14px 30px; }

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

.card h2 { margin: 0 0 4px; font-size: 1.04rem; }
.card h3 {
  margin: 20px 0 8px; font-size: .8rem; color: var(--text-dim);
  letter-spacing: .06em; font-weight: 700;
}

.hint { color: var(--text-dim); font-size: .8rem; margin: 0 2px 12px; }
.empty { text-align: center; color: var(--text-dim); padding: 30px 10px; }

.banner {
  background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  color: var(--warn);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: .85rem;
  margin-bottom: 14px;
}

/* ---------- 検索 ---------- */

.searchbar { margin: 4px 0 6px; display: flex; gap: 8px; }

.searchbar input {
  flex: 1; min-width: 0; font: inherit; font-size: 1rem;
  padding: 13px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  box-shadow: var(--shadow);
}
.searchbar input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.searchbar button {
  font: inherit; font-weight: 700; padding: 0 18px;
  border-radius: var(--radius); border: 0; background: var(--accent);
  color: #fff; cursor: pointer; white-space: nowrap;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }

.chip {
  font: inherit; font-size: .78rem; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text-dim);
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.on { border-color: var(--accent); color: var(--accent); font-weight: 700; background: var(--accent-soft); }
.chip.charapick svg { width: 22px; height: 22px; }

/* ---------- 問題 ---------- */

.qhead { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }

.qid {
  font-family: var(--mono); font-size: .76rem; color: var(--accent);
  background: var(--accent-soft); padding: 2px 8px; border-radius: 6px; white-space: nowrap;
}

.qmeta { font-size: .76rem; color: var(--text-dim); }
.badge-multi { background: var(--warn-soft); color: var(--warn); padding: 1px 7px; border-radius: 5px; }

.qtext { font-size: 1.03rem; white-space: pre-wrap; margin: 6px 0 4px; line-height: 1.85; }

.figure {
  margin: 14px 0 0; padding: 10px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 12px; overflow-x: auto;
}
.figure svg, .figure img { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.figure figcaption { font-size: .78rem; color: var(--text-dim); text-align: center; margin-top: 8px; }

/* ---------- 選択肢 ---------- */

.choices { list-style: none; padding: 0; margin: 14px 0 0; }

.choice {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 13px; margin-bottom: 9px; background: var(--panel-2);
}

.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.wrong { background: var(--ng-soft); border-color: color-mix(in srgb, var(--ng) 45%, transparent); }
.choice.pickable { cursor: pointer; }
.choice.pickable:hover { border-color: var(--accent); }
.choice.picked-on { border-color: var(--accent); background: var(--accent-soft); }

.choice-head { display: flex; gap: 9px; align-items: flex-start; }
.choice-label { font-family: var(--mono); font-weight: 700; min-width: 1.4em; }
.choice-text { flex: 1; }
.picked { font-size: .72rem; color: var(--text-dim); }

.mark { font-weight: 700; white-space: nowrap; font-size: .82rem; }
.mark.ok { color: var(--ok); }
.mark.ng { color: var(--ng); }

.choice-exp {
  margin: 9px 0 0 calc(1.4em + 9px);
  font-size: .89rem; color: var(--text-dim); line-height: 1.75;
}

/* ヒントで消した選択肢 */
.choice.eliminated { opacity: .42; background: var(--panel-2); }
.choice.eliminated .choice-text { text-decoration: line-through; }

/* ---------- ヒント ---------- */

.hintbox {
  margin-top: 14px; padding: 12px 14px; border-radius: 12px;
  background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  font-size: .88rem; line-height: 1.8;
}

.hint-line { margin-bottom: 6px; }
.hint-line:last-child { margin-bottom: 0; }
.hint-line b {
  display: inline-block; font-size: .7rem; font-weight: 700;
  background: var(--warn); color: #fff;
  padding: 1px 8px; border-radius: 5px; margin-right: 7px; vertical-align: 1px;
}
.hint-line.hint-note { color: var(--text-dim); font-size: .8rem; }
.hintbox .kw { margin-bottom: 0; }

.hintbtn { border-color: var(--warn); color: var(--warn); font-weight: 600; }
.hintbtn:hover { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
.choice-exp.none { font-style: normal; opacity: .75; }

.why {
  display: inline-block; font-size: .7rem; font-weight: 700;
  padding: 1px 7px; border-radius: 5px; margin-right: 6px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text-dim);
}
.choice.correct .why { color: var(--ok); border-color: var(--ok); }
.choice.wrong .why, .choice:not(.correct) .why { color: var(--ng); border-color: color-mix(in srgb, var(--ng) 45%, transparent); }

.autotag { display: block; margin-top: 4px; opacity: .65; font-size: .7rem; }

/* ---------- 本文の色分け ---------- */

.hl-num { font-weight: 700; color: var(--text); background: color-mix(in srgb, var(--accent) 14%, transparent); padding: 0 3px; border-radius: 4px; }
.hl-ok { color: var(--ok); font-weight: 700; }
.hl-ng { color: var(--ng); font-weight: 700; }

.prose { white-space: pre-wrap; line-height: 1.85; }
.keypoints { margin: 6px 0 0; padding-left: 1.2em; }
.keypoints li { margin-bottom: 4px; }

.answer-badge {
  display: inline-block; font-weight: 700; background: var(--ok-soft); color: var(--ok);
  border: 1px solid var(--ok); border-radius: 9px; padding: 3px 14px; font-size: 1rem;
}
.answer-badge.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }

/* ---------- キーワード ---------- */

.kw, .kwlink {
  font: inherit; cursor: pointer; border-radius: 7px;
  border: 1px solid transparent; background: transparent; color: inherit;
}

.kw {
  font-size: .84rem; padding: 4px 10px; margin: 0 4px 5px 0;
  border-color: var(--line); background: var(--panel-2);
}
.kw:hover { border-color: var(--accent); }

.kw.lv-a { border-color: var(--lv-a); background: var(--lv-a-soft); color: var(--lv-a); font-weight: 700; }
.kw.lv-b { border-color: var(--lv-b); background: var(--lv-b-soft); color: var(--lv-b); }
.kw.lv-c { font-size: .74rem; padding: 2px 8px; opacity: .72; }

.kwrow { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin-bottom: 7px; }
.kwrow-c { opacity: .85; }

/* 1語1行、説明つきの並び */
.kwlist { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }

.kwitem {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "lv word" "lv def";
  gap: 1px 8px;
  align-items: center;
  text-align: left;
  font: inherit; color: inherit; cursor: pointer;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
}
.kwitem:hover { border-color: var(--accent); }
.kwitem .kwlabel { grid-area: lv; align-self: start; margin: 2px 0 0; }
.kwitem-word { grid-area: word; font-weight: 700; font-size: .95rem; }
.kwitem-def { grid-area: def; font-size: .79rem; color: var(--text-dim); line-height: 1.6; }
.kwitem-def:empty { display: none; }

.kwitem.lv-a { background: var(--lv-a-soft); border-color: color-mix(in srgb, var(--lv-a) 45%, transparent); }
.kwitem.lv-a .kwitem-word { color: var(--lv-a); }
.kwitem.lv-b { background: var(--lv-b-soft); border-color: color-mix(in srgb, var(--lv-b) 35%, transparent); }
.kwitem.lv-c { opacity: .8; }
.kwitem.lv-c .kwitem-word { font-size: .86rem; font-weight: 600; }

/* 間違えた回数 */
.miss-count { color: var(--ng); font-weight: 700; }

/* ---------- キャラクターの選択 ---------- */

.charapicker { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

.characard {
  display: flex; align-items: center; gap: 12px;
  text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px;
}
.characard:hover { border-color: var(--accent); }
.characard.on { border-color: var(--accent); background: var(--accent-soft); }
.characard-art { flex: 0 0 46px; }
.characard-art .chara { width: 46px; height: 46px; }
.characard-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.characard-body b { font-size: .95rem; }

.kwlabel {
  font-size: .68rem; font-weight: 700; padding: 2px 8px; border-radius: 5px;
  margin-right: 6px; white-space: nowrap;
}
.kwlabel.lv-a { background: var(--lv-a); color: #fff; }
.kwlabel.lv-b { background: var(--lv-b); color: #fff; }
.kwlabel.lv-c { background: var(--panel-2); color: var(--text-dim); border: 1px solid var(--line); }

/* 本文中の用語（控えめに下線） */
.kwlink { padding: 0 1px; text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px; }
.kwlink.lv-a { text-decoration-color: var(--lv-a); text-decoration-thickness: 2px; }
.kwlink.lv-b { text-decoration-color: var(--lv-b); }
.kwlink.lv-c { text-decoration-color: var(--line); }
.kwlink:hover { background: var(--accent-soft); }

/* 用語の小窓 */
.kwpanel {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.42);
  display: flex; align-items: flex-end; justify-content: center;
}
.kwpanel[hidden] { display: none; }

.kwsheet {
  background: var(--panel); width: 100%; max-width: 620px;
  max-height: 84vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 18px 26px;
  border: 1px solid var(--line); border-bottom: 0;
}
@media (min-width: 620px) {
  .kwpanel { align-items: center; }
  .kwsheet { border-radius: 18px; border-bottom: 1px solid var(--line); }
}

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

.todaycard { display: flex; gap: 14px; align-items: center; }
.today-left { flex: 0 0 78px; }
.chara { width: 78px; height: 78px; display: block; }
.today-right { flex: 1; min-width: 0; }
.today-msg { font-weight: 600; margin-bottom: 10px; line-height: 1.6; }
.today-stats { display: flex; flex-wrap: wrap; gap: 14px; }
.today-stat { text-align: center; min-width: 54px; }
.today-stat b { display: block; font-size: 1.3rem; line-height: 1.2; }
.today-stat span { font-size: .68rem; color: var(--text-dim); display: block; }

.menu { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 9px; margin-top: 10px; }

.menu-item {
  text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px;
}
.menu-item:hover { border-color: var(--accent); }
.menu-item b { display: block; font-size: .95rem; }
.menu-item span { font-size: .76rem; color: var(--text-dim); }

.weekchart { display: flex; gap: 8px; align-items: flex-end; height: 110px; margin-top: 8px; }
.daybar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; }
.daybar-track { flex: 1; width: 100%; background: var(--panel-2); border-radius: 7px; display: flex; align-items: flex-end; overflow: hidden; }
.daybar-fill { width: 100%; border-radius: 7px; min-height: 3px; transition: height .3s; }
.daybar span { font-size: .7rem; color: var(--text-dim); }

/* ---------- 一覧・表 ---------- */

.result-item {
  display: block; width: 100%; text-align: left; font: inherit; color: inherit;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 11px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
}
.result-item:hover { border-color: var(--accent); }
.result-item .snippet { font-size: .86rem; color: var(--text-dim); margin-top: 2px; }
.result-item mark { background: var(--accent-soft); color: inherit; padding: 0 2px; border-radius: 3px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 9px; }

.stat {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 11px; padding: 11px 8px; text-align: center;
}
.stat b { display: block; font-size: 1.4rem; line-height: 1.2; }
.stat span { font-size: .72rem; color: var(--text-dim); }

table.rank { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.rank th, table.rank td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
table.rank th { color: var(--text-dim); font-weight: 700; font-size: .78rem; }
table.rank td.num { text-align: right; font-family: var(--mono); white-space: nowrap; }
table.rank tbody tr { cursor: pointer; }
table.rank tbody tr:hover { background: var(--panel-2); }

.tagrow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.tag {
  font: inherit; font-size: .73rem; color: var(--text-dim); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; cursor: pointer;
}
.tag:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- ボタン ---------- */

.btn {
  font: inherit; font-size: .86rem; padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { opacity: .92; color: #fff; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------- 折りたたみ ---------- */

details.reveal { margin-top: 14px; }

details.reveal > summary {
  cursor: pointer; font-weight: 700; color: var(--accent);
  background: var(--accent-soft); border-radius: 11px; padding: 11px 16px;
  list-style: none; user-select: none; text-align: center;
}
details.reveal > summary::-webkit-details-marker { display: none; }
details.reveal > summary::before { content: "▶ "; font-size: .8em; }
details.reveal[open] > summary::before { content: "▼ "; }
.revealed { margin-top: 4px; }

/* ---------- フォーム ---------- */

.field { margin-bottom: 13px; }
.field label { display: block; font-size: .78rem; color: var(--text-dim); margin-bottom: 4px; font-weight: 700; }

.field input[type=text], .field input[type=number], .field input[type=date],
.field select, .field textarea, textarea {
  width: 100%; font: inherit; font-size: .95rem; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2); color: var(--text);
}
.field textarea, textarea { min-height: 90px; resize: vertical; line-height: 1.7; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 130px; }

.choice-edit { border: 1px solid var(--line); border-radius: 11px; padding: 10px; margin-bottom: 8px; background: var(--panel-2); }
.choice-edit .top { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.choice-edit .top input[type=text] { flex: 1; }
.choice-edit .top label { font-size: .8rem; display: flex; align-items: center; gap: 4px; margin: 0; white-space: nowrap; }

footer.site { text-align: center; color: var(--text-dim); font-size: .74rem; padding: 20px 16px 30px; }

.site-nav { margin-left: auto; display: flex; flex-wrap: wrap; gap: 4px; }
.site-nav button, .site-nav a {
  border: 0; background: transparent; color: var(--text-dim); font: inherit;
  font-size: .82rem; padding: 6px 9px; border-radius: 8px; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.site-nav button:hover, .site-nav a:hover { background: var(--panel-2); color: var(--text); }
.site-nav button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

/* 教員用の画面は幅が狭いと見出しが窮屈になるので折り返す */
.site-inner { flex-wrap: wrap; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
