:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #070907;
  color: #ede5cf;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 640px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 82% 8%, rgba(125, 27, 20, .18), transparent 30rem),
    radial-gradient(circle at 14% 70%, rgba(67, 84, 70, .13), transparent 38rem),
    repeating-linear-gradient(96deg, rgba(255,255,255,.012) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #151713, #070907 75%);
}

button, select { font: inherit; }
#map-select { display: block; width: 100%; margin: 8px 0; padding: 12px; color: #e8dfcc; background: #202b2c; border: 1px solid #91c8d0; border-radius: 5px; }
#map-description { min-height: 2.5em; color: #c6d8cf; }

.game-shell {
  width: min(1500px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 12px;
}

h1, h2, p { margin-top: 0; }
h1, h2 { font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; font-weight: 500; text-transform: uppercase; }
h1 { margin-bottom: 0; color: #e7dec6; font-size: clamp(25px, 3vw, 43px); letter-spacing: .025em; text-shadow: 0 2px #16120f, 2px 0 rgba(123, 32, 23, .65); }
h2 { margin-bottom: 12px; color: #e3dac2; font-size: 34px; letter-spacing: .035em; }
.eyebrow { margin-bottom: 4px; color: #d95443; font-size: 12px; font-weight: 900; letter-spacing: .17em; text-shadow: 0 0 14px rgba(217,84,67,.28); }
.fineprint { margin: 14px 0 0; color: #ada793; font-size: 12px; }

.hud { display: flex; gap: 8px; }
.hud div {
  min-width: 92px;
  padding: 9px 12px;
  border: 1px solid #3e4038;
  border-radius: 3px;
  background: linear-gradient(135deg, rgba(30, 32, 28, .96), rgba(14, 16, 14, .96));
  box-shadow: inset 0 0 18px rgba(0,0,0,.35);
}
.hud span, .hud strong { display: block; }
.hud span { color: #aaa993; font-size: 10px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.hud strong { margin-top: 2px; font-size: 21px; }

.battle-wrap {
  position: relative;
  overflow: hidden;
  border: 2px solid #544d40;
  border-radius: 4px;
  background: #171b18;
  box-shadow: 0 26px 80px rgba(0,0,0,.55), inset 0 0 0 1px rgba(171, 146, 103, .12);
}

canvas { display: block; width: 100%; height: auto; cursor: crosshair; }

/* Compact battlefield-first controls. The editor remains available in build phases. */
.topbar { gap: 12px; align-items: center; flex-wrap: wrap; }
.topbar h1 { font-size: clamp(23px,2.2vw,32px); }
.hud div { min-width: 72px; padding: 7px 9px; }
.hud strong { font-size: 18px; }
.combat-tools { display: grid; grid-template-columns: auto auto; gap: 6px; align-items: center; }
.combat-tools .speed-control { min-width: 100px; padding: 7px 9px; display: flex; gap: 8px; align-items: center; }
.combat-tools small { font-size: 10px; }
.combat-tools button:disabled { opacity: .45; cursor: not-allowed; }
.flash-control { grid-column: 1/-1; color: #c2c9bf; font-size: 11px; }
.flash-control input { accent-color: #91c8d0; }
button:focus-visible,input:focus-visible,select:focus-visible { outline: 2px solid #91e8f4; outline-offset: 3px; }

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 30px;
  background: rgba(5, 8, 6, .82);
  backdrop-filter: blur(5px);
}
.overlay.open { display: grid; }
.overlay .panel { max-height: 100%; overflow-y: auto; }
.wave-preview { margin: 8px 0; padding: 9px; border: 1px solid #615646; color: #e2cda8; font-size: 12px; line-height: 1.5; background: #25221d; }
.coach { display: flex; gap: 20px; align-items: center; justify-content: space-between; padding: 12px 16px; margin-top: 12px; background: #1c2c2d; border: 1px solid #83bbc0; }
.coach[hidden] { display: none; }
.coach p { margin: 4px 0 0; font-size: 13px; line-height: 1.5; color: #cee0db; }
.coach button { padding: 10px; white-space: nowrap; }
.guided-option { display: block; margin-bottom: 12px; }
.campaign-status, .breach-summary { margin: 12px 0; padding: 12px; border: 1px solid #5c6258; background: #1b2421; }
.campaign-status p, .breach-summary p { margin: 6px 0 0; font-size: 13px; line-height: 1.5; }
#continue-campaign { margin-top: 8px; }
.panel {
  width: min(850px, 92%);
  padding: 28px;
  border: 1px solid #5f5849;
  border-radius: 3px;
  background:
    repeating-linear-gradient(100deg, rgba(255,255,255,.014) 0 1px, transparent 1px 9px),
    linear-gradient(155deg, rgba(38, 39, 33, .98), rgba(15, 18, 16, .98));
  box-shadow: 0 30px 90px rgba(0,0,0,.55);
}
.panel > p:not(.eyebrow):not(.fineprint) { color: #cbc6b4; line-height: 1.55; }

.primary, .ability, .build, .upgrade, .wave-control, .speed-control, .mute-control, .remove-control, .manager-control, .upgrade-choice, .skill-node {
  border: 1px solid #55564c;
  border-radius: 3px;
  color: #f4ecd8;
  background: linear-gradient(160deg, #282b27, #1b1e1b);
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.primary:hover, .ability:hover:not(:disabled), .build:hover, .upgrade:hover:not(:disabled),
.wave-control:hover:not(:disabled), .speed-control:hover, .mute-control:hover { transform: translateY(-1px); border-color: #d2a052; }
.primary { width: 100%; padding: 14px 20px; border-color: #a84b3f; background: linear-gradient(180deg, #7e3028, #50211d); font-weight: 900; letter-spacing: .05em; text-transform: uppercase; }

.controls {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}
.build-list { display: flex; flex-direction: column; gap: 8px; }
.build, .ability, .wave-control, .speed-control { min-width: 185px; padding: 10px 13px; text-align: left; }
.build span, .ability span, .wave-control span, .speed-control span { display: block; font-weight: 800; }
.build small, .ability small, .wave-control small, .speed-control small { display: block; margin-top: 2px; color: #aaa992; }
.build.active { border-color: #d65b4b; background: linear-gradient(160deg, #482724, #261b19); box-shadow: inset 0 0 20px rgba(160,45,34,.18); }
.ability { border-color: #9f493e; background: #43221f; }
.ability:disabled, .wave-control:disabled { cursor: not-allowed; opacity: .55; }
.action-list { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.wave-control { border-color: #8c544b; background: #392522; }
.speed-control { min-width: 135px; border-color: #4e6748; background: #222f24; }
.volume-control {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 150px;
  padding: 8px 11px;
  border: 1px solid #4b5543;
  border-radius: 8px;
  background: #202429;
  color: #c7c1af;
  font-size: 12px;
  font-weight: 800;
}
.volume-control input { width: 90px; accent-color: #dc6253; }
.mute-control { padding: 8px 12px; }

.tower-tooltip {
  position: fixed;
  z-index: 4;
  width: 265px;
  padding: 13px 14px;
  pointer-events: none;
  border: 1px solid #765b57;
  border-radius: 3px;
  background: rgba(16, 19, 16, .97);
  box-shadow: 0 16px 40px rgba(0,0,0,.48);
  color: #eee5d0;
  transform: none;
  box-sizing: border-box;
}
.tower-tooltip h3 { margin: 0; font-size: 16px; }
.tower-tooltip p { margin: 5px 0 10px; color: #aaa993; font-size: 11px; line-height: 1.35; }
.stat-grid { display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; font-size: 12px; }
.stat-grid span:nth-child(odd) { color: #aaa993; }
.tooltip-upgrade { margin-top: 10px; padding-top: 9px; border-top: 1px solid #424750; color: #eb8b7f; font-size: 12px; font-weight: 800; }
.tooltip-max { color: #89b86b; }

.build-editor {
  width: 390px;
  padding: 11px 13px;
  border: 1px solid #474a40;
  border-radius: 3px;
  background: linear-gradient(160deg, #22251f, #161916);
}
.editor-heading { margin-bottom: 10px; }
.editor-heading span, .editor-heading strong { display: block; }
.editor-heading span { color: #e56a5b; font-size: 10px; font-weight: 900; letter-spacing: .12em; }
.editor-heading strong { margin-top: 3px; font-size: 13px; }
.build-editor label { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; margin-top: 8px; color: #aaaeb5; font-size: 11px; font-weight: 800; }
.build-editor input { grid-column: 1 / -1; width: 100%; accent-color: #db6557; }
.rhythm-preview { margin: 8px 0; padding: 7px 8px; border: 1px solid #394c58; border-radius: 6px; background: #151c21; color: #76c9df; font-size: 10px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; }
.threat-preview { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 7px 0 10px; }
.threat { display: grid; grid-template-columns: 10px 1fr; grid-template-rows: auto auto; column-gap: 6px; padding: 5px 6px; border: 1px solid #3c4038; background: rgba(10, 13, 11, .62); }
.threat i { grid-row: 1 / 3; align-self: center; width: 8px; height: 13px; background: #71836a; clip-path: polygon(15% 0, 100% 18%, 84% 100%, 0 82%); }
.threat strong { color: #ded6c0; font-size: 9px; line-height: 1; text-transform: uppercase; letter-spacing: .04em; }
.threat small { margin-top: 2px; color: #858a7e; font-size: 8px; line-height: 1; text-transform: uppercase; }
.threat.sprinter i { background: #d5a34e; clip-path: polygon(0 42%, 100% 0, 74% 100%); }
.threat.brute i { width: 10px; background: #68727a; clip-path: none; }
.threat.screamer i { background: #8fc8bd; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.terrain-preview { display: flex; gap: 5px; margin: -4px 0 9px; }
.terrain-preview span { flex: 1; display: flex; align-items: center; gap: 5px; color: #9da399; font-size: 8px; font-weight: 900; letter-spacing: .035em; text-transform: uppercase; }
.terrain-preview i { width: 14px; height: 8px; border: 2px solid #343a35; background: #131815; }
.terrain-preview .turret-ground i { border-color: #91e8f4; background: #405654; }
.manager-stats { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin: 8px 0; padding: 8px; border-radius: 6px; background: #171a1f; color: #aeb4bd; font-size: 10px; }
.manager-stats strong { color: #f0e7d3; }
.upgrade-options { display: grid; gap: 6px; margin: 8px 0; }
.upgrade-choice { padding: 8px 9px; text-align: left; }
.upgrade-choice strong, .upgrade-choice small { display: block; }
.upgrade-choice small { margin-top: 3px; color: #aeb0b5; line-height: 1.3; }
.upgrade-choice:disabled { opacity: .42; cursor: not-allowed; }
.upgrade-choice.specialization { border-color: #8d5d8f; background: #302337; }
.manager-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 9px; }
.manager-control, .remove-control { padding: 8px 9px; }
.remove-control { grid-column: 1 / -1; }
.manager-control:disabled, .remove-control:disabled { opacity: .4; cursor: not-allowed; }

.skill-tree { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.skill-branch { display: flex; flex-direction: column; gap: 7px; }
.skill-branch h3 { margin: 0 0 2px; color: #d9d3c5; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.skill-node { min-height: 72px; padding: 9px; text-align: left; }
.skill-node strong, .skill-node small { display: block; }
.skill-node small { margin-top: 3px; color: #a9aab0; line-height: 1.25; }
.skill-node.unlocked { border-color: #688758; background: #263323; }
.skill-node:disabled:not(.unlocked) { opacity: .42; cursor: not-allowed; }
.research-total { grid-column: 1 / -1; color: #eb8b7f; font-weight: 900; }

.workshop {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 20px 0;
}
.upgrade { min-height: 82px; padding: 10px; text-align: left; }
.upgrade strong, .upgrade small { display: block; }
.upgrade small { margin-top: 4px; color: #aaa993; line-height: 1.25; }
.upgrade:disabled { opacity: .45; cursor: not-allowed; }
.ironwood { grid-column: 1 / -1; color: #e0bb73; font-weight: 800; }

@media (max-width: 1100px) {
  .topbar { align-items: start; }
  .hud { display: grid; grid-template-columns: 1fr 1fr; }
  .controls { align-items: stretch; }
  .controls { flex-wrap: wrap; }
  .build-list { flex-flow: row wrap; }
  .build, .ability { min-width: 155px; }
  .action-list { max-width: 520px; }
  .build-editor { width: 360px; }
}

.controls { display:grid; grid-template-columns: minmax(0,1fr) auto; align-items:start; }
.topbar .hud { display:flex; flex-wrap:wrap; gap:6px; }
.build-list { flex-direction:row; flex-wrap:wrap; }
.build-list .build { min-width:135px; flex:1; padding:9px 11px; }
.build-list small { font-size:11px; }
.action-list { grid-column:2; grid-row:1; max-width:420px; }
.build-editor { grid-column:1/-1; grid-row:2; width:100%; }
.game-shell[data-phase="combat"] .build-editor > label,
.game-shell[data-phase="combat"] .build-editor .manager-actions,
.game-shell[data-phase="combat"] .build-editor .terrain-preview,
.game-shell[data-phase="combat"] .build-editor .threat-preview { display:none; }
.game-shell[data-phase="combat"] .build-editor { padding:8px 12px; display:flex; flex-wrap:wrap; gap:8px 16px; align-items:center; }
.game-shell[data-phase="combat"] .build-editor .editor-heading { margin:0; max-width:260px; }
.game-shell[data-phase="combat"] .build-editor .wave-preview { flex:1; margin:0; }
.game-shell[data-phase="combat"] .build-editor .rhythm-preview { margin:0; }
@media(max-width:900px) {
  .game-shell { width:calc(100vw - 20px); padding-top:10px; }
  .topbar > div:first-child { flex:1; }
  .hud { display:flex; flex-wrap:wrap; order:3; width:100%; }
  .hud > div { flex:1; }
  .controls { grid-template-columns:1fr; }
  .action-list { grid-row:2; grid-column:1; max-width:none; justify-content:flex-start; }
  .build-editor { grid-row:3; }
  .overlay { padding:12px; }
  .panel { width:96%; padding:16px; }
}
 .controls-settings {margin:8px 0;color:#c6c6b3;font-size:.85rem;}
 .controls-settings summary {cursor:pointer;padding:7px 0;}
 #control-bindings {display:flex;flex-wrap:wrap;gap:12px;}
 #control-bindings label {display:flex;align-items:center;gap:8px;}
 #control-bindings select {width:110px;}
.audio-mix-settings label {display:inline-flex;align-items:center;gap:8px;margin:4px 18px 4px 0;flex-wrap:wrap;}
.audio-mix-settings output {min-width:38px;}
.audio-mix-settings input {width:160px;}
