@font-face {
  font-family: "Unbounded";
  src: url("fonts/unbounded-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("fonts/instrument-sans-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("fonts/instrument-sans-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #070a24;
  --paper: #f5f7ff;
  --spark: #ffc94d;
  --font-display: "Unbounded", "Arial Black", system-ui, sans-serif;
  --font-text: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --pad: clamp(20px, 5vw, 72px);
  --top: calc(env(safe-area-inset-top, 0px) + clamp(22px, 7vh, 84px));
}

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

html, body { height: 100%; margin: 0; }

body {
  background: linear-gradient(#0b1040, #5a2f86 62%, #ff8a5c);
  color: var(--paper);
  font-family: var(--font-text);
  font-size: 16px;
  line-height: 1.45;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

p, h1, h2, dl, dd, dt { margin: 0; }

/* Spielfläche */
#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 1.4s ease;
}
#scene.ready { opacity: 1; }

/* Lesbarkeit der Schrift über jeder Tageszeit */
.scrim {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(5, 7, 30, 0.3) 0%, rgba(5, 7, 30, 0.12) 36%, rgba(5, 7, 30, 0) 56%),
    linear-gradient(0deg, rgba(5, 7, 30, 0.5) 0%, rgba(5, 7, 30, 0) 30%),
    radial-gradient(120% 90% at 50% 45%, transparent 60%, rgba(3, 4, 20, 0.3) 100%);
  transition: opacity 0.6s ease;
}
body:not([data-state="attract"]) .scrim { opacity: 0.55; }

.veil {
  position: fixed;
  inset: 0;
  z-index: 5;
  background: var(--ink);
  opacity: 0;
  pointer-events: none;
}
.veil.flash { animation: veil 0.45s ease-out; }
@keyframes veil {
  0% { opacity: 0; }
  35% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* Titel */
.title {
  position: fixed;
  z-index: 2;
  left: var(--pad);
  top: var(--top);
  max-width: min(40rem, calc(100vw - 2 * var(--pad)));
  transition: opacity 0.5s ease, transform 0.5s ease;
}
body:not([data-state="attract"]) .title {
  opacity: 0;
  transform: translateY(-14px);
  pointer-events: none;
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(3.4rem, 14vw, 9.25rem);
  line-height: 0.9;
  letter-spacing: -0.045em;
  text-shadow: 0 4px 60px rgba(5, 7, 30, 0.45);
}
.wordmark span {
  color: var(--spark);
  font-size: 0.4em;
  letter-spacing: -0.02em;
  margin-left: 0.08em;
}

.keys { text-shadow: 0 1px 2px rgba(5, 7, 30, 0.55), 0 0 22px rgba(5, 7, 30, 0.5); }

.cta {
  margin-top: 1.8rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.9rem 1.1rem;
}
.keys { font-size: 0.92rem; opacity: 0.85; }
.fine {
  position: fixed;
  z-index: 2;
  left: var(--pad);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  max-width: min(34rem, calc(100vw - 2 * var(--pad) - 11rem));
  font-size: 0.86rem;
  opacity: 0.78;
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.fine p + p { margin-top: 0.1rem; opacity: 0.85; }
body:not([data-state="attract"]) .fine { opacity: 0; transform: translateY(10px); pointer-events: none; }

/* Impressum und Datenschutz bleiben auf jeder Ansicht erreichbar */
.legal {
  position: fixed;
  z-index: 3;
  right: max(var(--pad), env(safe-area-inset-right, 0px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  display: flex;
  font-size: 0.82rem;
  text-shadow: 0 1px 8px rgba(5, 7, 30, 0.7);
  transition: opacity 0.4s ease;
}
.legal a {
  padding: 0.85rem 0.65rem;
  color: inherit;
  opacity: 0.75;
  text-decoration: none;
  border-radius: 8px;
}
.legal a:hover { opacity: 1; text-decoration: underline; text-underline-offset: 3px; }
.legal a:focus-visible { opacity: 1; outline: 2px solid var(--paper); }
body[data-state="play"] .legal { opacity: 0.6; }

.btn {
  position: relative;
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 1.05em 2em;
  min-height: 48px;
  background: var(--spark);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  box-shadow: 0 10px 30px rgba(255, 201, 77, 0.28);
}
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 0 0 rgba(255, 201, 77, 0.55);
  animation: ping 2.6s ease-out 1.6s infinite;
  pointer-events: none;
}
@keyframes ping {
  0% { box-shadow: 0 0 0 0 rgba(255, 201, 77, 0.55); }
  70%, 100% { box-shadow: 0 0 0 18px rgba(255, 201, 77, 0); }
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 14px 36px rgba(255, 201, 77, 0.38); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--paper); outline-offset: 4px; }

/* Anzeige im Spiel */
.hud {
  position: fixed;
  z-index: 2;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) max(var(--pad), env(safe-area-inset-right, 0px)) 0 max(var(--pad), env(safe-area-inset-left, 0px));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}
body[data-state="play"] .hud,
body[data-state="dead"] .hud { opacity: 1; }
.hud-right { display: flex; align-items: center; gap: 1rem; }

.dist {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 5vw, 2.7rem);
  line-height: 1;
  text-shadow: 0 2px 22px rgba(5, 7, 30, 0.55);
}
.dist small { margin-left: 0.3em; font-size: 0.42em; opacity: 0.8; }
.clock {
  margin-top: 0.55rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 10px rgba(5, 7, 30, 0.6);
  opacity: 0.9;
}
.clock .dot { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: 0.7; }

.sparks {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  text-shadow: 0 2px 16px rgba(5, 7, 30, 0.55);
}
.spark-icon {
  width: 0.7em;
  height: 0.7em;
  background: var(--spark);
  transform: rotate(45deg);
  border-radius: 2px;
  box-shadow: 0 0 14px 2px rgba(255, 201, 77, 0.7);
}
.sparks.pop { animation: pop 0.28s ease-out; }
@keyframes pop { 40% { transform: scale(1.18); } }

.icon-btn {
  pointer-events: auto;
  appearance: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(7, 10, 36, 0.4);
  color: var(--paper);
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  touch-action: manipulation;
}
.icon-btn .waves, .icon-btn .slash { display: none; }
.icon-btn[aria-pressed="true"] .waves { display: block; }
.icon-btn[aria-pressed="false"] .slash { display: block; }

/* Ende der Runde */
.over {
  position: fixed;
  z-index: 2;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  padding: 0 var(--pad);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.over::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(closest-side, rgba(5, 7, 30, 0.6), rgba(5, 7, 30, 0) 100%);
}
body[data-state="dead"] .over { opacity: 1; pointer-events: auto; transition-delay: 0.45s; }
.over h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.9rem, 6vw, 3.2rem);
  letter-spacing: -0.03em;
  line-height: 1;
}
.record {
  margin-top: 0.8rem;
  padding: 0.3em 0.9em;
  border-radius: 999px;
  background: rgba(255, 201, 77, 0.16);
  color: var(--spark);
  font-weight: 600;
  font-size: 0.9rem;
}
.stats {
  margin-top: 1.6rem;
  display: flex;
  gap: clamp(1.4rem, 5vw, 3rem);
}
.stats dt { font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.75; }
.stats dd {
  margin-top: 0.3rem;
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 3.6vw, 1.8rem);
  font-variant-numeric: tabular-nums;
}
.over .cta { justify-content: center; margin-top: 2rem; }

/* Titel erscheint nacheinander, das ist der einzige inszenierte Moment */
@media (prefers-reduced-motion: no-preference) {
  .title > * { animation: rise 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
  .title > :nth-child(2) { animation-delay: 0.2s; }
  .fine p { animation: rise 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) 0.6s both; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); filter: blur(6px); }
  to { opacity: 1; transform: none; filter: none; }
}

@media (prefers-reduced-motion: reduce) {
  #scene { transition: none; }
  .btn::after, .veil.flash, .sparks.pop { animation: none; }
  .title, .hud, .over, .scrim { transition-duration: 0.01s; }
}

/* Schmale Bildschirme */
@media (max-width: 560px) {
  .cta { margin-top: 1.3rem; }
  .keys { display: none; }
  .legal { left: max(calc(var(--pad) - 0.65rem), env(safe-area-inset-left, 0px)); right: auto; bottom: calc(env(safe-area-inset-bottom, 0px) + 2px); }
  .fine { max-width: calc(100vw - 2 * var(--pad)); bottom: calc(env(safe-area-inset-bottom, 0px) + 58px); }
}

/* Niedrige Fenster, zum Beispiel Handy quer */
@media (max-height: 520px) {
  :root { --top: calc(env(safe-area-inset-top, 0px) + 14px); }
  .wordmark { font-size: clamp(2.4rem, 9vw, 4.5rem); }
  .fine { display: none; }
  .cta { margin-top: 0.9rem; }
}

/* Ohne WebGL bleibt eine ruhige Seite mit Verlauf stehen */
.no-webgl #scene, .no-webgl .hud, .no-webgl .btn, .no-webgl .keys, .no-webgl .fine { display: none; }
