:root {
  color-scheme: dark;
  --ink: #e8eeeb;
  --ink-soft: #a8b5ad;
  --paper: #121816;
  --paper-deep: #0d1110;
  --forest: #52b788;
  --forest-deep: #95d5b2;
  --moss: #74c69d;
  --highlight: #f4d35e;
  --highlight-run: rgba(82, 183, 136, 0.16);
  --badge-ar: #40916c;
  --badge-en: #4cc9f0;
  --line: rgba(232, 238, 235, 0.12);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --surface: rgba(24, 32, 28, 0.92);
  --surface-soft: rgba(32, 42, 36, 0.75);
  --radius: 14px;
  --font-brand: "Fraunces", Georgia, serif;
  --font-ar: "Amiri", "Traditional Arabic", serif;
  --font-en: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --font-ui: "IBM Plex Sans", system-ui, sans-serif;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font-ui);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(64, 145, 108, 0.14), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(76, 201, 240, 0.08), transparent 55%),
    linear-gradient(180deg, #1a221e 0%, var(--paper) 45%, var(--paper-deep) 100%);
  animation: drift 18s ease-in-out infinite alternate;
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.22;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
  pointer-events: none;
}

@keyframes drift {
  from {
    transform: scale(1) translateY(0);
  }
  to {
    transform: scale(1.03) translateY(-8px);
  }
}

.top {
  padding: 1.25rem 1.25rem 0.5rem;
  max-width: 42rem;
  margin: 0 auto;
}

.brand-lockup {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  animation: rise 0.7s ease both;
}

@supports (animation-timeline: view()) {
  /* no-op: keeps cascade tidy */
}

.brand {
  margin: 0;
  font-family: var(--font-brand);
  font-size: clamp(2.4rem, 9vw, 3.4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--forest-deep);
}

.brand-ar {
  margin: 0;
  font-family: var(--font-ar);
  font-size: clamp(1.6rem, 6vw, 2.1rem);
  color: var(--moss);
  line-height: 1;
}

.tagline {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
  animation: rise 0.7s ease 0.08s both;
}

.shell {
  max-width: 42rem;
  margin: 0 auto;
  padding: 0.75rem 1.1rem calc(2.5rem + env(safe-area-inset-bottom));
}

.book-meta {
  margin: 1rem 0 1.1rem;
.upload-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.75rem;
  margin: 0 0 0.95rem;
  padding: 0.75rem 0.85rem;
  border: 1px dashed rgba(82, 183, 136, 0.35);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  background: var(--forest);
  color: #f4faf7;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}

.sample-link {
  font-size: 0.82rem;
  color: var(--forest);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.file-status {
  flex: 1 1 100%;
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.library-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.library-select {
  max-width: min(14rem, 42vw);
  padding: 0.4rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(82, 183, 136, 0.35);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.voice-list {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--ink-soft);
  max-height: 50vh;
  overflow: auto;
}

.en-engine {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 0.55rem;
}

.en-title {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 1.05rem;
  font-weight: 560;
  color: var(--forest);
}

.en-engine label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.en-engine select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  background: var(--surface);
  font: inherit;
  color: var(--ink);
}

.en-status {
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  background: rgba(82, 183, 136, 0.08);
  border: 1px solid var(--line);
}

.en-status[data-phase="download"],
.en-status[data-phase="import"],
.en-status[data-phase="queued"],
.en-status[data-phase="synthesize"] {
  background: rgba(217, 119, 6, 0.12);
}

.en-status[data-phase="ready"] {
  background: rgba(64, 145, 108, 0.14);
}

.en-status[data-phase="error"] {
  background: rgba(185, 28, 28, 0.12);
}

.en-status-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.84rem;
  color: var(--ink);
}

.en-bar {
  margin-top: 0.45rem;
  height: 6px;
  border-radius: 999px;
  background: rgba(20, 34, 28, 0.12);
  overflow: hidden;
}

.en-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--forest);
  transition: width 0.2s ease;
}

.en-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

  animation: rise 0.7s ease 0.12s both;
}

.book-meta h1 {
  margin: 0;
  font-family: var(--font-brand);
  font-size: clamp(1.45rem, 5.5vw, 1.9rem);
  font-weight: 560;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.45;
}

.transport {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 0.55rem 0.65rem;
  background: var(--surface);
  padding: 0.7rem;
  margin-bottom: 0.85rem;
  background: rgba(231, 238, 241, 0.88);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  animation: rise 0.7s ease 0.16s both;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.65rem 1.05rem;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
  touch-action: manipulation;
}

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

.btn.primary {
  background: var(--forest);
  color: #f4faf7;
  min-width: 5.2rem;
}

.btn.primary[aria-pressed="true"] {
  background: #d97706;
  color: #1a1205;
}

.btn.ghost {
  background: transparent;
  color: var(--forest);
  border: 1px solid rgba(27, 67, 50, 0.28);
}

.rate-wrap {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  grid-column: 1 / -1;
}

.rate-wrap input {
  flex: 1;
  accent-color: var(--forest);
}

.rate-wrap span:not(.sr-only) {
  min-width: 2.6rem;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.live {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.6rem;
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  background: rgba(20, 34, 28, 0.08);
  font-weight: 600;
  font-size: 0.8rem;
  transition: background 0.25s ease, color 0.25s ease;
}

.badge[data-lang="ar"] {
  background: var(--badge-ar);
  color: #eaf6ef;
  font-family: var(--font-ar);
}

.badge[data-lang="en"] {
  background: var(--badge-en);
  color: #eef3fa;
}

.voices {
  margin-bottom: 1rem;
  background: var(--surface-soft);
  border-radius: var(--radius);
  padding: 0.35rem 0.85rem 0.85rem;
  background: rgba(255, 255, 255, 0.35);
}

.voices summary {
  cursor: pointer;
  padding: 0.55rem 0;
  font-weight: 600;
  color: var(--forest);
}

.voice-grid {
  display: grid;
  gap: 0.7rem;
}

.voice-grid label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.voice-grid select {
  width: 100%;
  background: var(--surface);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  background: #fff;
  font: inherit;
  color: var(--ink);
}

.device-note {
  margin: 0.75rem 0 0;
  font-size: 0.82rem;
  line-height: 1.45;
.reader-shell {
  position: relative;
  margin-top: 0.5rem;
}

.scrubber-demo {
  pointer-events: none;
}

.scrubber-demo > * {
  pointer-events: auto;
}

.scrubber-open {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  z-index: 4;
  font-size: 0.78rem;
  padding: 0.35rem 0.65rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.scrubber-overlay[hidden] {
  display: none !important;
}

.scrubber-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0.75rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom));
  background: rgba(8, 14, 12, 0.45);
  backdrop-filter: blur(6px);
}

.scrubber-sheet {
  display: flex;
  flex-direction: column;
  max-height: min(78vh, 520px);
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.scrubber-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--line);
}

.scrubber-sheet-title {
  margin: 0;
  font-size: 0.95rem;
  font-family: var(--font-brand);
  color: var(--forest);
}

.scrubber-seek-block {
  padding: 0.65rem 0.85rem 0.35rem;
  border-bottom: 1px solid var(--line);
}

.scrubber-seek-label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.scrubber-range {
  width: 100%;
  accent-color: var(--forest);
}

.scrubber-preview {
  margin: 0;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--line);
  max-height: 28vh;
  overflow: hidden;
}

.scrubber-preview[hidden] {
  display: none !important;
}

.scrubber-preview-title {
  margin: 0 0 0.45rem;
  font-family: var(--font-brand);
  font-size: 1.05rem;
  color: var(--forest);
}

.scrubber-preview-excerpt {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.scrubber-preview-meta {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.scrubber-toc {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow: auto;
}

.scrubber-toc li.is-active .scrubber-toc-btn {
  background: rgba(82, 183, 136, 0.14);
}

.scrubber-toc-btn {
  width: 100%;
  text-align: start;
  padding: 0.65rem 0.85rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.scrubber-toc-title {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
}

.section.scrubber-flash {
  animation: scrubber-flash 0.9s ease;
}

@keyframes scrubber-flash {
  0% {
    background: rgba(82, 183, 136, 0.22);
  }
  100% {
    background: transparent;
  }
}

  color: var(--ink-soft);
  background: var(--surface-soft);

.reader {
  padding: 1.15rem 1rem 1.4rem;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  padding: 1.15rem 1rem 1.4rem;
  box-shadow: var(--shadow);
  animation: rise 0.8s ease 0.2s both;
}

.section + .section {
  margin-top: 1.6rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
}

.section h2 {
  margin: 0 0 0.85rem;
  font-family: var(--font-brand);
  font-size: 1.15rem;
  font-weight: 560;
  color: var(--forest);
}

.block {
  margin: 0 0 0.95rem;
  line-height: 1.75;
  font-size: 1.08rem;
  color: var(--ink);
}

.block.lang-ar,
.run-ar {
  font-family: var(--font-ar);
  font-size: 1.28rem;
  line-height: 1.9;
}

.block.lang-en,
.run-en {
  font-family: var(--font-en);
}

.run {
  border-radius: 0.25em;
  transition: background 0.25s ease;
}

.run.is-speaking {
  background: var(--highlight-run);
}

.word {
  cursor: pointer;
  border-radius: 0.2em;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}

.word:focus-visible {
  outline: 2px solid var(--moss);
  outline-offset: 2px;
}

.word.is-active {
  background: var(--highlight);
  box-shadow: 0 0 0 2px var(--highlight);
  animation: pulse-word 0.45s ease;
}

@keyframes pulse-word {
  from {
    transform: scale(1.03);
  }
  to {
    transform: scale(1);
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.foot {
  margin-top: 1.25rem;
  color: var(--ink-soft);
  font-size: 0.86rem;
  line-height: 1.5;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (min-width: 640px) {
  .transport {
    grid-template-columns: auto auto 1fr auto;
  }

  .rate-wrap {
    grid-column: auto;
  }

  .live {
    grid-column: auto;
    justify-content: end;
  }

  .voice-grid {
    grid-template-columns: 1fr 1fr;
  }

  .reader {
    padding: 1.5rem 1.4rem 1.75rem;
  }
}

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