:root {
  --font-sans: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-mono: Consolas, "SFMono-Regular", Menlo, monospace;
  --reader-font: var(--font-sans);
  --reader-size: 64px;
  --radius: 14px;
}

[data-theme="dark"] {
  --bg: #14120f;
  --card: #1e1b17;
  --stage: #0f0d0b;
  --text: #ece7de;
  --muted: #a39b8d;
  --border: #302b24;
  --accent: #ff5a4d;
  --accent-2: #66b39d;
  --control: #292520;
  --on-accent: #0b0d11;
  --control-hover: #342f28;
}
[data-theme="light"] {
  --bg: #f3eee5;
  --card: #fffdf9;
  --stage: #fbf8f2;
  --text: #1f1b16;
  --muted: #5c5448;
  --border: #ded5c4;
  --accent: #d92d2d;
  --accent-2: #2e5e52;
  --control: #ece6da;
  --control-hover: #e0d8c8;
}
[data-theme="sepia"] {
  --bg: #e9dfc9;
  --card: #f4ecd8;
  --stage: #f8f1df;
  --text: #3b3226;
  --muted: #625747;
  --border: #d8cbaa;
  --accent: #b3341f;
  --accent-2: #86571b;
  --control: #eadfc3;
  --control-hover: #dfd1ae;
}
[data-theme="midnight"] {
  --bg: #05070f;
  --card: #0b1020;
  --stage: #03050b;
  --text: #dbe4ff;
  --muted: #808fb2;
  --border: #1a2340;
  --accent: #ff6b8a;
  --accent-2: #6ea8ff;
  --control: #121a30;
  --on-accent: #0b0d11;
  --control-hover: #1a2542;
}
[data-theme="amoled"] {
  --bg: #000000;
  --card: #0a0a0a;
  --stage: #000000;
  --text: #f2f2f2;
  --muted: #8a8a8a;
  --border: #1c1c1c;
  --accent: #ff3b3b;
  --accent-2: #4da3ff;
  --control: #151515;
  --on-accent: #0b0d11;
  --control-hover: #222222;
}
[data-theme="solarized"] {
  --bg: #002b36;
  --card: #073642;
  --stage: #002129;
  --text: #eee8d5;
  --muted: #b4bdbd;
  --border: #0f4a58;
  --accent: #df4441;
  --accent-2: #55a3da;
  --control: #0b3d4a;
  --on-accent: #0b0d11;
  --control-hover: #12505f;
}
[data-theme="forest"] {
  --bg: #0f1a14;
  --card: #16251c;
  --stage: #0b130f;
  --text: #e1efe5;
  --muted: #94ac9d;
  --border: #223a2c;
  --accent: #f08a4b;
  --accent-2: #5fcf8a;
  --control: #1c3024;
  --on-accent: #0b0d11;
  --control-hover: #25402f;
}
[data-theme="nord"] {
  --bg: #2e3440;
  --card: #3b4252;
  --stage: #2a303b;
  --text: #eceff4;
  --muted: #c6ced6;
  --border: #4c566a;
  --accent: #cb7b82;
  --accent-2: #88c0d0;
  --control: #434c5e;
  --on-accent: #0b0d11;
  --control-hover: #4c566a;
}
[data-theme="rose"] {
  --bg: #f8eef0;
  --card: #fffafb;
  --stage: #fff5f7;
  --text: #3a2229;
  --muted: #6d545c;
  --border: #ecd3d9;
  --accent: #c2185b;
  --accent-2: #7b4bc2;
  --control: #f5e1e6;
  --control-hover: #eccdd5;
}
[data-theme="paper"] {
  --bg: #e8e8e6;
  --card: #f7f7f5;
  --stage: #fcfcfa;
  --text: #222222;
  --muted: #5e5e5e;
  --border: #d4d4d0;
  --accent: #b00020;
  --accent-2: #1f5fbf;
  --control: #ececea;
  --control-hover: #dededa;
}

/* More themes: the light or dark partner of an older theme, and new families. Light variants of
   several families are richly tinted, not near-white. Every variant passes tests/contrast.test.js;
   src/ui/themes.js lists the families. */
[data-theme="midnight-light"] {
  --bg: #eaedf6;
  --card: #fcfcfd;
  --stage: #f9f9fb;
  --text: #141924;
  --muted: #4f5a72;
  --border: #bfcae3;
  --accent: #c3133f;
  --accent-2: #1646b6;
  --control: #dfe4f1;
  --control-hover: #cdd6ea;
}
[data-theme="solarized-light"] {
  --bg: #efe4c8;
  --card: #f6f0df;
  --stage: #f8f4e7;
  --text: #242014;
  --muted: #605843;
  --border: #dac281;
  --accent: #c32213;
  --accent-2: #14659f;
  --control: #e9dbb4;
  --control-hover: #e3d2a0;
}
[data-theme="forest-light"] {
  --bg: #cee9d7;
  --card: #e3f2e8;
  --stage: #eaf6ee;
  --text: #16221a;
  --muted: #3f5a48;
  --border: #8ecca3;
  --accent: #c35413;
  --accent-2: #0e7137;
  --control: #bce1c8;
  --control-hover: #abd9ba;
}
[data-theme="nord-light"] {
  --bg: #eceff3;
  --card: #fcfcfd;
  --stage: #f9fafb;
  --text: #161b22;
  --muted: #4d5c6f;
  --border: #c7cfdb;
  --accent: #c31322;
  --accent-2: #14709f;
  --control: #e3e7ed;
  --control-hover: #d3dae3;
}
[data-theme="terminal-light"] {
  --bg: #cdead7;
  --card: #e2f3e8;
  --stage: #eaf6ee;
  --text: #142419;
  --muted: #3f5a48;
  --border: #8dcea3;
  --accent: #c35c13;
  --accent-2: #0e7127;
  --control: #bbe2c8;
  --control-hover: #a9daba;
}
[data-theme="amoled-light"] {
  --bg: #f0f0f0;
  --card: #fcfcfc;
  --stage: #fafafa;
  --text: #1c1c1c;
  --muted: #5c5c5c;
  --border: #d1d1d1;
  --accent: #c31322;
  --accent-2: #1659b6;
  --control: #e8e8e8;
  --control-hover: #dbdbdb;
}
[data-theme="sepia-dark"] {
  --bg: #1c1812;
  --card: #28221a;
  --stage: #14110d;
  --text: #efebe6;
  --muted: #c0b5a5;
  --border: #41382a;
  --accent: #ee6e4f;
  --accent-2: #ecb665;
  --control: #352d22;
  --on-accent: #0b0d11;
  --control-hover: #443a2c;
}
[data-theme="paper-dark"] {
  --bg: #171717;
  --card: #212121;
  --stage: #111111;
  --text: #ebebeb;
  --muted: #b3b3b3;
  --border: #363636;
  --accent: #ee4f69;
  --accent-2: #659dec;
  --control: #2b2b2b;
  --on-accent: #0b0d11;
  --control-hover: #383838;
}
[data-theme="rose-dark"] {
  --bg: #1c1215;
  --card: #281a1f;
  --stage: #140d0f;
  --text: #efe6e9;
  --muted: #c0a5ae;
  --border: #412a32;
  --accent: #ee4f91;
  --accent-2: #b465ec;
  --control: #352228;
  --on-accent: #0b0d11;
  --control-hover: #442c34;
}
[data-theme="ocean-dark"] {
  --bg: #0f1a1f;
  --card: #16252d;
  --stage: #0b1316;
  --text: #e6ecf0;
  --muted: #a5b7c0;
  --border: #233c48;
  --accent: #ee6e4f;
  --accent-2: #65caec;
  --control: #1c303b;
  --on-accent: #0b0d11;
  --control-hover: #243f4c;
}
[data-theme="ocean-light"] {
  --bg: #cbe1eb;
  --card: #e1eef4;
  --stage: #e9f2f7;
  --text: #141f24;
  --muted: #3f515a;
  --border: #89bad2;
  --accent: #c33613;
  --accent-2: #106784;
  --control: #b9d6e4;
  --control-hover: #a6cbdd;
}
[data-theme="sunset-dark"] {
  --bg: #1e1410;
  --card: #2b1d17;
  --stage: #160f0c;
  --text: #f0e9e6;
  --muted: #c0ada5;
  --border: #462f25;
  --accent: #ee4f5c;
  --accent-2: #eca465;
  --control: #38261e;
  --on-accent: #0b0d11;
  --control-hover: #493127;
}
[data-theme="sunset-light"] {
  --bg: #f1d2c5;
  --card: #f7e6de;
  --stage: #f9ece6;
  --text: #241914;
  --muted: #5a473f;
  --border: #e0997b;
  --accent: #c31322;
  --accent-2: #884911;
  --control: #edc3b1;
  --control-hover: #e8b39c;
}
[data-theme="lavender-dark"] {
  --bg: #16111d;
  --card: #20182a;
  --stage: #100c15;
  --text: #eae6f0;
  --muted: #b0a5c0;
  --border: #332745;
  --accent: #ee4f9e;
  --accent-2: #9c6eed;
  --control: #291f37;
  --on-accent: #0b0d11;
  --control-hover: #352848;
}
[data-theme="lavender-light"] {
  --bg: #d9cdea;
  --card: #e9e2f3;
  --stage: #efeaf6;
  --text: #1b1424;
  --muted: #483d57;
  --border: #a88dce;
  --accent: #c3136b;
  --accent-2: #5116b6;
  --control: #cbbbe2;
  --control-hover: #bea9da;
}
[data-theme="mint-dark"] {
  --bg: #111d19;
  --card: #192924;
  --stage: #0c1512;
  --text: #e6f0ec;
  --muted: #a5c0b7;
  --border: #28433a;
  --accent: #ee694f;
  --accent-2: #65ecca;
  --control: #21362f;
  --on-accent: #0b0d11;
  --control-hover: #2a463d;
}
[data-theme="mint-light"] {
  --bg: #cdeae0;
  --card: #e2f3ed;
  --stage: #eaf6f2;
  --text: #15231e;
  --muted: #3f5a51;
  --border: #8dceb8;
  --accent: #c33113;
  --accent-2: #0d6d55;
  --control: #bbe2d5;
  --control-hover: #a9daca;
}
[data-theme="coffee-dark"] {
  --bg: #1d1711;
  --card: #2a2118;
  --stage: #15100c;
  --text: #f0eae6;
  --muted: #c0b2a5;
  --border: #453527;
  --accent: #ee644f;
  --accent-2: #eca865;
  --control: #372b1f;
  --on-accent: #0b0d11;
  --control-hover: #483728;
}
[data-theme="coffee-light"] {
  --bg: #eadacc;
  --card: #f3eae2;
  --stage: #f6efe9;
  --text: #241c14;
  --muted: #5a4c3f;
  --border: #d0ab8b;
  --accent: #c32b13;
  --accent-2: #8d4f11;
  --control: #e3cdba;
  --control-hover: #dcc0a8;
}
[data-theme="cherry-dark"] {
  --bg: #1e1012;
  --card: #2b171b;
  --stage: #160c0d;
  --text: #f0e6e7;
  --muted: #c0a5a9;
  --border: #46252b;
  --accent: #ee4f69;
  --accent-2: #ec7765;
  --control: #381e23;
  --on-accent: #0b0d11;
  --control-hover: #49272d;
}
[data-theme="cherry-light"] {
  --bg: #eccad0;
  --card: #f4e1e4;
  --stage: #f7e8eb;
  --text: #241416;
  --muted: #543b3f;
  --border: #d58693;
  --accent: #c31331;
  --accent-2: #a32714;
  --control: #e6b7bf;
  --control-hover: #dfa4ae;
}
[data-theme="slate-dark"] {
  --bg: #14161a;
  --card: #1d2025;
  --stage: #0f1013;
  --text: #e8eaed;
  --muted: #a9b1bc;
  --border: #2f343c;
  --accent: #ee844f;
  --accent-2: #65a8ec;
  --control: #262a31;
  --on-accent: #0b0d11;
  --control-hover: #31373f;
}
[data-theme="slate-light"] {
  --bg: #eeeff2;
  --card: #fcfcfd;
  --stage: #fafafa;
  --text: #191b1f;
  --muted: #535c6a;
  --border: #ccd0d7;
  --accent: #c34e13;
  --accent-2: #1666b6;
  --control: #e5e8eb;
  --control-hover: #d7dbe0;
}
[data-theme="citrus-dark"] {
  --bg: #1c1e10;
  --card: #282b17;
  --stage: #14160c;
  --text: #eef0e6;
  --muted: #bcc0a5;
  --border: #404625;
  --accent: #ee914f;
  --accent-2: #bfec65;
  --control: #34381e;
  --on-accent: #0b0d11;
  --control-hover: #434927;
}
[data-theme="citrus-light"] {
  --bg: #e9f0c7;
  --card: #f2f6df;
  --stage: #f6f9e7;
  --text: #222414;
  --muted: #5b6043;
  --border: #cddd7e;
  --accent: #c35c13;
  --accent-2: #50710e;
  --control: #e1ebb2;
  --control-hover: #d9e59e;
}
[data-theme="aurora-dark"] {
  --bg: #101e17;
  --card: #172b21;
  --stage: #0c1611;
  --text: #e6f0eb;
  --muted: #a5c0b3;
  --border: #254636;
  --accent: #c64fee;
  --accent-2: #65ecbf;
  --control: #1e382b;
  --on-accent: #0b0d11;
  --control-hover: #274938;
}
[data-theme="aurora-light"] {
  --bg: #cee9db;
  --card: #e3f2eb;
  --stage: #eaf6f0;
  --text: #14241c;
  --muted: #3f5a4d;
  --border: #8eccad;
  --accent: #9713c3;
  --accent-2: #0d6d4d;
  --control: #bce1cf;
  --control-hover: #abd9c2;
}
[data-theme="sakura-dark"] {
  --bg: #1d1117;
  --card: #2a1821;
  --stage: #150c11;
  --text: #f0e6eb;
  --muted: #c0a5b3;
  --border: #452736;
  --accent: #ee4f84;
  --accent-2: #ec65ec;
  --control: #371f2b;
  --on-accent: #0b0d11;
  --control-hover: #482838;
}
[data-theme="sakura-light"] {
  --bg: #eec9db;
  --card: #f5e0eb;
  --stage: #f8e8f0;
  --text: #24141c;
  --muted: #543b47;
  --border: #d883ad;
  --accent: #c3134e;
  --accent-2: #9a139a;
  --control: #e8b5cf;
  --control-hover: #e2a2c2;
}
[data-theme="gruvbox-dark"] {
  --bg: #1c1811;
  --card: #292319;
  --stage: #15120d;
  --text: #efece6;
  --muted: #c0b6a5;
  --border: #423929;
  --accent: #ee5c4f;
  --accent-2: #b4ec65;
  --control: #362e21;
  --on-accent: #0b0d11;
  --control-hover: #463c2b;
}
[data-theme="gruvbox-light"] {
  --bg: #ede0c9;
  --card: #f5ede0;
  --stage: #f7f2e8;
  --text: #231e15;
  --muted: #5d5341;
  --border: #d6b885;
  --accent: #c32213;
  --accent-2: #42680d;
  --control: #e7d5b6;
  --control-hover: #e0caa3;
}
[data-theme="dracula-dark"] {
  --bg: #15101e;
  --card: #1e172b;
  --stage: #0f0c16;
  --text: #e9e6f0;
  --muted: #afa5c0;
  --border: #312546;
  --accent: #ee4f9e;
  --accent-2: #65d5ec;
  --control: #281e38;
  --on-accent: #0b0d11;
  --control-hover: #342749;
}
[data-theme="dracula-light"] {
  --bg: #d8cee8;
  --card: #e9e3f2;
  --stage: #eeeaf5;
  --text: #1a1424;
  --muted: #463d57;
  --border: #a690cb;
  --accent: #c3136b;
  --accent-2: #0d5d6d;
  --control: #cabde0;
  --control-hover: #bcacd8;
}
[data-theme="tokyo-dark"] {
  --bg: #10121e;
  --card: #171a2c;
  --stage: #0b0d16;
  --text: #e6e7f0;
  --muted: #a5a9c0;
  --border: #242a47;
  --accent: #ee4f84;
  --accent-2: #659dec;
  --control: #1d2239;
  --on-accent: #0b0d11;
  --control-hover: #262c4a;
}
[data-theme="tokyo-light"] {
  --bg: #cdd2ea;
  --card: #e2e5f3;
  --stage: #eaecf6;
  --text: #141624;
  --muted: #3d4157;
  --border: #8d98ce;
  --accent: #c3134e;
  --accent-2: #1554ac;
  --control: #bbc2e2;
  --control-hover: #a9b1da;
}
[data-theme="ember-dark"] {
  --bg: #1e1210;
  --card: #2b1a17;
  --stage: #160d0c;
  --text: #f0e7e6;
  --muted: #c0a8a5;
  --border: #462a25;
  --accent: #ee914f;
  --accent-2: #ec8465;
  --control: #38221e;
  --on-accent: #0b0d11;
  --control-hover: #492c27;
}
[data-theme="ember-light"] {
  --bg: #eecec9;
  --card: #f5e3e0;
  --stage: #f8eae8;
  --text: #241614;
  --muted: #57403d;
  --border: #d88e83;
  --accent: #c35c13;
  --accent-2: #9f3414;
  --control: #e8bcb5;
  --control-hover: #e2aaa2;
}
[data-theme="contrast-dark"] {
  --bg: #000000;
  --card: #0a0a0a;
  --stage: #000000;
  --text: #ffffff;
  --muted: #d0d0d0;
  --border: #6e6e6e;
  --accent: #ffd400;
  --accent-2: #5cc8ff;
  --control: #1a1a1a;
  --on-accent: #000000;
  --control-hover: #2c2c2c;
}
[data-theme="contrast-light"] {
  --bg: #ffffff;
  --card: #ffffff;
  --stage: #ffffff;
  --text: #000000;
  --muted: #3a3a3a;
  --border: #6e6e6e;
  --accent: #b00020;
  --accent-2: #0036b3;
  --control: #ececec;
  --control-hover: #dcdcdc;
}
[data-theme="terminal"] {
  --bg: #050805;
  --card: #0a110a;
  --stage: #030503;
  --text: #b8ffb8;
  --muted: #86d886;
  --border: #1f3a1f;
  --accent: #ffb000;
  --accent-2: #3dff72;
  --control: #101a10;
  --on-accent: #031003;
  --control-hover: #182818;
}

/* Atkinson Hyperlegible (vendored, see vendor/atkinson-hyperlegible/README.md) */
@font-face {
  font-family: "Atkinson Hyperlegible";
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url("../../vendor/atkinson-hyperlegible/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  src: url("../../vendor/atkinson-hyperlegible/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2");
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.5;
  /* An app shell: the window never scrolls, the header stays put and the main area fills the rest. */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

[hidden] { display: none !important; }

/* ---------- Header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1000px;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 20px 6px;
  width: 100%;
  flex: none;
  flex-wrap: wrap; /* on a phone the buttons drop to a second row instead of making the page scroll sideways */
}
.top-brand { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 14px; min-width: 0; }
.top h1 { margin: 0; line-height: 0; }
/* The wordmark (src/ui/brand.svg): letters in the theme's text color, the focus letter and the two ticks in its accent, so it follows every theme and mode. The width is the symbol's 1850:674 shape at this height. */
.wordmark { display: block; height: 42px; width: 115.3px; fill: var(--text); color: var(--accent); }
.top-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 6px; flex: 0 1 auto; max-width: 100%; }

.round-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.round-btn:hover { background: var(--control); color: var(--text); }
.round-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

main {
  position: relative;
  display: flex; /* the reader sits in the middle of the window; margin-block: auto on it keeps a tall page scrollable */
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1000px;
  transition: max-width 0.45s var(--ease-out);
  margin: 0 auto;
  padding: 12px 20px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
  scrollbar-width: none; /* it still scrolls on a short window, without a bar */
}
main::-webkit-scrollbar { display: none; }
main > .reader { flex: 1 1 0; min-width: 0; margin-block: auto; }

h2, h3 { font-weight: 600; }

/* ---------- Stage ---------- */
.stage {
  position: relative;
  height: 280px;
  transition: height 0.45s var(--ease-out); /* it grows and shrinks for what it shows, never jumps */
  background: var(--stage);
  border: 1px solid var(--border);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  outline: none;
}
.stage:focus-visible { border-color: var(--accent-2); }

.word {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  width: 100%;
  font-family: var(--reader-font);
  font-size: var(--reader-size);
  line-height: 1.2;
  white-space: pre;
}
.w-before { text-align: right; }
.w-after { text-align: left; }
.w-pivot { text-align: center; }
.word.highlight .w-pivot { color: var(--accent); }

.guide {
  position: absolute;
  left: 50%;
  width: 2px;
  height: 26px;
  margin-left: -1px;
  background: var(--accent);
  opacity: 0.55;
}
.guide-top { top: 0; }
.guide-bottom { bottom: 0; }
.stage.no-guides .guide { display: none; }

.stage-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 24px;
  text-align: center;
  color: var(--muted);
  font-size: 1.05rem;
  pointer-events: none;
}
.stage-msg[hidden] { display: none; }
.stage-msg.count { font-family: var(--reader-font); font-size: clamp(3.5rem, 12vw, 6.5rem); color: var(--text); line-height: 1; }
.stage.showing-msg .word,
.stage.showing-msg .guide,
.stage.showing-msg .formula { visibility: hidden; }

/* Nothing loaded yet: a short invitation instead of a word. */
.empty-state {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 24px;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
}
body[data-state="empty"] .stage:not(.showing-msg) .empty-state { display: flex; }
.empty-state svg { width: 40px; height: 40px; margin-bottom: 8px; fill: none; stroke: var(--muted); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; opacity: 0.7; }
.empty-title { margin: 0; font-family: var(--font-display); font-size: 1.9rem; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
.empty-sub { margin: 6px 0 0; max-width: 34ch; font-size: 0.98rem; line-height: 1.5; color: var(--muted); text-align: center; }
.empty-state svg .tick { stroke: var(--accent); stroke-width: 2.4; opacity: 1; }
.sp-head h2, .overlay h2, .result-stats b, .help-pop h2 { font-family: var(--font-display); }

/* ---------- Formula hold ---------- */
/* A sentence containing a formula (or a long number or unit) is shown whole
   and playback waits for the reader. */
.stage.has-formula { height: 320px; }
.stage.has-formula .word,
.stage.has-formula .guide { display: none; }
.formula {
  box-sizing: border-box;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  padding: 28px 32px 48px;
  text-align: left;
  font-family: var(--reader-font);
  font-size: clamp(1.15rem, calc(var(--reader-size) * 0.42), 2.1rem);
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.formula[hidden] { display: none; }
.formula.is-display { text-align: center; }
.formula .math {
  padding: 0 0.2em;
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent-2) 14%, transparent);
}
/* An inline formula stays in one piece: it moves to its own line instead of
   breaking in the middle, and scrolls sideways if it is wider than the stage. */
.formula .math:not(.math-display) {
  display: inline-block;
  vertical-align: middle;
  max-width: 100%;
  padding: 0.1em 0.35em;
  overflow-x: auto;
  overflow-y: hidden;
}
.formula .math-plain { font-weight: 600; color: var(--accent); }
.formula .math-display { display: block; margin: 0.35em 0; padding: 0.2em 0.4em; }
.formula .katex-display { margin: 0; }
.formula .katex { font-size: 1.25em; }
.hold-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  pointer-events: none;
}
.hold-hint[hidden] { display: none; }
.stage.is-holding { cursor: pointer; }
body.playing .stage:not(.has-overlay) { cursor: pointer; }

/* ---------- Progress (a thin line under the stage) ---------- */
.progress { margin-top: 14px; }
/* The progress line is a slider with a thinner line and a knob that only shows on hover. */
.progress input[type="range"] { --dot: transparent; --line: 3px; height: 20px; }
.progress input[type="range"]:hover,
.progress input[type="range"]:focus-visible { --dot: var(--accent-2); }
.progress input[type="range"]:disabled { cursor: default; }
.progress-info {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

/* While reading (or counting down), the reader moves so the stage sits in the
   exact middle of the window; app.js works out --shift. Idle, the page keeps its
   normal layout. */
.reader { transition: transform 0.45s cubic-bezier(.2,.8,.3,1); }
body.playing .reader { transform: translateY(var(--shift, 0px)); }
body.overlay-open .reader { transition: none; } /* while a panel resizes the stage, the shift follows it frame by frame instead of lagging behind */
.reader-below { padding-top: 6px; min-width: 0; }

/* ---------- Controls: play / pause sits in the exact center ---------- */
.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  margin-top: 18px;
}
.ctl-left, .ctl-right { display: flex; gap: 10px; }
.ctl-left { justify-self: end; }
.ctl-right { justify-self: start; }

button {
  font: inherit;
  color: var(--text);
  background: var(--control);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { background: var(--control-hover); }
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
button.primary {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: var(--on-accent, #fff);
  font-weight: 600;
}
button.primary:hover { opacity: 0.9; }

.icon-btn, .play-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.icon-btn { width: 46px; height: 46px; border-radius: 50%; background: transparent; border-color: transparent; }
.icon-btn:hover { background: var(--control); }
.play-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-2);
  border-color: var(--accent-2);
}
.play-btn:hover { background: var(--accent-2); opacity: 0.9; }
.icon-btn svg { width: 20px; height: 20px; fill: var(--text); }
/* Skip and replay icons are outlines, never filled shapes. */
.ctl-skip svg { fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.play-btn svg { width: 26px; height: 26px; fill: var(--on-accent, #fff); }
.play-btn svg[hidden] { display: none; }

.speed-row {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 360px;
  margin: 14px auto 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.speed-row input { flex: 1; min-width: 0; }
.speed-row label { font-size: 0.9rem; }
.speed-row output { min-width: 76px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.speed-row output::after { content: " wpm"; font-weight: 400; color: var(--muted); }

.review-btns { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.review-btns button { border-radius: 999px; background: transparent; padding: 0; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.review-btns button svg { width: 22px; height: 22px; }
.saved-label { display: inline-flex; align-items: center; gap: 5px; color: var(--accent-2); font-weight: 600; }
.saved-label svg { width: 15px; height: 15px; }
.saved-label[hidden] { display: none; }
.review-btns button:hover { color: var(--text); background: var(--control); }

/* ---------- What stays on screen while playing ---------- */
/* The word is always shown. Everything else fades out while playing; each
   piece can be kept with a "While playing" setting (body.hide-* classes). */
.top-brand, .top-actions, .ctl-main, .ctl-skip, .speed-row, .progress, .review-btns, .reader-coll {
  transition: opacity 0.3s ease, visibility 0s linear 0s;
}
body.playing .review-btns,
body.playing .reader-coll,
body.playing .top-brand,
body.playing .top-actions,
body.playing.hide-main:not(.peek) .ctl-main,
body.playing.hide-skip:not(.peek) .ctl-skip,
body.playing.hide-speed:not(.peek) .speed-row,
body.playing.hide-progress:not(.peek) .progress {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}
/* The hidden text box still takes up room below; do not show a scrollbar for it. */
html:has(body.playing) { overflow: hidden; }
/* Nothing has been read yet, so there is no position to show. */
body[data-state="ready"] .progress { visibility: hidden; }
/* Nothing to play yet: no transport controls. */
body[data-state="empty"] .guide { display: none; }
body[data-state="empty"] .controls,
body[data-state="empty"] .speed-row,
body[data-state="empty"] .progress { display: none; }

textarea {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  font: 1rem/1.6 var(--font-sans);
  color: var(--text);
  background: var(--stage);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.text-meta { color: var(--muted); font-size: 0.85rem; margin: 6px 0 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.text-meta + .row { margin-top: 0; }
.cleanup-note { color: var(--muted); font-size: 0.85rem; margin: -6px 0 12px; }
.cleanup-note[hidden] { display: none; }
.link-btn { background: none; border: 0; padding: 0 2px; color: var(--accent-2); text-decoration: underline; cursor: pointer; font: inherit; }
.overlay .panel-cleanup .cleanup-explain { font-size: 0.9rem; }

/* ---------- Settings panel ---------- */
.settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.settings-backdrop.open { opacity: 1; pointer-events: auto; }
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: min(720px, 100vw);
  background: var(--card);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.28s cubic-bezier(.2,.8,.3,1), visibility 0s linear 0.28s;
}
.settings-panel.open { transform: none; visibility: visible; transition: transform 0.28s cubic-bezier(.2,.8,.3,1); }
.sp-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 14px 24px; border-bottom: 1px solid var(--border); }
.sp-head h2 { margin: 0; font-size: 1.15rem; }
.sp-body { flex: 1; min-height: 0; display: flex; }
.sp-nav { flex: none; width: 190px; display: flex; flex-direction: column; gap: 2px; padding: 12px; border-right: 1px solid var(--border); overflow-y: auto; }
.stab {
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}
.stab:hover { background: var(--control); color: var(--text); transform: none; }
.stab[aria-selected="true"] { background: var(--control); color: var(--text); font-weight: 600; }
.sp-content { flex: 1; min-width: 0; overflow-y: auto; padding: 8px 24px 40px; }
.spane h3 {
  margin: 20px 0 4px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.spane > h3:first-child { margin-top: 14px; }
.spane .lead { margin: 12px 0 4px; color: var(--muted); font-size: 0.9rem; }
@media (max-width: 640px) {
  .sp-body { flex-direction: column; }
  .sp-nav { width: auto; flex-direction: row; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; overflow-y: hidden; padding: 8px 10px; }
  .stab { white-space: nowrap; padding: 8px 12px; }
  .sp-content { padding: 4px 18px 40px; }
}

.setting {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px 14px;
  padding: 11px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.setting label { grid-column: 1; grid-row: 1; font-size: 0.95rem; }
.setting .lbl { grid-column: 1; grid-row: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.setting .lbl label { grid-column: auto; grid-row: auto; }
.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 20px;
  height: 20px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--muted);
  color: var(--muted);
  font: italic 600 0.72rem/1 Georgia, serif;
}
.info-btn:hover, .info-btn[aria-expanded="true"] { color: var(--text); border-color: var(--accent-2); background: color-mix(in srgb, var(--accent-2) 18%, transparent); transform: none; }
.spane h3 .info-btn { margin-left: 6px; vertical-align: middle; text-transform: none; }
/* The text behind an "i" button is kept here but only ever shown in the small pop-up (see app.js infoPopups). */
.info-text { display: none !important; }
.info-pop {
  position: fixed;
  z-index: 200;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}
.info-pop[hidden] { display: none; }
.info-pop b { color: var(--text); font-weight: 600; }
.info-text p { margin: 0 0 6px; }
.info-text p:last-child { margin-bottom: 0; }
.info-text b { color: var(--text); font-weight: 600; }
.setting output {
  grid-column: 2;
  grid-row: 1;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.88rem;
}
.setting input[type="range"] { grid-column: 1 / 3; grid-row: 2; }
.setting select {
  grid-column: 2;
  grid-row: 1;
  max-width: 220px;
  font: inherit;
  color: var(--text);
  background: var(--control);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 8px;
}
.setting.check input { grid-column: 2; grid-row: 1; }
.setting.check label { cursor: pointer; }
.setting.text label { grid-column: 1 / 3; }
.setting.text input { grid-column: 1 / 3; grid-row: 2; }
.setting input[type="text"],
.setting input[type="password"] {
  font: inherit;
  color: var(--text);
  background: var(--control);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
.setting[hidden] { display: none; }
.note { margin: 8px 0 0; color: var(--muted); font-size: 0.82rem; }
.font-preview {
  margin: 8px 0 4px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--stage);
  font-family: var(--reader-font);
  font-size: var(--reader-size); /* the same size as the reading text */
  line-height: 1.2;
  overflow-wrap: anywhere;
}

/* Sliders: one look everywhere. The filled part and the knob are both drawn
   from --p (0 to 1, set by app.js), so they can never disagree. The real knob
   stays, invisible and the same size, only so that dragging and keys work. */
input[type="range"] {
  --dot: var(--accent-2);
  --line: 4px;
  --x: calc(8px + (100% - 16px) * var(--p, 0));
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 22px;
  background:
    radial-gradient(circle 10px at var(--x) 50%, var(--dot) 0 6px, color-mix(in srgb, var(--dot) 24%, transparent) 6px 10px, transparent 10px),
    linear-gradient(to right, var(--accent-2) var(--x), var(--control-hover) var(--x)) center / 100% var(--line) no-repeat;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: 3px;
  border: 0;
  background: transparent;
  box-shadow: none;
}
/* Firefox draws its own fill and knob, which is already in step. */
input[type="range"]::-moz-range-track { height: var(--line); border-radius: 4px; background: var(--control-hover); }
input[type="range"]::-moz-range-progress { height: var(--line); border-radius: 4px; background: var(--accent-2); }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; border: 0; background: var(--dot); }
input[type="range"]:disabled { cursor: default; opacity: 0.6; }
/* On / off switches in the settings panel */
.setting.check input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  width: 42px;
  height: 24px;
  margin: 0;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--control-hover);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.setting.check input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s ease, background 0.15s ease;
}
.setting.check input[type="checkbox"]:checked { background: var(--accent-2); border-color: var(--accent-2); }
.setting.check input[type="checkbox"]:checked::after { transform: translateX(18px); background: var(--on-accent, #fff); }

/* ---------- Keyboard help ---------- */
.help-pop {
  position: fixed;
  top: 64px;
  right: 20px;
  z-index: 30;
  width: min(320px, calc(100vw - 40px));
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.help-pop h2 { margin: 0 0 8px; font-size: 1rem; }
.kb-list { margin: 0; padding: 0; list-style: none; }
.kb-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 0.9rem; border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.kb-list li:last-child { border-bottom: 0; }
.kb-keys { display: inline-flex; gap: 4px; flex: none; }
kbd {
  min-width: 1.7em;
  padding: 1px 7px;
  text-align: center;
  font: 0.8rem/1.5 var(--font-sans);
  color: var(--text);
  background: var(--control);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 60;
  transform: translateX(-50%);
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--control);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }

/* Phones and tablets: bigger things to tap. */
@media (pointer: coarse) {
  button { min-height: 44px; }
  .round-btn { width: 48px; height: 48px; }
  .icon-btn { width: 56px; height: 56px; }
  .play-btn { width: 76px; height: 76px; }
  .play-btn svg { width: 32px; height: 32px; }
  .icon-btn svg { width: 24px; height: 24px; }
  .setting { padding: 14px 0; }
  .setting.check input[type="checkbox"] { width: 52px; height: 30px; }
  .setting.check input[type="checkbox"]::after { width: 24px; height: 24px; }
  .setting.check input[type="checkbox"]:checked::after { transform: translateX(22px); }
  .progress input[type="range"] { height: 32px; }
  .stab { min-height: 44px; }
}
@media (max-width: 640px) {
  .stage { height: 220px; }
  .stage.has-formula { height: 300px; }
}

/* What was switched off for this session, each with a way back. */
.session-skips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 0; max-height: 0; opacity: 0; overflow: hidden; font-size: 0.85rem; color: var(--muted); transition: max-height 0.4s var(--ease-out), opacity 0.3s ease, margin 0.4s var(--ease-out); } /* grows into place instead of popping in */
.session-skips.on { max-height: 90px; opacity: 1; margin: 8px 0 0; }
.ss-chip { animation: chip-in 0.3s cubic-bezier(.3,1.5,.5,1) both; border: 1px solid var(--border); background: var(--control); color: var(--text); border-radius: 999px; padding: 3px 12px; font: inherit; cursor: pointer; }
.ss-chip::after { content: " \00D7"; color: var(--muted); }
.ss-chip:hover { background: var(--control-hover); }
.ss-chip:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* ---------- Comprehension overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column; /* with margin: auto on the panel: centered, or top-aligned when it scrolls */
  overflow-x: hidden;
  overflow-y: auto;
  padding: 16px 20px;
  background: var(--stage);
  color: var(--text);
}
.overlay[hidden] { display: none; }
body.panel-wide main { max-width: 1280px; } /* a panel that lists things gets the room a side dock never had */
.stage.has-overlay { height: 420px; } /* the reader fits the height to the panel (fitStageToOverlay in app.js) */
.stage.overlay-wide .overlay .panel { max-width: 100%; }
/* A panel is as wide as what it holds: a short overview or summary is a centred column, a long one (seven or more points) sets its lists in two. */
.overlay .panel-preview, .overlay .panel-closing { max-width: 680px; }
@media (min-width: 880px) {
  .stage.overlay-wide .panel-preview:has(.panel-list li:nth-child(7)), .stage.overlay-wide .panel-closing:has(.panel-list li:nth-child(7)) { max-width: 100%; }
  .stage.overlay-wide .panel-preview:has(.panel-list li:nth-child(7)) .panel-list,
  .stage.overlay-wide .panel-closing:has(.panel-list li:nth-child(7)) .panel-list { columns: 2; column-gap: 32px; }
  .stage.overlay-wide .panel-preview .panel-list li,
  .stage.overlay-wide .panel-closing .panel-list li { break-inside: avoid; }
}
.overlay .panel-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.overlay .panel-muted { color: var(--muted); }
/* The one-line recap under the last question's feedback: set apart by a rule, not by colour or motion. */
.overlay .panel-recap { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--border); }
.overlay .panel-recap-label { font-weight: 600; }
.overlay .panel-questions { max-height: none; } /* the list uses the height the window has; the overlay scrolls if it is longer */
.overlay .saved-question { margin: 0 0 14px; }
.overlay .saved-right { font-weight: 600; }

/* ---------- Comprehension panels ---------- */
.overlay .panel { width: 100%; max-width: 640px; margin: auto; }
.overlay .panel-title { margin: 0 0 8px; font-size: 1.05rem; text-transform: none; letter-spacing: 0; color: var(--text); }
.overlay .panel-sub {
  margin: 12px 0 4px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.overlay .panel p { margin: 0 0 6px; }
.overlay .panel-summary { line-height: 1.55; overflow-wrap: anywhere; }
.overlay .panel-list { margin: 0; padding-left: 1.3em; overflow-wrap: anywhere; }
.overlay .panel-list li { margin: 2px 0; }
.overlay .panel-stats { margin-top: 10px; color: var(--muted); font-size: 0.92rem; }
.overlay .panel-error { border-left: 4px solid var(--accent); padding-left: 12px; }
.overlay .panel-error .panel-title::before { content: "! "; color: var(--accent); font-weight: 700; }
.overlay .panel-actions[hidden], .overlay .closing-main[hidden] { display: none; }
.overlay .closing-sections { margin: 12px 0 0; }
.overlay .closing-sections summary { cursor: pointer; font-weight: 600; }
.overlay .closing-sections .panel-list { margin-top: 8px; }
.overlay .panel-actions { position: sticky; bottom: -16px; padding: 8px 0; background: var(--stage); }
.overlay .panel:focus { outline: none; }
.overlay .panel-detail { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.overlay .progress { height: 6px; margin: 10px 0; border-radius: 3px; overflow: hidden; background: var(--control); border: 1px solid var(--border); }
.overlay .progress-fill { width: 35%; height: 100%; border-radius: 3px; background: var(--accent-2); animation: progress-slide 1.4s ease-in-out infinite; }
.overlay .loading-elapsed { font-variant-numeric: tabular-nums; margin-bottom: 2px; }
.overlay .loading-expect, .overlay .loading-slow { font-size: 0.9rem; }
@keyframes progress-slide { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
@media (prefers-reduced-motion: reduce) {
  .overlay .progress-fill {
    animation: none; width: 100%;
    background: repeating-linear-gradient(135deg, var(--accent-2) 0 8px, transparent 8px 16px);
  }
}

/* ---------- Section quiz ---------- */
.overlay .quiz-meta { margin: -2px 0 6px; color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; }
.overlay .quiz-prompt { font-size: 1.05rem; line-height: 1.5; overflow-wrap: anywhere; margin-bottom: 10px; }
.overlay .quiz-options { display: grid; gap: 6px; }
/* "Skip ... this session": a quiet link at the end of the row, so it is there but not one of the main choices. */
.overlay .skip-all { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; margin-left: auto; }
.overlay .skip-all:hover { color: var(--text); background: transparent; }
@media (min-width: 880px) {
  .overlay .panel-quiz { max-width: 720px; }
  .overlay .panel-quiz .quiz-prompt { font-size: 1.25rem; line-height: 1.4; margin-bottom: 14px; }
  .overlay .panel-quiz .quiz-option { font-size: 1rem; padding-block: 11px; }
}
.overlay .quiz-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--control);
  cursor: pointer;
  overflow-wrap: anywhere;
}
.overlay .quiz-option:hover { background: var(--control-hover); }
.overlay .quiz-option:has(input:checked) { border-color: var(--accent-2); }
.overlay .quiz-option input { accent-color: var(--accent-2); margin: 0; }
.overlay .quiz-key {
  min-width: 1.5em;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.overlay button:disabled { opacity: 0.5; cursor: default; }
.overlay .quiz-correct { border-left: 4px solid var(--accent-2); padding-left: 12px; }
.overlay .quiz-wrong { border-left: 4px solid var(--accent); padding-left: 12px; }
.overlay .quiz-answer { overflow-wrap: anywhere; }
.overlay .quiz-answer-label { font-weight: 600; }
.reread-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--control);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 10px;
}
.reread-banner .reread-skip { min-height: 32px; padding: 2px 12px; font-size: 0.85rem; }

/* ---------- Flashcards ---------- */
/* A card with two faces that turns over (design principle 29). */
.overlay .flash-scene { perspective: 1100px; margin: 8px 0 14px; }
.overlay .flash-card {
  position: relative;
  min-height: 220px;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(.3,.7,.3,1);
}
.overlay .flash-card.is-flipped { transform: rotateY(180deg); }
.overlay .flash-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 22px 24px;
  text-align: center;
  overflow: auto;
  overflow-wrap: anywhere;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.overlay .flash-back { transform: rotateY(180deg); background: var(--control); }
.overlay .flash-face p { margin: 0; }
.overlay .flash-side { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.overlay .flash-term { font-size: 1.6rem; font-weight: 650; line-height: 1.25; }
.overlay .flash-definition { font-size: 1.15rem; line-height: 1.5; }
.overlay .flash-term-small { margin-top: 8px; font-size: 0.85rem; color: var(--muted); }
.overlay .flash-hint { margin-top: 14px; font-size: 0.78rem; color: var(--muted); }
@media (max-width: 420px) { .overlay .flash-card { min-height: 260px; } .overlay .flash-term { font-size: 1.4rem; } }

/* ---------- Game juice ---------- */
button { transition: transform 0.12s ease, background 0.15s ease; }
button:hover:not(:disabled) { transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(1px) scale(0.94); }
.play-btn:hover:not(:disabled) { transform: scale(1.06); }
.play-btn:active:not(:disabled) { transform: scale(0.9); }

.stage { transition: border-color 0.3s ease, box-shadow 0.4s ease; }
/* The frame and the glow are the "Frame around the text" and "Glow around the text" while-playing settings (both off by default). */
body:not(.hide-frame) .stage.playing { border-color: var(--accent-2); }

body.playing.hide-frame .stage:not(.has-overlay):not(.has-formula) { background: transparent; border-color: transparent; }
.play-btn { position: relative; }
/* Optional paper behind the text: fine grain, long horizontal fibres, a soft mottling and a few specks, all flat noise in mid warm grey
   (no gradient, shadow or blur), so it reads as paper on every theme without lowering the contrast of the words. */
body.paper-texture .stage:not(.has-overlay) {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320'%3E%3Cfilter id='g' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='4' seed='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .41 0 0 0 0 .36 0 0 0 .16 -.02'/%3E%3C/filter%3E%3Cfilter id='f' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012 .55' numOctaves='3' seed='11' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .4 0 0 0 0 .35 0 0 0 0 .29 0 0 0 .4 -.14'/%3E%3C/filter%3E%3Cfilter id='m' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.03' numOctaves='2' seed='5' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .45 0 0 0 0 .38 0 0 0 .32 -.1'/%3E%3C/filter%3E%3Cfilter id='s' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.45' numOctaves='1' seed='9' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .3 0 0 0 0 .26 0 0 0 0 .21 0 0 0 12 -8.4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23m)'/%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3Crect width='100%25' height='100%25' filter='url(%23s)'/%3E%3C/svg%3E");
  background-size: 320px 320px;
}
/* The pointer hides after a few seconds of reading without moving (app.js armCursorHide). */
body.cursor-hidden, body.cursor-hidden * { cursor: none !important; }


/* Motion: one easing for everything that moves into place. */
:root { --ease-out: cubic-bezier(.2,.8,.3,1); }
@keyframes chip-in { from { opacity: 0; transform: scale(0.7); } to { opacity: 1; transform: none; } }
/* U / Ctrl+Z: the word you went back to slides in from the left, so the jump has a direction. */
.stage.undo-cue .word, .stage.undo-cue .page-view { animation: undo-in 0.4s var(--ease-out) both; }
@keyframes undo-in { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }
/* A review that has just become due: the badge pops once. */
#notesBadge:not([hidden]) { animation: badge-pop 0.6s cubic-bezier(.3,1.6,.5,1) both; }
@keyframes badge-pop { from { transform: scale(0); } to { transform: none; } }
/* The result card: its numbers count up (app.js countUp) and each cell rises in turn. */
.result .result-stats > div { animation: panel-in 0.5s var(--ease-out) both; }
.result .result-stats > div:nth-child(2) { animation-delay: 0.08s; }
.result .result-stats > div:nth-child(3) { animation-delay: 0.16s; }
.result .result-stats > div:nth-child(4) { animation-delay: 0.24s; }
.result .result-stats > div:nth-child(5) { animation-delay: 0.32s; }

/* Panels slide in; options stagger; right pops, wrong shakes. */
.overlay .panel { animation: panel-in 0.3s cubic-bezier(.2,.8,.3,1) both; }
/* Question, then feedback, then the next question: each slides in from the right, like turning a card, so the quiz has a direction. */
@keyframes panel-slide { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }
.overlay .panel-quiz { animation: panel-slide 0.38s var(--ease-out) both; }
@keyframes panel-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }
.overlay .quiz-option { animation: option-in 0.3s cubic-bezier(.2,.8,.3,1) both; transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease; }
.overlay .quiz-option:nth-child(1) { animation-delay: 0.05s; }
.overlay .quiz-option:nth-child(2) { animation-delay: 0.10s; }
.overlay .quiz-option:nth-child(3) { animation-delay: 0.15s; }
.overlay .quiz-option:nth-child(4) { animation-delay: 0.20s; }
.overlay .quiz-option:nth-child(n+5) { animation-delay: 0.25s; }
@keyframes option-in { from { opacity: 0; transform: translateX(-16px); } to { opacity: 1; transform: none; } }
.overlay .quiz-option:hover { transform: translateX(3px); }
.overlay .quiz-option:has(input:checked) { animation: option-pop 0.25s ease-out; background: var(--control-hover); }
@keyframes option-pop { 50% { transform: scale(1.03); } }
.overlay .quiz-correct { animation: panel-slide 0.38s var(--ease-out) both, correct-flash 0.7s ease-out 0.2s; }
.overlay .quiz-correct .panel-title { animation: title-pop 0.45s cubic-bezier(.3,1.6,.5,1) both; }
.overlay .quiz-wrong { animation: panel-slide 0.35s var(--ease-out) both, shake 0.45s ease-in-out 0.3s, wrong-flash 0.6s ease-out 0.3s; }
@keyframes correct-flash { from { box-shadow: inset 0 0 0 4px var(--accent-2); } to { box-shadow: inset 0 0 0 0 transparent; } }
@keyframes wrong-flash { from { box-shadow: inset 0 0 0 4px var(--accent); } to { box-shadow: inset 0 0 0 0 transparent; } }
@keyframes title-pop { from { transform: scale(0.5); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shake { 15% { transform: translateX(-8px); } 35% { transform: translateX(7px); } 55% { transform: translateX(-5px); } 75% { transform: translateX(3px); } }

.reread-banner { animation: banner-in 0.3s cubic-bezier(.3,1.5,.5,1) both; }
@keyframes banner-in { from { transform: translate(-50%, -20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.stage-msg:not([hidden]) { animation: panel-in 0.4s ease-out both; }

/* Confetti */
.juice-layer { position: absolute; inset: 0; z-index: 8; pointer-events: none; overflow: hidden; }
.juice-bit { position: absolute; width: 8px; height: 12px; border-radius: 2px; opacity: 0; will-change: transform; }
.juice-bit.round { width: 9px; height: 9px; border-radius: 50%; }

/* Reduced motion: no fades, slides, pulses or hover movement anywhere. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  .overlay, .overlay *, .stage-msg, .reread-banner, .play-btn::after { animation: none !important; }
  button, .quiz-option { transition: none; }
}

/* Settings > Appearance > Screen animations off: the same as the system's reduced-motion request. */
body.no-anim *, body.no-anim *::before, body.no-anim *::after { animation: none !important; transition: none !important; }
body.no-anim .overlay .progress-fill {
  width: 100%;
  background: repeating-linear-gradient(135deg, var(--accent-2) 0 8px, transparent 8px 16px);
}
.setting.sub { padding-left: 22px; }
.setting.sub input:disabled, .setting.sub input:disabled + * { opacity: 0.45; cursor: default; }
.setting.sub:has(input:disabled) label { opacity: 0.45; }

/* Streak, count-up, sweep */
.overlay .streak-msg { font-weight: 700; color: var(--accent-2); animation: title-pop 0.45s 0.1s cubic-bezier(.3,1.6,.5,1) both; }
.overlay .quiz-wrong .streak-msg { color: var(--muted); }
.stat-num { font-variant-numeric: tabular-nums; color: var(--text); font-size: 1.15em; }
.juice-sweep {
  position: absolute; top: 0; bottom: 0; left: 0; width: 35%; z-index: 6; pointer-events: none;
  background: color-mix(in srgb, var(--accent-2) 30%, transparent);
}
/* The section-end ring (juice.arc): centred in the stage, above the words' area but under any panel's text. */
.juice-arc { position: absolute; left: 50%; top: 50%; width: 120px; height: 120px; z-index: 4; pointer-events: none; transform: translate(-50%, -50%); }
.juice-arc circle { fill: none; stroke-width: 6; stroke-linecap: round; }
.juice-arc-track { stroke: color-mix(in srgb, var(--accent-2) 18%, transparent); }
.juice-arc-bar { stroke: var(--accent-2); }
@media (prefers-reduced-motion: reduce) { .streak-msg { animation: none !important; } }

/* Flashcards: only the card itself animates, never the panel, buttons or overlay. */
.overlay .panel-flash { animation: none; }
.overlay .flash-card.flash-gone { pointer-events: none; }

/* ---------- Bring-your-own-AI panel ---------- */
.overlay .panel-manual .panel-actions { position: static; padding: 4px 0; }
.setting[hidden] { display: none; }

/* ---------- Sample picker ---------- */
.overlay .manual-box { min-height: 90px; max-height: 160px; font-size: 0.85rem; line-height: 1.4; margin: 6px 0; }

/* Themed scrollbars: slim, rounded, follow the active theme colors */
* {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 55%, transparent) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 45%, transparent);
  border: 3px solid transparent;
  background-clip: padding-box;
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--muted) 80%, transparent);
  background-clip: padding-box;
}
*::-webkit-scrollbar-corner { background: transparent; }

/* ---------- Tables, code and screen-reader text (from the formula work) ---------- */
/* Text only for screen readers: off screen, but still announced. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}


/* A table or block of code: its own lines, in the page's own colors. */
.formula.is-block { font-size: 0.95rem; line-height: 1.5; padding-bottom: 44px; }
.formula .block-code {
  margin: 0;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent-2) 10%, transparent);
  border: 1px solid var(--border);
}
.formula .block-table {
  border-collapse: collapse;
  min-width: 60%;
  max-width: 100%;
  margin: 0 auto;
}
.formula .block-table th,
.formula .block-table td {
  padding: 6px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.formula .block-table th {
  font-weight: 600;
  color: var(--accent);
  border-bottom: 2px solid var(--accent-2);
}
.formula .block-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.formula .block-table tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--accent-2) 8%, transparent);
}

/* ---------- Calm look (delete this whole block to undo it) ---------- */
/* Flatter and quieter: no outline on the reading area, softer buttons and more room to breathe. */
main { padding-top: 28px; }
.stage { border-color: transparent; border-radius: 24px; }
.stage:focus-visible { border-color: color-mix(in srgb, var(--accent-2) 60%, transparent); }
.progress { margin-top: 20px; }
.controls { margin-top: 26px; }
.speed-row { margin-top: 18px; }

/* ---------- Library panel (your text, recent texts, samples) ---------- */
.settings-panel.left {
  right: auto;
  left: 0;
  width: min(480px, 100vw);
  border-left: 0;
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
}
.settings-panel.left.open { transform: none; }
.lib-content { padding-top: 16px; }
.lib-section { margin-bottom: 22px; }
.lib-section h3 { margin: 0 0 8px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.lib-list { display: flex; flex-direction: column; gap: 4px; }
.lib-row { display: flex; align-items: stretch; gap: 4px; }
.lib-item {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 14px;
  text-align: left;
  background: transparent;
  border-color: transparent;
}
.lib-item:hover { background: var(--control); }
.lib-item strong { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.lib-item span { font-size: 0.82rem; color: var(--muted); }
.lib-del { flex: none; width: 36px; padding: 0; background: transparent; border-color: transparent; color: var(--muted); font-size: 1.2rem; }
.lib-del:hover { color: var(--text); background: var(--control); }
.lib-keep { flex: none; padding: 0 10px; font-size: 0.8rem; color: var(--muted); background: transparent; border-color: transparent; }
.lib-keep:hover, .lib-keep[aria-pressed="true"] { color: var(--text); background: var(--control); }
.lib-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; }
.lib-toolbar select, .lib-toolbar button { font-size: 0.85rem; }
.lib-count { font-size: 0.85rem; color: var(--muted); }
.lib-star { flex: none; width: 34px; padding: 0; background: transparent; border-color: transparent; color: var(--muted); font-size: 1.1rem; }
.lib-star[aria-pressed="true"] { color: var(--accent-2); }
.lib-check { flex: none; align-self: center; margin: 0 6px 0 2px; }
.lib-current .lib-item { background: var(--control); }
.lib-editor { display: flex; flex-direction: column; gap: 8px; margin: 2px 0 10px 8px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
.lib-field { display: flex; flex-direction: column; gap: 3px; font-size: 0.82rem; color: var(--muted); }
.lib-field input, .lib-field select, .lib-field textarea { font: inherit; color: var(--text); }
.offline-pill { margin-left: 10px; padding: 2px 10px; border-radius: 999px; font-size: 0.78rem; color: var(--muted); border: 1px solid var(--border, currentColor); }
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; pointer-events: auto; }

/* ---------- Result card (end of a read) ---------- */
.result { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--muted); }
.result-title { margin: 0; font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; color: var(--text); }
.result-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 32px; }
.result-stats div { display: flex; flex-direction: column; align-items: center; }
.result-stats b { font-family: var(--reader-font); font-size: 2.1rem; font-weight: 600; line-height: 1.1; color: var(--text); font-variant-numeric: tabular-nums; }
.result-stats span { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.07em; }
.result-note { margin: 0; color: var(--accent-2); font-weight: 600; }
.result-hint { margin: 4px 0 0; font-size: 0.85rem; }

/* ---------- Profile chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.chip { padding: 7px 16px; border-radius: 999px; background: transparent; color: var(--muted); }
.chip:hover { color: var(--text); }
.chip[aria-checked="true"] { background: var(--accent-2); border-color: var(--accent-2); color: var(--on-accent, #fff); font-weight: 600; }
.chip[aria-checked="true"], .chip[aria-pressed="true"] { background: var(--accent-2); border-color: var(--accent-2); color: var(--on-accent, #fff); font-weight: 600; }

/* ---------- Theme swatches ---------- */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; margin-top: 6px; }
.swatch {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 6px;
  background: transparent;
  border: 2px solid transparent;
  border-radius: 14px;
}
.swatch:hover { background: var(--control); }
.swatch[aria-checked="true"] { border-color: var(--accent-2); }
/* The art takes the colors of the theme named in its own data-theme. */
.swatch-art {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 52px;
  border-radius: 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
}
.swatch-art i { font: 600 1.25rem/1 Georgia, serif; font-style: normal; }
.swatch-art u { position: absolute; right: 7px; bottom: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent-2); }
.swatch-art::before { content: ""; position: absolute; left: 7px; bottom: 7px; width: 18px; height: 4px; border-radius: 2px; background: var(--accent); }
.swatch-name { font-size: 0.8rem; color: var(--muted); text-align: center; }
.swatch[aria-checked="true"] .swatch-name { color: var(--text); font-weight: 600; }

/* ---------- App feel ---------- */
/* Behave like an installed app: interface text cannot be selected by accident,
   there is no tap flash, no double-tap zoom, no pull-to-refresh bounce and
   buttons keep the normal arrow cursor. Text you read or write stays selectable. */
html { overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
textarea, input[type="text"], input[type="password"], .overlay, .formula, .result, .info-text, .note, .kb-list { -webkit-user-select: text; user-select: text; }
button, summary, label, select, input[type="range"], .stage { touch-action: manipulation; }
button, select, label { cursor: default; }
.settings-panel .sp-content { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
@media (display-mode: standalone) { .top { padding-top: max(14px, env(safe-area-inset-top)); } }
body.playing main { overflow: hidden; }

/* ---------- Account and cloud library ---------- */
.acct-form { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.acct-form label { font-size: 0.9rem; }
.acct-form input,
.cloud-tools input,
.cloud-tools select,
.cloud-folder-form input,
.cloud-edit input,
.cloud-edit select {
  font: inherit;
  color: var(--text);
  background: var(--control);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
#acctWho { margin: 6px 0; font-weight: 600; overflow-wrap: anywhere; }
.acct-danger { margin-top: 18px; }
.acct-danger summary { cursor: pointer; color: var(--muted); }
.acct-danger button[type="submit"] { color: #fff; background: #b3261e; border-color: #b3261e; }
.acct-danger button[type="submit"]:disabled { opacity: 0.5; cursor: default; }
.note.error { color: #d92d2d; }
.cloud-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.cloud-tools select { flex: 0 1 45%; }
.cloud-tools input { flex: 1 1 120px; }
.cloud-folder-form { display: flex; gap: 8px; margin-top: 10px; }
.cloud-folder-form input { flex: 1; }
#cloudList { margin-top: 12px; }
.cloud-row { display: flex; flex-direction: column; gap: 4px; }
.cloud-row .lib-row .lib-del { font-size: 1rem; }
.cloud-tags { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 14px 4px; }
.cloud-tag { font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; background: var(--control); color: var(--muted); }
.cloud-edit { display: flex; flex-direction: column; gap: 8px; padding: 8px 14px 12px; }
.cloud-edit .row { margin-top: 0; }
/* ---------- Plan block in Settings, and the Pro dialog (paywall.js) ---------- */
.plan-block { margin-bottom: 12px; }
.plan-block .plan-title { margin: 0; font-weight: 600; }
.plan-block .plan-detail { margin-top: 2px; }
.plan-block .row { margin-top: 10px; align-items: center; flex-wrap: wrap; gap: 8px; }
.gate-note { margin: 0 0 12px; padding: 8px 10px; border-left: 3px solid var(--accent-2); background: var(--control); border-radius: 6px; }

.paywall-backdrop {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px; overflow-y: auto;
  background: rgba(0, 0, 0, 0.6);
}
.paywall {
  position: relative; width: 100%; max-width: 640px; margin: auto;
  padding: 24px; border-radius: var(--radius);
  background: var(--card); color: var(--text); border: 1px solid var(--border);
}
.paywall:focus { outline: none; }
.paywall-x { position: absolute; top: 12px; right: 12px; font-size: 1.4rem; line-height: 1; }
.paywall-title { margin: 0 40px 6px 0; font-size: 1.3rem; }
.paywall-lead { margin: 0 0 14px; line-height: 1.5; }
.paywall-sub { margin: 0 0 6px; font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.paywall-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 14px; }
.paywall-col { padding: 10px 12px; border: 1px solid transparent; }
.paywall-col-pro { border-color: var(--accent-2); border-radius: 10px; }
.paywall-list { margin: 0; padding-left: 1.2em; font-size: 0.92rem; line-height: 1.45; }
.paywall-list li { margin: 3px 0; }
.paywall-intervals { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 12px; }
.paywall-interval {
  display: flex; align-items: center; gap: 8px; flex: 1 1 180px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
}
.paywall-interval:has(input:checked) { border-color: var(--accent-2); background: var(--control); }
.paywall-interval-name { font-weight: 600; }
.paywall-interval-price { margin-left: auto; color: var(--muted); white-space: nowrap; }
.paywall-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; }
.paywall-fine { margin: 0 0 6px; color: var(--muted); font-size: 0.82rem; line-height: 1.45; }
.paywall-warn { margin: 0 0 12px; padding: 8px 10px; border-left: 3px solid var(--accent); background: var(--control); border-radius: 6px; font-size: 0.92rem; }
.paywall-error { margin: 10px 0 0; color: var(--accent); font-size: 0.92rem; }
@media (max-width: 560px) {
  .paywall { padding: 18px 16px; }
  .paywall-cols { grid-template-columns: 1fr; gap: 10px; }
}

/* Failed-payment banner (paywall.js) */
.billing-banner {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px 12px;
  max-width: 1000px; margin: 4px auto 0; padding: 8px 14px; width: calc(100% - 40px);
  border-left: 3px solid var(--accent); background: var(--control); border-radius: 8px; font-size: 0.92rem;
}
.billing-banner-error { color: var(--accent); }
body.playing .billing-banner { display: none; }
/* Links to the information pages, at the foot of the help popover */
.help-links { margin: 10px 0 0; font-size: 0.85rem; color: var(--muted); }
.help-links a { color: var(--accent-2); }
/* ---------- Page view (scrolling text with a highlight) ---------- */
.sv {
  display: none;
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 28px clamp(16px, 5vw, 40px);
  font-family: var(--reader-font);
  font-size: clamp(17px, calc(var(--reader-size) * 0.42), 38px);
  line-height: 1.7;
  text-align: left;
  scrollbar-width: none;
}
.sv::-webkit-scrollbar { display: none; }
.stage.is-page .sv { display: block; }
.stage.is-page:not(.has-overlay) { height: 360px; }
.stage.is-page .word,
.stage.is-page .guide { display: none; }
.stage.showing-msg .sv { visibility: hidden; }
.sv-p { margin: 0 0 1em; }
.sv-w { border-radius: 4px; padding: 0 1px; transition: color 0.2s ease, background 0.15s ease; }
.sv-w b { font-weight: 800; }
.sv-w.sv-read { color: var(--muted); }
.sv-w.sv-cur { color: var(--text); background: color-mix(in srgb, var(--accent-2) 32%, transparent); }

/* Pacing guide: a moving underline instead of a highlight block */
.stage.is-guide .sv-w.sv-cur { background: none; border-radius: 0; box-shadow: 0 3px 0 var(--accent); }
.stage.is-guide .sv-w.sv-read { color: inherit; }
body.no-back .sv-w.sv-read { color: var(--muted); opacity: 0.3; }

/* ---------- Train panel ---------- */
.train-content { padding-top: 16px; }
.tr-lead { margin: 0 0 14px; color: var(--muted); font-size: 0.9rem; }
.tr-card { margin: 0 0 16px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: color-mix(in srgb, var(--control) 40%, transparent); }
.tr-card h3 { margin: 0 0 10px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.tr-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.tr-stat { display: flex; flex-direction: column; gap: 2px; }
.tr-stat b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.tr-stat span { font-size: 0.78rem; color: var(--muted); }
.tr-note, .tr-sub { margin: 10px 0 0; font-size: 0.82rem; color: var(--muted); }
.tr-bars { display: flex; align-items: flex-end; gap: 6px; height: 64px; margin-top: 6px; }
.tr-bars i { flex: 1; min-height: 2px; border-radius: 4px 4px 0 0; background: color-mix(in srgb, var(--accent-2) 45%, transparent); }
.tr-bars i.now { background: var(--accent-2); }
.tr-goal { display: grid; grid-template-columns: 1fr 110px; align-items: center; gap: 10px; padding: 6px 0; }
.tr-goal input, .tr-input { width: 100%; box-sizing: border-box; font: inherit; color: var(--text); background: var(--control); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.tr-meter { margin-top: 12px; }
.tr-meter-top { display: flex; justify-content: space-between; gap: 10px; font-size: 0.85rem; color: var(--muted); }
.tr-meter-bar { height: 8px; margin-top: 4px; border-radius: 999px; background: var(--control); overflow: hidden; }
.tr-meter-bar i { display: block; height: 100%; background: var(--accent-2); border-radius: 999px; }
.tr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.tr-tile { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; text-align: left; padding: 12px 14px; border-radius: 12px; }
.tr-tile span { font-size: 0.82rem; color: var(--muted); font-weight: 400; }
.tr-back { margin-bottom: 6px; background: transparent; border: 0; color: var(--muted); padding: 6px 0; }
.tr-back:hover { color: var(--text); background: transparent; }
.tr-title { margin: 0 0 12px; font-size: 1.15rem; text-transform: none; letter-spacing: 0; color: var(--text); }

.tr-passage-title { margin: 0 0 8px; font-size: 1.05rem; }
.tr-passage { padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--stage); font-family: var(--reader-font); font-size: 1.1rem; line-height: 1.65; margin-bottom: 14px; }
.tr-passage p { margin: 0 0 0.9em; }
.tr-passage p:last-child { margin-bottom: 0; }
.tr-question { margin: 4px 0 12px; font-size: 1.1rem; font-weight: 600; }
.tr-options { display: flex; flex-direction: column; gap: 8px; }
.tr-option { text-align: left; padding: 12px 14px; border-radius: 12px; font-weight: 400; }
.tr-body .row { margin-top: 14px; }

/* Schulte table */
.tr-schulte { position: relative; display: grid; gap: 6px; max-width: 440px; margin: 10px auto; }
.tr-cell { aspect-ratio: 1; min-height: 0; padding: 0; font-size: clamp(1rem, 5vw, 1.6rem); font-variant-numeric: tabular-nums; border-radius: 10px; -webkit-user-select: none; user-select: none; }
.tr-cell.found { opacity: 0.3; }
.tr-cell.wrong { background: color-mix(in srgb, var(--accent) 45%, var(--control)); }
.tr-fix { position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--accent); pointer-events: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.tr-cell.center { box-shadow: inset 0 0 0 2px var(--accent); }
.tr-find { text-align: center; font-size: 1.1rem; color: var(--text); }

/* Chunk drill */
.tr-flash { display: flex; align-items: center; justify-content: center; min-height: 120px; margin: 8px 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--stage); font-family: var(--reader-font); font-size: clamp(1.5rem, 6vw, 2.6rem); text-align: center; padding: 0 12px; }
.tr-flash.fix { color: var(--accent); font-size: 2.2rem; }
.tr-option.right { background: color-mix(in srgb, #3fa86a 45%, var(--control)); }
.tr-option.wrong { background: color-mix(in srgb, var(--accent) 45%, var(--control)); }

/* Peripheral drill */
.tr-peri { position: relative; font-family: var(--font-mono); font-size: 1.7rem; }
.tr-plus { color: var(--accent); }
.tr-target { position: absolute; top: 50%; transform: translateY(-50%); letter-spacing: 0; }
.tr-options-row { display: grid; grid-template-columns: repeat(2, 1fr); }
.tr-options-row .tr-sub { grid-column: 1 / -1; margin: 0; }

/* Subvocalization drill */
.tr-rsvp { display: grid; grid-template-columns: 1fr auto 1fr; font-size: clamp(1.8rem, 8vw, 3rem); white-space: pre; padding: 0; }
.tr-rsvp span:first-child { text-align: right; }
.tr-rsvp span:last-child { text-align: left; }
.tr-rsvp .tr-pv { color: var(--accent); }

/* Warm-up */
.tr-warm-area { margin: 12px 0 4px; }
.tr-eyes { position: relative; height: 90px; margin: 10px 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--stage); overflow: hidden; }
.tr-eyes i { position: absolute; top: 50%; left: 5%; width: 18px; height: 18px; margin-top: -9px; border-radius: 50%; background: var(--accent); animation: tr-eyes-x 4s ease-in-out infinite alternate; }
.tr-eyes.still i { animation: none; left: 50%; }
@keyframes tr-eyes-x { from { left: 5%; } to { left: calc(95% - 18px); } }
/* ---------- Comprehension methods (method-panels.js) ---------- */
.overlay .method-field { margin: 10px 0; display: grid; gap: 4px; }
.overlay .method-label { font-size: 0.95rem; line-height: 1.4; }
.overlay .method-box, .overlay .method-search {
  width: 100%; box-sizing: border-box; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--control); border: 1px solid var(--border); border-radius: 8px; resize: vertical;
}
.overlay .method-box:focus-visible, .overlay .method-search:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.overlay .method-rating { font-size: 1.3rem; letter-spacing: 0.1em; color: var(--accent-2); margin-bottom: 4px; }
.overlay .method-score { font-size: 1.05rem; }
/* Recall test offer and result: the text's name large, a line of what it is, and flat pills. */
.overlay .panel-recall .recall-name { margin: 4px 0 6px; font-size: 1.25rem; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.overlay .panel-recall .recall-pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.overlay .panel-recall .recall-pill { padding: 3px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--control); font-size: 0.9rem; }
.overlay .panel-recall .recall-score { margin: 0 0 8px; font-size: 1.1rem; font-weight: 600; }
.overlay .panel-recall .recall-meter { height: 10px; border-radius: 5px; background: var(--control); border: 1px solid var(--border); overflow: hidden; margin-bottom: 10px; }
.overlay .panel-recall .recall-meter i { display: block; height: 100%; background: var(--accent-2); }
.overlay .method-missed { border-left: 3px solid var(--border); padding-left: 10px; margin: 8px 0; }
.overlay .method-q { font-weight: 600; overflow-wrap: anywhere; }
.overlay .panel-method { max-height: 100%; overflow-y: auto; }
.overlay .glossary-list { display: grid; gap: 8px; margin: 8px 0; max-height: 45vh; overflow-y: auto; }
.overlay .glossary-row { border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.overlay .glossary-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.overlay .glossary-def { margin: 2px 0; overflow-wrap: anywhere; }
.overlay .lookup-text { line-height: 2; font-size: 1.05rem; overflow-wrap: anywhere; }
.overlay .lookup-word {
  display: inline; padding: 1px 3px; margin: 0; font: inherit; color: inherit; background: none; border: 0;
  border-bottom: 1px dotted var(--muted); border-radius: 3px; cursor: pointer; min-height: 0;
}
.overlay .lookup-word:hover { background: var(--control-hover); }
.overlay .lookup-word.is-current { border-bottom: 2px solid var(--accent); }
.overlay .lookup-word.is-picked { background: var(--control-hover); border-bottom-color: var(--accent-2); }
.overlay .lookup-out { min-height: 3em; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.overlay .lookup-def { margin: 2px 0; overflow-wrap: anywhere; }
.overlay .lookup-key { margin-top: 6px; }
@media (max-width: 640px) {
  .overlay .glossary-list { max-height: 38vh; }
  .overlay .lookup-word { padding: 4px 3px; }
}
/* The lookup panel is short: keep its buttons in the flow so they never cover the last result button. */
.overlay .panel-lookup .panel-actions { position: static; }
/* ---------- File import: import panel ---------- */
.import-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 26px 18px;
  text-align: center;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--card);
}
.import-zone-title { margin: 0; font-weight: 600; }
.import-zone-sub { margin: 0 0 6px; color: var(--muted); font-size: 0.88rem; max-width: 34ch; }
body.dragging-files .import-zone { border-color: var(--accent-2); background: var(--control); }
body.dragging-files::after {
  content: "Drop to import";
  position: fixed;
  inset: 12px;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border: 3px dashed var(--accent-2);
  border-radius: 18px;
  pointer-events: none;
}

.imp-summary { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 6px; }
.imp-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.imp-row { padding: 10px 12px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; min-width: 0; }
.imp-row.is-error { border-color: var(--accent); }
.imp-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; min-width: 0; }
.imp-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.imp-kind { flex: none; font-size: 0.78rem; color: var(--muted); }
.imp-status { margin-top: 2px; font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.imp-row.is-error .imp-status { color: var(--text); }
.imp-progress { display: block; width: 100%; height: 6px; margin-top: 8px; accent-color: var(--accent-2); }
.imp-progress[hidden] { display: none; }
.imp-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.imp-actions:empty { display: none; }
.imp-actions button { padding: 5px 12px; }
.imp-actions .link-btn { padding: 0 2px; }
.imp-password { flex: 1; min-width: 8rem; padding: 6px 10px; color: var(--text); background: var(--control); border: 1px solid var(--border); border-radius: 10px; font: inherit; }

@media (max-width: 640px) {
  .import-zone { padding: 20px 14px; }
}
/* ---------- Progress panel (stats, badges, share card) ---------- */
.stats-panel { width: min(560px, 100vw); }
.st-body { padding-top: 16px; }
.st-section { margin-bottom: 26px; }
.st-section h3 { margin: 0 0 10px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.st-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.st-stat { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--control); min-width: 0; }
.st-stat b { font-size: 1.35rem; line-height: 1.2; overflow-wrap: anywhere; }
.st-stat span { font-size: 0.82rem; color: var(--muted); }
.st-note { font-size: 0.84rem; color: var(--muted); line-height: 1.45; margin: 6px 0 0; }
.st-bar { height: 8px; border-radius: 4px; background: var(--control-hover); overflow: hidden; margin-top: 6px; }
.st-bar-fill { height: 100%; background: var(--accent-2); border-radius: 4px; transition: width 0.3s ease; }
.st-level, .st-goal, .st-goalform, .st-ref { margin-top: 12px; }
.st-goal-line { font-size: 0.92rem; }
.st-goalform { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.st-field { display: flex; flex-direction: column; gap: 4px; font-size: 0.84rem; color: var(--muted); }
.st-field input, .st-field select, .st-name { font: inherit; color: var(--text); background: var(--control); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; min-width: 0; }
.st-name { width: 100%; margin-top: 8px; }
.st-empty { padding: 12px 14px; border: 1px dashed var(--border); border-radius: 10px; color: var(--muted); margin-bottom: 20px; }
.st-empty p { margin: 0; }
.st-fig { margin: 0 0 14px; }
.st-fig figcaption { font-size: 0.86rem; margin-bottom: 4px; }
.st-chart { display: block; width: 100%; height: 80px; border: 1px solid var(--border); border-radius: 8px; background: var(--control); }
.st-line { stroke: var(--accent-2); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.st-dot { fill: var(--accent-2); }
.st-barrect { fill: var(--accent-2); }
.st-topic { margin-bottom: 10px; }
.st-topic-head { display: flex; justify-content: space-between; gap: 10px; font-size: 0.9rem; }
.st-topic-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-topic-val { flex: none; color: var(--muted); font-size: 0.82rem; }
.st-hist { display: flex; flex-direction: column; padding: 7px 0; border-top: 1px solid var(--border); min-width: 0; }
.st-hist strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.st-hist span { font-size: 0.82rem; color: var(--muted); }
.st-badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.st-badge { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; opacity: 0.72; min-width: 0; }
.st-badge.earned { opacity: 1; border-color: var(--accent-2); background: color-mix(in srgb, var(--accent-2) 10%, transparent); }
.st-badge span { font-size: 0.8rem; color: var(--muted); line-height: 1.35; }
.st-badge em { font-size: 0.78rem; font-style: normal; color: var(--accent-2); }
.st-card { display: block; width: 100%; height: auto; max-height: 340px; object-fit: contain; border: 1px solid var(--border); border-radius: 10px; margin: 10px 0; background: var(--control); }
.st-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.st-checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 6px 12px; margin-top: 12px; }
.st-check { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.st-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.st-emailrow { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; }
.st-danger { margin-top: 8px; color: var(--accent); }
@media (pointer: coarse) { .st-check input { width: 22px; height: 22px; } }
/* Sources: read later, public-domain books, lists (sources-ui.js) */
.src-note { margin: 6px 0; font-size: 0.82rem; color: var(--muted); }
.src-form { display: flex; gap: 6px; margin: 8px 0; }
.src-form input, .src-share input, #sourcesMount .lib-section > input { flex: 1; min-width: 0; }
.src-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.src-tab[aria-pressed="true"] { background: var(--control-hover); border-color: var(--accent-2); }
.src-small { padding: 4px 10px; font-size: 0.82rem; }
.src-share { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 12px 0; }
.src-share .src-note { flex-basis: 100%; margin: 0; }
.src-email { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.src-email .src-note { flex-basis: 100%; margin: 0; }
.src-addr { overflow-wrap: anywhere; font-size: 0.82rem; }
.src-shared { border: 1px solid var(--accent-2); border-radius: 10px; padding: 10px 12px; }
.src-title { display: block; margin-bottom: 4px; }
a.lib-item { text-decoration: none; color: inherit; }
#sourcesMount input:not([type="range"]) {
  font: 1rem var(--font-sans);
  color: var(--text);
  background: var(--stage);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
}
#sourcesMount .lib-section > input { width: 100%; margin: 6px 0; box-sizing: border-box; }
.lib-row .src-small { align-self: center; }
/* ---------- Usage statistics consent ---------- */
.consent {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  max-width: 560px; margin: 0 auto; padding: 14px 16px; border-radius: 12px;
  background: var(--panel, var(--control)); color: var(--text); border: 1px solid var(--border, currentColor);
}
.consent p { margin: 0 0 10px; font-size: 0.9rem; line-height: 1.45; }
.consent-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Feedback dialog ---------- */
.feedback { width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 18px 20px; border-radius: 14px; background: var(--panel, var(--control)); color: var(--text); border: 1px solid var(--border, currentColor); }
.feedback::backdrop { background: rgba(0, 0, 0, 0.55); }
.feedback h2 { margin: 0 0 12px; font-size: 1.1rem; }
.feedback label { display: block; margin: 12px 0 4px; font-size: 0.85rem; color: var(--muted); }
.feedback select, .feedback textarea, .feedback input { width: 100%; box-sizing: border-box; font: inherit; color: var(--text); background: var(--control); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.feedback textarea { resize: vertical; min-height: 110px; }
.fb-status { min-height: 1.2em; margin: 8px 0 0; font-size: 0.88rem; }
.fb-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.help-feedback { margin: 10px 0 0; }
.linklike { padding: 0; background: none; border: 0; color: var(--accent, inherit); text-decoration: underline; font: inherit; cursor: pointer; }

/* Right and wrong are marked in text too, not only by color */
.tr-option.right::after { content: " \2713"; font-weight: 700; }
.tr-option.wrong::after { content: " \2717"; font-weight: 700; }
.tr-option:focus-visible, .tr-cell:focus-visible, .tr-tile:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.tr-title:focus, .tr-question:focus { outline: none; }

/* ---------- Settings: which settings are only defaults ---------- */
.def-pill { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--accent-2); color: var(--accent-2); font-size: 0.68rem; font-weight: 600; letter-spacing: 0.02em; text-transform: none; vertical-align: middle; }
.def-banner { margin: 0 0 14px; padding: 10px 12px; border-radius: 8px; background: var(--control); color: var(--muted); font-size: 0.88rem; line-height: 1.45; }
.def-banner .def-pill { margin: 0 6px 0 0; }

/* Debug controls never show while words flash or in focus mode. */
body.playing .debug-control, body.focus-mode .debug-control { display: none !important; }

/* Night shift: one flat amber layer multiplied over the page (no gradient, glow or blur). */
#nightShiftTint { position: fixed; inset: 0; z-index: 2147483000; pointer-events: none; mix-blend-mode: multiply; }
#nightShiftTint[hidden] { display: none; }

/* ---------- Surface and shape language (docs/design-research.md, docs/DECISIONS.md 29) ----------
   Measured from Readwise and Quizlet: pill buttons (radius 64 to 200px), a soft 0 1px 4px shadow on the active
   segment of a toggle, cards at 16 to 24px radius, a 2px accent border on the featured plan, a 10% tinted pill
   for "best value". All colours come from the theme's own tokens, so each collection keeps its own look.
   The tokens are declared on every themed element, not only :root, so color-mix sees that theme's colours. */
:root, [data-theme] {
  --radius: 18px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 4px rgb(0 0 0 / 0.1);
  --shadow-md: 0 12px 30px -14px rgb(0 0 0 / 0.3), 0 2px 6px rgb(0 0 0 / 0.08);
  --glow: 0 0 0 4px color-mix(in srgb, var(--accent-2) 28%, transparent);
  --glow-soft: 0 6px 20px -8px color-mix(in srgb, var(--accent-2) 65%, transparent);
  --grad-wash: radial-gradient(120% 100% at 0% 0%, color-mix(in srgb, var(--accent-2) 16%, transparent), transparent 62%), radial-gradient(90% 90% at 100% 0%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 58%);
  --grad-tint: linear-gradient(180deg, color-mix(in srgb, var(--accent-2) 12%, var(--card)), var(--card) 65%);
}

/* Buttons: the main action is a pill with a soft glow in the theme's colour; quiet ones in the main places are pills too. */
button.primary { border-radius: var(--radius-pill); padding: 10px 22px; box-shadow: var(--glow-soft); }
button.primary:hover { opacity: 1; filter: brightness(1.07); box-shadow: var(--glow-soft), 0 0 0 4px color-mix(in srgb, var(--accent-2) 16%, transparent); }
button.primary:focus-visible { box-shadow: var(--glow); outline-color: transparent; }
button.primary:disabled { box-shadow: none; }
.empty-actions button, .shelf-bar button, .shelf-create button, .fb-actions button, .paywall-actions button { border-radius: var(--radius-pill); padding-inline: 20px; }

/* Cards and panels sit on a soft shadow instead of a bare outline. */
.shelf-create, .coll-item, .coll-stat, .note-card, .set-card, .notes-text, .coll-editor, .add-choice, .imp-row { box-shadow: var(--shadow-sm); }
.paywall { box-shadow: var(--shadow-md); }

/* The Free / Pro columns and the billing choice: the featured column has a 2px accent border and a faint tint; the picked period is a pill with a glow. */
.paywall-col { border: 2px solid transparent; padding: 14px 16px; }
.paywall-col-pro { border-color: var(--accent-2); border-radius: var(--radius); background: var(--grad-tint); }
.paywall-interval { border-radius: var(--radius-pill); padding: 10px 20px; }
.paywall-interval:has(input:checked) { border-color: var(--accent-2); background: var(--card); box-shadow: var(--glow); }
.paywall-interval input { accent-color: var(--accent-2); }

/* Serif titles on the full screens and a pill for the way back. */
.coll-screen h1, .coll-screen h2, .coll-screen h3, .add-screen h1, .add-screen h2, .shelf-content h2, .overlay-head h2, .acct h2, .paywall-title { font-family: var(--font-display); font-weight: 600; }
.coll-screen .coll-back { border-radius: var(--radius-pill); }

/* Quizlet-style answer choices (docs/design-research.md): two columns of bordered boxes, the key number in a circle, the radio itself out of sight (it stays for keyboards and screen readers). */
.overlay .quiz-options { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.overlay .quiz-option { min-height: 64px; padding: 12px 16px; gap: 14px; border: 2px solid var(--border); border-radius: 14px; background: var(--card); }
.overlay .quiz-option input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.overlay .quiz-option { position: relative; }
.overlay .quiz-option:hover { transform: none; background: var(--card); border-color: color-mix(in srgb, var(--accent-2) 55%, var(--border)); }
.overlay .quiz-option:has(input:checked) { background: color-mix(in srgb, var(--accent-2) 10%, var(--card)); border-color: var(--accent-2); }
.overlay .quiz-option:has(input:focus-visible) { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.overlay .quiz-key { flex: none; display: grid; place-items: center; width: 28px; height: 28px; min-width: 28px; border-radius: 50%; font-size: 0.85rem; font-weight: 600; color: var(--muted); background: var(--control); }
.overlay .quiz-option:has(input:checked) .quiz-key { background: var(--accent-2); border-color: var(--accent-2); color: var(--on-accent, #fff); }
@media (max-width: 560px) { .overlay .quiz-options { grid-template-columns: minmax(0, 1fr); gap: 8px; } .overlay .quiz-option { min-height: 48px; padding: 8px 12px; gap: 12px; } }

/* Labels and callouts (design audit): small all-caps labels become sentence-case semibold headings, and callouts lose their thick coloured left bar for a full soft border and a faint tint (frontend-design and impeccable both list these as stock-template habits). The picked / correct / wrong states keep their colour and gain a full border. */
.lib-section h3, .tr-card h3, .st-section h3, .spane h3, .overlay .panel-sub, .paywall-sub, .overlay .quiz-meta, .overlay .flash-side, .result-stats span { text-transform: none; letter-spacing: 0; font-size: 0.9rem; font-weight: 600; }
.gate-note, .overlay .quiz-correct { border: 1px solid color-mix(in srgb, var(--accent-2) 45%, var(--border)); border-radius: 14px; background: color-mix(in srgb, var(--accent-2) 8%, var(--card)); }
.paywall-warn, .overlay .panel-error, .overlay .quiz-wrong { border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border)); border-radius: 14px; background: color-mix(in srgb, var(--accent) 8%, var(--card)); }
.overlay .quiz-correct, .overlay .quiz-wrong, .overlay .panel-error { padding: 12px 14px; }

/* "Jump back in" card on the empty reader (docs/design-research.md, from Quizlet's home): the text read last and not finished, with how far and a Continue button. */
.es-resume { display: flex; align-items: center; gap: 16px; width: min(460px, calc(100vw - 100px)); box-sizing: border-box; margin-top: 18px; padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow-sm); text-align: left; pointer-events: auto; }
.es-resume[hidden] { display: none; }
.empty-state.has-resume svg, .empty-state.has-resume .empty-sub { display: none; }
.empty-state.has-resume .empty-title { margin-bottom: 4px; }
.es-resume-info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.es-resume-info strong { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.05rem; }
.es-resume-info span { color: var(--muted); font-size: 0.88rem; }
.es-resume-bar { height: 6px; border-radius: 3px; background: var(--control); overflow: hidden; }
.es-resume-bar i { display: block; height: 100%; background: var(--accent-2); }

/* Calmer panels: they fade in, nothing bounces or staggers. The quiz keeps one short slide so it has a direction. Annotating does not re-enter at all. */
@keyframes panel-fade { from { opacity: 0; } to { opacity: 1; } }
.overlay .panel { animation: panel-fade 0.18s ease both; }
.overlay .panel-annotate, .overlay .panel-review, .overlay .panel-glossary { animation: none; }
.overlay .panel-quiz, .overlay .panel-feedback { animation: panel-slide 0.28s var(--ease-out) both; }
.overlay .quiz-option { animation: none; }
/* Question, answers and feedback share one 640px column (so their edges line up); answers are one per row, never an orphan in a grid. */
.overlay .panel-quiz, .overlay .panel-feedback { max-width: 640px; }
.overlay .quiz-options { grid-template-columns: minmax(0, 1fr); gap: 10px; }
.overlay .quiz-option { min-height: 56px; }
/* A panel that only asks one thing (annotate this section?) is centred, like the question it holds. */
.overlay .panel-annotate-offer { text-align: center; max-width: 520px; }
.overlay .panel-annotate-offer .panel-actions { justify-content: center; }
.overlay .panel-annotate-offer .skip-all { margin-left: 0; }

/* visual-edits:start (written by the dev page editor in src/dev; fold settled rules into real ones, then delete them here) */
@media (min-width: 761px) {
  h3#panel-title-2 {
    text-align: left !important;
  }
  button.primary {
    text-align: right !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }
  h3#panel-title-95 {
    text-align: center !important;
    font-weight: 700 !important;
  }
}
/* visual-edits:end */
