/* ── Tokens ─────────────────────────────────────────────────────────────
   Duolingo's own system colours. Light palette lives on bare :root so the
   un-stamped (system-default) document always resolves.                  */
:root {
  --green:        #58CC02;
  --green-edge:   #46A302;
  --blue:         #1CB0F6;
  --blue-edge:    #1478B8;
  --gold:         #FFC800;
  --gold-edge:    #E5A100;
  --red:          #FF4B4B;

  --bg:           #FFFFFF;
  --surface:      #FFFFFF;
  --surface-2:    #F7F9F8;
  --ink:          #22333B;
  --ink-2:        #5C7178;
  --ink-3:        #91A5AC;
  --line:         #E3E9E8;
  --line-strong:  #CFD9D8;

  --new-bg:       #FFF6D6;
  --new-line:     #F0C000;

  --radius:       16px;
  --edge:         4px;
  --story:        38rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #131F24;
    --surface:     #1B2B32;
    --surface-2:   #16242A;
    --ink:         #E8F0EF;
    --ink-2:       #A4B8BE;
    --ink-3:       #6E858C;
    --line:        #27383F;
    --line-strong: #354A52;
    --new-bg:      #33290A;
    --new-line:    #C9A400;
    --green:       #61D004;
    --blue:        #38BDFF;
  }
}

:root[data-theme="dark"] {
  --bg:          #131F24;
  --surface:     #1B2B32;
  --surface-2:   #16242A;
  --ink:         #E8F0EF;
  --ink-2:       #A4B8BE;
  --ink-3:       #6E858C;
  --line:        #27383F;
  --line-strong: #354A52;
  --new-bg:      #33290A;
  --new-line:    #C9A400;
  --green:       #61D004;
  --blue:        #38BDFF;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Nunito, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ── Shared chrome ───────────────────────────────────────────────────── */
.wrap { max-width: var(--story); margin: 0 auto; padding: 0 20px; }

.btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  font: 800 15px/1 Nunito, sans-serif;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 15px 22px;
  color: #fff;
  background: var(--green);
  box-shadow: 0 var(--edge) 0 var(--green-edge);
  cursor: pointer;
  transition: transform .06s, box-shadow .06s;
}
.btn:active { transform: translateY(var(--edge)); box-shadow: 0 0 0 var(--green-edge); }
.btn.blue { background: var(--blue); box-shadow: 0 var(--edge) 0 var(--blue-edge); }
.btn.blue:active { box-shadow: 0 0 0 var(--blue-edge); }
.btn.ghost {
  background: transparent; color: var(--ink-2);
  border: 2px solid var(--line-strong); box-shadow: 0 var(--edge) 0 var(--line);
}
.btn.ghost:active { box-shadow: 0 0 0 var(--line); }
.btn:focus-visible, .icon:focus-visible, .w:focus-visible, .ch-card:focus-visible {
  outline: 3px solid var(--blue); outline-offset: 3px; border-radius: 6px;
}
.btn[disabled] { opacity: .45; cursor: default; }

.icon {
  appearance: none; background: transparent; cursor: pointer;
  border: 2px solid var(--line); border-radius: 12px;
  color: var(--ink-2); width: 40px; height: 36px;
  font: 700 14px Nunito, sans-serif;
  display: inline-grid; place-items: center;
}
.icon:hover { border-color: var(--blue); color: var(--blue); }
.icon.on { border-color: var(--blue); color: #fff; background: var(--blue); }

.view { display: none; }
.view.active { display: block; }

/* ── Cover ───────────────────────────────────────────────────────────── */
#view-cover .wrap { padding-top: 40px; padding-bottom: 56px; }
.eyebrow {
  font: 800 12px Nunito, sans-serif; letter-spacing: 2px;
  text-transform: uppercase; color: var(--ink-3); margin-bottom: 10px;
}
.book-title {
  font: 800 clamp(34px, 9vw, 52px)/1.02 Nunito, sans-serif;
  margin: 0 0 8px; text-wrap: balance;
}
.book-sub { color: var(--ink-2); font-size: 16px; font-weight: 700; margin: 0 0 26px; }
.cover-art { margin: 0 0 28px; }

.stats { display: flex; gap: 10px; margin: 0 0 26px; flex-wrap: wrap; }
.stat {
  flex: 1 1 0; min-width: 96px;
  background: var(--surface-2); border: 2px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.stat b {
  display: block; font-size: 22px; font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat span {
  font-size: 11px; font-weight: 800; letter-spacing: 1px;
  text-transform: uppercase; color: var(--ink-3);
}
.stat.g b { color: var(--green); }
.stat.b b { color: var(--blue); }
.stat.y b { color: var(--gold-edge); }

.cover-actions { display: flex; flex-direction: column; gap: 12px; }

/* ── Chapter index ───────────────────────────────────────────────────── */
.ch-list { display: flex; flex-direction: column; gap: 12px; padding: 0 0 40px; }
.ch-card {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--surface); border: 2px solid var(--line);
  box-shadow: 0 var(--edge) 0 var(--line);
  border-radius: var(--radius); padding: 16px; cursor: pointer;
  color: inherit; font-family: inherit;
}
.ch-card:active { transform: translateY(var(--edge)); box-shadow: 0 0 0 var(--line); }
.ch-card[disabled] { opacity: .5; cursor: default; box-shadow: none; }
.ch-card[disabled]:active { transform: none; }
.ch-num {
  width: 42px; height: 42px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  font: 800 16px Nunito, sans-serif; color: #fff; background: var(--ink-3);
}
.ch-card.done .ch-num { background: var(--green); }
.ch-card.next .ch-num { background: var(--blue); }
.ch-t { font-weight: 800; font-size: 17px; }
.ch-s { font-size: 13px; color: var(--ink-3); font-weight: 700; }

/* ── Reading header ──────────────────────────────────────────────────── */
.readbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--bg); border-bottom: 2px solid var(--line);
}
.readbar-in {
  max-width: var(--story); margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 12px;
}
.readbar .who { flex: 1; min-width: 0; }
.readbar .who b { display: block; font-size: 15px; }
.readbar .who span { font-size: 11px; color: var(--ink-3); font-weight: 800; letter-spacing: 1px; text-transform: uppercase; }
.dots { display: flex; gap: 5px; padding: 0 20px 10px; max-width: var(--story); margin: 0 auto; }
.dot { height: 6px; flex: 1; border-radius: 99px; background: var(--line); }
.dot.on { background: var(--green); }

/* ── Story ───────────────────────────────────────────────────────────── */
.story { padding: 26px 0 56px; }
.ch-open { text-align: center; padding: 8px 0 30px; }
.ch-open .eyebrow { margin-bottom: 6px; }
.ch-open h2 { font: 800 30px/1.1 Nunito, sans-serif; margin: 0 0 4px; text-wrap: balance; }
.ch-open p { color: var(--ink-3); font-weight: 700; margin: 0; font-size: 14px; }

.scene-rule {
  display: flex; align-items: center; gap: 12px;
  margin: 34px 0 26px; color: var(--ink-3);
}
.scene-rule::before, .scene-rule::after {
  content: ""; flex: 1; height: 2px; background: var(--line);
}
.scene-rule b {
  font: 800 11px Nunito, sans-serif; letter-spacing: 2px; text-transform: uppercase;
}

.block { margin: 0 0 22px; }
.block p {
  font-family: Literata, Georgia, serif;
  margin: 0 0 10px; color: var(--ink);
}
.tools { display: flex; gap: 8px; margin-top: 4px; }
.trans {
  margin-top: 10px; padding: 12px 14px;
  background: var(--surface-2); border-left: 4px solid var(--blue);
  border-radius: 0 12px 12px 0;
}
.trans p {
  font-family: Nunito, sans-serif; font-size: 15px; line-height: 1.6;
  color: var(--ink-2); margin: 0 0 6px; font-weight: 600;
}
.trans p:last-child { margin-bottom: 0; }
[hidden] { display: none !important; }

.w { cursor: pointer; border-radius: 3px; }
.w:hover { background: color-mix(in srgb, var(--blue) 16%, transparent); }
.w.new {
  background: var(--new-bg);
  box-shadow: inset 0 -2px 0 var(--new-line);
  border-radius: 3px; padding: 0 1px;
}

/* ── Word popup ──────────────────────────────────────────────────────── */
#pop {
  position: fixed; z-index: 60; width: 232px;
  background: var(--surface); border: 2px solid var(--line-strong);
  box-shadow: 0 8px 0 rgba(0,0,0,.06), 0 12px 30px rgba(0,0,0,.18);
  border-radius: var(--radius); padding: 14px;
}
#pop .word { font: 800 19px Nunito, sans-serif; color: var(--blue); }
#pop .gloss { font-size: 15px; color: var(--ink); margin-top: 3px; font-weight: 600; }
#pop .tag {
  display: inline-block; margin-top: 8px; padding: 3px 8px; border-radius: 99px;
  background: var(--new-bg); color: var(--gold-edge);
  font: 800 10px Nunito, sans-serif; letter-spacing: 1px; text-transform: uppercase;
}
#pop .row { display: flex; gap: 8px; margin-top: 12px; }
#pop .row .btn { flex: 1; padding: 11px 10px; font-size: 12px; }

/* ── Chapter end ─────────────────────────────────────────────────────── */
.end { border-top: 2px solid var(--line); margin-top: 40px; padding-top: 30px; }
.panel {
  background: var(--surface-2); border: 2px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin: 0 0 16px;
}
.panel h3 {
  font: 800 12px Nunito, sans-serif; letter-spacing: 2px; text-transform: uppercase;
  color: var(--ink-3); margin: 0 0 14px;
}
.vocab { display: grid; grid-template-columns: 1fr; gap: 0; }
.vrow {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.vrow:last-child { border-bottom: none; }
.vrow b { font-weight: 800; }
.vrow span { color: var(--ink-2); text-align: right; font-weight: 600; font-size: 14px; }
.recap p { font-family: Literata, Georgia, serif; margin: 0 0 12px; }
.recap p:last-child { margin-bottom: 0; }

.saved-empty { color: var(--ink-3); font-weight: 700; padding: 30px 0; text-align: center; }
.saved-group h4 {
  font: 800 11px Nunito, sans-serif; letter-spacing: 2px; text-transform: uppercase;
  color: var(--ink-3); margin: 22px 0 8px;
}

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 99px;
  font: 800 14px Nunito, sans-serif; z-index: 80; pointer-events: none;
}

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

/* ── Reader levers ───────────────────────────────────────────────────── */
:root { --story-size: 19px; --story-lead: 1.72; }

.block p, .recap p {
  font-size: var(--story-size);
  line-height: var(--story-lead);
}
:root[data-font="round"] .block p,
:root[data-font="round"] .recap p {
  font-family: Nunito, system-ui, sans-serif;
  font-weight: 600;
}

/* new-word marking */
:root[data-marks="quiet"] .w.new {
  background: transparent;
  box-shadow: inset 0 -2px 0 var(--new-line);
}
:root[data-marks="off"] .w.new { background: transparent; box-shadow: none; }

/* translation granularity */
.tr-scene { margin-left: auto; }
:root[data-trans="block"]  .tr-scene { display: none; }
:root[data-trans="scene"]  .block .tr { display: none; }
:root[data-trans="always"] .block .tr,
:root[data-trans="always"] .tr-scene { display: none; }

/* explicit theme override — declared last so it beats both media and host */
:root[data-book-theme="light"] {
  --bg: #FFFFFF; --surface: #FFFFFF; --surface-2: #F7F9F8;
  --ink: #22333B; --ink-2: #5C7178; --ink-3: #91A5AC;
  --line: #E3E9E8; --line-strong: #CFD9D8;
  --new-bg: #FFF6D6; --new-line: #F0C000;
  --green: #58CC02; --blue: #1CB0F6;
}
:root[data-book-theme="dark"] {
  --bg: #131F24; --surface: #1B2B32; --surface-2: #16242A;
  --ink: #E8F0EF; --ink-2: #A4B8BE; --ink-3: #6E858C;
  --line: #27383F; --line-strong: #354A52;
  --new-bg: #33290A; --new-line: #C9A400;
  --green: #61D004; --blue: #38BDFF;
}

/* ── Settings drawer ─────────────────────────────────────────────────── */
#drawer { position: fixed; inset: 0; z-index: 70; }
#drawer[hidden] { display: none !important; }
#drawer .scrim { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
#drawer .sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-width: var(--story); margin: 0 auto;
  background: var(--surface); border-top: 2px solid var(--line);
  border-radius: 26px 26px 0 0; padding: 10px 20px 28px;
  max-height: 88vh; overflow: auto;
}
#drawer .grab {
  width: 46px; height: 5px; border-radius: 99px; background: var(--line-strong);
  margin: 6px auto 18px;
}
.lever { margin: 0 0 20px; }
.lever h4 {
  font: 800 11px Nunito, sans-serif; letter-spacing: 1.6px; text-transform: uppercase;
  color: var(--ink-3); margin: 0 0 9px;
}
.seg { display: flex; gap: 7px; }
.seg button {
  flex: 1; cursor: pointer; font: 800 13px Nunito, sans-serif;
  padding: 11px 4px; border-radius: 12px; color: var(--ink-2);
  background: var(--surface-2); border: 2px solid var(--line);
}
.seg button.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.seg button:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.lever .hint { font-size: 12px; color: var(--ink-3); font-weight: 700; margin: 8px 0 0; }

/* ── Bottom sheet (replaces the floating popup) ──────────────────────── */
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  max-width: var(--story); margin: 0 auto;
  background: var(--surface);
  border: 2px solid var(--line-strong); border-bottom: none;
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 34px rgba(0, 0, 0, .22);
  padding: 8px 20px calc(22px + env(safe-area-inset-bottom, 0px));
  max-height: 62vh; overflow: auto;
  visibility: hidden;
  transform: translateY(110%);
  transition: transform .26s cubic-bezier(.32, .72, 0, 1), visibility 0s .26s;
}
#sheet.open {
  visibility: visible;
  transform: translateY(0);
  transition: transform .26s cubic-bezier(.32, .72, 0, 1), visibility 0s 0s;
}
#sheet .grab {
  width: 46px; height: 5px; border-radius: 99px; background: var(--line-strong);
  margin: 4px auto 16px;
}
.sh-head {
  display: flex; align-items: flex-start; gap: 12px; margin-bottom: 4px;
}
.sh-head > div:first-child { flex: 1; min-width: 0; }
.sh-head h3 {
  flex: 1;
  font: 800 12px Nunito, sans-serif; letter-spacing: 2px; text-transform: uppercase;
  color: var(--ink-3); margin: 8px 0 0;
}
#sheet .word { font: 800 26px Nunito, sans-serif; color: var(--blue); line-height: 1.1; }
#sheet .gloss { font-size: 17px; color: var(--ink); margin-top: 4px; font-weight: 600; }
#sheet .tag {
  display: inline-block; margin-top: 12px; padding: 4px 10px; border-radius: 99px;
  background: var(--new-bg); color: var(--gold-edge);
  font: 800 10px Nunito, sans-serif; letter-spacing: 1px; text-transform: uppercase;
}
#sheet .row { display: flex; gap: 10px; margin-top: 18px; }
#sheet .row .btn { flex: 1; }
#sheet .row .btn.narrow { flex: 0 0 64px; }
.sheet-trans { margin-top: 14px; }
.sheet-trans p {
  font-family: Nunito, sans-serif; font-size: 16px; line-height: 1.62;
  color: var(--ink); margin: 0 0 10px; font-weight: 600;
}
.sheet-trans p:last-child { margin-bottom: 0; }
.sheet-trans .sc-gap { height: 1px; background: var(--line); margin: 14px 0; }

/* placement lever: inline translations only when asked for */
:root[data-place="sheet"][data-trans="block"] .trans,
:root[data-place="sheet"][data-trans="scene"] .trans { display: none; }

/* ── Error report ───────────────────────────────────────────────────────
   A text button, not an .icon square: the visible words are the accessible
   name, so a speech-control user can say what they read.                  */
.report {
  margin-left: auto; border: 2px solid var(--line); background: var(--surface);
  color: var(--ink-3); border-radius: 10px; padding: 0 10px; height: 30px;
  font: 800 11px Nunito, sans-serif; letter-spacing: .3px; cursor: pointer;
}
.report:hover { border-color: var(--blue); color: var(--blue); }
.report:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
:root[data-trans="always"] .tools .report,
:root[data-trans="scene"]  .tools .report { margin-left: 0; }

#sheet textarea {
  width: 100%; box-sizing: border-box; margin-top: 10px; resize: vertical;
  border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px;
  background: var(--bg); color: var(--ink);
  font: 600 15px/1.5 Nunito, sans-serif;
}
#sheet textarea:focus-visible { outline: 3px solid var(--blue); outline-offset: 1px; }

/* ── Survey ─────────────────────────────────────────────────────────────
   The pay/level/email questions shown after the last chapter. Styled like
   a lever but deliberately not a .seg: applyOpts() repaints those.        */
#view-survey .wrap { padding-top: 26px; padding-bottom: 56px; }
.survey .q { margin: 0 0 26px; }
.survey .q h4 {
  font: 800 16px/1.35 Nunito, sans-serif; margin: 0 0 10px; text-wrap: pretty;
}
.choice { display: flex; gap: 7px; }
.choice button {
  flex: 1; border: 2px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 12px; padding: 12px 8px; font: 800 14px Nunito, sans-serif; cursor: pointer;
}
.choice button.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.choice button:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.survey input[type="text"], .survey input[type="email"] {
  width: 100%; box-sizing: border-box; border: 2px solid var(--line);
  border-radius: 12px; padding: 12px 14px; background: var(--surface); color: var(--ink);
  font: 600 16px Nunito, sans-serif;
}
.survey input:focus-visible { outline: 3px solid var(--blue); outline-offset: 1px; }
.survey .check {
  display: flex; gap: 9px; align-items: flex-start; margin-top: 10px;
  font: 700 13px/1.45 Nunito, sans-serif; color: var(--ink-2);
}
.survey .check input { margin-top: 2px; width: 18px; height: 18px; accent-color: var(--blue); }
.survey .err {
  background: color-mix(in srgb, var(--red) 14%, transparent);
  border: 2px solid var(--red); border-radius: 12px; padding: 10px 14px;
  font: 800 13px Nunito, sans-serif; color: var(--ink); margin: 0 0 16px;
}
/* Focused by script when the form is replaced, so the ring must be explicit. */
#survey-thanks:focus-visible { outline: 3px solid var(--blue); outline-offset: 4px; border-radius: 16px; }
