:root {
  --bg: #1e1b4b;
  --panel: rgba(17, 14, 42, 0.78);
  --panel-solid: #1b1740;
  --text: #f5f3ff;
  --muted: #b8b2d9;
  --accent: #7c3aed;
  --accent-2: #a78bfa;
  --gold: #fbbf24;
  --radius: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg);
  overscroll-behavior: none; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; }

#stage { position: fixed; inset: 0; touch-action: none; }
#stage canvas { display: block; width: 100%; height: 100%; }

/* ---------- Namensschilder & Punkte ---------- */
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.label {
  position: absolute; left: 0; top: 0; white-space: nowrap;
  font-size: 13px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: rgba(15, 10, 36, 0.55); color: #fff; border: 2px solid var(--c);
  will-change: transform;
}
.label.me { background: var(--c); border-color: #fff; font-size: 14px; }
.label .crown { display: none; margin-right: 3px; }
.label.lead .crown { display: inline; }
.float {
  position: absolute; transform: translate(-50%, -50%); pointer-events: none;
  font-weight: 800; font-size: 20px; color: #fff;
  text-shadow: 0 2px 0 #4c1d95, 0 0 8px rgba(76, 29, 149, 0.6);
  animation: floatUp 0.9s ease-out forwards;
}
@keyframes floatUp { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -60px; } }

/* ---------- Joystick ---------- */
#joy { position: fixed; left: 0; top: 0; width: 0; height: 0; pointer-events: none; z-index: 5; }
#joy .base {
  position: absolute; width: 120px; height: 120px; left: -60px; top: -60px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.12); border: 2px solid rgba(255, 255, 255, 0.35);
}
#joy .knob {
  position: absolute; width: 52px; height: 52px; left: -26px; top: -26px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.8); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}

/* ---------- HUD ---------- */
#hud {
  position: fixed; inset: 0; pointer-events: none; z-index: 4;
  padding: calc(10px + var(--safe-t)) calc(10px + var(--safe-r)) 10px calc(10px + var(--safe-l));
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; align-content: start; gap: 8px;
}
#hud[hidden] { display: none; }
.hud-left { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.chip {
  display: flex; align-items: center; gap: 7px; background: var(--panel); padding: 6px 12px;
  border-radius: 999px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.chip b { font-size: 20px; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); font-size: 12px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(255,255,255,0.7); }
.sizebar { width: 150px; height: 8px; border-radius: 99px; background: var(--panel); overflow: hidden; }
.sizebar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--gold)); transition: width 0.25s; }
.lvl { font-size: 12px; font-weight: 600; background: var(--panel); padding: 3px 9px; border-radius: 99px; color: var(--muted); }
.hud-timer {
  font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums;
  background: var(--panel); padding: 4px 16px; border-radius: 14px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.hud-timer.urgent { color: #fca5a5; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.hud-buttons { display: flex; gap: 6px; pointer-events: auto; }
.hud-buttons button {
  width: 40px; height: 40px; border-radius: 12px; background: var(--panel); font-size: 18px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}

.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; min-width: 150px; }
.board li {
  display: flex; align-items: center; gap: 6px; background: var(--panel); border-radius: 10px;
  padding: 3px 9px; font-size: 13px;
}
.board li.me { background: rgba(124, 58, 237, 0.85); font-weight: 700; }
.board .pl { width: 1.4em; text-align: center; color: var(--muted); font-weight: 700; }
.board li.me .pl { color: #fff; }
.board .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.board .sc { font-variant-numeric: tabular-nums; font-weight: 700; }
.board.big li { font-size: 16px; padding: 8px 12px; border-radius: 12px; background: rgba(255,255,255,0.06); }
.board.big li.me { background: rgba(124, 58, 237, 0.85); }
.board.big .nm { max-width: none; }
.board.big .pl { font-size: 18px; }

@media (max-width: 600px) {
  #hud { grid-template-columns: 1fr auto; grid-template-areas: "timer right" "left right"; }
  .hud-timer { grid-area: timer; justify-self: start; font-size: 24px; }
  .hud-left { grid-area: left; }
  .hud-right { grid-area: right; }
  .chip b { font-size: 17px; }
  .sizebar { width: 120px; }
  .board { min-width: 0; }
  .board li { font-size: 12px; padding: 2px 7px; }
  .board .nm { max-width: 80px; }
}

/* ---------- Countdown ---------- */
#countdown {
  position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 6;
  font-size: min(30vw, 180px); font-weight: 900; color: #fff;
  text-shadow: 0 6px 0 #4c1d95, 0 0 30px rgba(76, 29, 149, 0.6);
}
#countdown[hidden] { display: none; }
#countdown.pop { animation: pop 0.6s ease-out; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } 40% { opacity: 1; } to { transform: scale(1); } }

/* ---------- Menü ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 8; display: grid; place-items: center; overflow-y: auto;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  background: radial-gradient(ellipse at center, rgba(30, 27, 75, 0.25), rgba(30, 27, 75, 0.7));
}
.overlay[hidden] { display: none; }
.card {
  background: var(--panel); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.menu-card { width: min(400px, 100%); padding: 26px 24px 22px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.logo { align-self: center; border-radius: 20px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); }
h1 { margin: 0; font-size: 44px; letter-spacing: -1px; line-height: 1; }
.tagline { margin: -6px 0 4px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; }
.field input {
  font: inherit; font-size: 17px; color: var(--text); background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 12px; padding: 10px 12px; outline: none;
  -webkit-user-select: text; user-select: text;
}
.field input:focus { border-color: var(--accent-2); }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; justify-content: space-between; }
.sw { width: 30px; height: 30px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 8px #0f0a24, 0 0 0 2px transparent; transition: transform 0.15s; }
.sw.on { box-shadow: inset 0 0 0 8px #0f0a24, 0 0 0 3px #fff; transform: scale(1.1); }
.primary {
  background: linear-gradient(180deg, #8b5cf6, #6d28d9); color: #fff; font-weight: 800; border-radius: 14px;
  padding: 12px 20px; box-shadow: 0 4px 0 #4c1d95; transition: transform 0.1s;
}
.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 #4c1d95; }
.primary.big { font-size: 22px; padding: 14px; }
.ghost { background: rgba(255, 255, 255, 0.1); border-radius: 14px; padding: 12px 18px; font-weight: 700; }
.ghost:hover { background: rgba(255, 255, 255, 0.16); }
.menu-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.menu-stats:empty { display: none; }
.menu-stats div { background: rgba(255, 255, 255, 0.06); border-radius: 12px; padding: 8px 4px; display: flex; flex-direction: column; }
.menu-stats b { font-size: 17px; }
.menu-stats span { font-size: 11px; color: var(--muted); }
.help { list-style: none; margin: 0; padding: 0; text-align: left; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.ios-hint { display: flex; gap: 8px; align-items: center; text-align: left; font-size: 13px; background: rgba(255, 255, 255, 0.08); border-radius: 12px; padding: 10px 12px; }
.ios-hint[hidden] { display: none; }
.ios-hint button { background: none; font-size: 16px; color: var(--muted); }

/* ---------- Dialoge ---------- */
dialog {
  border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 24px; padding: 22px; color: var(--text);
  background: var(--panel-solid); width: min(420px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
dialog::backdrop { background: rgba(15, 10, 36, 0.5); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 4px; text-align: center; font-size: 28px; }
dialog .sub { margin: 0 0 14px; text-align: center; color: var(--muted); }
.record { color: var(--gold); }
dialog .row { display: flex; gap: 8px; margin-top: 16px; }
dialog .row .primary { flex: 1; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translate(-50%, 20px);
  background: var(--panel-solid); color: #fff; padding: 10px 16px; border-radius: 14px; font-weight: 600;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; z-index: 20; text-align: center;
  max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
