/* ─── theme tokens ───────────────────────────────────────────── */

:root {
  --transition: 1200ms cubic-bezier(0.65, 0, 0.35, 1);
}

body[data-theme="midnight"] {
  --bg-from: #0a0e27;
  --bg-to:   #1b1f4a;
  --fg:      #ffffff;
  --accent:  #636BFC;
  --display: "DM Serif Display", serif;
  --body:    "DM Sans", sans-serif;
}

body[data-theme="rose"] {
  --bg-from: #FF3F7B;
  --bg-to:   #FF6E5B;
  --fg:      #ffffff;
  --accent:  #33405E;
  --display: "DM Serif Display", serif;
  --body:    "DM Sans", sans-serif;
}

body[data-theme="cream"] {
  --bg-from: #f7f1e3;
  --bg-to:   #ecd9c0;
  --fg:      #33405E;
  --accent:  #FF3F7B;
  --display: "DM Serif Display", serif;
  --body:    "DM Sans", sans-serif;
}

body[data-theme="electric"] {
  --bg-from: #050514;
  --bg-to:   #1a0033;
  --fg:      #00ff9f;
  --accent:  #00ff9f;
  --display: "Space Mono", monospace;
  --body:    "Space Mono", monospace;
}

body[data-theme="ocean"] {
  --bg-from: #002B5B;
  --bg-to:   #1A5F7A;
  --fg:      #FFD93D;
  --accent:  #FFD93D;
  --display: "DM Serif Display", serif;
  --body:    "DM Sans", sans-serif;
}

/* ─── base ───────────────────────────────────────────────────── */

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
body {
  color: var(--fg);
  font-family: var(--body);
  background: var(--bg-from);
  transition: background var(--transition);
  cursor: default;
}

#bg-layer {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 30% 20%, var(--accent) 0%, transparent 55%),
    linear-gradient(135deg, var(--bg-from) 0%, var(--bg-to) 100%);
  opacity: 0.95;
  transition: background var(--transition);
  z-index: 0;
}

#noise-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.08;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.6'/></svg>");
}

/* ─── stage ──────────────────────────────────────────────────── */

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 8vh 6vw;
  z-index: 2;
}

#scene {
  max-width: 1100px;
  width: 100%;
  text-align: left;
}

#caption {
  font-family: var(--body);
  font-weight: 500;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  opacity: 0.55;
  margin-bottom: 1.5rem;
  transform: translateY(8px);
  transition: opacity 700ms ease, transform 700ms ease;
  opacity: 0;
}

#message {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.2rem, 7.5vw, 6.4rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin-bottom: 3rem;
  opacity: 0;
  transform: translateY(28px);
  transition: opacity 900ms ease, transform 900ms ease;
}

#response {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.75rem 1rem;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 800ms ease 200ms, transform 800ms ease 200ms;

  /* Reserve vertical space so the message above doesn't reflow upward when
     the input/buttons fade in. The reserved height covers the tallest
     affordance (text input + hint, ~6.5rem) plus a small buffer. */
  min-height: 7rem;
}

/* Children of #response (buttons, inputs, hints) are inserted into the DOM
   long after the container has finished its own fade-in. Give each child its
   own enter animation so they don't pop in. The stagger makes a 2-line input
   (field + hint) feel like a single smooth gesture. */
@keyframes response-child-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#response > * {
  animation: response-child-in 600ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

#response > *:nth-child(2) { animation-delay: 90ms; }
#response > *:nth-child(3) { animation-delay: 180ms; }
#response > *:nth-child(4) { animation-delay: 270ms; }
#response > *:nth-child(5) { animation-delay: 360ms; }

/* visible state, applied after content is set */
body[data-state="ready"] #caption,
body[data-state="ready"] #message,
body[data-state="ready"] #response {
  opacity: 1;
  transform: translateY(0);
}
body[data-state="ready"] #caption { opacity: 0.55; }

/* ─── input affordances ──────────────────────────────────────── */

.choice {
  font-family: var(--body);
  font-size: clamp(1rem, 1.5vw, 1.15rem);
  font-weight: 500;
  padding: 1.1rem 2rem;
  border: 2px solid currentColor;
  background: transparent;
  color: var(--fg);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 200ms ease, background 200ms ease, color 200ms ease, box-shadow 200ms ease;
  position: relative;
  letter-spacing: -0.01em;
}

.choice:hover {
  transform: translateY(-3px);
  background: var(--fg);
  color: var(--bg-from);
  box-shadow: 0 8px 30px -8px var(--accent);
}

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

.text-input {
  width: 100%;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(1.4rem, 3vw, 2.4rem);
  padding: 0.5rem 0;
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--fg);
  color: var(--fg);
  outline: none;
  caret-color: var(--accent);
  letter-spacing: -0.01em;
}

.text-input::placeholder {
  color: var(--fg);
  opacity: 0.35;
  font-style: italic;
}

.text-hint {
  width: 100%;
  margin-top: 0.75rem;
  font-family: var(--body);
  font-size: 0.85rem;
  opacity: 0.5;
  letter-spacing: 0.05em;
}

.choice.continue {
  border: 1px solid currentColor;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.7rem 1.5rem;
  letter-spacing: 0.05em;
  opacity: 0.55;
  transition: opacity 200ms ease, transform 200ms ease, background 200ms ease, color 200ms ease;
}

.choice.continue:hover {
  opacity: 1;
  transform: translateY(-2px);
  background: var(--fg);
  color: var(--bg-from);
}

.choice.continue .arrow {
  display: inline-block;
  margin-left: 0.5rem;
  animation: pulseArrow 1.8s ease-in-out infinite;
}

@keyframes pulseArrow {
  0%, 100% { transform: translateY(0); opacity: 0.6; }
  50%      { transform: translateY(4px); opacity: 1; }
}

/* ─── chrome ─────────────────────────────────────────────────── */

#chrome {
  position: fixed;
  bottom: 1.5rem;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2rem;
  font-family: var(--body);
  font-size: 0.75rem;
  opacity: 0.4;
  pointer-events: none;
  transition: opacity 300ms ease, color var(--transition);
  color: var(--fg);
}

#chrome:hover { opacity: 0.85; }

#chrome a, #chrome code, #chrome span {
  pointer-events: auto;
}

#chrome a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}

#chrome code {
  font-family: "Space Mono", monospace;
}

/* ─── boot loader ────────────────────────────────────────────── */

#boot {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  background: var(--bg-from);
  transition: opacity 800ms ease;
}

#boot::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 30% 20%, var(--accent) 0%, transparent 55%),
    linear-gradient(135deg, var(--bg-from) 0%, var(--bg-to) 100%);
  opacity: 0.95;
}

#boot > .dot {
  position: relative;
  width: 12px;
  height: 12px;
  margin: 0 6px;
  border-radius: 50%;
  background: var(--fg);
  animation: pulse 1.4s infinite ease-in-out both;
}

#boot > .dot:nth-child(1) { animation-delay: -0.32s; }
#boot > .dot:nth-child(2) { animation-delay: -0.16s; }

body:not([data-state="loading"]) #boot {
  opacity: 0;
  pointer-events: none;
}

@keyframes pulse {
  0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
  40%           { transform: scale(1); opacity: 1; }
}

/* ─── error scene ────────────────────────────────────────────── */

body[data-state="error"] #scene {
  text-align: center;
}

body[data-state="error"] #caption,
body[data-state="error"] #message,
body[data-state="error"] #response {
  opacity: 1;
  transform: translateY(0);
}

body[data-state="error"] #caption { opacity: 0.55; }
