:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1b1f2a;
  --muted: #5f6677;
  --line: #dfe3ec;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --ok: #2b8a3e;
  --ok-bg: #e6f6ea;
  --bad: #c92a2a;
  --bad-bg: #fdecec;
  --sel: #e7ecff;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141a;
    --card: #1c1f28;
    --text: #e8eaf0;
    --muted: #a2a8b8;
    --line: #2e3340;
    --accent: #7b93ff;
    --accent-text: #0f1220;
    --ok: #69db7c;
    --ok-bg: #173323;
    --bad: #ff8787;
    --bad-bg: #3a1c1f;
    --sel: #262d48;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 12px 16px 6px;
  border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: flex-start; gap: 12px; }
.titles { flex: 1; min-width: 0; }
h1 { font-size: 19px; line-height: 1.25; margin: 0; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: 14px; }
.score {
  flex: none; font-weight: 700; font-size: 16px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px; white-space: nowrap;
}
.bar { height: 6px; background: var(--line); border-radius: 99px; margin: 10px 0 8px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .25s; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 4px 12px; font-size: 14px; cursor: pointer;
  min-height: 34px;
}
.tab.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.tab.done:not(.active) { border-color: var(--ok); }

.app { max-width: 640px; margin: 0 auto; padding: 16px 16px 110px; }
.stage-title { font-size: 21px; margin: 4px 0 4px; overflow-wrap: anywhere; }
.hint { color: var(--muted); font-size: 15px; margin: 0 0 14px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin: 0 0 14px;
  overflow-wrap: anywhere;
}
.q { font-weight: 600; margin: 0 0 10px; }
.num { color: var(--muted); font-weight: 600; margin-right: 4px; }

.opts { display: grid; gap: 8px; }
.opt {
  display: block; width: 100%; text-align: left;
  min-height: 48px; padding: 10px 14px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--card); cursor: pointer; overflow-wrap: anywhere;
}
.opt:disabled { cursor: default; }
.opt.ok { border-color: var(--ok); background: var(--ok-bg); }
.opt.bad { border-color: var(--bad); background: var(--bad-bg); }
.opt.sel { border-color: var(--accent); background: var(--sel); }
.opt.dim { opacity: .55; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.why { margin-top: 10px; padding: 10px 12px; border-radius: 10px; font-size: 15px; }
.why.ok { background: var(--ok-bg); }
.why.bad { background: var(--bad-bg); }
.why b { display: block; }

.btn {
  min-height: 48px; padding: 10px 18px; border-radius: 12px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--card);
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 15px; }
.btn:disabled { opacity: .45; cursor: default; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.actions-top { margin: 0 0 10px; }
.actions-footer { justify-content: center; margin-top: 24px; }
.hint-inline { margin: 8px 0 0; }
.center { text-align: center; }

.gap-form { display: flex; gap: 8px; margin-top: 4px; }
.gap-input {
  flex: 1; min-width: 0; min-height: 48px; font: inherit; font-size: 17px;
  padding: 8px 12px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--bg); color: var(--text);
}
.gap-input.ok { border-color: var(--ok); }
.gap-input.bad { border-color: var(--bad); }

.reading-text { white-space: pre-wrap; }
details.reading-peek { margin-bottom: 14px; }
details.reading-peek summary { cursor: pointer; color: var(--accent); min-height: 40px; padding: 8px 0; }

/* Flashcards */
.fc-filter { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.fc {
  min-height: 190px; display: flex; flex-direction: column; justify-content: center;
  align-items: center; text-align: center; cursor: pointer; user-select: none;
}
.fc-word { font-size: 28px; font-weight: 700; }
.fc-ex { color: var(--muted); margin-top: 8px; font-style: italic; }
.fc-tr { font-size: 24px; font-weight: 600; }
.fc-tag { font-size: 13px; color: var(--muted); margin-top: 10px; }
.fc-count { text-align: center; color: var(--muted); margin: -4px 0 10px; }

/* Match */
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: start; }
.match .col { display: grid; gap: 8px; }
.match .opt { text-align: center; font-size: 16px; padding: 10px 8px; }

.result-big { font-size: 40px; font-weight: 800; text-align: center; margin: 8px 0; }
.result-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.result-row:last-child { border-bottom: 0; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; gap: 10px; justify-content: space-between;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
.nav .btn { flex: 1; max-width: 300px; }

.error { text-align: center; color: var(--muted); padding: 40px 0; }
