*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  --ink: #030712;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --gold: #fbbd23;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.stage {
  position: fixed;
  inset: 0;
}

.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Top bar */

.top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(var(--safe-top) + 10px) 14px 0;
  z-index: 3;
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

.playing .top {
  opacity: 1;
  pointer-events: auto;
}

.progress {
  display: flex;
  gap: 4px;
}

.segment {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: rgba(241, 245, 249, 0.22);
  overflow: hidden;
}

.segment span {
  display: block;
  height: 100%;
  background: var(--text);
  transform-origin: left center;
  transform: scaleX(0);
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.brand img {
  display: block;
  border-radius: 8px;
}

.spacer {
  flex: 1;
}

.icon, .pill {
  height: 36px;
  border: 1px solid rgba(241, 245, 249, 0.18);
  background: rgba(3, 7, 18, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.icon {
  width: 36px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.icon .off, .icon[aria-pressed="false"] .on {
  display: none;
}

.icon[aria-pressed="false"] .off {
  display: block;
}

.pill {
  padding: 0 16px;
  border-radius: 18px;
  font-size: 14px;
  font-weight: 500;
}

/* Chapter card */

.card {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: 72px 24px calc(var(--safe-bottom) + 28px);
  background: linear-gradient(to bottom, rgba(3, 7, 18, 0) 0%, rgba(3, 7, 18, 0.78) 38%, rgba(3, 7, 18, 0.94) 100%);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.45s ease, transform 0.45s ease;
  pointer-events: none;
}

.playing .card.shown {
  opacity: 1;
  transform: none;
}

.era {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.title {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 600;
  line-height: 1.1;
}

.body {
  margin: 0;
  max-width: 34em;
  color: #cbd5e1;
  font-size: 15px;
  line-height: 1.55;
}

.outro {
  display: none;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
  pointer-events: auto;
}

.final .outro {
  display: flex;
}

.final #skip {
  visibility: hidden;
}

.cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  padding: 0 28px;
  border: 0;
  border-radius: 24px;
  background: var(--gold);
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
}

.ghost {
  height: 48px;
  padding: 0 22px;
  border: 1px solid rgba(241, 245, 249, 0.3);
  border-radius: 24px;
  background: transparent;
  font-size: 15px;
  font-weight: 500;
}

.in-app-note {
  display: none;
  flex-basis: 100%;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.in-app .brand, .in-app #play {
  display: none;
}

.in-app .in-app-note {
  display: block;
}

/* Intro */

.intro {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 24px 28px calc(var(--safe-bottom) + 56px);
  text-align: center;
  background: linear-gradient(to bottom, rgba(3, 7, 18, 0) 30%, rgba(3, 7, 18, 0.9) 75%);
  transition: opacity 0.7s ease;
}

.playing .intro {
  opacity: 0;
  pointer-events: none;
}

.kicker {
  margin: 0 0 12px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.intro-title {
  margin: 0 0 14px;
  font-family: var(--serif);
  font-size: 44px;
  font-weight: 600;
  line-height: 1.05;
}

.intro-body {
  max-width: 28em;
  margin: 0 0 28px;
  color: #cbd5e1;
  font-size: 16px;
  line-height: 1.55;
}

.hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* No WebGL: paint each era as a gradient instead of a scene */

.flat .stage {
  transition: background 1.2s ease;
  background: radial-gradient(120% 80% at 50% 30%, var(--flat-a, #1e293b) 0%, var(--flat-b, #030712) 70%);
}

@media (min-width: 900px) and (min-aspect-ratio: 1/1) {
  .card {
    right: auto;
    width: min(620px, 50vw);
    padding: 120px 48px 48px;
    background: linear-gradient(to right, rgba(3, 7, 18, 0.9) 0%, rgba(3, 7, 18, 0.6) 70%, rgba(3, 7, 18, 0) 100%);
  }

  .title {
    font-size: 52px;
  }

  .body {
    font-size: 17px;
  }

  .intro-title {
    font-size: 68px;
  }

  .intro {
    justify-content: center;
    background: radial-gradient(60% 60% at 50% 55%, rgba(3, 7, 18, 0.7) 0%, rgba(3, 7, 18, 0.2) 100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .card, .intro, .top {
    transition: none;
  }
}
