/* Skipper — night-navigation study drill.
   Direction: a ship's instrument panel after dark. Deep-sea navy, one warm
   amber "beacon" accent, monospace tabular readouts for every number, and
   port/starboard red-green answer feedback. */

:root {
  /* spacing — strict 4px scale */
  --s0: 4px; --s1: 8px; --s2: 12px; --s3: 16px; --s4: 24px; --s5: 32px; --s6: 48px;
  /* radii */
  --r-sm: 10px; --r: 14px; --r-lg: 20px; --r-pill: 999px;

  /* dark theme (default) */
  --bg: #0a0f1c; --bg-2: #0e1526;
  --card: #141d30; --raised: #1c2740;
  --text: #eef1f8; --muted: #94a1bb; --line: #253150;
  --accent: #ffb454; --accent-2: #ff9d3c; --accent-text: #ffc06e; --accent-ink: #241701;
  --good: #26c06e; --good-ink: #06231a; --bad: #d42a30; --bad-ink: #ffffff;
  --tint-good: rgba(38,192,110,0.14); --tint-bad: rgba(212,42,48,0.16);
  --img-mat: #f7f8fc;
  --glow: 0 10px 30px -8px rgba(255,150,40,0.55), 0 3px 8px rgba(0,0,0,0.4);
  --shadow: 0 1px 2px rgba(0,0,0,0.35);
  --topglow: radial-gradient(120% 60% at 50% -8%, rgba(255,170,80,0.10), transparent 60%);

  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
}
[data-theme="light"] {
  --bg: #eef1f8; --bg-2: #e6ebf5;
  --card: #ffffff; --raised: #f2f5fb;
  --text: #14203c; --muted: #566079; --line: #dde4f0;
  --accent: #e08700; --accent-2: #c96a00; --accent-text: #9a5a00; --accent-ink: #241701;
  --good: #26c06e; --good-ink: #06231a; --bad: #d42a30; --bad-ink: #ffffff;
  --tint-good: rgba(30,150,85,0.12); --tint-bad: rgba(212,42,48,0.10);
  --img-mat: #ffffff;
  --glow: 0 10px 26px -10px rgba(200,110,0,0.5), 0 1px 3px rgba(20,30,60,0.14);
  --shadow: 0 1px 2px rgba(20,30,60,0.08);
  --topglow: radial-gradient(120% 60% at 50% -8%, rgba(224,135,0,0.10), transparent 60%);
}

* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  background: var(--topglow), linear-gradient(180deg, var(--bg-2), var(--bg) 22%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }

#view {
  max-width: 480px; margin: 0 auto;
  padding: var(--s3) var(--s3) calc(96px + env(safe-area-inset-bottom));
  min-height: 100%;
}
/* Drill & flashcard screens fill the visible viewport (100dvh accounts for the
   iOS toolbars) so the Next button is always on-screen — the card scrolls
   internally if a tall image + options don't fit, the footer stays pinned. */
#view.drilling {
  height: 100dvh; min-height: 0;
  padding-bottom: calc(var(--s3) + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; overflow: hidden;
}
#view.drilling > .drill-head { flex: 0 0 auto; }
#view.drilling > .card { flex: 0 1 auto; min-height: 0; overflow-y: auto; }
#view.drilling > .drill-foot,
#view.drilling > .fc-foot { flex: 0 0 auto; }
.pad { padding: var(--s4) var(--s1); color: var(--muted); text-align: center; }

/* reusable micro-label — a nautical instrument caption */
.day-label, .chip, .tile span, .topic-row .tname,
.plan p, .misses .you, .misses .ans { font-family: var(--sans); }

/* ---------- offline pill ---------- */
#offline {
  position: fixed; top: calc(var(--s1) + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%); z-index: 30;
  background: var(--raised);
  background: color-mix(in srgb, var(--raised) 82%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  color: var(--muted); border: 1px solid var(--line);
  padding: var(--s0) var(--s2); border-radius: var(--r-pill);
  font-size: 0.72rem; letter-spacing: 0.03em; box-shadow: var(--shadow);
}

/* ---------- tab bar ---------- */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around;
  background: var(--card);
  background: color-mix(in srgb, var(--card) 86%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(1.3); backdrop-filter: blur(14px) saturate(1.3);
  border-top: 1px solid var(--line);
  padding: var(--s1) var(--s1) calc(var(--s1) + env(safe-area-inset-bottom));
}
#tabbar .tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-width: 72px; min-height: 48px; padding: var(--s0) var(--s2);
  color: var(--muted); border-radius: var(--r); font-size: 1.2rem;
  transition: color 0.15s ease, background 0.15s ease;
}
#tabbar .tab span { font-size: 0.66rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
#tabbar .tab.active { color: var(--accent-text); background: var(--raised); }
#tabbar .tab:active { transform: scale(0.94); }

/* ---------- home ---------- */
.home-head { display: flex; justify-content: space-between; align-items: center; padding: var(--s0) 0 var(--s2); }
.streak {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--raised); border: 1px solid var(--line);
  padding: 6px var(--s2); border-radius: var(--r-pill);
}
.ghost {
  min-width: 44px; min-height: 44px; border-radius: var(--r);
  border: 1px solid var(--line); font-size: 1.1rem; color: var(--muted);
  display: inline-grid; place-items: center;
  transition: transform 0.08s ease, background 0.15s ease;
}
.ghost:active { transform: scale(0.94); background: var(--raised); }

.hero { text-align: center; padding: var(--s5) 0 var(--s1); animation: rise 0.4s ease both; }
.day-label {
  color: var(--accent-text); font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: var(--s3);
}
.big-number {
  font-family: var(--mono); font-size: 2.7rem; font-weight: 700; line-height: 1;
  letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-bottom: var(--s0);
}
.big-number span { font-size: 1.1rem; color: var(--muted); font-weight: 600; }
.big-number::after {
  content: "questions mastered"; display: block;
  font-family: var(--sans); font-size: 0.66rem; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
  margin-top: var(--s1); margin-bottom: var(--s4);
}

/* the beacon — the one dominant element */
.big {
  display: block; width: 100%; min-height: 64px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: var(--accent-ink); border-radius: var(--r-lg);
  font-size: 1.15rem; font-weight: 800; letter-spacing: 0.01em;
  box-shadow: var(--glow);
  transition: transform 0.08s ease, box-shadow 0.2s ease;
}
.big:active { transform: scale(0.97); box-shadow: 0 4px 14px -6px rgba(255,150,40,0.5); }
.hint { color: var(--muted); font-size: 0.8rem; margin-top: var(--s2); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); margin-top: var(--s5); }
.actions button {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 0 var(--s2);
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); font-size: 0.92rem; font-weight: 600;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}
.actions button:active:not(:disabled) { transform: scale(0.97); background: var(--raised); border-color: var(--accent); }
.actions button:disabled { opacity: 0.4; }

/* ---------- drill ---------- */
.drill-head { display: flex; align-items: center; gap: var(--s2); padding-bottom: var(--s2); }
.chip {
  flex: 1; text-align: center; color: var(--muted); font-size: 0.68rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700;
}
.prog, .clock {
  font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 700;
  min-width: 52px; text-align: right; letter-spacing: 0.02em;
}
.clock { color: var(--accent-text); font-size: 1.05rem; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s3); box-shadow: var(--shadow); animation: rise 0.22s ease both;
}
.qimg {
  display: block; max-width: 100%; max-height: 26dvh; margin: 0 auto var(--s2);
  border-radius: var(--r-sm); background: var(--img-mat); padding: var(--s1);
  border: 1px solid var(--line); cursor: zoom-in;
}
.qtext { font-size: 1.08rem; line-height: 1.4; font-weight: 600; margin-bottom: var(--s3); }

.options { display: grid; gap: var(--s2); }
.opt {
  position: relative;
  display: flex; gap: var(--s2); align-items: center; text-align: left;
  min-height: 56px; padding: var(--s2) var(--s5) var(--s2) var(--s2);
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--r);
  transition: transform 0.08s ease, border-color 0.12s ease;
  animation: rise 0.26s ease both;
}
.options .opt:nth-child(2) { animation-delay: 0.04s; }
.options .opt:nth-child(3) { animation-delay: 0.08s; }
.options .opt:nth-child(4) { animation-delay: 0.12s; }
.opt:active:not(:disabled) { transform: scale(0.98); border-color: var(--accent); }
.opt b {
  flex: 0 0 30px; height: 30px; display: grid; place-items: center;
  border-radius: 9px; background: var(--card); border: 1px solid var(--line);
  color: var(--muted); font-family: var(--mono); font-size: 0.9rem; font-weight: 700;
}
.opt span { flex: 1; line-height: 1.32; overflow-wrap: anywhere; }

.opt.correct { background: var(--good); border-color: var(--good); color: var(--good-ink); animation: pulse 0.4s ease; }
.opt.wrong { background: var(--bad); border-color: var(--bad); color: var(--bad-ink); animation: shake 0.32s ease; }
.opt.correct b, .opt.wrong b { background: rgba(255,255,255,0.22); border-color: transparent; color: inherit; }
.opt.correct::after, .opt.wrong::after {
  position: absolute; right: var(--s2); top: 50%; transform: translateY(-50%);
  font-size: 1.15rem; font-weight: 800;
}
.opt.correct::after { content: "✓"; }
.opt.wrong::after { content: "✗"; }

@keyframes pulse { 0%,100% { transform: scale(1); } 45% { transform: scale(1.035); } }
@keyframes shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.drill-foot { padding-top: var(--s3); }

/* ---------- summary ---------- */
.summary { text-align: center; padding-top: var(--s6); animation: rise 0.35s ease both; }
.summary h1 {
  font-family: var(--mono); font-size: 3.6rem; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.summary h1 span { font-size: 1.5rem; color: var(--muted); }
.summary .sub { color: var(--muted); margin: var(--s3) 0 var(--s4); font-size: 0.95rem; }
.summary .big { margin-bottom: var(--s2); }
.ghost.wide {
  width: 100%; min-height: 52px; border-radius: var(--r);
  color: var(--muted); font-weight: 600;
}

.misses { list-style: none; text-align: left; margin: 0 0 var(--s4); display: grid; gap: var(--s2); }
.misses li {
  display: flex; gap: var(--s2); background: var(--card);
  border: 1px solid var(--line); border-radius: var(--r); padding: var(--s2);
  box-shadow: var(--shadow);
}
.misses img { width: 60px; height: 60px; flex: 0 0 60px; object-fit: contain; background: var(--img-mat); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 3px; }
.misses .mq { font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; line-height: 1.35; }
.misses .you { color: var(--bad); font-size: 0.8rem; }
.misses .ans { color: var(--good); font-size: 0.8rem; margin-top: 2px; }

/* ---------- zoom + confetti ---------- */
#zoom {
  position: fixed; inset: 0; z-index: 40; background: rgba(3,6,14,0.9);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
  padding: var(--s4); animation: fade 0.15s ease both;
}
#zoom img { max-width: 96vw; max-height: 92vh; background: #fff; border-radius: var(--r); padding: var(--s1); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.confetti { position: fixed; inset: 0; z-index: 50; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute; top: -14px; left: var(--x);
  width: 9px; height: 13px; border-radius: 2px;
  background: hsl(var(--h) 85% 60%);
  animation: fall var(--d) linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(680deg); opacity: 0.5; } }

/* ---------- shared page header ---------- */
.page-head { display: flex; align-items: center; gap: var(--s2); padding: var(--s0) 0 var(--s4); }
.page-head h1 { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.01em; }
.page-head p { color: var(--muted); font-size: 0.85rem; }

/* ---------- topics + stats bars ---------- */
.topics { display: grid; gap: var(--s2); }
.topic-row {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: var(--s1) var(--s2);
  width: 100%; text-align: left; padding: var(--s2) var(--s3); min-height: 62px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow); transition: transform 0.08s ease, border-color 0.15s ease;
}
button.topic-row:active { transform: scale(0.99); border-color: var(--accent); }
.topic-row .tname { font-weight: 600; font-size: 0.92rem; }
.topic-row .frac { font-family: var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.topic-row .bar {
  grid-column: 1 / -1; height: 8px; border-radius: var(--r-pill);
  background: var(--raised);
  background: color-mix(in srgb, var(--raised) 70%, var(--bg)); overflow: hidden;
}
.topic-row .bar i {
  display: block; height: 100%; border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--good), #62e2a4);
  transition: width 0.5s cubic-bezier(0.22,1,0.36,1);
}

/* ---------- plan ---------- */
.plan { list-style: none; padding: 0; display: grid; gap: var(--s2); }
.plan li {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow); transition: opacity 0.2s ease;
}
.plan li.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 8px 24px -12px var(--accent); }
.plan li.done { opacity: 0.5; }
.plan label { display: flex; gap: var(--s2); padding: var(--s2) var(--s3); align-items: flex-start; cursor: pointer; }
.plan input { position: absolute; opacity: 0; width: 0; height: 0; }
.plan .check {
  flex: 0 0 26px; height: 26px; margin-top: 1px; border-radius: 9px;
  border: 2px solid var(--line); display: grid; place-items: center;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.plan input:checked + .check { background: var(--good); border-color: var(--good); transform: scale(1.02); }
.plan input:checked + .check::after { content: "✓"; color: var(--good-ink); font-size: 0.85rem; font-weight: 800; }
.plan input:focus-visible + .check { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.plan .daytag {
  display: block; font-family: var(--mono); font-size: 0.62rem; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent-text); margin-bottom: 2px;
}
.plan li:not(.today) .daytag { color: var(--muted); }
.plan b { font-size: 0.95rem; }
.plan p { color: var(--muted); font-size: 0.8rem; margin-top: var(--s0); line-height: 1.35; }
.plan li.done b, .plan li.done p { text-decoration: line-through; }

/* ---------- stats tiles ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); margin-bottom: var(--s4); }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: var(--s3) var(--s2); text-align: center; box-shadow: var(--shadow);
}
.tile b { display: block; font-family: var(--mono); font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.tile span { display: block; margin-top: 6px; color: var(--muted); font-size: 0.68rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }

/* ---------- learn ---------- */
.learn-note { color: var(--muted); font-size: 0.8rem; margin-top: 4px; line-height: 1.35; }
.lesson { display: grid; gap: 16px; }
.lesson-sec { background: var(--card); border: 1px solid var(--line); border-radius: var(--r, 12px); padding: 14px 16px; }
.lesson-sec h3 { font-size: 0.95rem; margin-bottom: 8px; }
.lesson-sec ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.lesson-sec li { font-size: 0.9rem; line-height: 1.4; }
.mnemonic { background: var(--raised); border-radius: var(--r, 12px); padding: 12px 14px; font-size: 0.9rem; }
.lesson-foot { padding-top: 16px; display: grid; gap: 10px; }
.lesson-foot .ghost.wide { min-height: 48px; border: 1px solid var(--line); border-radius: var(--r-lg, 16px); }
.fc-foot { display: flex; gap: 10px; padding-top: 14px; }
.fc-foot .big { flex: 1; }
.fc-foot .ghost.wide { flex: 1; min-height: 52px; border: 1px solid var(--line); border-radius: var(--r-lg, 16px); }
.fc-foot .ghost.wide:disabled { opacity: 0.4; }

/* ---------- lesson diagrams (fixed-colour on a light matte, readable in both themes) ---------- */
.diagram {
  margin: 10px 0 4px; padding: 10px; background: #f7f8fb;
  border: 1px solid var(--line); border-radius: var(--r3, 12px);
}
.diagram svg { display: block; width: 100%; height: auto; max-height: 40vh; }

/* tap-to-define glossary terms in lessons */
.term {
  font: inherit; color: inherit; background: none; border: 0; padding: 0;
  border-bottom: 1px dotted var(--accent); cursor: pointer; line-height: inherit;
}
.term:active { color: var(--accent); }
.term-def {
  display: block; margin: 6px 0 2px; padding: 8px 10px;
  background: var(--raised); border-left: 3px solid var(--accent);
  border-radius: 8px; font-size: 0.85rem; color: var(--muted);
}

/* glossary screen */
.gloss-filter {
  width: 100%; min-height: 44px; margin-bottom: 12px; padding: 10px 14px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r3, 12px); font: inherit;
}
.glossary { display: grid; gap: 8px; margin: 0; }
.gloss-row {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r3, 12px); padding: 10px 14px;
}
.gloss-row dt { font-weight: 700; font-size: 0.9rem; }
.gloss-row dd { margin: 4px 0 0; color: var(--muted); font-size: 0.85rem; line-height: 1.4; }
.gloss-entry { margin-bottom: 10px; }

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; animation-delay: 0s !important; transition-duration: 0.001s !important; }
}

.badge-en {
  font: 700 0.62rem var(--mono); color: var(--muted);
  border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 1px 6px; margin-left: var(--s1); vertical-align: 3px;
}
.home-head > div { display: flex; gap: var(--s1); }
#lang { font: 700 0.8rem var(--mono); }

.profile-new { display: flex; gap: var(--s2); margin-top: var(--s3); }
.profile-new input {
  flex: 1; min-width: 0; padding: var(--s2) var(--s3);
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  font: inherit;
}
.profile-new .big { width: auto; padding-inline: var(--s4); }

.opt.selected { border-color: var(--accent); background: var(--raised); }
.verdict { font: 800 1.5rem var(--sans); letter-spacing: 0.06em; }
.verdict.pass { color: var(--good); }
.verdict.fail { color: var(--bad); }
#profile { font-size: 0.85rem; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ready-chip {
  display: inline-block; margin-top: var(--s2); padding: 4px 12px;
  border-radius: var(--r-pill); font-weight: 700; font-size: 0.85rem;
}
.ready-chip.ready { background: var(--tint-good); color: var(--good); }
.ready-chip.close { background: rgba(255, 180, 84, 0.14); color: var(--accent-text); }
.ready-chip.not-yet { background: var(--raised); color: var(--muted); }
.ready-card { margin-bottom: var(--s3); }
.ready-card .sub { color: var(--muted); font-size: 0.85rem; margin-top: var(--s1); }

/* ---------- auth screens ---------- */
.auth-form { flex-direction: column; }
.auth-form input { width: 100%; }
.auth-form .big { width: 100%; padding-inline: var(--s4); }
.auth-err { color: var(--bad); font-size: 0.85rem; }
.auth-links { display: grid; gap: var(--s2); margin-top: var(--s3); }

/* ---------- course picker + lock screen ---------- */
.profile-new select {
  flex: 1; min-width: 0; padding: var(--s2) var(--s3);
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  font: inherit;
}
a.ghost, a.big { text-decoration: none; display: inline-grid; place-items: center; }
#prelang { margin-left: auto; }
