/* My Yomi - mobile first, dark by default, tuned for one-handed use. */

:root {
  color-scheme: dark;
  --bg: #0e1116;
  --surface: #161b23;
  --surface-2: #1d232d;
  --line: #2a313d;
  --text: #e8eaed;
  --muted: #98a1b0;
  --accent: #d9a441;
  --accent-soft: rgba(217, 164, 65, 0.16);
  --done: #4f9d69;
  --played: #5b91d6;
  --danger: #c9584f;
  --radius: 14px;
  --tap: 44px;
}

/* Dark is the design, not a preference: these are listened to early in the
   morning and late at night, and a light flash in a dark room is jarring. The
   palette above is the only one, so no light-scheme override is defined. */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Room for the mini player, plus the home indicator on iOS. */
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

#app { max-width: 720px; margin: 0 auto; padding: 0 16px; }

h1, h2, h3 { margin: 0; line-height: 1.25; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

/* --- header --- */

.topbar { padding: 20px 0 8px; }
.topbar-main { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.topbar h1 { font-size: 26px; letter-spacing: -0.02em; }
.dateline { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.collection-name { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.icon-btn {
  min-width: var(--tap); min-height: var(--tap);
  background: none; border: 0; border-radius: 50%;
  font-size: 18px; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); }

.progress { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.ring-wrap { width: 56px; height: 56px; flex: none; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 6; stroke-linecap: round; }
.ring-track { stroke: var(--line); }
.ring-value { stroke: var(--accent); transition: stroke-dashoffset 400ms ease; }
.progress-text { display: flex; flex-direction: column; }
.progress-text strong { font-size: 20px; }
.progress-text span { color: var(--muted); font-size: 13px; }

/* --- up next --- */

.hero {
  margin: 16px 0;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.hero-label { margin: 0 0 6px; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.hero h2 { font-size: 22px; }
.hero-sub { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.hero-actions { display: flex; align-items: center; gap: 14px; margin-top: 16px; flex-wrap: wrap; }
.hero-count { color: var(--muted); font-size: 13px; }
.hero-done { text-align: center; }

.primary {
  min-height: var(--tap);
  padding: 0 24px;
  background: var(--accent);
  color: #15120b;
  border: 0; border-radius: 999px;
  font-weight: 650;
}
.primary:active { transform: scale(0.98); }

/* --- filters --- */

.filters { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }

.chip {
  min-height: 36px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex; align-items: center;
}
.chip-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip-danger { color: var(--danger); border-color: var(--danger); }

/* --- list --- */

.book { margin-bottom: 22px; }
.book-name { font-size: 15px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }

.chapter { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; background: var(--surface); overflow: hidden; }
.chapter-done .chapter-name { color: var(--done); }

.chapter-head {
  width: 100%; min-height: var(--tap);
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: none; border: 0;
  text-align: left;
}
.chapter-name { flex: 1; font-weight: 600; }
.chapter-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.chevron { color: var(--muted); width: 16px; text-align: center; }

.tracks { list-style: none; margin: 0; padding: 0 0 6px; }

.track { display: flex; align-items: stretch; gap: 8px; border-top: 1px solid var(--line); }
.track-current { background: var(--accent-soft); }

.track-main {
  flex: 1; min-width: 0; min-height: var(--tap);
  display: flex; align-items: center; gap: 12px;
  padding: 10px 4px 10px 14px;
  background: none; border: 0;
  text-align: left;
}
.track-text { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }

/* The play mark carries the status: green to start or continue, blue once
   finished, and a slow pulse on anything left part-way through. */
.track-play {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  color: var(--done);
}
.track-play svg { margin-left: 2px; }   /* a triangle looks off-centre when it is not */
.track-play-done { color: var(--played); }
.track-play-playing { animation: pulse 1.6s ease-in-out infinite; }

/* Something left part-way through should catch the eye from across the list,
   so the mark swings all the way to the accent colour rather than only
   breathing a ring. */
@keyframes pulse {
  0%, 100% {
    color: var(--done);
    box-shadow: 0 0 0 0 rgba(79, 157, 105, 0.55);
    transform: scale(1);
  }
  50% {
    color: var(--accent);
    box-shadow: 0 0 0 9px rgba(217, 164, 65, 0);
    transform: scale(1.08);
  }
}

.track-stamp { color: var(--muted); font-size: 11px; opacity: 0.85; }
.stamp-done { color: var(--played); }
.track-title { font-size: 15px; }
.track-done .track-title { color: var(--muted); }
.track-meta { display: flex; flex-wrap: wrap; gap: 6px; color: var(--muted); font-size: 12px; }
.dot-sep::before { content: "· "; }
.resume { color: var(--accent); }

.track-bar { display: block; height: 3px; background: var(--line); border-radius: 2px; margin-top: 6px; }
.track-bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

.empty { padding: 40px 0; text-align: center; color: var(--muted); }

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

.mini {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface-2);
  border-top: 1px solid var(--line);
}
.mini[hidden] { display: none; }
.mini-progress { position: absolute; top: 0; left: 0; height: 2px; background: var(--accent); transition: width 250ms linear; }
.mini-main { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; background: none; border: 0; text-align: left; }
.mini-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.mini-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.mini-play { width: var(--tap); height: var(--tap); flex: none; background: var(--accent); color: #15120b; border: 0; border-radius: 50%; font-size: 16px; }

/* --- sheets --- */

dialog.sheet {
  width: min(680px, 100%);
  max-height: 92vh;
  margin: auto auto 0;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.6); }
.sheet-body { padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 92vh; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet-head h2 { font-size: 20px; }
.sheet-ref { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.scrub { width: 100%; accent-color: var(--accent); }
.times { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.transport { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 14px 0; }
.play-big { width: 64px; height: 64px; border: 0; border-radius: 50%; background: var(--accent); color: #15120b; font-size: 22px; }
.ghost { min-height: var(--tap); padding: 0 12px; background: none; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 13px; }

.player-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.note { color: var(--muted); font-size: 13px; line-height: 1.45; }
.error { color: var(--danger); font-size: 14px; }

textarea {
  width: 100%; margin-top: 12px; padding: 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  resize: vertical;
}

.drive-frame { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 10px; background: #000; }

/* --- reader --- */

.reader { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.reader-toggle { min-height: var(--tap); padding: 0 16px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; }
.reader-controls { display: flex; gap: 8px; margin-top: 12px; }
.reader-status { color: var(--muted); font-size: 14px; }

.passage { margin-top: 14px; }
.passage-chapter { font-size: 15px; color: var(--muted); margin: 18px 0 8px; }
.verse { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.verse-num { flex: none; width: 26px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; padding-top: 6px; }
.verse-text { flex: 1; min-width: 0; }
.verse .he { margin: 0; font-size: 21px; line-height: 1.9; }
.verse .en { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.credit { margin-top: 16px; color: var(--muted); font-size: 12px; }

@media (min-width: 640px) {
  .topbar h1 { font-size: 30px; }
  .verse .he { font-size: 23px; }
}

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

/* --- up-next prompt --- */

.next-prompt { text-align: center; }
.next-prompt h2 { font-size: 22px; margin-top: 6px; }
.next-prompt .sheet-ref { margin-top: 6px; }

.countdown { margin: 18px 0 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.countdown-num { font-size: 46px; font-weight: 700; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.countdown-label { color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }

.next-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.next-actions .primary { width: 100%; min-height: 52px; font-size: 17px; }
.next-actions .ghost { width: 100%; min-height: 48px; }
.next-toggle { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); display: flex; justify-content: center; }

/* --- checkbox --- */

.toggle { display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap); cursor: pointer; }
.toggle input { width: 20px; height: 20px; flex: none; accent-color: var(--accent); margin: 0; }
.toggle span { font-size: 15px; }

/* --- Hebrew --- */

/* Hebrew sits inside a left-aligned English layout. `direction` and the bidi
   isolation fix the ORDER of the characters; alignment is a separate matter,
   and must stay left so a Hebrew title lines up with the English beneath it
   instead of drifting to the opposite edge of the row. */
.rtl {
  direction: rtl;
  unicode-bidi: isolate;
  text-align: left;
}

.book-name { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.book-name .rtl { font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--text); }
.book-translit { font-size: 12px; letter-spacing: 0.06em; }
.book-name .rtl + .book-translit { color: var(--muted); }

.hero h2.rtl, .sheet-head h2.rtl { font-size: 26px; line-height: 1.35; }
.hero-translit { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.track-title.rtl { font-size: 17px; line-height: 1.5; }
.chapter-name.rtl { font-size: 16px; }

.verse-num { font-size: 13px; }

/* The English number rides alongside the Hebrew rather than replacing it. */
.chapter-translit { color: var(--muted); font-size: 12px; font-weight: 400; }
.chapter-name { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.passage-chapter { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }

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

/* One row, ordered by how central each control is: the speed modifier, then
   the action the app exists for, then sharing, then everything that leaves
   the app. No wrapping, so the layout never reshuffles under a thumb. */
.tool-row { display: flex; align-items: center; gap: 10px; margin-top: 16px; }

.speed {
  min-width: 56px; min-height: var(--tap);
  padding: 0 12px;
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex: none;
}

.mark-done {
  flex: 1; min-width: 0; min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 16px;
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}
.mark-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.mark-check { display: inline-flex; }

.icon-action {
  width: var(--tap); height: var(--tap); flex: none;
  display: grid; place-items: center;
  background: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
}
.icon-action:hover { color: var(--text); border-color: var(--muted); }
.icon-action:active { transform: scale(0.96); }

/* --- overflow menu --- */

.menu { display: flex; flex-direction: column; }
.menu-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px;
  padding: 0 4px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  font-size: 16px;
}
.menu-item:last-child { border-bottom: 0; }
.menu-external { color: var(--muted); display: inline-flex; }

.tool-spacer { flex: 1; }

/* The menu holds actions as well as links, so buttons must match the rows. */
button.menu-item {
  width: 100%;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font: inherit;
}
.menu-on { color: var(--accent); }

/* --- sync code --- */

.qr {
  margin: 16px auto;
  padding: 12px;
  width: min(260px, 70vw);
  background: #fff;   /* Scanners want a light quiet zone, whatever the theme. */
  border-radius: 12px;
}
.qr svg { display: block; width: 100%; height: auto; }

/* A playback failure needs a way out, not just an explanation. */
.error { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; margin: 12px 0; }
.error p { margin: 0; }

/* Drive's own player, shown when we are not allowed to stream the audio. */
.fallback { display: flex; flex-direction: column; gap: 12px; margin: 4px 0 8px; }
.fallback .note { margin: 0; }
.fallback .drive-frame { aspect-ratio: 16 / 10; }

/* The speed control is a real select now, styled to match the pills. */
select.speed {
  appearance: none;
  padding: 0 28px 0 14px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}
select.speed option { background: var(--surface); color: var(--text); }

/* The only control on a row now, so it gets a full-size tap target rather
   than the narrow one it had while sharing the space with a checkmark. */
.track-more {
  width: var(--tap); flex: none;
  display: grid; place-items: center;
  background: none; border: 0;
  color: var(--muted);
}
.track-more svg { width: 18px; height: 18px; }
.track-more:hover { color: var(--text); }

/* A held row should not look like a text selection while the menu opens. */
.track-main { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

/* Section heading inside a sheet menu. */
.menu-label {
  margin: 22px 0 6px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
