:root {
  --bg: #f5f3ef;
  --card: #ffffff;
  --ink: #1d232b;
  --muted: #5f6b78;
  --line: #e1ddd5;
  --brand: #1f3a5f;
  --brand-ink: #ffffff;
  --read: #2f6fb3;
  --read-bg: #e3eefa;
  --cue: #8a5a00;
  --cue-bg: #fbefd6;
  --cover: #6b3fa0;
  --cover-bg: #efe6fa;
  --ok: #1f7a4a;
  --ok-bg: #e2f4ea;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  --rec: #d93025;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 14px rgba(0, 0, 0, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161b;
    --card: #1b2128;
    --ink: #e8ebee;
    --muted: #9aa5b1;
    --line: #2c343d;
    --brand: #7fb0e8;
    --brand-ink: #0d1a2a;
    --read: #8cbcf0;
    --read-bg: #1d2f45;
    --cue: #f0c46a;
    --cue-bg: #3a2e14;
    --cover: #c4a4ef;
    --cover-bg: #2e2342;
    --ok: #6fd39c;
    --ok-bg: #173527;
    --bad: #ff8a80;
    --bad-bg: #42201d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom));
}

h1, h2, h3 { line-height: 1.25; margin: 0; }
h1:focus { outline: none; }
h1 { font-size: 1.1rem; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; display: flex; align-items: center; gap: 8px; }
p { margin: 0; }

.bar {
  display: grid;
  grid-template-columns: minmax(70px, auto) 1fr minmax(70px, auto);
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.bar > :last-child { justify-self: end; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.spread { justify-content: space-between; }
.grow { flex: 1; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.lede { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.9rem; }
.notice { background: var(--bad-bg); color: var(--bad); padding: 10px 14px; border-radius: 10px; }
.countdown { color: var(--muted); }
.countdown strong { color: var(--ink); }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.95rem; }
.field.inline { flex-direction: row; flex-wrap: wrap; align-items: center; font-weight: 500; }
input, textarea, select {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  font-weight: 400;
}
.field.inline input, .field.inline select { width: auto; min-width: 4.5em; }
textarea.drop { outline: 3px dashed var(--brand); outline-offset: 2px; }
textarea { resize: vertical; min-height: 200px; line-height: 1.55; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 1px; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
  touch-action: manipulation;
}
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 650; }
button.big { padding: 16px 20px; font-size: 1.05rem; border-radius: var(--radius); }
button.ghost { background: transparent; border-color: transparent; color: var(--brand); font-weight: 600; padding-inline: 8px; }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad-bg); }
button.small { min-height: 34px; padding: 4px 12px; font-size: 0.9rem; }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 6px 14px;
  min-height: 40px;
  font-size: 0.92rem;
  font-weight: 600;
  border: 2px solid transparent;
}
span.chip { min-height: 0; padding: 2px 10px; font-size: 0.8rem; }
.mode-read { background: var(--read-bg); color: var(--read); }
.mode-cue { background: var(--cue-bg); color: var(--cue); }
.mode-cover { background: var(--cover-bg); color: var(--cover); }
.chip.done { opacity: 0.6; }
.chip.next { border-color: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent); }
.chip.selected { border-color: var(--ink); opacity: 1; }
.chip.on { border-color: currentColor; }
.chip.add { background: transparent; border: 2px dashed var(--line); color: var(--muted); }
.chip .miss { background: var(--bad); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 0.75rem; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 0.82rem; color: var(--muted); }

.today { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); }
.expect { font-size: 1.05rem; }
.progress { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--ok); transition: width 0.3s; }
.done-all { font-weight: 650; color: var(--ok); }

.day { padding: 12px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.day.is-past { opacity: 0.6; }
.tag { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; background: var(--brand); color: var(--brand-ink); padding: 2px 8px; border-radius: 999px; }
.tag.present { background: var(--rec); color: #fff; }

.toolbar { display: flex; flex-direction: column; gap: 10px; background: var(--bg); }

.trouble { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.trouble li { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.trouble .miss { color: var(--bad); font-size: 0.85rem; font-weight: 600; }
.secno { color: var(--muted); font-weight: 700; font-size: 0.8rem; font-variant-numeric: tabular-nums; }

/* Run screen */
.instruction { font-weight: 600; }
.speech { display: flex; flex-direction: column; gap: 14px; font-size: 1.15rem; line-height: 1.65; }
.sec.cue { font-weight: 600; }
.sec.covered { display: flex; align-items: center; gap: 10px; background: var(--cover-bg); border-radius: 10px; padding: 10px 12px; min-height: 52px; }
.sec.covered .blank { flex: 1; color: var(--muted); font-size: 0.9rem; letter-spacing: 0.02em; }
.sec.covered.peeked { background: var(--bad-bg); }
.drill { border-color: var(--bad); background: color-mix(in srgb, var(--bad-bg) 55%, var(--card)); }
.drill-item { display: flex; gap: 12px; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 10px; }
.drill-item p { flex: 1; font-size: 1.05rem; }
.drill-item.complete p { opacity: 0.55; }
.counter { min-width: 72px; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--card); }
.drill-item.complete .counter { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.spacer { height: 110px; }

.recbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  max-width: 720px;
  margin: 0 auto;
  z-index: 10;
}
.rec {
  width: 72px;
  height: 72px;
  min-width: 72px;
  border-radius: 50%;
  border: 4px solid var(--line);
  background: var(--card);
  padding: 0;
  display: grid;
  place-items: center;
}
.rec .dot { width: 34px; height: 34px; border-radius: 50%; background: var(--rec); transition: all 0.2s; }
.rec.on { border-color: var(--rec); }
.rec.on .dot { width: 26px; height: 26px; border-radius: 6px; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
.recinfo { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.recinfo strong { font-variant-numeric: tabular-nums; }
.live { color: var(--muted); font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Review */
audio { width: 100%; }
.marks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.mark {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  border-radius: 12px;
  border-width: 2px;
}
.mark.ok { background: var(--ok-bg); border-color: transparent; }
.mark.missed { background: var(--bad-bg); border-color: var(--bad); }
.mark .mstate { font-size: 0.82rem; font-weight: 700; white-space: nowrap; }
.mark.ok .mstate { color: var(--ok); }
.mark.missed .mstate { color: var(--bad); }
.mtext { overflow: hidden; text-overflow: ellipsis; }
.transcript { color: var(--muted); font-size: 0.92rem; margin-top: 8px; }
details summary { cursor: pointer; color: var(--brand); font-weight: 600; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  width: max-content;
  max-width: calc(100vw - 32px);
  text-align: center;
  z-index: 20;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
