:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #111111;
  --muted: #4a4a4a;
  --line: #b8b8b8;
  --card: #f6f6f4;
  --accent: #1d4ed8;
  --accent-fg: #ffffff;
  --ok: #0a6b2d;
  --ok-bg: #e3f4e8;
  --bad: #a4161a;
  --bad-bg: #fdeaea;
  --lock: #9a9a9a;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212;
    --fg: #f2f2f2;
    --muted: #c4c4c4;
    --line: #555555;
    --card: #1e1e1e;
    --accent: #8ab4ff;
    --accent-fg: #0b1220;
    --ok: #7fe0a0;
    --ok-bg: #12301d;
    --bad: #ff9c9c;
    --bad-bg: #3a1414;
    --lock: #777777;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 18px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
main { max-width: 720px; margin: 0 auto; padding: 12px 16px 48px; }
h1 { font-size: 1.3rem; margin: 4px 0 0; line-height: 1.25; }
.es { display: block; font-style: italic; font-size: 0.8em; color: var(--muted); }
.es-inline { font-style: italic; font-size: 0.8em; color: var(--muted); }
.lesson { color: var(--muted); font-size: 0.85rem; margin: 0; }
.loading { color: var(--muted); }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn {
  min-height: 48px; padding: 10px 18px; border-radius: var(--radius);
  border: 2px solid var(--fg); background: var(--bg); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn .es-inline { color: inherit; opacity: 0.85; }

/* tabs */
.tabs { display: flex; gap: 6px; margin: 12px 0; border-bottom: 2px solid var(--line); }
.tab {
  flex: 1 1 0; min-height: 52px; padding: 6px 4px; border: 0; background: none;
  border-bottom: 4px solid transparent; margin-bottom: -2px; font-weight: 600; line-height: 1.15;
}
.tab .es { font-weight: normal; }
.tab[aria-selected="true"] { border-bottom-color: var(--accent); }

/* identity */
.panel { background: var(--card); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.field { display: block; margin: 0 0 14px; font-weight: 600; }
.field input, .field select {
  display: block; width: 100%; min-height: 48px; margin-top: 4px; padding: 8px 12px;
  border: 2px solid var(--line); border-radius: 10px; background: var(--bg);
}
.who { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; color: var(--muted); font-size: 0.9rem; }
.linkish { background: none; border: 0; color: var(--accent); text-decoration: underline; padding: 8px 0; min-height: 44px; }

/* progress dots */
.dots { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; padding: 0; list-style: none; }
.dot {
  min-width: 44px; min-height: 44px; border-radius: 22px; border: 2px solid var(--line);
  background: var(--bg); font-weight: 700;
}
.dot.done { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.dot.current { border-color: var(--accent); border-width: 3px; }
.dot:disabled { color: var(--lock); border-style: dashed; cursor: not-allowed; }

/* item */
.item { background: var(--card); border-radius: var(--radius); padding: 16px; }
.qnum { font-weight: 700; color: var(--muted); margin: 0 0 6px; }
.stem { margin: 0 0 4px; font-size: 1.1rem; }
.stem-es { margin: 0 0 10px; }
.audio { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.audio .btn { min-width: 128px; }
.audio .btn[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
.figure { margin: 8px 0; text-align: center; }
.figure svg { width: 100%; max-width: 380px; height: auto; max-height: 300px; color: var(--fg); }
.answer-row { display: flex; gap: 8px; align-items: center; margin: 12px 0 8px; flex-wrap: wrap; }
.answer-row label { width: 100%; font-weight: 600; }
.answer-row input {
  flex: 1 1 140px; min-width: 0; min-height: 52px; font-size: 1.25rem; padding: 8px 12px;
  border: 2px solid var(--fg); border-radius: 10px; background: var(--bg);
}
.unit { font-size: 1.2rem; font-weight: 600; }
.choices { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.choice label {
  display: flex; gap: 12px; align-items: flex-start; min-height: 52px; padding: 10px 12px;
  border: 2px solid var(--line); border-radius: 10px; background: var(--bg); cursor: pointer;
}
.choice input { width: 24px; height: 24px; margin-top: 2px; flex: none; }
.choice.picked-wrong label { border-color: var(--bad); }
.choice.picked-right label { border-color: var(--ok); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.actions .btn { flex: 1 1 160px; }

.feedback { margin-top: 12px; border-radius: 10px; padding: 12px; border: 2px solid transparent; }
.feedback:empty { display: none; }
.feedback.right { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); font-weight: 700; }
.feedback.wrong { background: var(--bad-bg); border-color: var(--bad); }
.feedback.wrong .head { color: var(--bad); font-weight: 700; }
.feedback.blank { background: var(--card); border-color: var(--line); }

/* reference sheet */
.sheet-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.sheet-tools .btn { min-width: 52px; }
.sheet-wrap {
  overflow: auto; max-height: 80vh; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; touch-action: pan-x pan-y pinch-zoom; -webkit-overflow-scrolling: touch;
}
.sheet-wrap img { display: block; width: 100%; height: auto; }

/* score */
.big { font-size: 2.2rem; font-weight: 800; margin: 0; }
.code {
  font: 800 2.4rem/1.1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.18em;
  background: var(--bg); border: 3px solid var(--fg); border-radius: 10px; padding: 10px 14px;
  display: inline-block; margin: 6px 0; user-select: all; -webkit-user-select: all;
}
.pill { display: inline-block; border-radius: 999px; padding: 4px 12px; font-size: 0.9rem; font-weight: 600; }
.pill.saved { background: var(--ok-bg); color: var(--ok); }
.pill.pending { background: var(--bad-bg); color: var(--bad); }
.itemlist { list-style: none; padding: 0; margin: 8px 0 0; }
.itemlist li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.ok { color: var(--ok); font-weight: 700; }
.bad { color: var(--bad); font-weight: 700; }
.muted { color: var(--muted); }
.setlist { list-style: none; padding: 0; }
.setlist a { display: block; padding: 14px; margin: 8px 0; border: 2px solid var(--line); border-radius: var(--radius); color: inherit; text-decoration: none; }

@media (max-width: 380px) {
  body { font-size: 17px; }
  .code { font-size: 2rem; letter-spacing: 0.12em; }
  .tab { font-size: 0.9rem; }
}
