:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #faf9f5;
  --ink: #1b2130;
  --ink-2: #3c4458;
  --muted: #6b7182;
  --line: #e4e1d8;
  --brand: #1f3a8a;
  --brand-2: #2f55d4;
  --brand-soft: #e8edfc;
  --ok: #157f52;
  --ok-soft: #e3f4ea;
  --ng: #c23a32;
  --ng-soft: #fbe7e4;
  --warn: #a86400;
  --warn-soft: #fdf1dc;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 4px 16px rgba(20, 24, 40, .05);
  --radius: 14px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151d;
    --surface: #1a1e29;
    --surface-2: #1f2431;
    --ink: #e9ebf1;
    --ink-2: #c7cbd6;
    --muted: #9298a8;
    --line: #2d3342;
    --brand: #8fa8ff;
    --brand-2: #a9bcff;
    --brand-soft: #222c4a;
    --ok: #5fd39a;
    --ok-soft: #173326;
    --ng: #ff8a80;
    --ng-soft: #3a1f1d;
    --warn: #f4bf5c;
    --warn-soft: #3a2e17;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: 16px; line-height: 1.75; min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--brand-2); }
button, input, select { font: inherit; color: inherit; }
main { flex: 1; width: 100%; max-width: 860px; margin: 0 auto; padding: 20px 16px 96px; outline: none; }
h1, h2, h3 { line-height: 1.4; margin: 0 0 .6em; letter-spacing: .01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.loading { padding: 48px 0; text-align: center; color: var(--muted); }

/* ---- header ---- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-weight: 700; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--brand); color: #fff; font-weight: 800; font-size: 17px;
}
@media (prefers-color-scheme: dark) { .brand-mark { color: #12151d; } }
.topnav { display: flex; gap: 4px; margin-left: 8px; }
.topnav a { text-decoration: none; color: var(--ink-2); padding: 6px 12px; border-radius: 999px; font-size: .93rem; }
.topnav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.account-link {
  margin-left: auto; text-decoration: none; font-size: .9rem; padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--ink); background: var(--surface); max-width: 45vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tabbar { display: none; }
@media (max-width: 720px) {
  .topnav { display: none; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; padding: 6px 0 7px;
    font-size: .68rem; color: var(--muted); text-decoration: none; line-height: 1.3;
  }
  .tabbar a .ti { font-size: 1.15rem; line-height: 1.2; }
  .tabbar a.active { color: var(--brand); font-weight: 700; }
  .seg { gap: 6px; }
  .seg label { padding: 6px 12px; font-size: .85rem; }
  .card { padding: 16px; }
  .tbl { font-size: .84rem; }
  .tbl th, .tbl td { padding: 9px 4px; }
}
.tbl th, .tbl td.num { white-space: nowrap; }
.footer { max-width: 860px; margin: 0 auto; padding: 0 16px 90px; color: var(--muted); font-size: .78rem; line-height: 1.6; }
@media (min-width: 721px) { .footer { padding-bottom: 32px; } }

/* ---- common ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.flat { box-shadow: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 10px 20px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 700; cursor: pointer; text-decoration: none; transition: transform .05s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #12151d; } }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--ng); border-color: var(--ng); background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .78rem;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap;
}
.chip.brand { background: var(--brand-soft); border-color: transparent; color: var(--brand); font-weight: 700; }
.chip.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.chip.ng { background: var(--ng-soft); border-color: transparent; color: var(--ng); }
.chip.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.notice { background: var(--brand-soft); border-radius: 12px; padding: 14px 16px; font-size: .9rem; margin-bottom: 16px; }
.notice.warn { background: var(--warn-soft); }
.notice.ng { background: var(--ng-soft); color: var(--ng); }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 560px) { .grid3 { gap: 8px; } .stat { padding: 10px; } .stat .v { font-size: 1.2rem; } .stat .k { font-size: .7rem; } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat .v { font-size: 1.5rem; font-weight: 800; line-height: 1.3; font-variant-numeric: tabular-nums; }
.stat .k { font-size: .78rem; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .9rem;
  transition: all .2s; pointer-events: none; z-index: 50; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- home ---- */
.hero { padding: 12px 0 8px; }
.hero h1 { font-size: 1.7rem; margin-bottom: .3em; }
.hero p { color: var(--ink-2); }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 20px 0; }
@media (max-width: 520px) { .quick { grid-template-columns: 1fr; } }
.quick .btn { min-height: 64px; font-size: 1.02rem; flex-direction: column; gap: 0; }
.quick .btn small { font-weight: 400; font-size: .78rem; opacity: .85; }
.cat-list { display: grid; gap: 8px; }
.cat-row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; text-align: left; width: 100%;
}
.cat-row:hover { border-color: var(--brand-2); }
.cat-row .name { font-weight: 700; font-size: .95rem; }
.cat-row .meta { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { grid-column: 1 / -1; height: 6px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand-2); border-radius: 999px; }
.bar.ok > i { background: var(--ok); }

/* ---- form ---- */
.field { margin-bottom: 16px; }
.field > label, .field > .label { display: block; font-weight: 700; font-size: .9rem; margin-bottom: 6px; }
.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); font-size: 16px;
}
.input:focus { outline: 2px solid var(--brand-2); outline-offset: 1px; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg label {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-size: .9rem; user-select: none;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--brand-soft); border-color: var(--brand-2); color: var(--brand); font-weight: 700; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--brand-2); }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input { flex: 1; accent-color: var(--brand-2); }
.range-row output { font-weight: 800; min-width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 16px; overflow-x: auto; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px; cursor: pointer; font-size: .88rem; white-space: nowrap; }
.tabs button.on { background: var(--surface); box-shadow: var(--shadow); font-weight: 700; color: var(--brand); }
.err { color: var(--ng); font-size: .88rem; min-height: 1.2em; margin: 4px 0 8px; }
.sticky-start { padding-top: 4px; }

/* ---- quiz ---- */
.qhead { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.progress { flex: 1; height: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand-2); transition: width .3s; }
.qcount { font-variant-numeric: tabular-nums; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.qmeta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.stem { font-size: 1.05rem; line-height: 1.85; margin-bottom: 16px; white-space: pre-wrap; word-break: break-word; }
.figs img { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); background: #fff; display: block; margin: 8px 0; }
details.figbox { margin-bottom: 14px; }
details.figbox summary { cursor: pointer; color: var(--brand-2); font-size: .9rem; }
.choices { display: grid; gap: 10px; margin-bottom: 16px; }
.choice {
  display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: start; text-align: left; width: 100%;
  padding: 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); cursor: pointer;
  line-height: 1.65; font-size: .98rem;
}
.choice:hover:not(:disabled) { border-color: var(--brand-2); }
.choice .no {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .85rem;
  background: var(--surface-2); border: 1px solid var(--line);
}
.choice:disabled { cursor: default; }
.choice.sel { border-color: var(--brand-2); background: var(--brand-soft); }
.choice.sel .no { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
.choice.right { border-color: var(--ok); background: var(--ok-soft); }
.choice.right .no { background: var(--ok); color: #fff; border-color: var(--ok); }
.choice.wrong { border-color: var(--ng); background: var(--ng-soft); }
.choice.wrong .no { background: var(--ng); color: #fff; border-color: var(--ng); }
.verdict { font-size: 1.2rem; font-weight: 800; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.verdict.ok { color: var(--ok); }
.verdict.ng { color: var(--ng); }
.explain { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; }
.explain p { margin: 0 0 .7em; }
.explain p:last-child { margin-bottom: 0; }
.qstats { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.qactions { display: flex; gap: 10px; }
.qactions .btn.primary { flex: 1; }
.star { font-size: 1.2rem; min-width: 52px; }
.star.on { color: #d99a00; border-color: #d99a00; }
.kbd-hint { font-size: .75rem; color: var(--muted); text-align: center; margin-top: 10px; }
@media (max-width: 720px) { .kbd-hint { display: none; } }

/* ---- result ---- */
.score-big { font-size: 3rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.score-big small { font-size: 1.1rem; color: var(--muted); font-weight: 700; }
.rlist { display: grid; gap: 8px; }
.ritem { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.ritem summary { display: grid; grid-template-columns: 26px 1fr; gap: 8px; padding: 12px 14px; cursor: pointer; list-style: none; font-size: .92rem; line-height: 1.6; }
.ritem summary::-webkit-details-marker { display: none; }
.ritem .mk { font-weight: 800; }
.ritem .mk.ok { color: var(--ok); }
.ritem .mk.ng { color: var(--ng); }
.ritem .body { padding: 0 14px 14px; font-size: .92rem; }
.ritem .body ol { padding-left: 1.4em; margin: 0 0 10px; }
.ritem .body li.ans { color: var(--ok); font-weight: 700; }
.ritem .body li.mine { color: var(--ng); }

/* ---- exam ---- */
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.05rem; }
.timer.low { color: var(--ng); }
.navgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 6px; margin: 12px 0; }
.navgrid button {
  height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: .8rem;
  font-variant-numeric: tabular-nums;
}
.navgrid button.done { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.navgrid button.flag { box-shadow: inset 0 -3px 0 #d99a00; }
.navgrid button.cur { outline: 2px solid var(--brand-2); }

/* ---- stats ---- */
.days { display: flex; align-items: flex-end; gap: 3px; height: 110px; padding-top: 8px; border-bottom: 1px solid var(--line); }
.days div { flex: 1; background: var(--brand-2); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; opacity: .85; }
.days div.zero { background: var(--line); }
.days-axis { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); margin-top: 4px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th, .tbl td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.tbl th { font-size: .78rem; color: var(--muted); font-weight: 600; }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl tr.me td { background: var(--brand-soft); font-weight: 700; }
.rank-no { font-weight: 800; width: 2.6em; }
.medal1 { color: #c79300; } .medal2 { color: #8a94a6; } .medal3 { color: #b4683a; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
