/* The story player: the read-along video (or, in Listen, the chapter's picture) as big as the
   screen allows, the Watch/Listen switch and the chapters underneath. */

.watch {
  --top-h: 60px;
  min-height: 100svh;
  background:
    radial-gradient(90% 60% at 50% 0%, rgba(47, 134, 255, 0.14), transparent 70%),
    var(--night-950);
}

/* ------------------------------------------------------------ top bar */
.w-top {
  position: sticky; top: 0; z-index: 20;
  height: var(--top-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 max(12px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  background: rgba(5, 8, 23, 0.86); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.w-back {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 10px 0 4px;
  border-radius: 999px; text-decoration: none; font-weight: 800;
}
.w-back svg { width: 20px; height: 20px; }
.w-back img { width: 30px; height: 30px; }
.w-back:hover { color: var(--honey-300); }
.w-top__title {
  flex: 1; min-width: 0; margin: 0; text-align: center;
  font-family: var(--font-display); font-weight: 600; font-size: 1.02rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.w-lang { display: inline-flex; flex: none; padding: 3px; gap: 2px; border-radius: 999px; border: 1.5px solid rgba(188, 195, 230, 0.3); }
.w-lang button {
  min-width: 44px; height: 38px; padding: 0 10px; border: 0; border-radius: 999px; background: transparent;
  color: var(--text-muted); font-weight: 800; font-size: 0.85rem; cursor: pointer;
}
.w-lang button:hover { color: var(--text); }
.w-lang button[aria-pressed="true"] { background: var(--honey-400); color: var(--night-900); }
@media (max-width: 520px) {
  .w-top__title { visibility: hidden; }
  .w-back span { display: none; }
}

/* ------------------------------------------------------------ the stage */
/* As wide as the page, but never so tall that the switch and title drop off a laptop screen. */
.w-stage {
  position: relative;
  width: min(100%, calc((100svh - var(--top-h) - 150px) * 16 / 9), 1600px);
  min-width: min(100%, 560px);
  aspect-ratio: 16 / 9;
  margin: 0 auto;
  background: #000;
  outline: none;
}
@media (min-width: 900px) {
  .w-stage {
    margin-top: 18px; border-radius: 18px; overflow: hidden; box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.9);
    width: min(calc(100% - 2 * var(--gutter)), calc((100svh - var(--top-h) - 190px) * 16 / 9), 1600px);
  }
}
/* Listen has its controls and the line being read under the picture: a smaller picture keeps
   the Watch/Listen switch on screen. */
.w-stage[data-mode="listen"] { width: min(100%, calc((100svh - var(--top-h) - 300px) * 16 / 9), 1100px); }
@media (min-width: 900px) {
  .w-stage[data-mode="listen"] { width: min(calc(100% - 2 * var(--gutter)), calc((100svh - var(--top-h) - 340px) * 16 / 9), 1100px); }
}
.w-stage video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.w-stage:fullscreen { width: 100%; height: 100%; border-radius: 0; margin: 0; }

/* Listen: the chapter's picture stands in for the video. */
.w-listen { position: absolute; inset: 0; background: var(--night-900); }
.w-listen__pic, .w-listen__pic picture, .w-listen__pic img { width: 100%; height: 100%; }
.w-listen__pic { cursor: pointer; }
.w-listen__pic img { object-fit: cover; }

.w-bigplay {
  position: absolute; left: 50%; top: 50%; z-index: 1; transform: translate(-50%, -50%);
  width: 76px; height: 76px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--honey-400); color: var(--night-900);
  box-shadow: 0 14px 40px -10px rgba(0, 0, 0, 0.8), 0 0 0 8px rgba(255, 193, 92, 0.22);
  transition: transform 0.2s var(--ease);
}
.w-bigplay svg { width: 30px; height: 30px; margin-left: 4px; }
.w-bigplay:hover { transform: translate(-50%, -50%) scale(1.06); }
/* In Watch the browser's control bar is along the bottom; keep clear of it. */
.w-stage[data-mode="watch"] .w-bigplay { top: 46%; }

/* Waiting for the stream or the MP3. */
.w-loading {
  position: absolute; left: 50%; bottom: 16%; z-index: 1; transform: translateX(-50%); margin: 0;
  display: inline-flex; align-items: center; gap: 10px; padding: 8px 16px; border-radius: 999px;
  background: rgba(5, 8, 23, 0.82); font-weight: 800; font-size: 0.92rem; white-space: nowrap;
}
.w-loading__dot { width: 10px; height: 10px; border-radius: 50%; background: var(--honey-400); animation: w-pulse 1s ease-in-out infinite alternate; }
@keyframes w-pulse { from { opacity: 0.25; } to { opacity: 1; } }

/* End of a chapter: what's next, over the last frame. */
.w-end, .w-msg {
  position: absolute; inset: 0; z-index: 2;
  display: grid; place-items: center; padding: 12px 16px;
  background: rgba(5, 8, 23, 0.8); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.w-end__card {
  display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "pic text" "actions actions";
  gap: 12px 16px; align-items: center; max-width: 34rem; width: 100%;
}
.w-end__pic { grid-area: pic; width: clamp(110px, 26vw, 220px); aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; box-shadow: 0 0 0 2px var(--honey-400); }
.w-end__pic picture, .w-end__pic img { width: 100%; height: 100%; object-fit: cover; }
.w-end__text { grid-area: text; min-width: 0; }
.w-end__kicker { margin: 0 0 0.2em; font-weight: 800; font-size: 0.78rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--honey-400); }
.w-end__title { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: clamp(1.1rem, 0.9rem + 1.4vw, 1.9rem); line-height: 1.15; }
.w-end__actions { grid-area: actions; display: flex; flex-wrap: wrap; gap: 10px; }
.w-end.is-last .w-end__card { grid-template-columns: 1fr; grid-template-areas: "text" "actions"; text-align: center; }
.w-end.is-last .w-end__pic { display: none; }
.w-end.is-last .w-end__actions { justify-content: center; }
@media (max-width: 520px) {
  .w-end .btn { min-height: 44px; padding: 0.5em 1em; font-size: 0.92rem; }
}
.w-msg { gap: 6px; align-content: center; text-align: center; }
.w-msg .face { --w: 56px; margin: 0 auto 4px; }
.w-msg p { margin: 0; max-width: 28rem; }
.w-msg__actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px !important; }
.w-noscript { position: absolute; inset: auto 16px 16px; margin: 0; text-align: center; }

/* ------------------------------------------------------------ Listen controls and the line being read */
.w-audio { width: min(100%, 900px); margin: 0 auto; padding: 14px var(--gutter) 0; }
.w-audio__row { display: flex; align-items: center; gap: 12px; font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: 0.85rem; }
.w-audio__play {
  flex: none; width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--honey-400); color: var(--night-900);
}
.w-audio__play svg { width: 20px; height: 20px; }
.w-audio__seek { flex: 1; min-width: 0; height: 28px; accent-color: var(--honey-400); }
.w-cue {
  min-height: 3.2em; margin: 14px 0 0; text-align: center;
  font-family: var(--font-display); font-size: clamp(1.05rem, 0.95rem + 0.6vw, 1.35rem); line-height: 1.45; color: var(--text);
  text-wrap: balance;
}

/* Watch on a phone held upright: the words drawn into the video are small there, so the line
   being read is also written under it, as in Listen. Wider screens show the video's own. */
.w-vcue { display: none; width: 100%; margin: 0; padding: 12px var(--gutter) 0; }
@media (max-width: 719px) and (orientation: portrait) {
  .w-vcue { display: block; }
}

/* ------------------------------------------------------------ title and tools */
.w-info {
  display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: center; justify-content: space-between;
  padding-top: 18px; padding-bottom: 6px;
}
.w-info__text { min-width: 0; }
.w-kicker { margin: 0; font-weight: 800; font-size: 0.8rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--honey-400); }
.w-title { margin: 0.15em 0 0; font-size: clamp(1.45rem, 1.1rem + 1.6vw, 2.2rem); }
.w-resume { margin: 0.4em 0 0; color: var(--text-muted); font-size: 0.95rem; }
.w-info__tools { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: center; }
.btn--small { min-height: 44px; padding: 0.5em 1.1em; font-size: 0.92rem; }
.linklike {
  border: 0; background: none; padding: 0; color: var(--honey-300); font: inherit; font-weight: 800;
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer; min-height: 32px;
}

/* Watch | Listen */
.w-mode { display: inline-flex; padding: 4px; gap: 2px; border-radius: 999px; border: 1.5px solid rgba(188, 195, 230, 0.3); background: rgba(12, 20, 54, 0.6); }
.w-mode button {
  display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 16px; border: 0; border-radius: 999px;
  background: transparent; color: var(--text-muted); font-weight: 800; font-size: 0.95rem; cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}
.w-mode button svg { width: 20px; height: 20px; }
.w-mode button:hover { color: var(--text); }
.w-mode button[aria-pressed="true"] { background: var(--honey-400); color: var(--night-900); }
.w-mode button:disabled { opacity: 0.4; cursor: not-allowed; }

.w-read {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 800; text-decoration: none; color: var(--honey-300);
}
.w-read svg { width: 20px; height: 20px; }
.w-read:hover { text-decoration: underline; text-underline-offset: 3px; }

/* A plain on/off switch around a real checkbox. */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 800; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track {
  position: relative; width: 46px; height: 28px; flex: none; border-radius: 999px;
  background: rgba(188, 195, 230, 0.25); border: 1.5px solid rgba(188, 195, 230, 0.4); transition: background-color 0.2s;
}
.switch__track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 19px; height: 19px; border-radius: 50%;
  background: var(--text); transition: transform 0.2s var(--ease);
}
.switch input:checked + .switch__track { background: var(--honey-400); border-color: var(--honey-400); }
.switch input:checked + .switch__track::after { transform: translateX(18px); background: var(--night-900); }
.switch input:focus-visible + .switch__track { outline: 3px solid var(--honey-400); outline-offset: 3px; }

/* ------------------------------------------------------------ chapters */
.w-rail { padding-top: 14px; padding-bottom: 48px; }
.w-rail ol {
  list-style: none; margin: 0; padding: 4px 2px 10px;
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(150px, 42%); gap: 12px;
  overflow-x: auto; scroll-snap-type: x mandatory; overscroll-behavior-x: contain;
}
@media (min-width: 760px) { .w-rail ol { grid-auto-flow: row; grid-template-columns: repeat(5, minmax(0, 1fr)); overflow: visible; } }
.w-rail li { scroll-snap-align: start; min-width: 0; }
.w-chip {
  position: relative; display: flex; flex-direction: column; height: 100%; text-decoration: none;
  border-radius: 14px; overflow: hidden; background: var(--night-800); border: 1.5px solid var(--line);
  transition: transform 0.2s var(--ease), border-color 0.2s;
}
.w-chip:hover { transform: translateY(-2px); border-color: rgba(244, 239, 229, 0.5); }
.w-chip[aria-current="true"] { border-color: var(--honey-400); box-shadow: 0 0 0 1.5px var(--honey-400); }
.w-chip__img { display: block; aspect-ratio: 16 / 9; overflow: hidden; background: var(--night-700); }
.w-chip__img picture, .w-chip__img img { width: 100%; height: 100%; object-fit: cover; }
.w-chip__img img.is-page { object-position: 50% 25%; }
.w-chip__n {
  position: absolute; top: 8px; left: 8px; width: 28px; height: 28px; border-radius: 9px;
  display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 0.95rem;
  background: var(--honey-400); color: var(--night-900);
}
.w-chip__title { display: block; padding: 8px 10px 0; font-weight: 800; font-size: 0.9rem; line-height: 1.25; }
.w-chip__len { display: block; margin-top: auto; padding: 2px 10px 10px; font-size: 0.8rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  .w-loading__dot { animation: none; }
  .w-chip:hover, .w-bigplay:hover { transform: none; }
  .w-bigplay:hover { transform: translate(-50%, -50%); }
}
