:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --line: #e3e8ef;
  --primary: #1e3a5f;
  --primary-soft: #e6eef8;
  --accent: #f0a500;
  --ok: #1f8f4e;
  --ok-soft: #e3f5ea;
  --ng: #c93a3a;
  --ng-soft: #fbe7e7;
  --note: #fff6dc;
  --note-line: #f0a500;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1520; --card: #182130; --text: #e8edf5; --muted: #98a2b3; --line: #2a3648;
    --primary: #6ea0dd; --primary-soft: #1f2d44; --note: #3a3012; --ok-soft: #123a24; --ng-soft: #44191b;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 16px; line-height: 1.65;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  background: var(--primary); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
}
.topbar h1 { flex: 1; font-size: 17px; margin: 0; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn { width: 36px; height: 36px; border: 0; border-radius: 10px; background: rgba(255,255,255,.15); color: #fff; font-size: 22px; line-height: 1; cursor: pointer; }
.iconbtn[hidden] { visibility: hidden; display: inline-block; }
main { max-width: 720px; margin: 0 auto; padding: 14px 14px 40px; }

h2 { font-size: 20px; margin: 18px 0 10px; }
h3 { font-size: 16px; margin: 20px 0 8px; padding-left: 10px; border-left: 4px solid var(--primary); }
p { margin: 8px 0; }
.muted { color: var(--muted); font-size: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.card h3 { margin-top: 0; }
button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 12px 16px; font-size: 15px; font-weight: 600; cursor: pointer;
  background: var(--primary); color: #fff; touch-action: manipulation;
}
button.btn.secondary { background: var(--primary-soft); color: var(--primary); }
button.btn.ghost { background: transparent; color: var(--primary); border: 1px solid var(--line); }
button.btn.warn { background: var(--ng); }
button.btn.block { width: 100%; }
button.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1; min-width: 0; }
.stack { display: grid; gap: 10px; }

/* home */
.hero { background: linear-gradient(135deg, var(--primary), #2f5d8f); color: #fff; border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.hero .big { font-size: 21px; font-weight: 700; }
.hero .muted { color: rgba(255,255,255,.8); }
.chapter { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: start; }
.chapter .num { width: 44px; height: 44px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; }
.chapter .name { font-weight: 600; font-size: 16px; }
.chapter .modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; grid-column: 1 / -1; }
.chapter .modes .btn { padding: 8px 4px; font-size: 14px; flex-direction: column; gap: 0; line-height: 1.3; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.stat { display: flex; gap: 10px; font-size: 13px; color: var(--muted); margin-top: 4px; flex-wrap: wrap; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.ng { background: var(--ng-soft); color: var(--ng); }

/* study */
.study ul { padding-left: 22px; margin: 6px 0; }
.study li { margin: 3px 0; }
.defs { display: grid; gap: 6px; margin: 8px 0; }
.def { background: var(--primary-soft); border-radius: 10px; padding: 8px 10px; }
.def b { color: var(--primary); display: block; font-size: 15px; }
.note { background: var(--note); border-left: 4px solid var(--note-line); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.note::before { content: "★ 試験ポイント"; display: block; font-size: 12px; font-weight: 700; color: #a06f00; margin-bottom: 2px; }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 8px -4px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; min-width: 320px; }
th, td { border: 1px solid var(--line); padding: 6px 8px; vertical-align: top; text-align: left; }
th { background: var(--primary-soft); color: var(--primary); }
figure { margin: 10px 0; text-align: center; }
figure img { max-width: 100%; border-radius: 10px; background: #fff; }
figcaption { font-size: 13px; color: var(--muted); margin-top: 4px; }
.toc { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 14px; }
.toc a { font-size: 13px; padding: 5px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--text); text-decoration: none; }
mark { background: none; color: inherit; font-weight: 700; border-bottom: 2px solid rgba(240,165,0,.7); padding: 0; }

/* flashcards */
.flash { min-height: 220px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; cursor: pointer; user-select: none; -webkit-user-select: none; position: relative; }
.flash .side { font-size: 12px; color: var(--muted); position: absolute; top: 10px; left: 14px; }
.flash .term { font-size: 20px; font-weight: 700; }
.flash .def { background: transparent; font-size: 16px; padding: 0; }
.flash.flipped { background: var(--primary-soft); }

/* quiz */
.qhead { display: flex; justify-content: space-between; align-items: center; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.progress { height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: 12px; }
.progress > i { display: block; height: 100%; background: var(--primary); }
.qtext { font-size: 17px; font-weight: 600; margin-bottom: 12px; white-space: pre-wrap; }
.choices { display: grid; gap: 8px; }
.choice {
  display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start;
  text-align: left; width: 100%; padding: 12px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); color: var(--text); font-size: 15px; line-height: 1.5; cursor: pointer;
}
.choice .k { width: 28px; height: 28px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; }
.choice.selected { border-color: var(--primary); }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.correct .k { background: var(--ok); color: #fff; }
.choice.wrong { border-color: var(--ng); background: var(--ng-soft); }
.choice.wrong .k { background: var(--ng); color: #fff; }
.choice:disabled { cursor: default; }
.explain { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--primary-soft); }
.explain .verdict { font-weight: 700; margin-bottom: 4px; }
.explain .verdict.ok { color: var(--ok); }
.explain .verdict.ng { color: var(--ng); }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.timer.low { color: var(--ng); }

/* result */
.score { text-align: center; padding: 10px 0; }
.score .big { font-size: 48px; font-weight: 800; color: var(--primary); line-height: 1.1; }
.review .item { padding: 10px 0; border-top: 1px solid var(--line); }
.review .item:first-child { border-top: 0; }
.review .q { font-weight: 600; }
.review .a { font-size: 14px; margin-top: 4px; }
.chart { display: grid; gap: 6px; margin: 10px 0; }
.chart .r { display: grid; grid-template-columns: 56px 1fr 44px; gap: 8px; align-items: center; font-size: 13px; }
.chart .r .bar { margin: 0; height: 10px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 50; }
.center { text-align: center; }
.small { font-size: 13px; }
.mt { margin-top: 12px; }

/* 教科書での表現・補足（ネット調査由来） */
.supp { background: var(--primary-soft); border-left: 4px solid var(--primary); border-radius: 8px; padding: 10px 12px; margin: 10px 0; font-size: 15px; }
.supp::before { content: "📚 教科書ではこう出る"; display: block; font-size: 12px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
.supp > b { display: block; margin-bottom: 2px; }
.supp ul { margin: 4px 0 0; padding-left: 20px; }
