:root {
  color-scheme: dark;
  --night: #0c0721;
  --deep-purple: #160b3d;
  --violet: #32206d;
  --violet-bright: #6844c5;
  --gold: #f1c65a;
  --gold-soft: #ffe7a2;
  --lavender: #d8ccff;
  --cream: #fff9e9;
  --ink: #20153e;
  --muted: #bdb2dc;
  --line: rgba(255, 231, 162, 0.22);
  --shadow: 0 26px 70px rgba(2, 0, 14, 0.5);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--night);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  color: var(--cream);
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 8% 12%, rgba(115, 73, 204, 0.36), transparent 28rem),
    radial-gradient(circle at 94% 78%, rgba(23, 164, 183, 0.18), transparent 28rem),
    linear-gradient(145deg, #090519 0%, var(--deep-purple) 48%, #0c1838 100%);
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.sky {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.sky::before,
.sky::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  filter: blur(2px);
}

.sky::before {
  width: 20rem;
  height: 20rem;
  left: -9rem;
  bottom: -8rem;
  background: rgba(79, 51, 158, 0.22);
}

.sky::after {
  width: 16rem;
  height: 16rem;
  right: -7rem;
  top: -6rem;
  background: rgba(241, 198, 90, 0.09);
}

.spark {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--gold-soft);
  box-shadow: 0 0 12px var(--gold);
  animation: shimmer 3.8s ease-in-out infinite;
}

.spark-one { top: 8%; left: 15%; }
.spark-two { top: 18%; right: 12%; animation-delay: -1.2s; }
.spark-three { bottom: 14%; left: 7%; animation-delay: -2.4s; }
.spark-four { bottom: 8%; right: 24%; animation-delay: -0.6s; }
.spark-five { top: 52%; right: 5%; animation-delay: -3s; }

@keyframes shimmer {
  0%, 100% { opacity: 0.28; transform: scale(0.75); }
  50% { opacity: 1; transform: scale(1.45); }
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 0 max(24px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.brand-button {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 52px;
  padding: 4px 6px;
  border: 0;
  color: var(--cream);
  text-align: left;
  background: transparent;
  cursor: pointer;
}

.brand-button strong,
.brand-button small {
  display: block;
}

.brand-button strong {
  color: var(--gold-soft);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
  letter-spacing: 0.075em;
}

.brand-button small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.brand-star {
  display: grid;
  width: 43px;
  height: 43px;
  place-items: center;
  border: 1px solid rgba(255, 231, 162, 0.5);
  border-radius: 15px;
  color: var(--gold);
  font-size: 1.55rem;
  background: linear-gradient(145deg, rgba(104, 68, 197, 0.88), rgba(27, 15, 65, 0.88));
  box-shadow: 0 10px 26px rgba(7, 2, 28, 0.42);
}

.star-counter {
  display: flex;
  align-items: baseline;
  min-width: 82px;
  justify-content: center;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(15, 9, 39, 0.7);
  box-shadow: 0 10px 30px rgba(4, 0, 20, 0.22);
  backdrop-filter: blur(14px);
}

.counter-star {
  margin-right: 7px;
  color: var(--gold);
  font-size: 1.1rem;
}

#starCount {
  font-size: 1.05rem;
  font-weight: 800;
}

.counter-total {
  color: var(--muted);
  font-size: 0.88rem;
}

.story-stage {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(390px, 0.82fr);
  min-height: min(690px, calc(100svh - 118px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 32px;
  background: rgba(18, 10, 48, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.art-panel {
  position: relative;
  min-height: 560px;
  overflow: hidden;
  background: linear-gradient(150deg, #39216f, #111a40);
}

.art-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

.art-panel img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transition: opacity 280ms ease, transform 700ms ease;
}

.art-panel.is-changing img {
  opacity: 0.15;
  transform: scale(1.025);
}

.image-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(8, 5, 25, 0.6), transparent 42%);
  pointer-events: none;
}

.chapter-pill {
  position: absolute;
  top: 20px;
  left: 20px;
  max-width: calc(100% - 150px);
  overflow: hidden;
  padding: 9px 13px;
  border: 1px solid rgba(255, 231, 162, 0.48);
  border-radius: 999px;
  color: var(--gold-soft);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: rgba(15, 7, 39, 0.72);
  box-shadow: 0 9px 22px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(10px);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.earned-star {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  color: var(--gold);
  font-size: 4rem;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.25) rotate(-20deg);
  text-shadow: 0 0 30px rgba(241, 198, 90, 0.95);
  pointer-events: none;
}

.earned-star.pop {
  animation: star-pop 900ms ease-out;
}

@keyframes star-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.2) rotate(-20deg); }
  42% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(6deg); }
  100% { opacity: 0; transform: translate(-50%, -64%) scale(0.82) rotate(0deg); }
}

.story-panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: clamp(25px, 4vw, 48px);
}

.progress-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: clamp(34px, 6vh, 64px);
}

.progress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
}

.progress-track span {
  display: block;
  width: 4%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #b686ff, var(--gold));
  box-shadow: 0 0 16px rgba(241, 198, 90, 0.42);
  transition: width 450ms ease;
}

#progressLabel {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.story-copy {
  flex: 1;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: 0.8rem;
  font-weight: 850;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 15ch;
  margin: 0;
  color: var(--cream);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 4vw, 3.3rem);
  font-weight: 700;
  line-height: 1.03;
  letter-spacing: -0.025em;
}

.narration {
  max-width: 36rem;
  margin: 22px 0 0;
  color: #ddd6f3;
  font-size: 1.04rem;
  line-height: 1.66;
}

.dialogue {
  display: grid;
  gap: 10px;
  margin-top: 23px;
}

.dialogue[hidden] {
  display: none;
}

.line {
  margin: 0;
  padding: 13px 15px;
  border-left: 3px solid var(--gold);
  border-radius: 0 14px 14px 0;
  color: #f7f3ff;
  font-size: 1rem;
  line-height: 1.46;
  background: rgba(255, 255, 255, 0.055);
}

.line strong {
  color: var(--gold-soft);
}

.choice-area {
  display: grid;
  gap: 12px;
  margin-top: 30px;
}

.choice {
  display: flex;
  width: 100%;
  min-height: 57px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 15px 18px;
  border: 1px solid rgba(255, 231, 162, 0.5);
  border-radius: 17px;
  color: var(--cream);
  font-size: 1rem;
  font-weight: 800;
  text-align: left;
  background: linear-gradient(135deg, rgba(100, 64, 190, 0.92), rgba(49, 29, 110, 0.95));
  box-shadow: 0 11px 26px rgba(5, 1, 24, 0.25);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, filter 160ms ease;
}

.choice:hover {
  border-color: var(--gold-soft);
  filter: brightness(1.08);
  transform: translateY(-2px);
}

.choice:active {
  transform: translateY(0) scale(0.99);
}

.primary-choice {
  color: #21143f;
  background: linear-gradient(135deg, #ffe8a5, var(--gold));
}

.footer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 14px;
}

.audio-controls {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 4;
  display: flex;
  gap: 10px;
}

.audio-toggle {
  position: relative;
  display: grid;
  width: 48px;
  height: 48px;
  align-items: center;
  justify-items: center;
  padding: 0;
  border: 1px solid rgba(255, 231, 162, 0.58);
  border-radius: 50%;
  color: var(--cream);
  background: rgba(15, 7, 39, 0.78);
  box-shadow: 0 9px 24px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(12px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.audio-toggle:hover {
  border-color: var(--gold-soft);
  background: rgba(50, 32, 109, 0.94);
  transform: translateY(-1px);
}

.audio-toggle[aria-pressed="true"] {
  border-color: var(--gold-soft);
  color: var(--ink);
  background: linear-gradient(145deg, var(--gold-soft), var(--gold));
}

.audio-toggle:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
}

.audio-icon {
  display: block;
  width: 24px;
  height: 24px;
}

.audio-icon svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.audio-icon path {
  fill: currentColor;
  stroke: none;
}

.audio-icon .sound-wave,
.audio-icon .icon-slash {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.audio-icon .icon-slash {
  opacity: 0;
  stroke-width: 2.25;
  paint-order: stroke;
}

.audio-toggle[aria-pressed="false"] .icon-slash {
  opacity: 1;
}

.audio-tooltip {
  position: absolute;
  top: calc(100% + 9px);
  left: 50%;
  width: max-content;
  max-width: 120px;
  padding: 6px 9px;
  border: 1px solid rgba(255, 231, 162, 0.35);
  border-radius: 9px;
  color: var(--cream);
  font-size: 0.74rem;
  font-weight: 750;
  line-height: 1.1;
  text-align: center;
  background: rgba(12, 7, 33, 0.94);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -4px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.audio-toggle:hover .audio-tooltip,
.audio-toggle:focus-visible .audio-tooltip,
.audio-toggle.show-tooltip .audio-tooltip {
  opacity: 1;
  transform: translate(-50%, 0);
}

.text-button {
  min-height: 44px;
  border: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  background: transparent;
  cursor: pointer;
}

.text-button:hover {
  color: var(--cream);
}

.device-note {
  color: rgba(216, 204, 255, 0.68);
  font-size: 0.76rem;
  font-weight: 650;
}

.story-copy.is-reading .narration {
  color: #fff;
}

.line {
  transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.line.is-speaking {
  border-left-color: #fff3c7;
  background: rgba(241, 198, 90, 0.12);
  transform: translateX(3px);
}

.ending-card {
  position: fixed;
  inset: 50% auto auto 50%;
  z-index: 20;
  width: min(440px, calc(100% - 34px));
  padding: 32px;
  border: 1px solid rgba(255, 231, 162, 0.66);
  border-radius: 28px;
  color: var(--cream);
  text-align: center;
  background:
    radial-gradient(circle at 50% 0, rgba(241, 198, 90, 0.19), transparent 48%),
    rgba(24, 12, 61, 0.98);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.72);
  transform: translate(-50%, -50%);
}

.ending-card[hidden] {
  display: none;
}

.ending-card::before {
  content: "";
  position: fixed;
  inset: -100vh -100vw;
  z-index: -1;
  background: rgba(4, 1, 13, 0.68);
  backdrop-filter: blur(7px);
}

.ending-card p {
  margin: 7px 0 13px;
  color: var(--lavender);
  line-height: 1.5;
}

.ending-card h2 {
  margin: 0 0 12px;
  color: var(--gold-soft);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.15rem;
}

.badge-icon {
  display: grid;
  width: 66px;
  height: 66px;
  margin: -2px auto 14px;
  place-items: center;
  border: 2px solid rgba(255, 231, 162, 0.72);
  border-radius: 50%;
  color: var(--gold);
  font-size: 2.2rem;
  background: #3b277b;
  box-shadow: 0 0 35px rgba(241, 198, 90, 0.2);
}

@media (max-width: 800px) {
  .app-shell {
    width: min(100%, 650px);
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .topbar {
    padding: 0 14px;
    margin-bottom: 10px;
  }

  .brand-button strong {
    font-size: 0.92rem;
  }

  .brand-button small {
    font-size: 0.72rem;
  }

  .brand-star {
    width: 39px;
    height: 39px;
    border-radius: 13px;
  }

  .story-stage {
    display: flex;
    min-height: 0;
    flex-direction: column;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .art-panel {
    min-height: 0;
    aspect-ratio: 4 / 3;
  }

  .chapter-pill {
    top: 14px;
    left: 14px;
  }

  .audio-controls {
    top: 14px;
    right: 14px;
  }

  .story-panel {
    min-height: calc(100svh - 46vw - 83px);
    padding: 23px 20px 18px;
  }

  .progress-wrap {
    margin-bottom: 27px;
  }

  h1 {
    max-width: 18ch;
    font-size: clamp(1.9rem, 9vw, 2.7rem);
  }

  .narration {
    margin-top: 16px;
    font-size: 1rem;
    line-height: 1.56;
  }

  .dialogue {
    margin-top: 17px;
  }

  .choice-area {
    margin-top: 24px;
  }
}

@media (max-width: 430px) {
  .app-shell {
    width: 100%;
  }

  .topbar {
    gap: 8px;
  }

  .star-counter {
    min-width: 70px;
    padding: 9px 11px;
  }

  .brand-button {
    gap: 8px;
  }

  .brand-button small {
    display: none;
  }

  .story-panel {
    padding-right: 18px;
    padding-left: 18px;
  }

  .choice {
    min-height: 55px;
    padding: 14px 16px;
  }

  .audio-controls {
    gap: 8px;
  }

  .audio-toggle {
    width: 46px;
    height: 46px;
  }
}

@media (max-width: 360px) {
  .device-note {
    display: none;
  }
}

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