/* Pagepurr. Mobile-first: desktop only widens the content and centres the sheets.
   Sections: tokens, base, controls, home, reader, sheets, overlays, reading comfort. */

/* ---------- Fonts (bundled, free licences, so the app works offline) ---------- */

@font-face {
  font-family: "Inter";
  src: url("vendor/fonts/inter-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
/* The name, in a soft rounded face that matches the sticker logo (Fredoka, OFL). */
@font-face {
  font-family: "Fredoka";
  src: url("vendor/fonts/fredoka-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Serif";
  src: url("vendor/fonts/instrument-serif-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("vendor/fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("vendor/fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "Lexend";
  src: url("vendor/fonts/lexend-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Lexend";
  src: url("vendor/fonts/lexend-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "OpenDyslexic";
  src: url("vendor/fonts/opendyslexic-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "OpenDyslexic";
  src: url("vendor/fonts/opendyslexic-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

/* ---------- Tokens ---------- */

:root {
  /* Molo palette: black on off-white, with soft blue, pink and gold as accents. */
  --bg: #f5f5f5;
  --surface: #ffffff;
  --text: #0a0a0a;
  --muted: #696765;
  --line: #e8e6e3;
  --track: #dcdad6;
  --chip: #f0efed;
  --accent: var(--text);         /* primary actions take the text colour of the page */
  --accent-ink: var(--surface);
  --blue: #a2bcf7;
  --pink: #f9abee;
  --gold: #f3d98f;
  --tint: rgba(162, 188, 247, 0.38); /* selected and pressed states */
  --danger: #b3261e;
  --paper: #ffffff;

  --mark-yellow: #f3d98f;
  --mark-green: #bfe8c8;
  --mark-pink: #f9c4f0;
  --mark-blue: #c4d5fa;

  --shadow-1: 0 1px 2px rgba(10, 10, 10, 0.06), 0 1px 1px rgba(10, 10, 10, 0.04);
  --shadow-2: 0 10px 30px rgba(10, 10, 10, 0.08), 0 2px 6px rgba(10, 10, 10, 0.05);
  --shadow-3: 0 24px 60px rgba(10, 10, 10, 0.22);

  --ui: var(--ui-font, "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
  --display: var(--display-font, "Instrument Serif", Georgia, "Times New Roman", serif);

  --text-size: 20px;
  --text-leading: 1.6;
  --text-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0a0a0a;
  --surface: #151514;
  --text: #f4f3f1;
  --muted: #a3a09c;
  --line: #272625;
  --track: #3a3836;
  --chip: #201f1e;
  --tint: rgba(162, 188, 247, 0.24);
  --danger: #ff8a80;
  --mark-yellow: rgba(243, 217, 143, 0.34);
  --mark-green: rgba(150, 214, 170, 0.3);
  --mark-pink: rgba(249, 171, 238, 0.3);
  --mark-blue: rgba(162, 188, 247, 0.34);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-2: 0 10px 30px rgba(0, 0, 0, 0.5);
  --shadow-3: 0 24px 60px rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

/* Tinted pages. Off-white backgrounds reduce glare; each keeps strong text contrast. */
:root[data-theme="cream"] {
  --bg: #f1e7d0;
  --surface: #fbf5e6;
  --paper: #fbf5e6;
  --text: #2a2620;
  --muted: #655c4d;
  --line: #e3d8be;
  --track: #d6c9a9;
  --chip: #f1e7cf;
}
:root[data-theme="blue"] {
  --bg: #dbe7f3;
  --surface: #eef5fc;
  --paper: #eef5fc;
  --text: #1d2733;
  --muted: #526071;
  --line: #cfddec;
  --track: #b9cbdf;
  --chip: #e0ebf6;
}
:root[data-theme="green"] {
  --bg: #dcebdb;
  --surface: #eff7ee;
  --paper: #eff7ee;
  --text: #1e2a20;
  --muted: #536357;
  --line: #d0e1ce;
  --track: #b9d0b6;
  --chip: #e1eee0;
}
:root[data-theme="grey"] {
  --bg: #d8d6d1;
  --surface: #e8e6e2;
  --paper: #e8e6e2;
  --text: #2e2d2b;
  --muted: #5d5b57;
  --line: #d2cfc9;
  --track: #bdb9b2;
  --chip: #dcd9d4;
}

/* The colour that follows the reading (sentence and word), chosen in Reading comfort. */
:root { --read-rgb: 162, 188, 247; --read-soft: 0.42; --read-strong: 1; }
:root[data-read="yellow"] { --read-rgb: 243, 217, 143; --read-soft: 0.5; }
:root[data-read="green"] { --read-rgb: 150, 214, 170; --read-soft: 0.45; }
:root[data-read="pink"] { --read-rgb: 249, 171, 238; --read-soft: 0.4; }
:root[data-read="orange"] { --read-rgb: 248, 190, 140; --read-soft: 0.45; }
:root[data-read="grey"] { --read-rgb: 150, 150, 156; --read-soft: 0.26; --read-strong: 0.55; }
:root[data-theme="dark"] { --read-soft: 0.26; --read-strong: 0.55; }
:root,
:root[data-theme] {
  --read-sentence: rgba(var(--read-rgb), var(--read-soft));
  --read-word: rgba(var(--read-rgb), var(--read-strong));
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
* { scrollbar-width: thin; scrollbar-color: var(--track) transparent; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

::selection { background: rgba(162, 188, 247, 0.6); }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.14s, color 0.14s, border-color 0.14s, box-shadow 0.14s, transform 0.14s, opacity 0.14s;
}
button:disabled { opacity: 0.38; cursor: default; }

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
  box-shadow: 0 0 0 1px var(--text);
}

h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* Icons are little stickers: white shapes with a thick black outline and a white border,
   the same on every page colour (see tools/make-sprite.py). */
.icon {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: #0a0a0a;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
  flex: none;
}
.sticker-edge { stroke: #fff; stroke-width: 5.4; }

/* ---------- Controls ---------- */

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
}
.icon-btn:hover { background: var(--chip); }
.icon-btn:active { transform: scale(0.96); }
.icon-btn[aria-pressed="true"] { background: var(--tint); }
.icon-btn.large .icon { width: 32px; height: 32px; stroke-width: 1.8; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 14px;
  background: var(--chip);
  font-weight: 600;
  font-size: 15px;
}
.btn:hover { background: var(--line); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-1); }
.btn.primary:hover { opacity: 0.88; background: var(--accent); }
.btn.large { min-height: 54px; padding: 0 22px; border-radius: 16px; font-size: 16px; }
.btn.large .icon { width: 20px; height: 20px; stroke-width: 2.2; }
.btn.danger { color: var(--danger); }

.text-input {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  border: 1px solid var(--track);
  border-radius: 14px;
  background: var(--surface);
  transition: border-color 0.14s;
}
.text-input:hover { border-color: var(--muted); }
textarea.text-input { resize: vertical; line-height: 1.45; }
::placeholder { color: var(--muted); opacity: 1; }

select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

/* Sliders: a filled track and a round handle. --fill is set from script (see syncRange in app.js). */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  --fill: 0%;
  width: 100%;
  height: 32px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--fill), var(--track) var(--fill));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -7px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  box-shadow: var(--shadow-1);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--track); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
}

/* The view switch (PDF / Text / AI) and other either-or choices. */
.segmented {
  justify-self: center;
  display: flex;
  width: 100%;
  max-width: 300px;
  padding: 4px;
  border-radius: 999px;
  background: var(--chip);
}
.segmented button {
  flex: 1;
  min-height: 40px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  color: var(--muted);
}
.segmented button:hover { color: var(--text); }
.segmented button:disabled { opacity: 0.35; }
.segmented.small { max-width: 300px; justify-self: start; }
.segmented.small button { min-height: 38px; font-size: 14px; }
.segmented button[aria-selected="true"],
.segmented button[aria-checked="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

.screen {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- Home ---------- */

.home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 12px 4px 20px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 40px; height: 40px; border-radius: 11px; transform: rotate(-4deg); }
/* Like the stickers: black letters with a white border around them, in both themes. */
.wordmark {
  font-family: "Fredoka", var(--ui);
  font-weight: 500;
  font-size: 25px;
  line-height: 1;
  letter-spacing: 0;
  color: #0a0a0a;
  -webkit-text-stroke: 6px #fff;
  paint-order: stroke fill;
  filter: drop-shadow(0 1px 1.5px rgba(10, 10, 10, 0.22));
}
.head-actions { display: flex; gap: 2px; }

/* The whole home screen scrolls, so the scrollbar sits at the window edge. */
#home { display: block; overflow-y: auto; }
.home-main {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 4px 20px calc(40px + env(safe-area-inset-bottom));
}

.hero { padding: 36px 0 6px; }
.hero-title {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(38px, 8vw, 60px);
  line-height: 1.04;
  letter-spacing: -0.015em;
  max-width: 14ch;
}
.hero-text {
  max-width: 44ch;
  margin-top: 14px;
  font-size: 17px;
  color: var(--muted);
}
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}
.drop-hint { margin-top: 12px; font-size: 14px; color: var(--muted); }
@media (hover: none) { .drop-hint { display: none; } }

.sync-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-top: 14px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.sync-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #58b97a;
}
.sync-chip[data-status="expired"] { color: var(--text); }
.sync-chip[data-status="expired"]::before { background: var(--gold); }
.sync-chip:hover { border-color: var(--muted); }
.sheet-body a { color: inherit; text-underline-offset: 3px; }
.sync-state {
  margin: 14px 0 4px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--chip);
  font-weight: 600;
}

/* With files in the library, the greeting steps back and the library leads. */
.home-main.has-files .hero { padding-top: 14px; }
.home-main.has-files .hero-title { font-size: clamp(28px, 6vw, 38px); max-width: none; }
.home-main.has-files .hero-text { display: none; }
.home-main.has-files .hero-actions { margin-top: 16px; }

.section-head {
  margin: 34px 0 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}

.continue {
  position: relative;
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 18px;
  align-items: center;
  margin-top: 26px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  cursor: pointer;
}
.continue-thumb {
  width: 112px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  object-position: top;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--chip);
}
.continue-body { min-width: 0; padding-right: 36px; }
.continue-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.continue-label::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--blue);
}
.continue-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 6px;
  font-family: var(--display);
  font-size: clamp(22px, 5vw, 28px);
  line-height: 1.12;
  overflow-wrap: anywhere;
}
.continue .card-meta { margin-top: 8px; font-size: 13px; }
.continue .card-bar { max-width: 320px; margin-top: 10px; }
.continue .btn { margin-top: 14px; }

.library {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}
.card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  transition: box-shadow 0.18s, transform 0.18s;
}
.card:hover { box-shadow: var(--shadow-2); transform: translateY(-2px); }
.card-open {
  display: block;
  width: 100%;
  text-align: left;
}
.card-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  object-position: top;
  background: var(--chip);
  border-bottom: 1px solid var(--line);
}
.card-body { display: block; padding: 12px 14px 14px; }
.card-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-weight: 600;
  font-size: 14.5px;
  line-height: 1.3;
  min-height: 2.6em;
  overflow-wrap: anywhere;
}
.card-meta { display: block; margin-top: 6px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card-bar {
  display: block;
  height: 4px;
  margin-top: 8px;
  border-radius: 2px;
  background: var(--track);
  overflow: hidden;
}
.card-bar > span { display: block; height: 100%; border-radius: 2px; background: var(--accent); }
.card-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
}
/* A small button, so extend its hit area to a comfortable touch size. */
.card-remove::before { content: ""; position: absolute; inset: -5px; }
.card-remove:hover { color: var(--danger); background: var(--surface); }
.card-remove .icon { width: 18px; height: 18px; }

.library-empty {
  margin-top: 30px;
  padding: 22px;
  border: 1px dashed var(--track);
  border-radius: 18px;
  color: var(--muted);
}

/* ---------- Reader: top bar ---------- */

.topbar {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 8px;
  padding: calc(5px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 5px max(10px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

/* On a phone the top bar gets out of the way while reading (scrolling down, or listening). */
@media (max-width: 700px), (max-height: 620px) {
  .topbar {
    max-height: 140px;
    transition: max-height 0.22s ease, padding 0.22s ease, visibility 0s;
  }
  :root[data-bar="auto"] #reader.immersed .topbar {
    max-height: env(safe-area-inset-top, 0px);
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: 0;
    border-bottom-width: 0;
    overflow: hidden;
    visibility: hidden;
    transition: max-height 0.22s ease, padding 0.22s ease, visibility 0s 0.22s;
  }
  /* The page number, its arrows and the page-size buttons go with it. */
  .page-nav, .zoom, .text-head { transition: opacity 0.22s ease, visibility 0s; }
  :root[data-bar="auto"] #reader.immersed .page-nav,
  :root[data-bar="auto"] #reader.immersed .zoom,
  :root[data-bar="auto"] #reader.immersed .text-head {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.22s ease, visibility 0s 0.22s;
  }
}

/* ---------- Reader: views ---------- */

.views {
  position: relative;
  flex: 1;
  min-height: 0;
}
.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Page controls on the PDF tab: previous, "3 / 20" (opens Go to page), next. */
.page-nav {
  position: absolute;
  z-index: 2;
  top: 10px;
  left: 10px;
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: 999px;
  background: rgba(10, 10, 10, 0.78);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
}
.page-nav .icon-btn { width: 40px; height: 40px; border-radius: 50%; }
.page-nav .icon-btn:hover { background: rgba(255, 255, 255, 0.16); }
.page-nav .icon { width: 20px; height: 20px; stroke-width: 2.2; }
.page-label {
  min-width: 64px;
  height: 40px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.page-label:hover { background: rgba(255, 255, 255, 0.16); }

/* The same controls on the Text tab: a bar that stays at the top while the text scrolls. */
.text-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 -12px 14px;
  padding: 8px 0;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-family: var(--ui);
  letter-spacing: 0;
  word-spacing: 0;
}
.text-head .icon-btn { width: 44px; height: 44px; flex: none; }
.text-head .text-pagenum { margin: 0; min-height: 40px; cursor: pointer; }
.text-head .text-pagenum:hover { background: var(--line); }

.pdf-pages { padding: 8px 10px 20px; }
#view-pdf { overflow: auto; }

/* Page size on the PDF tab: smaller to see more, bigger to read fine print. */
.zoom {
  position: absolute;
  z-index: 2;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
}
.zoom .icon-btn { width: 40px; height: 40px; border-radius: 50%; }
.zoom .icon { width: 20px; height: 20px; stroke-width: 2; }
.zoom-value {
  min-width: 56px;
  height: 40px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.zoom-value:hover { background: var(--chip); }
/* The page takes the colour of the chosen theme: white in the PDF becomes the paper colour. */
.pdf-page {
  position: relative;
  width: calc(min(100%, 900px) * var(--zoom, 1));
  margin: 10px auto;
  border-radius: 6px;
  background: var(--paper);
  box-shadow: var(--shadow-2);
  overflow: hidden;
  cursor: pointer;
}
.pdf-page canvas {
  display: block;
  width: 100%;
  height: 100%;
  mix-blend-mode: multiply;
}
:root[data-theme="dark"] .pdf-page canvas { filter: brightness(0.86); }
.pdf-overlay {
  position: absolute;
  inset: 0;
  mix-blend-mode: multiply;
  pointer-events: none;
}
.pdf-overlay > div { position: absolute; border-radius: 3px; }
.pdf-active { background: rgba(var(--read-rgb), 0.5); }
.pdf-word { background: rgba(var(--read-rgb), 1); }
:root[data-hl="sentence"] .pdf-word,
:root[data-hl="word"] .pdf-active { display: none; }
.pdf-mark[data-mark="yellow"] { background: #f3d98f; }
.pdf-mark[data-mark="green"] { background: #bfe8c8; }
.pdf-mark[data-mark="pink"] { background: #f9c4f0; }
.pdf-mark[data-mark="blue"] { background: #c4d5fa; }

#view-text { background: var(--surface); }
.text-page {
  max-width: var(--text-width, 760px);
  margin: 0 auto;
  padding: 4px 22px 40px;
  font-family: var(--text-font);
  font-size: var(--text-size);
  line-height: var(--text-leading);
  letter-spacing: var(--text-letter, 0);
  word-spacing: var(--text-word, 0);
  overflow-wrap: break-word;
}
.text-pagenum {
  display: inline-block;
  margin-bottom: 20px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--chip);
  font: 600 13px/1.2 var(--ui);
  letter-spacing: 0;
  word-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.text-pagenum span { color: var(--muted); font-weight: 500; }
.text-page .blk { margin: 0 0 0.95em; }
.text-page h2.blk { font-size: 1.3em; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; margin-top: 1.2em; }
.text-head + h2.blk { margin-top: 0.2em; }
.text-page .caption { font-size: 0.88em; color: var(--muted); }
.text-page figure { margin: 1.2em 0 1.4em; text-align: center; }
.text-page figure img { max-width: 100%; height: auto; border-radius: 12px; background: #fff; box-shadow: var(--shadow-1); }
.text-page figure .caption { margin: 0.6em 0 0; }
.text-empty {
  margin: 20px 0;
  padding: 18px;
  border-radius: 16px;
  background: var(--chip);
  font: 16px/1.5 var(--ui);
  letter-spacing: 0;
  word-spacing: 0;
}
.text-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 36px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-family: var(--ui);
  letter-spacing: 0;
  word-spacing: 0;
}

.s {
  cursor: pointer;
  border-radius: 5px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background-color 0.16s;
}
.s[data-mark="yellow"] { background: var(--mark-yellow); }
.s[data-mark="green"] { background: var(--mark-green); }
.s[data-mark="pink"] { background: var(--mark-pink); }
.s[data-mark="blue"] { background: var(--mark-blue); }
.s.active { background: var(--read-sentence); }
.w { border-radius: 4px; }
.w.active { background: var(--read-word); }
.w b { font-weight: 700; }

#view-ai { background: var(--surface); }
.ai-panel {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 22px 40px;
}
.ai-panel h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 34px;
  line-height: 1.1;
  margin-bottom: 18px;
}
.ai-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.ai-controls .segmented { flex: 1 1 240px; }
.ai-output {
  list-style: none;
  margin: 18px 0;
  padding: 0;
  font-size: 17px;
  line-height: 1.55;
}
.ai-output li {
  position: relative;
  margin-bottom: 10px;
  padding: 14px 16px 14px 40px;
  border-radius: 16px;
  background: var(--chip);
}
.ai-output li::before {
  content: "";
  position: absolute;
  left: 16px;
  top: 23px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--blue);
}
.ai-jump { text-align: left; font: inherit; }
.ai-jump:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Reader: bottom toolbar and player ---------- */

.bottom {
  position: relative;
  z-index: 3;
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(10, 10, 10, 0.04);
  padding: 0 max(14px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(14px, env(safe-area-inset-left));
}
.bottom-inner {
  position: relative;
  max-width: 720px;
  margin: 0 auto;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 0;
  border-bottom: 1px solid var(--line);
}
.aa { font-size: 19px; font-weight: 700; letter-spacing: -0.5px; line-height: 24px; }
.dot {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--blue);
  border: 2px solid var(--surface);
  box-sizing: content-box;
}
.text-btn {
  margin-left: auto;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
}
.text-btn:hover { background: var(--chip); color: var(--text); }

.show-tools {
  position: absolute;
  top: -23px;
  right: 0;
  width: 56px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 12px 12px 0 0;
  background: var(--surface);
  color: var(--muted);
}
/* A slim tab, so extend its hit area to a comfortable touch size. */
.show-tools::before { content: ""; position: absolute; inset: -22px -4px 0; }
.show-tools .icon { width: 20px; height: 20px; }

.hl-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0 4px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.swatches { display: flex; }
.swatch {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
}
.swatch::before {
  content: "";
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--track);
}
.swatch[data-color="yellow"]::before { background: #f3d98f; }
.swatch[data-color="green"]::before { background: #a6dcb4; }
.swatch[data-color="pink"]::before { background: #f9abee; }
.swatch[data-color="blue"]::before { background: #a2bcf7; }
.swatch[aria-checked="true"]::before { box-shadow: 0 0 0 2px var(--text); }

.voice-status {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

.player { padding: 4px 0 8px; }
.progress {
  display: flex;
  align-items: center;
  gap: 12px;
}
.time {
  min-width: 40px;
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
#time-total { text-align: right; }
#seek { flex: 1; min-width: 0; }

.controls {
  display: flex;
  align-items: flex-end; /* the names under the buttons sit on one line */
  justify-content: space-between;
  max-width: 420px;
  margin: 2px auto 0;
}
.ctl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.avatar {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--chip);
}
.avatar:hover { background: var(--line); }
.play {
  position: relative;
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 8px 22px rgba(10, 10, 10, 0.22);
}
.play:hover { transform: scale(1.04); }
.play:active { transform: scale(0.97); }
.play .icon { width: 30px; height: 30px; }
/* Waiting for a natural voice to produce the next sentence. */
.play.busy::after {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--blue);
  animation: spin 0.9s linear infinite;
}
.speed {
  width: 56px;
  height: 48px;
  border-radius: 14px;
  background: var(--chip);
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.speed:hover { background: var(--line); }

/* Names under buttons, so no icon has to be guessed. */
.btn-label {
  display: none;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.1;
  color: var(--muted);
}
:root[data-labels="on"] .btn-label { display: block; }
:root[data-labels="on"] .topbar .icon-btn,
:root[data-labels="on"] .toolbar .icon-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: auto;
  min-width: 60px;
  height: 50px;
  padding: 0 6px;
}
:root[data-labels="on"] .topbar { grid-template-columns: auto 1fr auto; }
.icon-btn[aria-pressed="true"] .btn-label { color: var(--text); }

/* Wide or short windows: the top bar's buttons put the name beside the icon, which is lower. */
@media (min-width: 920px), (max-height: 620px) {
  .topbar { padding-top: calc(5px + env(safe-area-inset-top)); padding-bottom: 5px; }
  :root[data-labels="on"] .topbar .icon-btn {
    flex-direction: row;
    gap: 7px;
    min-width: 0;
    height: 40px;
    padding: 0 12px;
  }
  :root[data-labels="on"] .topbar .btn-label { font-size: 13px; color: var(--text); }
  .topbar .segmented button { min-height: 34px; }
}

/* The controls should take as little of the page as they can.
   Wide screens: tools, playback and Hide share one row under the progress bar. */
@media (min-width: 920px) {
  .bottom-inner {
    max-width: 1040px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
  }
  .voice-status { grid-column: 1 / -1; grid-row: 1; }
  .hl-strip { grid-column: 1 / -1; grid-row: 2; }
  .player { display: contents; }
  .progress { grid-column: 1 / -1; grid-row: 3; padding-top: 2px; }
  .toolbar { grid-column: 1 / -1; grid-row: 4; padding: 0 0 8px; border-bottom: 0; }
  .controls {
    grid-column: 2;
    grid-row: 4;
    z-index: 1;
    gap: 14px;
    max-width: none;
    margin: 0;
    padding-bottom: 8px;
  }
}

/* "Hide" shrinks everything to a slim player: back, play, forward and the progress bar. */
.bottom.mini .bottom-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.bottom.mini .voice-status { flex: 0 0 100%; }
.bottom.mini .player {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 6px 0;
}
.bottom.mini .progress { flex: 1; order: 2; min-width: 0; padding: 0; }
.bottom.mini .controls {
  order: 1;
  align-items: center;
  gap: 2px;
  max-width: none;
  margin: 0;
  padding: 0;
}
.bottom.mini .ctl .btn-label,
.bottom.mini .ctl:has(#btn-voice),
.bottom.mini .ctl:has(#btn-speed) { display: none; }
.bottom.mini .play { width: 46px; height: 46px; box-shadow: none; }
.bottom.mini .play .icon { width: 24px; height: 24px; }
.bottom.mini .icon-btn.large { width: 42px; height: 42px; }
.bottom.mini .icon-btn.large .icon { width: 27px; height: 27px; }
.bottom.mini .show-tools {
  position: static;
  order: 3;
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 14px;
  background: var(--chip);
  color: var(--text);
}
.bottom.mini .show-tools::before { content: none; }
@media (max-width: 480px) {
  .bottom.mini #time-current { display: none; }
}

/* ---------- Sheets (bottom sheets on phones, centred on desktop) ---------- */

.sheet {
  width: 100%;
  max-width: 540px;
  max-height: 86vh;
  max-height: 86dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 26px 26px 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-3);
}
.sheet[open] {
  display: flex;
  flex-direction: column;
  animation: sheet-in 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet::backdrop {
  background: rgba(10, 10, 10, 0.42);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade-in 0.2s;
}
@keyframes sheet-in { from { transform: translateY(28px); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }
/* A handle, as a hint that the sheet is a layer over the page. */
.sheet::before {
  content: "";
  flex: none;
  width: 40px;
  height: 4px;
  margin: 10px auto 0;
  border-radius: 2px;
  background: var(--track);
}
.sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px 6px 22px;
}
.sheet header h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 26px;
  line-height: 1.15;
}
.sheet header .icon-btn { background: var(--chip); border-radius: 50%; width: 40px; height: 40px; margin: 4px; }
.sheet header .icon-btn .icon { width: 20px; height: 20px; }
.sheet-body {
  overflow-y: auto;
  padding: 6px 22px calc(24px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .sheet { margin: auto; border-radius: 26px; }
  .sheet::before { display: none; }
  .sheet header { padding-top: 14px; }
}
.sheet.tall[open] { height: 86vh; height: 86dvh; }

/* Reading comfort: a sample of the text that stays in view while the settings below scroll. */
.comfort-preview {
  position: relative;
  flex: none;
  height: 148px;
  margin: 2px 22px 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}
.comfort-preview .text-page { max-width: none; padding: 26px 16px 0; }
.comfort-preview .blk { margin: 0; }
.comfort-preview::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 26px;
  background: linear-gradient(transparent, var(--surface));
  pointer-events: none;
}
.preview-tag {
  position: absolute;
  z-index: 1;
  top: 6px;
  left: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
@media (max-height: 620px) { .comfort-preview { height: 96px; } }
.sheet-fixed { padding: 4px 22px 8px; }
.sheet-fixed p { margin-top: 8px; min-height: 1.4em; }
.sheet.tall .sheet-body { flex: 1; }
.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 22px calc(18px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.sheet-actions.inline { padding: 14px 0 0; border: 0; }
.section-title {
  margin: 26px 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.section-title:first-child { margin-top: 6px; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 56px;
  padding: 6px 8px;
  border-radius: 14px;
  text-align: left;
  font-weight: 600;
}
.menu-item:hover { background: var(--chip); }
.menu-item > .icon,
.menu-item > .aa {
  box-sizing: content-box;
  width: 22px;
  height: 22px;
  padding: 9px;
  flex: none;
  border-radius: 12px;
  background: var(--chip);
  text-align: center;
  font-size: 16px;
  line-height: 22px;
}
/* Each sticker sits on its own coloured tile, slightly askew, like a sheet of stickers. */
.menu-item > .icon,
.menu-item > .aa,
.tips li > .icon,
.tips li > .aa {
  background: #f9abee;
  color: #0a0a0a;
  border-radius: 14px;
  transform: rotate(-3deg);
}
:is(.menu-item, .tips li):nth-of-type(5n + 2) > :is(.icon, .aa) { background: #a2bcf7; transform: rotate(2.5deg); }
:is(.menu-item, .tips li):nth-of-type(5n + 3) > :is(.icon, .aa) { background: #f3d98f; transform: rotate(-2deg); }
:is(.menu-item, .tips li):nth-of-type(5n + 4) > :is(.icon, .aa) { background: #a9dfbf; transform: rotate(3deg); }
:is(.menu-item, .tips li):nth-of-type(5n + 5) > :is(.icon, .aa) { background: #c9b8f8; transform: rotate(-2.5deg); }
.menu-item span { flex: 1; }
.menu-item.danger { color: var(--danger); }
#menu-file { overflow-wrap: anywhere; }

.tips { list-style: none; margin: 8px 0 14px; padding: 0; }
.tips li {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  line-height: 1.45;
}
.tips li:last-child { border-bottom: 0; }
.tips li > .icon,
.tips li > .aa {
  box-sizing: content-box;
  flex: none;
  width: 22px;
  height: 22px;
  padding: 9px;
  border-radius: 12px;
  background: var(--tint);
  text-align: center;
  font-size: 16px;
  line-height: 22px;
}

.goto {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 14px;
  padding: 10px 10px 10px 16px;
  border-radius: 16px;
  background: var(--chip);
}
.goto label { font-weight: 600; margin-right: auto; }
#goto-total { white-space: nowrap; }
.goto input {
  width: 84px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--track);
  border-radius: 12px;
  background: var(--surface);
  text-align: center;
}
.goto .btn { background: var(--accent); color: var(--accent-ink); }

.place {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  min-height: 50px;
  padding: 12px 10px;
  border-radius: 12px;
  text-align: left;
}
.place:hover { background: var(--chip); }
.place + .place, .place-row + .place-row { border-top: 1px solid var(--line); border-radius: 0; }
.place-title { overflow-wrap: anywhere; }
.place mark { background: var(--read-word); color: inherit; border-radius: 4px; padding: 0 1px; }
.place-row { display: flex; align-items: center; }
.place-row .place { flex: 1; }

.note-item {
  margin-bottom: 14px;
  padding: 14px 14px 14px 18px;
  border-radius: 16px;
  background: var(--chip);
  border-left: 6px solid var(--mark-yellow);
}
.note-item[data-mark="green"] { border-left-color: var(--mark-green); }
.note-item[data-mark="pink"] { border-left-color: var(--mark-pink); }
.note-item[data-mark="blue"] { border-left-color: var(--mark-blue); }
.note-text { display: block; width: 100%; text-align: left; line-height: 1.45; }
.note-text:hover { text-decoration: underline; text-underline-offset: 3px; }
.note-row { display: flex; align-items: center; justify-content: space-between; }

.pron-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.pron-row .text-input { flex: 1; min-width: 0; }
#paste-form { display: flex; flex-direction: column; gap: 12px; }
#paste-text { flex: 1; min-height: 160px; }
#paste-form .btn { align-self: flex-start; }

.field { display: block; margin: 14px 0 20px; }
.field > span { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 8px; }
.field output { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.field select {
  width: 100%;
  min-height: 50px;
  padding: 0 40px 0 14px;
  border: 1px solid var(--track);
  border-radius: 14px;
  background-color: var(--surface);
}

/* On/off settings are shown as switches. */
.check {
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
}
.check:first-of-type { margin-top: 12px; }
.check > span { flex: 1; font-weight: 500; }
.check small { display: block; margin-top: 2px; font-size: 13px; font-weight: 400; color: var(--muted); }
.check input {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 50px;
  height: 30px;
  margin: 0;
  border-radius: 999px;
  background: var(--track);
  cursor: pointer;
  transition: background-color 0.16s;
}
.check input::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.16s;
}
.check input:checked { background: var(--accent); }
.check input:checked::before { transform: translateX(20px); background: var(--accent-ink); }

.voice-list h3 {
  margin: 22px 0 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.voice-list h3:first-child { margin-top: 6px; }
.voice {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 52px;
  padding: 8px 14px;
  border-radius: 14px;
  text-align: left;
  font-weight: 500;
}
/* A radio mark at the start of each row shows which one is chosen. */
.voice::before {
  content: "";
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--track);
}
.voice:hover { background: var(--chip); }
.voice[aria-pressed="true"],
.voice[aria-checked="true"] { background: var(--tint); font-weight: 600; }
.voice[aria-pressed="true"]::before,
.voice[aria-checked="true"]::before { border: 6px solid var(--accent); }
.voice small { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 13px; white-space: nowrap; }

.presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0 6px;
}
.preset {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 72px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  text-align: left;
}
.preset:hover { border-color: var(--muted); }
.preset strong { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.preset-state {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--chip);
  font-style: normal;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
}
.preset span { font-size: 13px; line-height: 1.35; color: var(--muted); }
.preset[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--tint); }
.preset[aria-pressed="true"] .preset-state { background: var(--accent); color: var(--accent-ink); }
.preset[aria-pressed="true"] span { color: var(--text); }

.themes, .read-colors {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 8px 0;
}
.theme-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 8px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px transparent;
}
.theme-swatch:hover { background: var(--chip); }
.theme-swatch[aria-checked="true"] { box-shadow: inset 0 0 0 2px var(--accent); }
.chip-sample {
  display: grid;
  place-items: center;
  width: 100%;
  height: 44px;
  border: 1px solid rgba(128, 128, 128, 0.35);
  border-radius: 10px;
  font-family: var(--display);
  font-size: 20px;
}
.read-colors .chip-sample { height: 30px; }
[data-theme-choice="light"] .chip-sample { background: #ffffff; color: #0a0a0a; }
[data-theme-choice="cream"] .chip-sample { background: #fbf5e6; color: #2a2620; }
[data-theme-choice="blue"] .chip-sample { background: #eef5fc; color: #1d2733; }
[data-theme-choice="green"] .chip-sample { background: #eff7ee; color: #1e2a20; }
[data-theme-choice="grey"] .chip-sample { background: #e8e6e2; color: #2e2d2b; }
[data-theme-choice="dark"] .chip-sample { background: #151514; color: #f4f3f1; }
[data-read-color="blue"] .chip-sample { background: #a2bcf7; }
[data-read-color="yellow"] .chip-sample { background: #f3d98f; }
[data-read-color="green"] .chip-sample { background: #96d6aa; }
[data-read-color="pink"] .chip-sample { background: #f9abee; }
[data-read-color="orange"] .chip-sample { background: #f8be8c; }
[data-read-color="grey"] .chip-sample { background: #a9a9ae; }

/* A destructive button asks once more before acting. */
.confirming { color: var(--danger) !important; }
.card-remove.confirming {
  width: auto;
  padding: 0 14px;
  border-radius: 22px;
  font-weight: 700;
  font-size: 14px;
}

/* ---------- Overlays ---------- */

.loading, .drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-weight: 600;
}
.drop-overlay {
  inset: 12px;
  border: 2px dashed var(--text);
  border-radius: 28px;
  font-family: var(--display);
  font-weight: 400;
  font-size: 30px;
  pointer-events: none;
}
.spinner {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid var(--track);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  z-index: 30;
  inset: auto auto calc(196px + env(safe-area-inset-bottom)) 50%;
  margin: 0;
  border: 0;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(92vw, 520px);
  padding: 12px 6px 12px 18px;
  border-radius: 18px;
  background: #0a0a0a;
  color: #fff;
  font-size: 15px;
  line-height: 1.4;
  box-shadow: var(--shadow-3);
  align-items: center;
  gap: 8px;
}
:root[data-theme="dark"] .toast { background: #2a2927; }
.toast.error { background: #8c1d18; }
.toast:popover-open, .toast:not([popover]):not([hidden]) { display: flex; }
.toast-close {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
}
.toast-close:hover { background: rgba(255, 255, 255, 0.15); }
.toast-close .icon { width: 18px; height: 18px; }

/* ---------- Reading comfort ---------- */

/* Focus: while a sentence is being read, everything else fades back. */
:root[data-focus="on"] .text-page:has(.s.active) .s,
:root[data-focus="on"] .text-page:has(.s.active) figure { transition: opacity 0.2s, background-color 0.16s; }
:root[data-focus="on"] .text-page:has(.s.active) .s:not(.active),
:root[data-focus="on"] .text-page:has(.s.active) figure { opacity: 0.3; }

:root[data-hl="sentence"] .w.active { background: none; }
:root[data-hl="word"] .s.active { background: none; }

/* Reduce motion: chosen in Reading comfort, or asked for by the device. */
:root[data-motion="reduce"] *,
:root[data-motion="reduce"] *::before,
:root[data-motion="reduce"] *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}
:root[data-motion="reduce"] .card:hover,
:root[data-motion="reduce"] .play:hover,
:root[data-motion="reduce"] button:active { transform: none; }

/* ---------- One sentence at a time ---------- */

.focus-view {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--surface);
  color: var(--text);
  animation: fade-in 0.2s;
}
.focus-view[hidden] { display: none; }
.focus-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 0 22px;
}
.focus-where { font-size: 13px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.focus-head .icon-btn { background: var(--chip); border-radius: 50%; width: 44px; height: 44px; }
.focus-stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: 12px 28px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.focus-sentence {
  max-width: 30ch;
  margin: 0;
  font-family: var(--text-font);
  font-size: clamp(28px, 3.2vw + 16px, 54px);
  font-weight: 500;
  line-height: 1.38;
  letter-spacing: var(--text-letter, 0);
  word-spacing: var(--text-word, 0);
  text-align: center;
  text-wrap: balance;
  overflow-wrap: break-word;
  animation: focus-in 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes focus-in { from { opacity: 0; transform: translateY(10px); } }
.focus-sentence .w { padding: 0 0.06em; border-radius: 0.2em; transition: background-color 0.12s; }
.focus-sentence .w.active { background: var(--read-word); }
.focus-foot { display: grid; justify-items: center; gap: 14px; padding: 8px 22px 18px; }
.focus-track { width: min(420px, 100%); height: 4px; border-radius: 2px; background: var(--track); overflow: hidden; }
.focus-track span { display: block; height: 100%; width: 0; border-radius: 2px; background: var(--text); transition: width 0.3s; }
.focus-controls { display: flex; align-items: center; gap: 28px; }
.focus-hint { margin: 0; font-size: 12px; color: var(--muted); text-align: center; }
@media (max-height: 560px) { .focus-hint { display: none; } }

/* ---------- Reading ruler ---------- */

.text-page { position: relative; z-index: 1; }
.text-ruler {
  position: absolute;
  z-index: 0;
  left: 0;
  width: 100%;
  border-radius: 12px;
  pointer-events: none;
  transition: top 0.18s ease, height 0.18s ease;
}
.text-ruler.band,
.pdf-ruler.band {
  background: rgba(var(--read-rgb), 0.16);
  box-shadow: inset 0 0 0 2px rgba(var(--read-rgb), 0.55);
}
.text-ruler.mask,
.pdf-ruler.mask {
  z-index: 2;
  box-shadow: 0 0 0 200vmax color-mix(in srgb, var(--surface) 68%, transparent);
}
.pdf-ruler { position: absolute; left: 0; width: 100%; pointer-events: none; border-radius: 4px; transition: top 0.18s ease, height 0.18s ease; }

/* ---------- Home: listening progress ---------- */

.progress-card {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 18px 22px;
  margin: 0 0 22px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
.progress-today { display: flex; align-items: center; gap: 14px; }
.goal-ring { position: relative; width: 64px; height: 64px; flex: none; }
.goal-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.goal-ring circle { fill: none; stroke-width: 7; stroke-linecap: round; }
.goal-ring .track { stroke: var(--chip); }
.goal-ring .value { stroke: var(--text); transition: stroke-dashoffset 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); }
.goal-ring .done { stroke: #6cc58d; }
.goal-ring .mark { position: absolute; inset: 0; display: grid; place-items: center; }
.goal-ring .mark { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.progress-figure { font-family: var(--display); font-size: 34px; line-height: 1; }
.progress-figure small { font-family: var(--ui); font-size: 14px; font-weight: 600; margin-left: 4px; }
.progress-sub { margin-top: 4px; font-size: 13px; color: var(--muted); }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; height: 76px; }
.week .day { display: grid; grid-template-rows: 1fr auto; justify-items: center; gap: 6px; height: 100%; }
.week .bar { align-self: end; width: 100%; max-width: 22px; min-height: 5px; border-radius: 7px; background: var(--chip); }
.week .day.has .bar { background: var(--blue); }
.week .day.goal .bar { background: #a9dfbf; }
.week .day.today .bar { background: var(--text); }
.week .label { font-size: 11px; font-weight: 600; color: var(--muted); }
.week .day.today .label { color: var(--text); }
@media (max-width: 420px) {
  .progress-card { grid-template-columns: 1fr; }
}

.paste-tip { margin: 2px 0 10px; }

/* ---------- Choices shown as pills ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 6px; }
.chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  min-height: 44px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  text-align: left;
  transition: background-color 0.15s, border-color 0.15s, transform 0.15s;
}
.chip small { font-size: 12px; font-weight: 500; color: var(--muted); }
.chip:hover { border-color: var(--track); }
.chip:active { transform: scale(0.97); }
.chip[aria-checked="true"] { background: var(--text); border-color: var(--text); color: var(--surface); }
.chip[aria-checked="true"] small { color: color-mix(in srgb, var(--surface) 70%, transparent); }

/* ---------- Save as audio ---------- */

.audio-intro { margin: 0 0 6px; color: var(--muted); }
.page-range { display: flex; flex-wrap: wrap; gap: 10px 16px; margin: 10px 0 4px; font-weight: 600; }
.page-range input {
  width: 84px;
  height: 44px;
  margin-left: 6px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.audio-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0 4px;
}
.audio-summary .fact { padding: 12px 14px; border-radius: 16px; background: var(--chip); }
.audio-summary .fact strong { display: block; font-family: var(--display); font-size: 24px; font-weight: 400; line-height: 1.1; }
.audio-summary .fact span { font-size: 12px; color: var(--muted); }
.audio-summary .note { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.audio-working { padding: 8px 0 0; }
.audio-meter { height: 10px; border-radius: 5px; background: var(--chip); overflow: hidden; }
.audio-meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--blue), var(--pink));
  transition: width 0.4s ease;
}
.audio-status { margin: 14px 0 4px; font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.audio-none p { margin: 0 0 10px; }

/* ---------- A word's meaning ---------- */

.word-title { font-size: 34px !important; }
.word-lang { margin: -4px 0 14px; font-size: 13px; font-weight: 600; color: var(--muted); }
.word-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.word-card { margin: 0 0 12px; padding: 16px 18px; border-radius: 20px; background: var(--chip); }
.word-card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.word-card-title .icon { width: 22px; height: 22px; }
.word-card-title select {
  margin-left: auto;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: 600 13px var(--ui);
  text-transform: none;
  letter-spacing: 0;
}
.word-part { margin: 10px 0 4px; font-size: 13px; font-weight: 700; font-style: italic; color: var(--muted); }
.word-part:first-child { margin-top: 0; }
.word-meanings { margin: 0; padding-left: 20px; line-height: 1.5; }
.word-meanings li + li { margin-top: 4px; }
.word-translated { margin: 0 0 8px; font-size: 22px; font-weight: 600; }
.word-sentence { margin: 0; line-height: 1.5; color: var(--text); }
.word-sentence-label { display: block; margin-bottom: 2px; font-size: 12px; font-weight: 700; color: var(--muted); }
.word-source { margin: 4px 2px 0; }
.word-wait { color: var(--muted); }

/* The old address points people to the new one. */
.moved-address {
  margin: 0 0 14px;
  font-family: "Fredoka", var(--ui);
  font-weight: 500;
  font-size: 30px;
  color: #0a0a0a;
  -webkit-text-stroke: 6px #fff;
  paint-order: stroke fill;
  filter: drop-shadow(0 1px 1.5px rgba(10, 10, 10, 0.22));
}
#moved-go { text-decoration: none; }

/* A downloadable voice: the voice, then Download / progress / Remove beside it. */
.voice-row { display: flex; align-items: center; gap: 8px; }
.voice-row .voice { flex: 1; min-width: 0; }
.voice-dl {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 92px;
  height: 38px;
  padding: 0 12px;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.voice-dl .icon { width: 18px; height: 18px; }
.voice-dl:hover:not(:disabled) { border-color: var(--track); }
.voice-dl:disabled { opacity: 1; color: var(--muted); }
.voice-dl.remove { min-width: 0; border-color: transparent; background: none; color: var(--muted); font-weight: 500; }
.voice-dl.remove:hover { color: var(--danger); }
/* With the Download button beside it, the details go under the name instead of beside it. */
.voice-row .voice { flex-wrap: wrap; row-gap: 2px; padding-top: 10px; padding-bottom: 10px; }
.voice-row .voice small { flex-basis: 100%; margin-left: 32px; white-space: normal; }
