/* boss-bible — RSVP Scripture reader
   Visual language taken from the reference recording: pure black ground,
   high-contrast serif, a single word on a fixed pivot with the focal letter
   in red, thin guide rails above and below. */

:root {
  --bg:        #000000;
  --ink:       #f4f2ef;
  --ink-dim:   #8a8782;
  --ink-faint: #46443f;
  --orp:       #ff3b40;   /* sampled from the reference: #FF373C */
  --rail:      #2e2c29;
  --sheet:     #101010;
  --line:      #232220;
  --serif:     "Playfair Display", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --read:      "Spectral", Georgia, "Times New Roman", serif;
  --safe-t:    env(safe-area-inset-top, 0px);
  --safe-b:    env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--read);
  overscroll-behavior: none;
}

body {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: none;
}

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

/* ───────────────────────── layout ───────────────────────── */

.screen {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  padding: calc(var(--safe-t) + 8px) 0 calc(var(--safe-b) + 10px);
}

/* top bar */
#topbar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
}

#ref-wrap { text-align: center; line-height: 1.15; min-width: 0; }

#ref {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#translation-tag {
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-top: 3px;
}

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: none; border: 0; padding: 0;
  color: var(--ink-dim);
  cursor: pointer;
  border-radius: 12px;
  transition: color .15s, background .15s;
}
.icon-btn:hover { color: var(--ink); }
.icon-btn:active { background: #ffffff10; }
.icon-btn svg { width: 21px; height: 21px; fill: currentColor; }

/* progress */
#progress-wrap { padding: 10px 22px 0; }

#counts {
  display: flex;
  justify-content: space-between;
  font-family: var(--serif);
  font-size: 13px;
  color: var(--ink-dim);
  margin-bottom: 7px;
  font-variant-numeric: tabular-nums;
}

#progress-track {
  height: 3px;
  background: #ffffff14;
  border-radius: 2px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  width: 0%;
  background: var(--ink);
  border-radius: 2px;
  transition: width .12s linear;
}

/* ───────────────────────── the RSVP stage ───────────────────────── */

#stage {
  position: relative;
  display: grid;
  place-items: center;
  cursor: pointer;
  min-height: 0;
}

#rails { width: 100%; max-width: 900px; padding: 0 16px; }

.rail {
  position: relative;
  height: 1px;
  background: var(--rail);
  transition: opacity .2s;
}

/* the small centre tick that marks the focal point */
.rail .tick {
  position: absolute;
  left: 50%;
  width: 1px;
  height: 11px;
  background: var(--rail);
  transform: translateX(-50%);
}
.rail-top .tick    { top: 0; }
.rail-bottom .tick { bottom: 0; }

body.no-rails .rail { opacity: 0; }

/* Equal minmax(0,1fr) side columns keep the pivot letter pinned to the exact
   centre no matter how long the word is — the whole trick of RSVP. */
#word {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: baseline;
  font-family: var(--serif);
  font-size: var(--word-size, 52px);
  font-weight: 500;
  line-height: 1.5;
  padding: 26px 0;
  white-space: pre;
}

#word .pre  { text-align: right; }
#word .post { text-align: left; }
#word .orp  { text-align: center; color: var(--orp); }

body.no-orp #word .orp { color: var(--ink); }

/* a soft beat between sentences */
#word.beat { opacity: .18; }

#verse-badge {
  position: absolute;
  bottom: 8%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  letter-spacing: .17em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
  transition: opacity .2s;
}
body.no-verse #verse-badge { opacity: 0; }

#hint {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(var(--safe-b) + 108px);
  text-align: center;
  font-size: 12.5px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  pointer-events: none;
  transition: opacity .3s;
}
body.playing #hint { opacity: 0; }

/* ───────────────── paused: whole chapter, tap to jump ───────────────── */

#paused-text {
  position: absolute;
  inset: calc(var(--safe-t) + 92px) 0 calc(var(--safe-b) + 96px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 26px 40px;
  font-family: var(--read);
  font-size: 17.5px;
  line-height: 1.85;
  color: var(--ink-dim);
  z-index: 3;
  overscroll-behavior: contain;
  /* opaque: this panel covers the RSVP stage while paused */
  background: var(--bg);
}

/* keep a comfortable measure when installed on a desktop */
@media (min-width: 700px) {
  #paused-text {
    padding-left: max(26px, calc(50% - 21em));
    padding-right: max(26px, calc(50% - 21em));
    font-size: 18.5px;
  }
}
#paused-text .v-num {
  font-family: var(--serif);
  font-size: 11px;
  color: var(--ink-faint);
  vertical-align: .45em;
  margin-right: 3px;
  margin-left: 2px;
}
#paused-text w {
  cursor: pointer;
  border-radius: 3px;
  transition: color .12s;
}
#paused-text w:hover { color: var(--ink); }
#paused-text w.at { color: var(--orp); }
#paused-text w.read { color: #5f5c57; }

/* ───────────────────────── controls ───────────────────────── */

#controls { padding: 0 22px; }

#speed-row {
  display: grid;
  grid-template-columns: 1fr 52px;
  gap: 16px;
  align-items: center;
}

#speed-wrap { position: relative; padding: 6px 0; }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%;
  height: 30px;
  background: transparent;
  cursor: pointer;
  margin: 0;
  display: block;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 30px;
  background: #ffffff0f;
  border-radius: 15px;
}
input[type=range]::-moz-range-track {
  height: 30px;
  background: #ffffff0f;
  border-radius: 15px;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px; height: 24px;
  margin-top: 3px;
  border-radius: 50%;
  background: var(--ink);
  border: 0;
  box-shadow: 0 1px 6px #0009;
}
input[type=range]::-moz-range-thumb {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--ink);
  border: 0;
}

/* the tick marks sitting inside the slider track */
#speed-ticks {
  position: absolute;
  inset: 6px 14px auto;
  height: 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}
#speed-ticks i {
  width: 1px;
  height: 9px;
  background: #ffffff20;
}

.round-btn {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: #ffffff12;
  border: 0;
  display: grid; place-items: center;
  color: var(--ink-dim);
  cursor: pointer;
  position: relative;
  transition: background .18s, color .18s;
}
.round-btn:active { transform: scale(.95); }
.round-btn svg { width: 23px; height: 23px; fill: currentColor; }
.round-btn .ic-on { display: none; }
.round-btn[aria-pressed="true"] { background: var(--ink); color: #000; }
.round-btn[aria-pressed="true"] .ic-on  { display: block; }
.round-btn[aria-pressed="true"] .ic-off { display: none; }
.round-btn.busy svg { opacity: 0; }

.spinner {
  position: absolute;
  width: 19px; height: 19px;
  border: 2px solid #ffffff30;
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.round-btn[aria-pressed="true"] .spinner { border-color: #00000030; border-top-color: #000; }
@keyframes spin { to { transform: rotate(360deg); } }

#wpm-label {
  text-align: center;
  margin-top: 9px;
  font-size: 11px;
  letter-spacing: .17em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
#wpm-label b { color: var(--ink-dim); font-weight: 600; }

/* edge chapter nav — desktop affordance, swipe does it on touch */
.edge-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 46px; height: 92px;
  background: none; border: 0;
  color: #ffffff1f;
  font-size: 34px;
  font-family: var(--serif);
  cursor: pointer;
  z-index: 4;
  transition: color .2s;
}
.edge-nav:hover { color: var(--ink-dim); }
#nav-prev { left: 0; }
#nav-next { right: 0; }
body.playing .edge-nav { opacity: 0; pointer-events: none; }
@media (pointer: coarse) { .edge-nav { display: none; } }

/* ───────────────────────── sheets ───────────────────────── */

#scrim {
  position: fixed; inset: 0;
  background: #000000b8;
  backdrop-filter: blur(3px);
  z-index: 10;
}

.sheet {
  position: fixed;
  z-index: 11;
  background: var(--sheet);
  display: flex;
  flex-direction: column;
  animation: rise .26s cubic-bezier(.22,.9,.3,1);
}

@media (max-width: 720px) {
  .sheet {
    left: 0; right: 0; bottom: 0;
    top: 8%;
    border-radius: 20px 20px 0 0;
    padding-bottom: var(--safe-b);
  }
  @keyframes rise { from { transform: translateY(100%); } }
}
@media (min-width: 721px) {
  .sheet {
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: min(560px, 92vw);
    max-height: 84vh;
    border-radius: 16px;
    border: 1px solid var(--line);
  }
  @keyframes rise { from { opacity: 0; transform: translate(-50%, -46%); } }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 10px 12px 22px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 500;
}
.icon-btn.close { font-size: 17px; }

.scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0 24px;
  overscroll-behavior: contain;
}

/* segmented control */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 14px 18px 6px;
  background: #ffffff0d;
  border-radius: 11px;
  padding: 4px;
}
.seg-btn {
  border: 0; background: none;
  padding: 9px 4px;
  border-radius: 8px;
  color: var(--ink-dim);
  font-size: 13.5px;
  cursor: pointer;
}
.seg-btn.is-on { background: #ffffff17; color: var(--ink); }

/* book + chapter pickers */
.book-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 13px 22px;
  background: none; border: 0;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
}
.book-row:active { background: #ffffff0d; }
.book-row .bn { font-family: var(--serif); font-size: 16.5px; flex: 1; }
.book-row .bc { font-size: 11.5px; color: var(--ink-faint); letter-spacing: .05em; }

#chapter-grid { padding: 14px 18px 30px; }
.text-btn {
  background: none; border: 0;
  color: var(--ink-dim);
  cursor: pointer;
  padding: 6px 4px;
  font-size: 14px;
}
#chapter-book-name {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 21px;
  margin: 6px 4px 14px;
}
#chapter-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 8px;
}
.ch-btn {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  background: none;
  border-radius: 10px;
  color: var(--ink-dim);
  font-family: var(--serif);
  font-size: 15px;
  cursor: pointer;
  transition: background .14s, color .14s;
}
.ch-btn:hover { background: #ffffff10; color: var(--ink); }
.ch-btn.is-on { background: var(--ink); color: #000; border-color: var(--ink); }

/* settings */
.settings-body { padding: 4px 22px 34px; }
.settings-body h3 {
  font-family: var(--serif);
  font-size: 12px;
  letter-spacing: .17em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
  margin: 26px 0 11px;
}
.settings-body h3:first-child { margin-top: 16px; }

.opts { display: grid; gap: 8px; }
.opt {
  display: block;
  width: 100%;
  text-align: left;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: none;
  cursor: pointer;
  color: var(--ink-dim);
  transition: border-color .15s, background .15s;
}
.opt b {
  display: block;
  font-family: var(--serif);
  font-size: 15.5px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 2px;
}
.opt small { font-size: 12.5px; line-height: 1.4; display: block; }
.opt.is-on { border-color: var(--ink); background: #ffffff0a; }
.opt[disabled] { opacity: .42; cursor: not-allowed; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 11px 0;
  font-size: 14.5px;
  color: var(--ink-dim);
  border-bottom: 1px solid #ffffff08;
}
.row input[type=range] { flex: 0 0 165px; height: 26px; }
.row input[type=range]::-webkit-slider-runnable-track { height: 26px; border-radius: 13px; }
.row input[type=range]::-webkit-slider-thumb { width: 20px; height: 20px; margin-top: 3px; }
.row input[type=checkbox] {
  appearance: none; -webkit-appearance: none;
  width: 44px; height: 26px;
  border-radius: 13px;
  background: #ffffff17;
  position: relative;
  cursor: pointer;
  flex: none;
  transition: background .2s;
}
.row input[type=checkbox]::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--ink-dim);
  transition: transform .2s, background .2s;
}
.row input[type=checkbox]:checked { background: var(--ink); }
.row input[type=checkbox]:checked::after { transform: translateX(18px); background: #000; }

#kokoro-voice-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 12px;
  font-size: 14px;
  color: var(--ink-dim);
}
select {
  background: #ffffff0d;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  flex: 1;
  max-width: 220px;
}

.note {
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--ink-faint);
  margin: 12px 0 0;
}
.note.credit { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }

/* toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 128px);
  transform: translateX(-50%);
  background: #1c1c1c;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 11px 17px;
  border-radius: 11px;
  font-size: 13.5px;
  z-index: 30;
  max-width: 84vw;
  text-align: center;
  animation: rise .2s ease;
  box-shadow: 0 8px 30px #000a;
}

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
