/* Chapter reader: text column, art panel, player. */
:root { --bar-h: 60px; --art-w: 0px; --player-h: 0px; }

.booting *, .booting *::before, .booting *::after { transition: none !important; }

/* ---------------------------------------------------------------- top bar */
.progress { position: fixed; inset: 0 0 auto 0; height: 2px; z-index: 40; pointer-events: none; }
.progress span {
  display: block; height: 100%; width: 100%; transform-origin: 0 50%; transform: scaleX(0);
  background: linear-gradient(90deg, var(--ruby-deep), var(--ruby)); box-shadow: 0 0 12px var(--ruby-glow);
}

.bar {
  position: fixed; top: 0; left: 0; right: var(--art-w); z-index: 30;
  height: var(--bar-h); padding: 0 max(var(--gutter), env(safe-area-inset-left));
  display: flex; align-items: center; gap: 12px;
  font-family: var(--font-ui); font-size: 14px;
  background: linear-gradient(var(--bg) 55%, transparent);
  transition: transform .35s ease, opacity .35s ease;
}
.bar.tucked { transform: translateY(-100%); opacity: 0; }
.bar-home {
  display: inline-flex; align-items: center; gap: 4px; text-decoration: none; color: var(--ink-2);
  min-height: 44px; padding-right: 8px; white-space: nowrap;
}
.bar-home:hover { color: var(--ink); }
.bar-home span { font-family: var(--font-display); font-size: 18px; font-weight: 600; letter-spacing: .02em; }
.bar-title {
  flex: 1; min-width: 0; text-align: center; color: var(--ink-quiet);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transition: opacity .3s ease;
}
.bar.scrolled .bar-title { opacity: 1; }
.bar-num { color: var(--gold); text-transform: uppercase; letter-spacing: .12em; font-size: 11px; margin-right: 6px; }

.mode-switch {
  display: inline-flex; padding: 3px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); backdrop-filter: blur(12px);
}
.mode-switch button {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 999px; border: 0;
  background: transparent; color: var(--ink-2); cursor: pointer; font-size: 14px; font-weight: 500;
  transition: background-color .25s ease, color .25s ease;
}
.mode-switch button svg { width: 18px; height: 18px; }
.mode-switch button[aria-pressed="true"] { background: var(--ruby); color: #fff; }
.aa { font-family: var(--font-display); font-size: 20px; font-weight: 600; }

.settings {
  position: fixed; top: calc(var(--bar-h) + 4px); right: calc(var(--art-w) + var(--gutter)); z-index: 35;
  width: min(320px, calc(100vw - 2 * var(--gutter)));
  padding: 14px; border-radius: 16px; background: var(--surface-solid); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-family: var(--font-ui); font-size: 14px;
}
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.set-label { color: var(--ink-2); }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 2px; }
.seg button { min-height: 36px; min-width: 44px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); cursor: pointer; }
.seg button[aria-checked="true"] { background: var(--surface-solid); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.25); }

/* ---------------------------------------------------------------- text */
.layout { position: relative; }
.text {
  max-width: calc(36rem * var(--fs) + 2 * var(--gutter));
  margin: 0 auto;
  padding: calc(var(--bar-h) + 24px) var(--gutter) calc(160px + var(--player-h));
  font-size: calc(1.125rem * var(--fs));
  line-height: 1.78;
  outline: none;
}
.text p { margin: 0 0 1.05em; hyphens: auto; -webkit-hyphens: auto; transition: color .5s ease; }

.ch-head { margin: 7vh 0 3.2rem; text-align: center; padding: 6px 0; border-radius: 12px; }
.ch-num {
  margin: 0 0 .4rem !important; font-family: var(--font-ui); font-size: 12px; font-weight: 600;
  letter-spacing: .32em; text-transform: uppercase; color: var(--gold);
}
.ch-head h1 {
  margin: 0; font-family: var(--font-display); font-weight: 500; font-size: clamp(2.4rem, 7vw, 3.6rem);
  line-height: 1.05; letter-spacing: .005em;
}
.ch-head::after {
  content: ""; display: block; width: 10px; height: 10px; margin: 1.6rem auto 0; transform: rotate(45deg);
  background: var(--ruby); box-shadow: 0 0 18px var(--ruby-glow);
}

.break { display: flex; justify-content: center; align-items: center; gap: 14px; margin: 2.6em 0; }
.break::before, .break::after { content: ""; width: 64px; height: 1px; background: linear-gradient(90deg, transparent, var(--ink-quiet)); }
.break::after { transform: scaleX(-1); }
.break span { width: 7px; height: 7px; transform: rotate(45deg); background: var(--ruby); box-shadow: 0 0 12px var(--ruby-glow); }

.text .beat {
  text-align: center; margin: 1.6em 0; color: var(--ruby);
  font-size: 1.05em; letter-spacing: .08em;
}
.text .readout {
  margin: 1.4em 0; padding: .8em 1em; border-left: 2px solid var(--eva);
  font-family: var(--font-ui); font-size: .78em; line-height: 1.7; letter-spacing: .06em;
  color: var(--eva); background: color-mix(in srgb, var(--eva) 7%, transparent); border-radius: 0 10px 10px 0;
}
.text .readout strong { font-weight: 500; }

/* Eva's telepathic voice gets a sapphire tint; Zoe's thoughts stay in plain italics. */
.sp-eva em, .sp-eva { color: var(--eva); }
.p .sp-eva { color: var(--eva); }

.ln { border-radius: 4px; transition: background-color .35s ease, color .35s ease, box-shadow .35s ease; }

/* Listen mode: the line being read is lit; the rest settles back. */
.mode-listen .text p, .mode-listen .text .ch-head { color: var(--ink-quiet); }
.mode-listen .text .ln { cursor: pointer; }
.mode-listen .text .ln:hover { color: var(--ink-2); }
.mode-listen .text .ln.on { color: var(--ink); background: var(--hl); box-shadow: 0 0 0 3px var(--hl); }
.mode-listen .text .ln.on.sp-eva, .mode-listen .text .ln.on .sp-eva, .mode-listen .text .ln.on.sp-eva em { color: var(--eva); }
.mode-listen .text .beat .ln.on { color: var(--ruby); background: transparent; box-shadow: none; animation: beat 1s ease-in-out infinite; display: inline-block; }
@keyframes beat { 0%, 100% { transform: scale(1); text-shadow: none; } 15% { transform: scale(1.08); text-shadow: 0 0 18px var(--ruby-glow); } 30% { transform: scale(1); } 45% { transform: scale(1.05); } }

/* Inline plates appear in the text on narrow screens. */
.plate-inline { margin: 2.2em calc(-1 * var(--gutter)); }
.plate-inline img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; }
.plate-inline figcaption, .art-cap {
  font-family: var(--font-ui); font-size: 13px; color: var(--ink-quiet); line-height: 1.5;
  display: flex; gap: 10px; align-items: baseline; justify-content: space-between;
}
.plate-inline figcaption { padding: 10px var(--gutter) 0; }
.standin {
  flex: none; font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink-quiet);
}
.art-off .plate-inline { display: none; }

.ch-end { text-align: center; margin-top: 4.5rem; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.ch-end-mark { width: 10px; height: 10px; transform: rotate(45deg); background: var(--ruby); box-shadow: 0 0 18px var(--ruby-glow); margin-bottom: 6px; }
.ch-end-label { font-family: var(--font-ui); font-size: 12px; letter-spacing: .3em; text-transform: uppercase; color: var(--gold); margin: 0 !important; }
.ch-end-soon { color: var(--ink-2); font-style: italic; margin: 0 0 6px !important; }

/* ---------------------------------------------------------------- art panel */
.art { display: none; }
.art-stage { position: relative; overflow: hidden; background: #000; }
.plate {
  position: absolute; inset: 0; margin: 0; opacity: 0;
  transition: opacity 1.6s ease;
}
.plate.on { opacity: 1; }
.plate img { width: 100%; height: 100%; object-fit: cover; transform-origin: 60% 40%; }
.mode-listen .plate.on img { animation: drift 40s ease-in-out infinite alternate; }
@keyframes drift { from { transform: scale(1) translate(0, 0); } to { transform: scale(1.09) translate(-1.5%, 1%); } }
.subtitle, .art-close { display: none; }

@media (min-width: 1000px) {
  :root { --art-w: min(44vw, 720px); }
  .art {
    display: block; position: fixed; top: 0; right: 0; bottom: 0; width: var(--art-w); z-index: 20;
    background: #000;
  }
  .art-stage { position: absolute; inset: 0; }
  .art::after { /* soften the edge where art meets the page */
    content: ""; position: absolute; inset: 0 auto 0 0; width: 90px; pointer-events: none;
    background: linear-gradient(90deg, var(--bg), transparent);
  }
  .art-cap {
    position: absolute; left: 0; right: 0; bottom: 0; padding: 60px 28px 24px 110px;
    background: linear-gradient(transparent, rgba(0,0,0,.75)); color: rgba(255,255,255,.78);
  }
  .art-cap .standin { color: rgba(255,255,255,.6); border-color: rgba(255,255,255,.25); }
  .layout { margin-right: var(--art-w); }
  .plate-inline { display: none; }
  .art-off .art { display: none; }
  .art-off { --art-w: 0px; }
  .art-off .layout { margin-right: 0; }
}

/* Art view: the illustration fills the screen and the narration runs as a subtitle. */
.cinema { overflow: hidden; }
.cinema .art {
  display: block; position: fixed; inset: 0; width: auto; z-index: 45; background: #000;
}
.cinema .art-stage { position: absolute; inset: 0; }
.cinema .art::after { display: none; }
.cinema .art-cap { display: none; }
.cinema .subtitle {
  display: block; position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--player-h) + 28px); width: min(46rem, calc(100% - 2 * var(--gutter)));
  margin: 0; text-align: center; font-size: clamp(1.05rem, 2.4vw, 1.35rem); line-height: 1.55;
  color: #fff; text-shadow: 0 2px 14px rgba(0,0,0,.9), 0 0 2px rgba(0,0,0,.9);
  transition: opacity .4s ease;
}
.cinema .subtitle.sp-eva { color: #b9d8ff; font-style: italic; }
.cinema .art-close {
  display: inline-flex; position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px;
  color: #fff; background: rgba(0,0,0,.4);
}
.cinema .bar, .cinema .listen-here, .cinema .resync { display: none; }
.cinema .player { left: 0; right: 0; z-index: 50; }

/* ---------------------------------------------------------------- floating buttons */
.listen-here, .resync {
  position: fixed; z-index: 25; left: 50%; transform: translateX(-50%);
  margin-left: calc(var(--art-w) / -2);
  bottom: max(20px, env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 8px; min-height: 46px; padding: 0 20px 0 16px;
  border-radius: 999px; border: 1px solid var(--line); cursor: pointer;
  background: var(--surface); backdrop-filter: blur(14px); box-shadow: var(--shadow);
  font-family: var(--font-ui); font-size: 14px; font-weight: 500; color: var(--ink);
  transition: opacity .3s ease, transform .3s ease;
}
.listen-here svg { width: 18px; height: 18px; color: var(--ruby); fill: var(--ruby); stroke: none; }
.listen-here:hover, .resync:hover { border-color: var(--ink-quiet); }
.mode-listen .listen-here { opacity: 0; pointer-events: none; transform: translate(-50%, 12px); }
.resync { bottom: calc(var(--player-h) + 16px); }
.resync[hidden] { display: none; }

/* ---------------------------------------------------------------- player */
.player {
  position: fixed; z-index: 30; left: 0; right: var(--art-w); bottom: 0;
  padding: 10px max(var(--gutter), env(safe-area-inset-left)) max(10px, env(safe-area-inset-bottom));
  background: var(--surface); backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border-top: 1px solid var(--line);
  font-family: var(--font-ui);
  transform: translateY(105%); transition: transform .4s cubic-bezier(.2,.8,.2,1);
}
.mode-listen .player { transform: none; }
.pl-scrub, .pl-controls { max-width: 40rem; margin: 0 auto; display: flex; align-items: center; }
.pl-scrub { gap: 12px; }
.pl-time { font-size: 12px; color: var(--ink-quiet); font-variant-numeric: tabular-nums; min-width: 42px; }
.pl-left { text-align: right; }
.pl-range {
  flex: 1; height: 28px; margin: 0; background: transparent; cursor: pointer;
  -webkit-appearance: none; appearance: none; --pct: 0%;
}
.pl-range::-webkit-slider-runnable-track {
  height: 4px; border-radius: 4px;
  background: linear-gradient(90deg, var(--ruby) var(--pct), var(--line) var(--pct));
}
.pl-range::-moz-range-track { height: 4px; border-radius: 4px; background: var(--line); }
.pl-range::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--ruby); }
.pl-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%;
  background: var(--ink); box-shadow: 0 0 0 4px var(--ruby-glow);
}
.pl-range::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--ink); }
.pl-controls { justify-content: space-between; gap: 4px; margin-top: 2px; }
.pl-controls svg text { font-family: var(--font-ui); font-size: 7px; font-weight: 600; fill: currentColor; stroke: none; }
.pl-speed { font-size: 13px; font-weight: 600; min-width: 52px; }
.pl-sleep-label { font-size: 12px; font-weight: 600; }
.pl-sleep.active, .pl-cinema[aria-pressed="true"] { color: var(--ruby); }
.pl-play {
  width: 58px; height: 58px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--ruby); color: #fff;
  box-shadow: 0 8px 28px var(--ruby-glow); transition: transform .15s ease;
}
.pl-play:active { transform: scale(.94); }
.pl-play svg { width: 26px; height: 26px; grid-area: 1 / 1; }
.pl-play .i-play { fill: #fff; stroke: none; margin-left: 3px; }
.pl-play .i-pause { stroke-width: 3; display: none; }
.playing .pl-play .i-play { display: none; }
.playing .pl-play .i-pause { display: block; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed; z-index: 60; left: 50%; top: calc(var(--bar-h) + 10px);
  transform: translate(-50%, -10px); margin-left: calc(var(--art-w) / -2);
  width: max-content; max-width: calc(100vw - var(--art-w) - 2 * var(--gutter));
  display: flex; align-items: center; gap: 14px; padding: 10px 10px 10px 18px; border-radius: 14px;
  background: var(--surface-solid); border: 1px solid var(--line); box-shadow: var(--shadow);
  font-family: var(--font-ui); font-size: 14px; color: var(--ink-2);
  opacity: 0; pointer-events: none; transition: opacity .3s ease, transform .3s ease;
}
.toast.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.toast button {
  border: 0; background: var(--line); color: var(--ink); border-radius: 10px; min-height: 36px; padding: 0 12px;
  cursor: pointer; font-size: 13px; font-weight: 500; white-space: nowrap;
}

@media (max-width: 640px) {
  .bar-home span { display: none; }
  .bar-title { visibility: hidden; }
  .mode-switch button { padding: 0 12px; }
  .mode-switch button span { font-size: 13px; }
  .bar { gap: 6px; }
}
@media (max-width: 380px) {
  .mode-switch button svg { display: none; }
}
