/* Active Listening reader — mobile-first, dark, big thumb targets for use while
   walking. Designed so the primary actions (answer, next, replay, note) are all
   reachable one-handed without looking closely. */

:root {
  --bg: #10151c;
  --bg-2: #161d26;
  --surface: #1c2530;
  --surface-2: #232e3b;
  --ink: #eef3f1;
  --muted: #aab6c2;
  --quiet: #8493a1;
  --line: #2b3949;
  --accent: #8eb5e9;
  --accent-ink: #10151c;
  --good: #57c98b;
  --good-bg: rgba(87, 201, 139, 0.16);
  --bad: #ef6b6b;
  --bad-bg: rgba(239, 107, 107, 0.16);
  --warn: #e0b25a;
  --radius: 16px;
  --tap: 60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 80% at 50% -10%, #1a2433, var(--bg)) fixed;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
#reader-root { height: 100%; }
button { font-family: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible,
[role="button"]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.app {
  display: flex;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  position: relative;
}
/* The player (topbar + stage + controls) is one column; on desktop a document
   pane sits beside it. */
.player-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ---- desktop document pane (hidden on mobile) ---- */
.doc-pane { display: none; }
/* resize/hide controls are desktop-only (shown in the media query below) */
.pane-divider, .player-restore, .doc-restore { display: none; }
/* .topbar-scoped so these beat .icon-btn's own `display: grid` (defined later) —
   they are desktop-only (there is no document pane to hide/focus on mobile). */
.topbar .hide-player-btn, .topbar .focus-btn { display: none; }
body.resizing { cursor: col-resize; user-select: none; }

@media (min-width: 1000px) {
  /* Use wide screens: fill up to 1900px, then center. Beyond that the reading
     column is capped (below) so lines stay readable instead of running edge to
     edge — the extra pane width becomes calm document margin, not empty screen. */
  .app { max-width: 1900px; }
  .doc-pane {
    display: flex;
    flex-direction: column;
    flex: 1.2;
    min-width: 0;
    height: 100dvh;
    border-right: 1px solid var(--line);
    background: var(--bg-2);
  }
  /* Wider reading measure on big screens → less vertical scrolling — but capped
     so a line never gets uncomfortably long, and centered within the pane. */
  .doc-reading { align-self: center; width: 100%; max-width: 1120px; }
  .player-col { flex: none; width: var(--player-w, 440px); }
  .pane-divider {
    display: block; flex: none; width: 7px; align-self: stretch;
    cursor: col-resize; background: var(--line); transition: background 120ms ease;
  }
  .pane-divider:hover, body.resizing .pane-divider { background: var(--accent); }
  .topbar .hide-player-btn, .topbar .focus-btn { display: grid; }
  .app.player-hidden .player-col, .app.player-hidden .pane-divider { display: none; }
  .app.player-hidden .doc-pane { border-right: none; flex: 1; }
  /* Focus mode: hide the document pane + divider and CENTER the reader column at a
     comfortable width, so nothing competes with reading + answering questions. */
  .app.doc-hidden .doc-pane, .app.doc-hidden .pane-divider { display: none; }
  .app.doc-hidden .player-col { flex: none; width: min(680px, 92vw); margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .focus-btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
  .player-restore, .doc-restore {
    position: fixed; top: 14px; z-index: 30;
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface); border: 1px solid var(--line); color: var(--ink);
    border-radius: 999px; padding: 9px 15px; font-size: 0.85rem; font-weight: 600; cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  }
  .player-restore { right: 14px; }
  .doc-restore { left: 14px; }
  .player-restore:active, .doc-restore:active { transform: scale(0.96); }
}

.doc-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.doc-toolbar-title { font-weight: 640; font-size: 0.9rem; flex: 1; color: var(--quiet); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: none; background: transparent; color: var(--muted); font: inherit; font-size: 0.78rem; font-weight: 600; padding: 6px 14px; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.doc-open-pdf {
  min-height: 31px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 8px; color: var(--muted);
  padding: 5px 10px; text-decoration: none; font-size: 0.74rem; font-weight: 700;
  white-space: nowrap; background: transparent; font-family: inherit; cursor: pointer;
}
.doc-open-pdf:hover { color: var(--ink); border-color: var(--accent); }
.doc-open-pdf:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.doc-open-pdf:disabled { cursor: wait; opacity: 0.64; }

.doc-pdf-page {
  flex: 1; min-width: 0; overflow: auto; padding: 18px;
  display: flex; align-items: flex-start; justify-content: center;
  background: #20252c;
}
.doc-pdf-page-image {
  display: block; width: min(100%, 1280px); height: auto;
  background: #fff; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}
.doc-pdf-page-status { margin: auto; color: var(--quiet); font-size: 0.86rem; }
.doc-reading { flex: 1; overflow-y: auto; padding: 22px 26px 60px; }
.doc-window-nav {
  display: block; width: fit-content; min-height: 34px; margin: 4px auto 10px;
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px;
  background: var(--surface); color: var(--muted); font: inherit; font-size: 0.76rem;
  font-weight: 700; cursor: pointer;
}
.doc-window-nav:last-child { margin-top: 10px; margin-bottom: 4px; }
.doc-window-nav:hover, .doc-window-nav:focus-visible { color: var(--ink); border-color: var(--accent); }
.doc-sec {
  display: grid; grid-template-columns: 34px 1fr; gap: 6px;
  padding: 10px 12px; margin: 2px 0; border-radius: 12px; cursor: pointer;
  border-left: 3px solid transparent; transition: background 140ms ease;
}
.doc-sec:hover { background: rgba(142, 181, 233, 0.06); }
.doc-sec.active { background: rgba(142, 181, 233, 0.12); border-left-color: var(--accent); }
.doc-sec-marker {
  display: flex; justify-content: flex-end; align-items: flex-start; padding: 4px 0 0;
  min-width: 30px; border: 0; background: transparent; color: var(--quiet); cursor: pointer;
  font: inherit;
}
.doc-sec-marker:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
.doc-sec-index { font-size: 0.68rem; font-weight: 700; line-height: 1.5; }
.note-pin { font-style: normal; font-size: 0.66rem; font-weight: 700; color: var(--warn); background: rgba(224, 178, 90, 0.16); border-radius: 999px; padding: 2px 7px; white-space: nowrap; }
.doc-sec-body h3 { font-size: 1.02rem; margin: 0 0 4px; line-height: 1.3; }
.doc-sec-body p { font-size: 1.02rem; line-height: 1.62; margin: 0; color: var(--muted); }
.doc-kind { display: inline-block; font-size: 0.64rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--warn); margin-bottom: 4px; }
/* Images rendered from the document source keep their original colors. */
.doc-reading img { filter: none !important; }

/* ---- PDF view with a section gutter (note markers + active highlight) ---- */
.doc-pdf-wrap { flex: 1; display: flex; min-height: 0; }
.doc-gutter { width: 48px; flex: none; overflow-y: auto; padding: 8px 7px; border-right: 1px solid var(--line); background: var(--bg); display: flex; flex-direction: column; gap: 6px; }
.gutter-dot { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--quiet); font-size: 0.72rem; font-weight: 700; cursor: pointer; display: grid; place-items: center; }
.gutter-dot:active { transform: scale(0.92); }
.gutter-dot.active { border-color: var(--accent); color: var(--accent); background: rgba(142, 181, 233, 0.14); }
.gutter-dot.has-note { color: var(--warn); border-color: rgba(224, 178, 90, 0.5); }
.gutter-dot.has-note.active { color: var(--accent); }
.gutter-dot.gutter-nav { color: var(--muted); font-size: 1rem; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 21, 28, 0.7);
  backdrop-filter: blur(10px);
}
.topbar .title {
  font-weight: 640; font-size: 0.98rem; line-height: 1.2; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar .title small {
  display: block; color: var(--quiet); font-weight: 500; font-size: 0.74rem;
  overflow: hidden; text-overflow: ellipsis;
}
.chip {
  font-size: 0.72rem; font-weight: 600; padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.chip.online { color: var(--good); border-color: rgba(87,201,139,.4); }
.chip.offline { color: var(--warn); border-color: rgba(224,178,90,.4); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 1.1rem; cursor: pointer;
  display: grid; place-items: center; flex: none;
}
.icon-btn:active { transform: scale(0.94); }
.account-sign-in {
  flex: none; height: 40px; padding: 0 13px;
  border: 1px solid var(--accent); border-radius: 8px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 0.84rem; font-weight: 760; white-space: nowrap; cursor: pointer;
}
.account-sign-in:active, .account-profile:active { transform: scale(0.94); }
.account-profile, .account-loading {
  width: 40px; height: 40px; flex: none; border-radius: 50%;
}
.account-profile {
  display: grid; place-items: center; padding: 2px; overflow: hidden;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer;
}
.account-profile img, .account-initial {
  display: grid; place-items: center; width: 100%; height: 100%; border-radius: 50%;
}
.account-profile img { object-fit: cover; }
.account-initial {
  background: var(--accent); color: var(--accent-ink);
  font-size: 0.92rem; font-weight: 800;
}
.account-loading {
  display: block; border: 1px solid var(--line);
  background: var(--surface);
}

@media (max-width: 420px) {
  .topbar { gap: 8px; padding-inline: 10px; }
  .topbar .title small { display: none; }
  .account-sign-in { padding-inline: 11px; }
}

/* ---- progress ---- */
.progress { height: 4px; background: var(--line); }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width 240ms ease; }

/* ---- stage (current chunk) ---- */
.stage { flex: 1; overflow-y: auto; padding: 20px 18px 8px; -webkit-overflow-scrolling: touch; }
.kind {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.72rem; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; color: var(--accent);
  background: rgba(142,181,233,.12); border: 1px solid rgba(142,181,233,.28);
  padding: 4px 10px; border-radius: 999px; margin-bottom: 14px;
}
.section-meta-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  min-width: 0; margin-bottom: 14px;
}
.section-meta-row > .kind { min-width: 0; margin-bottom: 0; }
.manual-advance-btn {
  flex: none; min-height: 27px; padding: 4px 9px; white-space: nowrap;
  border: 1px solid rgba(224,178,90,.45); border-radius: 7px;
  background: rgba(224,178,90,.1); color: var(--warn);
  font-size: .72rem; font-weight: 700; cursor: pointer;
}
.manual-advance-btn:active { transform: scale(.97); }
.manual-narration-note {
  flex: none; min-height: 27px; padding: 4px 8px; white-space: nowrap;
  display: inline-flex; align-items: center;
  border: 1px solid rgba(224,178,90,.35); border-radius: 7px;
  background: rgba(224,178,90,.08); color: var(--warn);
  font-size: .72rem; font-weight: 700;
}
.kind.figure { color: var(--warn); background: rgba(224,178,90,.12); border-color: rgba(224,178,90,.3); }
.kind.table { color: #c4a6f0; background: rgba(183,161,239,.12); border-color: rgba(183,161,239,.3); }
.kind.formula { color: var(--good); background: rgba(87,201,139,.12); border-color: rgba(87,201,139,.3); }
.content-text { font-size: 1.22rem; line-height: 1.6; letter-spacing: -0.003em; }
.content-text.heading-lead::first-line { font-weight: 600; }
.speaking-dot { display:inline-block; width:9px; height:9px; border-radius:50%; background:var(--accent); margin-left:8px; animation: pulse 1.1s ease-in-out infinite; vertical-align: middle; }
@keyframes pulse { 0%,100%{opacity:.3;transform:scale(.8)} 50%{opacity:1;transform:scale(1.2)} }

/* ---- question ---- */
/* per-concept progress: one dot per important concept in this section */
.concept-dots { display: flex; gap: 7px; margin: 10px 0 2px; }
.concept-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); transition: background 180ms ease; }
.concept-dot.on { background: var(--accent); box-shadow: 0 0 0 3px rgba(142,181,233,0.16); }
.concept-dot.done { background: var(--good); }
.q-stem { font-size: 1.18rem; line-height: 1.5; font-weight: 600; margin-bottom: 16px; }
.q-meta { color: var(--quiet); font-size: 0.8rem; margin-bottom: 14px; }
.options { display: grid; gap: 12px; }
.option {
  display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: var(--tap); padding: 14px 16px; text-align: left;
  background: var(--surface); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: var(--radius);
  font-size: 1.06rem; line-height: 1.35; cursor: pointer;
  transition: transform 90ms ease, border-color 140ms ease, background 140ms ease;
}
.option:active { transform: scale(0.985); }
.option .letter {
  flex: none; width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  font-weight: 760; background: var(--surface-2); color: var(--accent); border: 1px solid var(--line);
}
.option.correct { border-color: var(--good); background: var(--good-bg); }
.option.correct .letter { background: var(--good); color: var(--accent-ink); border-color: var(--good); }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.option.wrong .letter { background: var(--bad); color: #fff; border-color: var(--bad); }
.option.dim { opacity: 0.5; }
.option:disabled { cursor: default; }
.feedback { margin-top: 16px; font-size: 0.98rem; line-height: 1.5; padding: 12px 14px; border-radius: 12px; }
.feedback.good { color: var(--good); background: var(--good-bg); }
.feedback.bad { color: var(--bad); background: var(--bad-bg); }
.feedback.diagnostic { color: var(--ink); background: var(--surface-2); border: 1px solid var(--line); }
.misconception-panel { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.misconception-prompt { margin: 0 0 10px; color: var(--ink); font-size: 1rem; font-weight: 700; line-height: 1.4; }
.misconception-options { display: grid; gap: 9px; }
.misconception-option {
  width: 100%; min-height: var(--tap); padding: 11px 13px; text-align: left;
  color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; font-size: .95rem; line-height: 1.4; cursor: pointer;
}
.misconception-option:active { transform: scale(.99); }
.misconception-option.selected { border-color: var(--accent); background: rgba(142,181,233,.12); }
.misconception-continue { margin-top: 14px; }

/* ---- bottom controls ---- */
.controls {
  display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 12px; align-items: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: rgba(16,21,28,.8); backdrop-filter: blur(10px);
}
.ctl {
  height: 64px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 1rem; font-weight: 600;
  display: grid; place-items: center; gap: 2px; cursor: pointer;
}
.ctl:active { transform: scale(0.96); }
.ctl:disabled { opacity: 0.4; cursor: default; }
.ctl.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-size: 1.05rem; }
.ctl small { font-size: 0.66rem; font-weight: 600; color: var(--quiet); }
.ctl.primary small { color: var(--accent-ink); }

.subbar { display: flex; flex-wrap: wrap; gap: 10px; padding: 0 16px 10px; }
.subbar button {
  flex: 1 1 96px; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--muted); font-size: 0.86rem; font-weight: 600; cursor: pointer;
}
.subbar button:active { transform: scale(0.97); }
.subbar button.armed { color: var(--accent); border-color: rgba(142,181,233,.4); }
.speed-control {
  flex: 1 1 116px; height: 44px; display: flex; align-items: center; gap: 7px;
  padding: 0 9px 0 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg-2); color: var(--muted); font-size: .82rem; font-weight: 650;
}
.speed-control select {
  flex: 1; min-width: 0; height: 32px; padding: 0 5px; border: 0; border-radius: 8px;
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 750;
}
.subbar button.voice-command.listening {
  color: var(--accent); border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(142,181,233,.12);
}
.voice-status {
  margin: 0 16px 10px; padding: 9px 11px; border: 1px solid rgba(142,181,233,.35);
  border-radius: 10px; color: var(--muted); background: rgba(142,181,233,.08);
  font-size: .78rem; line-height: 1.4;
}
.prep-status {
  margin: 0 16px 10px; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 10px; color: var(--muted); background: var(--surface);
  font-size: .78rem; line-height: 1.4;
}
.prep-status.waiting { color: var(--warn); border-color: rgba(224,178,90,.35); }
.prep-status.error { color: var(--bad); border-color: rgba(239,107,107,.4); }

/* ---- sheets (notes / settings / library) ---- */
.scrim { position: fixed; inset: 0; background: rgba(8,11,15,.6); z-index: 30; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-width: 640px; margin: 0 auto;
  background: var(--bg-2); border-top-left-radius: 22px; border-top-right-radius: 22px;
  border-top: 1px solid var(--line); padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 82dvh; overflow-y: auto;
  animation: rise 220ms cubic-bezier(.2,.7,.2,1);
}
@keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet h2 { margin: 0 0 12px; font-size: 1.1rem; }
.sheet label { display: block; font-size: 0.82rem; color: var(--muted); margin: 12px 0 6px; }
.sheet input, .sheet textarea, .sheet select {
  width: 100%; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; font-size: 1rem; font-family: inherit;
}
.sheet label.toggle-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: start;
  column-gap: 10px;
  margin: 12px 0 6px;
  cursor: pointer;
}
.sheet label.toggle-row > input[type="checkbox"] {
  appearance: auto;
  width: 18px;
  min-width: 18px;
  height: 18px;
  margin: 2px 0 0;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  accent-color: var(--accent);
}
.sheet label.toggle-row > .hint { min-width: 0; margin: 0; }
.sheet textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.btn {
  width: 100%; height: 54px; border-radius: 14px; border: none; margin-top: 14px;
  background: var(--accent); color: var(--accent-ink); font-size: 1rem; font-weight: 700; cursor: pointer;
}
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn:disabled, .btn[disabled], .btn.is-disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn.busy { position: relative; }
.note-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-top: 10px; background: var(--surface); }
.note-item .meta { color: var(--quiet); font-size: 0.74rem; margin-top: 8px; display: flex; justify-content: space-between; }
.dl-bar { margin-top: 12px; height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.dl-bar > i { display: block; height: 100%; background: var(--good); width: 0; transition: width 200ms ease; }
.offline-result { margin: 10px 0 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: .82rem; line-height: 1.5; }
.offline-result.good { color: var(--good); background: var(--good-bg); border-color: rgba(87, 201, 139, .35); }
.offline-result.warn { color: var(--warn); background: rgba(224, 178, 90, .10); border-color: rgba(224, 178, 90, .35); }
.offline-result.error { color: #ffaaaa; background: var(--bad-bg); border-color: rgba(239, 107, 107, .42); }
.hint { color: var(--quiet); font-size: 0.82rem; line-height: 1.5; }
.sheet details { border-top: 1px solid var(--line); padding-top: 12px; }
.sheet summary { color: var(--muted); font-size: .86rem; font-weight: 700; cursor: pointer; }
.lib-item { display:flex; align-items:center; gap:12px; padding:14px; border:1px solid var(--line); border-radius:12px; background:var(--surface); margin-top:10px; cursor:pointer; }
.lib-item .dot { width:10px; height:10px; border-radius:50%; background:var(--quiet); flex:none; }
.lib-item .dot.ready { background: var(--good); }
/* the OPEN document: highlighted row + chip, and a framed group for its actions */
.lib-item.current { border-color: var(--accent); background: rgba(142, 181, 233, 0.08); }
.rename-input { flex: 1; min-width: 0; background: var(--surface-2); color: var(--ink); border: 1px solid var(--accent); border-radius: 10px; padding: 8px 10px; font-size: 0.95rem; font-weight: 600; font-family: inherit; }
.open-chip { font-size:.66rem; font-weight:800; letter-spacing:.07em; text-transform:uppercase; color:var(--accent-ink); background:var(--accent); border-radius:999px; padding:3px 9px; flex:none; }
/* ---- public documents (readable by every visitor, signed in or not) ---- */
.public-doc-heading {
  margin: 22px 0 4px; font-size: .8rem; letter-spacing: .05em;
  color: var(--muted); text-transform: uppercase;
}
.public-doc-list { list-style: none; margin: 0; padding: 0; }
.public-doc-item {
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  margin-top: 10px; overflow: hidden;
}
.public-doc-item.current { border-color: var(--accent); background: rgba(142, 181, 233, 0.08); }
.public-doc-open {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "kind state" "title state" "blurb state";
  align-items: center; column-gap: 12px; row-gap: 4px;
  width: 100%; padding: 14px; border: 0; background: transparent;
  color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.public-doc-open:disabled { cursor: default; }
.public-doc-kind {
  grid-area: kind; justify-self: start;
  font-size: .64rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent);
}
.public-doc-title { grid-area: title; font-weight: 650; line-height: 1.35; }
.public-doc-blurb { grid-area: blurb; color: var(--quiet); font-size: .78rem; line-height: 1.45; }
.public-doc-state {
  grid-area: state; flex: none; align-self: center;
  color: var(--muted); font-size: .78rem; font-weight: 700; white-space: nowrap;
}
.public-doc-item.current .public-doc-state { color: var(--accent); }
.public-doc-links {
  display: flex; flex-wrap: wrap; gap: 14px;
  margin: 0; padding: 0 14px 12px; font-size: .78rem;
}
.public-doc-links a { color: var(--muted); text-decoration: none; font-weight: 600; }
.public-doc-links a:hover, .public-doc-links a:focus-visible { color: var(--accent); text-decoration: underline; }
@media (max-width: 420px) {
  .public-doc-open {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "kind" "title" "blurb" "state";
  }
  .public-doc-state { justify-self: start; margin-top: 4px; }
}

.doc-group { border:1px solid var(--accent); border-radius:12px; padding:16px; margin-top:22px; background: rgba(142, 181, 233, 0.05); }
.doc-group > h2 { margin:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.doc-group > h2 em { color:var(--accent); font-style:normal; }
.doc-group h3 { margin:18px 0 6px; font-size:.8rem; letter-spacing:.05em; color:var(--muted); text-transform:uppercase; }

.toast {
  position: fixed; bottom: calc(96px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 999px; font-size: 0.86rem; z-index: 40; box-shadow: 0 10px 30px rgba(0,0,0,.4);
  animation: rise 180ms ease;
}

/* ---- "break into smaller chunks" / "merge with next" controls ---- */
.chunk-ops { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.split-btn {
  margin-top: 16px; padding: 9px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  font-size: 0.84rem; font-weight: 600; cursor: pointer;
}
.split-btn:active { transform: scale(0.97); }
.split-btn:disabled { opacity: 0.6; cursor: default; }
.doc-split-btn {
  margin-top: 8px; padding: 4px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: transparent; color: var(--quiet);
  font-size: 0.72rem; font-weight: 600; cursor: pointer;
}
.doc-split-btn:disabled { opacity: 0.6; cursor: default; }

/* ============ motivation: streak chip, points, celebration, progress ============ */
.streak-chip {
  display: inline-flex; align-items: center; gap: 4px; flex: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 5px 10px; font-size: 0.8rem; font-weight: 700; cursor: pointer;
}
.streak-chip .flame { filter: grayscale(1) opacity(0.6); font-size: 0.9rem; line-height: 1; }
.streak-chip.lit { border-color: rgba(244, 199, 82, 0.5); color: var(--ink); }
.streak-chip.lit .flame { filter: none; }
.streak-chip .streak-n { font-variant-numeric: tabular-nums; }
.streak-chip .streak-pts { color: var(--accent); font-size: 0.72rem; margin-left: 2px; }
.streak-chip.at-risk { border-color: var(--accent); animation: chip-pulse 1.8s ease-in-out infinite; }
@keyframes chip-pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(142,181,233,0); } 50% { box-shadow: 0 0 0 4px rgba(142,181,233,0.18); } }

/* floating +N over the quiz on a correct answer */
.points-float {
  position: absolute; top: -6px; right: 0; z-index: 5; pointer-events: none;
  display: inline-flex; flex-direction: column; align-items: flex-end;
  color: var(--good); font-weight: 800; font-size: 1.5rem; text-shadow: 0 2px 10px rgba(0,0,0,0.4);
  animation: float-up 1.3s ease-out forwards;
}
.points-float small { font-size: 0.66rem; font-weight: 700; color: #f4c752; text-transform: uppercase; letter-spacing: .04em; }
@keyframes float-up { 0% { opacity: 0; transform: translateY(10px) scale(0.8); } 20% { opacity: 1; transform: translateY(0) scale(1.1); } 60% { opacity: 1; transform: translateY(-8px) scale(1); } 100% { opacity: 0; transform: translateY(-34px) scale(0.95); } }

/* celebration burst */
.celebrate { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(16,21,28,0.35); animation: rise 160ms ease; }
.celebrate-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: 18px; padding: 22px 30px; text-align: center; box-shadow: 0 24px 70px rgba(0,0,0,0.5); animation: pop 360ms cubic-bezier(.2,1.3,.5,1); }
.celebrate-title { font-size: 1.35rem; font-weight: 800; }
.celebrate-sub { color: var(--muted); margin-top: 6px; font-size: 0.9rem; }
@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-pc { position: absolute; top: -12px; border-radius: 2px; animation-name: confetti-drop; animation-timing-function: cubic-bezier(.3,.6,.5,1); animation-iteration-count: 1; }
@keyframes confetti-drop { 0% { transform: translateY(-10vh) rotate(0); opacity: 1; } 100% { transform: translateY(105vh) rotate(540deg); opacity: 0.9; } }

/* progress dashboard */
.streak-hero { display: flex; align-items: center; gap: 16px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(135deg, rgba(244,199,82,0.08), rgba(142,181,233,0.06)); margin-top: 4px; }
.hero-flame { font-size: 2.6rem; filter: grayscale(1) opacity(0.55); }
.hero-flame.lit { filter: none; animation: flicker 2.4s ease-in-out infinite; }
@keyframes flicker { 0%,100% { transform: scale(1) rotate(-2deg); } 50% { transform: scale(1.08) rotate(2deg); } }
.hero-streak { font-size: 2rem; font-weight: 800; line-height: 1; }
.hero-streak span { font-size: 0.95rem; font-weight: 600; color: var(--muted); }
.hero-sub { color: var(--quiet); font-size: 0.82rem; margin-top: 6px; line-height: 1.45; }

.goal-block { display: flex; align-items: center; gap: 18px; margin-top: 18px; }
.goal-ring { position: relative; flex: none; width: 128px; height: 128px; display: grid; place-items: center; }
.goal-ring svg { position: absolute; inset: 0; }
.ring-track { fill: none; stroke: var(--line); stroke-width: 10; }
.ring-fill { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset 600ms ease; }
.ring-fill.met { stroke: #f4c752; }
.goal-ring-label { position: relative; text-align: center; line-height: 1.1; }
.goal-ring-label strong { font-size: 1.7rem; font-weight: 800; }
.goal-ring-label span { color: var(--quiet); font-size: 0.8rem; }
.goal-ring-label small { display: block; color: var(--muted); font-size: 0.68rem; margin-top: 3px; }
.goal-side { flex: 1; min-width: 0; }
.goal-side-h { font-weight: 700; margin-bottom: 8px; }
.goal-presets { display: flex; gap: 8px; }
.goal-preset { flex: 1; border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 10px; padding: 8px 0; font-weight: 700; font-size: 0.82rem; cursor: pointer; }
.goal-preset.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.trend-row { display: flex; gap: 12px; margin-top: 18px; }
.trend-card { flex: 1; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--surface); min-width: 0; }
.trend-h { color: var(--quiet); font-size: 0.72rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.trend-big { font-size: 1.7rem; font-weight: 800; margin: 2px 0 4px; }
.trend { font-size: 0.78rem; font-weight: 700; }
.trend.up { color: var(--good); } .trend.down { color: var(--bad); } .trend.flat { color: var(--quiet); }

.prog-h { margin: 22px 0 10px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.heatmap { display: flex; gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.hm-col { display: flex; flex-direction: column; gap: 3px; flex: none; }
.hm-cell { width: 13px; height: 13px; border-radius: 3px; flex: none; }
.hm-empty { background: transparent; }
.hm-0 { background: var(--line); } .hm-1 { background: rgba(142,181,233,0.35); }
.hm-2 { background: rgba(142,181,233,0.6); } .hm-3 { background: rgba(142,181,233,0.85); } .hm-4 { background: #8eb5e9; }
.hm-goal { box-shadow: inset 0 0 0 1.5px #f4c752; }
.hm-legend { display: flex; align-items: center; gap: 4px; margin-top: 8px; color: var(--quiet); font-size: 0.72rem; }
.hm-legend .hm-cell { width: 12px; height: 12px; }

.wbars { display: flex; align-items: flex-end; gap: 6px; height: 96px; }
.wbar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; }
.wbar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.wbar-fill { width: 100%; min-height: 3px; background: rgba(142,181,233,0.5); border-radius: 4px 4px 0 0; transition: height 400ms ease; }
.wbar-fill.now { background: var(--accent); }
.wbar-x { color: var(--quiet); font-size: 0.64rem; }

.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.badge { border: 1px solid var(--line); border-radius: 12px; padding: 12px 8px; text-align: center; background: var(--surface); opacity: 0.55; }
.badge.unlocked { opacity: 1; border-color: rgba(244,199,82,0.5); background: linear-gradient(160deg, rgba(244,199,82,0.1), var(--surface)); }
.badge-emoji { font-size: 1.7rem; filter: grayscale(1); }
.badge.unlocked .badge-emoji { filter: none; }
.badge-name { font-weight: 700; font-size: 0.8rem; margin-top: 4px; }
.badge-desc { color: var(--quiet); font-size: 0.68rem; margin-top: 2px; }
.badge-bar { height: 4px; border-radius: 999px; background: var(--line); margin-top: 7px; overflow: hidden; }
.badge-bar > i { display: block; height: 100%; background: var(--accent); }

.life-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 8px; }
.life-stat { border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; background: var(--surface); }
.life-stat strong { display: block; font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.life-stat span { color: var(--quiet); font-size: 0.72rem; }

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

/* Automatic cross-device sync status bar (Documents sheet) */
.sync-bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 14px; }
.sync-bar .sync-dot { display: inline-block; font-size: .95rem; line-height: 1; color: var(--good); }
.sync-bar.syncing .sync-dot { color: var(--accent); animation: sync-spin 1s linear infinite; }
.sync-bar.offline .sync-dot, .sync-bar.signedout .sync-dot { color: var(--quiet); }
.sync-bar.error .sync-dot, .sync-bar.quota .sync-dot { color: var(--bad); }
.sync-bar .sync-msg { flex: 1; min-width: 0; font-size: .8rem; color: var(--muted); }
.sync-bar .sync-now { flex: none; border: 1px solid var(--line); background: transparent; color: var(--accent); border-radius: 9px; padding: 6px 12px; font-weight: 700; font-size: .78rem; cursor: pointer; }
.sync-bar .sync-now:disabled { opacity: .5; cursor: default; }
@keyframes sync-spin { to { transform: rotate(360deg); } }

/* ---------------- Leitner box (spaced repetition) ---------------- */
.leitner-chip { position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: transparent;
  cursor: pointer; font-size: 1.05rem; flex: none; }
.leitner-chip.has-due { border-color: var(--accent); }
.leitner-chip .lc-badge { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: .68rem; font-weight: 800;
  display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.leitner-chip .lc-check2 { position: absolute; top: -5px; right: -5px; font-size: .6rem; color: var(--good); }

.leitner-cta { width: 100%; font-size: 1.06rem; padding: 15px; }
.leitner-empty { text-align: center; padding: 12px 4px; }
.leitner-caught { text-align: center; padding: 14px 6px 6px; }
.leitner-caught .lc-check { font-size: 2.4rem; line-height: 1; }
.leitner-caught h2 { margin: 8px 0 4px; }

.box-chart { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; align-items: end; margin: 20px 0 8px; height: 150px; }
.box-col { display: flex; flex-direction: column; align-items: center; height: 100%; }
.box-bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.box-bar { width: 100%; border-radius: 8px 8px 4px 4px; min-height: 4px; display: flex; align-items: flex-start;
  justify-content: center; padding-top: 4px; transition: height 300ms ease; }
.box-bar span { font-size: .74rem; font-weight: 800; color: var(--accent-ink); }
.box-bar.b1 { background: #7b8794; } .box-bar.b2 { background: #6ba3e0; }
.box-bar.b3 { background: #4f86c6; } .box-bar.b4 { background: #e0b25a; } .box-bar.b5 { background: var(--good); }
.box-lab { font-weight: 700; font-size: .8rem; margin-top: 6px; color: var(--ink); }
.box-sub { font-size: .62rem; color: var(--quiet); text-align: center; line-height: 1.2; }
.leitner-stats { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; margin-top: 12px;
  font-size: .82rem; color: var(--muted); }
.leitner-stats b { color: var(--ink); font-weight: 800; }
.leitner-stats .leech b { color: var(--warn); }

.review-card { }
.rc-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.rc-box { font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
  padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--quiet); }
.rc-box.b5 { color: var(--good); border-color: rgba(87,201,139,.4); }
.rc-concept { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--warn); margin-bottom: 6px; }
.rc-feedback { margin-top: 14px; }
.rc-verdict { font-weight: 700; padding: 10px 12px; border-radius: 12px; margin: 0 0 8px; }
.rc-verdict.good { color: var(--good); background: var(--good-bg); }
.rc-verdict.bad { color: var(--bad); background: var(--bad-bg); }
.rc-expl { color: var(--muted); font-size: .92rem; line-height: 1.5; margin: 0 0 14px; }
.rc-actions { display: flex; gap: 10px; }
.rc-actions .btn { flex: 1; }

/* ---- updated-section highlight (after a document version update) ---- */
.doc-sec.updated { background: rgba(224, 178, 90, 0.10); }
.doc-sec.updated:not(.active) { border-left-color: rgba(224, 178, 90, 0.6); }
.updated-badge { display: inline-block; font-size: 0.6rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--accent-ink); background: var(--warn); border-radius: 999px; padding: 2px 8px; margin-bottom: 6px; }
.updated-note { color: var(--warn); background: rgba(224, 178, 90, 0.12); border: 1px solid rgba(224, 178, 90, 0.3);
  border-radius: 12px; padding: 9px 12px; font-size: 0.84rem; font-weight: 600; line-height: 1.4; margin: 8px 0 12px; }

/* ---- learning visuals (LLM-generated SVG diagram/mnemonic beside a chunk) ---- */
.doc-visual { margin: 10px 0 4px; padding: 12px 14px 8px; max-width: 440px;
  border: 1px solid var(--line); border-radius: 12px; background: rgba(142, 181, 233, 0.05); }
.doc-visual-svg { color: var(--muted); }        /* currentColor in the SVG follows the theme */
.doc-visual-svg svg { display: block; width: 100%; height: auto; }
.doc-visual figcaption { font-size: 0.74rem; color: var(--quiet); margin-top: 6px; line-height: 1.4; }
.doc-visual.bundled {
  width: min(100%, 720px);
  max-width: 720px;
  padding: 0;
  overflow: hidden;
  border-radius: 8px;
  background: #f7f6f2;
}
.doc-visual-asset-link {
  display: block;
  width: 100%;
  background: #f7f6f2;
  cursor: zoom-in;
}
.doc-visual-asset-link img {
  display: block;
  width: 100%;
  height: auto;
  filter: none !important;
}
.doc-visual.bundled figcaption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  padding: 9px 12px 10px;
  background: var(--surface);
}
.doc-visual-open {
  flex: none;
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.doc-visual-open:hover { text-decoration: underline; }
@media (max-width: 420px) {
  .doc-visual.bundled figcaption {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }
}

/* ---- exact source artifacts (locally rendered from the original PDF) ---- */
.source-artifact {
  margin: 14px 0 6px;
  width: min(100%, 720px);
}
.source-artifact-preview {
  display: grid;
  position: relative;
  width: 100%;
  min-height: 150px;
  max-height: 360px;
  padding: 0;
  overflow: hidden;
  cursor: zoom-in;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f4f3ef;
  color: #3a434e;
}
.source-artifact-preview img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 360px;
  object-fit: contain;
  object-position: top center;
}
.source-artifact-placeholder {
  display: grid;
  place-items: center;
  min-height: 150px;
  padding: 24px;
  color: #596675;
  font-size: 0.82rem;
  font-weight: 650;
}
.source-artifact-preview.loading .source-artifact-placeholder::before {
  content: "";
  width: 24px;
  height: 24px;
  margin-bottom: 10px;
  border: 3px solid #c9d0d7;
  border-top-color: #315f99;
  border-radius: 50%;
  animation: source-artifact-spin 0.8s linear infinite;
}
@keyframes source-artifact-spin { to { transform: rotate(360deg); } }
.source-artifact-action {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 7px 11px;
  border-radius: 8px;
  background: rgba(16, 21, 28, 0.88);
  color: #eef3f1;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
  font-size: 0.76rem;
  font-weight: 750;
}
.source-artifact figcaption {
  margin-top: 7px;
  color: var(--quiet);
  font-size: 0.76rem;
  line-height: 1.4;
}
.source-artifact figcaption strong { color: var(--muted); }
.source-artifact-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  background: rgba(5, 8, 12, 0.86);
  backdrop-filter: blur(7px);
}
.source-artifact-dialog {
  display: flex;
  flex-direction: column;
  width: min(1120px, 100%);
  height: min(94dvh, 980px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-2);
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}
.source-artifact-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 9px 10px 9px 16px;
  border-bottom: 1px solid var(--line);
}
.source-artifact-toolbar > div:first-child {
  display: grid;
  min-width: 0;
  margin-right: auto;
}
.source-artifact-toolbar strong { font-size: 0.9rem; }
.source-artifact-toolbar span { margin-top: 2px; color: var(--quiet); font-size: 0.72rem; }
.source-artifact-tools { display: flex; gap: 6px; flex: none; }
.source-artifact-tools button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.25rem;
  cursor: pointer;
}
.source-artifact-tools button:disabled { opacity: 0.4; cursor: default; }
.source-artifact-detail {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: #d8d8d6;
  -webkit-overflow-scrolling: touch;
}
.source-artifact-detail img {
  display: block;
  min-width: 100%;
  height: auto;
  margin: 0 auto;
  background: #fff;
}
.source-artifact-detail-status {
  display: grid;
  place-items: center;
  min-height: 100%;
  margin: 0;
  padding: 24px;
  color: #3a434e;
  font-weight: 650;
  text-align: center;
}

@media (max-width: 520px) {
  .source-artifact-preview,
  .source-artifact-preview img { max-height: 300px; }
  .source-artifact-backdrop { padding-inline: 0; }
  .source-artifact-dialog {
    width: 100%;
    height: 100dvh;
    max-height: none;
    border-width: 0;
    border-radius: 0;
  }
  .source-artifact-toolbar { padding-left: 12px; }
}
