/* NEON GRIDLOCK — UI theme. All HUD sizing uses container-query units (cqw/cqh)
   so DOM chrome scales with the game frame at any window size. */

:root {
  --cyan: #00f0ff;
  --cyan-dim: #0a5f6e;
  --magenta: #ff2bd6;
  --lime: #b6ff00;
  --amber: #ffb300;
  --red: #ff3355;
  --ink: #05060f;
  --panel: rgba(4, 10, 26, 0.90);
  --panel-edge: rgba(0, 240, 255, 0.35);
  --text: #bfe9ff;
  --text-dim: #4e6d96;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #010208;
  font-family: "Courier New", Menlo, Consolas, monospace;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 120% 90% at 50% 45%, #0a1230 0%, #04060f 55%, #010208 100%);
}

#game-frame {
  position: relative;
  aspect-ratio: 10 / 7;
  width: min(100vw, calc(100vh * 10 / 7));
  container-type: size;
  background: var(--ink);
  border: 2px solid #16223f;
  border-radius: 8px;
  box-shadow:
    0 0 40px rgba(0, 240, 255, 0.10),
    0 0 120px rgba(255, 43, 214, 0.06),
    inset 0 0 60px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}

#game-frame canvas { position: absolute; inset: 0; margin: auto; }

/* ---- HUD layer: transparent to input except .ui widgets ---- */
#hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
#hud .ui { pointer-events: auto; }
.hidden { display: none !important; }

/* ---- Top bar ---- */
#top-bar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center;
  gap: 1.4cqw;
  padding: 0.7cqh 1.2cqw;
  background: linear-gradient(180deg, rgba(2, 6, 18, 0.94) 0%, rgba(2, 6, 18, 0.80) 75%, transparent 100%);
  border-bottom: 1px solid rgba(0, 240, 255, 0.12);
}

.brand {
  font-size: 1.7cqw; font-weight: bold; letter-spacing: 0.22cqw;
  color: var(--cyan);
  text-shadow: 0 0 8px var(--cyan), 0 0 24px rgba(0, 240, 255, 0.5);
  margin-right: 0.6cqw;
  white-space: nowrap;
}
.brand span { color: var(--magenta); text-shadow: 0 0 8px var(--magenta), 0 0 24px rgba(255, 43, 214, 0.5); }

.stat { display: flex; flex-direction: column; align-items: center; min-width: 6cqw; }
.stat .lbl { font-size: 0.95cqw; letter-spacing: 0.12cqw; color: var(--text-dim); }
.stat .val {
  font-size: 1.65cqw; font-weight: bold; color: var(--text);
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.55);
  font-variant-numeric: tabular-nums;
}
.stat .val.money { color: var(--lime); text-shadow: 0 0 10px rgba(182, 255, 0, 0.6); }
.stat .val.lives { color: var(--red); text-shadow: 0 0 10px rgba(255, 51, 85, 0.6); }
.stat .val.score { color: var(--amber); text-shadow: 0 0 10px rgba(255, 179, 0, 0.6); }
.stat .val.hurt { animation: stat-hurt 0.4s; }
@keyframes stat-hurt { 0% { transform: scale(1.6); color: #fff; } 100% { transform: scale(1); } }

#speed-buttons { display: flex; gap: 0.4cqw; margin-left: auto; }

/* ---- Buttons ---- */
.btn {
  font-family: inherit; font-weight: bold;
  font-size: 1.2cqw; letter-spacing: 0.08cqw;
  color: var(--cyan);
  background: rgba(4, 14, 34, 0.9);
  border: 1px solid var(--cyan-dim);
  border-radius: 4px;
  padding: 0.55cqh 0.9cqw;
  cursor: pointer;
  text-shadow: 0 0 6px rgba(0, 240, 255, 0.6);
  transition: all 0.12s ease;
}
.btn:hover { border-color: var(--cyan); box-shadow: 0 0 10px rgba(0, 240, 255, 0.4), inset 0 0 8px rgba(0, 240, 255, 0.12); }
.btn:active { transform: translateY(1px); }
.btn.active { background: rgba(0, 240, 255, 0.16); border-color: var(--cyan); box-shadow: 0 0 12px rgba(0, 240, 255, 0.5); color: #fff; }
.btn.gear { color: var(--amber); border-color: rgba(255, 179, 0, 0.4); text-shadow: 0 0 6px rgba(255, 179, 0, 0.6); }
.btn.gear:hover { border-color: var(--amber); box-shadow: 0 0 10px rgba(255, 179, 0, 0.4); }
.btn.danger { color: var(--red); border-color: rgba(255, 51, 85, 0.45); text-shadow: 0 0 6px rgba(255, 51, 85, 0.6); }
.btn.danger:hover { border-color: var(--red); box-shadow: 0 0 10px rgba(255, 51, 85, 0.4); }
.btn.big { font-size: 1.8cqw; padding: 1.1cqh 2.4cqw; }
.btn:disabled { opacity: 0.35; cursor: default; box-shadow: none; }

/* ---- Build bar ---- */
#build-bar {
  position: absolute; bottom: 0.8cqh; left: 50%; transform: translateX(-50%);
  display: flex; gap: 0.55cqw;
  padding: 0.7cqh 0.8cqw;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  box-shadow: 0 0 24px rgba(0, 240, 255, 0.12);
}
.tower-card {
  width: 6.2cqw;
  display: flex; flex-direction: column; align-items: center;
  padding: 0.5cqh 0.2cqw;
  border: 1px solid rgba(0, 240, 255, 0.18);
  border-radius: 6px;
  background: rgba(2, 8, 22, 0.85);
  cursor: pointer;
  transition: all 0.12s ease;
}
.tower-card img { width: 3.4cqw; height: 3.4cqw; image-rendering: pixelated; }
.tower-card .tname { font-size: 0.82cqw; letter-spacing: 0.04cqw; color: var(--text); white-space: nowrap; margin-top: 0.3cqh; }
.tower-card .tcost { font-size: 1cqw; font-weight: bold; color: var(--lime); text-shadow: 0 0 6px rgba(182, 255, 0, 0.5); }
.tower-card .tkey { font-size: 0.75cqw; color: var(--text-dim); }
.tower-card:hover { border-color: var(--cyan); box-shadow: 0 0 14px rgba(0, 240, 255, 0.35); transform: translateY(-2px); }
.tower-card.selected { border-color: var(--magenta); box-shadow: 0 0 16px rgba(255, 43, 214, 0.5); background: rgba(40, 6, 34, 0.7); }
.tower-card.broke { opacity: 0.42; }
.tower-card.broke .tcost { color: var(--red); }
.tower-card.shake { animation: card-shake 0.3s; }
@keyframes card-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* ---- Side panels (tower info, wave preview) ---- */
.side-panel {
  position: absolute;
  width: 15.5cqw; min-width: 170px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  padding: 0.9cqh 0.9cqw;
  box-shadow: 0 0 24px rgba(0, 240, 255, 0.12);
  color: var(--text);
  font-size: 1.05cqw;
}
#tower-panel { right: 0.8cqw; top: 24cqh; }
#wave-preview { right: 0.8cqw; top: 7.5cqh; }

.side-panel h3 {
  font-size: 1.25cqw; letter-spacing: 0.1cqw;
  margin-bottom: 0.6cqh;
  text-shadow: 0 0 8px currentColor;
}
.side-panel .row { display: flex; justify-content: space-between; margin: 0.28cqh 0; }
.side-panel .row .k { color: var(--text-dim); }
.side-panel .row .v { font-weight: bold; font-variant-numeric: tabular-nums; }
.side-panel .btn { width: 100%; margin-top: 0.5cqh; font-size: 1.05cqw; }
.side-panel .hpbar { height: 0.9cqh; background: #1a0f1c; border: 1px solid #45324d; border-radius: 3px; margin: 0.4cqh 0; overflow: hidden; }
.side-panel .hpbar > div { height: 100%; background: linear-gradient(90deg, var(--red), var(--amber), var(--lime)); }

#wave-preview .wp-title { color: var(--magenta); }
#wave-preview .wp-units { display: flex; flex-wrap: wrap; gap: 0.35cqw; margin: 0.5cqh 0; }
#wave-preview .wp-unit {
  display: flex; align-items: center; gap: 0.25cqw;
  border: 1px solid rgba(255, 43, 214, 0.3); border-radius: 4px;
  padding: 0.15cqh 0.35cqw; font-size: 0.95cqw;
}
#wave-preview .wp-unit .dot { width: 0.8cqw; height: 0.8cqw; border-radius: 50%; box-shadow: 0 0 6px currentColor; }
#wave-preview .badge { color: var(--amber); font-size: 0.85cqw; }

/* ---- Dev panel drawer ---- */
#dev-panel {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 26cqw; min-width: 300px; max-width: 420px;
  background: rgba(2, 6, 18, 0.97);
  border-right: 1px solid var(--panel-edge);
  box-shadow: 8px 0 40px rgba(0, 0, 0, 0.6);
  transform: translateX(-102%);
  transition: transform 0.22s ease;
  /* Above #menu-root (50) and .overlay (60) so the drawer is usable from the
     menu and while paused/level-complete/game-over. Below #crt (100), which is
     pointer-events:none. When closed it is translated fully off-screen, so it
     never intercepts clicks meant for lower layers. */
  z-index: 90;
  display: flex; flex-direction: column;
  color: var(--text);
}
#dev-panel.open { transform: translateX(0); }
#dev-panel .dp-head {
  padding: 1cqh 1cqw;
  border-bottom: 1px solid rgba(0, 240, 255, 0.15);
  display: flex; align-items: center; gap: 0.6cqw; flex-wrap: wrap;
}
#dev-panel .dp-head h2 { font-size: 1.4cqw; color: var(--amber); text-shadow: 0 0 8px rgba(255, 179, 0, 0.6); width: 100%; }
#dev-panel .dp-head select, #dev-panel .dp-head .btn { font-size: 1cqw; }
#dev-panel .dp-body { flex: 1; overflow-y: auto; padding: 0.6cqh 0; }

#dev-panel details { border-bottom: 1px solid rgba(0, 240, 255, 0.08); }
#dev-panel summary {
  cursor: pointer; list-style: none;
  padding: 0.75cqh 1cqw;
  font-size: 1.15cqw; font-weight: bold; letter-spacing: 0.08cqw;
  color: var(--cyan); text-shadow: 0 0 6px rgba(0, 240, 255, 0.5);
}
#dev-panel summary::before { content: "▸ "; }
#dev-panel details[open] summary::before { content: "▾ "; }
#dev-panel summary:hover { background: rgba(0, 240, 255, 0.06); }

.dp-row {
  display: grid;
  grid-template-columns: 1fr 5.4cqw 3.6cqw;
  align-items: center; gap: 0.5cqw;
  padding: 0.32cqh 1cqw;
  font-size: 0.95cqw;
}
.dp-row:hover { background: rgba(0, 240, 255, 0.04); }
.dp-row label { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dp-row.changed label { color: var(--amber); }
.dp-row .numv {
  text-align: right; color: var(--lime); font-weight: bold;
  font-variant-numeric: tabular-nums;
  background: none; border: 1px solid transparent; border-radius: 3px;
  font-family: inherit; font-size: 0.95cqw; width: 100%;
}
.dp-row .numv:focus { border-color: var(--cyan-dim); outline: none; background: rgba(0, 240, 255, 0.07); color: #fff; }
.dp-note { padding: 0.2cqh 1cqw 0.6cqh; font-size: 0.8cqw; color: var(--text-dim); }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  height: 0.5cqh; min-height: 4px;
  background: linear-gradient(90deg, var(--cyan-dim), var(--cyan));
  border-radius: 3px; outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 1cqw; height: 1cqw; min-width: 10px; min-height: 10px;
  background: var(--cyan); border-radius: 50%;
  box-shadow: 0 0 8px var(--cyan);
}
input[type="range"]::-moz-range-thumb {
  width: 10px; height: 10px; background: var(--cyan); border: none; border-radius: 50%;
  box-shadow: 0 0 8px var(--cyan);
}

.dp-toggle { display: inline-flex; align-items: center; cursor: pointer; justify-self: end; grid-column: 2 / 4; }
.dp-toggle input { display: none; }
.dp-toggle .tk {
  width: 3cqw; height: 1.4cqw; min-width: 30px; min-height: 14px;
  border: 1px solid var(--cyan-dim); border-radius: 999px; position: relative;
  background: rgba(0, 0, 0, 0.5); transition: all 0.15s;
}
.dp-toggle .tk::after {
  content: ""; position: absolute; top: 8%; left: 4%;
  width: 44%; height: 84%;
  background: var(--text-dim); border-radius: 50%; transition: all 0.15s;
}
.dp-toggle input:checked + .tk { border-color: var(--lime); background: rgba(182, 255, 0, 0.12); }
.dp-toggle input:checked + .tk::after { left: 52%; background: var(--lime); box-shadow: 0 0 8px var(--lime); }

.dp-row select, .dp-row button.btn { grid-column: 2 / 4; font-size: 0.9cqw; padding: 0.3cqh 0.4cqw; }
select {
  font-family: inherit; color: var(--cyan);
  background: rgba(4, 14, 34, 0.95);
  border: 1px solid var(--cyan-dim); border-radius: 4px;
}
#dev-panel textarea {
  width: 100%; height: 12cqh;
  background: rgba(0, 0, 0, 0.5); color: var(--lime);
  border: 1px solid var(--cyan-dim); border-radius: 4px;
  font-family: inherit; font-size: 0.85cqw; padding: 0.4cqh 0.4cqw;
  resize: none;
}

/* ---- Overlays ---- */
.overlay {
  position: absolute; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(2, 4, 12, 0.80);
  backdrop-filter: blur(2px);
  pointer-events: auto;
}
.overlay .panel {
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  padding: 3cqh 4cqw;
  box-shadow: 0 0 60px rgba(0, 240, 255, 0.18);
  max-width: 60cqw;
}
.overlay h1 {
  font-size: 4.2cqw; letter-spacing: 0.4cqw; margin-bottom: 1.4cqh;
  color: var(--cyan);
  text-shadow: 0 0 14px var(--cyan), 0 0 50px rgba(0, 240, 255, 0.5);
}
.overlay h1.bad { color: var(--red); text-shadow: 0 0 14px var(--red), 0 0 50px rgba(255, 51, 85, 0.5); }
.overlay h1.good { color: var(--lime); text-shadow: 0 0 14px var(--lime), 0 0 50px rgba(182, 255, 0, 0.5); }
.overlay .sub { color: var(--text); font-size: 1.5cqw; margin-bottom: 1.2cqh; }
.overlay .stats-grid {
  display: grid; grid-template-columns: auto auto; gap: 0.4cqh 3cqw;
  justify-content: center; margin: 1.6cqh 0; font-size: 1.3cqw;
}
.overlay .stats-grid .k { color: var(--text-dim); text-align: left; }
.overlay .stats-grid .v { color: var(--amber); font-weight: bold; text-align: right; }
.overlay .btnrow { display: flex; gap: 1cqw; justify-content: center; margin-top: 2cqh; }

/* ---- Menu ---- */
#menu-root { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; pointer-events: auto; }
.menu-panel { text-align: center; }
.menu-title {
  font-size: 7cqw; font-weight: bold; letter-spacing: 0.7cqw; line-height: 1.05;
  color: var(--cyan);
  text-shadow: 0 0 18px var(--cyan), 0 0 70px rgba(0, 240, 255, 0.55);
  animation: title-pulse 2.6s ease-in-out infinite;
}
.menu-title span { color: var(--magenta); text-shadow: 0 0 18px var(--magenta), 0 0 70px rgba(255, 43, 214, 0.55); }
@keyframes title-pulse { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.35); } }
.menu-sub { color: var(--text-dim); font-size: 1.4cqw; letter-spacing: 0.3cqw; margin: 1cqh 0 3cqh; }
.menu-row { display: flex; gap: 0.8cqw; justify-content: center; align-items: center; margin: 1.2cqh 0; font-size: 1.2cqw; color: var(--text); flex-wrap: wrap; }
.menu-hiscore { color: var(--amber); font-size: 1.3cqw; margin-top: 2cqh; text-shadow: 0 0 8px rgba(255, 179, 0, 0.5); }

/* ---- Toast / flash / splash ---- */
#toast {
  position: absolute; left: 50%; top: 9cqh; transform: translateX(-50%);
  padding: 0.5cqh 1.4cqw;
  background: rgba(20, 4, 10, 0.92);
  border: 1px solid var(--red); border-radius: 6px;
  color: #ffd9e0; font-size: 1.1cqw; font-weight: bold;
  opacity: 0; transition: opacity 0.2s; z-index: 70;
  text-shadow: 0 0 6px rgba(255, 51, 85, 0.7);
  white-space: nowrap;
}
#toast.info { border-color: var(--cyan); background: rgba(3, 14, 26, 0.92); color: var(--text); text-shadow: 0 0 6px rgba(0, 240, 255, 0.7); }
#toast.show { opacity: 1; }

#flash { position: absolute; inset: 0; background: var(--red); opacity: 0; z-index: 55; }
#flash.go { animation: leak-flash 0.45s ease-out; }
@keyframes leak-flash { 0% { opacity: 0.28; } 100% { opacity: 0; } }

#boot-splash {
  position: absolute; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  background: var(--ink);
  color: var(--cyan); font-size: 2.4cqw; letter-spacing: 0.5cqw;
}
#boot-splash .pulse { animation: title-pulse 1.2s ease-in-out infinite; text-shadow: 0 0 16px var(--cyan); }

/* ---- Scrollbars (dev panel) ---- */
#dev-panel .dp-body::-webkit-scrollbar { width: 8px; }
#dev-panel .dp-body::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.4); }
#dev-panel .dp-body::-webkit-scrollbar-thumb { background: var(--cyan-dim); border-radius: 4px; }
