:root {
  --ink: #17243c;
  --muted: #526177;
  --navy: #102a55;
  --blue: #1266d6;
  --cyan: #17b7d4;
  --violet: #6f5bea;
  --surface: #ffffff;
  --surface-soft: #f3f7fc;
  --line: #cbd7e7;
  --focus: #ffbf47;
  --shadow: 0 24px 70px rgba(18, 43, 84, 0.14);
  --radius-xl: 32px;
  --radius-lg: 22px;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: #eef4fb;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 280px;
  background:
    radial-gradient(circle at 8% 3%, rgba(23, 183, 212, 0.16), transparent 26rem),
    radial-gradient(circle at 92% 7%, rgba(111, 91, 234, 0.13), transparent 30rem),
    linear-gradient(180deg, #f9fbff 0%, #eef4fb 48%, #f8fbff 100%);
  line-height: 1.6;
}

button,
a,
summary {
  font: inherit;
}

a {
  color: #064fae;
}

:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 4px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 1rem;
  left: 1rem;
  padding: 0.7rem 1rem;
  border-radius: 0.7rem;
  background: var(--navy);
  color: #fff;
  transform: translateY(-180%);
}

.skip-link:focus {
  transform: translateY(0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(1180px, calc(100% - 2rem));
  margin: 1rem auto 0;
  padding: 0.8rem 1rem;
  border: 1px solid rgba(203, 215, 231, 0.78);
  border-radius: 1.2rem;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 34px rgba(18, 43, 84, 0.09);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
  color: var(--navy);
  font-weight: 800;
  text-decoration: none;
}

.brand img {
  display: block;
  width: 150px;
  height: auto;
}

.brand span {
  padding-left: 0.8rem;
  border-left: 1px solid var(--line);
}

.site-header nav {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.site-header nav a,
.quiet-button {
  padding: 0.55rem 0.7rem;
  border: 0;
  background: transparent;
  color: var(--navy);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

main {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
}

.episode-hero {
  position: relative;
  overflow: hidden;
  margin: 4.5rem auto 2rem;
  padding: clamp(2rem, 6vw, 5rem);
  border: 1px solid rgba(203, 215, 231, 0.82);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.episode-hero::after {
  content: "";
  position: absolute;
  right: -8rem;
  bottom: -10rem;
  width: 24rem;
  height: 24rem;
  border-radius: 50%;
  background: conic-gradient(from 30deg, rgba(23, 183, 212, 0.28), rgba(111, 91, 234, 0.22), rgba(18, 102, 214, 0.2), rgba(23, 183, 212, 0.28));
  filter: blur(4px);
}

.episode-hero > * {
  position: relative;
  z-index: 1;
}

.eyebrow,
.section-label,
.scene-number {
  margin: 0 0 0.6rem;
  color: var(--blue);
  font-size: 0.79rem;
  font-weight: 850;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  max-width: 16ch;
  margin: 0;
  color: var(--navy);
  font-size: clamp(2.6rem, 7vw, 5.7rem);
  line-height: 0.98;
  letter-spacing: -0.055em;
}

.lead {
  max-width: 66ch;
  margin: 1.6rem 0;
  color: var(--muted);
  font-size: clamp(1.08rem, 2vw, 1.35rem);
}

.episode-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin: 1.5rem 0;
}

.episode-meta div {
  display: inline-flex;
  gap: 0.35rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
}

.episode-meta dt {
  font-weight: 800;
}

.episode-meta dd {
  margin: 0;
}

.fiction-note {
  max-width: 72ch;
  margin: 1.4rem 0 0;
  padding-left: 1rem;
  border-left: 4px solid var(--cyan);
  color: var(--muted);
  font-size: 0.95rem;
}

.reader-shell,
.caution,
.transcript,
.next-episode {
  margin: 2rem 0;
  padding: clamp(1rem, 3vw, 2rem);
  border: 1px solid rgba(203, 215, 231, 0.86);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.91);
  box-shadow: 0 16px 50px rgba(18, 43, 84, 0.1);
}

.reader-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.7rem;
}

.reader-toolbar h2,
.caution h2,
.transcript h2,
.next-episode h2 {
  margin: 0;
  color: var(--navy);
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  letter-spacing: -0.03em;
}

.view-switch {
  display: flex;
  gap: 0.35rem;
  padding: 0.3rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
}

.mode-button,
.scene-controls button {
  min-height: 44px;
  padding: 0.6rem 1rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--navy);
  font-weight: 800;
  cursor: pointer;
}

.mode-button[aria-pressed="true"],
.scene-controls button {
  background: var(--navy);
  color: #fff;
}

.mode-button:hover,
.scene-controls button:hover {
  filter: brightness(1.12);
}

.scene-controls button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.keyboard-help {
  margin: 0.5rem 0 1.4rem;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.scene-item {
  margin: 0 0 1.6rem;
}

.reader-shell[data-mode="paged"] .scene-item[hidden] {
  display: none;
}

.scene {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: 0 14px 38px rgba(18, 43, 84, 0.09);
}

.scene-heading {
  padding: 1rem 1.2rem;
  background: linear-gradient(90deg, #f7faff, #eef7fb);
}

.scene-heading p {
  margin-bottom: 0.1rem;
}

.scene-title {
  margin: 0;
  color: var(--navy);
  font-size: clamp(1.35rem, 3vw, 2rem);
}

figure {
  margin: 0;
}

.scene-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 3 / 2;
  background: #dbe5f1;
}

.scene-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.speech-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.bubble {
  position: absolute;
  left: var(--x);
  top: var(--y);
  z-index: 2;
  width: min(38%, 22rem);
  margin: 0;
  padding: 0.72rem 0.88rem;
  border: 2px solid var(--navy);
  border-radius: 1rem 1rem 1rem 0.25rem;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  box-shadow: 0 8px 24px rgba(16, 42, 85, 0.2);
  font-size: clamp(0.78rem, 1.5vw, 1.04rem);
  line-height: 1.25;
}

.bubble::after {
  content: "";
  position: absolute;
  left: 1rem;
  bottom: -0.65rem;
  width: 0.85rem;
  height: 0.85rem;
  border-right: 2px solid var(--navy);
  border-bottom: 2px solid var(--navy);
  background: inherit;
  transform: rotate(45deg);
}

.bubble[data-kind="message"] {
  border-color: #5d4ed2;
  background: #f5f1ff;
}

.bubble[data-kind="offscreen"] {
  border-style: dashed;
}

.bubble[data-kind="screen"] {
  border: 1px solid #8ea8c7;
  border-radius: 0.65rem;
  background: rgba(241, 247, 255, 0.96);
  font-size: 0.82rem;
}

.bubble[data-kind="screen"]::after {
  display: none;
}

.speaker {
  display: block;
  margin-bottom: 0.12rem;
  color: #095dbd;
  font-size: 0.78em;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

figcaption {
  padding: 1rem 1.2rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.96rem;
}

.scene-description {
  margin: 0 1.2rem 1.2rem;
  padding: 0.7rem 0.9rem;
  border-radius: 0.8rem;
  background: var(--surface-soft);
}

.scene-description summary {
  color: var(--navy);
  font-weight: 800;
  cursor: pointer;
}

.scene-description p {
  margin: 0.6rem 0 0;
}

.scene-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.8rem;
  margin-top: 1rem;
}

.scene-controls button:last-child {
  justify-self: end;
}

.scene-controls span {
  color: var(--muted);
  font-weight: 800;
}

.next-episode {
  background: linear-gradient(130deg, #112a54, #214d8a 60%, #27789a);
  color: #fff;
}

.next-episode h2,
.next-episode .section-label {
  color: #fff;
}

.caution {
  border-left: 7px solid var(--cyan);
}

.transcript-content {
  margin-top: 1.3rem;
}

.transcript-scene {
  padding: 1.1rem 0;
  border-top: 1px solid var(--line);
}

.transcript-scene h3 {
  margin: 0 0 0.4rem;
  color: var(--navy);
}

.transcript-description,
.transcript-caption {
  color: var(--muted);
}

.transcript-dialogue {
  padding-left: 1rem;
  border-left: 3px solid #9cbfe9;
}

footer {
  width: min(1120px, calc(100% - 2rem));
  margin: 2rem auto;
  padding: 1.2rem;
  color: var(--muted);
  text-align: center;
}

.noscript-message,
.error-message {
  width: min(900px, calc(100% - 2rem));
  margin: 2rem auto;
  padding: 1rem;
  border: 2px solid #a11b32;
  border-radius: 1rem;
  background: #fff1f3;
  color: #681122;
}

@media (max-width: 760px) {
  .site-header {
    align-items: flex-start;
  }

  .brand span,
  .site-header nav a {
    display: none;
  }

  .site-header nav a:first-child {
    display: inline-flex;
  }

  .site-header nav {
    gap: 0;
  }

  .episode-hero {
    margin-top: 2rem;
  }

  .reader-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .view-switch {
    width: 100%;
    border-radius: 1rem;
  }

  .mode-button {
    flex: 1;
    border-radius: 0.8rem;
  }

  .scene-frame {
    overflow: visible;
    aspect-ratio: auto;
    background: #fff;
  }

  .scene-image {
    height: auto;
    aspect-ratio: 3 / 2;
  }

  .speech-layer {
    position: static;
    display: grid;
    gap: 0.65rem;
    padding: 0.8rem;
    background: #f7faff;
  }

  .bubble {
    position: relative;
    left: auto;
    top: auto;
    width: 100%;
    min-height: 44px;
    font-size: 1rem;
  }

  .bubble::after {
    display: none;
  }

  .scene-controls {
    grid-template-columns: 1fr 1fr;
  }

  .scene-controls span {
    grid-column: 1 / -1;
    grid-row: 1;
    text-align: center;
  }

  .scene-controls button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  :root {
    background: #fff;
  }

  body {
    background: #fff;
    font-size: 10.5pt;
  }

  .site-header,
  .reader-toolbar,
  .keyboard-help,
  .scene-controls,
  .skip-link,
  footer,
  .scene-description,
  .transcript {
    display: none !important;
  }

  main {
    width: 100%;
  }

  .episode-hero,
  .reader-shell,
  .caution,
  .next-episode {
    margin: 0 0 8mm;
    padding: 6mm;
    border: 1px solid #777;
    box-shadow: none;
    break-inside: avoid;
  }

  .scene-item,
  .reader-shell[data-mode="paged"] .scene-item[hidden] {
    display: list-item !important;
    break-before: page;
    break-inside: avoid;
  }

  .scene {
    border: 0;
    box-shadow: none;
  }

  .scene-frame {
    border: 1px solid #777;
  }

  .bubble {
    border-color: #000;
    box-shadow: none;
  }

  @page {
    size: A4 portrait;
    margin: 12mm;
  }
}
