/* layout.css — App-Grid, Header, Leben-HUD, Toolbar, Modals, Overlays */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 780px;
  margin: 0 auto;
  padding: 8px 12px 16px;
}

/* ---- Header ---- */

#brand {
  text-align: center;
  font-weight: 900;
  font-size: 1.6rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  padding: 8px 0 2px;
  background: linear-gradient(180deg, var(--text), color-mix(in srgb, var(--primary) 55%, var(--text)));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.15);
}

#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 2px 14px;
}

#level-label {
  font-weight: 800;
  font-size: 1.05rem;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  white-space: nowrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
}

/* Leben-Anzeige */
#lives-display {
  display: flex;
  align-items: center;
  gap: 7px;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px 4px 8px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}

#lives-display:hover { box-shadow: var(--shadow); }
#lives-display:active { transform: scale(0.96); }

.heart {
  display: inline-block;
  width: 20px;
  height: 20px;
  background: linear-gradient(160deg, #ff6b81, #e11d48);
  clip-path: path('M10 18s-7-4.7-7-9.4A4.1 4.1 0 0 1 10 5.6a4.1 4.1 0 0 1 7 3C17 13.3 10 18 10 18z');
  filter: drop-shadow(0 1px 2px rgba(225, 29, 72, 0.5));
  animation: heartBeat 2.4s ease-in-out infinite;
}

@keyframes heartBeat {
  0%, 88%, 100% { transform: scale(1); }
  92% { transform: scale(1.18); }
  96% { transform: scale(1.04); }
}

#lives-display.empty .heart { filter: grayscale(1); opacity: 0.45; animation: none; }

#lives-timer {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 700;
  min-width: 40px;
  text-align: right;
}

#lives-timer.full { color: var(--success); }

#lives-display.gain { animation: livesGain 0.6s cubic-bezier(.2, 1.5, .3, 1); }
#lives-display.loss { animation: livesLoss 0.5s ease; }

@keyframes livesGain {
  0% { transform: scale(1); }
  40% { transform: scale(1.22); box-shadow: 0 0 20px rgba(16, 185, 129, 0.6); }
  100% { transform: scale(1); }
}

@keyframes livesLoss {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); box-shadow: 0 0 18px rgba(225, 29, 72, 0.6); }
  60% { transform: translateX(5px); }
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 13px;
  width: 40px;
  height: 40px;
  font-size: 18px;
  line-height: 1;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
  flex: 0 0 auto;
}

.icon-btn:hover { box-shadow: var(--shadow); }
.icon-btn:active { transform: scale(0.94); }

/* ---- Spielbereich ---- */

#game {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex: 1;
}

#board-wrap { flex: 1; min-width: 0; }

#board {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 26px 20px;
  padding: 34px 14px 38px;
  background: var(--board-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  overflow: visible;
}

/* Sanfter Lichtkegel über dem Brett */
#board::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(120% 70% at 50% -20%, rgba(255, 255, 255, 0.35), transparent 65%);
  pointer-events: none;
}

aside[data-ad-slot][hidden] { display: none !important; }

aside[data-ad-slot] {
  width: 160px;
  min-height: 240px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

#ad-slot-bottom { width: 100%; min-height: 90px; margin: 12px 0 4px; }

/* ---- Toolbar ---- */

#toolbar {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 16px 0 12px;
}

.btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 11px 20px;
  font-weight: 700;
  box-shadow: 0 2px 0 var(--border);
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn:hover { box-shadow: var(--shadow); background: var(--surface-2); }
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(180deg, var(--primary-2), var(--primary));
  color: var(--primary-contrast);
  border-color: transparent;
  box-shadow: 0 4px 0 color-mix(in srgb, var(--primary) 60%, black), var(--shadow);
}

.btn-primary:hover {
  background: linear-gradient(180deg, color-mix(in srgb, var(--primary-2) 88%, white), var(--primary));
}

.btn-primary:active { box-shadow: 0 1px 0 color-mix(in srgb, var(--primary) 60%, black); }

.btn-gold {
  background: linear-gradient(180deg, #ffd76a, var(--gold));
  color: #5a3400;
  border-color: transparent;
  box-shadow: 0 4px 0 #b46a05, var(--shadow);
}

.btn-gold:active { box-shadow: 0 1px 0 #b46a05; }

.btn-full { width: 100%; border-radius: 14px; margin-top: 8px; }

/* ---- Footer ---- */

#footer {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---- Modals ---- */

#modal-root { position: fixed; inset: 0; z-index: 50; pointer-events: none; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 20, 0.62);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  pointer-events: auto;
  z-index: 60;
  animation: modalFade 0.22s ease;
}

@keyframes modalFade { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  max-width: 440px;
  width: 100%;
  padding: 26px;
  border: 1px solid var(--border);
  animation: cardPop 0.34s cubic-bezier(.2, 1.5, .35, 1);
  overflow: hidden;
}

@keyframes cardPop {
  0% { transform: scale(0.82) translateY(24px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-title { margin: 0 0 12px; font-size: 1.25rem; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

.modal-actions .btn { flex: 1 1 auto; min-width: 120px; }

/* ---- Sieg-Screen ---- */

.modal.modal-win .modal-card {
  text-align: center;
  background:
    radial-gradient(120% 80% at 50% -10%, color-mix(in srgb, var(--gold) 24%, var(--surface)), var(--surface) 65%);
  border-color: color-mix(in srgb, var(--gold) 40%, var(--border));
}

/* Strahlenkranz: zwei gegenläufige, radial ausmaskierte Ebenen.
 * Die Maske ist der entscheidende Teil — ohne sie endet der Kranz an einer
 * harten Kreiskante und wirkt wie ein aufgeklebtes PNG. So blendet er zur
 * Mitte hin (hinter der Überschrift) und nach außen weich weg. */
.win-burst {
  position: absolute;
  left: 50%;
  top: 34%;
  width: 148%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%) scale(0.55);
  opacity: 0;
  pointer-events: none;
  z-index: 0;
  animation: burstIn 900ms cubic-bezier(.16, .9, .3, 1) forwards;
}

.win-burst::before,
.win-burst::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  -webkit-mask-image: radial-gradient(closest-side,
    transparent 0%, rgba(0, 0, 0, 0.35) 16%, #000 34%,
    rgba(0, 0, 0, 0.6) 62%, transparent 82%);
  mask-image: radial-gradient(closest-side,
    transparent 0%, rgba(0, 0, 0, 0.35) 16%, #000 34%,
    rgba(0, 0, 0, 0.6) 62%, transparent 82%);
}

/* Breite Hauptstrahlen, langsam im Uhrzeigersinn */
.win-burst::before {
  background: repeating-conic-gradient(from 0deg,
    rgba(255, 193, 74, 0) 0deg 5deg,
    rgba(255, 193, 74, 0.46) 7deg 11deg,
    rgba(255, 193, 74, 0) 13deg 22deg);
  filter: blur(1.6px);
  animation: burstSpin 34s linear infinite;
}

/* Feine Gegenstrahlen, entgegengesetzt und weicher */
.win-burst::after {
  background: repeating-conic-gradient(from 4deg,
    rgba(255, 222, 142, 0) 0deg 3deg,
    rgba(255, 222, 142, 0.30) 4deg 5.5deg,
    rgba(255, 222, 142, 0) 7deg 12deg);
  filter: blur(3.5px);
  animation: burstSpin 52s linear infinite reverse;
}

:root[data-theme='dark'] .win-burst::before {
  background: repeating-conic-gradient(from 0deg,
    rgba(255, 214, 120, 0) 0deg 5deg,
    rgba(255, 214, 120, 0.5) 7deg 11deg,
    rgba(255, 214, 120, 0) 13deg 22deg);
}

:root[data-theme='dark'] .win-burst::after {
  background: repeating-conic-gradient(from 4deg,
    rgba(255, 240, 200, 0) 0deg 3deg,
    rgba(255, 240, 200, 0.32) 4deg 5.5deg,
    rgba(255, 240, 200, 0) 7deg 12deg);
}

@keyframes burstIn {
  0% { transform: translate(-50%, -50%) scale(0.5) rotate(-14deg); opacity: 0; }
  60% { opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 1; }
}

@keyframes burstSpin {
  to { transform: rotate(360deg); }
}

/* Warmes Halo hinter Überschrift und Sternen — nimmt dem Kranz die Kante
 * und bindet ihn in die Karte ein. */
.win-glow {
  position: absolute;
  left: 50%;
  top: 30%;
  width: 116%;
  aspect-ratio: 1.15;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(ellipse at center,
    rgba(255, 214, 130, 0.55) 0%,
    rgba(255, 198, 100, 0.26) 30%,
    rgba(255, 190, 90, 0.08) 52%,
    transparent 72%);
  filter: blur(6px);
  animation: haloBreathe 4.2s ease-in-out infinite;
}

:root[data-theme='dark'] .win-glow {
  background: radial-gradient(ellipse at center,
    rgba(255, 205, 110, 0.42) 0%,
    rgba(255, 180, 70, 0.20) 32%,
    transparent 70%);
}

@keyframes haloBreathe {
  0%, 100% { opacity: 0.75; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
}

/* Inhalt immer über den Dekor-Ebenen */
.modal.modal-win .modal-card > *:not(.win-burst):not(.win-glow) {
  position: relative;
  z-index: 1;
}

/* Im hellen Theme sitzt der Titel auf einem goldgetönten Karton — helle
 * Goldschrift wäre dort fast unlesbar. Deshalb ein tiefes Amber mit hellem
 * Aufsetzer; im dunklen Theme bleibt es leuchtendes Gold. */
.win-headline {
  font-size: 2rem;
  font-weight: 900;
  margin: 6px 0 2px;
  letter-spacing: 0.02em;
  background: linear-gradient(180deg, #b45309 0%, #7c2d12 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.75));
  animation: headlinePop 0.6s cubic-bezier(.2, 1.7, .3, 1);
}

:root[data-theme='dark'] .win-headline {
  background: linear-gradient(180deg, #ffe08a 0%, var(--gold) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45));
}

@keyframes headlinePop {
  0% { transform: scale(0.4) rotate(-8deg); opacity: 0; }
  70% { transform: scale(1.12) rotate(2deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Auf dem goldgetönten Sieg-Karton ist --muted zu blass (4,1:1) — hier
 * ein wärmerer, dunklerer Ton für sichere Lesbarkeit. */
.win-sub {
  color: color-mix(in srgb, var(--muted) 45%, #4a2c0a);
  margin: 0 0 14px;
  font-weight: 700;
}

:root[data-theme='dark'] .win-sub {
  color: color-mix(in srgb, var(--muted) 70%, #ffe6b0);
}

.stars {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 6px 0 16px;
}

.star {
  width: 46px;
  height: 46px;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  background: var(--surface-3);
  transform: scale(0.6);
  opacity: 0.5;
}

.star.on {
  background: linear-gradient(160deg, #fff1b8, var(--gold));
  filter: drop-shadow(0 0 12px var(--gold-glow));
  animation: starIn 0.55s cubic-bezier(.2, 1.8, .3, 1) forwards;
  animation-delay: var(--d, 0ms);
  opacity: 0;
}

@keyframes starIn {
  0% { transform: scale(0) rotate(-140deg); opacity: 0; }
  70% { transform: scale(1.3) rotate(10deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.win-stats {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 4px 0 4px;
  flex-wrap: wrap;
}

.win-stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 16px;
  min-width: 92px;
}

.win-stat b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.win-stat span { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 70;
}

/* ---- Tod / Keine Leben ---- */

.modal.modal-dead .modal-card {
  text-align: center;
  background: radial-gradient(120% 80% at 50% -10%, color-mix(in srgb, var(--danger) 20%, var(--surface)), var(--surface) 65%);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

.dead-headline {
  font-size: 1.9rem;
  font-weight: 900;
  margin: 4px 0 2px;
  color: var(--danger);
  animation: headlinePop 0.5s cubic-bezier(.2, 1.5, .3, 1);
}

.dead-icon {
  font-size: 3rem;
  line-height: 1;
  margin: 6px 0 4px;
  animation: deadDrop 0.7s cubic-bezier(.3, 1.4, .4, 1);
  display: block;
}

@keyframes deadDrop {
  0% { transform: translateY(-40px) rotate(-30deg); opacity: 0; }
  60% { transform: translateY(6px) rotate(8deg); }
  100% { transform: translateY(0) rotate(0); opacity: 1; }
}

.life-lost {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 800;
  margin: 8px 0 4px;
}

.life-lost .heart-big {
  width: 22px; height: 22px;
  background: linear-gradient(160deg, #ff6b81, #e11d48);
  clip-path: path('M11 20s-8-5.2-8-10.4A4.5 4.5 0 0 1 11 6.2a4.5 4.5 0 0 1 8 3.4C19 14.8 11 20 11 20z');
  animation: heartBreak 0.8s ease;
}

@keyframes heartBreak {
  0% { transform: scale(1.4); filter: none; }
  40% { transform: scale(0.9) rotate(-8deg); }
  100% { transform: scale(1) rotate(0); filter: grayscale(0.4); }
}

.lives-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.life-pip {
  width: 20px; height: 20px;
  background: linear-gradient(160deg, #ff6b81, #e11d48);
  clip-path: path('M10 18s-7-4.7-7-9.4A4.1 4.1 0 0 1 10 5.6a4.1 4.1 0 0 1 7 3C17 13.3 10 18 10 18z');
}

.life-pip.off { background: var(--surface-3); filter: none; }

.countdown-big {
  font-size: 2.2rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  margin: 6px 0 2px;
  color: var(--primary);
}

.ad-note {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 10px;
}

/* ---- Toast ---- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 11px 20px;
  border-radius: 999px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 80;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Level-Auswahl ---- */

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 2px;
}

.level-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 0;
  font-weight: 800;
  transition: transform 0.08s ease;
}

.level-btn:hover:not(:disabled) { transform: translateY(-2px); }

.level-btn.completed {
  background: linear-gradient(180deg, #ffe9a8, #ffd166);
  border-color: var(--gold);
  color: #6b3f00;
}

.level-btn:disabled { opacity: 0.32; }

/* ---- Settings ---- */

.settings-list { display: flex; flex-direction: column; gap: 10px; }

.toggle-row,
.theme-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}

.toggle-row input[type='checkbox'] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

.theme-row .theme-options { display: flex; gap: 6px; }

.theme-row .theme-opt {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.theme-row .theme-opt.active {
  background: var(--primary);
  color: var(--primary-contrast);
  border-color: var(--primary);
}

/* ---- Ad-Stub-Fortschritt ---- */

.ad-progress {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  margin: 14px 0 4px;
}

.ad-progress > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary-2), var(--primary));
  transition: width 0.1s linear;
}

/* ---- Mobil ---- */

@media (max-width: 640px) {
  aside[data-ad-slot] { display: none !important; }
  #board { gap: 22px 14px; padding: 26px 10px 30px; }
  .btn { padding: 10px 15px; font-size: 0.92rem; }
  #brand { font-size: 1.3rem; }
  .stat { font-size: 0.78rem; padding: 4px 9px; }
  #lives-display { padding: 3px 9px 3px 6px; font-size: 0.85rem; }
  .win-headline { font-size: 1.6rem; }
}

/* Flasche ist an einem laufenden Guss beteiligt */
.bottle.locked { cursor: default; }

/* ==================================================================
 * Premium gameplay shell + resilient mobile HUD (v3)
 * ================================================================== */

#app {
  width: 100%;
  min-width: 0;
  padding:
    max(8px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

#brand {
  font-size: clamp(1.2rem, 4vw, 1.62rem);
  letter-spacing: .36em;
  padding-top: 7px;
  filter: drop-shadow(0 4px 10px color-mix(in srgb, var(--primary) 20%, transparent));
}

#topbar {
  min-width: 0;
  border-radius: 18px;
}

#level-label { min-width: 0; }

.icon-btn,
.stat,
#lives-display,
.btn {
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
}

.icon-btn {
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--surface) 92%, white 8%),
    color-mix(in srgb, var(--surface-2) 94%, transparent));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.18),
    0 5px 14px color-mix(in srgb, var(--glass-shadow) 68%, transparent);
}

#game,
#board-wrap { min-width: 0; }

#board {
  isolation: isolate;
  gap: clamp(24px, 4vw, 34px) clamp(15px, 2.4vw, 22px);
  min-width: 0;
  padding: clamp(32px, 6vw, 48px) clamp(12px, 2.4vw, 20px) clamp(39px, 6vw, 52px);
  border-color: color-mix(in srgb, var(--border) 70%, var(--glass-hi) 30%);
  background:
    radial-gradient(85% 55% at 50% 3%, rgba(255,255,255,.20), transparent 72%),
    linear-gradient(180deg,
      color-mix(in srgb, var(--board-bg) 92%, var(--primary) 8%),
      var(--board-bg));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.28),
    inset 0 -28px 55px color-mix(in srgb, var(--bg-deep) 20%, transparent),
    0 18px 48px color-mix(in srgb, var(--glass-shadow) 72%, transparent);
}

#board::before {
  inset: 1px;
  z-index: 0;
  border-radius: calc(var(--radius) - 1px);
  background:
    radial-gradient(60% 50% at 50% -8%, rgba(255,255,255,.34), transparent 72%),
    linear-gradient(115deg, rgba(255,255,255,.08), transparent 32% 72%, rgba(255,255,255,.04));
}

#board::after {
  content: '';
  position: absolute;
  z-index: 0;
  left: 7%;
  right: 7%;
  bottom: 20px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center,
    color-mix(in srgb, var(--primary) 12%, var(--glass-shadow)) 0%,
    transparent 72%);
  filter: blur(9px);
  opacity: .62;
  pointer-events: none;
}

#toolbar {
  margin-top: auto;
  padding: 18px 0 8px;
}

#toolbar .btn {
  min-height: 44px;
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--surface) 94%, white 6%),
    var(--surface-2));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.18),
    0 4px 0 color-mix(in srgb, var(--border) 76%, transparent),
    0 9px 20px color-mix(in srgb, var(--glass-shadow) 58%, transparent);
}

#footer { display: none; }

@media (max-width: 640px) {
  #app {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  #brand {
    font-size: 1.15rem;
    padding: 5px 0 1px;
  }

  #topbar {
    display: grid;
    grid-template-columns: 38px 38px minmax(0, 1fr) 38px;
    grid-template-rows: 38px 32px;
    gap: 6px 7px;
    padding: 7px 2px 12px;
    width: 100%;
  }

  #btn-menu { grid-column: 1; grid-row: 1; }
  #btn-levels { grid-column: 2; grid-row: 1; }
  #level-label {
    grid-column: 3;
    grid-row: 1;
    text-align: center;
    font-size: .94rem;
  }
  #btn-settings { grid-column: 4; grid-row: 1; }

  #topbar .icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    font-size: 16px;
  }

  #topbar .stat {
    min-width: 0;
    width: 100%;
    padding: 4px 3px;
    text-align: center;
    font-size: .72rem;
    line-height: 1.15;
  }

  #topbar .stat[title='Zeit'] { grid-column: 1 / 2; grid-row: 2; }
  #topbar .stat[title='Züge'] { grid-column: 2 / 3; grid-row: 2; }

  #lives-display {
    grid-column: 3 / 5;
    grid-row: 2;
    justify-content: center;
    min-width: 0;
    height: 32px;
    padding: 3px 8px;
    font-size: .78rem;
  }

  #lives-display .heart { width: 17px; height: 17px; }
  #lives-timer { min-width: 36px; font-size: .68rem; }

  #board {
    gap: 24px 13px;
    padding: 29px 9px 38px;
    border-radius: 22px;
  }

  #toolbar { padding-top: 14px; }
}

@media (max-width: 360px) {
  #topbar {
    grid-template-columns: 36px 36px minmax(0, 1fr) 36px;
    gap: 5px;
  }

  #topbar .icon-btn { width: 36px; height: 36px; }
  #lives-display { gap: 5px; padding-inline: 5px; }
  #board { gap: 21px 10px; padding-inline: 7px; }
}

@media (max-height: 480px) and (orientation: landscape) {
  #app {
    max-width: 940px;
    padding-top: max(4px, env(safe-area-inset-top));
    padding-bottom: max(4px, env(safe-area-inset-bottom));
  }

  #brand { display: none; }
  #topbar {
    display: flex;
    padding: 4px 2px 7px;
  }
  #board { padding-block: 24px 31px; }
  #toolbar { padding: 8px 0 2px; }
}

/* ==================================================================
 * Native-feeling HUD, controls and bottom dock (v5)
 * ================================================================== */

#app {
  position: relative;
  z-index: 0;
  max-width: 820px;
}

#brand {
  font-weight: 900;
  letter-spacing: .42em;
  background: linear-gradient(110deg,
    color-mix(in srgb, var(--text) 92%, white),
    color-mix(in srgb, var(--primary-2) 72%, var(--text)),
    color-mix(in srgb, var(--text) 92%, white));
  background-size: 180% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 5px 16px color-mix(in srgb, var(--primary) 34%, transparent));
}

#topbar {
  background: linear-gradient(145deg,
    color-mix(in srgb, var(--surface) 90%, white 10%),
    color-mix(in srgb, var(--surface-2) 80%, transparent));
  border: 1px solid color-mix(in srgb, var(--border) 72%, var(--ui-highlight));
  box-shadow:
    inset 0 1px 0 var(--ui-highlight),
    0 12px 32px color-mix(in srgb, var(--ui-shadow) 52%, transparent);
  padding: 8px;
}

#level-label {
  font-weight: 900;
  letter-spacing: -.01em;
}

.icon-btn {
  position: relative;
  width: 44px;
  height: 44px;
  border: 1px solid color-mix(in srgb, var(--border) 82%, var(--ui-highlight));
  border-radius: 15px;
  background: linear-gradient(160deg,
    color-mix(in srgb, var(--surface) 88%, white 12%),
    color-mix(in srgb, var(--surface-2) 90%, var(--primary) 10%));
  box-shadow:
    inset 0 1px 0 var(--ui-highlight),
    0 3px 0 color-mix(in srgb, var(--border) 76%, transparent),
    0 8px 18px color-mix(in srgb, var(--ui-shadow) 52%, transparent);
}

.icon-btn:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--primary) 46%, var(--border));
}

.icon-btn:active {
  transform: translateY(2px) scale(.97);
  box-shadow:
    inset 0 1px 0 var(--ui-highlight),
    0 1px 0 color-mix(in srgb, var(--border) 76%, transparent);
}

.stat,
#lives-display {
  border-color: color-mix(in srgb, var(--border) 74%, var(--ui-highlight));
  background: color-mix(in srgb, var(--surface-2) 84%, transparent);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--ui-highlight) 68%, transparent);
}

#lives-display {
  min-height: 38px;
}

#board {
  border-width: 1px;
  background:
    radial-gradient(80% 48% at 50% -2%, color-mix(in srgb, var(--primary-2) 13%, white), transparent 74%),
    linear-gradient(165deg,
      color-mix(in srgb, var(--board-bg) 94%, var(--surface) 6%),
      color-mix(in srgb, var(--board-bg) 92%, var(--bg-deep) 8%));
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--ui-highlight) 76%, transparent),
    inset 0 -34px 70px color-mix(in srgb, var(--bg-deep) 24%, transparent),
    0 22px 54px color-mix(in srgb, var(--ui-shadow) 68%, transparent);
}

#toolbar {
  align-self: center;
  width: min(100%, 330px);
  gap: 7px;
  padding: 7px;
  margin-top: auto;
  border: 1px solid color-mix(in srgb, var(--border) 74%, var(--ui-highlight));
  border-radius: 22px;
  background: linear-gradient(160deg,
    color-mix(in srgb, var(--surface) 91%, white 9%),
    color-mix(in srgb, var(--surface-2) 88%, transparent));
  box-shadow:
    inset 0 1px 0 var(--ui-highlight),
    0 15px 34px color-mix(in srgb, var(--ui-shadow) 62%, transparent);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
}

#toolbar .btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  padding: 10px 14px;
  border: 0;
  border-radius: 16px;
  font-weight: 850;
  letter-spacing: -.01em;
  background: linear-gradient(160deg,
    color-mix(in srgb, var(--surface-2) 84%, white 16%),
    color-mix(in srgb, var(--surface-3) 82%, var(--primary) 18%));
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--ui-highlight) 74%, transparent),
    0 3px 0 color-mix(in srgb, var(--border) 88%, transparent);
}

#toolbar .btn:first-child {
  background: linear-gradient(155deg,
    color-mix(in srgb, var(--primary-2) 84%, white 16%),
    var(--primary));
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.25);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.3),
    0 3px 0 color-mix(in srgb, var(--primary) 66%, black),
    0 8px 18px color-mix(in srgb, var(--primary) 28%, transparent);
}

#toolbar .btn:active {
  transform: translateY(2px) scale(.98);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--ui-highlight) 64%, transparent);
}

.modal {
  background:
    radial-gradient(70% 44% at 50% 18%, color-mix(in srgb, var(--primary) 16%, transparent), transparent),
    rgba(3, 6, 16, .72);
  backdrop-filter: blur(14px) saturate(1.15);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
}

.modal-card {
  border-radius: 28px;
  border-color: color-mix(in srgb, var(--border) 72%, var(--ui-highlight));
  box-shadow:
    inset 0 1px 0 var(--ui-highlight),
    0 30px 80px rgba(0,0,0,.46);
}

@media (max-width: 640px) {
  #app {
    padding-top: max(7px, env(safe-area-inset-top));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  #brand {
    font-size: 1.08rem;
    letter-spacing: .38em;
    padding: 4px 0 5px;
  }

  #topbar {
    grid-template-columns: 44px 44px minmax(0, 1fr) 44px;
    grid-template-rows: 44px 34px;
    gap: 7px;
    padding: 7px;
    border-radius: 21px;
    margin-bottom: 10px;
  }

  #topbar .icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    font-size: 17px;
  }

  #level-label { font-size: 1rem; }

  #topbar .stat {
    min-height: 34px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    font-size: .72rem;
  }

  #lives-display {
    height: 34px;
    border-radius: 12px;
  }

  #board {
    border-radius: 25px;
    padding-top: 31px;
  }

  #toolbar {
    width: min(100%, 320px);
    margin-bottom: max(0px, env(safe-area-inset-bottom));
  }

  #toolbar .btn {
    min-height: 50px;
    font-size: .92rem;
  }

  .modal {
    align-items: flex-end;
    padding: 10px;
  }

  .modal-card {
    max-width: none;
    border-radius: 28px;
    padding: 24px 20px max(22px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 360px) {
  #topbar {
    grid-template-columns: 44px 44px minmax(0, 1fr) 44px;
    gap: 5px;
  }

  #topbar .icon-btn {
    width: 44px;
    height: 44px;
  }

  #toolbar .btn { padding-inline: 10px; }
}

@media (max-height: 480px) and (orientation: landscape) {
  #topbar {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
  }

  #toolbar {
    margin: 6px auto 2px;
    padding: 5px;
  }

  #toolbar .btn { min-height: 42px; }
}
