:root {
  --bg: #FBF8F3;
  --surface: #FFFFFF;
  --ink: #1F3A5F;
  --ink-soft: #5B6B80;
  --track: #E6DFD2;
  --gold: #E8B04B;
  --gold-soft: #FFF4DC;
  --gold-ink: #C98F22;
  --danger: #B4442F;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(31, 58, 95, 0.06), 0 4px 14px rgba(31, 58, 95, 0.07);
  --shadow-cover: 0 4px 10px rgba(20, 42, 71, 0.12), 0 18px 40px rgba(20, 42, 71, 0.22);
  --gutter: 24px;
  --cover: min(78vw, 340px, 44vh);
  --font: "Nunito", ui-rounded, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100vh; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

a { color: inherit; text-decoration: none; }

.app { min-height: 100vh; }

.loading {
  margin: 0;
  padding-top: 40vh;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink-soft);
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.icon-btn svg { width: 26px; height: 26px; }
.icon-btn:active { transform: scale(0.94); }

/* ---------- Cover ---------- */

.cover {
  position: relative;
  width: var(--cover);
  height: var(--cover);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-cover);
  background: var(--ink);
}

.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Generated cover for passages without a `cover:` image. */
.cover-art {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10%;
  text-align: center;
  color: #fff;
  background:
    radial-gradient(circle at 50% 24%, rgba(232, 176, 75, 0.28), transparent 46%),
    linear-gradient(165deg, #284A75 0%, #142A47 100%);
}

.cover-art::after {
  content: "";
  position: absolute;
  top: 5%;
  right: 5%;
  bottom: 5%;
  left: 5%;
  border: 2px solid rgba(232, 176, 75, 0.45);
  border-radius: 10px;
  pointer-events: none;
}

.cover-star { width: 26%; color: var(--gold); margin-bottom: 7%; }
.cover-star svg { display: block; width: 100%; height: auto; }

.cover-title {
  font-size: calc(var(--cover) * 0.15);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.01em;
}

.cover-sub {
  margin-top: 5%;
  font-size: calc(var(--cover) * 0.062);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}

/* ---------- Player ---------- */

.player {
  position: relative;
  min-height: 100vh;
  max-width: 1040px;
  margin: 0 auto;
  padding: 28px var(--gutter) calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
}

.library-btn { position: absolute; top: 16px; left: var(--gutter); z-index: 1; }

.cover-wrap { flex: none; }

.player-main {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 18px;
}

.now { text-align: center; }

.now-title {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  line-height: 1.15;
}

.now-sub {
  margin: 4px 0 0;
  font-size: 19px;
  font-weight: 700;
  color: var(--ink-soft);
}

.now-error {
  margin: 6px 0 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--danger);
}

/* Scrubber */

.scrubber { width: 100%; }

.scrub {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 36px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

.scrub:focus { outline: none; }

.scrub::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--gold) var(--pct, 0%), var(--track) var(--pct, 0%));
}

.scrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -9px;
  border-radius: 50%;
  background: var(--ink);
  border: 4px solid var(--surface);
  box-shadow: 0 1px 4px rgba(20, 42, 71, 0.3);
}

.scrub::-moz-range-track { height: 6px; border-radius: 3px; background: var(--track); }
.scrub::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--gold); }
.scrub::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ink);
  border: 4px solid var(--surface);
  box-shadow: 0 1px 4px rgba(20, 42, 71, 0.3);
}

.times {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 2px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}


/* Transport controls */

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
}

.ctl {
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
  transition: transform 0.12s ease, opacity 0.2s ease, background-color 0.15s ease;
}

.ctl:active { transform: scale(0.92); background: rgba(31, 58, 95, 0.07); }
.ctl:disabled { opacity: 0.28; cursor: default; }
.ctl:disabled:active { transform: none; background: none; }

.ctl-skip { width: 88px; height: 88px; }
.ctl-skip svg { width: 60px; height: 60px; }

.ctl-play {
  width: 116px;
  height: 116px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 6px 18px rgba(31, 58, 95, 0.3);
}

.ctl-play svg { width: 48px; height: 48px; }
.ctl-play:active { background: #172D4A; }

/* Speed */

.toolbar {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
}

.tool {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 17px;
  font-weight: 800;
  color: var(--ink-soft);
}

.tool-strong { color: var(--ink); }
.tool:active { transform: scale(0.96); }

/* ---------- Library (only shown with more than one passage) ---------- */

.library {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px var(--gutter) 32px;
}

.library-title { margin: 0 0 16px; font-size: 32px; font-weight: 800; }

.book-row {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 12px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.book-row:active { transform: scale(0.98); }

.cover-mini { --cover: 96px; flex: none; }
.cover-mini .cover { border-radius: 10px; box-shadow: 0 2px 8px rgba(20, 42, 71, 0.2); }
.cover-mini .cover-art::after { border-radius: 6px; border-width: 1px; }

.book-info { display: flex; flex-direction: column; min-width: 0; }
.book-title { font-size: 24px; font-weight: 800; line-height: 1.15; }
.book-sub { margin-top: 2px; font-size: 16px; font-weight: 700; color: var(--ink-soft); }

/* ---------- Messages ---------- */

.message {
  max-width: 560px;
  margin: 12vh auto 0;
  padding: 28px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  border-top: 6px solid var(--danger);
}

.message h1 { margin: 0 0 8px; font-size: 26px; }
.message p { margin: 0 0 8px; font-size: 18px; font-weight: 600; color: var(--ink-soft); }
.message pre {
  margin: 12px 0 0;
  padding: 14px;
  border-radius: 12px;
  background: var(--bg);
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Small phones ---------- */

@media (max-width: 400px) {
  :root { --gutter: 16px; }
  .controls { gap: 24px; }
  .ctl-skip { width: 76px; height: 76px; }
  .ctl-skip svg { width: 52px; height: 52px; }
  .ctl-play { width: 100px; height: 100px; }
  .now-title { font-size: 25px; }
}

/* ---------- Short landscape screens (Echo Show 5 at 960×480, phones on their side) ----------
   Like Audible in landscape: cover on the left, controls on the right. */

@media (min-aspect-ratio: 5/4) and (max-height: 640px) {
  :root { --cover: min(calc(100vh - 48px), 420px); }

  .player {
    flex-direction: row;
    gap: 44px;
    padding-top: 24px;
    padding-bottom: 24px;
  }

  .player-main { gap: 14px; }
  .library-btn { top: 12px; left: 12px; }
}

@media (min-aspect-ratio: 5/4) and (max-height: 420px) {
  .ctl-play { width: 96px; height: 96px; }
  .ctl-skip { width: 76px; height: 76px; }
  .ctl-skip svg { width: 52px; height: 52px; }
  .now-title { font-size: 24px; }
  .player-main { gap: 8px; }
  .toolbar { margin-top: 8px; }
}

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