/* EasyRead styles.
   Themes live as custom properties on :root[data-theme=…].
   contrast.js checks every text/background pair during development. */

/* ---------- Reading fonts (self-hosted for offline use) ---------- */

@font-face {
  font-family: "OpenDyslexic";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/opendyslexic-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "OpenDyslexic";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("./fonts/opendyslexic-latin-700-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/atkinson-hyperlegible-latin-ext-400-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("./fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("./fonts/atkinson-hyperlegible-latin-ext-700-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

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

:root {
  --sys-font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --read-font: "OpenDyslexic", var(--sys-font);
  --read-size: 19px;
  --lh: 1.8;
  --ls: 0em;
  --ws: 0em;
  --measure: 60;
  --side-pad: 20px;

  --radius-sheet: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
  --dur: 250ms;
  --ease: cubic-bezier(0.32, 0.72, 0, 1); /* quick start, soft landing */
  --spring: cubic-bezier(0.34, 1.36, 0.64, 1); /* a little overshoot, like a spring */
  --bar-h: 52px;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

@media (min-width: 744px) {
  :root { --read-size: 21px; --side-pad: 32px; }
}

/* ---------- Themes ---------- */
/* Every text/background pair reaches 7:1 (checked by contrast.js on
   localhost). The current word sits on a solid color so its contrast
   doesn't depend on the sentence highlight underneath. In Dark and
   Night it's a solid amber "highlighter" with dark ink, because the
   lighter amber in the guide only reaches about 4.5:1 with light text. */

:root,
:root[data-theme="paper"] {
  color-scheme: light;
  --bg: #FBF5E9;
  --bg-rgb: 251, 245, 233;
  --text: #2B2620;
  --muted: #574F44;
  --hl: rgba(245, 196, 81, 0.35);
  --word-bg: #F7D077;
  --word-text: #2B2620;
  --word-line: #E9A93B;
  --accent: #E9A93B;
  --on-accent: #2B2620;
  --surface: rgba(255, 253, 248, 0.86);
  --surface-solid: #FFFDF8;
  --fill: rgba(43, 38, 32, 0.06);
  --fill-strong: rgba(43, 38, 32, 0.11);
  --separator: rgba(43, 38, 32, 0.12);
}

:root[data-theme="sky"] {
  color-scheme: light;
  --bg: #EAF2F8;
  --bg-rgb: 234, 242, 248;
  --text: #1E2A35;
  --muted: #46525E;
  --hl: rgba(245, 196, 81, 0.38);
  --word-bg: #F2D07B;
  --word-text: #1E2A35;
  --word-line: #E9A93B;
  --accent: #E9A93B;
  --on-accent: #1E2A35;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-solid: #F8FBFD;
  --fill: rgba(30, 42, 53, 0.06);
  --fill-strong: rgba(30, 42, 53, 0.11);
  --separator: rgba(30, 42, 53, 0.12);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1C1C1E;
  --bg-rgb: 28, 28, 30;
  --text: #E5E5E7;
  --muted: #B4B4B8;
  --hl: rgba(245, 196, 81, 0.22);
  --word-bg: #F2C14E;
  --word-text: #1C1C1E;
  --word-line: #1C1C1E;
  --accent: #F2C14E;
  --on-accent: #1C1C1E;
  --surface: rgba(44, 44, 46, 0.86);
  --surface-solid: #2C2C2E;
  --fill: rgba(229, 229, 231, 0.08);
  --fill-strong: rgba(229, 229, 231, 0.14);
  --separator: rgba(229, 229, 231, 0.14);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.32);
}

:root[data-theme="night"] {
  color-scheme: dark;
  --bg: #17140F;
  --bg-rgb: 23, 20, 15;
  --text: #D9CBB3;
  --muted: #B3A68F;
  --hl: rgba(230, 170, 90, 0.20);
  --word-bg: #E6AA5A;
  --word-text: #17140F;
  --word-line: #17140F;
  --accent: #F2C14E;
  --on-accent: #17140F;
  --surface: rgba(36, 31, 24, 0.9);
  --surface-solid: #241F18;
  --fill: rgba(217, 203, 179, 0.08);
  --fill-strong: rgba(217, 203, 179, 0.14);
  --separator: rgba(217, 203, 179, 0.14);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

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

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sys-font);
  font-size: 1rem;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

[hidden] { display: none !important; }

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

button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: opacity 150ms var(--ease), background-color 150ms var(--ease), transform var(--dur) var(--ease);
}

button:disabled { cursor: default; }

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon.filled { fill: currentColor; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  color: var(--text);
}

.icon-btn:active { background: var(--fill); }

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px 0 14px;
  border-radius: 999px;
  background: var(--fill);
  font-size: 0.9375rem;
  font-weight: 600;
}

.pill-btn .icon { width: 20px; height: 20px; }
.pill-btn:active { background: var(--fill-strong); }
.pill-btn.small { min-height: 40px; padding: 0 14px 0 12px; font-size: 0.875rem; }
.pill-btn.small .icon { width: 18px; height: 18px; }

/* ---------- App shell ---------- */

.app {
  position: relative;
  display: flex;
  height: 100vh;
  height: 100dvh;
}

.view {
  position: absolute;
  inset: 0;
}

/* ---------- Library ---------- */

.library {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding:
    calc(var(--safe-t) + 8px)
    calc(var(--safe-r) + 20px)
    calc(var(--safe-b) + 32px)
    calc(var(--safe-l) + 20px);
}

.library-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  margin: 8px 0 12px;
}

.library-head .icon-btn { margin-right: -10px; }
.library-head .icon { width: 26px; height: 26px; }

.large-title {
  min-width: 0;
  margin: 0;
  font-size: min(2.125rem, 11.5vw);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.022em;
}

.doc-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.doc-list li + li { box-shadow: 0 -1px 0 var(--separator); }

.doc-row {
  display: block;
  width: 100%;
  padding: 14px 0;
  text-align: left;
}

.doc-row:active { opacity: 0.6; }

.doc-title {
  display: block;
  overflow: hidden;
  font-family: var(--read-font);
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.doc-sub {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-top: 2px;
  color: var(--muted);
}

.doc-preview {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-family: var(--read-font);
  font-size: 0.9375rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.doc-time {
  flex: none;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-height: 55vh;
  min-height: 55dvh;
  text-align: center;
}

.empty p {
  margin: 0;
  font-family: var(--read-font);
  font-size: 1.25rem;
  line-height: 1.5;
}

.big-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 200px;
  min-height: 56px;
  padding: 0 28px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 1.0625rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.big-btn:active { transform: scale(0.97); }

.library-foot {
  margin: 28px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

/* ---------- Reader ---------- */

.reader { overflow: hidden; }

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  height: calc(var(--bar-h) + var(--safe-t));
  padding: var(--safe-t) calc(var(--safe-r) + 10px) 0 calc(var(--safe-l) + 6px);
  background: var(--surface);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  backdrop-filter: blur(20px) saturate(1.4);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.topbar .back .icon { width: 28px; height: 28px; }

.topbar-title {
  margin: 0;
  overflow: hidden;
  font-family: var(--read-font);
  font-size: 0.9375rem;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.topbar.titled .topbar-title { opacity: 1; transform: none; }

.aa-btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  font-size: 1.0625rem;
  font-weight: 600;
}

.aa-btn:active,
.aa-btn[aria-expanded="true"] { background: var(--fill); }

.reader.bar-hidden .topbar {
  opacity: 0;
  transform: translateY(-100%);
  pointer-events: none;
}

.reader-scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: calc(var(--bar-h) + var(--safe-t) + 20px) 0 calc(var(--safe-b) + 150px);
  -webkit-tap-highlight-color: transparent;
}

.page {
  max-width: calc(var(--measure) * 1ch + 2 * var(--side-pad));
  margin: 0 auto;
  padding: 0 calc(var(--side-pad) + var(--safe-r)) 0 calc(var(--side-pad) + var(--safe-l));
  font-family: var(--read-font);
  font-size: var(--read-size);
  font-style: normal;
  line-height: var(--lh);
  letter-spacing: var(--ls);
  word-spacing: var(--ws);
  text-align: left;
  hyphens: manual;
  overflow-wrap: break-word;
}

.page p { margin: 0 0 1em; }
.page p.tight { margin-bottom: 0.3em; }

.page .doc-heading {
  margin: 0 0 0.8em;
  font-size: 1.4em;
  font-weight: 700;
  line-height: 1.35;
}

.s {
  border-radius: 6px;
  cursor: pointer;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.s.cur {
  background-color: var(--hl);
  box-shadow: 0 0 0 0.14em var(--hl);
}

.s.cur.paused {
  background-color: color-mix(in srgb, var(--hl) 55%, transparent);
  box-shadow: 0 0 0 0.14em color-mix(in srgb, var(--hl) 55%, transparent);
}

.w { position: relative; border-radius: 4px; }

.w.cur,
.w.flash {
  background-color: var(--word-bg);
  box-shadow: 0 0 0 0.08em var(--word-bg);
  color: var(--word-text);
}

.w.cur::after,
.w.flash::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -0.14em;
  height: 2px;
  border-radius: 2px;
  background: var(--word-line);
}

/* Line focus */

.ruler {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  --band-top: 30%;
  --band-bottom: 45%;
}

.ruler-mask {
  position: absolute;
  left: 0;
  right: 0;
  background: rgba(var(--bg-rgb), 0.65);
}

.ruler-mask.top { top: 0; height: var(--band-top); }
.ruler-mask.bottom { top: var(--band-bottom); bottom: 0; }
.ruler.animate .ruler-mask { transition: height var(--dur) var(--ease), top var(--dur) var(--ease); }

.ruler-handle {
  position: absolute;
  top: calc((var(--band-top) + var(--band-bottom)) / 2);
  right: calc(var(--safe-r) + 8px);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-top: -22px;
  border-radius: 999px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  color: var(--muted);
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
}

.ruler.reading .ruler-handle { display: none; }

/* Player */

.player-area {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-b) + 16px);
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.player-area > * { pointer-events: auto; }

/* One round play button; while reading it grows into a pill. */
.player {
  display: flex;
  align-items: center;
  max-width: calc(100% - 16px);
  padding: 0;
  border-radius: 999px;
  background: transparent;
  transition: padding var(--dur) var(--spring), background-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.player.playing {
  padding: 6px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  backdrop-filter: blur(20px) saturate(1.4);
  box-shadow: var(--shadow);
}

.player-side {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-width var(--dur) var(--spring), opacity 200ms var(--ease);
}

.player.playing .player-side {
  max-width: 180px;
  opacity: 1;
}

.player.playing .player-side:first-child { padding-right: 6px; }
.player.playing .player-side:last-child { padding-left: 6px; }

.player-btn {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 999px;
}

.player-btn:active { background: var(--fill); }

.player-btn.play {
  flex: none;
  width: 60px;
  height: 60px;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow);
}

.player.playing .player-btn.play {
  width: 56px;
  height: 56px;
  box-shadow: none;
}

.player-btn.play:active { transform: scale(0.94); background: var(--accent); }
.player-btn.play .icon { width: 26px; height: 26px; }
.player-btn .icon.filled { stroke-width: 1.5; }

.speed-btn {
  min-width: 56px;
  height: 44px;
  margin: 0 4px 0 2px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--fill);
  font-size: 0.9375rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.speed-btn:active { background: var(--fill-strong); }

.player-line {
  max-width: calc(100% - 32px);
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
}

.no-voice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 12px;
  max-width: calc(100% - 32px);
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
}

.no-voice p { margin: 0; }

.chip {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + 92px);
  z-index: 30;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

/* ---------- Sheets ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: transparent;
  transition: background-color var(--dur) var(--ease);
}

.backdrop.dim { background: rgba(0, 0, 0, 0.25); }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  max-height: min(80vh, 760px);
  max-height: min(80dvh, 760px);
  padding-bottom: var(--safe-b);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  background: var(--surface);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  backdrop-filter: blur(20px) saturate(1.4);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.12);
  color: var(--text);
  transform: translateY(105%);
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}

.sheet.open { transform: translateY(0); }
.sheet.dragging { transition: none; }
.sheet:focus { outline: none; }

.sheet-bar,
.sheet-head {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 4px;
}

.sheet-head { padding-left: 20px; touch-action: none; }

.sheet-head h2 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
}

.bar-btn {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 1.0625rem;
}

.bar-btn.strong { font-weight: 600; }
.bar-btn:active { background: var(--fill); }
.bar-btn:disabled { opacity: 0.35; background: none; }

.sheet-grab {
  flex: none;
  padding-top: 8px;
  touch-action: none;
}

.sheet-grabber {
  width: 36px;
  height: 5px;
  margin: 0 auto;
  border-radius: 3px;
  background: var(--fill-strong);
}

.sheet-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 20px 20px;
}

/* New text (full height) */

.new-sheet {
  top: calc(var(--safe-t) + 10px);
  max-height: none;
  background: var(--bg);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.new-sheet textarea {
  flex: 1;
  width: 100%;
  min-height: 0;
  padding: 8px calc(var(--safe-r) + 20px) 16px calc(var(--safe-l) + 20px);
  border: 0;
  background: transparent;
  font-family: var(--read-font);
  font-size: max(16px, 1.0625rem);
  line-height: 1.6;
  resize: none;
  -webkit-appearance: none;
  appearance: none;
}

.new-sheet textarea:focus { outline: none; }
.new-sheet textarea::placeholder { color: var(--muted); opacity: 1; }

.new-actions {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px calc(var(--safe-r) + 20px) 14px calc(var(--safe-l) + 20px);
}

/* "Aa" sheet (like Apple Books) */

.look-page {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 20px 20px;
  animation: page-in var(--dur) var(--ease);
}

@keyframes page-in {
  from { opacity: 0; transform: translateX(12px); }
}

.size-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.size-btn {
  min-height: 48px;
  border-radius: 999px;
  background: var(--fill);
  font-weight: 600;
  line-height: 1;
}

.size-btn.small { font-size: 15px; }
.size-btn.large { font-size: 25px; }
.size-btn:active { background: var(--fill-strong); }
.size-btn:disabled { opacity: 0.35; }

.swatches {
  display: flex;
  flex-wrap: wrap; /* only wraps on very narrow screens, like 200% zoom */
  justify-content: space-between;
  gap: 12px;
}

.swatch {
  flex: 1 1 0;
  min-width: 44px;
  max-width: 64px;
  aspect-ratio: 1;
  border-radius: 999px;
  background: var(--sw-bg);
  color: var(--sw-text);
  font-family: var(--read-font);
  font-size: 17px;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(127, 127, 127, 0.28);
}

.swatch[aria-pressed="true"] {
  box-shadow: inset 0 0 0 1px rgba(127, 127, 127, 0.28), 0 0 0 2px var(--bg), 0 0 0 4px var(--text);
}

.look-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  width: 100%;
  min-height: 48px;
  text-align: left;
}

.look-label { flex: none; font-weight: 500; }

.look-line .seg { flex: 1 1 180px; max-width: 240px; }

.seg {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 12px;
  background: var(--fill);
}

.seg button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 0 8px;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
}

.seg button[aria-pressed="true"] {
  background: var(--surface-solid);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  font-weight: 600;
}

.seg .font-dyslexic { font-family: "OpenDyslexic", var(--sys-font); font-size: 0.8125rem; }
.seg .font-standard { font-family: "Atkinson Hyperlegible", var(--sys-font); }

.switch {
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  border-radius: 999px;
  background: var(--fill-strong);
  transition: background-color var(--dur) var(--ease);
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
  transition: transform var(--dur) var(--ease);
}

[aria-checked="true"] > .switch { background: var(--accent); }
[aria-checked="true"] > .switch::after { transform: translateX(20px); }

.nav-row .nav-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.nav-row .chevron { width: 18px; height: 18px; margin-left: -10px; color: var(--muted); }
.nav-row:active { opacity: 0.6; }

/* Voice list (pushed from Voice) */

.page-head {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  margin: -6px -10px 0;
}

.page-head h2 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
  text-align: center;
}

.list-label {
  margin: 4px 0 -6px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

.voice-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.voice-list button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  text-align: left;
}

.voice-list button:active { opacity: 0.6; }
.voice-list .voice-note { color: var(--muted); font-size: 0.875rem; }
.voice-list .icon { width: 20px; height: 20px; color: var(--text); visibility: hidden; }
.voice-list [aria-checked="true"] .icon { visibility: visible; }

.list-foot {
  margin: 0;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.4;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  top: calc(var(--safe-t) + 12px);
  left: 50%;
  z-index: 70;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: 16px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.35;
  text-align: center;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- iPad and Mac (900px and wider) ---------- */

@media (min-width: 900px) {
  /* The library becomes a sidebar next to the reader. */
  .library,
  .library[hidden] {
    position: relative;
    display: block !important;
    flex: none;
    width: 340px;
    padding-left: calc(var(--safe-l) + 16px);
    padding-right: 16px;
    background-image: linear-gradient(var(--fill), var(--fill));
    box-shadow: inset -1px 0 0 var(--separator);
  }

  .library .large-title { font-size: 1.75rem; }
  .doc-row { padding: 12px 10px; border-radius: 10px; }
  .doc-row.active { background: var(--fill-strong); }
  .doc-list li + li { box-shadow: none; }

  .reader {
    position: relative;
    inset: auto;
    flex: 1;
  }

  .topbar { grid-template-columns: 44px minmax(0, 1fr) 44px; }
  .topbar .back { visibility: hidden; }

  .look-sheet {
    left: auto;
    right: calc(var(--safe-r) + 12px);
    bottom: auto;
    top: calc(var(--safe-t) + var(--bar-h) + 8px);
    width: 380px;
    max-height: calc(100dvh - var(--bar-h) - var(--safe-t) - 24px);
    padding-bottom: 0;
    border-radius: var(--radius-sheet);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.16);
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
    transform-origin: top right;
  }

  .look-sheet.open { opacity: 1; transform: none; }

  .new-sheet {
    left: 50%;
    right: auto;
    top: 50%;
    bottom: auto;
    width: min(640px, calc(100vw - 48px));
    height: min(80dvh, 720px);
    padding-bottom: 0;
    border-radius: var(--radius-sheet);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.16);
    opacity: 0;
    transform: translate(-50%, -48%) scale(0.98);
  }

  .new-sheet.open { opacity: 1; transform: translate(-50%, -50%); }

  .sheet-grab { display: none; }
  .sheet-head { padding-top: 10px; }
}

/* ---------- Very narrow screens (small phones, or 200% zoom) ---------- */

@media (max-width: 340px) {
  .player.playing { padding: 4px; }
  .player-side { gap: 2px; }
  .player-btn { width: 44px; height: 44px; }
  .player-btn.play,
  .player.playing .player-btn.play { width: 48px; height: 48px; }
  .speed-btn { min-width: 44px; margin: 0; padding: 0 8px; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
