:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1c2330;
  --muted: #5d6878;
  --border: #d5dae2;
  --accent: #1f5fbf;
  --accent-ink: #ffffff;
  --accent-soft: #e3ecfa;
  --ok: #1d7a46;
  --ok-soft: #e1f3e8;
  --ng: #c23b2a;
  --ng-soft: #fbe6e3;
  --flag: #b86e00;
  --flag-soft: #fdf0d9;
  --paper: #ffffff;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .05);
  --radius: 10px;
  --font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", "Noto Sans Mono CJK JP", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #13161c; --surface: #1c2029; --surface-2: #252a35; --text: #e6e9ef; --muted: #9aa3b2;
    --border: #343a47; --accent: #6aa1ff; --accent-ink: #0d1420; --accent-soft: #1f2d47;
    --ok: #5cc98a; --ok-soft: #173325; --ng: #ff7d6b; --ng-soft: #3a1d1a; --flag: #f0a640; --flag-soft: #3a2c14;
    --paper: #f3f3f0; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #13161c; --surface: #1c2029; --surface-2: #252a35; --text: #e6e9ef; --muted: #9aa3b2;
  --border: #343a47; --accent: #6aa1ff; --accent-ink: #0d1420; --accent-soft: #1f2d47;
  --ok: #5cc98a; --ok-soft: #173325; --ng: #ff7d6b; --ng-soft: #3a1d1a; --flag: #f0a640; --flag-soft: #3a2c14;
  --paper: #f3f3f0; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.7; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.loading { padding: 40px 16px; text-align: center; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 16px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, .opt:focus-visible, .qnav button:focus-visible, .tab:focus-visible, .chip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--ng); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- home ---------- */
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px 48px; }
.site-head { display: flex; align-items: center; gap: 12px; padding: 18px 0 8px; }
.logo { width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; font-size: 14px; flex: none; }
.site-head h1 { font-size: 20px; margin: 0; line-height: 1.3; }
.site-head p { margin: 0; color: var(--muted); font-size: 13px; }
.site-head .spacer { flex: 1; }

.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 13px; color: var(--muted); font-weight: 500; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tab { border: 0; background: none; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.card h3 { margin: 0; font-size: 16px; }
.card .meta { color: var(--muted); font-size: 13px; }
.card .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.ng { background: var(--ng-soft); color: var(--ng); }
.badge.flag { background: var(--flag-soft); color: var(--flag); }
.dots { display: flex; gap: 4px; flex-wrap: wrap; }
.dot { width: 22px; height: 22px; border-radius: 5px; font-size: 11px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-weight: 700; }
.dot.ok { background: var(--ok-soft); color: var(--ok); }
.dot.ng { background: var(--ng-soft); color: var(--ng); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 3px 12px; font-size: 13px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.toolbar .label { font-size: 12px; color: var(--muted); margin-right: 2px; }

.qtable { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.qtable th, .qtable td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; font-size: 14px; vertical-align: middle; }
.qtable th { background: var(--surface-2); font-size: 12px; color: var(--muted); font-weight: 600; }
.qtable tr:last-child td { border-bottom: 0; }
.qtable td.num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.qtable tbody tr:hover { background: var(--surface-2); }
.qtable input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); border-top: 1px solid var(--border); margin-top: 14px; padding: 10px 0; display: flex; gap: 8px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }

.genre-group { margin-bottom: 18px; }
.genre-group h3 { font-size: 13px; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.genre { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.genre:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.genre input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.genre .gbody { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.4; }
.genre .name { font-weight: 600; }
.genre .gmeta { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.genre .cnt { font-size: 13px; color: var(--muted); white-space: nowrap; }
.genre-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; width: 70px; flex: none; }
.bar i { display: block; height: 100%; background: var(--ok); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.panel h2 { font-size: 16px; margin: 0 0 10px; }
.form-row { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; }
.form-row label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.form-row select, .form-row input[type=number] { min-height: 36px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); padding: 0 8px; }
.footnote { color: var(--muted); font-size: 12px; margin-top: 28px; line-height: 1.6; }
.empty { color: var(--muted); padding: 24px; text-align: center; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* ---------- exam (CBT) ---------- */
body.exam-mode { background: var(--surface-2); }
.cbt { display: grid; grid-template-rows: auto 1fr auto; height: 100dvh; }
.cbt-top { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: #26324a; color: #fff; }
.cbt-top .title { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.cbt-top .pos { font-variant-numeric: tabular-nums; font-size: 14px; white-space: nowrap; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 18px; padding: 2px 12px; border-radius: 6px; background: rgba(255,255,255,.12); white-space: nowrap; }
.timer.warn { background: #c23b2a; }
.cbt-top .btn { min-height: 34px; background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.25); color: #fff; }
.cbt-top .btn.finish { background: #fff; color: #26324a; border-color: #fff; }

.cbt-body { display: grid; grid-template-columns: 168px 1fr; min-height: 0; }
.qnav { overflow-y: auto; border-right: 1px solid var(--border); background: var(--surface); padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.qnav .legend { font-size: 11px; color: var(--muted); line-height: 1.5; margin-bottom: 4px; }
.qnav button { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 6px 8px; cursor: pointer; font-size: 13px; text-align: left; }
.qnav button .n { font-weight: 700; width: 3.2em; }
.qnav button .a { margin-left: auto; font-weight: 700; color: var(--accent); }
.qnav button.answered { background: var(--accent-soft); }
.qnav button.current { outline: 2px solid var(--accent); outline-offset: -2px; }
.qnav button .f { color: var(--flag); font-size: 12px; }

.qview { overflow-y: auto; padding: 16px; scroll-behavior: smooth; }
.qview-inner { margin: 0 auto; max-width: var(--paper-w, 820px); }
.paper { background: var(--paper); border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.12); padding: 10px; margin-bottom: 12px; }
.paper img { display: block; width: 100%; height: auto; }
.qhead { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.qhead h2 { margin: 0; font-size: 17px; }
.qhead .meta { color: var(--muted); font-size: 13px; }

.answer-bar { background: var(--surface); border-top: 1px solid var(--border); padding: 10px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.answer-bar .lbl { font-weight: 700; font-size: 13px; color: var(--muted); }
.opts { display: flex; flex-wrap: wrap; gap: 6px; }
.opt { width: 44px; height: 44px; border-radius: 8px; border: 1.5px solid var(--border); background: var(--surface); font-size: 18px; font-weight: 700; cursor: pointer; }
.opt:hover { border-color: var(--accent); }
.opt[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.flagbox { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 14px; user-select: none; }
.flagbox input { width: 18px; height: 18px; accent-color: var(--flag); }
.answer-bar .navbtns { margin-left: auto; display: flex; gap: 8px; }
.zoom { display: inline-flex; gap: 2px; }

/* ---------- result / review ---------- */
.score { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.ring { --p: 0; width: 120px; height: 120px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: conic-gradient(var(--ok) calc(var(--p) * 1%), var(--surface-2) 0); }
.ring > div { width: 92px; height: 92px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; text-align: center; line-height: 1.2; }
.ring b { font-size: 26px; font-variant-numeric: tabular-nums; }
.ring span { font-size: 12px; color: var(--muted); display: block; }
.score .facts { display: grid; gap: 2px; font-size: 14px; }
.score .facts strong { font-variant-numeric: tabular-nums; }
.mark { font-weight: 800; font-size: 17px; }
.mark.ok { color: var(--ok); }
.mark.ng { color: var(--ng); }

.review-opts { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 6px; }
.review-opts span { width: 40px; height: 40px; border-radius: 8px; border: 1.5px solid var(--border); display: grid; place-items: center; font-weight: 700; position: relative; background: var(--surface); }
.review-opts span.correct { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.review-opts span.wrong { background: var(--ng-soft); border-color: var(--ng); color: var(--ng); }
.review-opts span .you { position: absolute; top: -9px; right: -9px; font-size: 10px; background: var(--text); color: var(--surface); border-radius: 99px; padding: 0 5px; line-height: 16px; }
.explain { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 14px 18px; margin: 14px 0; }
.explain h3 { margin: 0 0 6px; font-size: 15px; }
.explain p { margin: 8px 0; }
.explain ul { margin: 6px 0; padding-left: 1.3em; }
.explain pre { font-family: var(--mono); font-size: 13px; line-height: 1.55; background: var(--surface-2); padding: 10px 12px; border-radius: 6px; overflow-x: auto; margin: 8px 0; }
.explain code { font-family: var(--mono); }
.verdict { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius); font-weight: 700; margin: 10px 0; }
.verdict.ok { background: var(--ok-soft); color: var(--ok); }
.verdict.ng { background: var(--ng-soft); color: var(--ng); }
.review-nav { display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap; margin: 16px 0; }
.page-head { display: flex; align-items: center; gap: 10px; padding: 16px 0 10px; flex-wrap: wrap; }
.page-head h1 { font-size: 19px; margin: 0; flex: 1; min-width: 200px; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(10, 15, 25, .55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); color: var(--text); border-radius: 12px; max-width: 560px; width: 100%; max-height: calc(100dvh - 32px); overflow: auto; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal.wide { max-width: 900px; }
.modal h2 { margin: 0 0 10px; font-size: 18px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.modal .grid-status { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; margin: 10px 0; }
.modal .grid-status button { border: 1px solid var(--border); border-radius: 6px; padding: 6px; background: var(--surface); cursor: pointer; font-size: 13px; }
.modal .grid-status button.answered { background: var(--accent-soft); }
.modal .grid-status button.unanswered { border-color: var(--ng); color: var(--ng); }
.time-choice { display: grid; gap: 8px; margin: 8px 0; }
.time-choice label { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.time-choice label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.time-choice input[type=radio] { accent-color: var(--accent); }
.time-choice small { color: var(--muted); margin-left: auto; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  body { font-size: 14px; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .cbt-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .qnav { flex-direction: row; overflow-x: auto; overflow-y: hidden; border-right: 0; border-bottom: 1px solid var(--border); padding: 6px 10px; }
  .qnav .legend { display: none; }
  .qnav button { flex: none; padding: 4px 8px; }
  .qnav button .n { width: auto; }
  .qview { padding: 10px; }
  .paper { padding: 4px; }
  .cbt-top { padding: 6px 10px; gap: 6px; flex-wrap: wrap; }
  .cbt-top .title { flex-basis: 100%; order: -1; font-size: 13px; }
  .cbt-top .btn { padding: 0 10px; }
  .timer { font-size: 16px; }
  .answer-bar { padding: 8px 10px; gap: 8px; }
  .answer-bar .navbtns { margin-left: 0; width: 100%; }
  .answer-bar .navbtns .btn { flex: 1; }
  .qview-inner { min-width: var(--paper-min, 0); }
  .opt { width: 40px; height: 40px; }
  .qtable .hide-sm { display: none; }
}
