:root {
  --bg: #05010c;
  --cyan: #00f0ff;
  --pink: #ff2bd6;
  --yellow: #ffe600;
  --violet: #b26bff;
  --text: #d9e7ff;
  --dim: #7c86a8;
  --panel: rgba(10, 6, 24, 0.92);
  --font: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Roboto Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: var(--font); overflow: hidden; overscroll-behavior: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
button { font-family: inherit; }
.cyan { color: var(--cyan); } .pink { color: var(--pink); } .yellow { color: var(--yellow); }
.hidden { display: none !important; }

#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 43, 214, 0.12), transparent 60%),
    radial-gradient(ellipse at 50% 100%, rgba(0, 240, 255, 0.10), transparent 60%),
    var(--bg);
}

/* ---------- HUD ---------- */
#hud {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  border-bottom: 1px solid rgba(0, 240, 255, 0.25);
  box-shadow: 0 0 18px rgba(0, 240, 255, 0.12);
}
.stat { flex: 1; display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.stat .k { font-size: 10px; color: var(--dim); letter-spacing: 2px; }
.stat .v { font-size: 20px; font-weight: 700; text-shadow: 0 0 8px currentColor; }
.hud-btn {
  width: 44px; height: 40px; border-radius: 8px; font-size: 15px; font-weight: 700;
  background: transparent; color: var(--cyan); border: 1px solid rgba(0, 240, 255, 0.5);
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.25) inset;
}
.hud-btn:active { background: rgba(0, 240, 255, 0.15); }

#board { flex: 1; width: 100%; min-height: 0; display: block; touch-action: none; }

/* ---------- Bottom panel ---------- */
#panel {
  height: 184px; padding: 10px 12px 12px; background: var(--panel);
  border-top: 1px solid rgba(255, 43, 214, 0.35);
  box-shadow: 0 -4px 24px rgba(255, 43, 214, 0.12);
  display: flex; flex-direction: column; gap: 8px; overflow: hidden;
}
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.label { font-size: 11px; letter-spacing: 2px; color: var(--dim); }
.headline { font-size: 16px; font-weight: 700; }
.hint { font-size: 12px; color: var(--dim); line-height: 1.4; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip { font-size: 12px; padding: 2px 7px; border-radius: 10px; border: 1px solid currentColor; white-space: nowrap; }
.affix { font-size: 12px; color: var(--yellow); margin-top: 4px; }

.btn {
  font-size: 14px; font-weight: 700; letter-spacing: 1px; padding: 12px 14px; border-radius: 10px;
  color: var(--cyan); background: rgba(0, 240, 255, 0.06);
  border: 1px solid rgba(0, 240, 255, 0.6); box-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
}
.btn:active { transform: scale(0.97); background: rgba(0, 240, 255, 0.18); }
.btn.primary {
  color: #05010c; background: var(--cyan); border-color: var(--cyan);
  box-shadow: 0 0 18px rgba(0, 240, 255, 0.6);
}
.btn.pinkbtn { color: var(--pink); border-color: rgba(255, 43, 214, 0.7); background: rgba(255, 43, 214, 0.08); box-shadow: 0 0 10px rgba(255, 43, 214, 0.25); }
.btn.danger { color: #ff4d6d; border-color: rgba(255, 77, 109, 0.6); background: rgba(255, 77, 109, 0.06); box-shadow: none; }
.btn:disabled { opacity: 0.35; box-shadow: none; }
.btn.icon { padding: 0 14px; font-size: 20px; }
.btn.sm { padding: 9px 10px; font-size: 12px; }

.tower-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; flex: 1; }
.tbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border-radius: 10px; padding: 6px 2px; background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--c); color: var(--c); box-shadow: 0 0 8px color-mix(in srgb, var(--c) 35%, transparent);
}
.tbtn:active { background: color-mix(in srgb, var(--c) 20%, transparent); }
.tbtn:disabled { opacity: 0.3; box-shadow: none; }
.tbtn .ic { width: 22px; height: 22px; border: 2px solid var(--c); border-radius: 6px; box-shadow: 0 0 6px var(--c); }
.tbtn .nm { font-size: 10px; font-weight: 700; text-align: center; line-height: 1.1; }
.tbtn .cs { font-size: 12px; color: var(--text); }

.stats { display: flex; gap: 12px; font-size: 12px; color: var(--dim); }
.stats b { color: var(--text); }
.actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(3, 0, 10, 0.86); backdrop-filter: blur(4px);
}
.card {
  width: 100%; max-width: 380px; padding: 24px 20px; border-radius: 16px;
  background: rgba(12, 6, 28, 0.95); border: 1px solid rgba(255, 43, 214, 0.5);
  box-shadow: 0 0 30px rgba(255, 43, 214, 0.25), 0 0 60px rgba(0, 240, 255, 0.08) inset;
  max-height: 100%; overflow-y: auto;
}
.title {
  margin: 0 0 6px; text-align: center; font-size: 40px; letter-spacing: 4px; color: var(--cyan);
  text-shadow: 0 0 10px var(--cyan), 0 0 30px rgba(0, 240, 255, 0.5);
}
.title span { color: var(--pink); text-shadow: 0 0 10px var(--pink); }
.title.sm { font-size: 28px; }
.title.pink { color: var(--pink); text-shadow: 0 0 10px var(--pink), 0 0 30px rgba(255, 43, 214, 0.5); }
.tag { text-align: center; color: var(--dim); font-size: 12px; line-height: 1.5; margin-bottom: 16px; }
.lbl { display: block; font-size: 11px; letter-spacing: 3px; color: var(--pink); margin-bottom: 6px; }
.seed-row { display: flex; gap: 8px; }
#seed-input {
  flex: 1; min-width: 0; font-family: inherit; font-size: 18px; font-weight: 700; letter-spacing: 2px;
  padding: 12px; border-radius: 10px; color: var(--yellow); background: #07030f;
  border: 1px solid rgba(255, 230, 0, 0.5); outline: none; text-transform: uppercase;
  box-shadow: 0 0 10px rgba(255, 230, 0, 0.15) inset; user-select: text; -webkit-user-select: text;
}
#seed-input:focus { border-color: var(--yellow); box-shadow: 0 0 12px rgba(255, 230, 0, 0.4); }
.best { min-height: 18px; margin: 8px 0 14px; font-size: 12px; color: var(--yellow); text-align: center; }
.btn-col { display: flex; flex-direction: column; gap: 10px; }
.score { text-align: center; margin: 10px 0; }
.score span { display: block; font-size: 64px; font-weight: 800; color: var(--yellow); text-shadow: 0 0 20px var(--yellow); }
.score small { color: var(--dim); letter-spacing: 3px; }
.howto { margin-top: 16px; font-size: 12px; color: var(--dim); }
.howto summary { color: var(--cyan); letter-spacing: 2px; cursor: pointer; }
.howto ul { padding-left: 18px; line-height: 1.6; }

.toast {
  position: fixed; left: 50%; top: 70px; transform: translate(-50%, -10px); z-index: 5;
  padding: 8px 14px; border-radius: 10px; font-size: 13px; font-weight: 700; pointer-events: none;
  background: rgba(10, 6, 24, 0.92); border: 1px solid var(--yellow); color: var(--yellow);
  box-shadow: 0 0 14px rgba(255, 230, 0, 0.35); opacity: 0; transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Granular upgrade grid ---------- */
.stats { flex-wrap: wrap; row-gap: 2px; }
.dimv { color: var(--dim); }
.up-grid { display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: 1fr; gap: 6px; flex: 1; min-height: 0; }
.ubtn {
  --c: var(--cyan);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  border-radius: 9px; padding: 3px 2px; background: rgba(255, 255, 255, 0.03);
  border: 1px solid color-mix(in srgb, var(--c) 70%, transparent); color: var(--c);
  box-shadow: 0 0 6px color-mix(in srgb, var(--c) 30%, transparent);
}
.ubtn:active { background: color-mix(in srgb, var(--c) 20%, transparent); }
.ubtn:disabled { opacity: 0.35; box-shadow: none; }
.ubtn.maxed:disabled { opacity: 0.75; }
.ubtn .un { font-size: 10px; font-weight: 700; letter-spacing: 1px; }
.ubtn .up { font-size: 10px; letter-spacing: 1px; line-height: 1; }
.ubtn .uc { font-size: 12px; color: var(--text); }
.ubtn.move { --c: var(--pink); }
.ubtn.sell { --c: #ff4d6d; }
.tbtn.locked { filter: grayscale(0.7); }
.tbtn.locked .ic { border: none; box-shadow: none; font-size: 14px; display: flex; align-items: center; justify-content: center; }

/* ---------- Specials & core abilities ---------- */
.ubtn.special { border-style: dashed; }
.ubtn.special .un::before { content: '★ '; }
.special-desc { font-size: 10px; color: var(--yellow); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.special-desc.locked { color: var(--dim); }
#hud-core { cursor: pointer; }
.ab-grid { display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 1fr; gap: 6px; flex: 1; min-height: 0; }
.abtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-align: center;
  border-radius: 10px; padding: 6px 4px; color: var(--cyan); background: rgba(0, 240, 255, 0.05);
  border: 1px solid rgba(0, 240, 255, 0.6); box-shadow: 0 0 8px rgba(0, 240, 255, 0.2);
}
.abtn:active { background: rgba(0, 240, 255, 0.18); }
.abtn:disabled { opacity: 0.4; box-shadow: none; }
.abtn.maxed:disabled { opacity: 0.8; }
.abtn .un { font-size: 11px; font-weight: 700; }
.abtn .up { font-size: 11px; color: var(--text); }
.abtn .ad { font-size: 9px; color: var(--dim); line-height: 1.25; }

/* ---------- Build menu tabs ---------- */
.tabs { display: flex; gap: 4px; }
.tab {
  font-family: inherit; font-size: 11px; font-weight: 700; letter-spacing: 1px; padding: 6px 10px; border-radius: 8px;
  color: var(--dim); background: transparent; border: 1px solid rgba(255, 255, 255, 0.15);
}
.tab.on { color: var(--cyan); border-color: var(--cyan); box-shadow: 0 0 8px rgba(0, 240, 255, 0.35); }
.label.right { text-align: right; }
.tower-grid { grid-auto-rows: 1fr; min-height: 0; }
.tbtn .nm { font-size: 9px; }
.chips { max-height: 52px; overflow: hidden; }

.tower-status { font-size: 10px; font-weight: 700; color: #ff3d7f; min-height: 0; }
.tower-status:empty { display: none; }
.abtn { padding: 3px 4px; gap: 1px; }

/* ---------- Orbital strike HUD button ---------- */
#btn-orbital { color: var(--dim); font-size: 14px; }
#btn-orbital.ready { color: #fff; border-color: #fff; box-shadow: 0 0 12px rgba(255, 255, 255, 0.6); animation: orbPulse 1.2s infinite; }
#btn-orbital.aiming { color: #ff4d6d; border-color: #ff4d6d; }
@keyframes orbPulse { 50% { box-shadow: 0 0 4px rgba(255, 255, 255, 0.2); } }

/* ---------- Account ---------- */
.account { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  min-height: 34px; margin: -6px 0 14px; font-size: 12px; }
.acct-dim { color: var(--dim); }
.acct-callsign { color: var(--yellow); font-weight: 700; letter-spacing: 1px; text-shadow: 0 0 8px rgba(255, 230, 0, 0.4); }
.acct-btn { text-decoration: none; display: inline-block; }
.linkbtn { background: none; border: none; padding: 4px 2px; font: inherit; font-size: 12px; color: var(--cyan);
  text-decoration: underline; cursor: pointer; }
#callsign-input {
  width: 100%; font-family: inherit; font-size: 20px; font-weight: 700; letter-spacing: 2px; text-align: center;
  padding: 12px; border-radius: 10px; color: var(--yellow); background: #07030f; outline: none;
  border: 1px solid rgba(255, 230, 0, 0.5); user-select: text; -webkit-user-select: text;
}
#callsign-input:focus { border-color: var(--yellow); box-shadow: 0 0 12px rgba(255, 230, 0, 0.4); }
.callsign-error { min-height: 18px; margin: 8px 0 12px; color: #ff4d6d; font-size: 12px; text-align: center; }

/* ---------- Online: game-over status, leaderboard, update banner ---------- */
.go-online { display: flex; flex-direction: column; align-items: center; gap: 8px; min-height: 22px; margin: -4px 0 14px; font-size: 12px; text-align: center; }
.go-online .ok { color: #39ff14; font-weight: 700; letter-spacing: 1px; }
.go-online .rank { color: var(--yellow); font-weight: 800; font-size: 16px; text-shadow: 0 0 10px rgba(255, 230, 0, 0.5); }
.go-online .warn { color: #ff4d6d; }
.go-online .dim, .lb-me .dim { color: var(--dim); }
.go-online .small { font-size: 10px; }
.go-online a.btn { text-decoration: none; }
.pulse { color: var(--cyan); animation: pulseText 1s infinite; letter-spacing: 2px; }
@keyframes pulseText { 50% { opacity: 0.4; } }
.lb-card { max-width: 420px; }
.lb-tabs { justify-content: center; margin-bottom: 8px; }
.lb-list { list-style: none; margin: 0 0 8px; padding: 0; max-height: 46vh; overflow-y: auto; }
.lb-row { display: grid; grid-template-columns: 44px 1fr 48px 52px; align-items: center; gap: 6px; padding: 7px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06); font-size: 13px; }
.lb-row .lb-rank { color: var(--dim); }
.lb-row .lb-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.lb-row .lb-wave { color: var(--yellow); text-align: right; font-weight: 700; }
.lb-row .lb-core { color: var(--dim); text-align: right; font-size: 11px; }
.lb-row.top1 .lb-rank { color: #ffd700; } .lb-row.top2 .lb-rank { color: #d9e7ff; } .lb-row.top3 .lb-rank { color: #ff9e00; }
.lb-row.me { background: rgba(0, 240, 255, 0.1); border-radius: 8px; box-shadow: 0 0 0 1px rgba(0, 240, 255, 0.5) inset; }
.lb-empty { color: var(--dim); text-align: center; padding: 18px 0; font-size: 12px; }
.lb-me { text-align: center; color: var(--cyan); font-size: 12px; min-height: 18px; margin-bottom: 12px; }
#leaderboard { z-index: 12; } /* above the game-over card it can be opened from */
#callsign { z-index: 14; }
.update-banner { position: fixed; left: 50%; top: calc(8px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 20;
  font-family: inherit; font-size: 12px; font-weight: 700; letter-spacing: 1px; padding: 10px 14px; border-radius: 10px;
  color: #05010c; background: var(--yellow); border: none; box-shadow: 0 0 18px rgba(255, 230, 0, 0.6); }
