/* Lexend (SIL Open Font License, siehe fonts/OFL-Lexend.txt) – liegt in der App, läuft offline */
@font-face { font-family: "Lexend"; font-weight: 100 500; font-display: swap; src: url(fonts/lexend-400.woff2) format("woff2"); }
@font-face { font-family: "Lexend"; font-weight: 600 700; font-display: swap; src: url(fonts/lexend-700.woff2) format("woff2"); }
@font-face { font-family: "Lexend"; font-weight: 800 900; font-display: swap; src: url(fonts/lexend-800.woff2) format("woff2"); }

:root {
  --bg: #0c0d14;
  --panel: rgba(255, 255, 255, 0.035);
  --cell: rgba(255, 255, 255, 0.04);
  --line: rgba(255, 255, 255, 0.07);
  --text: #f4f5fb;
  --muted: #8a8ea8;
  --accent: #818cf8;
  /* Kachelgröße: passt 5 Spalten in die Breite und 8.2 Reihen in die Höhe */
  --reserve: 0px;   /* Video-Modus: Höhe des freien Bereichs oben */
  --chrome: 170px;  /* Höhe von Kopf- und Fußleiste samt Abständen */
  --u: min(18vw, calc((100dvh - var(--chrome) - var(--reserve)) / 8.3), 84px);
  --radius: calc(var(--u) * 0.2);
  --fly: 160ms;
  --move: 120ms;
  --ease-out: cubic-bezier(.2, .9, .3, 1);
  --ease-back: cubic-bezier(.3, 1.6, .5, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(120% 60% at 50% -10%, #1d1f3a 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: "Lexend", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding:
    max(12px, env(safe-area-inset-top), var(--safe-top, 0px))
    16px
    max(12px, env(safe-area-inset-bottom), var(--safe-bottom, 0px));
}

.top, .bottom {
  width: calc(var(--u) * 5);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.22em;
  background: linear-gradient(90deg, #5eead4, #a5b4fc, #f9a8d4);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stat { display: flex; flex-direction: column; min-width: 80px; }
.stat.right { align-items: flex-end; }
.label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); }
#score, #best { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
#score { display: inline-block; transform-origin: left center; }
#score.bump { animation: bump 280ms var(--ease-out); }
@keyframes bump { 35% { transform: scale(1.18); color: #fde047; } }

/* ---------- Spielfeld ---------- */

#board {
  position: relative;
  width: calc(var(--u) * 5);
  height: calc(var(--u) * 8.2);
  touch-action: none;
  cursor: pointer;
  --aim: var(--accent);
}

#cells {
  position: absolute;
  inset: 0 0 auto 0;
  height: calc(var(--u) * 7);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(7, 1fr);
  padding: 2px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 6px);
}
#cells div { margin: 3px; border-radius: var(--radius); background: var(--cell); }

/* Zielspalte: schmaler Lichtstrahl in der Farbe des nächsten Blocks */
#aim {
  position: absolute;
  left: 0; top: 0;
  width: var(--u);
  height: calc(var(--u) * 8.2);
  transform: translateX(calc(var(--c, 2) * var(--u)));
  transition: transform 90ms var(--ease-out);
  pointer-events: none;
}
#aim::before {
  content: '';
  position: absolute;
  inset: 4px calc(var(--u) * 0.18) calc(var(--u) * 0.6);
  border-radius: 999px;
  background: linear-gradient(to top, color-mix(in srgb, var(--aim) 38%, transparent), transparent 85%);
}

/* ---------- Kacheln ---------- */

.tile {
  position: absolute;
  left: 0; top: 0;
  width: var(--u);
  height: var(--u);
  padding: 4px;
  transform: translate(calc(var(--c) * var(--u)), calc(var(--r) * var(--u)));
  transition: transform var(--move) var(--ease-out);
  pointer-events: none;
}
.tile.fly { transition: transform var(--fly) cubic-bezier(.25, .8, .35, 1); }
.tile.noanim { transition: none; }

.face {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: calc(var(--radius) * 0.7);
  overflow: hidden;
  font-weight: 700;
  font-size: calc(var(--u) * 0.34);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: var(--c2);   /* Flat: klare Vollfarbe in der satten Stufenfarbe */
}
.face.long { font-size: calc(var(--u) * 0.28); }
.face b { grid-area: 1 / 1; font-weight: inherit; position: relative; z-index: 1; }
.face b.in { animation: numIn 320ms var(--ease-back); }
.face b.out { animation: numOut 220ms ease-in forwards; }   /* nach .in: gewinnt im Zweifel */
@keyframes numOut { to { transform: translateY(-70%) scale(0.7); opacity: 0; filter: blur(2px); } }
@keyframes numIn { from { transform: translateY(70%) scale(1.3); opacity: 0; filter: blur(2px); } }

/* Einschlag-Ring */
.face::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
}

/* Große Blöcke (ab 1K): wandernder Glanz */
.tile.glow .face::before {
  content: '';
  position: absolute;
  inset: -50%;
  background: linear-gradient(115deg, transparent 42%, rgba(255, 255, 255, 0.45) 50%, transparent 58%);
  animation: sheen 2.8s ease-in-out infinite;
}
@keyframes sheen { from { transform: translateX(-60%); } 60%, to { transform: translateX(60%); } }

/* ---------- Bewegungen ---------- */

/* Landen: kurzes Stauchen */
.tile.land .face { animation: land 260ms var(--ease-out); }
@keyframes land {
  0% { transform: scale(1.1, 0.86); }
  45% { transform: scale(0.97, 1.04); }
  100% { transform: none; }
}

/* Eingesaugt werden: beschleunigt in den Zielblock, schrumpft und verblasst */
.tile.absorb { transition: transform 130ms cubic-bezier(.6, 0, .9, .5); z-index: 0; }
.tile.absorb .face { transform: scale(0.55); opacity: 0.35; transition: transform 130ms ease-in, opacity 130ms ease-in; }

/* Einschlag: aufleuchten, überschwingen, Ring in Blockfarbe */
.tile.impact { z-index: 2; }
.tile.impact .face { animation: impact 380ms var(--ease-back); }
.tile.impact .face::after { animation: ring 420ms ease-out; }
@keyframes impact {
  0% { transform: scale(0.82); filter: brightness(2.2) saturate(0.6); }
  40% { transform: scale(1.14); filter: brightness(1.25); }
  100% { transform: none; filter: none; }
}
@keyframes ring {
  0% { opacity: 1; box-shadow: 0 0 0 0 var(--c1), inset 0 0 0 3px #fff; }
  100% { opacity: 0; box-shadow: 0 0 0 calc(var(--u) * 0.35) transparent, inset 0 0 0 0 transparent; }
}

/* Großer Einschlag (ab 256-Rekord / 1K) */
.tile.bigpop { z-index: 3; }
.tile.bigpop .face { animation: bigpop 700ms var(--ease-back); }
@keyframes bigpop {
  0% { transform: scale(0.7); filter: brightness(3); }
  35% { transform: scale(1.45); filter: brightness(1.6); }
  65% { transform: scale(0.95); }
  100% { transform: none; filter: none; }
}

.tile.gone { opacity: 0; transform: translate(calc(var(--c) * var(--u)), calc(var(--r) * var(--u))) scale(0.4); transition: opacity 200ms, transform 200ms; }
.tile.dead .face { filter: grayscale(0.9) brightness(0.5); transition: filter 450ms; }

#shooter { --r: 7.2; transition: transform 90ms var(--ease-out); }
#shooter .face { animation: hover 2.4s ease-in-out infinite; }
#shooter.hide { visibility: hidden; }
@keyframes hover { 50% { transform: translateY(-3px); } }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
#board.shake { animation: shake 180ms; }

/* ---------- Leiste unten ---------- */

.next { display: flex; align-items: center; gap: 10px; }
.mini.face {
  width: calc(var(--u) * 0.62);
  height: calc(var(--u) * 0.62);
  border-radius: calc(var(--radius) * 0.75);
  font-size: calc(var(--u) * 0.24);
}
.mini.face.long { font-size: calc(var(--u) * 0.19); }

button {
  font: inherit;
  color: var(--text);
  background: var(--accent);
  border: 0;
  border-radius: 14px;
  padding: 11px 20px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms var(--ease-out), background 120ms;
}
button:active { transform: scale(0.94); }
button:disabled { opacity: 0.35; cursor: default; }
button.icon {
  width: 44px; height: 44px; padding: 0;
  font-size: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
}
button.ghost { background: var(--cell); border: 1px solid var(--line); }

/* ---------- Game Over ---------- */

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 9, 14, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: calc(var(--radius) + 6px);
  cursor: default;
}
#overlay[hidden] { display: none; }
#overlay:not([hidden]) { animation: fadeIn 300ms 250ms both; }
#overlay:not([hidden]) .panel { animation: panelIn 500ms 350ms var(--ease-back) both; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes panelIn { from { transform: scale(0.85) translateY(24px); opacity: 0; } }
.panel {
  background: rgba(24, 26, 40, 0.92);
  border: 1px solid var(--line);
  padding: 24px 28px;
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.6);
}
.panel h2 { margin: 0 0 8px; font-size: 26px; letter-spacing: -0.02em; }
.panel p { margin: 4px 0; color: #c9cbe0; }
.panel .row { display: flex; gap: 10px; margin-top: 16px; }
.newbest { color: #fde047 !important; font-weight: 800; letter-spacing: 0.04em; margin: 0 0 8px !important; }
.newbest[hidden] { display: none; }
.version { margin: 12px 0 0 !important; font-size: 11px; color: var(--muted) !important; }
.version:empty { display: none; }

/* Wird die Leiste schmal: Beschriftung "Nächster" weglassen, der Block spricht für sich */
.bottom { container-type: inline-size; }
@container (max-width: 350px) {
  .next .label { display: none; }
  .group { gap: 6px; }
}

/* ---------- Bombe ---------- */

#bomb, #undo { position: relative; }
#bomb:disabled, #undo:disabled { opacity: 0.3; }
#undo:disabled b { display: none; }
#undo.earned { animation: earned 600ms var(--ease-back); }
#bomb b, #undo b {
  position: absolute; top: -5px; right: -5px;
  min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px;
  background: #ea580c;
  font-size: 11px; font-weight: 800; line-height: 18px;
}
#bomb:disabled b { display: none; }
#bomb.on { background: #ea580c; border-color: transparent; }
#bomb.on b { background: #0c0d14; }
button#undo b { background: #4f46e5; }   /* Rückgängig: indigo statt Bomben-Orange */
#bomb.urgent { animation: urgent 1s ease-in-out infinite; }
#bomb.earned { animation: earned 600ms var(--ease-back); }
@keyframes urgent { 50% { box-shadow: 0 0 0 6px rgba(234, 88, 12, 0.45); transform: scale(1.08); } }
@keyframes earned { 0% { transform: scale(0.6); } 40% { transform: scale(1.35) rotate(-12deg); } 100% { transform: none; } }

/* Zielen: Werfer tritt zurück, jeder Block wird zum Ziel */
#board.bombing { cursor: crosshair; }
#board.bombing #aim, #board.bombing #shooter { opacity: 0.2; transition: opacity 150ms; }
#board.bombing .tile .face { animation: target 1.1s ease-in-out infinite; }
@keyframes target { 50% { box-shadow: inset 0 0 0 3px rgba(251, 146, 60, 0.9); transform: scale(0.94); } }

/* Zündung: zittern und rot aufglühen – dann Knall */
.tile.fuse .face { animation: fuse 300ms linear; }
@keyframes fuse {
  0%, 100% { transform: none; filter: none; }
  20% { transform: translate(-2px, 1px) scale(1.04); }
  40% { transform: translate(2px, -1px) scale(1.08); filter: brightness(1.4) sepia(0.6) hue-rotate(-30deg) saturate(3); }
  60% { transform: translate(-2px, -1px) scale(1.12); }
  80% { transform: translate(2px, 1px) scale(1.16); filter: brightness(2) sepia(1) hue-rotate(-30deg) saturate(4); }
}
.tile.blast .face { transform: scale(1.7); opacity: 0; filter: brightness(3); transition: transform 200ms ease-out, opacity 200ms ease-out, filter 200ms; }

/* ---------- Mehr Gefühl: Werfer, Nachbarn ---------- */

/* Werfer staucht sich beim Antippen wie eine gespannte Feder */
#shooter.charge .face { animation: none; transform: scale(1.08, 0.86); transition: transform 90ms ease-out; }

/* Nachbarn werden vom Einschlag kurz weggedrückt */
.tile.nudge .face { animation: nudge 300ms var(--ease-out); }
@keyframes nudge {
  30% { transform: translate(var(--nx, 0), var(--ny, 0)) scale(0.96); }
  100% { transform: none; }
}

/* ---------- Bestenliste ---------- */

#bestBtn {
  background: none; border: 0; padding: 0; color: inherit; font: inherit;
  text-align: right; cursor: pointer; border-radius: 10px;
}
#bestBtn:active { transform: scale(0.95); }
.rank { color: #fde047 !important; font-weight: 700; }
.rank:empty { display: none; }
button.link { background: none; color: var(--muted); padding: 6px; margin-top: 10px; font-weight: 600; }

#scores {
  position: fixed; inset: 0; z-index: 7;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 9, 14, 0.75);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  padding: 16px;
  animation: fadeIn 200ms both;
}
#scores[hidden] { display: none; }
.panel.scores { width: min(100%, 360px); animation: panelIn 350ms var(--ease-back) both; }
#scoresList { list-style: none; margin: 12px 0 8px; padding: 0; text-align: left; }
#scoresList li {
  display: grid; grid-template-columns: 26px 1fr 40px 58px; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 10px;
}
#scoresList li:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
#scoresList li.me { background: rgba(129, 140, 248, 0.22); }
#scoresList li.empty { display: block; text-align: center; color: var(--muted); }
#scoresList .rank { color: var(--muted) !important; font-weight: 700; text-align: center; }
#scoresList li:nth-child(1) .rank { color: #fde047 !important; }
#scoresList .pts { font-weight: 800; font-variant-numeric: tabular-nums; }
#scoresList .blk { width: 40px; height: 28px; border-radius: 7px; font-size: 13px; }
#scoresList .date { color: var(--muted); font-size: 12px; text-align: right; }
.panel.scores .note { font-size: 12px; color: var(--muted) !important; margin: 4px 0 12px !important; }

/* ---------- Video-Modus ---------- */

button.icon.on { background: var(--accent); border-color: transparent; }

/* Kopfzeile steckt im freien Bereich, deshalb weniger Abzug für die Leisten */
html.video { --reserve: calc(min(100vw, 520px) * 0.36); --chrome: 118px; }
html.video #app { justify-content: flex-start; }
html.video #board { margin-top: auto; }
html.video .top {
  width: min(100%, 520px);
  height: var(--reserve);
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto 1fr;
  align-items: start;
  gap: 10px 14px;
}
html.video .brand { display: none; }
html.video .bottom { width: min(100%, max(calc(var(--u) * 5), 340px)); }
html.video .stat.right { grid-column: 1; grid-row: 2; align-items: flex-start; }
/* Platzhalter, wo das Bild-im-Bild-Video hingehört */
html.video .top::after {
  content: '▶  Platz für dein Video';
  grid-column: 2;
  grid-row: 1 / 4;
  justify-self: end;
  width: min(100%, calc(var(--reserve) * 16 / 9));
  height: 100%;
  display: grid;
  place-items: center;
  border: 1.5px dashed rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Effekt-Ebenen ---------- */

.group { display: flex; gap: 8px; }

#fx, #fxText { position: fixed; inset: 0; pointer-events: none; }
#fx { width: 100vw; height: 100vh; z-index: 5; }
#fxText { z-index: 6; overflow: hidden; }

#hint {
  position: absolute;
  inset: calc(var(--u) * 2.6) 0 auto;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
  pointer-events: none;
  animation: breathe 2.4s ease-in-out infinite;
}
#hint[hidden] { display: none; }
@keyframes breathe { 50% { opacity: 0.45; } }

.float {
  position: absolute;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  text-align: center;
  color: #fff;
}

/* Punkte: klein, leuchtend, steigen auf */
.float.points {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.6), 0 2px 4px rgba(0, 0, 0, 0.5);
  animation: rise 750ms var(--ease-out) forwards;
}
@keyframes rise {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(0.7); }
  20% { opacity: 1; transform: translate(-50%, -70%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -190%); }
}

/* Kombo: Pille mit Verlauf, gleitet herein – kein Wackeln, kein Drehen */
.float.combo {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 18px;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--a1), var(--a2));
  box-shadow: 0 10px 30px -8px var(--a2), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  animation: comboIn 950ms var(--ease-out) forwards;
}
.float.combo span { font-size: 13px; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; }
.float.combo b { font-size: 26px; font-weight: 900; letter-spacing: -0.02em; line-height: 1; }
@keyframes comboIn {
  0% { opacity: 0; transform: translate(-50%, -10%) scale(0.8); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  30% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -85%) scale(0.96); }
}

/* Großer Moment: Zahl schärft sich aus der Unschärfe, mit Farbglühen */
.float.huge { animation: hugeIn 1500ms var(--ease-out) forwards; }
.float.huge b {
  display: block;
  font-size: min(24vw, 120px);
  font-weight: 900;
  letter-spacing: -0.05em;
  line-height: 1;
  background: linear-gradient(180deg, #fff 15%, var(--a1) 60%, var(--a2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 28px color-mix(in srgb, var(--a1) 70%, transparent));
}
.float.huge em {
  display: block;
  font-style: normal;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--a1);
  margin-bottom: 6px;
}
@keyframes hugeIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); filter: blur(12px); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.04); filter: blur(0); }
  32% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); filter: blur(0); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1.08); filter: blur(6px); }
}

.float.info { font-size: 14px; font-weight: 600; color: var(--muted); animation: rise 1400ms ease-out forwards; }

@media (prefers-reduced-motion: reduce) {
  .tile.glow .face::before, #shooter .face, #hint { animation: none; }
}
