:root {
  color-scheme: dark;
  --night: #07111f;
  --ink: #0b1018;
  --paper: #fff8e9;
  --yellow: #ffd21c;
  --cyan: #35d7ff;
  --magenta: #ff4eaa;
  --lime: #a7f542;
  --red: #ff4b3e;
  --white: #ffffff;
  --rail-height: 72px;
  --bar-height: 68px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--night);
}

body {
  font-family: "Trebuchet MS", Arial, sans-serif;
  color: var(--white);
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.reader {
  height: 100svh;
  min-height: 520px;
  display: grid;
  grid-template-rows: var(--bar-height) minmax(0, 1fr) var(--rail-height);
  background: var(--night);
}

.mission-bar,
.reader-controls {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  border-color: rgba(255, 255, 255, 0.13);
  background: rgba(5, 12, 23, 0.96);
}

.mission-bar {
  justify-content: space-between;
  gap: 20px;
  padding: 0 clamp(14px, 3vw, 42px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--white);
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 36px;
  flex: 0 0 auto;
  fill: var(--yellow);
}

.brand-spark {
  fill: var(--cyan);
}

.brand span {
  display: grid;
  line-height: 1;
}

.brand strong {
  font-family: Impact, "Arial Black", sans-serif;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand small {
  margin-top: 3px;
  color: var(--cyan);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.episode-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 0 12px;
  border-left: 3px solid var(--magenta);
  background: rgba(255, 255, 255, 0.07);
  font-size: 11px;
  text-transform: uppercase;
}

.episode-chip span {
  color: var(--magenta);
  font-weight: 900;
}

.episode-chip strong {
  font-size: 11px;
}

.header-tools {
  display: flex;
  gap: 8px;
}

.icon-button,
.dialog-close,
.page-arrow {
  display: grid;
  place-items: center;
  border: 0;
  color: var(--white);
  cursor: pointer;
}

.icon-button {
  width: 40px;
  height: 40px;
  background: transparent;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: rgba(255, 255, 255, 0.1);
}

.icon-button svg,
.dialog-close svg,
.read-button svg,
.page-arrow svg,
.turn-device svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.story-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  background: #111b2a;
}

.scene-image {
  position: absolute;
  z-index: -4;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0;
  transform: scale(1.035);
  transition: opacity 420ms ease, transform 1.2s ease;
}

.scene-image.loaded {
  opacity: 1;
  transform: scale(1);
}

.scene-shade {
  position: absolute;
  z-index: -3;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(2, 7, 14, 0.84) 0%, rgba(2, 7, 14, 0.32) 43%, rgba(2, 7, 14, 0.04) 72%),
    linear-gradient(180deg, rgba(2, 7, 14, 0.18) 30%, rgba(2, 7, 14, 0.76) 100%);
}

.reader.cover .scene-shade {
  background:
    linear-gradient(90deg, rgba(2, 7, 14, 0.82) 0%, rgba(2, 7, 14, 0.22) 52%, rgba(2, 7, 14, 0.05) 100%),
    linear-gradient(180deg, rgba(2, 7, 14, 0.04) 30%, rgba(2, 7, 14, 0.76) 100%);
}

.speed-lines,
.spark-field {
  position: absolute;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}

.reader.action-page .speed-lines {
  opacity: 0.32;
  background: repeating-linear-gradient(105deg, transparent 0 32px, rgba(255, 255, 255, 0.22) 33px 35px, transparent 36px 78px);
  animation: race-lines 900ms linear infinite;
}

.reader.space-page .spark-field {
  opacity: 0.9;
  background-image:
    radial-gradient(circle at 12% 19%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 37% 71%, #35d7ff 0 1px, transparent 2px),
    radial-gradient(circle at 72% 16%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 88% 62%, #ffd21c 0 1px, transparent 2px);
  background-size: 210px 180px, 260px 220px, 310px 240px, 390px 300px;
  animation: stars 10s linear infinite;
}

.chapter-label {
  position: absolute;
  top: 24px;
  left: clamp(76px, 8vw, 132px);
  padding: 7px 12px;
  border-left: 4px solid var(--yellow);
  background: rgba(5, 12, 23, 0.82);
  color: var(--yellow);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.story-copy {
  position: absolute;
  z-index: 4;
  left: clamp(76px, 8vw, 132px);
  bottom: clamp(30px, 6vh, 76px);
  width: min(560px, calc(100% - 190px));
  animation: copy-in 500ms both;
}

.page-kicker {
  margin: 0 0 6px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.story-copy h1 {
  max-width: 720px;
  margin: 0;
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(34px, 5.3vw, 72px);
  font-weight: 900;
  line-height: 0.96;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.36);
}

.reader.cover .story-copy h1 {
  max-width: 600px;
  color: var(--yellow);
  font-size: clamp(46px, 7.3vw, 96px);
}

.narration {
  max-width: 520px;
  margin: 14px 0 0;
  padding: 11px 14px;
  border-left: 5px solid var(--yellow);
  background: rgba(255, 248, 233, 0.94);
  color: var(--ink);
  font-size: clamp(15px, 1.5vw, 19px);
  font-weight: 800;
  line-height: 1.34;
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.3);
}

.speech-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.speech {
  position: relative;
  width: fit-content;
  max-width: 360px;
  margin: 0;
  padding: 9px 12px;
  border: 2px solid var(--ink);
  background: var(--white);
  color: var(--ink);
  font-size: clamp(13px, 1.2vw, 16px);
  font-weight: 900;
  line-height: 1.25;
  box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.38);
}

.speech.ayden {
  border-color: var(--yellow);
}

.speech.maya {
  border-color: var(--magenta);
}

.speech.annie {
  border-color: var(--cyan);
}

.mission-action {
  position: absolute;
  z-index: 8;
  top: 72px;
  right: clamp(72px, 7vw, 112px);
  width: min(340px, calc(100% - 150px));
}

.action-panel {
  padding: 15px;
  border-top: 4px solid var(--cyan);
  background: rgba(5, 12, 23, 0.9);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
  animation: action-in 420ms 220ms both;
}

.action-panel.complete {
  border-color: var(--lime);
}

.action-eyebrow,
.action-result {
  margin: 0;
  color: var(--cyan);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.action-panel.complete .action-eyebrow,
.action-result.success {
  color: var(--lime);
}

.action-panel h2 {
  margin: 4px 0 0;
  font-family: Impact, "Arial Black", sans-serif;
  font-size: 23px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.action-panel p {
  margin: 7px 0 0;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
}

.action-buttons,
.sequence-buttons {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.action-button,
.dialog-button,
.start-button {
  min-height: 42px;
  border: 0;
  background: var(--yellow);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
  text-transform: uppercase;
}

.action-button:hover,
.action-button:focus-visible,
.dialog-button:hover,
.start-button:hover {
  background: var(--cyan);
}

.action-button.wrong {
  background: var(--red);
  color: var(--white);
  animation: shake 250ms linear;
}

.sequence-buttons {
  grid-template-columns: repeat(3, 1fr);
}

.sequence-button {
  min-height: 48px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
}

.sequence-button.blue {
  background: #168bff;
}

.sequence-button.gold {
  background: var(--yellow);
}

.sequence-button.pink {
  background: var(--magenta);
}

.sequence-meter {
  display: flex;
  gap: 7px;
  margin-top: 12px;
}

.sequence-meter span {
  width: 25px;
  height: 8px;
  background: rgba(255, 255, 255, 0.18);
}

.sequence-meter span.filled {
  background: var(--lime);
}

.hotspot {
  position: fixed;
  left: var(--x);
  top: var(--y);
  width: 62px;
  height: 62px;
  border: 3px solid var(--yellow);
  border-radius: 50%;
  background: rgba(255, 210, 28, 0.18);
  box-shadow: 0 0 0 10px rgba(255, 210, 28, 0.1);
  cursor: pointer;
  animation: hotspot-pulse 1.4s ease-in-out infinite;
}

.hotspot::before,
.hotspot::after {
  content: "";
  position: absolute;
  background: var(--yellow);
}

.hotspot::before {
  width: 22px;
  height: 3px;
  left: 17px;
  top: 27px;
}

.hotspot::after {
  width: 3px;
  height: 22px;
  left: 27px;
  top: 17px;
}

.hotspot.found {
  border-color: var(--lime);
  background: rgba(167, 245, 66, 0.25);
  animation: pop 420ms both;
}

.hotspot.found::before,
.hotspot.found::after {
  background: var(--lime);
}

.countdown {
  margin-top: 8px;
  color: var(--yellow);
  font-family: Impact, "Arial Black", sans-serif;
  font-size: 58px;
  line-height: 1;
  text-align: center;
}

.mission-stamp {
  display: inline-block;
  margin-top: 11px;
  padding: 7px 10px;
  border: 3px solid var(--lime);
  color: var(--lime);
  font-family: Impact, "Arial Black", sans-serif;
  font-size: 19px;
  transform: rotate(-2deg);
  text-transform: uppercase;
}

.page-arrow {
  position: absolute;
  z-index: 12;
  top: 50%;
  width: 52px;
  height: 68px;
  transform: translateY(-50%);
  background: rgba(5, 12, 23, 0.74);
  backdrop-filter: blur(8px);
}

.page-arrow:hover,
.page-arrow:focus-visible {
  background: var(--yellow);
  color: var(--ink);
}

.page-arrow:disabled {
  opacity: 0;
  pointer-events: none;
}

.page-arrow.previous {
  left: 0;
}

.page-arrow.next {
  right: 0;
}

.page-arrow svg {
  width: 30px;
  height: 30px;
}

.reader-controls {
  gap: 22px;
  padding: 0 clamp(14px, 3vw, 42px);
  border-top: 1px solid rgba(255, 255, 255, 0.13);
}

.read-button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
  color: var(--white);
  font-weight: 900;
  cursor: pointer;
}

.read-button:hover,
.read-button:focus-visible {
  border-color: var(--cyan);
  color: var(--cyan);
}

.progress-track {
  min-width: 0;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(15, minmax(8px, 1fr));
  gap: 5px;
}

.progress-dot {
  height: 8px;
  padding: 0;
  border: 0;
  background: rgba(255, 255, 255, 0.16);
  cursor: pointer;
}

.progress-dot.visited {
  background: rgba(53, 215, 255, 0.55);
}

.progress-dot.active {
  background: var(--yellow);
}

.page-number {
  min-width: 54px;
  color: rgba(255, 255, 255, 0.76);
  font-size: 12px;
  font-weight: 900;
  text-align: right;
}

.mission-dialog {
  width: min(560px, calc(100% - 28px));
  max-height: min(680px, calc(100svh - 28px));
  padding: 30px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: #0c1727;
  color: var(--white);
  box-shadow: 18px 18px 0 rgba(0, 0, 0, 0.36);
}

.mission-dialog::backdrop {
  background: rgba(0, 0, 0, 0.76);
  backdrop-filter: blur(6px);
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  background: transparent;
}

.dialog-kicker,
.dialog-subtitle {
  margin: 0;
}

.dialog-kicker {
  color: var(--cyan);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.mission-dialog h2 {
  margin: 5px 0;
  color: var(--yellow);
  font-family: Impact, "Arial Black", sans-serif;
  font-size: 40px;
  text-transform: uppercase;
}

.dialog-subtitle {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
}

.discovery-list {
  margin: 22px 0;
  padding: 0;
  list-style: none;
}

.discovery-list li {
  padding: 11px 0 11px 30px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(90deg, var(--lime) 0 12px, transparent 12px);
  font-weight: 800;
}

.discovery-list li.locked {
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.18) 0 12px, transparent 12px);
  color: rgba(255, 255, 255, 0.38);
}

.dialog-button {
  width: 100%;
}

.turn-device {
  display: none;
}

.reader.flash .story-stage::after {
  content: "";
  position: absolute;
  z-index: 30;
  inset: 0;
  pointer-events: none;
  background: var(--yellow);
  animation: flash 600ms both;
}

.reader.shake .story-stage {
  animation: stage-shake 420ms linear;
}

@keyframes copy-in {
  from { opacity: 0; transform: translateX(-24px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes action-in {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes race-lines {
  to { transform: translateX(-78px); }
}

@keyframes stars {
  to { transform: translate(-70px, 40px); }
}

@keyframes hotspot-pulse {
  50% { transform: scale(1.12); box-shadow: 0 0 0 18px rgba(255, 210, 28, 0.04); }
}

@keyframes pop {
  60% { transform: scale(1.4) rotate(12deg); }
  to { transform: scale(1); }
}

@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}

@keyframes flash {
  from { opacity: 0.85; }
  to { opacity: 0; }
}

@keyframes stage-shake {
  20% { transform: translate(-6px, 2px); }
  40% { transform: translate(7px, -3px); }
  60% { transform: translate(-4px, 4px); }
  80% { transform: translate(3px, -2px); }
}

@media (max-width: 820px) {
  :root {
    --bar-height: 58px;
    --rail-height: 62px;
  }

  .reader {
    min-height: 460px;
  }

  .brand-mark {
    width: 34px;
  }

  .brand strong {
    font-size: 15px;
  }

  .episode-chip strong,
  .brand small,
  .read-button span {
    display: none;
  }

  .episode-chip {
    min-height: 30px;
    padding: 0 8px;
  }

  .story-copy {
    left: 56px;
    bottom: 18px;
    width: min(470px, calc(100% - 116px));
  }

  .story-copy h1 {
    font-size: clamp(30px, 6vw, 52px);
  }

  .reader.cover .story-copy h1 {
    font-size: clamp(38px, 8vw, 64px);
  }

  .narration {
    margin-top: 8px;
    padding: 8px 10px;
    font-size: 13px;
  }

  .speech-row {
    margin-top: 7px;
  }

  .speech {
    padding: 7px 9px;
    font-size: 12px;
  }

  .chapter-label {
    top: 14px;
    left: 56px;
  }

  .mission-action {
    top: 54px;
    right: 58px;
    width: min(270px, calc(100% - 120px));
  }

  .action-panel {
    padding: 10px;
  }

  .action-panel h2 {
    font-size: 18px;
  }

  .action-panel p {
    font-size: 11px;
  }

  .action-button {
    min-height: 36px;
    font-size: 11px;
  }

  .page-arrow {
    width: 42px;
    height: 58px;
  }

  .reader-controls {
    gap: 10px;
    padding: 0 10px;
  }

  .read-button {
    width: 42px;
    min-height: 40px;
    padding: 0;
    justify-content: center;
  }
}

@media (max-height: 620px) and (orientation: landscape) {
  :root {
    --bar-height: 50px;
    --rail-height: 54px;
  }

  .reader {
    min-height: 0;
  }

  .mission-bar {
    padding: 0 12px;
  }

  .brand-mark {
    width: 30px;
    height: 28px;
  }

  .brand strong {
    font-size: 13px;
  }

  .brand small,
  .episode-chip strong,
  .read-button span {
    display: none;
  }

  .episode-chip {
    min-height: 28px;
    padding: 0 7px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
  }

  .chapter-label {
    display: none;
  }

  .story-copy {
    left: 48px;
    bottom: 10px;
    width: min(390px, 48%);
  }

  .story-copy h1,
  .reader.cover .story-copy h1 {
    font-size: clamp(26px, 5.2vw, 42px);
  }

  .page-kicker {
    margin-bottom: 3px;
    font-size: 9px;
  }

  .narration {
    margin-top: 6px;
    padding: 6px 8px;
    border-left-width: 3px;
    font-size: 10px;
    line-height: 1.25;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.28);
  }

  .speech-row {
    display: none;
  }

  .mission-action {
    top: 12px;
    right: 46px;
    width: min(260px, 39%);
  }

  .action-panel {
    padding: 8px;
    border-top-width: 3px;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.28);
  }

  .action-eyebrow {
    font-size: 8px;
  }

  .action-panel h2 {
    margin-top: 2px;
    font-size: 15px;
  }

  .action-panel p {
    margin-top: 3px;
    font-size: 9px;
    line-height: 1.2;
  }

  .action-buttons,
  .sequence-buttons {
    gap: 4px;
    margin-top: 6px;
  }

  .action-button {
    min-height: 28px;
    font-size: 9px;
  }

  .sequence-button {
    min-height: 30px;
  }

  .sequence-meter {
    margin-top: 5px;
  }

  .countdown {
    font-size: 32px;
  }

  .mission-stamp {
    margin-top: 5px;
    padding: 3px 6px;
    border-width: 2px;
    font-size: 12px;
  }

  .start-button {
    min-height: 34px;
    font-size: 11px;
  }

  .page-arrow {
    width: 38px;
    height: 48px;
  }

  .reader-controls {
    gap: 9px;
    padding: 0 10px;
  }

  .read-button {
    width: 38px;
    min-height: 36px;
    padding: 0;
    justify-content: center;
  }

  .progress-track {
    gap: 3px;
  }

  .progress-dot {
    height: 6px;
  }

  .hotspot {
    width: 48px;
    height: 48px;
  }

  .hotspot::before {
    width: 18px;
    left: 12px;
    top: 20px;
  }

  .hotspot::after {
    height: 18px;
    left: 20px;
    top: 12px;
  }
}

@media (orientation: portrait) and (max-width: 600px) {
  .turn-device {
    position: fixed;
    z-index: 100;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 16px;
    padding: 36px;
    background: var(--night);
    color: var(--yellow);
    text-align: center;
  }

  .turn-device svg {
    width: 58px;
    height: 58px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
