:root {
  --bg: #10141c;
  --bg-deep: #0a0d13;
  --player: #4da8ff;
  --enemy: #ff5a3c;
  --gold: #ffd24d;
  --heal: #4ade80;
  --danger: #ff4d5e;
  --text: #e7eef7;
  --muted: #7f8ea0;
  --font: 'Rajdhani', system-ui, sans-serif;
  --font-head: 'Space Grotesk', var(--font);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
}

#game { position: fixed; inset: 0; }
#game canvas { display: block; touch-action: none; }

.hidden { display: none !important; }

/* ── HUD ── */
.hud { position: fixed; top: 0; left: 0; right: 0; z-index: 5; pointer-events: none; }
.hud-top {
  display: flex; flex-direction: column; align-items: center; gap: 0.35rem;
  padding: calc(env(safe-area-inset-top) + 0.55rem) 1rem 0;
}
.hud-row { display: flex; align-items: baseline; justify-content: center; gap: 1rem; width: 100%; max-width: 460px; }
.hud-label { font-size: 0.6rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.hud-value { font-size: 1.15rem; font-weight: 900; font-family: var(--font-head); }
.hud-mini { display: flex; align-items: baseline; gap: 0.35rem; }
.hud-mini.gold .hud-value { color: var(--gold); }
.hud-wave { font-family: var(--font-head); font-weight: 700; font-size: 1rem; color: var(--player); text-shadow: 0 0 14px rgba(77,168,255,0.4); }
.hud-time { font-size: 0.85rem; font-weight: 700; color: var(--muted); margin-right: auto; }
.hud-value.punch { animation: score-punch .2s ease-out; }
@keyframes score-punch { 0%{transform:scale(1)} 35%{transform:scale(1.28)} 100%{transform:scale(1)} }

/* Wall HP bar — prominent, full width */
.wall-wrap { width: 100%; max-width: 460px; }
.wall-bar {
  position: relative; width: 100%; height: 22px;
  border-radius: 6px; background: rgba(0,0,0,0.42);
  border: 1.5px solid rgba(255,255,255,0.14); overflow: hidden;
  background-image: repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), rgba(0,0,0,0.35) calc(10% - 1px) 10%);
}
.wall-fill { position: absolute; inset: 0; width: 100%; transform-origin: left;
  background: linear-gradient(90deg, #3a6ea8, #6bb0f5); transition: width .18s ease-out; }
.wall-fill.mid { background: linear-gradient(90deg, #b58a1e, var(--gold)); }
.wall-fill.low { background: linear-gradient(90deg, #a01e2c, var(--danger)); }
.wall-text { position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 0.72rem; font-weight: 900; font-family: var(--font-head);
  color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.8); letter-spacing: 0.04em; }

/* ── Einheiten-Dock ── */
.dock {
  position: fixed; left: 0; right: 0; z-index: 6;
  bottom: calc(env(safe-area-inset-bottom) + 0.5rem);
  display: flex; gap: 0.7rem; justify-content: center;
  padding: 0 0.6rem;
}
.dock-item {
  position: relative; width: 92px; padding: 0.5rem 0.3rem 0.45rem;
  border-radius: 14px; border: 1.5px solid rgba(77,168,255,0.4);
  background: rgba(12,20,32,0.82);
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  cursor: grab; touch-action: none; --pc: var(--player);
}
.dock-item:active { cursor: grabbing; }
.dock-item.cant { opacity: 0.4; --pc: var(--muted); border-color: rgba(255,255,255,0.12); cursor: default; }
.dock-icon { width: 30px; height: 30px; }
.dock-name { font-family: var(--font-head); font-weight: 700; font-size: 0.74rem; color: var(--text); line-height: 1; }
.dock-price { font-size: 0.72rem; font-weight: 900; color: var(--gold); font-family: var(--font-head); }
.dock-item.cant .dock-price { color: var(--danger); }

/* Kommandanten-Dock-Items (M3) — Gold-Akzent, Cast/Cooldown-Zustände */
.dock-item.cmd { border-color: rgba(255,210,77,0.55); }
.dock-item.cmd .dock-name { color: var(--gold); }
.dock-item.cmd.cast { border-color: var(--gold); box-shadow: 0 0 16px rgba(255,210,77,0.45); }
.dock-item.cmd.cast .dock-price { color: var(--heal); }
.dock-item.cmd.cast { animation: cmd-ready 1.3s ease-in-out infinite; }
@keyframes cmd-ready { 0%,100%{box-shadow:0 0 10px rgba(255,210,77,0.3)} 50%{box-shadow:0 0 20px rgba(255,210,77,0.6)} }
.dock-item.cmd.cooling { opacity: 0.9; cursor: default; }
.dock-item.cmd.cooling .dock-price { color: var(--muted); }
.cd-veil {
  position: absolute; left: 0; right: 0; bottom: 0; height: 0%;
  background: rgba(6,12,24,0.72); border-radius: 0 0 12px 12px; pointer-events: none;
  transition: height .12s linear;
}
@media (prefers-reduced-motion: reduce) { .dock-item.cmd.cast { animation: none; } }

/* Drag-Ghost — folgt dem Finger */
.drag-ghost {
  position: fixed; z-index: 20; pointer-events: none; display: none;
  width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%;
  border: 2px solid var(--player); background: rgba(77,168,255,0.28);
  box-shadow: 0 0 18px rgba(77,168,255,0.6);
}
.drag-ghost.show { display: block; }
.drag-ghost.bad { border-color: var(--danger); background: rgba(255,77,94,0.24); box-shadow: 0 0 18px rgba(255,77,94,0.5); }
.drag-ghost.cast { border-color: var(--gold); background: rgba(255,210,77,0.24); box-shadow: 0 0 18px rgba(255,210,77,0.6); }
.drag-ghost.cast.bad { border-color: var(--danger); background: rgba(255,77,94,0.24); }

/* ── zentrale Feier ── */
.pop {
  position: fixed; z-index: 7; pointer-events: none;
  top: 30%; left: 50%; transform: translate(-50%, -50%) scale(0.4);
  font-family: var(--font-head); font-weight: 700;
  font-size: clamp(2.2rem, 12vw, 4.2rem); color: var(--gold);
  text-shadow: 0 0 28px currentColor; opacity: 0; text-align: center;
}
.pop.show { animation: pop .9s cubic-bezier(.2,.9,.3,1) forwards; }
@keyframes pop {
  0%{ opacity:0; transform: translate(-50%,-50%) scale(0.4);}
  22%{ opacity:1; transform: translate(-50%,-50%) scale(1.15);}
  60%{ opacity:1; transform: translate(-50%,-50%) scale(1);}
  100%{ opacity:0; transform: translate(-50%,-72%) scale(1);}
}
@media (prefers-reduced-motion: reduce) { .pop.show, .hud-value.punch { animation: none; } }

/* ── Screens ── */
.screen {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center; padding: 1.2rem;
  background: radial-gradient(120% 90% at 50% 25%, rgba(30,50,80,0.4) 0%, rgba(10,13,19,0.9) 72%);
  backdrop-filter: blur(2px);
}
.card { width: 100%; max-width: 360px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 0.9rem; }
.logo {
  font-family: var(--font-head); font-weight: 700;
  font-size: clamp(2.8rem, 16vw, 4.4rem); line-height: 0.9; letter-spacing: -0.02em;
  text-shadow: 0 0 34px rgba(77,168,255,0.4);
}
.logo span {
  display: inline-grid; place-items: center; width: 0.95em; height: 0.95em;
  margin-left: 0.14em; border-radius: 0.24em; transform: rotate(-6deg);
  background: linear-gradient(160deg, var(--player), #2a5f9e); color: #06101c;
  box-shadow: 0 0 24px rgba(77,168,255,0.5);
}
.tagline { color: var(--text); font-size: 1.1rem; font-weight: 700; }
.how { color: var(--muted); font-size: 0.88rem; font-weight: 600; line-height: 1.4; }
.tap-hint { margin-top: 0.5rem; color: var(--text); font-weight: 700; font-size: 1.05rem; opacity: 0.85; animation: blink 1.3s ease-in-out infinite; }
@keyframes blink { 0%,100%{opacity:0.35} 50%{opacity:0.95} }
@media (prefers-reduced-motion: reduce) { .tap-hint { animation: none; } }

/* ── Game Over / Victory ── */
.go-title { font-family: var(--font-head); font-weight: 700; font-size: 1.5rem; color: var(--danger); }
.go-title.win { color: var(--heal); }
.go-score { font-family: var(--font-head); font-weight: 700; font-size: clamp(3.4rem, 22vw, 5rem); line-height: 1; }
.go-score.newbest { color: var(--heal); text-shadow: 0 0 26px rgba(74,222,128,0.6); }
.go-best { color: var(--muted); font-size: 1.05rem; }
.go-best strong { color: #fff; }
.go-taunt { color: var(--gold); font-size: 1rem; font-weight: 700; min-height: 1.2em; }
.share-btn {
  margin-top: 0.4rem; padding: 0.8rem 1.6rem; border: none; border-radius: 999px;
  background: linear-gradient(160deg, var(--player), #2a5f9e); color: #06101c;
  font-family: var(--font); font-weight: 900; font-size: 1.05rem; cursor: pointer;
  box-shadow: 0 5px 0 rgba(0,0,0,0.3);
}
.share-btn:active { transform: translateY(2px); box-shadow: 0 3px 0 rgba(0,0,0,0.3); }

/* ── Registration panel ── */
.reg-panel { width: 100%; display: flex; flex-direction: column; gap: 0.55rem;
  padding: 0.9rem; border: 1px solid rgba(255,255,255,0.12); border-radius: 12px; background: rgba(255,255,255,0.04); }
.reg-panel form { display: flex; flex-direction: column; gap: 0.55rem; }
.reg-hint { font-size: 0.9rem; font-weight: 700; opacity: 0.65; }
.reg-input { width: 100%; padding: 0.65rem 0.9rem; border: 1.5px solid rgba(255,255,255,0.18); border-radius: 8px;
  background: rgba(255,255,255,0.07); color: #fff; font-family: var(--font); font-size: 1rem; outline: none; }
.reg-input::placeholder { opacity: 0.4; }
.reg-input:focus { border-color: rgba(255,255,255,0.45); }
.reg-error { font-size: 0.82rem; font-weight: 700; color: var(--danger); }
.reg-btns { display: flex; gap: 0.55rem; }
.reg-submit-btn { flex: 1; padding: 0.7rem; border: none; border-radius: 8px; background: var(--heal); color: #06140c;
  font-family: var(--font); font-weight: 900; font-size: 1rem; cursor: pointer; }
.reg-skip-btn { padding: 0.7rem 1rem; border: 1px solid rgba(255,255,255,0.18); border-radius: 8px;
  background: transparent; color: rgba(255,255,255,0.45); font-family: var(--font); font-weight: 700; font-size: 0.9rem; cursor: pointer; }
.reg-saved { font-size: 0.95rem; font-weight: 700; color: var(--heal); }

/* ── Aufwertungs-Leiste (Update 0.4, ersetzt den Skilltree-Baum) ── */
/* Sitzt direkt über dem Dock, immer sichtbar, jederzeit antippbar. */
.upgrades {
  position: fixed; left: 0; right: 0; z-index: 6;
  bottom: calc(env(safe-area-inset-bottom) + 0.5rem + 78px);
  display: flex; gap: 0.5rem; justify-content: center; padding: 0 0.6rem;
}
.upg-item {
  width: 92px; padding: 0.34rem 0.3rem 0.3rem;
  border-radius: 11px; border: 1.5px solid rgba(77,168,255,0.35);
  background: rgba(12,20,32,0.82); color: var(--text);
  font-family: var(--font); cursor: pointer; touch-action: manipulation;
  display: flex; flex-direction: column; align-items: center; gap: 0.16rem;
}
.upg-item:active { transform: translateY(1px); }
.upg-name { font-family: var(--font-head); font-weight: 700; font-size: 0.66rem;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); line-height: 1; }
/* Stufen-Punkte tragen dieselbe Helligkeitsrampe wie die Einheiten auf dem Feld */
.upg-pips { display: flex; gap: 3px; }
.upg-pip { width: 9px; height: 9px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.22); background: transparent; }
.upg-pip.on { border-color: transparent; }
.upg-cost { font-size: 0.7rem; font-weight: 900; color: var(--gold); font-family: var(--font-head); line-height: 1; }
.upg-item.cant { opacity: 0.45; cursor: default; }
.upg-item.cant .upg-cost { color: var(--danger); }
.upg-item.maxed { border-color: rgba(74,222,128,0.5); cursor: default; }
.upg-item.maxed .upg-cost { color: var(--heal); }

/* ── Wellen-Pause: schmale Leiste, KEIN Overlay (GDD 0.4 §5) ── */
/* Das Schlachtfeld muss sichtbar bleiben — die eigene Armee ist die
   Entscheidungsgrundlage fürs Aufwerten. */
.break-bar {
  position: fixed; left: 0; right: 0; z-index: 12;
  bottom: calc(env(safe-area-inset-bottom) + 0.5rem + 150px);
  display: flex; align-items: center; justify-content: center; gap: 0.7rem;
  padding: 0 0.6rem; pointer-events: none;
}
.break-bar > * { pointer-events: auto; }
.break-next { font-family: var(--font-head); font-weight: 700; font-size: 1rem; color: var(--enemy);
  text-shadow: 0 0 16px rgba(255,90,60,0.4); }
.break-gold { font-size: 0.82rem; font-weight: 700; color: var(--muted); }
.break-gold b { color: var(--gold); font-family: var(--font-head); font-size: 1rem; }
.brk-go {
  padding: 0.5rem 1.5rem; border: none; border-radius: 999px;
  background: linear-gradient(160deg, var(--heal), #1f9e5a); color: #06140c;
  font-family: var(--font); font-weight: 900; font-size: 0.95rem; cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.3);
}
.brk-go:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.3); }
