:root {
  --bg: #0a0a0a;
  --fg: #f4f2ee;
  --muted: rgba(244, 242, 238, 0.56);
  --line: rgba(244, 242, 238, 0.14);
  --card-w: 240px;
  --card-h: 320px;
  --radius: 14px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --stage-bg: radial-gradient(120% 90% at 50% 45%, #1b1b1b 0%, #0e0e0e 45%, #070707 100%);
  --surface: rgba(255, 255, 255, 0.06);
  --surface-hover: rgba(255, 255, 255, 0.12);
  --line-hover: rgba(244, 242, 238, 0.3);
  --chip-bg: #000;
  --title-shadow: 0 2px 24px rgba(0, 0, 0, 0.6);
  --card-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.75);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #efece6;
  --fg: #151515;
  --muted: rgba(21, 21, 21, 0.56);
  --line: rgba(21, 21, 21, 0.14);
  --stage-bg: radial-gradient(120% 90% at 50% 45%, #ffffff 0%, #f3f1ec 45%, #e2ded6 100%);
  --surface: rgba(255, 255, 255, 0.55);
  --surface-hover: rgba(255, 255, 255, 0.9);
  --line-hover: rgba(21, 21, 21, 0.3);
  --chip-bg: #fff;
  --title-shadow: none;
  --card-shadow: 0 18px 40px -14px rgba(40, 32, 20, 0.35);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Inter Tight", ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

/* The page scroll drives the whole sequence; the stage stays pinned. */
.scroller {
  position: relative;
  height: 650vh;
}

.stage {
  position: sticky;
  top: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--stage-bg);
  color: var(--fg);
  transition: color 400ms ease;
  perspective: 1600px;
  perspective-origin: 50% 48%;
  user-select: none;
  -webkit-user-select: none;
}

/* Subtle film grain so the black never looks flat. */
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.06;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  mix-blend-mode: overlay;
}

/* ---------- Title ---------- */

.title {
  position: absolute;
  left: 50%;
  top: 50%;
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 0.35em;
  white-space: nowrap;
  font-weight: 500;
  font-size: clamp(22px, 3.1vw, 44px);
  letter-spacing: -0.02em;
  transform: translate(-50%, -50%);
  opacity: 0;
  z-index: 3;
  pointer-events: none;
  text-shadow: var(--title-shadow);
  transition:
    opacity 900ms var(--ease),
    top 1200ms var(--ease),
    font-size 1200ms var(--ease);
}

.title__kicker {
  text-transform: uppercase;
  letter-spacing: -0.01em;
}

.title__dash {
  color: var(--muted);
}

.stage:not([data-phase="loading"]) .title {
  opacity: 1;
}

.is-gathering .title {
  top: clamp(56px, 11vh, 110px);
  font-size: clamp(18px, 2vw, 28px);
}

/* ---------- 3D scene ---------- */

.scene {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  z-index: 2;
  outline: none;
  touch-action: pan-y;
}

[data-phase="carousel"] .scene {
  cursor: grab;
}

[data-phase="carousel"] .scene.is-dragging {
  cursor: grabbing;
}

.ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}

.card {
  position: absolute;
  left: calc(var(--card-w) / -2);
  top: calc(var(--card-h) / -2);
  width: var(--card-w);
  height: var(--card-h);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: inherit;
  will-change: transform, opacity;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-origin: 50% 50%;
  cursor: inherit;
}

.card__face,
.card__reflect {
  position: absolute;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  pointer-events: none;
}

.card__face {
  top: 0;
  background: #1a1a1a;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    var(--card-shadow);
}

.card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* Depth shading for cards buried in the stack. */
.card__face::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #050505;
  opacity: var(--shade, 0);
}

/* Light streak on the angled side cards of the carousel. */
.card__face::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(
    100deg,
    transparent 20%,
    rgba(255, 255, 255, 0.5) 46%,
    rgba(255, 255, 255, 0.08) 56%,
    transparent 72%
  );
  background-size: 260% 100%;
  background-position: var(--sx, 50%) 0;
  mix-blend-mode: soft-light;
  opacity: var(--sheen, 0);
}

/* Mirrored copy below the card, fading into the floor. */
.card__reflect {
  top: calc(100% + 8px);
  transform: scaleY(-1);
  opacity: calc(var(--reflect, 0) * 0.32);
  -webkit-mask-image: linear-gradient(to top, rgba(0, 0, 0, 0.85), transparent 42%);
  mask-image: linear-gradient(to top, rgba(0, 0, 0, 0.85), transparent 42%);
}

.card:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 4px;
}

/* ---------- Caption + controls ---------- */

.caption {
  position: absolute;
  left: 50%;
  bottom: clamp(92px, 14vh, 150px);
  transform: translate(-50%, 12px);
  display: flex;
  align-items: baseline;
  gap: 14px;
  white-space: nowrap;
  font-size: 15px;
  opacity: 0;
  z-index: 3;
  pointer-events: none;
  transition:
    opacity 700ms var(--ease) 600ms,
    transform 700ms var(--ease) 600ms;
}

.caption__index {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.caption__name {
  font-weight: 500;
}

.caption__tag {
  color: var(--muted);
}

.controls {
  position: absolute;
  left: 50%;
  bottom: clamp(28px, 6vh, 64px);
  transform: translate(-50%, 12px);
  display: flex;
  gap: 10px;
  opacity: 0;
  z-index: 3;
  pointer-events: none;
  transition:
    opacity 700ms var(--ease) 800ms,
    transform 700ms var(--ease) 800ms;
}

.is-stacked[data-phase="deck"] .caption,
[data-phase="carousel"] .caption,
[data-phase="carousel"] .controls {
  opacity: 1;
  transform: translate(-50%, 0);
}

[data-phase="carousel"] .controls {
  pointer-events: auto;
}

.btn {
  appearance: none;
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition:
    background 200ms ease,
    border-color 200ms ease,
    opacity 300ms ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.btn:hover {
  background: var(--surface-hover);
  border-color: var(--line-hover);
}

.btn:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 3px;
}

.btn--icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
}

.btn--icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn--ghost {
  height: 36px;
  padding: 0 16px;
  font-size: 13px;
}

/* ---------- Chip + actions ---------- */

.chip {
  position: absolute;
  left: clamp(16px, 2.4vw, 32px);
  bottom: clamp(16px, 3vh, 32px);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 38px;
  padding: 0 16px 0 14px;
  border-radius: 999px;
  background: var(--chip-bg);
  border: 1px solid var(--line);
  font-size: 14px;
  z-index: 4;
}

.chip__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ff5a1f;
  box-shadow: 0 0 0 4px rgba(255, 90, 31, 0.18);
}

.actions {
  position: absolute;
  right: clamp(16px, 2.4vw, 32px);
  bottom: clamp(16px, 3vh, 32px);
  display: flex;
  gap: 8px;
  z-index: 4;
}

#replay {
  display: none;
}

[data-phase="carousel"] #replay {
  display: inline-block;
}

/* Theme switch: shows the mode it switches to. */
.btn--theme {
  width: 36px;
  height: 36px;
}

.btn--theme svg {
  width: 16px;
  height: 16px;
}

.btn--theme .icon-moon,
:root[data-theme="light"] .btn--theme .icon-sun {
  display: none;
}

:root[data-theme="light"] .btn--theme .icon-moon {
  display: block;
}

.loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--muted);
  z-index: 5;
  transition: opacity 500ms ease;
  pointer-events: none;
}

.stage:not([data-phase="loading"]) .loader {
  opacity: 0;
}

/* Scroll cue, only before the first scroll. */
.hint {
  position: absolute;
  left: 50%;
  bottom: clamp(24px, 5vh, 48px);
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 10px;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  z-index: 3;
  pointer-events: none;
  transition: opacity 500ms ease;
}

.hint i {
  width: 1px;
  height: 36px;
  background: linear-gradient(to bottom, var(--fg), transparent);
  transform-origin: top;
  animation: hint 1.8s var(--ease) infinite;
}

@keyframes hint {
  0% { transform: scaleY(0); opacity: 1; }
  70% { transform: scaleY(1); opacity: 1; }
  100% { transform: scaleY(1); opacity: 0; }
}

.stage[data-phase="loading"] .hint,
.stage.has-scrolled .hint {
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .hint i {
    animation: none;
  }
}

@media (max-width: 640px) {
  .caption {
    font-size: 13px;
    gap: 10px;
  }

  .caption__tag {
    display: none;
  }

  .chip {
    font-size: 12px;
    height: 32px;
  }

  .actions {
    bottom: clamp(16px, 3vh, 32px);
  }

  .controls {
    bottom: clamp(64px, 10vh, 96px);
  }

  .caption {
    bottom: clamp(128px, 19vh, 170px);
  }
}
