:root {
  --bg: #f6f7f9;
  --card: #fff;
  --ink: #1d2330;
  --muted: #6b7280;
  --line: #d9dde3;
  --brand: #1f4e79;
  --brand-soft: #e8f0f8;
  --right: #1e7a46;
  --right-soft: #e5f4ea;
  --wrong: #b42318;
  --wrong-soft: #fdecea;
  --hl: #fff2b3;
  --ko: "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --card: #1b2029;
    --ink: #e6e9ef;
    --muted: #9aa3b2;
    --line: #2d3440;
    --brand: #7fb3e6;
    --brand-soft: #1e2b3a;
    --right: #5cc98a;
    --right-soft: #16301f;
    --wrong: #f2857a;
    --wrong-soft: #3a1c1a;
    --hl: #5a4a10;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

button { font: inherit; color: inherit; cursor: pointer; }

header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
@media (prefers-color-scheme: dark) { header { background: #1e2b3a; } }
header h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 600; }
#score { font-weight: 600; font-variant-numeric: tabular-nums; }

.icon {
  border: 0; background: none; font-size: 26px; line-height: 1;
  width: 36px; height: 36px; padding: 0;
}
header .icon { color: #fff; }

main { max-width: 720px; margin: 0 auto; padding: 12px; }

.hint { color: var(--muted); font-size: 14px; }

/* exam list */
.exam {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; margin-bottom: 12px; color: inherit; text-decoration: none;
}
.exam span { color: var(--muted); font-size: 14px; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); }

/* group + question */
.q { scroll-margin-top: 64px; }
.group, .q {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; margin-bottom: 12px;
}
.group h2 { font-size: 17px; margin: 0 0 6px; font-family: var(--ko); font-weight: 600; line-height: 1.6; }
.q h3 { font-size: 16px; margin: 0 0 10px; font-family: var(--ko); font-weight: 600; line-height: 1.6; }
.q h3 small { color: var(--muted); font-weight: 400; }

.ko, .otext, .group h2, .q h3, .example { font-family: var(--ko); }
.ko { font-size: 18px; line-height: 1.9; word-break: keep-all; }

.box {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; margin: 10px 0;
}
.imgtext summary, details.vi summary, .example summary {
  color: var(--brand); font-size: 14px; cursor: pointer; padding: 4px 0;
}
details.vi div { color: var(--muted); font-size: 15px; padding: 4px 0 2px; }
.example { margin: 8px 0; font-size: 16px; }
.example .exans { font-weight: 700; color: var(--brand); }

img { display: block; max-width: 100%; height: auto; margin: 10px auto; border-radius: 6px; background: #fff; }

.blank { white-space: pre; }

/* tappable words */
.w { border-radius: 4px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.w:active, .w.on { background: var(--hl); }

/* options */
.opts { list-style: none; padding: 0; margin: 10px 0 0; }
.opt {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 10px; margin-bottom: 6px;
  border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.opt .num {
  flex: none; width: 34px; height: 34px; margin: -3px 0;
  border: 0; border-radius: 50%; background: none;
  font-size: 22px; line-height: 34px; padding: 0;
}
.otext { font-size: 17px; line-height: 1.7; padding-top: 1px; word-break: keep-all; }
.opt.picked { border-color: var(--brand); background: var(--brand-soft); }
.opt.picked .num { color: var(--brand); font-weight: 700; }
.opt.right { border-color: var(--right); background: var(--right-soft); }
.opt.right .num { color: var(--right); font-weight: 700; }
.opt.wrong { border-color: var(--wrong); background: var(--wrong-soft); }
.opt.wrong .num { color: var(--wrong); }

.actions { margin-top: 8px; }
.primary, .ghost {
  width: 100%; padding: 11px; border-radius: 10px; font-weight: 600;
}
.primary { background: var(--brand); color: #fff; border: 0; }
@media (prefers-color-scheme: dark) { .primary { color: #12151b; } }
.primary:disabled { opacity: .4; }
.ghost { background: none; border: 1px solid var(--line); color: var(--muted); }

.verdict { margin-top: 10px; padding: 10px 12px; border-radius: 10px; font-weight: 600; }
.verdict p { margin: 6px 0 0; font-weight: 400; font-size: 15px; }
.verdict.ok { background: var(--right-soft); color: var(--right); }
.verdict.bad { background: var(--wrong-soft); color: var(--wrong); }
.verdict p { color: var(--ink); }

/* pager */
#pager {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; gap: 8px; padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
#pager button {
  flex: 1; padding: 10px 6px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg);
}
#pager #jump { flex: 1.4; font-size: 14px; }
#pager button:disabled { opacity: .35; }

/* result */
.result { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.result h2 { margin: 0; }
.result .big { font-size: 28px; font-weight: 700; margin: 8px 0 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; margin: 14px 0; }
.cell {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 40px; border-radius: 8px;
  border: 1px solid var(--line); color: inherit; text-decoration: none; font-variant-numeric: tabular-nums;
}
.legend .cell { width: 18px; height: 18px; vertical-align: middle; margin: 0 4px 0 10px; }
.cell.right { background: var(--right-soft); border-color: var(--right); color: var(--right); }
.cell.wrong { background: var(--wrong-soft); border-color: var(--wrong); color: var(--wrong); }

/* bottom sheet */
#scrim { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 9; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  max-height: 65vh; overflow-y: auto;
  background: var(--card); border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.15);
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 720px; margin: 0 auto;
}
.sheet .close { position: absolute; top: 8px; right: 8px; color: var(--muted); }
.sheet h3 { margin: 0 40px 2px 0; font-size: 24px; font-family: var(--ko); }
.sheet .gloss { margin: 0 0 10px; font-size: 17px; }
.parts { list-style: none; padding: 0; margin: 0; }
.part { border-top: 1px solid var(--line); padding: 10px 0; }
.part b { font-family: var(--ko); font-size: 18px; }
.part small { color: var(--muted); margin-left: 6px; }
.gtoggle {
  display: flex; align-items: baseline; gap: 8px; width: 100%;
  border: 0; background: none; padding: 0; text-align: left;
}
.gtoggle b { color: var(--brand); flex: none; }
.gtoggle span { flex: 1; color: var(--ink); }
.gtoggle i { font-style: normal; color: var(--muted); transition: transform .15s; }
.gtoggle.open i { transform: rotate(90deg); }
.gdetail { margin-top: 6px; padding: 8px 10px; background: var(--bg); border-radius: 8px; font-size: 15px; }
.gdetail p { margin: 0 0 6px; }
.gdetail ul { margin: 0; padding-left: 18px; }
.gdetail li { margin-bottom: 6px; }
.gdetail [lang="ko"] { font-family: var(--ko); font-size: 16px; }
.muted { color: var(--muted); }

.error { color: var(--wrong); }
