:root {
  --ink: #e9e4d8;
  --muted: rgba(233, 228, 216, 0.62);
  --panel: rgba(14, 17, 20, 0.62);
  --panel-edge: rgba(255, 255, 255, 0.10);
  --gold: #e8c060;
  --gold-dim: rgba(232, 192, 96, 0.35);
  --green: #6fd27a;
  --red: #ff6b6b;
  --blue: #7fc8ff;
  --font: "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0d10; font-family: var(--font); color: var(--ink); }
#c { display: block; width: 100%; height: 100%; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; user-select: none; }
#hitflash { position: absolute; inset: 0; opacity: 0; background: radial-gradient(ellipse at center, rgba(160, 0, 0, 0) 55%, rgba(200, 10, 10, 0.72) 100%); }
#top { position: absolute; top: 14px; left: 14px; right: 14px; display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; }
.panel {
  background: linear-gradient(180deg, rgba(20, 24, 28, 0.72), rgba(10, 12, 15, 0.62));
  border: 1px solid var(--panel-edge); border-top-color: rgba(255, 255, 255, 0.18);
  border-radius: 8px; padding: 9px 14px; min-width: 160px; font-size: 13px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(6px);
}
#phase { font-weight: 800; letter-spacing: 3px; font-size: 13px; color: var(--muted); }
#timer { font-size: 32px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5); }
#wave { font-size: 12px; color: var(--muted); margin-top: 2px; letter-spacing: 1px; }
.label { font-size: 10px; letter-spacing: 2.5px; color: var(--muted); margin-top: 5px; }
.bar { width: 240px; height: 9px; background: rgba(255, 255, 255, 0.08); border-radius: 4px; overflow: hidden; margin-top: 3px; box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5); }
.fill { height: 100%; width: 100%; transition: width 0.15s; border-radius: 4px; }
.fill.tower { background: linear-gradient(90deg, #c99a3a, var(--gold)); box-shadow: 0 0 8px rgba(232, 192, 96, 0.35); }
.fill.hp { background: linear-gradient(90deg, #3fa650, var(--green)); box-shadow: 0 0 8px rgba(111, 210, 122, 0.35); }
#budget { font-size: 21px; font-weight: 800; color: var(--gold); text-shadow: 0 0 12px rgba(232, 192, 96, 0.25); font-variant-numeric: tabular-nums; }
#kills { color: var(--muted); font-size: 12px; margin-top: 2px; }
#squad { color: var(--blue); font-size: 12px; margin-top: 2px; }
#tally { color: var(--blue); opacity: 0.8; font-size: 11px; margin-top: 2px; max-width: 250px; }
#era { font-size: 10px; color: var(--muted); letter-spacing: 2px; margin-top: 5px; }

#crosshair { position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border: 1.5px solid rgba(255, 255, 255, 0.75); border-radius: 50%; box-shadow: 0 0 3px rgba(0, 0, 0, 0.8), inset 0 0 3px rgba(0, 0, 0, 0.6); }
#crosshair::after { content: ""; position: absolute; left: 5.5px; top: 5.5px; width: 2px; height: 2px; background: #fff; border-radius: 1px; }

#msg { position: absolute; left: 0; right: 0; top: 22%; text-align: center; font-size: 36px; font-weight: 900; letter-spacing: 4px; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9), 0 0 24px rgba(0, 0, 0, 0.6); opacity: 0; transform: translateY(6px); transition: opacity 0.3s, transform 0.3s; }
#msg.show { opacity: 1; transform: translateY(0); }
#prompt { position: absolute; left: 0; right: 0; top: 56%; text-align: center; font-size: 14px; letter-spacing: 1px; color: var(--ink); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9); }
#prompt:empty { display: none; }

#bottom { position: absolute; bottom: 16px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 7px; }
#mode { font-size: 11px; letter-spacing: 4px; font-weight: 800; background: var(--panel); border: 1px solid var(--panel-edge); padding: 4px 12px; border-radius: 5px; }
#mode.fight { color: var(--red); }
#mode.build { color: var(--blue); }
#hotbar { display: flex; gap: 7px; flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 32px); }
.slot {
  width: 92px; height: 60px; padding: 6px 8px; font-size: 12px; border-radius: 7px;
  background: linear-gradient(180deg, rgba(22, 26, 30, 0.78), rgba(10, 12, 15, 0.7));
  border: 1.5px solid var(--panel-edge); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  transition: border-color 0.12s, transform 0.12s, background 0.12s;
}
.slot.active { border-color: var(--gold); background: linear-gradient(180deg, rgba(70, 52, 14, 0.78), rgba(38, 28, 6, 0.75)); transform: translateY(-3px); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45), 0 0 12px var(--gold-dim); }
.slot.poor { opacity: 0.42; }
.slot .k { font-size: 10px; color: var(--muted); font-family: var(--mono); }
.slot .n { font-weight: 700; margin-top: 1px; }
.slot .c { color: var(--gold); font-size: 11px; }
#hint { font-size: 11px; color: var(--muted); letter-spacing: 0.3px; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); }

/* ---------- overlay ---------- */
#overlay { position: fixed; inset: 0; background: radial-gradient(ellipse at center, rgba(8, 10, 14, 0.55), rgba(4, 5, 8, 0.88)); display: flex; align-items: center; justify-content: center; cursor: pointer; }
#overlay.hidden { display: none; }
.card {
  max-width: 580px; padding: 30px 38px; text-align: center; border-radius: 12px;
  background: linear-gradient(180deg, rgba(22, 26, 32, 0.96), rgba(12, 14, 18, 0.96));
  border: 1px solid rgba(255, 255, 255, 0.12); border-top-color: rgba(232, 192, 96, 0.5);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.card h1 { margin: 0; letter-spacing: 10px; font-size: 42px; font-weight: 900; color: var(--gold); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6), 0 0 28px rgba(232, 192, 96, 0.25); }
.card .sub { color: var(--muted); margin-top: 6px; letter-spacing: 0.5px; }
.card p { line-height: 1.55; }
.card .controls { font-size: 12px; color: var(--muted); line-height: 1.8; border-top: 1px solid rgba(255, 255, 255, 0.08); padding-top: 12px; }
.card .click { font-weight: 800; color: var(--gold); font-size: 18px; margin-top: 16px; letter-spacing: 1px; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
.card .era-links { font-size: 12px; color: var(--muted); }
.card a { color: var(--blue); text-decoration: none; border-bottom: 1px solid rgba(127, 200, 255, 0.35); }
#shopbtn { position: fixed; top: 96px; left: 12px; z-index: 30; pointer-events: auto; background: rgba(60,45,0,0.85); color: #ffd36a; border: 1px solid #ffd36a; border-radius: 5px; padding: 5px 10px; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
#shopbtn.hidden, #shop.hidden { display: none; }
#shop { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 40; width: min(540px, calc(100vw - 32px)); background: rgba(15,20,28,0.96); border: 1px solid rgba(255,255,255,0.2); border-radius: 8px; padding: 12px; }
#shopitems { max-height: calc(100vh - 150px); overflow-y: auto; padding-right: 4px; }
#shop button { font: inherit; cursor: pointer; }
#shop .tabs { display: flex; gap: 6px; margin-bottom: 10px; }
#shop .tab { flex: 1; background: rgba(255,255,255,0.08); color: #eee; border: 1px solid rgba(255,255,255,0.18); border-radius: 5px; padding: 6px; font-weight: 700; }
#shop .tab.active { background: rgba(60,45,0,0.8); border-color: #ffd36a; color: #ffd36a; }
#shop .close { background: none; border: 0; color: #eee; font-size: 20px; padding: 0 8px; }
#shop .item { padding: 9px 6px; border-bottom: 1px solid rgba(255,255,255,0.08); font-size: 13px; }
#shop .item.off { opacity: 0.72; }
#shop .item .head { display: flex; align-items: baseline; gap: 10px; }
#shop .item .n { font-weight: 800; font-size: 15px; flex: 1; }
#shop .item .own { opacity: 0.75; font-size: 12px; }
#shop .item .c { color: #ffd36a; font-size: 13px; font-weight: 700; }
#shop .item .role { margin-top: 3px; }
#shop .item .vs { margin-top: 1px; opacity: 0.68; font-size: 12px; }
#shop .item .stats { margin-top: 3px; color: #a6d8ff; font-family: var(--mono); font-size: 11px; }
#shop .item .act { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 5px; min-height: 26px; }
#shop .item .why { color: var(--red); font-size: 12px; font-weight: 700; flex: 1; }
#shop .item button { background: rgba(90,180,110,0.25); color: #d6ffe0; border: 1px solid rgba(90,180,110,0.7); border-radius: 4px; padding: 3px 10px; width: 92px; }
#shop .item button:disabled { background: rgba(255,255,255,0.05); color: #888; border-color: rgba(255,255,255,0.15); cursor: default; }
#shop .note, #shop .foot { font-size: 11px; opacity: 0.65; margin-top: 8px; }

/* The last wave's champion: one bar at the top of the screen. */
#champion { position: absolute; top: 96px; left: 50%; transform: translateX(-50%); width: 340px; text-align: center; color: #f2d0a0; font: 600 13px/1.4 system-ui, sans-serif; letter-spacing: 0.08em; text-shadow: 0 1px 2px #000; }
#champion.hidden { display: none; }
#capture { position: absolute; top: 130px; left: 50%; transform: translateX(-50%); width: 300px; text-align: center; color: #a8c8ff; font: 700 13px/1.4 system-ui, sans-serif; letter-spacing: 0.08em; text-shadow: 0 1px 2px #000; }
#capture.hidden { display: none; }
#capture .bar { margin-top: 3px; }
#capture.danger { color: #ff8a70; }
#champion .bar { margin-top: 3px; }
#overlay-body { white-space: pre-line; }

/* The frame-time overlay: backquote toggles it. */
#perf { position: fixed; top: 8px; left: 50%; transform: translateX(-50%); margin: 0; padding: 6px 10px; background: rgba(8, 10, 14, 0.78); color: #d8f0d0; font: 12px/1.35 Consolas, 'Courier New', monospace; z-index: 40; pointer-events: none; white-space: pre; display: none; }

.side-links a, .era-links a { color: #e8d48a; cursor: pointer; }
.side-links a.on, .era-links a.on { font-weight: 700; text-decoration: underline; }
#objective { position: absolute; top: 96px; left: 50%; transform: translateX(-50%); color: #f0e8c8; font-size: 13px; text-shadow: 0 1px 2px #000; pointer-events: none; }
