:root {
  --ink: #1f2933; --muted: #52606d; --paper: #fffdf7; --card: #ffffff;
  --brand: #e8590c; --brand-ink: #fff; --sky: #1971c2; --gold: #f59f00;
  --good: #2f9e44; --bad: #e03131; --shadow: 0 6px 20px rgba(31, 41, 51, .12);
  --r: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--paper); color: var(--ink);
  min-height: 100dvh; overscroll-behavior-y: none;
}
button { font: inherit; cursor: pointer; border: none; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: linear-gradient(135deg, #e8590c, #f08c00);
  color: #fff; box-shadow: var(--shadow);
}
#topbar .brand { font-weight: 800; font-size: 18px; letter-spacing: .3px; }
#topbar .chip {
  background: rgba(255,255,255,.22); padding: 6px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600; max-width: 40vw; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
#topbar .spacer { flex: 1; }
.iconbtn {
  background: rgba(255,255,255,.22); color: #fff; border-radius: 12px;
  width: 40px; height: 40px; font-size: 18px; display: grid; place-items: center;
}
.iconbtn:active { transform: scale(.94); }

#offlinebar {
  background: #fff3bf; color: #664d03; padding: 8px 14px; font-size: 13px;
  font-weight: 600; text-align: center;
}

/* ---------- home ---------- */
#home { max-width: 760px; margin: 0 auto; padding: 16px 14px 90px; }
.continue {
  background: var(--card); border-radius: var(--r); padding: 16px; margin-bottom: 18px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 14px; width: 100%;
  text-align: left;
}
.continue .thumb { width: 52px; height: 70px; object-fit: cover; border-radius: 8px;
  border: 2px solid #ffe8cc; background: #ffe8cc; }
.continue b { font-size: 16px; }
.continue small { color: var(--muted); display: block; margin-top: 3px; }
.unitgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 420px) { .unitgrid { grid-template-columns: 1fr; } }
.unitcard {
  background: var(--card); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow);
  border-top: 6px solid var(--brand);
}
.unitcard:nth-child(2) { border-top-color: var(--sky); }
.unitcard:nth-child(3) { border-top-color: var(--good); }
.unitcard:nth-child(4) { border-top-color: #9c36b5; }
.unitcard h3 { margin: 2px 0 10px; font-size: 17px; }
.pagechips { display: flex; flex-wrap: wrap; gap: 7px; }
.pchip {
  background: #f1f3f5; border-radius: 10px; padding: 7px 9px; font-size: 12.5px;
  font-weight: 600; color: var(--ink); position: relative;
}
.pchip.practice { background: #fff4e6; }
.pchip .best { position: absolute; top: -7px; right: -5px; font-size: 10px;
  background: var(--gold); color: #fff; border-radius: 8px; padding: 1px 5px; }
.extras { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.extras button {
  background: #e9ecef; color: var(--ink); padding: 9px 14px; border-radius: 12px;
  font-weight: 600; font-size: 13.5px;
}
.footlinks { margin-top: 22px; text-align: center; color: var(--muted); font-size: 13px; }
.footlinks a { color: var(--sky); font-weight: 600; text-decoration: none; }
.madeby { margin-top: 14px; text-align: center; color: #b8b2a7; font-size: 12.5px; letter-spacing: .02em; }
.madeby b { color: #8a8577; }

/* ---------- reader ---------- */
#reader { padding: 12px 10px 150px; max-width: 720px; margin: 0 auto; }
.pagetitle { display: flex; align-items: baseline; gap: 8px; margin: 2px 4px 10px; }
.pagetitle h2 { font-size: 17px; margin: 0; }
.pagetitle small { color: var(--muted); }
#stage { position: relative; border-radius: 14px; overflow: hidden;
  box-shadow: var(--shadow); background: #fff; }
#stage img.pageimg { display: block; width: 100%; height: auto; }
.tappable {
  position: absolute; border-radius: 8px; cursor: pointer;
}
.tappable:active { background: rgba(25, 113, 194, .18); }
.tappable.speaking {
  outline: 3px solid var(--gold); background: rgba(245, 159, 0, .28);
  animation: pulse 1s infinite alternate;
}
@keyframes pulse { from { background: rgba(245,159,0,.18);} to { background: rgba(245,159,0,.4);} }

/* text panel */
#textpanel {
  background: var(--card); border-radius: var(--r); margin-top: 14px;
  box-shadow: var(--shadow); padding: 6px 16px;
}
#textpanel header {
  display: flex; align-items: center; gap: 8px; padding: 10px 0 6px;
}
#textpanel header b { font-size: 15px; }
#textpanel header .spacer { flex: 1; }
#textpanel header button {
  background: #f1f3f5; border-radius: 10px; padding: 6px 10px; font-weight: 700;
  font-size: 13px; color: var(--ink);
}
#blocks { transition: max-height .3s; overflow: hidden; }
#blocks.open { max-height: 60vh; overflow-y: auto; padding-bottom: 12px; }
.blockrow {
  padding: 10px 8px; border-radius: 10px; font-size: var(--readsize, 18px);
  line-height: 1.55; display: flex; gap: 10px; align-items: flex-start;
}
.blockrow .num { color: var(--brand); font-weight: 800; font-size: .8em; min-width: 22px;
  padding-top: .25em; }
.blockrow:active, .blockrow.speaking { background: #fff4e6; }
.blockrow.speaking { outline: 2px solid var(--gold); }

/* ---------- control dock ---------- */
#dock {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: #fffdf7ee; backdrop-filter: blur(8px);
  border-top: 1px solid #ffe8cc; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 10px; justify-content: center; align-items: center;
}
#dock button { border-radius: 14px; font-weight: 700; }
.navbtn { background: #f1f3f5; color: var(--ink); padding: 13px 16px; font-size: 16px; }
.listenbtn { background: var(--sky); color: #fff; padding: 13px 18px; font-size: 15px; }
.listenbtn.playing { filter: brightness(.9) saturate(1.25); box-shadow: inset 0 0 0 2px rgba(255,255,255,.45); }
.speedbtn { background: #e7f5ff; color: var(--sky); padding: 13px 12px; font-size: 14px; }
.micbtn {
  background: linear-gradient(135deg, #e03131, #e8590c); color: #fff;
  padding: 14px 22px; font-size: 16px; box-shadow: 0 6px 16px rgba(224,49,49,.35);
}
.micbtn:disabled { background: #ced4da; box-shadow: none; }
#dock .pgnum { position: absolute; left: 14px; top: -26px; background: var(--ink);
  color: #fff; border-radius: 10px; padding: 3px 10px; font-size: 12px; font-weight: 700; }

/* ---------- modals ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(31,41,51,.55); z-index: 50;
  display: grid; place-items: center; padding: 18px;
}
.sheet {
  background: var(--card); border-radius: 22px; padding: 22px 20px; width: min(430px, 94vw);
  max-height: 88dvh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.sheet h3 { margin: 0 0 6px; font-size: 20px; }
.sheet p.sub { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.bigbtn {
  width: 100%; padding: 15px; border-radius: 15px; font-size: 17px; font-weight: 800;
  margin-top: 10px;
}
.bigbtn.primary { background: var(--brand); color: #fff; }
.bigbtn.blue { background: var(--sky); color: #fff; }
.bigbtn.ghost { background: #f1f3f5; color: var(--ink); }
.rowbtns { display: flex; gap: 10px; }
.rowbtns .bigbtn { flex: 1; }

/* record modal */
#recstate { text-align: center; font-size: 15px; margin: 8px 0 2px; font-weight: 700; }
#rectimer { text-align: center; font-size: 30px; font-weight: 800; letter-spacing: 2px;
  margin: 4px 0 10px; font-variant-numeric: tabular-nums; }
.recdot { display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  background: var(--bad); margin-right: 6px; animation: pulse 0.9s infinite alternate; }
#recpage { color: var(--muted); font-size: 13.5px; text-align: center; }

/* result modal */
.bandbox {
  background: linear-gradient(135deg, #fff4e6, #ffe8cc); border-radius: 16px;
  padding: 14px; text-align: center; margin: 8px 0 12px;
}
.bandbox .band { font-size: 19px; font-weight: 800; color: #d9480f; }
.bandbox .note { color: #846359; font-size: 13.5px; margin-top: 4px; }
.starrows { display: grid; gap: 9px; margin: 4px 0 6px; }
.starrow { display: flex; align-items: center; gap: 10px; background: #f8f9fa;
  border-radius: 12px; padding: 9px 12px; }
.starrow .lbl { flex: 1; font-weight: 700; font-size: 14.5px; }
.starrow .stars { font-size: 19px; letter-spacing: 2px; color: var(--gold); }
.missed { margin-top: 10px; }
.missed b { font-size: 14px; }
.missed .words { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.missed .w { background: #ffe3e3; color: #c92a2a; border-radius: 9px; padding: 5px 9px;
  font-size: 13px; font-weight: 600; }
.scorewait { text-align: center; padding: 18px 0; }
.scorewait .spin { font-size: 40px; animation: spin 1.1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.scorewait .eta { color: var(--muted); font-size: 13.5px; margin-top: 8px; }

/* student picker */
.stuchips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 12px; }
.stuchips button {
  background: #e7f5ff; color: var(--sky); border-radius: 12px; padding: 10px 14px;
  font-weight: 700; font-size: 15px;
}
.stuchips button.me { background: var(--sky); color: #fff; }
.addname { display: flex; gap: 8px; }
.addname input {
  flex: 1; border: 2px solid #dee2e6; border-radius: 12px; padding: 11px 12px;
  font-size: 16px; font-family: inherit;
}
.addname input:focus { outline: none; border-color: var(--sky); }

/* install guide */
.steps { counter-reset: s; }
.steps li { margin: 10px 0; padding-left: 6px; list-style: none; position: relative; }
.steps li::before {
  counter-increment: s; content: counter(s);
  position: absolute; left: -34px; top: 0; width: 26px; height: 26px;
  background: var(--brand); color: #fff; border-radius: 50%; display: grid;
  place-items: center; font-weight: 800; font-size: 14px;
}
.steps { padding-left: 40px; margin: 12px 0; }
.steps b { display: block; }
.steps small { color: var(--muted); }

/* teacher */
#teacher { max-width: 1000px; margin: 0 auto; padding: 18px 14px 60px; }
#teacher h1 { font-size: 22px; }
#teacher .tools { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
#teacher .tools button, #teacher .tools select {
  background: var(--sky); color: #fff; border-radius: 12px; padding: 10px 14px;
  font-weight: 700; border: none; font-size: 14px;
}
#teacher .tools select { background: #e7f5ff; color: var(--sky); }
table.attempts { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.attempts th, table.attempts td { padding: 8px 8px; border-bottom: 1px solid #e9ecef;
  text-align: left; vertical-align: top; }
table.attempts tr:nth-child(even) { background: #f8f9fa; }
.bandid { font-weight: 800; color: #d9480f; white-space: nowrap; }
audio { width: 190px; height: 34px; }
.qrbox { background: #f8f9fa; border-radius: 14px; padding: 14px; display: flex;
  gap: 16px; align-items: center; margin: 12px 0; flex-wrap: wrap; }
.qrbox img, .qrbox svg { width: 150px; height: 150px; background: #fff; padding: 8px;
  border-radius: 10px; }
.qrbox code { background: #e9ecef; padding: 4px 8px; border-radius: 8px; font-size: 14px; }

/* ---------- hero & quote ---------- */
.hero {
  background: linear-gradient(135deg, #fff4e6, #ffe8cc 60%, #fff0e0);
  border-radius: 22px; padding: 22px 18px 16px; margin-bottom: 18px;
  box-shadow: var(--shadow); text-align: center;
}
.hero .hero-emoji { font-size: 32px; letter-spacing: 8px; }
.hero h1 { margin: 8px 0 6px; font-size: 24px; letter-spacing: -.2px; }
.hero .hero-sub { color: var(--muted); font-size: 14.5px; line-height: 1.55;
  margin: 0 auto 14px; max-width: 540px; }
.quote-card {
  background: #fff; border-radius: 16px; padding: 16px 18px 14px;
  box-shadow: 0 4px 14px rgba(232, 89, 12, .12); position: relative; text-align: left;
}
.quote-card .qmark {
  position: absolute; top: 2px; left: 10px; font-size: 40px; line-height: 1;
  color: #ffd8a8; font-family: Georgia, "Times New Roman", serif;
}
.quote-card p { margin: 6px 0 6px 24px; font-size: 15.5px; font-weight: 600;
  font-style: italic; line-height: 1.5; }
.quote-card small { margin-left: 24px; color: var(--muted); font-weight: 700; }
.quote-card .shuffle {
  position: absolute; right: 10px; bottom: 10px; background: #fff4e6;
  border-radius: 10px; padding: 6px 10px; font-size: 14px;
}
.quote-card .shuffle:active { transform: scale(.92); }
.madewith { margin-top: 12px; font-size: 13.5px; font-weight: 800; color: #c2410c; letter-spacing: .02em; }

/* ---------- welcome gate ---------- */
.welcome { text-align: center; }
.wc-logo { font-size: 44px; margin-bottom: 2px; }
#wc-name {
  width: 100%; border: 2px solid #dee2e6; border-radius: 12px;
  padding: 12px 14px; font-size: 16px; font-family: inherit; margin-top: 2px;
}
#wc-name:focus { outline: none; border-color: var(--brand); }
.wc-label { margin: 14px 0 8px; font-weight: 700; font-size: 14px; color: var(--muted); text-align: left; }
.wc-grades { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.wc-grades button {
  background: #f1f3f5; border: 3px solid transparent; border-radius: 14px; padding: 12px 8px;
}
.wc-grades button b { font-size: 17px; display: block; }
.wc-grades button small { color: var(--muted); }
.wc-grades button.sel { border-color: var(--brand); background: #fff4e6; }
.wc-skip {
  margin-top: 12px; background: none; color: var(--muted);
  font-size: 12.5px; text-decoration: underline;
}

/* install button glow when one-tap install is available */
.iconbtn.ready {
  background: #fff; color: var(--brand);
  animation: glowpulse 1.2s infinite alternate;
}
@keyframes glowpulse {
  from { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
  to   { box-shadow: 0 0 14px 5px rgba(255, 255, 255, .7); }
}
