:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1b1f27;
  --muted: #5f6673;
  --border: #d9dde5;
  --accent: #d97706;
  --accent-soft: #fff1dc;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --ng: #b91c1c;
  --ng-soft: #fee2e2;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141a;
    --surface: #1c1f27;
    --surface-2: #262a35;
    --text: #e8eaef;
    --muted: #9aa1ad;
    --border: #343946;
    --accent: #f5a524;
    --accent-soft: #3a2a10;
    --ok: #4ade80;
    --ok-soft: #14301f;
    --ng: #f87171;
    --ng-soft: #3a1717;
    --info: #60a5fa;
    --info-soft: #172647;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 16px;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.3; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
a { color: var(--info); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-home {
  background: none; border: none; padding: 4px 0;
  font-weight: 700; font-size: 1rem;
}
.topbar-info { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .95rem; display: flex; gap: 12px; align-items: center; }
.topbar-info .timer { font-weight: 700; color: var(--text); }
.topbar-info .timer.warn { color: var(--ng); }

.app { max-width: 760px; margin: 0 auto; padding: 20px 16px 60px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card.compact { padding: 12px 14px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  text-decoration: none;
  transition: background .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn.danger { color: var(--ng); border-color: var(--ng); }
.btn.block { width: 100%; }
.btn.lg { padding: 14px 20px; font-size: 1.05rem; }
.btn.sm { padding: 6px 10px; font-size: .875rem; }

.menu { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.menu-item {
  text-align: left;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px;
}
.menu-item:hover { border-color: var(--accent); }
.menu-item .title { font-weight: 700; font-size: 1.05rem; }
.menu-item .desc { color: var(--muted); font-size: .875rem; font-weight: 400; }
.menu-item .icon { font-size: 1.5rem; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat .v { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: .8rem; color: var(--muted); }

.bar-list { display: flex; flex-direction: column; gap: 8px; }
.bar-item { display: grid; grid-template-columns: 8.5em 1fr 4.5em; gap: 10px; align-items: center; font-size: .9rem; }
.bar-item .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.bar > i.ok { background: var(--ok); }
.bar > i.ng { background: var(--ng); }
.bar-item .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

.field { margin-bottom: 14px; }
.field > label.title, .field > .title { display: block; font-weight: 700; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: .9rem; user-select: none;
}
.chip input { margin: 0; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); }
select, input[type="number"] {
  font: inherit; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}

.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin: 8px 0 14px; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .2s; }

.q-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.q-num { font-weight: 700; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: .8rem; }
.tag.cat { background: var(--info-soft); color: var(--info); }
.q-text { font-size: 1.05rem; white-space: pre-line; margin: 12px 0; }
.figure {
  margin: 12px auto; padding: 12px;
  max-width: 360px;
  border: 1px dashed var(--border); border-radius: 10px;
  background: var(--surface);
}
.figure svg { display: block; width: 100%; height: auto; max-height: 260px; color: var(--text); }

.choices { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.choice {
  display: grid; grid-template-columns: 2.2em 1fr; align-items: center; gap: 10px;
  padding: 10px 12px; text-align: left;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  white-space: pre-line;
}
.choice:hover:not(:disabled) { border-color: var(--accent); background: var(--surface-2); }
.choice .lbl {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2em; height: 2em; border-radius: 50%;
  background: var(--surface-2); font-weight: 700;
}
.choice.selected { border-color: var(--accent); background: var(--accent-soft); }
.choice.selected .lbl { background: var(--accent); color: #fff; }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.correct .lbl { background: var(--ok); color: #fff; }
.choice.wrong { border-color: var(--ng); background: var(--ng-soft); }
.choice.wrong .lbl { background: var(--ng); color: #fff; }
.choice:disabled { cursor: default; }

.verdict { font-weight: 700; font-size: 1.1rem; margin-bottom: 6px; }
.verdict.ok { color: var(--ok); }
.verdict.ng { color: var(--ng); }
.explain {
  margin-top: 10px; padding: 12px 14px;
  border-left: 4px solid var(--accent);
  background: var(--surface-2); border-radius: 0 10px 10px 0;
  white-space: pre-line;
}
.explain .title { font-weight: 700; margin-bottom: 4px; }

.nav-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; margin: 10px 0; }
.nav-cell {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  font-size: .85rem; font-variant-numeric: tabular-nums; padding: 0;
}
.nav-cell.answered { background: var(--info-soft); border-color: var(--info); }
.nav-cell.flag { box-shadow: inset 0 0 0 2px var(--accent); }
.nav-cell.current { outline: 2px solid var(--text); outline-offset: 1px; }
.nav-cell.ok { background: var(--ok-soft); border-color: var(--ok); }
.nav-cell.ng { background: var(--ng-soft); border-color: var(--ng); }
@media (max-width: 480px) { .nav-grid { grid-template-columns: repeat(8, 1fr); } }

.score-big { font-size: 3rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.score-big small { font-size: 1.2rem; color: var(--muted); font-weight: 600; }
.badge { display: inline-block; padding: 4px 12px; border-radius: 999px; font-weight: 700; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.ng { background: var(--ng-soft); color: var(--ng); }

details.q-review { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: var(--surface); }
details.q-review > summary {
  cursor: pointer; padding: 10px 12px; list-style: none;
  display: grid; grid-template-columns: 1.6em 1fr auto; gap: 8px; align-items: center;
}
details.q-review > summary::-webkit-details-marker { display: none; }
details.q-review > summary .mark { font-weight: 700; }
details.q-review > summary .mark.ok { color: var(--ok); }
details.q-review > summary .mark.ng { color: var(--ng); }
details.q-review > summary .qt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.q-review > .body { padding: 10px 12px 12px; border-top: 1px solid var(--border); }
details.q-review[open] > summary .qt { white-space: normal; }

table.hist { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.hist th, table.hist td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.hist td.num { text-align: right; font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tab { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: .9rem; }
.tab.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.footer-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: space-between; margin-top: 14px; }
.kbd-hint { color: var(--muted); font-size: .8rem; }
kbd { font-family: inherit; padding: 1px 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-2); font-size: .8em; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

.app-footer { margin-top: 2rem; padding: 1rem 0 3rem; }
.admax-wrap { margin-top: 1rem; overflow-x: auto; text-align: center; min-height: 90px; }
