/* readaloud: a quiet, paper-coloured shelf that works on a phone or a laptop. */

:root {
  --paper: #faf8f5;
  --surface: #ffffff;
  --surface-2: #f2eee8;
  --ink: #221f1c;
  --muted: #6d655d;
  --line: #e2dbd1;
  --accent: #a8502a;
  --accent-soft: #f3e3da;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 8px 24px rgba(40, 30, 20, .07);
  --radius: 14px;
  --tap: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16151a;
    --surface: #1e1c22;
    --surface-2: #26232b;
    --ink: #ece7e1;
    --muted: #9c948c;
    --line: #322e38;
    --accent: #e29063;
    --accent-soft: #3a2a22;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

/* A class that sets `display` would otherwise beat the `hidden` attribute. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 ui-serif, "Iowan Old Style", Georgia, serif;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { font-weight: 600; letter-spacing: -.01em; margin: 0; }

.view { max-width: 720px; margin: 0 auto; padding: 0 18px 60px; }

/* ---------- top bar ---------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 22px 0 18px; position: sticky; top: 0; z-index: 5;
  background: linear-gradient(var(--paper) 72%, transparent);
  padding-top: max(22px, env(safe-area-inset-top));
}

.topbar h1 { font-size: 22px; }

.brand { display: grid; gap: 1px; }
.tagline {
  font-family: system-ui, sans-serif; font-size: 12.5px; color: var(--muted);
  letter-spacing: .01em;
}

/* ---------- buttons ---------- */

.btn {
  font: inherit; font-size: 15px; border: 1px solid transparent;
  border-radius: 999px; padding: 11px 18px; min-height: var(--tap);
  background: var(--surface-2); color: var(--ink);
  cursor: pointer; transition: filter .15s, background .15s, transform .06s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { filter: brightness(.96); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #1a1114; } }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.small { min-height: 38px; padding: 6px 14px; font-size: 14px; }

.btn.round {
  width: 58px; height: 58px; border-radius: 50%; padding: 0;
  font-size: 13px; font-variant-numeric: tabular-nums;
  background: var(--surface); border: 1px solid var(--line);
  flex-direction: column; line-height: 1;
}
.btn.round::after { content: "sec"; font-size: 9px; color: var(--muted); }

.btn.play {
  width: 76px; height: 76px; border-radius: 50%; padding: 0;
  background: var(--accent); color: #fff; box-shadow: var(--shadow);
}
.btn.play svg { width: 30px; height: 30px; fill: currentColor; }

.chip {
  font-size: 13px; padding: 5px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}

/* ---------- shelf ---------- */

.shelf { display: grid; gap: 14px; }

.card {
  display: grid; grid-template-columns: 66px 1fr; gap: 15px; align-items: center;
  padding: 13px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  cursor: pointer; text-align: left; width: 100%; font: inherit; color: inherit;
}
.card:hover { border-color: var(--accent); }

.card img, .card .noart {
  width: 66px; height: 88px; object-fit: cover; border-radius: 7px;
  background: var(--surface-2); display: block;
}
.card .noart { display: grid; place-items: center; color: var(--muted); font-size: 22px; }

.card h3 { font-size: 17px; margin-bottom: 3px; }
.card .sub { font-size: 13.5px; color: var(--muted); font-family: system-ui, sans-serif; }

.bar { height: 4px; border-radius: 3px; background: var(--surface-2); margin-top: 9px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* ---------- jobs ---------- */

.jobs { display: grid; gap: 10px; margin-bottom: 16px; }

.job {
  padding: 13px 15px; border-radius: var(--radius); background: var(--accent-soft);
  border: 1px solid var(--line); font-family: system-ui, sans-serif; font-size: 14px;
}
.job .row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.job strong { font-weight: 600; }
.job .pct { color: var(--muted); font-variant-numeric: tabular-nums; }
.job.failed { background: var(--surface-2); }

/* ---------- empty ---------- */

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h2 { color: var(--ink); font-size: 20px; margin-bottom: 8px; }
.empty p { max-width: 380px; margin: 0 auto 22px; font-size: 15px; }

.hostnote {
  margin-top: 34px; padding-top: 16px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 13px; font-family: system-ui, sans-serif;
  text-align: center;
}

/* "Open on your phone" is a message for the desktop. On a touch device you are
   already there, so it is noise. */
@media (hover: none) and (pointer: coarse) {
  .hostnote { display: none; }
}

.phone-panel {
  display: grid; justify-items: center; gap: 10px; margin-top: 18px;
  animation: rise .18s ease-out;
}
.phone-panel p { margin: 0; max-width: 300px; }
.phone-panel code {
  font-size: 13px; background: var(--surface-2); color: var(--ink);
  padding: 7px 13px; border-radius: 8px;
}

/* The QR is drawn as 1-unit modules, so it scales crisply to any size. */
.qr {
  width: 200px; height: 200px; padding: 12px; border-radius: 12px;
  background: #fff; box-shadow: var(--shadow); image-rendering: pixelated;
}

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

/* ---------- player ---------- */

.nowplaying { display: flex; gap: 18px; align-items: flex-end; margin: 6px 0 26px; }

.cover {
  width: 116px; height: 152px; object-fit: cover; border-radius: 9px;
  box-shadow: var(--shadow); background: var(--surface-2); flex: none;
}
.meta { min-width: 0; }
.meta h2 { font-size: 21px; line-height: 1.25; }
.chapter-now {
  margin: 8px 0 0; color: var(--muted); font-size: 14.5px;
  font-family: system-ui, sans-serif;
}

.scrub { margin-bottom: 8px; }

input[type=range] {
  width: 100%; -webkit-appearance: none; appearance: none;
  background: transparent; height: 30px; margin: 0; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 4px; background: var(--surface-2);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 17px; height: 17px; border-radius: 50%;
  background: var(--accent); margin-top: -6px; border: 2px solid var(--paper);
}
input[type=range]::-moz-range-track { height: 5px; border-radius: 4px; background: var(--surface-2); }
input[type=range]::-moz-range-thumb {
  width: 15px; height: 15px; border: 2px solid var(--paper); border-radius: 50%;
  background: var(--accent);
}

.times {
  display: flex; justify-content: space-between; color: var(--muted);
  font-size: 13px; font-variant-numeric: tabular-nums;
  font-family: system-ui, sans-serif;
}

.controls {
  display: flex; align-items: center; justify-content: center; gap: 26px;
  margin: 20px 0 22px;
}

.speeds { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 34px; }

.speeds button {
  font: inherit; font-family: system-ui, sans-serif; font-size: 14px;
  padding: 8px 15px; min-height: 40px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  cursor: pointer;
}
/* Selection is a filled chip, never a stripe on the edge. */
.speeds button[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
@media (prefers-color-scheme: dark) {
  .speeds button[aria-pressed="true"] { color: #1a1114; }
}

/* ---------- narrator and speed ---------- */

.topbar-actions { display: flex; gap: 8px; }

/* Two quiet dropdowns rather than a wall of chips. */
.settings {
  display: flex; gap: 16px; justify-content: center; align-items: center;
  margin-bottom: 32px; flex-wrap: nowrap;
}

.setting {
  display: flex; align-items: center; gap: 8px;
  font-family: system-ui, sans-serif; font-size: 12.5px; color: var(--muted);
}
.setting select {
  min-width: 0;
  font: inherit; font-family: system-ui, sans-serif; font-size: 14px;
  color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 9px 14px; min-height: 42px; max-width: 100%;
}

/* ---------- read along ---------- */

/* Its own layer with its own scroll, so reading never moves the page behind. */
.modal {
  position: fixed; inset: 0; z-index: 30; background: var(--paper);
  display: flex; flex-direction: column;
}

.modal-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--line); background: var(--surface);
  flex: none;
}

.reader-text {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 20px max(16px, env(safe-area-inset-left)) 55vh;
  max-width: 680px; width: 100%; margin: 0 auto;
}

.reader-chapter {
  font-family: ui-serif, Georgia, serif; font-size: 17px; font-weight: 600;
  margin: 32px 0 12px; padding: 0 10px; color: var(--ink);
}
.reader-chapter.part { font-size: 20px; margin-top: 44px; }

.reader-line {
  font-size: 17px; line-height: 1.62; margin: 0;
  padding: 6px 10px; border-radius: 8px; color: var(--muted);
}
/* The line being spoken is filled, so it reads as one block of text. */
.reader-line.now { background: var(--accent-soft); color: var(--ink); }
.reader-line.read { color: var(--ink); opacity: .6; }
.reader-line.picked { outline: 2px solid var(--accent); outline-offset: 1px; }

.jump-offer {
  display: flex; gap: 8px; padding: 10px 10px 4px; align-items: center;
}
.jump-offer .btn { min-height: 40px; }

#followBtn[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
@media (prefers-color-scheme: dark) {
  #followBtn[aria-pressed="true"] { color: #1a1114; }
}

/* ---------- navigation vs actions ---------- */

/* Going back is not the same kind of thing as opening a panel, so it does not
   look like one. */
.btn.back, .btn.close {
  background: transparent; border: 0; color: var(--muted);
  padding: 10px 6px; font-size: 15px;
}
.btn.back::before { content: "\2039"; font-size: 21px; line-height: 1; margin-right: 3px; }
.btn.back:hover, .btn.close:hover { color: var(--ink); background: transparent; }
.btn.close { font-weight: 600; color: var(--accent); }

/* ---------- save ---------- */

/* Wide and low on the screen: the thumb finds it without looking. */
.btn.save {
  width: 100%; min-height: 56px; margin-bottom: 20px; font-size: 16px;
  background: var(--accent-soft); color: var(--ink);
  border: 1px solid var(--accent);
}
.btn.save:disabled { border-color: var(--line); background: var(--surface-2); }
.btn.save.saved { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { .btn.save.saved { color: #1a1114; } }

/* ---------- snippets ---------- */

.snip-title { font-size: 22px; margin-bottom: 6px; }
.snip-help {
  color: var(--muted); font-size: 14px; font-family: system-ui, sans-serif;
  margin: 0 0 22px;
}

.snip-list { display: grid; gap: 16px; }

.snip {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow); overflow: hidden;
}

.snip-lines { padding: 6px 6px 2px; }

.snip-line {
  display: block; width: 100%; text-align: left; font: inherit; font-size: 15.5px;
  line-height: 1.5; padding: 9px 12px; border: 0; border-radius: 9px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.snip-line:hover { background: var(--surface-2); }
/* Included sentences read as one filled block, not an edge-marked run. */
.snip-line.in { background: var(--accent-soft); color: var(--ink); }
.snip-line.in:hover { filter: brightness(.97); }
.snip-line.in + .snip-line.in { border-radius: 9px; margin-top: -2px; }

.snip-note {
  width: 100%; font: inherit; font-size: 14.5px; font-family: system-ui, sans-serif;
  color: var(--ink); background: var(--surface-2); border: 0;
  border-top: 1px solid var(--line); padding: 12px 16px; resize: vertical;
  min-height: 44px; display: block;
}
.snip-note::placeholder { color: var(--muted); }

.snip-foot {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 11px 14px; border-top: 1px solid var(--line);
  font-family: system-ui, sans-serif; font-size: 13px; color: var(--muted);
}
.snip-where { flex: 1; min-width: 130px; }
.snip-foot .btn { min-height: 38px; padding: 6px 14px; font-size: 13.5px; }

/* ---------- chapters ---------- */

.chapters-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.chapters h3 { font-size: 16px; }

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

.chapters li button {
  width: 100%; text-align: left; font: inherit; cursor: pointer;
  display: flex; justify-content: space-between; gap: 14px; align-items: baseline;
  padding: 12px 14px; min-height: var(--tap); border-radius: 10px;
  background: transparent; border: 1px solid transparent; color: var(--ink);
}
.chapters li button:hover { background: var(--surface-2); }
.chapters li.part button { font-weight: 600; margin-top: 14px; }
.chapters li.sub button { padding-left: 26px; color: var(--muted); }
/* Current chapter reads as a filled row, not an edge marker. */
.chapters li.current button {
  background: var(--accent-soft); border-color: var(--accent); color: var(--ink);
}
.chapters .len {
  font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums;
  font-family: system-ui, sans-serif; flex: none;
}

/* ---------- add sheet ---------- */

.sheet {
  position: fixed; inset: 0; background: rgba(20, 15, 10, .45);
  display: grid; place-items: end center; z-index: 20;
  backdrop-filter: blur(3px);
}
.sheet-panel {
  background: var(--surface); width: 100%; max-width: 520px;
  border-radius: 18px 18px 0 0; padding: 26px 22px
    calc(26px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow); max-height: 92vh; overflow-y: auto;
}
@media (min-width: 560px) {
  .sheet { place-items: center; }
  .sheet-panel { border-radius: 18px; }
}
.sheet-panel h2 { font-size: 19px; margin-bottom: 18px; }

.drop {
  display: grid; place-items: center; text-align: center; padding: 30px 18px;
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  color: var(--muted); cursor: pointer; margin-bottom: 18px;
  font-family: system-ui, sans-serif; font-size: 14.5px; min-height: 108px;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop.chosen { color: var(--ink); border-style: solid; border-color: var(--accent); }

.field { display: grid; gap: 6px; margin-bottom: 16px; font-size: 14px; color: var(--muted);
         font-family: system-ui, sans-serif; }
.field select {
  font: inherit; font-size: 15px; color: var(--ink); padding: 12px 14px;
  min-height: var(--tap); border-radius: 11px;
  border: 1px solid var(--line); background: var(--surface-2);
}

.note { font-size: 13px; color: var(--muted); font-family: system-ui, sans-serif;
        margin: 0 0 20px; }

.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- toast ---------- */

.toast-undo {
  font: inherit; font-family: system-ui, sans-serif; font-size: 14px;
  font-weight: 600; color: var(--paper); background: transparent;
  border: 0; border-bottom: 1px solid currentColor; padding: 0 0 1px;
  margin-left: 14px; cursor: pointer;
}

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--paper); padding: 12px 20px;
  border-radius: 999px; font-size: 14px; font-family: system-ui, sans-serif;
  z-index: 40; box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}
