:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eaeef3;
  --text: #16202c;
  --muted: #5b6b7c;
  --line: #d9dee6;
  /* Brand (NextStripe): navy is the main color, amber a sparing accent for "next" and "due" moments only.
     Amber is a fill with --amber-ink on it, never text on a light background. */
  --navy: #1f3a5f;
  --navy-ink: #ffffff;
  --amber: #f4a51c;
  --amber-ink: #16202c;
  --accent: var(--navy);
  --accent-ink: var(--navy-ink);
  --panel: #1f3a5f;          /* the Today panel: the logo's navy here, a deep navy in dark mode */
  --panel-ink: #ffffff;
  --panel-muted: #b9c8db;
  --good: #1d7a4c;
  --good-bg: #e2f4ea;
  --bad: #b3361f;
  --bad-bg: #fbe7e2;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 2px 10px rgba(16,24,40,.04);
  --tabbar-h: 62px;
  --player-h: 0px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f151c; --surface: #18212b; --surface-2: #222d3a; --text: #e8edf3; --muted: #97a6b6;
    --line: #2b3746;
    --navy: #7fb0e8; --navy-ink: #0b1420; --amber: #ffbe4d; --amber-ink: #1a1405;
    --panel: #1b304c; --panel-ink: #f2f6fb; --panel-muted: #a3b6cd;
    --good: #5ed095; --good-bg: #163526; --bad: #ff9b83; --bad-bg: #3d1c15;
    --shadow: 0 1px 2px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --bg: #0f151c; --surface: #18212b; --surface-2: #222d3a; --text: #e8edf3; --muted: #97a6b6;
  --line: #2b3746;
  --navy: #7fb0e8; --navy-ink: #0b1420; --amber: #ffbe4d; --amber-ink: #1a1405;
  --panel: #1b304c; --panel-ink: #f2f6fb; --panel-muted: #a3b6cd;
  --good: #5ed095; --good-bg: #163526; --bad: #ff9b83; --bad-bg: #3d1c15;
  --shadow: 0 1px 2px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + var(--player-h) + var(--safe-b) + 20px);
}
body.bare { padding-bottom: calc(var(--player-h) + var(--safe-b) + 20px); }
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2.5px solid var(--navy); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand img { display: block; }
.wordmark { font-weight: 700; font-size: 19px; letter-spacing: -0.01em; color: var(--navy); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .wordmark { color: var(--text); } }
:root[data-theme="dark"] .wordmark { color: var(--text); }
.account {
  width: 36px; height: 36px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--surface);
  font-weight: 700; font-size: 14px; color: var(--navy); display: grid; place-items: center; padding: 0;
}

/* ---------- page ---------- */
.view { max-width: 640px; margin: 0 auto; padding: 8px 16px 16px; }
h1 { font-size: 28px; line-height: 1.15; letter-spacing: -0.015em; margin: 6px 0 6px; }
h2 { font-size: 17px; line-height: 1.3; margin: 26px 0 10px; }
.sub { color: var(--muted); margin: 0 0 16px; }
.small { font-size: 14px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: 15px; font-weight: 600; margin: 4px 0 2px; }
.back svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.kicker { color: var(--muted); font-size: 14px; font-weight: 600; margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.center { text-align: center; }
.mt { margin-top: 16px; }
.kbd { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }

/* ---------- Today ---------- */
.due-panel {
  position: relative; overflow: hidden; isolation: isolate;
  background: var(--panel); color: var(--panel-ink); border-radius: 22px;
  padding: 22px 20px 20px; margin: 10px 0 14px;
}
/* the logo's rising stripes beside the count: the next stripe up is the amber one */
.due-panel .stripes { position: absolute; right: 22px; top: 46px; width: 84px; height: 84px; z-index: -1; }
.due-panel .stripes .top-stripe { fill: var(--amber); }
.due-panel .stripes .lower { fill: rgba(255,255,255,.16); }
.due-label { font-size: 15px; color: var(--panel-muted); font-weight: 600; margin: 0; }
.due-num { font-size: 76px; line-height: 1; font-weight: 800; letter-spacing: -0.04em; margin: 6px 0 2px; }
.due-num.has-due { color: var(--amber); }
.due-note { color: var(--panel-muted); margin: 0 0 18px; font-size: 15px; }
.due-panel .btn { width: 100%; }
.today-tip { color: var(--muted); font-size: 14px; margin: 0 4px; }
.streak { display: flex; align-items: center; gap: 12px; margin: 0 0 12px; }
.streak-num { flex: none; min-width: 48px; height: 48px; padding: 0 8px; border-radius: 14px; background: var(--surface-2); display: grid; place-items: center; font-weight: 800; font-size: 22px; letter-spacing: -0.02em; color: var(--navy); }
.streak.today .streak-num { background: var(--good-bg); color: var(--good); }
.streak .t { font-weight: 700; }
.streak .d { font-size: 14px; color: var(--muted); }
.continue { margin: 0 0 12px; }
.continue .row { margin: 6px 0 10px; }
.continue .t { font-weight: 700; line-height: 1.3; }
.continue .d { font-size: 14px; color: var(--muted); }
.continue .btn { flex: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 13px 18px; min-height: 48px;
  font-weight: 700; text-decoration: none; background: var(--navy); color: var(--navy-ink);
}
.btn.next { background: var(--amber); color: var(--amber-ink); }
.btn.on-panel { background: rgba(255,255,255,.14); color: var(--panel-ink); }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.ghost { background: transparent; color: var(--muted); padding-left: 8px; padding-right: 8px; }
.btn.danger { background: var(--bad); color: var(--surface); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:active:not(:disabled) { transform: translateY(1px); }

/* ---------- Orders ---------- */
.order-link { display: flex; gap: 14px; text-decoration: none; align-items: flex-start; }
.order-no {
  flex: none; width: 54px; height: 54px; border-radius: 14px; background: var(--surface-2);
  display: grid; place-items: center; font-weight: 800; font-size: 18px; letter-spacing: -0.02em; color: var(--navy);
}
.order-title { font-weight: 700; font-size: 17px; line-height: 1.3; margin: 0 0 8px; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 14px; color: var(--muted); align-items: center; }

.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--navy); border-radius: 99px; transition: width .3s; }
.bar.good > i { background: var(--good); }

.pill { display: inline-block; font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill.due { background: var(--amber); color: var(--amber-ink); }
.pill.good { background: var(--good-bg); color: var(--good); }

.segmented { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 13px; margin: 16px 0 14px; }
.segmented a { flex: 1; text-align: center; text-decoration: none; padding: 9px; border-radius: 10px; font-weight: 700; color: var(--muted); }
.segmented a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.chapter { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.chapter:last-child { border-bottom: 0; padding-bottom: 2px; }
.chapter:first-child { padding-top: 2px; }
.chapter .num { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-size: 14px; font-weight: 700; flex: none; }
.chapter.done .num { background: var(--good-bg); color: var(--good); }
.chapter.playing .num { background: var(--navy); color: var(--navy-ink); }
.chapter .t { font-weight: 600; line-height: 1.3; }
.chapter .d { font-size: 14px; color: var(--muted); }
.chapter button.play { border: 1.5px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 14px; font-weight: 700; font-size: 14px; flex: none; }
.chapter.playing button.play { border-color: var(--navy); color: var(--navy); }
/* a long Order's Parts: each heads its own Chapters */
.part + .part { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.part-head { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 4px; font-size: 13px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.part-head .d { font-weight: 600; letter-spacing: 0; text-transform: none; }
/* Orders that share an Episode */
.shared-episode { font-size: 14px; color: var(--muted); margin: 0 4px 12px; }
.shared-episode a { color: var(--accent); font-weight: 600; text-underline-offset: 2px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.stat b { display: block; font-size: 22px; line-height: 1.15; letter-spacing: -0.02em; }
.stat span { font-size: 13px; color: var(--muted); }
.boxes { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 8px; }
.box { text-align: center; padding: 7px 2px; border-radius: 9px; background: var(--surface-2); }
.box b { display: block; font-size: 17px; }
.box span { font-size: 12px; color: var(--muted); }
.actions { display: grid; gap: 8px; margin-top: 14px; }
.note { font-size: 14px; color: var(--muted); margin: 4px 4px 0; }

/* ---------- Drill ---------- */
.drill-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; color: var(--muted); font-weight: 600; margin: 4px 0 8px; }
.q { font-size: 19px; font-weight: 650; line-height: 1.38; margin: 0 0 14px; }
.choices { display: grid; gap: 8px; }
.choice {
  text-align: left; border: 1.5px solid var(--line); background: var(--surface); border-radius: 13px;
  padding: 12px 14px; display: flex; gap: 12px; align-items: flex-start; line-height: 1.4; min-height: 48px;
}
.choice .k { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.choice:not(:disabled):hover { border-color: var(--navy); }
.choice.correct { border-color: var(--good); background: var(--good-bg); }
.choice.correct .k { background: var(--good); color: var(--surface); }
.choice.wrong { border-color: var(--bad); background: var(--bad-bg); }
.choice.wrong .k { background: var(--bad); color: var(--surface); }
.choice:disabled { cursor: default; color: var(--text); }
.feedback { margin-top: 14px; padding: 12px 14px; border-radius: 13px; background: var(--surface-2); }
.feedback.ok { background: var(--good-bg); }
.feedback.no { background: var(--bad-bg); }
.feedback b { display: block; margin-bottom: 4px; }
.cite { font-size: 14px; color: var(--muted); margin-top: 8px; }
.cite strong { color: var(--text); font-weight: 600; }
/* the link to an Order's official text in PowerDMS (app/powerdms.js) */
.powerdms { color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.powerdms::after { content: "\2197"; text-decoration: none; display: inline-block; margin-left: 4px; }
.cite .powerdms { display: inline-block; margin-top: 4px; }
.official { margin: -8px 0 16px; font-size: 15px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.drill-foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.drill-foot .btn:last-child { margin-left: auto; min-width: 120px; }

.results { text-align: center; padding: 28px 18px 20px; }
.results .score { font-size: 72px; line-height: 1; font-weight: 800; letter-spacing: -0.04em; margin: 10px 0 8px; color: var(--navy); }
.results .actions { max-width: 320px; margin: 18px auto 0; }

/* ---------- Progress ---------- */
.progress-order h2 { margin: 0 0 12px; }
.meter { margin: 0 0 12px; }
.meter .facts { justify-content: space-between; margin-bottom: 6px; }
.recent { list-style: none; margin: 10px 0 0; padding: 0; }
.recent li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.recent li span:first-child { color: var(--muted); }

/* ---------- Admin ---------- */
.field { flex: 1; min-width: 180px; padding: 11px 12px; border: 1.5px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--text); font: inherit; min-height: 48px; }
.person { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person .t { font-weight: 600; overflow-wrap: anywhere; }
.person .d { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.person button { border: 1.5px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 14px; font-weight: 700; font-size: 14px; flex: none; }
.person .acts { display: flex; gap: 6px; flex: none; }
.person .quote { font-size: 14px; margin-top: 4px; overflow-wrap: anywhere; }
/* ---------- asking for an Invite ---------- */
textarea.field { width: 100%; min-height: 72px; resize: vertical; }
.ask-link { display: block; text-align: center; margin: 18px 4px 0; font-size: 14px; color: var(--muted); }

/* ---------- following an Invite link ---------- */
.label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
.wide-field { width: 100%; }
.field[readonly] { background: var(--surface-2); color: var(--muted); }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
.invite .btn.wide { margin-top: 14px; }

/* ---------- player, docked above the tabs ---------- */
.player {
  position: fixed; left: 0; right: 0; z-index: 10;
  bottom: calc(var(--tabbar-h) + var(--safe-b));
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 8px 14px 6px;
}
body.bare .player { bottom: 0; padding-bottom: calc(6px + var(--safe-b)); }
.player-top, .player-row { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 8px; }
.player-meta { flex: 1; min-width: 0; }
.player-title { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; position: relative; flex: none; padding: 0; }
.icon svg { width: 24px; height: 24px; fill: currentColor; }
.icon span { position: absolute; font-size: 8px; font-weight: 800; top: 50%; left: 50%; transform: translate(-50%, -32%); }
.icon.big { width: 44px; height: 44px; background: var(--navy); color: var(--navy-ink); }
.player-row { margin-top: 2px; }
.player-row input { flex: 1; min-width: 0; margin: 0; accent-color: var(--navy); height: 22px; }
.time { font-size: 12px; color: var(--muted); min-width: 34px; }
.time:first-child { text-align: right; }
.speed { border: 1.5px solid var(--line); background: transparent; border-radius: 8px; padding: 2px 7px; font-size: 12px; font-weight: 700; flex: none; }

/* ---------- bottom tabs ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600; position: relative;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--navy); }
/* the count of Invites waiting for an Admin, on the Admin tab: an amber "due" moment */
.tab-badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--amber); color: var(--amber-ink); font-size: 11px; font-weight: 800; line-height: 18px; text-align: center; }
.tab-badge[hidden] { display: none; }
.tabbar a[aria-current="page"]::before { content: ""; position: absolute; top: -1px; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--navy); }

/* ---------- in-app dialogs (bottom sheet on phones) ---------- */
.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 85vh;
  background: var(--surface); color: var(--text); border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 40px rgba(0,0,0,.25);
}
.sheet::backdrop { background: rgba(10, 18, 30, .45); }
.sheet[open] { animation: sheet-up .22s ease-out; }
@keyframes sheet-up { from { transform: translateY(24px); } to { transform: none; } }
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet-body { padding: 20px 18px calc(18px + var(--safe-b)); }
.sheet-body h2 { margin: 0 0 6px; font-size: 20px; }
.sheet-body p { margin: 0 0 16px; color: var(--muted); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.picks { display: grid; gap: 6px; margin: 0 0 14px; max-height: 58vh; overflow: auto; }
.pick { display: flex; align-items: center; gap: 12px; text-align: left; border: 1.5px solid var(--line); background: var(--surface); border-radius: 13px; padding: 10px 12px; min-height: 52px; }
.pick:disabled { opacity: .5; cursor: default; }
.pick .num { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-size: 14px; font-weight: 700; }
.pick .t { font-weight: 600; line-height: 1.3; }
.pick .d { font-size: 13px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(var(--tabbar-h) + var(--player-h) + var(--safe-b) + 12px);
  background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px);
}
body.bare .toast { bottom: calc(var(--player-h) + var(--safe-b) + 12px); }
.toast.show { opacity: 1; }

/* the disclaimer: before first use, and under About */
.disclaimer h1 { margin-top: 0; }
.disclaimer-text { line-height: 1.55; margin: 0 0 16px; }
.disclaimer-text strong { display: block; margin-bottom: 8px; }
.disclaimer-text:last-child { margin-bottom: 0; }
.disclaimer h1 + .disclaimer-text { margin-top: 12px; }

/* Admin analytics */
.analytics-stats { margin-bottom: 4px; }
.analytics-stats .stat b { font-size: 19px; }
.analytics-stats .stat span { display: block; line-height: 1.3; margin-top: 2px; }
@media (max-width: 380px) { .analytics-stats { grid-template-columns: repeat(2, 1fr); } }
.trend-chart { display: flex; align-items: flex-end; gap: 2px; height: 120px; margin: 12px 0 4px; border-bottom: 1px solid var(--line); }
.trend-col { flex: 1; height: 100%; display: flex; align-items: flex-end; min-width: 0; }
.trend-col i { display: block; width: 100%; background: var(--navy); border-radius: 4px 4px 0 0; }
.trend-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.trend-list li span:first-child { flex: none; min-width: 7.5em; }
.trend-list li span:last-child { text-align: right; }
.trend-list small { font-size: 12px; }
.person-link { color: inherit; text-decoration: none; }
.person-link .chev { flex: none; font-size: 22px; color: var(--muted); line-height: 1; }
