:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #667085;
  --line: #e4e4e0;
  --accent: #2f6fde;
  --accent-soft: #e8f0fd;
  --ok: #1a8a5a;
  --ok-soft: #e3f5ec;
  --ng: #c93c3c;
  --ng-soft: #fbe9e9;
  --warn-soft: #fff6dc;
  --radius: 10px;
  --sidebar: 280px;
}
/* ダーク：OS設定に従う（手動でライトにしたときは除く）／手動でダーク */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1e2125;
    --text: #e6e6e6;
    --muted: #9aa0a6;
    --line: #2e3237;
    --accent: #6ea0ff;
    --accent-soft: #1d2a40;
    --ok: #4cc38a;
    --ok-soft: #173327;
    --ng: #ff7b7b;
    --ng-soft: #3a1f1f;
    --warn-soft: #3a3320;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #15171a;
  --surface: #1e2125;
  --text: #e6e6e6;
  --muted: #9aa0a6;
  --line: #2e3237;
  --accent: #6ea0ff;
  --accent-soft: #1d2a40;
  --ok: #4cc38a;
  --ok-soft: #173327;
  --ng: #ff7b7b;
  --ng-soft: #3a1f1f;
  --warn-soft: #3a3320;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.75;
  font-size: 15px;
}
a { color: var(--accent); text-decoration: none; }
b { color: var(--accent); font-weight: 600; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  height: 52px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); }
.topnav { margin-left: auto; display: flex; gap: 4px; }
.topnav a { display: inline-flex; align-items: center; gap: 5px; padding: 6px 9px; border-radius: 6px; color: var(--muted); font-size: 14px; white-space: nowrap; }
.topnav a.active, .topnav a:hover { background: var(--accent-soft); color: var(--accent); }
.theme-btn, .icon-btn { display: inline-flex; align-items: center; justify-content: center; background: none; border: 1px solid var(--line); border-radius: 999px; width: 34px; height: 34px; font-size: 16px; color: var(--text); cursor: pointer; flex-shrink: 0; }
.theme-btn:hover, .icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.menu-btn { display: none; align-items: center; background: none; border: 0; font-size: 20px; color: var(--text); cursor: pointer; padding: 4px; }
/* アイコン（Lucide） */
svg.lucide { width: 1.15em; height: 1.15em; stroke-width: 2; flex-shrink: 0; vertical-align: -0.2em; }
.topnav svg.lucide { width: 16px; height: 16px; }
.menu-btn svg.lucide { width: 22px; height: 22px; }
.theme-btn svg.lucide, .icon-btn svg.lucide { width: 17px; height: 17px; }
.btn svg.lucide { width: 16px; height: 16px; margin-right: 4px; }
@media (max-width: 1180px) { .topnav .nav-extra span { display: none; } }
@media (max-width: 980px) { .topnav a span { display: none; } .topnav a { padding: 7px 8px; } }

/* ---------- layout ---------- */
.layout { display: flex; }
.sidebar {
  position: sticky; top: 52px;
  width: var(--sidebar); height: calc(100vh - 52px); overflow-y: auto;
  padding: 16px 12px; border-right: 1px solid var(--line); background: var(--surface);
  flex-shrink: 0; font-size: 14px;
}
.content { flex: 1; min-width: 0; padding: 32px 40px 80px; max-width: 900px; }

.toc-ch { margin-bottom: 16px; }
.toc-ch > .toc-title { font-weight: 700; padding: 4px 8px; }
.toc-sec { color: var(--muted); font-size: 12px; padding: 8px 8px 2px; }
.toc a {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: 6px; color: var(--text);
}
.toc a:hover { background: var(--bg); }
.toc a.active { background: var(--accent-soft); color: var(--accent); }
.toc .dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--muted); flex-shrink: 0; }
.toc .dot.done { background: var(--ok); border-color: var(--ok); }

@media (max-width: 800px) {
  .menu-btn { display: inline-flex; }
  .sidebar { position: fixed; left: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 4px 0 20px rgba(0,0,0,.15); }
  .content { padding: 20px 16px 80px; }
  .topnav a { padding: 6px 6px; font-size: 13px; }
}

/* ---------- typography ---------- */
h1 { font-size: 26px; margin: 0 0 8px; line-height: 1.4; }
h2 { font-size: 19px; margin: 36px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.crumb { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.lead {
  background: var(--accent-soft); border-left: 4px solid var(--accent);
  padding: 12px 16px; border-radius: 0 var(--radius) var(--radius) 0; margin: 16px 0 8px;
}
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 20px; margin: 12px 0;
}
.note { background: var(--warn-soft); border-radius: var(--radius); padding: 12px 16px; margin: 12px 0; }
.note .label { font-size: 12px; font-weight: 700; color: var(--muted); display: block; }
.formula {
  text-align: center; font-weight: 700; font-size: 16px;
  padding: 16px; border: 2px dashed var(--accent); border-radius: var(--radius); margin: 16px 0;
}

/* ---------- terms ---------- */
.terms-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.toggle-hide { font-size: 12px; background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 3px 10px; cursor: pointer; white-space: nowrap; }
.toggle-hide.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.terms { display: grid; gap: 8px; }
.term { display: grid; grid-template-columns: 200px 1fr; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.term:first-child { border-top: 0; }
.term dt { font-weight: 700; }
.term dd { margin: 0; }
.terms.hidden dd { filter: blur(6px); cursor: pointer; user-select: none; transition: filter .15s; }
.terms.hidden dd.shown { filter: none; }
@media (max-width: 600px) { .term { grid-template-columns: 1fr; gap: 2px; } }

/* ---------- diagrams ---------- */
.diagram { margin: 20px 0; }
.diagram figcaption { text-align: center; font-size: 13px; color: var(--muted); margin-top: 8px; }
.cycle { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; align-items: stretch; }
.cycle .node {
  position: relative; background: var(--surface); border: 2px solid var(--accent);
  border-radius: var(--radius); padding: 12px; text-align: center; margin: 0 14px;
}
.cycle .node:not(:last-child)::after {
  content: "→"; position: absolute; right: -24px; top: 50%; transform: translateY(-50%);
  color: var(--accent); font-weight: 700;
}
.cycle .k { font-weight: 800; color: var(--accent); font-size: 18px; display: block; }
.cycle .v { font-size: 13px; }
.cycle-back { text-align: center; color: var(--accent); font-size: 13px; margin-top: 6px; }
.steps { display: flex; flex-direction: column; gap: 0; }
.steps .step {
  display: grid; grid-template-columns: 170px 1fr; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px;
}
.steps .step + .step { margin-top: 18px; position: relative; }
.steps .step + .step::before { content: "▼"; position: absolute; top: -18px; left: 70px; color: var(--accent); font-size: 12px; }
.steps .k { font-weight: 700; color: var(--accent); }
@media (max-width: 600px) {
  .cycle { grid-template-columns: 1fr 1fr; gap: 12px; }
  .cycle .node::after { display: none; }
  .steps .step { grid-template-columns: 1fr; gap: 2px; }
}
.triangle { position: relative; max-width: 420px; margin: 0 auto; }
.triangle svg { width: 100%; height: auto; display: block; }
.triangle svg text { fill: var(--text); }
.tri-legend { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; font-size: 13px; }
.tri-legend div { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
@media (max-width: 600px) { .tri-legend { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; font-size: 14px; }
th, td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; vertical-align: top; }
th { background: var(--accent-soft); }
td:first-child { white-space: nowrap; font-weight: 600; }
.table-wrap { overflow-x: auto; }
.small { font-size: 12px; color: var(--muted); }
ol.plain, ul.plain { padding-left: 1.4em; }

/* ---------- quiz ---------- */
.quiz { border-left: 4px solid var(--accent); }
.qhead { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.quiz .q { margin: 6px 0 12px; font-weight: 600; }
.choices { display: grid; gap: 8px; }
.choice {
  display: grid; grid-template-columns: 28px 1fr; gap: 8px; text-align: left;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; cursor: pointer; font: inherit; color: inherit; line-height: 1.6;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice .mark { font-weight: 700; }
.choice.correct { background: var(--ok-soft); border-color: var(--ok); }
.choice.wrong { background: var(--ng-soft); border-color: var(--ng); }
.choice:disabled { cursor: default; }
.explain { margin-top: 12px; padding: 12px; border-radius: 8px; background: var(--bg); display: none; }
.explain.show { display: block; }
.verdict { font-weight: 700; }
.verdict.ok { color: var(--ok); }
.verdict.ng { color: var(--ng); }

/* ---------- remember ---------- */
.remember { background: var(--surface); border: 2px solid var(--ok); border-radius: var(--radius); padding: 12px 16px; margin: 28px 0 12px; }
.remember h3 { margin: 0 0 6px; font-size: 15px; color: var(--ok); }
.chk { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.chk input { margin-top: 6px; accent-color: var(--ok); width: 16px; height: 16px; }

/* ---------- buttons, nav ---------- */
.btn {
  display: inline-block; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font: inherit; font-size: 14px; cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 40px; }
.pager a { flex: 1; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.pager a.next { text-align: right; }
.pager .small { display: block; }
.done-bar { display: flex; align-items: center; gap: 12px; margin-top: 32px; }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 16px 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .num { font-size: 26px; font-weight: 800; }
.stat .lbl { font-size: 12px; color: var(--muted); }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.ch-list .card { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* ---------- flashcards ---------- */
.flash-wrap { perspective: 1000px; margin: 20px 0; }
.flash {
  position: relative; min-height: 220px; cursor: pointer;
  transform-style: preserve-3d; transition: transform .4s;
}
.flash.flipped { transform: rotateY(180deg); }
.flash .face {
  position: absolute; inset: 0; backface-visibility: hidden;
  display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px;
}
.flash .front { font-size: 22px; font-weight: 700; }
.flash .back { transform: rotateY(180deg); font-size: 15px; }
.flash .hint { position: absolute; bottom: 10px; font-size: 12px; color: var(--muted); font-weight: 400; }
.flash-ctl { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.filters select, .filters label { font: inherit; font-size: 14px; }
.filters select { padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }

/* ---------- 選択して質問 ---------- */
.ask-pop {
  position: absolute; z-index: 30; width: 340px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 12px; display: none;
}
.ask-pop.show { display: block; }
.ask-pop .quote {
  font-size: 12px; color: var(--muted); border-left: 3px solid var(--accent);
  padding-left: 8px; max-height: 72px; overflow: hidden; margin-bottom: 8px;
}
.ask-pop textarea {
  width: 100%; min-height: 64px; resize: vertical; font: inherit; font-size: 14px;
  padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text);
}
.ask-pop .row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.ask-pop .chip {
  font-size: 12px; padding: 3px 8px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.ask-pop .actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
.ask-pop .btn { padding: 6px 12px; }

/* ---------- 質問履歴 ---------- */
.ask-item .quote { font-size: 13px; color: var(--muted); border-left: 3px solid var(--accent); padding-left: 8px; margin: 8px 0; }
.ask-item .ask-q { font-weight: 600; }
.ask-item .memo {
  width: 100%; min-height: 56px; margin-top: 8px; resize: vertical; font: inherit; font-size: 14px;
  padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text);
}
.ask-item .actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
.ask-item .btn { padding: 4px 10px; font-size: 13px; }
#histKw { width: 100%; max-width: 360px; padding: 8px 10px; font: inherit; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); }

/* ---------- 英語正式名称・出題履歴 ---------- */
.term dt .en, .flash .en { display: block; font-weight: 400; font-size: 11px; color: var(--muted); line-height: 1.4; margin-top: 2px; }
.flash .en { margin-top: 12px; }
.past { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; margin: 24px 0 0; }
.past summary { cursor: pointer; font-weight: 600; }
.past > div { padding: 4px 0; }

/* ---------- pyramid / timeline ---------- */
.pyramid { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pyramid .lv { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 6px; text-align: center; padding: 10px 8px; }
.pyramid .lv:nth-child(-n+2) { background: var(--accent); }
.pyramid .lv:nth-child(-n+2) b { color: #fff; }
.timeline .tl-line { display: flex; justify-content: space-between; position: relative; padding: 0 4%; }
.timeline .tl-line::before { content: ""; position: absolute; left: 0; right: 0; top: 7px; height: 2px; background: var(--accent); }
.timeline .tl-pt { position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; max-width: 30%; }
.timeline .tl-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--surface); border: 3px solid var(--accent); margin-bottom: 6px; }
.timeline .tl-pt.mid .tl-dot { background: var(--ng); border-color: var(--ng); }
.timeline .tl-pt.mid b { color: var(--ng); }
.tl-arrow { text-align: right; font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- 図版・午後問題 ---------- */
img.fig { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 6px; background: #fff; }
.pm-body { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 20px; margin: 16px 0; }
.pm-body summary { cursor: pointer; font-weight: 700; }
.pm-body h3 { font-size: 15px; margin: 20px 0 6px; }
.pm-q textarea { width: 100%; min-height: 56px; margin: 4px 0 8px; font: inherit; font-size: 14px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); }
.pm-q .actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* ---------- シーケンス図 ---------- */
.seq svg { width: 100%; height: auto; display: block; font-family: inherit; }
.seq .sq-actor { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; }
.seq .sq-actort { fill: var(--text); font-size: 14px; font-weight: 700; text-anchor: middle; }
.seq .sq-life { stroke: var(--line); stroke-width: 2; stroke-dasharray: 4 4; }
.seq .sq-arrow { stroke: var(--accent); stroke-width: 2; }
.seq .sq-arrow.dashed { stroke-dasharray: 6 4; }
.seq .sq-head { fill: var(--accent); }
.seq .sq-label { fill: var(--text); font-size: 13px; font-weight: 600; text-anchor: middle; }
.seq .sq-sub { fill: var(--muted); font-size: 11.5px; text-anchor: middle; }
.seq .sq-note { fill: var(--warn-soft); stroke: var(--line); }
.seq .sq-notet { fill: var(--text); font-size: 12.5px; text-anchor: middle; }
.seq .sq-div { stroke: var(--muted); stroke-dasharray: 2 4; }
.seq .sq-divt { fill: var(--muted); font-size: 11.5px; text-anchor: middle; }
.seq .sq-actort { font-size: 13px; }
.seq .sq-actort.sm { font-size: 11.5px; font-weight: 500; }
.seq { overflow-x: auto; }
@media (max-width: 600px) { .seq svg { min-width: 560px; } }


/* ========== モバイル（600px以下）========== */
.backdrop { display: none; }
@media (max-width: 800px) {
  .backdrop.show { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.35); }
}
@media (max-width: 600px) {
  body { font-size: 16px; }
  .topbar { gap: 10px; padding: 0 12px; }
  .brand { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
  /* 上のメニューは下部タブバーへ */
  .topnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 12; margin: 0;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .topnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: 11px; border-radius: 8px; }
  .topnav a span { display: inline !important; }
  .topnav svg.lucide { width: 21px; height: 21px; }
  .topnav .nav-extra { display: none; }
  .icon-btn { display: none; }
  .content { padding: 18px 16px 110px; }
  .sidebar { top: 52px; height: calc(100vh - 52px); width: min(86vw, 320px); }
  h1 { font-size: 22px; }
  h2 { font-size: 18px; margin-top: 28px; }
  .card { padding: 14px 14px; }
  /* 表は行ごとのカードにする */
  .table-wrap table, .table-wrap thead, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap table { background: transparent; }
  .table-wrap thead { display: none; }
  .table-wrap tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
  .table-wrap td { border: 0; border-top: 1px solid var(--line); padding: 8px 12px; white-space: normal; }
  .table-wrap td:first-child { border-top: 0; background: var(--accent-soft); font-weight: 700; }
  .table-wrap td[data-label]:not(:first-child)::before { content: attr(data-label); display: block; font-size: 11.5px; color: var(--muted); font-weight: 600; }
  .pager { flex-direction: column; }
  .pager a.next { text-align: left; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat .num { font-size: 22px; }
  .ch-list .bar { width: 100% !important; }
  .flash { min-height: 260px; }
  .tri-legend { grid-template-columns: 1fr; }
  /* 選択して質問：画面下からのシートにする */
  .ask-pop { position: fixed !important; left: 8px !important; right: 8px; top: auto !important; bottom: calc(70px + env(safe-area-inset-bottom)); width: auto; max-width: none; }
  .done-bar .btn, .flash-ctl .btn { flex: 1; }
  .flash-ctl { flex-wrap: nowrap; }
}

/* ポータルへ戻るボタン */
.portal-link { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 8px; color: var(--muted); font-size: 18px; flex-shrink: 0; }
.portal-link:hover { background: var(--accent-soft); color: var(--accent); }

/* サイドバー上部のツール（モバイルではタブバーにないもの） */
.side-tools { display: none; gap: 6px; margin-bottom: 14px; }
.side-tools a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); font-size: 12px; }
.side-tools svg.lucide { width: 20px; height: 20px; color: var(--accent); }
@media (max-width: 600px) { .side-tools { display: flex; } }

/* ボタンの並び */
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.ok-text { color: var(--ok); } .ng-text { color: var(--ng); }

/* 復習：習熟度 */
.boxes { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 150px; }
.box-col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 2px; }
.box-bar { width: 70%; max-width: 44px; background: var(--accent); border-radius: 4px 4px 0 0; opacity: .85; }
.box-col:first-child .box-bar { background: var(--ng); }
.box-col .num { font-weight: 700; font-size: 14px; }

/* 模試 */
.exam-opt { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.exam-bar { position: sticky; top: 52px; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 14px; margin: -8px 0 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 4px 14px rgba(0,0,0,.06); }
.exam-bar .btn { margin-left: auto; }
.exam-timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 18px; display: inline-flex; align-items: center; gap: 4px; }
.exam-timer.warn { color: var(--ng); }
.exam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 6px; margin: 0 0 16px; }
.exam-grid a { display: flex; align-items: center; justify-content: center; height: 34px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); font-size: 13px; background: var(--surface); }
.exam-grid a.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.exam-grid a.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.exam-grid a.ng { background: var(--ng-soft); color: var(--ng); border-color: var(--ng); }
.choice.picked { border-color: var(--accent); background: var(--accent-soft); }
.choice.picked .mark { background: var(--accent); color: #fff; }
div.choice { cursor: default; }
.exam-result { display: flex; align-items: center; gap: 18px; border-left: 4px solid var(--ok); }
.exam-result.fail { border-left-color: var(--ng); }
.exam-result .num { font-size: 40px; font-weight: 800; line-height: 1; }
@media (max-width: 600px) { .exam-bar { top: 52px; } .exam-opt { flex-direction: column; align-items: stretch; } }

/* 午後：自分の解答 */
.pm-ans { width: 100%; min-height: 90px; margin: 10px 0 0; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; resize: vertical; }
.pm-count { margin-right: auto; }

/* 検索 */
#searchQ, #glossKw { flex: 1; min-width: 0; font-size: 16px; }
.search-hit { display: block; color: var(--text); padding: 12px 14px; }
.search-hit:hover { border-color: var(--accent); }
.search-hit .qhead b { color: var(--text); font-size: 14px; }
mark { background: #ffe58a; color: inherit; border-radius: 2px; padding: 0 1px; }
:root[data-theme="dark"] mark { background: #6b5a14; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) mark { background: #6b5a14; } }

/* 用語集 */
.gloss-index { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 8px; position: sticky; top: 52px; z-index: 4; background: var(--bg); padding: 6px 0; }
.gloss-index a { min-width: 30px; text-align: center; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; background: var(--surface); }
.gloss { margin: 0; }
.gloss-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.gloss-item dt { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-weight: 700; }
.gloss-item dt .en { font-weight: 400; font-size: 12px; color: var(--muted); }
.gloss-item dt .small { margin-left: auto; font-weight: 400; }
.gloss-item dd { margin: 4px 0 0; font-size: 14px; }
h2[id^="gl-"] { scroll-margin-top: 110px; }
.quiz[id^="exq-"] { scroll-margin-top: 120px; }
