:root {
  --bg: #07080f;
  --text: #f4f3ff;
  --c1: #7c5cff;
  --c2: #00d4c8;
  --c3: #ff5c9a;
}

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

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Feines Rauschen gegen Banding in den Verläufen */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

main {
  position: relative;
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
}

h1 {
  margin: 0;
  font-size: clamp(3rem, 16vw, 12rem);
  font-weight: 800;
  letter-spacing: -0.045em;
  line-height: 1;
  background: linear-gradient(110deg, var(--text) 20%, var(--c2) 40%, var(--c1) 55%, var(--c3) 70%, var(--text) 90%);
  background-size: 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 40px rgba(124, 92, 255, 0.35));
  animation: shimmer 12s ease-in-out infinite alternate, rise 1.6s cubic-bezier(.2, .7, .2, 1) both;
  user-select: none;
  pointer-events: none;
}

@keyframes shimmer {
  from { background-position: 100% 0; }
  to   { background-position: 0% 0; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(24px) scale(0.98); filter: blur(12px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Spiel ---------- */

#game {
  position: fixed;
  inset: 0;
  z-index: 2;
  cursor: crosshair;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.flyer {
  position: absolute;
  top: 0;
  left: 0;
  padding: 0.35em 0.8em;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(20, 22, 40, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 0 18px -4px var(--glow, var(--c1));
  will-change: transform;
  user-select: none;
}

.flyer span {
  display: inline-block;
  animation: pop-in 0.35s cubic-bezier(.2, .9, .3, 1.4) both;
}

.flyer:hover {
  border-color: rgba(255, 255, 255, 0.45);
}

.flyer.hit {
  pointer-events: none;
  animation: poof-box 0.4s ease-out forwards;
}

.flyer.hit span {
  animation: poof 0.4s ease-out forwards;
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.4); }
  to   { opacity: 1; transform: none; }
}

@keyframes poof {
  to { opacity: 0; transform: scale(1.8); filter: blur(6px); }
}

@keyframes poof-box {
  to { opacity: 0; border-color: transparent; box-shadow: 0 0 40px 10px var(--glow, var(--c1)); }
}

.spark {
  position: absolute;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: var(--glow, var(--c2));
  box-shadow: 0 0 8px var(--glow, var(--c2));
  pointer-events: none;
  animation: spark 0.55s cubic-bezier(.1, .7, .3, 1) forwards;
}

@keyframes spark {
  to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.2); }
}

.plus {
  position: absolute;
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--c2);
  text-shadow: 0 0 10px rgba(0, 212, 200, 0.6);
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: float-up 0.8s ease-out forwards;
}

@keyframes float-up {
  to { opacity: 0; transform: translate(-50%, -150%); }
}

body.ouch #game {
  animation: ouch 0.35s ease-out;
}

@keyframes ouch {
  from { box-shadow: inset 0 0 120px rgba(255, 60, 90, 0.55); }
  to   { box-shadow: inset 0 0 0 rgba(255, 60, 90, 0); }
}

.hud {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 3;
  transform: translateX(-50%);
  display: flex;
  gap: 1.4em;
  align-items: center;
  padding: 0.6em 1.3em;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(10, 12, 24, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 0.95rem;
  color: rgba(244, 243, 255, 0.7);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.hud strong {
  margin-left: 0.3em;
  color: var(--text);
}

.lives {
  letter-spacing: 0.15em;
  color: var(--c3);
}

.lives .lost {
  opacity: 0.2;
}

.lives .lost.just {
  animation: heart-lost 0.5s ease-out;
}

@keyframes heart-lost {
  0%   { opacity: 1; transform: scale(1.6); }
  100% { opacity: 0.2; transform: scale(1); }
}

.lives span {
  display: inline-block;
}

.hint {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 3.4em);
  z-index: 3;
  margin: 0;
  padding: 0 16px;
  text-align: center;
  font-size: 0.9rem;
  color: rgba(244, 243, 255, 0.55);
  pointer-events: none;
  transition: opacity 0.6s;
}

.hint.gone {
  opacity: 0;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 6, 12, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in 0.3s ease-out;
}

.overlay[hidden] {
  display: none;
}

@keyframes fade-in {
  from { opacity: 0; }
}

.card {
  min-width: min(320px, 100%);
  padding: 2em 2.4em;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 20px;
  background: rgba(16, 18, 34, 0.85);
  text-align: center;
  box-shadow: 0 20px 60px -10px rgba(124, 92, 255, 0.45);
  animation: pop-in 0.4s cubic-bezier(.2, .9, .3, 1.3) both;
}

.card h2 {
  margin: 0 0 0.4em;
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.card .final {
  margin: 0;
  font-size: 1.15rem;
  color: rgba(244, 243, 255, 0.75);
}

.card .final strong {
  color: var(--text);
  font-size: 1.6em;
}

.card .record {
  margin: 0.6em 0 0;
  font-weight: 700;
  background: linear-gradient(90deg, var(--c2), var(--c1), var(--c3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.card button {
  margin-top: 1.4em;
  padding: 0.7em 1.8em;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--c1), var(--c3));
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.card button:focus-visible {
  outline: 2px solid var(--c2);
  outline-offset: 3px;
}

@media (max-width: 480px) {
  .hud {
    gap: 1em;
    font-size: 0.85rem;
    padding: 0.55em 1em;
  }
  .flyer {
    font-size: 0.85rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  h1 {
    animation: none;
    background-position: 50% 0;
  }
}
