/* ---------- tokens ---------- */
:root {
  --green: #58cc02; --green-d: #58a700;
  --blue: #1cb0f6; --blue-d: #1899d6;
  --red: #ff4b4b; --red-d: #ea2b2b;
  --orange: #ff9600; --orange-d: #e08600;
  --purple: #ce82ff; --purple-d: #a568cc;
  --gold: #ffc800; --gold-d: #e5a800;

  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f7f7;
  --border: #e5e5e5;
  --border-d: #cfcfcf;
  --text: #3c3c3c;
  --muted: #777777;
  --node-off: #e5e5e5; --node-off-d: #b7b7b7;

  --ok-bg: #d7ffb8; --ok-text: #58a700;
  --bad-bg: #ffdfe0; --bad-text: #ea2b2b;
  --sel-bg: #ddf4ff; --sel-border: #84d8ff; --sel-text: #1899d6;
  --shadow-pop: 0 10px 30px rgba(0, 0, 0, .14);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131f24; --surface: #131f24; --surface-2: #202f36;
    --border: #37464f; --border-d: #52656f;
    --text: #f1f7fb; --muted: #8fa3ad;
    --node-off: #37464f; --node-off-d: #25333a;
    --ok-bg: #1f3310; --ok-text: #79d634;
    --bad-bg: #3a1a1c; --bad-text: #ff7b7b;
    --sel-bg: #1b3848; --sel-border: #3f84a8; --sel-text: #49c0f8;
    --shadow-pop: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131f24; --surface: #131f24; --surface-2: #202f36;
  --border: #37464f; --border-d: #52656f;
  --text: #f1f7fb; --muted: #8fa3ad;
  --node-off: #37464f; --node-off-d: #25333a;
  --ok-bg: #1f3310; --ok-text: #79d634;
  --bad-bg: #3a1a1c; --bad-text: #ff7b7b;
  --sel-bg: #1b3848; --sel-border: #3f84a8; --sel-text: #49c0f8;
  --shadow-pop: 0 10px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

.c-green  { --c: var(--green);  --cd: var(--green-d); }
.c-blue   { --c: var(--blue);   --cd: var(--blue-d); }
.c-orange { --c: var(--orange); --cd: var(--orange-d); }
.c-purple { --c: var(--purple); --cd: var(--purple-d); }
.c-red    { --c: var(--red);    --cd: var(--red-d); }
.c-teal   { --c: #00b894;       --cd: #008f73; }

.k-fin    { --k: var(--blue);   --k-bg: rgba(28, 176, 246, .13); }
.k-idiom  { --k: var(--orange); --k-bg: rgba(255, 150, 0, .15); }
.k-marker { --k: var(--purple); --k-bg: rgba(206, 130, 255, .18); }
.k-saved  { --k: var(--gold);   --k-bg: rgba(255, 200, 0, .25); }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: Nunito, ui-rounded, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-weight: 600;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
body.in-lesson { overflow: hidden; }
a { color: var(--blue); }
h1 { font-size: 30px; font-weight: 900; margin: 0 0 6px; }
h2, h3 { font-weight: 900; }
h3 { font-size: 17px; margin: 0; }
p { line-height: 1.5; }
button { font-family: inherit; }
input, textarea { font-family: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.center { justify-content: center; }
.grow { flex: 1; }
.linklike { background: none; border: none; cursor: pointer; text-decoration: underline; padding: 0; text-align: left; }
.section-title { font-size: 20px; margin: 32px 0 12px; }

/* ---------- shell & nav ---------- */
.shell { display: flex; min-height: 100vh; }
#view { flex: 1; min-width: 0; }
.page { max-width: 1120px; margin: 0 auto; padding: 28px 28px 80px; }
.page-head { margin-bottom: 22px; }
.page-head p { margin: 0; }

.nav {
  position: sticky; top: 0; height: 100vh; width: 240px; flex: none;
  border-right: 2px solid var(--border);
  padding: 22px 14px; display: flex; flex-direction: column; gap: 6px;
  background: var(--bg); z-index: 20;
}
.nav a {
  display: flex; align-items: center; gap: 14px; position: relative;
  padding: 10px 14px; border-radius: 14px; border: 2px solid transparent;
  font-weight: 800; font-size: 14px; letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted); text-decoration: none;
}
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--sel-bg); border-color: var(--sel-border); color: var(--sel-text); }
.nav .ni { font-size: 24px; width: 32px; text-align: center; }
.nav .brand { font-size: 30px; font-weight: 900; color: var(--green); text-transform: lowercase; letter-spacing: -.02em; margin: 0 0 18px; gap: 10px; }
.nav .brand:hover { background: none; }
.due-badge {
  margin-left: auto; background: var(--red); color: #fff; font-size: 12px; font-weight: 900;
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 99px; display: grid; place-items: center;
}

/* ---------- buttons ---------- */
.btn {
  --shadow: var(--border);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 800; font-size: 14px; letter-spacing: .05em; text-transform: uppercase; text-decoration: none;
  padding: 12px 20px; border-radius: 14px; border: 2px solid var(--border);
  background: var(--surface); color: var(--blue);
  box-shadow: 0 4px 0 var(--shadow); cursor: pointer;
  transition: transform .06s, box-shadow .06s, filter .15s;
  margin-bottom: 4px;
}
.btn:hover:not(:disabled) { filter: brightness(1.05); }
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 0 0 var(--shadow); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; --shadow: var(--green-d); }
.btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; --shadow: var(--blue-d); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn:disabled { background: var(--node-off); border-color: var(--node-off); color: var(--muted); --shadow: var(--node-off); cursor: default; }
.btn.ghost:disabled { background: transparent; border-color: var(--border); }
.btn.small { padding: 8px 14px; font-size: 12px; border-radius: 12px; }
.btn.big { padding: 14px 28px; font-size: 15px; min-width: 200px; }
.btn svg { flex: none; }

.icon-btn {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  padding: 6px; border-radius: 10px; display: inline-grid; place-items: center; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 800; font-size: 13px; padding: 6px 12px; border-radius: 99px;
  border: 2px solid var(--border); background: var(--surface); color: var(--muted);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.pill:hover { background: var(--surface-2); }
.pill.on { border-color: var(--sel-border); background: var(--sel-bg); color: var(--sel-text); }

.speak {
  border: none; background: transparent; color: var(--blue); cursor: pointer;
  padding: 4px; border-radius: 8px; display: inline-grid; place-items: center; vertical-align: middle; flex: none;
}
.speak:hover { background: rgba(28, 176, 246, .14); }
.speak.sm svg { width: 18px; height: 18px; }

.card { background: var(--surface); border: 2px solid var(--border); border-radius: 16px; padding: 18px; }

.chip {
  display: inline-block; font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: .06em;
  color: var(--k, var(--muted)); background: var(--k-bg, var(--surface-2)); padding: 4px 8px; border-radius: 8px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-term {
  font-size: 14px; font-weight: 800; padding: 5px 10px; border-radius: 10px; cursor: pointer;
  border: 2px solid var(--k); background: var(--k-bg); color: var(--text); box-shadow: none;
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--k); margin-right: 6px; vertical-align: middle; }

/* ---------- progress ---------- */
.progress { flex: 1; height: 16px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress-bar { position: relative; height: 100%; width: 0; background: var(--green); border-radius: 99px; transition: width .45s cubic-bezier(.3, 1.3, .6, 1); }
.progress-bar::after { content: ''; position: absolute; top: 4px; left: 8px; right: 8px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .3); }
.progress-bar.gold { background: var(--gold); }

/* ---------- learn (home) ---------- */
.learn-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 44px; align-items: start; }
.unit { margin-bottom: 30px; }
.unit-banner {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 18px 22px; border-radius: 16px; color: #fff; background: var(--c); box-shadow: 0 4px 0 var(--cd);
}
.unit-banner h2 { margin: 2px 0; font-size: 22px; }
.unit-banner p { margin: 0; opacity: .92; font-weight: 700; }
.unit-kicker { font-size: 13px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; opacity: .85; }
.unit-count { font-weight: 900; font-size: 15px; background: rgba(0, 0, 0, .15); padding: 6px 12px; border-radius: 99px; white-space: nowrap; }
.nodes { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 34px 0 14px; }
.node-wrap { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; transform: translateX(var(--dx)); }
.node-wrap:has(.node-tip):not(:first-child) { margin-top: 34px; }
.node {
  width: 76px; height: 70px; border-radius: 50%; display: grid; place-items: center; text-decoration: none;
  font-size: 30px; font-weight: 900; color: #fff;
  background: var(--node-off); box-shadow: 0 8px 0 var(--node-off-d);
  transition: transform .08s, box-shadow .08s;
}
.node:hover { filter: brightness(1.05); }
.node:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--node-off-d); }
.node.next { background: var(--c); box-shadow: 0 8px 0 var(--cd); outline: 6px solid color-mix(in srgb, var(--c) 28%, transparent); outline-offset: 5px; }
.node.done { background: var(--gold); box-shadow: 0 8px 0 var(--gold-d); }
.node.open .node-icon { opacity: .75; }
.node-title { font-weight: 800; font-size: 14px; max-width: 200px; text-align: center; }
.node-tip {
  position: absolute; top: -46px; z-index: 1;
  background: var(--surface); color: var(--c); border: 2px solid var(--border);
  font-weight: 900; font-size: 14px; letter-spacing: .06em; padding: 7px 12px; border-radius: 12px;
  animation: bob 1.4s ease-in-out infinite;
}
.node-tip::after {
  content: ''; position: absolute; left: 50%; bottom: -8px; width: 12px; height: 12px; transform: translateX(-50%) rotate(45deg);
  background: var(--surface); border-right: 2px solid var(--border); border-bottom: 2px solid var(--border);
}

.side { position: sticky; top: 24px; display: flex; flex-direction: column; gap: 16px; }
.stat-row { display: flex; justify-content: space-around; }
.stat { display: flex; align-items: center; gap: 6px; font-size: 19px; font-weight: 900; color: var(--text); text-decoration: none; padding: 6px 12px; border-radius: 12px; }
a.stat:hover { background: var(--surface-2); }
.goal-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.week { display: flex; gap: 8px; margin-top: 16px; }
.day { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; }
.day-bar { width: 100%; height: 44px; background: var(--surface-2); border-radius: 8px; display: flex; align-items: flex-end; overflow: hidden; }
.day-bar i { display: block; width: 100%; background: var(--gold); border-radius: 6px 6px 0 0; }
.day.today span { color: var(--blue); }
.today-card { display: flex; flex-direction: column; gap: 4px; }
.today-card h3 { margin-bottom: 6px; }
.todo { display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 12px; color: var(--text); text-decoration: none; }
.todo:hover { background: var(--surface-2); }
.todo-icon { font-size: 24px; width: 36px; text-align: center; flex: none; }
.todo b { display: block; font-weight: 800; }
.todo small { display: block; color: var(--muted); font-size: 13px; }

/* ---------- lesson player ---------- */
#overlay { position: fixed; inset: 0; z-index: 50; background: var(--bg); overflow: auto; }
.lesson { min-height: 100%; display: flex; flex-direction: column; }
.lesson-top { width: 100%; max-width: 1000px; margin: 0 auto; padding: 24px 24px 8px; display: flex; align-items: center; gap: 16px; }
.hearts { display: flex; align-items: center; gap: 6px; color: var(--red); font-weight: 900; font-size: 18px; }
.heart { font-size: 24px; line-height: 1; }
.hearts.lost { animation: shake .5s; }
.lesson-body { flex: 1; display: flex; justify-content: center; padding: 28px 20px 40px; }
.ex-wrap { width: 100%; max-width: 640px; }
.ex.enter { animation: slidein .25s ease-out; }
.ex-title { font-size: 28px; margin: 0 0 24px; line-height: 1.25; }

.lesson-foot { position: sticky; bottom: 0; border-top: 2px solid var(--border); background: var(--bg); padding: 20px 24px calc(20px + env(safe-area-inset-bottom)); }
.lesson-foot.ok { background: var(--ok-bg); border-top-color: transparent; }
.lesson-foot.bad { background: var(--bad-bg); border-top-color: transparent; }
.foot-inner { max-width: 1000px; margin: 0 auto; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.feedback { flex: 1 1 380px; animation: popin .15s ease-out; }
.fb-title { font-size: 22px; font-weight: 900; }
.ok .fb-title { color: var(--ok-text); }
.bad .fb-title, .fb-answer { color: var(--bad-text); }
.fb-answer { font-weight: 800; font-size: 17px; }
.fb-said { display: flex; align-items: center; gap: 4px; margin-top: 6px; font-style: italic; }
.fb-explain { margin: 6px 0 0; }
.fb-terms { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.foot-actions { display: flex; gap: 12px; margin-left: auto; }
.foot-actions .main { min-width: 180px; }
.lesson-foot.bad .main { background: var(--red); border-color: var(--red); --shadow: var(--red-d); }

.options { display: flex; flex-direction: column; gap: 12px; }
.options.grid2 { display: grid; grid-template-columns: 1fr 1fr; }
.option {
  display: flex; align-items: center; gap: 14px; text-align: left;
  font-weight: 700; font-size: 17px; line-height: 1.35; color: var(--text);
  background: var(--surface); border: 2px solid var(--border); border-radius: 14px; box-shadow: 0 4px 0 var(--border);
  padding: 14px 16px; cursor: pointer; transition: transform .06s;
}
.option:hover:not(:disabled) { background: var(--surface-2); }
.option:active:not(:disabled) { transform: translateY(2px); }
.option kbd {
  flex: none; display: grid; place-items: center; min-width: 30px; height: 30px; border: 2px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 13px; font-weight: 800; color: var(--muted);
}
.option.selected { background: var(--sel-bg); border-color: var(--sel-border); color: var(--sel-text); box-shadow: 0 4px 0 var(--sel-border); }
.option.selected kbd { border-color: var(--sel-border); color: var(--sel-text); }
.option.correct { background: var(--ok-bg); border-color: var(--green); color: var(--ok-text); box-shadow: 0 4px 0 var(--green); }
.option.wrong { background: var(--bad-bg); border-color: var(--red); color: var(--bad-text); box-shadow: 0 4px 0 var(--red); animation: shake .4s; }
.option.paired { opacity: .4; box-shadow: none; }
.option:disabled { cursor: default; }

.quote { display: flex; gap: 10px; align-items: flex-start; margin: 0 0 26px; }
.quote blockquote {
  flex: 1; margin: 0; padding: 14px 18px; border: 2px solid var(--border); border-radius: 16px;
  font-size: 20px; font-weight: 700; line-height: 1.5;
}
.quote .speak { margin-top: 10px; }

.audio-row { display: flex; gap: 16px; justify-content: center; align-items: flex-end; margin: 6px 0 30px; }
.audio-btn {
  width: 116px; height: 116px; border-radius: 24px; border: none; cursor: pointer; display: grid; place-items: center;
  background: var(--blue); color: #fff; box-shadow: 0 6px 0 var(--blue-d); transition: transform .06s, box-shadow .06s;
}
.audio-btn svg { width: 52px; height: 52px; }
.audio-btn.slow { width: 74px; height: 74px; border-radius: 18px; }
.audio-btn.slow svg { width: 34px; height: 34px; }
.audio-btn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--blue-d); }

.curve { margin: 0 0 24px; border: 2px solid var(--border); border-radius: 16px; padding: 12px 12px 8px; }
.curve svg { width: 100%; height: auto; display: block; }
.curve .grid { stroke: var(--border); stroke-width: 1; }
.curve .axis { fill: var(--muted); font-size: 12px; font-weight: 700; }
.curve .before { fill: none; stroke: var(--muted); stroke-width: 3; stroke-dasharray: 6 6; }
.curve .before-dot { fill: var(--muted); }
.curve .after { fill: none; stroke: var(--blue); stroke-width: 4; stroke-linejoin: round; }
.curve .after-dot { fill: var(--blue); stroke: var(--surface); stroke-width: 2; }
.curve .delta { font-size: 12px; font-weight: 900; }
.curve .delta.up { fill: var(--red); }
.curve .delta.down { fill: var(--green-d); }
.curve figcaption { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; padding: 4px 6px 2px; }
.lg { display: inline-block; width: 22px; height: 0; border-top: 3px dashed var(--muted); }
.lg.after-lg { border-top: 4px solid var(--blue); margin-left: 8px; }

.match { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.match .col { display: flex; flex-direction: column; gap: 12px; }
.match-item { min-height: 58px; font-size: 16px; }

.build-prompt { margin-bottom: 8px; }
.bubble { display: inline-block; padding: 12px 16px; border: 2px solid var(--border); border-radius: 16px; font-size: 19px; font-weight: 700; }
.build-answer {
  min-height: 70px; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 8px; padding: 10px 0; margin: 22px 0;
  border-top: 2px solid var(--border); border-bottom: 2px solid var(--border);
}
.build-answer.correct { border-color: var(--green); }
.build-answer.wrong { border-color: var(--red); }
.build-bank { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.tile {
  font-weight: 700; font-size: 17px; padding: 10px 14px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--border); box-shadow: 0 3px 0 var(--border); background: var(--surface); color: var(--text);
}
.tile:active { transform: translateY(2px); }
.tile.used { background: var(--border); color: transparent; box-shadow: none; pointer-events: none; }

.text-answer {
  width: 100%; font-size: 20px; font-weight: 700; padding: 16px 18px; border-radius: 14px;
  border: 2px solid var(--border); background: var(--surface-2); color: var(--text);
}
.text-answer:focus { outline: none; border-color: var(--blue); }
.text-answer.correct { border-color: var(--green); }
.text-answer.wrong { border-color: var(--red); }

.lesson-end { max-width: 580px; margin: 0 auto; padding: 72px 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.lesson-end h1 { color: var(--gold-d); font-size: 32px; margin: 0; }
.end-badge { font-size: 92px; line-height: 1; animation: pop .5s ease-out; }
.end-stats { display: flex; gap: 14px; margin: 18px 0; flex-wrap: wrap; justify-content: center; }
.stat-box { --c: var(--green); border: 2px solid var(--c); border-radius: 16px; overflow: hidden; min-width: 130px; background: var(--c); }
.stat-box span { display: block; color: #fff; font-weight: 900; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; padding: 6px; }
.stat-box b { display: block; padding: 12px; font-size: 22px; color: var(--c); background: var(--surface); border-radius: 13px 13px 0 0; }
.stat-box.yellow { --c: var(--gold); }
.stat-box.blue { --c: var(--blue); }
.end-note { font-weight: 800; }
.end-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

/* ---------- highlighted text ---------- */
.term { cursor: pointer; border-radius: 4px; padding: 0 1px; background: var(--k-bg); box-shadow: inset 0 -2px 0 var(--k); transition: background .15s; }
.term:hover, .term.active { background: color-mix(in srgb, var(--k) 30%, transparent); }
.term:focus-visible { outline: 2px solid var(--k); outline-offset: 1px; }
.term.flash { animation: flash 1.2s; }
.chip-term.term { box-shadow: none; padding: 5px 10px; }
.w { cursor: pointer; border-radius: 3px; }
.w:hover, .w.active { background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--border-d); }
.w.saved { background: rgba(255, 200, 0, .25); box-shadow: inset 0 -2px 0 var(--gold); }

/* ---------- popover ---------- */
.popover {
  position: fixed; z-index: 100; width: 350px; max-width: calc(100vw - 16px);
  background: var(--surface); border: 2px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-pop);
  padding: 12px 16px 14px; animation: popin .12s ease-out;
  font-family: Nunito, system-ui, sans-serif; font-size: 15px; line-height: 1.4;
}
.popover.sheet { left: 0; right: 0; bottom: 0; top: auto; width: auto; max-width: none; border-radius: 20px 20px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
.pop-head { display: flex; justify-content: space-between; align-items: center; }
.pop-term { display: flex; align-items: center; gap: 6px; font-size: 22px; font-weight: 900; margin-top: 4px; }
.pop-es { font-size: 17px; font-weight: 800; color: var(--ok-text); }
.pop-def { margin: 8px 0; font-size: 14px; }
.pop-ex { display: flex; align-items: flex-start; gap: 4px; margin: 0; font-size: 14px; color: var(--muted); }
.pop-links { display: flex; flex-wrap: wrap; gap: 14px; margin: 8px 0 12px; }
.pop-links a { font-weight: 800; font-size: 13px; text-decoration: none; display: inline-flex; gap: 4px; align-items: center; }
.pop-label { display: block; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 4px; }
.pop-input { width: 100%; font-size: 15px; font-weight: 700; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--border); background: var(--surface-2); color: var(--text); }
.pop-input:focus { outline: none; border-color: var(--blue); }
.pop-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 12px; }
.pop-actions .btn { margin-left: auto; }

/* ---------- report dialog, toast ---------- */
.flag-btn {
  background: none; border: none; cursor: pointer; padding: 4px 0; margin-top: 8px;
  font-size: 13px; font-weight: 800; color: var(--muted); text-decoration: underline; text-underline-offset: 3px;
}
.flag-btn:hover { color: var(--text); }
.pop-actions .flag-btn { margin-top: 0; }
.modal {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow: auto;
  border: 2px solid var(--border); border-radius: 20px; padding: 20px 22px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-pop);
}
.modal::backdrop { background: rgba(0, 0, 0, .45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-size: 21px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.ctx-box { border: 2px dashed var(--border); border-radius: 14px; padding: 12px 14px; margin: 10px 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.ctx-box blockquote { margin: 0; padding-left: 10px; border-left: 3px solid var(--border-d); font-style: italic; }
.ctx-prompt { font-weight: 800; }
.ctx-ans.ok { color: var(--ok-text); }
.ctx-ans.bad { color: var(--bad-text); }
.reasons { border: none; padding: 0; margin: 12px 0 6px; display: flex; flex-direction: column; gap: 6px; }
.reasons legend { font-weight: 900; margin-bottom: 6px; padding: 0; }
.reason { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border: 2px solid var(--border); border-radius: 12px; cursor: pointer; font-size: 14px; }
.reason:has(input:checked) { border-color: var(--sel-border); background: var(--sel-bg); color: var(--sel-text); }
.reason input { accent-color: var(--blue); margin: 0; }
.field-label { display: block; font-weight: 800; font-size: 14px; margin: 12px 0 6px; }
.modal textarea, .new-form textarea, .new-form input, .new-form select, .comment-form input {
  width: 100%; font-size: 15px; font-weight: 600; padding: 10px 12px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--surface-2); color: var(--text); resize: vertical;
}
.modal textarea:focus, .new-form :is(textarea, input, select):focus, .comment-form input:focus { outline: none; border-color: var(--blue); }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 200;
  background: var(--text); color: var(--bg); font-weight: 800; padding: 12px 18px; border-radius: 14px;
  box-shadow: var(--shadow-pop); animation: popin .2s ease-out; transition: opacity .3s, transform .3s;
}
.toast.bad { background: var(--red); color: #fff; }
.toast.out { opacity: 0; transform: translate(-50%, 8px); }

/* ---------- bitácora ---------- */
.log-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters .pill b { margin-left: 2px; }
.new-form { margin-bottom: 18px; }
.new-form h3 { margin-bottom: 4px; }
.new-form .row { margin-top: 14px; }
.posts { display: flex; flex-direction: column; gap: 14px; }
.post { display: flex; flex-direction: column; gap: 8px; padding: 18px 20px; }
.post.s-fixed { border-color: color-mix(in srgb, var(--green) 45%, var(--border)); }
.post.s-wontfix { opacity: .75; }
.post-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.post-title { font-size: 18px; margin: 2px 0 0; }
.post-note { margin: 0; white-space: pre-wrap; }
.status-pill { font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .05em; padding: 4px 10px; border-radius: 99px; color: #fff; background: var(--orange); }
.status-pill.fixed { background: var(--green); }
.status-pill.wontfix { background: var(--muted); }
.comments { display: flex; flex-direction: column; gap: 8px; border-top: 2px solid var(--border); padding-top: 10px; margin-top: 4px; }
.comment { padding: 8px 12px; border-radius: 12px; background: var(--surface-2); }
.comment.claude { background: rgba(206, 130, 255, .12); border: 2px solid rgba(206, 130, 255, .35); }
.comment-head { display: flex; gap: 8px; align-items: baseline; font-size: 14px; }
.comment p { margin: 2px 0 0; white-space: pre-wrap; font-size: 14px; }
.comment-form { display: flex; gap: 8px; align-items: center; }
.comment-form .btn { flex: none; }
.post-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.log code { font-size: 13px; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }

/* ---------- transcript loading ---------- */
.tr-loading { display: flex; align-items: center; gap: 12px; padding: 24px 16px; color: var(--muted); font-weight: 800; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--blue); animation: spin .8s linear infinite; flex: none; }
.src-badge { font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: .05em; padding: 3px 8px; border-radius: 8px; background: var(--sel-bg); color: var(--sel-text); }
.src-badge.pasted { background: rgba(255, 200, 0, .25); color: var(--gold-d); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- watch ---------- */
.page.watch { max-width: 1440px; }
.watch-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(330px, 1fr); gap: 20px; align-items: start; }
.player-card { padding: 0; overflow: hidden; }
.player-frame { aspect-ratio: 16 / 9; background: #000; }
.player-frame iframe, .player-frame #yt { width: 100%; height: 100%; display: block; border: 0; }
.player-bar { display: flex; align-items: center; gap: 10px; padding: 12px 14px; flex-wrap: wrap; }
.now { flex: 1; min-width: 180px; display: flex; flex-direction: column; }
.speeds { display: flex; gap: 6px; }
.sources { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; margin-top: 16px; }
.source { display: flex; flex-direction: column; gap: 6px; }
.source p { margin: 0; }
.source-head { display: flex; gap: 12px; align-items: center; }
.source-icon { font-size: 30px; }
.episodes { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.episode {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  font-weight: 700; font-size: 14px; color: var(--text); background: transparent;
  border: 2px solid transparent; border-radius: 12px; padding: 7px 8px; cursor: pointer;
}
.episode:hover { background: var(--surface-2); }
.episode.on { background: var(--sel-bg); border-color: var(--sel-border); }
.ep-play { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--red); color: #fff; }
.episode.latest .ep-play { background: var(--muted); }
a.episode { text-decoration: none; }
.show-cards { display: contents; }
.list-note { grid-column: 1 / -1; margin: -6px 0 0; }
.list-note:empty { display: none; }
.tip-box { padding: 10px 12px; border-radius: 12px; background: var(--sel-bg); border: 2px solid var(--sel-border); line-height: 1.5; }
.tip-box code, .tr-empty code { font-size: 12px; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.ep-title { flex: 1; }
.ep-date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.ep-badge { font-size: 13px; }
.spotify summary { cursor: pointer; font-weight: 800; font-size: 14px; color: var(--blue); padding: 6px 0; }
.spotify iframe { width: 100%; border: 0; border-radius: 12px; margin: 6px 0; }
.url-form { display: flex; flex-direction: column; gap: 6px; }
.url-form p { margin: 0; }
.url-form input, .paste, .tr-input, .gl-search {
  width: 100%; font-size: 15px; font-weight: 600; padding: 12px 14px; border-radius: 14px;
  border: 2px solid var(--border); background: var(--surface-2); color: var(--text);
}
.url-form input:focus, .paste:focus, .tr-input:focus, .gl-search:focus { outline: none; border-color: var(--blue); }
.url-form .row { margin-top: 4px; }
.url-form .btn { margin-bottom: 4px; }
.shake { animation: shake .4s; border-color: var(--red) !important; }

.transcript-col { position: sticky; top: 16px; display: flex; flex-direction: column; height: calc(100vh - 32px); padding: 0; overflow: hidden; }
.tr-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 16px; border-bottom: 2px solid var(--border); }
.tr-head h2 { margin: 0; font-size: 18px; }
.tr-tools { display: flex; gap: 14px; }
.tr-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tr-toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 14px 6px; border-bottom: 2px solid var(--border); flex-wrap: wrap; }
.tr-lines { position: relative; flex: 1; overflow: auto; padding: 8px; }
.tline { display: grid; grid-template-columns: 52px 1fr 30px; gap: 6px; align-items: start; padding: 8px; border-radius: 12px; font-size: 15px; line-height: 1.55; }
.tline.now { background: var(--sel-bg); }
.ts { background: none; border: none; cursor: pointer; padding: 2px 0; text-align: left; font-size: 12px; font-weight: 800; color: var(--blue); font-variant-numeric: tabular-nums; }
.ts:hover { text-decoration: underline; }
.loop { opacity: 0; padding: 4px; }
.tline:hover .loop, .tline.now .loop { opacity: 1; }
.tr-lines.blurred .tx { filter: blur(5px); transition: filter .2s; cursor: pointer; }
.tr-lines.blurred .tline:hover .tx, .tr-lines.blurred .tline.reveal .tx { filter: none; }
.tr-empty { padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.tr-lead { margin: 0; }
.steps { margin: 0; padding-left: 22px; line-height: 1.55; }
.steps li { margin: 4px 0; }
.steps a { font-weight: 800; text-decoration: none; }
.tr-input { resize: vertical; font-size: 14px; }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 800; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { position: relative; width: 34px; height: 20px; border-radius: 99px; background: var(--border); transition: background .2s; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: left .2s; }
.switch input:checked + span { background: var(--blue); }
.switch input:checked + span::after { left: 17px; }
.switch input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- read ---------- */
.hero-paste { display: grid; grid-template-columns: 1fr 1.15fr; gap: 28px; padding: 26px; }
.hero-text h2 { font-size: 24px; margin: 6px 0 8px; }
.hero-text p { margin: 0 0 14px; }
.eyebrow { font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; color: var(--purple-d); }
.paste-box { display: flex; flex-direction: column; gap: 12px; }
.paste { resize: vertical; min-height: 220px; line-height: 1.5; }
.text-list { display: flex; flex-direction: column; gap: 10px; }
.text-item { display: flex; align-items: center; padding: 4px 8px 4px 16px; }
.text-open { flex: 1; display: flex; flex-direction: column; gap: 2px; text-align: left; background: none; border: none; color: var(--text); cursor: pointer; padding: 10px 0; font-size: 15px; }
.text-open:hover b { color: var(--blue); }

.reader-top { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.reader-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.article { padding: 28px 32px; }
.article-title { font-size: 26px; margin: 0 0 8px; }
.stats-row { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.stats-row b { color: var(--text); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin: 14px 0 22px; padding: 10px 14px; border-radius: 12px; background: var(--surface-2); }
.legend .dot { margin-right: 4px; }
.article-body { font-family: Georgia, 'Iowan Old Style', 'Times New Roman', serif; font-weight: 400; font-size: 19px; line-height: 1.75; }
.para { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 6px; }
.para p { margin: 0 0 20px; padding: 0 4px; border-radius: 8px; }
.para-play {
  width: 28px; height: 28px; margin-top: 6px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  border: 2px solid var(--border); background: var(--surface); color: var(--muted); opacity: .5;
}
.para:hover .para-play { opacity: 1; }
.para.playing .para-play { background: var(--blue); border-color: var(--blue); color: #fff; opacity: 1; }
.para.playing p { background: rgba(28, 176, 246, .07); }
.reader-side { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 16px; }
.side-card h3 { margin-bottom: 4px; }
.term-group h4 { margin: 14px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }
.tip { background: rgba(206, 130, 255, .08); border-color: rgba(206, 130, 255, .45); }
.tip p { margin: 6px 0 0; }

/* ---------- review ---------- */
.review-top { display: flex; align-items: center; gap: 16px; max-width: 700px; margin: 0 auto 28px; }
.flashcard-wrap { max-width: 640px; margin: 0 auto; }
.flashcard { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 34px 28px; text-align: center; animation: slidein .2s ease-out; }
.fc-term { font-size: 34px; font-weight: 900; display: flex; align-items: center; gap: 6px; }
.fc-ex { display: flex; align-items: flex-start; gap: 4px; margin: 0; font-size: 17px; color: var(--muted); }
.fc-back { border-top: 2px dashed var(--border); padding-top: 16px; width: 100%; }
.fc-es { font-size: 24px; font-weight: 900; color: var(--ok-text); }
.fc-def { max-width: 480px; margin: 8px auto 0; }
.fc-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.grade { flex-direction: column; gap: 2px; min-width: 130px; }
.grade small { font-size: 11px; opacity: .85; text-transform: none; letter-spacing: 0; }
.grade kbd { display: none; }
.grade.again { color: var(--red); }
.grade.good { background: var(--green); border-color: var(--green); color: #fff; --shadow: var(--green-d); }
.grade.easy { background: var(--blue); border-color: var(--blue); color: #fff; --shadow: var(--blue-d); }
.empty-state { max-width: 560px; margin: 32px auto; text-align: center; padding: 40px 28px; }
.empty-state h2 { margin: 8px 0; }
.big-emoji { font-size: 64px; }

/* ---------- glossary ---------- */
.gl-controls { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 0 14px; display: flex; flex-direction: column; gap: 12px; }
.gl-cats { display: flex; flex-wrap: wrap; gap: 8px; }
.gl-list { display: flex; flex-direction: column; gap: 10px; }
.gl-row { display: flex; align-items: flex-start; gap: 16px; padding: 14px 16px; }
.gl-main { flex: 1; min-width: 0; }
.gl-term { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-size: 17px; font-weight: 900; }
.gl-es { margin-left: 8px; color: var(--ok-text); font-weight: 800; }
.gl-def { margin: 4px 0; font-size: 14px; }
.gl-ex { display: flex; align-items: center; gap: 4px; margin: 0; font-size: 14px; color: var(--muted); }
.gl-note { width: 100%; margin: 6px 0; font-size: 14px; font-weight: 700; padding: 8px 12px; border-radius: 10px; border: 2px solid var(--border); background: var(--surface-2); color: var(--text); }

/* ---------- motion ---------- */
@keyframes slidein { from { opacity: 0; transform: translateX(28px); } }
@keyframes popin { from { opacity: 0; transform: translateY(6px) scale(.98); } }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.12); } }
@keyframes bob { 50% { transform: translateY(-5px); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes flash { 0%, 100% { background: var(--k-bg); } 25%, 65% { background: var(--gold); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- responsive ---------- */
@media (hover: none) { .option kbd { display: none; } }

@media (max-width: 1180px) {
  .nav { width: 88px; padding: 22px 12px; align-items: center; }
  .nav .nl, .nav .brand span { display: none; }
  .nav a { padding: 10px; justify-content: center; }
  .nav .due-badge { position: absolute; top: 2px; right: 2px; }
  .learn-grid { grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; }
}

@media (max-width: 1000px) {
  .learn-grid { grid-template-columns: 1fr; }
  .side { position: static; order: -1; display: grid; grid-template-columns: 1fr 1fr; }
  .side .stat-row { grid-column: 1 / -1; }
  .side > .muted, .side > .linklike { grid-column: 1 / -1; }
  .watch-grid, .reader-grid, .hero-paste { grid-template-columns: 1fr; }
  .transcript-col { position: static; height: 72vh; }
  .reader-side { position: static; }
}

@media (max-width: 760px) {
  .shell { display: block; }
  .nav {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; width: auto;
    flex-direction: row; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    border-right: none; border-top: 2px solid var(--border);
  }
  .nav .brand { display: none; }
  .nav a { flex: 1; min-width: 0; padding: 8px 0; }
  #view { padding-bottom: 76px; }
  .page { padding: 18px 16px 40px; }
  h1 { font-size: 26px; }
  .side { grid-template-columns: 1fr; }
  .node-wrap { transform: translateX(calc(var(--dx) * .6)); }
  .ex-title { font-size: 22px; margin-bottom: 18px; }
  .quote blockquote { font-size: 18px; }
  .options.grid2 { grid-template-columns: 1fr; }
  .option { font-size: 16px; padding: 12px 14px; }
  .match { gap: 10px; }
  .match-item { font-size: 14px; padding: 10px; }
  .lesson-top { padding: 16px 16px 4px; }
  .lesson-body { padding: 20px 16px 28px; }
  .lesson-foot { padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); }
  .foot-actions { width: 100%; }
  .foot-actions .main { flex: 1; min-width: 0; }
  .audio-btn { width: 96px; height: 96px; }
  .article { padding: 20px 18px; }
  .article-body { font-size: 18px; }
  .para { grid-template-columns: 1fr; }
  .para-play { display: none; }
  .hero-paste { padding: 18px; }
  .gl-row { flex-direction: column; gap: 8px; }
  .tline { grid-template-columns: 46px 1fr 26px; font-size: 14px; }
  .btn.big { min-width: 0; width: 100%; }
}
