/* ============================================================
   BUG DEFENCE — style.css
   Dark IDE world. Tokens are overridden at runtime by tweaks.js
   (art-direction theme), defaults below = "infested".
   ============================================================ */

:root {
  --bg: #13131d; --panel: #171823; --panel-edge: #2a2e44;
  --text: #c7d0f0; --muted: #6b7394;
  --health: #9ece6a; --commits: #e0af68; --danger: #f7768e;
  --accent: #bb9af7; --core: #7aa2f7; --overlay-tint: rgba(247,118,142,.06);
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --disp: "Space Grotesk", system-ui, sans-serif;
  --r: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--mono); font-size: 14px;
  overflow: hidden; -webkit-font-smoothing: antialiased;
  transition: background .4s ease;
}
button { font-family: var(--mono); cursor: pointer; color: inherit; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--panel-edge); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: none; flex-direction: column; }
.screen.on { display: flex; }
.bg-grid::before {
  content: ''; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: linear-gradient(var(--panel-edge) 1px, transparent 1px), linear-gradient(90deg, var(--panel-edge) 1px, transparent 1px);
  background-size: 38px 38px; opacity: .14;
  mask-image: radial-gradient(ellipse 80% 80% at 50% 40%, #000 30%, transparent 100%);
}

/* ============================================================
   MENU
   ============================================================ */
#screen-menu { align-items: center; justify-content: center; text-align: center; }
.menu-inner { position: relative; z-index: 2; max-width: 720px; padding: 24px; }
.menu-eyebrow {
  font-size: 12px; letter-spacing: .42em; color: var(--danger); font-weight: 700;
  text-transform: uppercase; margin-bottom: 18px;
}
.menu-logo {
  font-family: var(--disp); font-weight: 700; font-size: clamp(54px, 11vw, 130px);
  line-height: .9; letter-spacing: -.03em; margin: 0;
  color: var(--text); position: relative;
}
.menu-logo .bug { color: var(--danger); }
.menu-logo .cursor { color: var(--health); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.menu-tag { color: var(--muted); font-size: 15px; margin: 20px auto 4px; max-width: 460px; line-height: 1.6; }
.menu-tag b { color: var(--commits); font-weight: 500; }
.menu-btns { display: flex; gap: 12px; justify-content: center; margin-top: 38px; flex-wrap: wrap; }
.menu-btns button {
  border: 1px solid var(--panel-edge); background: var(--panel); color: var(--text);
  padding: 14px 26px; border-radius: var(--r); font-size: 14px; font-weight: 500;
  letter-spacing: .02em; transition: .15s; display: inline-flex; align-items: center; gap: 9px;
}
.menu-btns button:hover { border-color: var(--accent); transform: translateY(-2px); }
.menu-btns .primary { background: var(--health); color: #0c1208; border-color: var(--health); font-weight: 700; }
.menu-btns .primary:hover { filter: brightness(1.08); }
.menu-foot { margin-top: 40px; color: var(--muted); font-size: 11px; letter-spacing: .1em; }
.menu-foot kbd { background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 4px; padding: 1px 6px; color: var(--text); }

/* ============================================================
   GAME
   ============================================================ */
#screen-game { background: var(--bg); }
#hud-top {
  display: flex; align-items: center; gap: 20px; padding: 0 18px; height: 60px;
  background: var(--panel); border-bottom: 1px solid var(--panel-edge); z-index: 5; flex: 0 0 auto;
}
.hud-brand { font-family: var(--disp); font-weight: 700; font-size: 17px; letter-spacing: .02em; display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.logo-dot { width: 11px; height: 11px; border-radius: 3px; background: var(--danger); box-shadow: 0 0 12px var(--danger); }
.hud-stat { display: flex; flex-direction: column; gap: 3px; min-width: 70px; }
.hud-stat.grow { flex: 1; max-width: 300px; }
.hud-k { font-size: 9.5px; letter-spacing: .18em; color: var(--muted); font-weight: 700; }
.hud-v { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hud-v.big { font-size: 18px; }
#commits-val { color: var(--commits); }
#sprint-val { color: var(--accent); }
.hud-bar { width: 96px; height: 7px; border-radius: 4px; background: #0008; overflow: hidden; border: 1px solid var(--panel-edge); }
.hud-bar.wide { width: 100%; }
.hud-bar span { display: block; height: 100%; background: var(--health); transition: width .2s; border-radius: 4px; }
#wave-fill { background: var(--danger); }
.hud-ctrls { display: flex; gap: 6px; margin-left: auto; }
.ic-btn {
  width: 38px; height: 38px; border-radius: 7px; border: 1px solid var(--panel-edge);
  background: #0003; color: var(--muted); font-size: 13px; font-weight: 700; transition: .12s;
}
.ic-btn:hover { color: var(--text); border-color: var(--accent); }
.ic-btn.active { background: var(--accent); color: #150f25; border-color: var(--accent); }

#board-area { flex: 1; display: flex; min-height: 0; position: relative; }
#board-wrap { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; min-width: 0; padding: 12px; position: relative; }
#board { background: var(--bg); border: 1px solid var(--panel-edge); border-radius: 6px; box-shadow: 0 0 0 1px #0006, 0 20px 60px -20px #000; cursor: crosshair; }

/* dock */
#dock { background: var(--panel); border-top: 1px solid var(--panel-edge); display: flex; align-items: stretch; gap: 14px; padding: 12px 16px; flex: 0 0 auto; z-index: 4; }
#palette { display: flex; gap: 8px; }
.tw-card {
  position: relative; width: 74px; border: 1px solid var(--panel-edge); background: #0004;
  border-radius: var(--r); padding: 4px 4px 6px; display: flex; flex-direction: column; align-items: center; gap: 1px; transition: .12s;
}
.tw-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.tw-card.sel { border-color: var(--health); background: color-mix(in srgb, var(--health) 12%, transparent); box-shadow: 0 0 0 1px var(--health); }
.tw-card.cant { opacity: .42; }
.tw-card canvas { pointer-events: none; }
.tw-name { font-size: 9.5px; font-weight: 600; line-height: 1.05; text-align: center; }
.tw-cost { font-size: 10px; color: var(--commits); font-weight: 600; }
.tw-key { position: absolute; top: 3px; left: 5px; font-size: 9px; color: var(--muted); }

.dock-div { width: 1px; background: var(--panel-edge); }
#spells { display: flex; gap: 8px; align-items: stretch; }
.sp-card {
  position: relative; overflow: hidden; width: 84px; border: 1px solid var(--panel-edge); background: #0004;
  border-radius: var(--r); padding: 8px 6px; display: flex; flex-direction: column; align-items: center; gap: 3px; transition: .12s;
}
.sp-card:hover { border-color: var(--accent); }
.sp-card.sel { border-color: var(--core); box-shadow: 0 0 0 1px var(--core); }
.sp-card.cant { opacity: .45; }
.sp-key { position: absolute; top: 4px; left: 6px; font-size: 9px; color: var(--muted); border: 1px solid var(--panel-edge); border-radius: 3px; padding: 0 4px; z-index: 1; }
.sp-ic { pointer-events: none; margin-top: 2px; }
.sp-name { font-size: 11px; font-weight: 600; margin-top: 1px; }
.sp-cost { font-size: 10px; color: var(--commits); }
.sp-cd { position: absolute; inset: 0; pointer-events: none; }
.sp-cd span { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(10,12,20,.78); display: block; height: 0; }

#runbar { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; justify-content: center; gap: 6px; min-width: 150px; }
#run-btn { background: var(--health); color: #0c1208; border: none; padding: 13px 22px; border-radius: var(--r); font-weight: 700; font-size: 14px; letter-spacing: .02em; transition: .12s; }
#run-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
#run-hint { font-size: 10.5px; color: var(--muted); max-width: 170px; text-align: right; line-height: 1.4; }

/* selection floating panel */
#sel-panel { position: absolute; left: 18px; bottom: 18px; width: 220px; background: var(--panel); border: 1px solid var(--accent); border-radius: 10px; padding: 12px; display: none; z-index: 6; box-shadow: 0 16px 40px -12px #000; }
#sel-panel.on { display: block; }
.sel-hd { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.sel-hd b { font-size: 13px; } .sel-hd span { font-size: 10px; color: var(--accent); }
.sel-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 10px; }
.sel-stats div { font-size: 11px; font-weight: 600; background: #0004; border-radius: 5px; padding: 4px 6px; display: flex; justify-content: space-between; }
.sel-stats i { color: var(--muted); font-style: normal; font-size: 9px; letter-spacing: .08em; }
.sel-btns { display: flex; gap: 6px; }
.sel-btns button { flex: 1; padding: 8px; border-radius: 6px; border: 1px solid var(--panel-edge); background: var(--health); color: #0c1208; font-weight: 700; font-size: 11px; }
.sel-btns button:disabled { opacity: .4; background: var(--panel); color: var(--muted); }
.sel-btns .sell { background: transparent; color: var(--danger); border-color: var(--danger); }

/* rail layout */
body[data-layout="rail"] #board-area { flex-direction: row; }
body[data-layout="rail"] #dock { flex-direction: column; border-top: none; border-left: 1px solid var(--panel-edge); width: 196px; flex: 0 0 196px; overflow-y: auto; }
body[data-layout="rail"] #palette { flex-wrap: wrap; justify-content: center; }
body[data-layout="rail"] #spells { flex-wrap: wrap; justify-content: center; }
body[data-layout="rail"] #runbar { margin-left: 0; align-items: stretch; }
body[data-layout="rail"] #run-hint { text-align: center; max-width: none; }
body[data-layout="rail"] .dock-div { width: auto; height: 1px; }

/* ============================================================
   OVERLAY (sprint complete / game over)
   ============================================================ */
.overlay { position: fixed; inset: 0; z-index: 30; display: none; align-items: center; justify-content: center; background: rgba(8,9,14,.78); backdrop-filter: blur(4px); }
.overlay.on { display: flex; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; } }
.ov-card { width: 380px; background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 14px; padding: 28px; box-shadow: 0 30px 80px -20px #000; }
.ov-card.big { width: 440px; }
.ov-tag { font-size: 11px; letter-spacing: .24em; font-weight: 700; color: var(--health); margin-bottom: 10px; }
.ov-tag.r { color: var(--danger); } .ov-tag.g { color: var(--health); }
.ov-card h2 { font-family: var(--disp); font-size: 26px; margin: 0 0 8px; letter-spacing: -.01em; }
.ov-card p { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 0 0 18px; }
.ov-row { display: flex; justify-content: space-between; padding: 9px 0; border-top: 1px solid var(--panel-edge); font-size: 13px; }
.ov-row span { color: var(--muted); } .ov-row b { font-variant-numeric: tabular-nums; }
.ov-row b.bonus { color: var(--health); }
.ov-card button { margin-top: 18px; width: 100%; padding: 13px; border: none; border-radius: var(--r); background: var(--health); color: #0c1208; font-weight: 700; font-size: 14px; transition: .12s; }
.ov-card button:hover { filter: brightness(1.1); }
.ov-btns { display: flex; gap: 10px; }
.ov-btns button.ghost { background: transparent; border: 1px solid var(--panel-edge); color: var(--text); }
.overlay.lose .ov-tag { color: var(--danger); }

/* ============================================================
   ROSTER + BESTIARY
   ============================================================ */
.page { position: fixed; inset: 0; z-index: 2; overflow-y: auto; padding: 0 0 60px; }
.page-hd { position: sticky; top: 0; z-index: 3; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--panel-edge); padding: 20px 40px; display: flex; align-items: center; gap: 20px; }
.back-btn { border: 1px solid var(--panel-edge); background: var(--panel); border-radius: 7px; padding: 9px 16px; font-size: 12px; }
.back-btn:hover { border-color: var(--accent); }
.page-hd h1 { font-family: var(--disp); font-size: 26px; margin: 0; letter-spacing: -.01em; }
.page-hd .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.grid { max-width: 1180px; margin: 28px auto 0; padding: 0 40px; display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }

.rcard, .bcard { background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 12px; padding: 16px; }
.rcard-hd, .bcard-hd { display: flex; gap: 12px; align-items: center; }
.rcard-hd canvas, .bcard-hd canvas { background: #0004; border-radius: 8px; flex: 0 0 auto; }
.rname, .bname { font-family: var(--disp); font-size: 17px; font-weight: 700; }
.rsub, .btag { font-size: 11px; color: var(--muted); }
.btag { color: var(--danger); }
.rcost { font-size: 12px; color: var(--commits); font-weight: 600; margin-top: 3px; }
.rblurb, .bblurb { font-size: 12px; color: var(--muted); line-height: 1.55; margin: 12px 0; }
.tree { display: flex; flex-direction: column; gap: 0; }
.tier { display: flex; align-items: center; gap: 11px; padding: 9px 0; border-top: 1px solid var(--panel-edge); }
.tier-n { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--accent); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex: 0 0 auto; }
.tier-name { font-size: 12px; font-weight: 600; }
.tier-stat { font-size: 10.5px; color: var(--muted); margin-top: 1px; }
.tier-cost { margin-left: auto; font-size: 11px; color: var(--commits); font-weight: 600; }

.bcard.boss { border-color: var(--danger); }
.bstats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.bstats div { font-size: 12px; font-weight: 600; background: #0004; border-radius: 6px; padding: 6px 8px; display: flex; justify-content: space-between; }
.bstats i { color: var(--muted); font-style: normal; font-size: 9px; letter-spacing: .06em; align-self: center; }
.bthreat { display: flex; justify-content: space-between; align-items: center; font-size: 10px; letter-spacing: .12em; color: var(--muted); }
.bthreat b { color: var(--danger); letter-spacing: 2px; font-size: 12px; }

/* ============================================================
   TWEAKS PANEL
   ============================================================ */
#tweaks {
  position: fixed; right: 16px; bottom: 16px; z-index: 100; width: 250px; display: none;
  background: color-mix(in srgb, var(--panel) 94%, #000); border: 1px solid var(--panel-edge);
  border-radius: 12px; box-shadow: 0 18px 50px -14px #000; overflow: hidden;
}
#tweaks.on { display: block; }
.tw-hd { display: flex; justify-content: space-between; align-items: center; padding: 11px 12px 11px 15px; border-bottom: 1px solid var(--panel-edge); }
.tw-hd b { font-family: var(--disp); font-size: 13px; }
.tw-x { background: none; border: none; color: var(--muted); font-size: 12px; }
.tw-x:hover { color: var(--text); }
.tw-body { padding: 12px 15px 16px; display: flex; flex-direction: column; gap: 10px; }
.tw-sect { font-size: 9.5px; letter-spacing: .14em; color: var(--muted); font-weight: 700; margin-top: 2px; }
.tw-row { display: flex; flex-direction: column; gap: 6px; }
.tw-row-h { flex-direction: row; align-items: center; justify-content: space-between; }
.tw-lbl { font-size: 12px; color: var(--text); }
.tw-note { font-size: 10.5px; color: var(--muted); line-height: 1.45; margin-top: -3px; }
.tw-seg { display: flex; background: #0005; border-radius: 7px; padding: 2px; gap: 2px; }
.tw-seg button { flex: 1; border: none; background: none; color: var(--muted); font-size: 11px; padding: 6px 4px; border-radius: 5px; font-weight: 500; }
.tw-seg button.on { background: var(--accent); color: #150f25; font-weight: 700; }
.tw-toggle { width: 40px; height: 22px; border-radius: 12px; border: 1px solid var(--panel-edge); background: #0005; position: relative; padding: 0; }
.tw-toggle span { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: .15s; }
.tw-toggle.on { background: var(--health); border-color: var(--health); }
.tw-toggle.on span { left: 20px; background: #0c1208; }

/* ============================================================
   LEVEL SELECT
   ============================================================ */
.lcard { background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; transition: .15s; }
.lcard:hover { border-color: var(--accent); transform: translateY(-3px); box-shadow: 0 18px 40px -20px #000; }
.lprev { display: block; width: 100%; height: auto; background: var(--bg); border-bottom: 1px solid var(--panel-edge); }
.lbody { padding: 15px 16px 16px; display: flex; flex-direction: column; flex: 1; }
.lhd { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.lname { font-family: var(--disp); font-size: 18px; font-weight: 700; }
.ldiff { font-size: 9.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; padding: 3px 8px; border-radius: 20px; border: 1px solid; white-space: nowrap; }
.ldiff.d0 { color: var(--health); border-color: color-mix(in srgb, var(--health) 50%, transparent); }
.ldiff.d1 { color: var(--commits); border-color: color-mix(in srgb, var(--commits) 50%, transparent); }
.ldiff.d2 { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.ldiff.d3 { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.lsub { font-size: 12px; color: var(--muted); line-height: 1.55; margin: 9px 0 14px; flex: 1; }
.lplay { background: var(--health); color: #0c1208; border: none; padding: 11px; border-radius: var(--r); font-weight: 700; font-size: 13px; transition: .12s; }
.lplay:hover { filter: brightness(1.1); }

/* ============================================================
   INFO TOOLTIP (tower / spell details during play)
   ============================================================ */
.info-tip {
  position: fixed; z-index: 120; width: 260px; display: none; pointer-events: none;
  background: color-mix(in srgb, var(--panel) 96%, #000); border: 1px solid var(--accent);
  border-radius: 10px; padding: 11px 13px; box-shadow: 0 16px 44px -14px #000;
}
.info-tip.on { display: block; animation: fade .12s ease; }
.tip-hd { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tip-hd b { font-family: var(--disp); font-size: 14px; }
.tip-hd span { font-size: 11px; color: var(--commits); white-space: nowrap; }
.tip-sub { font-size: 10px; color: var(--accent); letter-spacing: .04em; margin-top: 1px; }
.tip-blurb { font-size: 11px; color: var(--muted); line-height: 1.5; margin: 8px 0; }
.tip-meta { font-size: 10.5px; color: var(--text); background: #0004; border-radius: 5px; padding: 5px 7px; }
.tip-tree { display: flex; flex-direction: column; border-top: 1px solid var(--panel-edge); margin-top: 4px; }
.tip-tier { display: flex; align-items: center; gap: 9px; padding: 6px 0; border-bottom: 1px solid color-mix(in srgb, var(--panel-edge) 60%, transparent); }
.tip-tier:last-child { border-bottom: none; }
.tip-n { width: 18px; height: 18px; flex: 0 0 auto; border-radius: 50%; border: 1px solid var(--accent); color: var(--accent); font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.tip-tn { font-size: 11px; font-weight: 600; }
.tip-ts { font-size: 9.5px; color: var(--muted); margin-top: 1px; }
.tip-tc { margin-left: auto; font-size: 10.5px; color: var(--commits); font-weight: 600; white-space: nowrap; }
