/* Grundgerüst: Farben, Schriften, Bühne, Bedienleiste, Startschirm.
   Szenen bringen ihr eigenes CSS mit und greifen auf die Variablen hier zu. */

@font-face {
  font-family: 'Unbounded';
  src: url('../fonts/unbounded.woff2') format('woff2');
  font-weight: 200 900;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('../fonts/jetbrains-mono.woff2') format('woff2');
  font-weight: 100 800;
  font-display: swap;
}

@property --spin {
  syntax: '<angle>';
  inherits: false;
  initial-value: 0deg;
}

:root {
  --bg: #05010d;
  --ink: #f5f0ff;
  --dim: #a79dbd;
  --pink: #ff0080;
  --green: #00ff80;
  --violet: #8000ff;
  --orange: #ff8000;
  --cyan: #00e5ff;
  --yellow: #ffe600;

  --font-display: 'Unbounded', 'Arial Black', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  /* Platz, den die Bedienleiste oben und unten belegt. Szenen halten ihn frei. */
  --hud-top: 68px;
  --hud-bottom: 92px;
  --pad: clamp(16px, 3vw, 40px);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: linear(0, 0.009, 0.035 2.1%, 0.141 4.4%, 0.723 12.9%, 0.938 16.7%, 1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%, 1.129 32.8%, 1.051 39.6%, 1.017 43.1%, 0.991, 0.977 51%, 0.974 53.8%, 0.975 57.1%, 0.997 69.8%, 1.003 76.9%, 1);

  color-scheme: dark;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

::selection { background: var(--pink); color: #fff; }

button { font: inherit; color: inherit; }

/* Touch: kein Doppeltipp-Zoom auf Knöpfen, kein Markieren oder Kontextmenü bei langem Druck. */
button, .btn, .chip, .caption, #hud {
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

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

/* ───────────── Bühne und Szenen ───────────── */

#stage {
  position: fixed;
  inset: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scroll-snap-type: y proximity;
  scroll-behavior: smooth;
  scrollbar-width: none;
  outline: none;
  translate: var(--shake-x, 0px) var(--shake-y, 0px);
}
#stage::-webkit-scrollbar { display: none; }
body[data-phase='boot'] #stage { overflow: hidden; }

.scene {
  --screens: 1;
  --progress: 0;
  position: relative;
  height: calc(var(--screens) * 100dvh);
  scroll-snap-align: start;
  view-timeline: --scene block;
}

/* Hier hinein baut die Szene. Bleibt bei mehrseitigen Szenen am Bildschirm kleben. */
.scene__stage {
  position: sticky;
  top: 0;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  isolation: isolate;
  contain: layout paint;
}

.scene__stage > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.scene__stage[data-state='loading']::after,
.scene__stage[data-state='failed']::after {
  content: 'Lädt';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
  pointer-events: none;
}
.scene__stage[data-state='failed']::after {
  content: 'Diese Szene macht gerade Pause';
}

/* ───────────── Gemeinsame Bausteine für Szenen ───────────── */

/* Beschriftung einer Szene: unten links, über dem Weiter-Knopf. */
.caption {
  position: absolute;
  left: var(--pad);
  right: var(--pad);
  bottom: calc(var(--hud-bottom) + 8px);
  max-width: 44rem;
  z-index: 5;
  pointer-events: none;
  text-shadow: 0 2px 24px rgba(5, 1, 13, 0.85);
}
.caption > * { pointer-events: auto; }

.kicker {
  margin: 0 0 0.6em;
  font-family: var(--font-mono);
  font-size: clamp(11px, 1.1vw, 13px);
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--green);
}

.headline {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.6rem, 4.2vw, 3.6rem);
  line-height: 1.02;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.hint {
  margin: 0.9em 0 0;
  font-family: var(--font-mono);
  font-size: clamp(12px, 1.2vw, 14px);
  line-height: 1.5;
  color: var(--dim);
  text-wrap: pretty;
}

.kbd {
  display: inline-block;
  padding: 0.1em 0.5em;
  border: 1px solid rgba(245, 240, 255, 0.28);
  border-bottom-width: 2px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--ink);
  background: rgba(245, 240, 255, 0.06);
}

.btn {
  --btn: var(--pink);
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.8em 1.4em;
  border: 0;
  border-radius: 999px;
  background: var(--btn);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(13px, 1.3vw, 15px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 0 0 0 color-mix(in oklab, var(--btn) 60%, transparent), 0 10px 40px -10px var(--btn);
  transition: transform 0.25s var(--ease-spring), box-shadow 0.25s, opacity 0.25s;
}
.btn:hover { transform: scale(1.05); box-shadow: 0 0 0 6px color-mix(in oklab, var(--btn) 28%, transparent), 0 14px 50px -8px var(--btn); }
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.45; cursor: progress; transform: none; }
.btn--ghost {
  background: rgba(245, 240, 255, 0.07);
  box-shadow: inset 0 0 0 1px rgba(245, 240, 255, 0.25);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.btn--ghost:hover { box-shadow: inset 0 0 0 1px rgba(245, 240, 255, 0.6); }
.btn--big { padding: 1.05em 2.2em; font-size: clamp(15px, 1.6vw, 19px); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.35em 0.8em;
  border-radius: 999px;
  background: rgba(245, 240, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(245, 240, 255, 0.16);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
}

/* ───────────── Bedienleiste ───────────── */

#hud {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  transition: opacity 0.6s;
}
#hud > * { pointer-events: auto; }
body[data-phase='boot'] #hud { opacity: 0; visibility: hidden; }
/* Szenen, die den ganzen Schirm brauchen (z. B. das Spiel), blenden die Leiste ab. */
/* Dann ist sie auch nicht klickbar, damit beim Spielen niemand versehentlich die Szene wechselt.
   Pause (Esc oder der Pause-Knopf der Szene) holt sie zurück. */
body[data-hud='quiet'] #hud { opacity: 0.18; }
body[data-hud='quiet'] #hud > * { pointer-events: none; }

.hud__brand {
  position: absolute;
  top: 0;
  left: var(--pad);
  height: var(--hud-top);
  display: flex;
  align-items: center;
  gap: 0.5em;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 15px;
  letter-spacing: 0.14em;
  pointer-events: none !important;
  mix-blend-mode: difference;
}
.hud__brand span { font-weight: 300; color: var(--green); }

.hud__tools {
  position: absolute;
  top: 0;
  right: var(--pad);
  height: var(--hud-top);
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-btn {
  padding: 0.55em 0.95em;
  border: 0;
  border-radius: 999px;
  background: rgba(10, 4, 22, 0.55);
  box-shadow: inset 0 0 0 1px rgba(245, 240, 255, 0.16);
  backdrop-filter: blur(12px) saturate(1.4);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  white-space: nowrap;
  cursor: pointer;
  transition: box-shadow 0.2s, background 0.2s, transform 0.2s var(--ease-spring);
}
.hud-btn:hover { box-shadow: inset 0 0 0 1px var(--green); transform: translateY(-1px); }
.hud-btn[aria-pressed='false'] { color: var(--dim); }

.hud__nav {
  position: absolute;
  right: var(--pad);
  top: 50%;
  translate: 0 -50%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.hud__nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  border: 0;
  background: none;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  cursor: pointer;
}
.hud__nav button span {
  opacity: 0;
  translate: 8px 0;
  transition: opacity 0.25s, translate 0.25s var(--ease-out);
  text-shadow: 0 1px 12px #000;
}
.hud__nav button::after {
  content: '';
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.55;
  transition: width 0.3s var(--ease-spring), opacity 0.2s, background 0.2s;
}
.hud__nav:hover button span,
.hud__nav button:focus-visible span,
.hud__nav button.is-active span { opacity: 1; translate: 0 0; }
.hud__nav button.is-active { color: var(--ink); }
.hud__nav button.is-active::after { width: 34px; opacity: 1; background: var(--pink); box-shadow: 0 0 12px var(--pink); }

.hud__next {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  translate: -50% 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0.7em 1.2em 0.7em 1.4em;
  border: 0;
  border-radius: 999px;
  background: rgba(10, 4, 22, 0.55);
  box-shadow: inset 0 0 0 1px rgba(245, 240, 255, 0.2);
  backdrop-filter: blur(12px) saturate(1.4);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.25s var(--ease-spring);
}
.hud__next:hover { box-shadow: inset 0 0 0 1px var(--pink), 0 0 30px -6px var(--pink); transform: translateY(-2px); }
.hud__next svg { animation: nudge 1.8s var(--ease-out) infinite; }
.hud__next.is-last svg { rotate: 180deg; }
@keyframes nudge { 0%, 100% { translate: 0 -2px; } 50% { translate: 0 3px; } }

.hud__fps {
  position: absolute;
  left: var(--pad);
  bottom: 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--green);
  white-space: pre;
  pointer-events: none !important;
}

/* ───────────── Meldungen ───────────── */

#toasts {
  position: fixed;
  left: 50%;
  top: calc(var(--hud-top) + 4px);
  translate: -50% 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.7em;
  padding: 0.7em 1.1em;
  border-radius: 14px;
  background: rgba(10, 4, 22, 0.8);
  box-shadow: inset 0 0 0 1px rgba(245, 240, 255, 0.18), 0 12px 40px -12px #000;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  max-width: min(90vw, 34rem);
  transition: opacity 0.35s, translate 0.5s var(--ease-spring), scale 0.5s var(--ease-spring);
}
@starting-style {
  .toast { opacity: 0; translate: 0 -16px; scale: 0.9; }
}
.toast.is-out { opacity: 0; translate: 0 -10px; scale: 0.96; }
.toast__icon { font-size: 1.3em; }

/* ───────────── Startschirm ───────────── */

#gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: var(--pad);
  background: var(--bg);
  overflow: hidden;
  transition: opacity 0.9s var(--ease-out), scale 0.9s var(--ease-out), filter 0.9s, visibility 0s 0.9s;
}
body[data-phase='live'] #gate {
  opacity: 0;
  scale: 1.25;
  filter: blur(24px);
  visibility: hidden;
  pointer-events: none;
}

.gate__aurora {
  position: absolute;
  inset: -30%;
  background:
    conic-gradient(from var(--spin) at 50% 50%,
      transparent 0deg, var(--pink) 60deg, transparent 120deg,
      var(--violet) 180deg, transparent 240deg, var(--green) 300deg, transparent 360deg);
  filter: blur(90px) saturate(1.3);
  opacity: 0.38;
  animation: spin 16s linear infinite;
}
@keyframes spin { to { --spin: 360deg; } }

.gate__inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(18px, 3.5vh, 36px);
  text-align: center;
  max-width: 60rem;
}

.gate__term {
  margin: 0;
  padding: 1.1em 1.4em;
  border-radius: 14px;
  background: rgba(5, 1, 13, 0.6);
  box-shadow: inset 0 0 0 1px rgba(245, 240, 255, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-family: var(--font-mono);
  font-size: clamp(11px, 1.25vw, 14px);
  line-height: 1.7;
  text-align: left;
  color: var(--dim);
  white-space: pre-wrap;
}
.gate__term span {
  display: inline-block;
  opacity: 0;
  animation: line-in 0.45s var(--ease-out) forwards;
  animation-delay: calc(var(--i) * 0.32s + 0.15s);
}
.gate__term b { color: var(--pink); }
.gate__term i { font-style: normal; color: var(--dim); }
.gate__term em { font-style: normal; color: var(--green); font-weight: 700; }
#gate-status::after { content: ' …'; animation: blink 1s steps(2) infinite; }
#gate-status.is-ready { color: var(--green); }
#gate-status.is-ready::after { content: ''; }
@keyframes line-in { from { opacity: 0; translate: -10px 0; } to { opacity: 1; translate: 0 0; } }
@keyframes blink { 50% { opacity: 0; } }

.gate__title {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15em;
  font-family: var(--font-display);
  line-height: 0.9;
}
.gate__title small {
  font-size: clamp(0.8rem, 2.2vw, 1.5rem);
  font-weight: 400;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0;
  animation: line-in 0.8s var(--ease-out) 1.2s forwards;
}
.gate__title span {
  font-size: clamp(4.5rem, 24vw, 19rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  text-transform: uppercase;
  background: linear-gradient(100deg, var(--pink), var(--orange) 30%, var(--yellow) 45%, var(--green) 62%, var(--cyan) 78%, var(--violet));
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 40px color-mix(in oklab, var(--pink) 55%, transparent));
  animation: title-in 1.3s var(--ease-spring) 0.5s both, slide-hue 7s linear infinite;
}
@keyframes title-in {
  from { opacity: 0; scale: 0.6; font-weight: 200; letter-spacing: 0.3em; }
  to { opacity: 1; scale: 1; font-weight: 900; letter-spacing: -0.03em; }
}
@keyframes slide-hue { to { background-position: -220% 0; } }

.gate__note {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
}

.gate__old {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--dim);
  text-decoration: underline;
  text-decoration-color: color-mix(in oklab, var(--dim) 45%, transparent);
  text-underline-offset: 4px;
  transition: color 0.2s, text-decoration-color 0.2s;
}
.gate__old:hover { color: var(--green); text-decoration-color: var(--green); }

.noscript {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 200;
  padding: 1em;
  text-align: center;
  background: var(--pink);
  font-family: var(--font-mono);
}

/* ───────────── Klein und ruhig ───────────── */

@media (max-width: 720px) {
  :root { --hud-top: 56px; --hud-bottom: 84px; }
  .hud__brand { font-size: 12px; }
  .hud-btn { padding: 0.5em 0.7em; font-size: 11px; }
  .hud__nav { display: none; }
  #btn-fullscreen { display: none; }
}

/* Niedrige Bildschirme (Handy quer, kleine Fenster): Beschriftung und Leiste kompakt. */
@media (max-height: 520px) {
  :root { --hud-top: 48px; --hud-bottom: 60px; }
  .hud__nav { display: none; }
  .hud__next { bottom: max(10px, env(safe-area-inset-bottom)); padding: 0.5em 1em 0.5em 1.2em; font-size: 11px; }
  .hud-btn { padding: 0.45em 0.75em; font-size: 11px; }
  .caption { max-width: min(26rem, 48vw); bottom: calc(var(--hud-bottom) + 4px); }
  .kicker { margin-bottom: 0.4em; font-size: 10px; }
  .headline { font-size: clamp(1.05rem, 3.2vw, 1.6rem); }
  .hint { display: none; }
  .gate__inner { gap: 10px; }
  .gate__term { display: none; }
  .gate__title span { font-size: clamp(3.5rem, 34vh, 9rem); }
  .gate__note { display: none; }
}

/* Seitliche Ränder am Handy quer (Notch, runde Ecken). */
@supports (padding: max(0px)) {
  :root { --pad: max(clamp(16px, 3vw, 40px), env(safe-area-inset-left), env(safe-area-inset-right)); }
}

/* Hinweis fürs Handy im Querformat: hochkant ist die Seite schöner. Wegklickbar. */
#rotate-hint { display: none; }
@media (orientation: landscape) and (max-height: 520px) and (pointer: coarse) {
  /* Das Spiel ist quer am schönsten, dort kommt der Hinweis nicht. */
  body[data-phase='live']:not([data-rotate='ok']):not([data-scene='game']) #rotate-hint {
    position: fixed;
    inset: 0;
    z-index: 95;
    display: grid;
    place-items: center;
    padding: var(--pad);
    background: rgba(5, 1, 13, 0.86);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    text-align: center;
  }
}
.rotate-hint__inner { display: grid; justify-items: center; gap: 14px; max-width: 28rem; }
.rotate-hint__icon { font-size: 44px; animation: rotate-nudge 2.4s var(--ease-spring) infinite; }
.rotate-hint__title { margin: 0; font-family: var(--font-display); font-weight: 800; font-size: 1.25rem; line-height: 1.1; text-wrap: balance; }
@keyframes rotate-nudge { 0%, 55%, 100% { rotate: 0deg; } 70%, 90% { rotate: -90deg; } }

@media (prefers-reduced-motion: reduce) {
  #stage { scroll-behavior: auto; }
  .gate__aurora, .hud__next svg { animation: none; }
}

@media print {
  #stage, #hud, #gate, #toasts { display: none !important; }
}
