:root {
  --bg: #0b0d12;
  --bg-2: #11151d;
  --panel: #161b25;
  --panel-2: #1d2330;
  --line: #2a3142;
  --text: #e6ecf5;
  --muted: #8a93a6;
  --accent: #ff6a00;
  --accent-2: #ffd23f;
  --danger: #ff3b3b;
  --good: #3ddc97;
  --blue: #4cc2ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 800px at 50% -200px, #1a2030 0%, var(--bg) 60%);
  color: var(--text);
  overflow: hidden;
}

#app { width: 100vw; height: 100vh; position: relative; }

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; }

/* ---------- Title ---------- */
#screen-title { align-items: center; justify-content: center; }
.bg-grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(circle at 50% 50%, black 30%, transparent 75%);
  pointer-events: none;
  z-index: 0;
}
.title-wrap {
  position: relative; z-index: 1; text-align: center;
  display: flex; flex-direction: column; align-items: center;
}
.logo-img {
  width: clamp(520px, 80vw, 1080px);
  height: auto;
  margin: 0 0 12px;
  filter: drop-shadow(0 16px 48px rgba(255,106,0,0.32));
  animation: logoFloat 4s ease-in-out infinite;
}
@keyframes logoFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}
.tagline {
  color: var(--muted);
  margin: 8px 0 32px;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 600;
}
.hint { color: var(--muted); margin-top: 28px; font-size: 12px; letter-spacing: 0.05em; }

/* ---------- Buttons ---------- */
.btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
  letter-spacing: 0.04em;
}
.btn:hover { background: var(--panel-2); border-color: #3a4258; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, #ff7a1f, #d24d00);
  border-color: #ff8a3a;
  color: white;
  box-shadow: 0 6px 20px rgba(255,106,0,0.25);
}
.btn-primary:hover { background: linear-gradient(180deg, #ff8a3a, #e25a07); }
.btn-ghost { background: transparent; }
.btn-pro {
  background: linear-gradient(180deg, #2d2050, #1a0f3a);
  border: 1px solid #b06bff;
  color: #fff;
  box-shadow: 0 0 16px rgba(176,107,255,0.25);
}
.btn-pro:hover { background: linear-gradient(180deg, #3a2966, #221555); border-color: #c98bff; }
.btn-bolts {
  background: linear-gradient(180deg, #fdc842, #d29400);
  border-color: #ffd966;
  color: #1a0f00;
  font-weight: 800;
}
.btn-bolts:hover { background: linear-gradient(180deg, #ffd95a, #e0a300); }
.btn-crowns {
  background: linear-gradient(180deg, #b06bff, #7400b8);
  border-color: #c98bff;
  color: #fff;
  font-weight: 800;
}
.btn-crowns:hover { background: linear-gradient(180deg, #c98bff, #8517d4); }
.btn-bolts:disabled, .btn-crowns:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.topbar h2 { margin: 0; font-size: 18px; letter-spacing: 0.1em; text-transform: uppercase; }
.topbar-actions { display: flex; gap: 10px; }

/* ---------- Builder ---------- */
.builder-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  overflow: auto;
}
.panel h3 {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex; align-items: center; justify-content: space-between;
}
.preview-panel { display: flex; flex-direction: column; align-items: center; gap: 12px; }
#preview-canvas {
  width: 100%; max-width: 320px; aspect-ratio: 1/1;
  background: #0a0d13;
  border: 1px solid var(--line);
  border-radius: 8px;
  image-rendering: pixelated;
}
.name-row, .color-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
}
.name-row label, .color-row label {
  font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); width: 60px;
}
.name-row input {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
}
.swatch-row { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.selected { border-color: white; box-shadow: 0 0 0 2px var(--accent); }
.swatch-sm { width: 18px; height: 18px; }
.pattern-row { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.pattern-btn {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 5px;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.04em;
}
.pattern-btn:hover { border-color: #3a4258; color: var(--text); }
.pattern-btn.selected { background: var(--accent); color: #0a0d13; border-color: var(--accent); }
.radar-wrap {
  width: 100%;
  display: flex; justify-content: center;
  margin-top: 6px;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}
#radar-canvas { width: 100%; max-width: 280px; height: auto; }

/* Tabs */
.tab-panel { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  padding: 0 8px;
  flex: 0 0 auto;
}
.tab-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 14px 20px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s, border-color 0.12s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content {
  flex: 1;
  overflow: auto;
  padding: 14px;
}
.tab-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.tab-header-info {
  font-size: 13px;
  color: var(--muted);
}
.tab-header-info b { color: var(--text); }

/* Card list / grid */
.card-list { display: flex; flex-direction: column; gap: 8px; }
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
}
.card:hover { border-color: #3a4258; }
.card:active { transform: translateY(1px); }
.card.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255,106,0,0.4), 0 0 14px rgba(255,106,0,0.1);
}
.card.disabled { opacity: 0.4; cursor: not-allowed; }
.card.disabled:hover { border-color: var(--line); }
.big-card { padding: 12px 14px; }
.card-title {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700;
  margin-bottom: 4px;
  gap: 8px;
}
.card-desc { font-size: 12px; color: var(--muted); line-height: 1.4; }
.card-tag {
  font-size: 10px; letter-spacing: 0.15em; text-transform: uppercase;
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
  padding: 2px 6px;
  color: var(--accent-2);
  flex: 0 0 auto;
  white-space: nowrap;
}
.mod-bonus {
  margin-top: 8px;
  font-size: 11px;
  color: var(--blue);
  letter-spacing: 0.02em;
}

/* Stats */
.stats-panel { display: flex; flex-direction: column; }
.stat-row {
  display: grid;
  grid-template-columns: 80px 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
}
.stat-row:last-child { border-bottom: none; }
.stat-name { font-size: 13px; letter-spacing: 0.05em; text-transform: uppercase; }
.stat-bar {
  height: 8px; background: var(--bg-2); border-radius: 4px; overflow: hidden;
}
.stat-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 4px;
  transition: width 0.15s;
}
.stat-val { width: 22px; text-align: center; font-variant-numeric: tabular-nums; }
.stat-btn {
  width: 26px; height: 26px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}
.stat-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.stat-btn:hover:not(:disabled) { background: var(--panel-2); }
.pts { color: var(--accent-2); font-weight: 700; letter-spacing: 0; }
.stats-summary {
  margin-top: 12px;
  padding: 10px;
  background: var(--bg-2);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}
.stats-summary b { color: var(--text); }

/* ---------- Arena ---------- */
.arena-topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 20px;
  padding: 10px 22px;
}
.hud-bot {
  display: flex; flex-direction: column; gap: 4px;
}
.hud-bot.right { align-items: flex-end; }
.hud-name { font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); }
.hud-bar {
  width: 320px; height: 12px;
  background: #1c2230;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.hud-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--good), #2bbf85);
  width: 100%;
  transition: width 0.15s;
}
.hud-fill.low { background: linear-gradient(90deg, var(--accent), var(--danger)); }
.arena-center { text-align: center; }
#round-label { font-size: 11px; letter-spacing: 0.2em; color: var(--muted); }
#match-timer {
  font-size: 32px; font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--accent-2);
  text-shadow: 0 0 18px rgba(255,210,63,0.35);
  line-height: 1;
}
.arena-wrap {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  background: #07090d;
}
#arena-canvas {
  background: #0a0d13;
  border: 2px solid var(--line);
  border-radius: 6px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 140px);
}
.controls-hint {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  color: var(--muted); font-size: 12px;
  display: flex; align-items: center; gap: 4px;
}
kbd {
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11px;
  font-family: inherit;
  color: var(--text);
  margin: 0 2px;
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute; inset: 0;
  background: rgba(7, 9, 13, 0.78);
  display: flex; align-items: center; justify-content: center;
  z-index: 5;
}
.overlay.hidden { display: none; }
.overlay-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 32px;
  text-align: center;
  display: flex; flex-direction: column; gap: 10px;
  min-width: 280px;
}
.overlay-card.big { padding: 40px 56px; min-width: 360px; }
.overlay-card h2 { margin: 0 0 8px; font-size: 28px; letter-spacing: 0.05em; }
.result-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

#screen-result { align-items: center; justify-content: center; }
#result-sub { color: var(--muted); margin: 0; }

@media (max-width: 1100px) {
  .builder-grid { grid-template-columns: 320px 1fr; }
}
@media (max-width: 900px) {
  .builder-grid { grid-template-columns: 1fr; }
  .preview-panel { max-height: 50vh; }
  .hud-bar { width: 180px; }
}
.stats-list { display: flex; flex-direction: column; }

/* ===========================================================================
   Title screen extras
   =========================================================================== */
.title-actions { display: flex; gap: 12px; }

/* ===========================================================================
   Balance HUD
   =========================================================================== */
.balance-hud {
  display: flex;
  align-items: center;
  gap: 8px;
}
#balance-hud-title {
  position: absolute;
  top: 22px; right: 28px;
  z-index: 2;
}
.bal-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.bal-bolts  { color: #ffd23f; border-color: rgba(253,200,66,0.4); }
.bal-crowns { color: #c98bff; border-color: rgba(176,107,255,0.4); }
.bal-pro {
  background: linear-gradient(135deg, #b06bff, #ff6a00);
  color: white;
  border: none;
  letter-spacing: 0.18em;
  box-shadow: 0 0 14px rgba(176,107,255,0.5);
  animation: proPulse 2.4s ease-in-out infinite;
}
@keyframes proPulse {
  0%, 100% { box-shadow: 0 0 12px rgba(176,107,255,0.4); }
  50%      { box-shadow: 0 0 22px rgba(255,106,0,0.5); }
}
.bal-icon { font-size: 14px; line-height: 1; }

/* ===========================================================================
   Lock badges in builder
   =========================================================================== */
.card.pro-card {
  border-color: rgba(176,107,255,0.45);
}
.card.pro-card.selected {
  box-shadow: inset 0 0 0 1px rgba(176,107,255,0.6), 0 0 14px rgba(176,107,255,0.18);
}
.card-tag.pro {
  background: linear-gradient(135deg, #b06bff, #ff6a00);
  color: white;
  letter-spacing: 0.15em;
}
.card.locked {
  opacity: 0.85;
  position: relative;
}
.card.locked .card-desc { opacity: 0.6; }
.card.locked::before {
  content: '';
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    45deg,
    rgba(0,0,0,0.0) 0 8px,
    rgba(176,107,255,0.05) 8px 16px
  );
  pointer-events: none;
  border-radius: inherit;
}
.lock-badge {
  margin-top: 8px;
  background: rgba(176,107,255,0.10);
  border: 1px solid rgba(176,107,255,0.4);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 700;
  color: #c98bff;
  display: inline-block;
  letter-spacing: 0.04em;
}
.swatch.locked {
  background: var(--bg-2) !important;
  border: 1px dashed rgba(176,107,255,0.6) !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.swatch.pro:not(.locked) {
  box-shadow: 0 0 0 1px rgba(176,107,255,0.5), 0 0 10px rgba(176,107,255,0.2);
}
.lock-mini {
  font-size: 11px;
  color: #c98bff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.pattern-btn.locked {
  border-color: rgba(176,107,255,0.4);
  color: #c98bff;
}
.pattern-btn.pro:not(.locked) {
  border-color: rgba(176,107,255,0.6);
  color: #c98bff;
}

/* ===========================================================================
   Store screen
   =========================================================================== */
.store-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 22px clamp(16px, 4vw, 56px);
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.store-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
}
.store-section-title {
  margin: 0 0 14px;
  font-size: 14px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.store-empty { color: var(--muted); margin: 0; }

/* Pro hero */
.store-hero { background: transparent; padding: 0; }
.pro-card {
  background: linear-gradient(135deg, #1d1438 0%, #0e0a1f 50%, #1a0a18 100%);
  border: 1px solid #b06bff;
  border-radius: 14px;
  padding: 26px 28px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 50px rgba(176,107,255,0.15);
}
.pro-card::before {
  content: '';
  position: absolute;
  top: -100px; right: -100px;
  width: 300px; height: 300px;
  background: radial-gradient(circle, rgba(255,106,0,0.18), transparent 70%);
  pointer-events: none;
}
.pro-active { border-color: #ffd23f; box-shadow: 0 0 50px rgba(255,210,63,0.18); }
.pro-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.pro-card-head h3 {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.14em;
  background: linear-gradient(90deg, #ffd23f, #ff6a00, #b06bff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.pro-tag {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.2em;
  padding: 4px 10px;
  border-radius: 4px;
  background: rgba(255,255,255,0.08);
  color: var(--muted);
}
.pro-benefits {
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 6px 18px;
  font-size: 13px;
  color: var(--text);
}
.pro-benefits li::marker { color: var(--accent-2); }
.plan-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  position: relative;
  z-index: 1;
}
.plan-card {
  position: relative;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(176,107,255,0.4);
  border-radius: 10px;
  padding: 16px 14px;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: transform 0.08s, border-color 0.15s, background 0.15s;
}
.plan-card:hover { background: rgba(176,107,255,0.10); border-color: #c98bff; transform: translateY(-2px); }
.plan-card.best {
  border-color: #ffd23f;
  background: linear-gradient(180deg, rgba(255,210,63,0.10), rgba(176,107,255,0.06));
}
.plan-badge {
  position: absolute;
  top: -10px; left: 50%; transform: translateX(-50%);
  background: #ffd23f;
  color: #0a0d13;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.2em;
  padding: 3px 8px;
  border-radius: 4px;
}
.plan-label { font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.plan-price { font-size: 26px; font-weight: 900; margin: 4px 0; }
.plan-save { font-size: 11px; color: #3ddc97; font-weight: 700; }
.pro-actions { margin-top: 12px; }

/* Crown packs */
.crown-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.crown-card {
  position: relative;
  background: linear-gradient(180deg, rgba(176,107,255,0.10), rgba(176,107,255,0.04));
  border: 1px solid rgba(176,107,255,0.35);
  border-radius: 10px;
  padding: 18px 14px 14px;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: transform 0.08s, border-color 0.15s, background 0.15s;
}
.crown-card:hover { background: rgba(176,107,255,0.14); border-color: #c98bff; transform: translateY(-2px); }
.crown-card.hot { border-color: #ff6a00; background: linear-gradient(180deg, rgba(255,106,0,0.14), rgba(255,106,0,0.05)); }
.crown-card.best { border-color: #ffd23f; background: linear-gradient(180deg, rgba(255,210,63,0.14), rgba(176,107,255,0.05)); }
.crown-flag {
  position: absolute;
  top: -8px; right: 10px;
  background: #ff6a00;
  color: white;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.18em;
  padding: 3px 8px;
  border-radius: 4px;
}
.crown-flag.best { background: #ffd23f; color: #0a0d13; right: auto; left: 10px; }
.crown-amt { font-size: 24px; font-weight: 900; color: #c98bff; }
.crown-icon { font-size: 22px; }
.crown-bonus { font-size: 11px; color: #3ddc97; font-weight: 700; min-height: 14px; }
.crown-price { font-size: 18px; font-weight: 900; margin-top: 6px; }
.crown-label { font-size: 10px; letter-spacing: 0.2em; color: var(--muted); margin-top: 2px; }

/* Store cards */
.store-card .card-tag.pro {
  background: linear-gradient(135deg, #b06bff, #ff6a00);
  color: white;
}
.store-prices, .paint-prices { display: flex; gap: 8px; margin-top: 10px; }
.store-owned, .paint-owned {
  margin-top: 10px;
  font-size: 12px;
  font-weight: 800;
  color: #3ddc97;
  letter-spacing: 0.08em;
}

/* Paint grid in store */
.paint-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.paint-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}
.paint-card.owned { border-color: #3ddc97; background: rgba(61,220,151,0.05); }
.paint-swatch {
  width: 100%;
  height: 60px;
  border-radius: 8px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  box-shadow: inset 0 0 12px rgba(0,0,0,0.35);
}
.paint-name { font-size: 13px; font-weight: 700; }

/* Demo notice */
.store-demo {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  border: 1px dashed var(--line);
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 18px;
}
.store-demo strong { color: var(--accent); }

/* Unlock dialog */
.unlock-card { min-width: 340px; padding: 22px; }
.unlock-card h2 { font-size: 22px; margin-bottom: 4px; }
.unlock-card p { color: var(--muted); margin: 0 0 14px; font-size: 13px; }
.unlock-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}
#unlock-preview { display: flex; justify-content: center; margin-bottom: 12px; }
#unlock-preview .paint-swatch { width: 160px; height: 70px; margin-bottom: 0; }
.unlock-tag {
  background: linear-gradient(135deg, #b06bff, #ff6a00);
  color: white;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.2em;
  padding: 6px 14px;
  border-radius: 4px;
}

/* Reward line on result screen */
.reward-line {
  margin-top: 14px;
  font-size: 16px;
  font-weight: 800;
  color: #ffd23f;
  letter-spacing: 0.05em;
}

/* Toast */
#toast-zone {
  position: fixed;
  bottom: 30px; left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 8px 28px rgba(0,0,0,0.5);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ===========================================================================
   Multiplayer / Auth / Ladder
   =========================================================================== */

/* Secondary button (less heavy than primary, but more prominent than ghost) */
.btn-secondary {
  background: linear-gradient(180deg, #2a3650, #1a2238);
  color: #e6edff;
  border-color: #3a4978;
  font-weight: 800;
}
.btn-secondary:hover {
  background: linear-gradient(180deg, #364d7c, #1f2a47);
  border-color: #5a72b8;
}

/* Title top-right container for balance + account pill */
.title-topright {
  position: absolute;
  top: 22px; right: 28px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.title-topright #balance-hud-title {
  position: static;
}

.account-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
  min-height: 24px;
}
.account-pill:empty { display: none; }
.acct-dot {
  width: 7px; height: 7px;
  background: #4ade80;
  border-radius: 50%;
  box-shadow: 0 0 8px #4ade80;
}
.acct-name { font-weight: 800; }
.acct-stats { color: var(--muted); font-weight: 600; }
.acct-link {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  cursor: pointer;
  border-left: 1px solid var(--line);
  padding-left: 8px;
}

.title-actions.slim {
  margin-top: 4px;
  gap: 8px;
}
.title-actions.slim .btn { padding: 6px 14px; font-size: 12px; }

/* --------------------------- Arena MP overlay --------------------------- */
.mp-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}
.mp-overlay.hidden { display: none; }

.mp-banner {
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  background: rgba(7, 9, 13, 0.78);
  border: 1px solid var(--line);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--text);
  text-transform: uppercase;
  pointer-events: none;
}
.mp-banner-count { color: #ffd23f; border-color: #ffd23f; }
.mp-banner-result { color: #4ade80; border-color: #4ade80; }
.mp-banner-bad    { color: #ff6b6b; border-color: #ff6b6b; }

.mp-scoreboard {
  position: absolute;
  top: 56px; right: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(7, 9, 13, 0.7);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 700;
  min-width: 180px;
  pointer-events: none;
}
.sb-row {
  display: grid;
  grid-template-columns: 1fr 56px 28px 36px;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  color: var(--text);
}
.sb-row.me .sb-name { color: #ffd23f; }
.sb-row.dead { opacity: 0.45; text-decoration: line-through; }
.sb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-hp {
  background: #2a3041;
  border-radius: 3px;
  height: 6px;
  overflow: hidden;
}
.sb-hp-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #4ade80, #ffd23f);
}
.sb-row.me .sb-hp-fill { background: linear-gradient(90deg, #ff6a00, #ffd23f); }
.sb-k { color: var(--muted); text-align: right; }
.sb-score { color: #ffd23f; text-align: right; }

.mp-quit {
  position: absolute;
  bottom: 14px; right: 14px;
  pointer-events: auto;
  font-size: 11px;
  padding: 6px 12px;
}

/* --------------------------- MP result modal --------------------------- */
.mp-result-card { min-width: 360px; max-width: 480px; }
.mp-result-board {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 8px 0 12px;
  font-size: 12px;
}
.mp-result-row {
  display: grid;
  grid-template-columns: 36px 1fr 56px 36px;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  background: var(--bg-2);
  border-radius: 4px;
}
.mp-result-row.me { background: rgba(255, 106, 0, 0.18); }
.mp-result-row.winner {
  background: linear-gradient(90deg, rgba(255, 210, 63, 0.2), rgba(255, 106, 0, 0.2));
  border: 1px solid #ffd23f;
}
.mp-result-row .rr-rank { color: var(--muted); font-weight: 800; }
.mp-result-row .rr-name { font-weight: 800; }
.mp-result-row .rr-score { color: #ffd23f; text-align: right; }
.mp-result-row .rr-k { color: var(--muted); text-align: right; }
.mp-result-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

/* --------------------------- Auth modal --------------------------- */
.auth-card { min-width: 320px; max-width: 380px; text-align: left; }
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.auth-tab {
  flex: 1;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 10px 0;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
.auth-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.auth-form input {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  outline: none;
}
.auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 106, 0, 0.18);
}
.auth-error {
  background: rgba(255, 80, 80, 0.12);
  border: 1px solid rgba(255, 100, 100, 0.4);
  color: #ff8e8e;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 12px;
  margin: 0;
}
.auth-display.hidden { display: none; }

/* --------------------------- Ladder modal --------------------------- */
.ladder-card { min-width: 380px; max-width: 480px; max-height: 70vh; }
.ladder-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 55vh;
  overflow-y: auto;
  margin: 8px 0 14px;
  text-align: left;
}
.ladder-empty { color: var(--muted); margin: 16px 0; text-align: center; }
.ladder-row {
  display: grid;
  grid-template-columns: 32px 1fr 36px 80px 90px;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-2);
  border-radius: 4px;
  font-size: 12px;
}
.ladder-row .lr-rank  { color: var(--muted); font-weight: 800; }
.ladder-row .lr-name  { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ladder-row .lr-level { color: #ffd23f; font-weight: 800; }
.ladder-row .lr-rp    { color: var(--accent); font-weight: 800; text-align: right; }
.ladder-row .lr-wk    { color: var(--muted); text-align: right; }

/* ===========================================================================
   Install (PWA) hint
   =========================================================================== */
.install-hint {
  margin-top: 6px;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(20, 26, 38, 0.85);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  max-width: 360px;
  text-align: center;
}
.install-hint.hidden { display: none; }

/* ===========================================================================
   Touch / mobile controls
   =========================================================================== */
.touch-controls {
  position: absolute; inset: 0;
  pointer-events: none;          /* let the canvas under us still receive */
  z-index: 4;
}
.touch-controls.hidden { display: none; }

.touch-controls .tc-joystick,
.touch-controls .tc-right,
.touch-controls .tc-btn {
  pointer-events: auto;          /* but our actual control surfaces do */
}

.tc-joystick {
  position: absolute;
  left: max(env(safe-area-inset-left, 0px), 16px);
  bottom: max(env(safe-area-inset-bottom, 0px), 16px);
  width: 180px; height: 180px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.tc-joy-base {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: rgba(15, 20, 30, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 0 28px rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.tc-joystick.active .tc-joy-base {
  border-color: rgba(120, 180, 255, 0.6);
  box-shadow: inset 0 0 28px rgba(0,0,0,0.55), 0 0 14px rgba(95, 168, 255, 0.35);
}
.tc-joy-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 80px; height: 80px;
  margin-left: -40px; margin-top: -40px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #5fa8ff, #2c6fd8 70%, #1a4796);
  border: 2px solid rgba(255,255,255,0.4);
  box-shadow: 0 4px 18px rgba(0,0,0,0.5);
  pointer-events: none;          /* parent handles all events */
}

.tc-right {
  position: absolute;
  right: max(env(safe-area-inset-right, 0px), 18px);
  bottom: max(env(safe-area-inset-bottom, 0px), 18px);
  display: flex; flex-direction: column-reverse; gap: 12px;
  align-items: flex-end;
}
.tc-btn {
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 50%;
  font-weight: 900;
  font-family: inherit;
  letter-spacing: 0.05em;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.45);
}
.tc-btn:active,
.tc-btn.active {
  transform: scale(0.94);
  filter: brightness(1.15);
}
.tc-fire {
  width: 120px; height: 120px;
  font-size: 22px;
  background: radial-gradient(circle at 30% 30%, #ff8a4c, #d43c1a 70%, #7a1d0c);
  transition: opacity 0.15s, filter 0.15s, background 0.15s;
}
/* Passive weapon: button becomes a non-actionable "AUTO" indicator. */
.tc-fire.passive {
  background: radial-gradient(circle at 30% 30%, #4a5360, #262c36 70%, #15181f);
  border-color: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.55);
  font-size: 16px;
  letter-spacing: 0.12em;
  opacity: 0.7;
  cursor: default;
}
.tc-fire.passive:active,
.tc-fire.passive.active {
  transform: none;
  filter: none;
}
.tc-pause {
  width: 56px; height: 56px;
  font-size: 18px;
  background: rgba(20, 26, 38, 0.75);
  border-color: rgba(255,255,255,0.2);
}

/* On touch devices, hide the desktop WASD/space hint to save space, and
   stop the page from scrolling/zooming while playing. */
body.touch-mode .controls-hint { display: none; }
body.touch-mode #screen-arena.active { overflow: hidden; touch-action: none; }
body.touch-mode #arena-canvas { touch-action: none; }

/* In-arena toast (used to explain AUTO weapons, etc.) */
.tc-toast {
  position: absolute;
  left: 50%; top: 14px;
  transform: translate(-50%, -8px);
  background: rgba(15, 20, 30, 0.92);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 14px;
  max-width: calc(100vw - 40px);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 6;
  box-shadow: 0 6px 20px rgba(0,0,0,0.45);
}
.tc-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ===========================================================================
   Mobile responsive tweaks
   =========================================================================== */
@media (max-width: 760px) {
  /* Keep the canvas as large as possible: shrink the topbar HUD. */
  .arena-topbar {
    padding: 6px 8px;
    gap: 6px;
  }
  .hud-bot { gap: 4px; }
  .hud-name { font-size: 10px; letter-spacing: 0.1em; }
  .hud-bar { width: 110px; height: 8px; }
  #round-label { font-size: 9px; }
  #match-timer { font-size: 22px; }

  #arena-canvas {
    max-width: 100vw;
    max-height: calc(100dvh - 90px);
    border-radius: 0;
    border-left: none; border-right: none;
  }
  .arena-wrap { padding: 0; }

  /* Title screen: stack the action buttons full-width */
  .title-actions { flex-direction: column; width: 100%; gap: 10px; }
  .title-actions .btn { width: 100%; }
  .title-actions.slim { flex-direction: row; }
  .title-wrap { padding: 24px 18px; gap: 14px; }
  .logo-img { max-width: 80vw; height: auto; }
  .tagline { font-size: 14px; }

  /* Top-bars on builder/store: allow wrapping */
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .topbar h2 { font-size: 16px; }
  .topbar-actions { flex-wrap: wrap; gap: 6px; }
  .topbar-actions .btn { padding: 6px 10px; font-size: 12px; }

  /* Account pill / balance HUD shouldn't overflow */
  #balance-hud-title {
    position: static; margin: 0 auto 8px;
  }
  .title-topright {
    position: static;
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    margin-bottom: 8px;
  }

  /* Auth / overlay cards: fit narrow screens */
  .overlay-card {
    min-width: 0;
    width: calc(100vw - 32px);
    max-width: 360px;
    padding: 20px 18px;
  }
  .overlay-card.big { padding: 24px 20px; min-width: 0; }

  /* Shop store list: single column */
  .store-wrap { padding: 12px; }
}

/* Very narrow phones: shrink slightly so controls don't overlap. */
@media (max-width: 380px) {
  .tc-joystick { width: 150px; height: 150px; }
  .tc-joy-knob { width: 70px; height: 70px; margin-left: -35px; margin-top: -35px; }
  .tc-fire { width: 100px; height: 100px; font-size: 18px; }
  .tc-pause { width: 48px; height: 48px; font-size: 14px; }
}

/* Landscape phones: shrink but keep generous tap targets. */
@media (max-height: 480px) and (pointer: coarse) {
  .tc-joystick { width: 140px; height: 140px; bottom: 10px; left: 10px; }
  .tc-joy-knob { width: 64px; height: 64px; margin-left: -32px; margin-top: -32px; }
  .tc-fire { width: 96px; height: 96px; font-size: 18px; }
  .tc-pause { width: 48px; height: 48px; font-size: 14px; }
  .tc-right  { right: 10px; bottom: 10px; gap: 10px; }
}

/* ===========================================================================
   Presets
   =========================================================================== */
.presets-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.presets-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.presets-header label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.presets-actions {
  display: flex;
  gap: 6px;
}
.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
  border-radius: 4px;
}
.preset-dropdown {
  position: relative;
  margin-top: 4px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  max-height: 200px;
  overflow-y: auto;
}
.preset-dropdown.hidden {
  display: none;
}
.preset-list {
  display: flex;
  flex-direction: column;
}
.preset-empty {
  padding: 12px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.preset-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.preset-item:last-child {
  border-bottom: none;
}
.preset-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.preset-actions {
  display: flex;
  gap: 4px;
}
.preset-btn {
  padding: 3px 8px;
  font-size: 10px;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: var(--bg-1);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.preset-btn:hover {
  background: var(--bg-2);
  border-color: var(--accent);
}
.preset-delete {
  color: #e74c3c;
}
.preset-delete:hover {
  background: rgba(231, 76, 60, 0.1);
  border-color: #e74c3c;
}
