:root {
  --bg: #0b0c09;
  --panel: #15170f;
  --panel-2: #1d2016;
  --line: #34382a;
  --line-strong: #6a5c40;
  --amber: #d9a650;
  --amber-dim: #8c6a38;
  --text: #ece2cf;
  --muted: #9c927f;
  --danger: #c4372a;
  --blood: #7e130c;
  --blood-bright: #c4281c;
  --ok: #8b9860;
  --hazard: repeating-linear-gradient(-45deg, #c9a03e 0 9px, #15130e 9px 18px);
  --top: 58px;
  --side: 318px;
  --display: "Barlow Condensed", "Arial Narrow", "Segoe UI", sans-serif;
  --stencil: "Black Ops One", "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "Barlow", "Segoe UI", sans-serif;
  --serif: "Source Serif 4", Georgia, serif;
  --noise: none;
  --splat: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200'%3E%3Cg fill='%237a0e08'%3E%3Cpath d='M100 52c10 0 14 12 22 14s20-8 26 0-4 18 2 26 22 6 22 16-16 10-20 18 6 22-4 28-18-6-26-2-10 22-22 22-12-18-22-20-24 8-30 0 8-18 2-26-22-8-22-18 18-8 20-16-6-22 4-28 18 4 24-2 10-22 24-22z'/%3E%3Ccircle cx='170' cy='40' r='6'/%3E%3Ccircle cx='30' cy='170' r='5'/%3E%3Ccircle cx='160' cy='160' r='8'/%3E%3Ccircle cx='40' cy='40' r='4'/%3E%3Ccircle cx='186' cy='110' r='3'/%3E%3Ccircle cx='12' cy='96' r='3.5'/%3E%3Ccircle cx='132' cy='22' r='2.5'/%3E%3Cpath d='M96 150c3 0 4 2 4 6v30c0 4-2 6-4 6s-4-2-4-6v-30c0-4 1-6 4-6z'/%3E%3C/g%3E%3Cpath fill='%23a8160e' opacity='.55' d='M100 70c12 0 26 10 26 30s-12 32-28 32-26-12-26-30 14-32 28-32z'/%3E%3C/svg%3E");
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  overflow: hidden;
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  touch-action: none;
}

#grain {
  position: fixed;
  inset: -64px;
  z-index: 1;
  pointer-events: none;
  opacity: 0.12;
  mix-blend-mode: multiply;
  background-size: 128px 128px;
  animation: grain 0.7s steps(5) infinite;
}

@keyframes grain {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-23px, 17px); }
  40% { transform: translate(31px, -9px); }
  60% { transform: translate(-11px, -29px); }
  80% { transform: translate(19px, 27px); }
  100% { transform: translate(0, 0); }
}

@media (prefers-reduced-motion: reduce) {
  #grain { animation: none; }
}

#topbar, #sidebar, #banner, #toasts, .screen { z-index: 3; }

body:not(.playing) #topbar,
body:not(.playing) #sidebar,
body:not(.playing) #banner { display: none; }

#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: var(--side);
  height: var(--top);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px 0 16px;
  background-color: #12140e;
  background-image: var(--noise), linear-gradient(180deg, rgba(34, 37, 26, 0.97), rgba(14, 15, 10, 0.95));
  background-blend-mode: multiply, normal;
  border-bottom: 1px solid #050504;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}
#topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -5px;
  height: 4px;
  background: var(--hazard);
  opacity: 0.75;
}

.wordmark { display: flex; flex-direction: column; min-width: 140px; }
.wordmark strong {
  font-family: var(--stencil);
  font-weight: 400;
  letter-spacing: 0.08em;
  font-size: 19px;
  line-height: 1;
  text-transform: uppercase;
  color: #efe4cc;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.7), 2px 0 0 rgba(126, 19, 12, 0.6);
}
.eyebrow, .section-label, .lbl, .mark, .kicker {
  font-family: var(--display);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--amber);
  font-size: 11px;
  font-weight: 700;
}
.lbl { display: block; margin-bottom: 2px; color: var(--muted); letter-spacing: 0.16em; }

.wave-readout { min-width: 180px; }
.wave-readout strong {
  display: block;
  font-family: var(--display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-shadow: 0 1px 0 #000;
}

.integrity {
  display: flex;
  align-items: center;
  gap: 8px;
}
.integrity .lbl { margin: 0; }
.integrity .bar {
  position: relative;
  width: 118px;
  height: 10px;
  background: #0a0a07;
  border: 1px solid #3a3a2c;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.8);
}
.integrity .bar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 6px, rgba(0, 0, 0, 0.7) 6px 7px);
  pointer-events: none;
}
#integrity-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(180deg, #c8c07a, #6e7036);
  transition: width 0.25s ease-out;
}
#integrity-fill.warn { background: linear-gradient(180deg, #f0a848, #8a4a18); }
#integrity-fill.bad {
  background: linear-gradient(180deg, #ff5a3c, #7a120c);
  box-shadow: 0 0 10px rgba(255, 60, 30, 0.6);
  animation: alarm 0.9s ease-in-out infinite;
}
@keyframes alarm {
  50% { filter: brightness(1.5); }
}
#integrity-num {
  font-family: var(--stencil);
  font-size: 16px;
  letter-spacing: 0.04em;
  min-width: 1.4em;
}

.stat strong {
  font-family: var(--stencil);
  font-weight: 400;
  font-size: 19px;
  letter-spacing: 0.04em;
}
.stat small { font-size: 12px; color: var(--muted); letter-spacing: 0.12em; }
.credits-stat strong { color: #f0cc80; text-shadow: 0 0 8px rgba(217, 166, 80, 0.25); }
.spacer { flex: 1; }

.cluster { display: flex; gap: 6px; align-items: center; }

button.primary, button.ghost, .cluster button, .segmented button {
  border: 1px solid #0c0d09;
  background: linear-gradient(180deg, #353a29, #1e2117);
  color: var(--text);
  padding: 8px 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-family: var(--display);
  font-size: 14px;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 244, 220, 0.09), inset 0 -2px 0 rgba(0, 0, 0, 0.45), 0 1px 0 rgba(0, 0, 0, 0.7);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.8);
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
}
button.primary {
  background: linear-gradient(180deg, #5e6634, #363c1e);
  color: #f6ead0;
  border-color: #141508;
}
button.primary:hover, .cluster button:hover, button.ghost:hover, .tower-card:hover {
  border-color: var(--amber-dim);
  box-shadow: inset 0 1px 0 rgba(255, 244, 220, 0.12), inset 0 -2px 0 rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(217, 166, 80, 0.25), 0 0 14px rgba(217, 166, 80, 0.15);
}
button.primary:hover { background: linear-gradient(180deg, #6c7540, #404624); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.42; cursor: not-allowed; filter: saturate(0.4); }
button.ghost { background: linear-gradient(180deg, rgba(40, 42, 32, 0.6), rgba(16, 17, 12, 0.6)); }
button.danger { color: #f0b8ac; border-color: #3a0c08; background: linear-gradient(180deg, #4a1612, #260806); }
button.danger:hover { border-color: var(--blood-bright); box-shadow: 0 0 14px rgba(196, 40, 28, 0.35); }
button.on, .segmented button.on, #btn-hold.on, #btn-speed[aria-pressed="true"] {
  border-color: var(--amber);
  color: var(--amber);
  box-shadow: inset 0 0 0 1px rgba(217, 166, 80, 0.3), inset 0 -2px 0 rgba(0, 0, 0, 0.45);
}

#sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--side);
  background-color: #12140e;
  background-image: var(--noise), linear-gradient(180deg, rgba(30, 33, 23, 0.98), rgba(12, 13, 9, 0.99));
  background-blend-mode: multiply, normal;
  border-left: 1px solid #050504;
  box-shadow: -10px 0 26px rgba(0, 0, 0, 0.5), inset 1px 0 0 rgba(255, 240, 210, 0.05);
  padding: 18px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
}
#sidebar::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: var(--hazard);
  opacity: 0.8;
}
#sidebar > section {
  position: relative;
  padding: 10px 10px 4px;
  background: rgba(6, 6, 4, 0.35);
  border: 1px solid rgba(0, 0, 0, 0.6);
  box-shadow: inset 0 1px 0 rgba(255, 240, 210, 0.04);
}

.section-label { margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.section-label::before {
  content: "";
  width: 6px;
  height: 6px;
  background: var(--blood-bright);
  box-shadow: 0 0 6px rgba(196, 40, 28, 0.7);
}

.sitrep h2, .detail h2, .card h2, .manual-card h2 {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0 0 6px;
  font-size: 26px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
}

.sitrep p, .detail p, #detail-copy {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.45;
}

.sitrep-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--text);
  font-size: 12.5px;
  margin-bottom: 8px;
  font-family: var(--display);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.maps {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0 0 8px;
}
.posting {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 0 0 12px;
}
.maps button, .posting button {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  background: linear-gradient(180deg, #23261b, #121410);
  border: 1px solid #070806;
  box-shadow: inset 0 1px 0 rgba(255, 244, 220, 0.06), 0 1px 0 rgba(0, 0, 0, 0.6);
  color: var(--text);
  padding: 8px 4px;
  font-family: var(--display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 13px;
  font-weight: 700;
}
.maps button span, .posting button span {
  color: var(--muted);
  font-family: var(--body);
  letter-spacing: 0;
  text-transform: none;
  font-size: 12px;
  font-weight: 500;
}
.maps button.on, .posting button.on {
  border-color: var(--amber);
  color: var(--amber);
  box-shadow: inset 0 0 0 1px rgba(217, 166, 80, 0.3), 0 0 14px rgba(217, 166, 80, 0.12);
}
.maps button.on span, .posting button.on span { color: #b89a62; }

.btn-row, .btn-col { display: flex; gap: 8px; }
.btn-col { flex-direction: column; }
.btn-row button, .btn-col button { flex: 1; }

.tower-card {
  width: 100%;
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 8px;
  align-items: center;
  text-align: left;
  background: linear-gradient(180deg, #20231a, #121410);
  border: 1px solid #070806;
  box-shadow: inset 0 1px 0 rgba(255, 244, 220, 0.05), 0 1px 0 rgba(0, 0, 0, 0.6);
  padding: 6px;
  margin-bottom: 8px;
  position: relative;
}
.tower-card canvas, .detail-portrait {
  background:
    radial-gradient(circle at 50% 70%, rgba(80, 70, 50, 0.6) 0%, rgba(14, 14, 10, 0) 70%),
    linear-gradient(180deg, #1e2016, #0c0d09);
  box-shadow: inset 0 0 0 1px #000, inset 0 0 18px rgba(0, 0, 0, 0.8);
  display: block;
}
.tower-copy { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.tower-card .name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1;
}
.tower-card .meta { color: var(--muted); font-size: 12px; }
.tower-card .cost {
  font-family: var(--stencil);
  letter-spacing: 0.06em;
  font-size: 13px;
  color: #e6c47e;
}
.tower-card.broke .cost { color: var(--blood-bright); }
.tower-card.broke { filter: saturate(0.6) brightness(0.85); }
.tower-card.armed {
  border-color: var(--amber);
  background: linear-gradient(180deg, #2e2a18, #16140c);
  box-shadow: inset 3px 0 0 var(--amber), 0 0 16px rgba(217, 166, 80, 0.18);
}

.detail-portrait {
  display: none;
  width: 96px;
  height: 72px;
  margin: 0 0 8px;
}
.detail-portrait:not([hidden]) { display: block; }

#detail dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 12px;
  margin: 0 0 8px;
  font-size: 13px;
}
#detail dt { color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-size: 11.5px; font-family: var(--display); }
#detail dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 15px;
}
.pen {
  grid-column: 1 / -1;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.4;
}

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 8px; }
.segmented button { padding: 6px 4px; }

.keys {
  margin-top: auto;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 8px;
  border-top: 1px solid #000;
  box-shadow: inset 0 1px 0 rgba(255, 240, 210, 0.04);
}
kbd {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.08em;
  border: 1px solid #000;
  border-bottom-width: 2px;
  background: linear-gradient(180deg, #2c2f22, #16180f);
  padding: 0 4px;
  color: var(--amber);
  font-size: 11px;
  margin-right: 3px;
}

#banner {
  position: fixed;
  top: 78px;
  left: 0;
  right: var(--side);
  text-align: center;
  pointer-events: none;
}
#banner .kicker {
  display: inline-block;
  padding: 2px 10px;
  background: rgba(10, 8, 6, 0.8);
  border: 1px solid rgba(217, 166, 80, 0.4);
}
#banner .title {
  display: block;
  width: fit-content;
  margin: 6px auto 4px;
  padding: 4px 48px;
  font-family: var(--stencil);
  font-size: 38px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #f2e6cc;
  background: linear-gradient(90deg, transparent, rgba(110, 10, 6, 0.85) 18%, rgba(110, 10, 6, 0.85) 82%, transparent);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.7);
}
#banner .sub {
  color: #efe6d6;
  font-family: var(--serif);
  font-size: 15px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}
#banner.hidden { display: none; }

#toasts {
  position: fixed;
  top: 80px;
  left: 0;
  right: var(--side);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
body:not(.playing) #toasts { right: 0; }
.toast {
  background: rgba(10, 10, 7, 0.94);
  border: 1px solid #000;
  border-left: 4px solid var(--amber);
  padding: 8px 14px;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 14px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.18s ease-out;
}
.toast.bad {
  border-left-color: var(--blood-bright);
  color: #ffb4a4;
  background: linear-gradient(90deg, rgba(80, 8, 4, 0.95), rgba(14, 8, 6, 0.94));
}
@keyframes toast-in {
  from { transform: translateY(-6px); opacity: 0; }
}

.screen {
  position: fixed;
  inset: 0;
  display: grid;
  pointer-events: none;
}
.screen.hidden { display: none; }

#screen-menu {
  align-items: center;
  justify-items: start;
  padding-left: 7vw;
  background: linear-gradient(90deg, rgba(6, 6, 4, 0.94) 0%, rgba(6, 6, 4, 0.78) 32%, rgba(6, 6, 4, 0.2) 58%, rgba(6, 6, 4, 0) 74%);
}
#screen-pause, #screen-end, #screen-manual {
  place-items: center;
  background: rgba(4, 4, 3, 0.66);
  pointer-events: auto;
}
#screen-end.lost {
  background:
    radial-gradient(ellipse at center, rgba(40, 0, 0, 0.35) 0%, rgba(30, 0, 0, 0.82) 80%),
    rgba(4, 2, 2, 0.6);
}
#screen-menu .card { pointer-events: auto; }

.card {
  width: min(460px, calc(100vw - 48px));
  background-color: #14160f;
  background-image: var(--noise), linear-gradient(180deg, #24271b, #121410);
  background-blend-mode: multiply, normal;
  border: 1px solid #000;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 240, 210, 0.06), inset 0 0 0 1px rgba(90, 80, 56, 0.25);
  padding: 28px 26px 22px;
  position: relative;
}
.card::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 5px;
  background: var(--hazard);
  opacity: 0.85;
}
.menu-card::after, #screen-end.lost .card::after {
  content: "";
  position: absolute;
  right: -38px;
  top: -46px;
  width: 190px;
  height: 190px;
  background: var(--splat) center / contain no-repeat;
  opacity: 0.85;
  pointer-events: none;
  transform: rotate(18deg);
  mix-blend-mode: multiply;
}
#screen-end.lost .card::after {
  right: auto;
  left: -60px;
  top: auto;
  bottom: -60px;
  width: 240px;
  height: 240px;
  transform: rotate(-40deg);
  opacity: 0.9;
}
#screen-end.lost .card { border-color: #3a0806; box-shadow: 0 0 60px rgba(160, 10, 6, 0.35), 0 30px 70px rgba(0, 0, 0, 0.7); }
#screen-end.lost h2 { color: #ff6a50; font-family: var(--stencil); font-weight: 400; letter-spacing: 0.08em; text-shadow: 0 0 18px rgba(196, 40, 28, 0.55), 0 3px 0 #000; }
#screen-end.held h2 { font-family: var(--stencil); font-weight: 400; letter-spacing: 0.08em; color: #f0d090; }
.menu-card h1 {
  font-family: var(--stencil);
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: clamp(46px, 6vw, 70px);
  line-height: 0.92;
  margin: 8px 0 16px;
  color: #efe4cc;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.75), 3px 0 0 rgba(126, 19, 12, 0.8);
  position: relative;
}
.menu-card h1::after {
  content: "";
  display: block;
  width: 62%;
  height: 6px;
  margin-top: 10px;
  background: linear-gradient(90deg, var(--blood) 0%, var(--blood-bright) 40%, rgba(126, 19, 12, 0) 100%);
  clip-path: polygon(0 30%, 18% 0, 46% 40%, 70% 10%, 100% 50%, 70% 100%, 40% 70%, 12% 100%);
}
.lede {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.45;
  margin: 0 0 16px;
  color: #e6dccb;
}
.fine { color: var(--muted); font-size: 12.5px; margin: 12px 0 0; }
.volume {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  color: var(--muted);
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 12px;
}
.volume > span { flex: none; width: 8.5em; }
.volume + .volume { margin-top: 8px; }
.volume input { flex: 1; accent-color: #a8862e; }

.manual-card {
  width: min(720px, calc(100vw - 40px));
  max-height: min(86vh, 820px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.manual-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex: none; }
.manual-body { overflow: auto; min-height: 0; padding-right: 8px; }
.manual-body h3 {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 16px;
  margin: 16px 0 6px;
  color: var(--amber);
}
.manual-body p, .manual-body li {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.45;
  margin: 0 0 8px;
  color: #e7dccb;
}
.manual-body ul { margin: 0; padding-left: 18px; }

.end-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin-bottom: 16px;
}
.end-stats div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid #000;
  box-shadow: 0 1px 0 rgba(255, 240, 210, 0.04);
  padding-bottom: 4px;
  font-size: 13px;
  color: var(--muted);
  font-family: var(--display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.end-stats strong {
  color: var(--text);
  font-family: var(--stencil);
  font-weight: 400;
  letter-spacing: 0.05em;
  font-size: 16px;
}

@media (max-width: 1180px) {
  :root { --side: 280px; }
  .wave-readout { display: none; }
  #banner .title { font-size: 28px; }
}

@media (max-width: 860px) {
  :root { --side: 240px; --top: 52px; }
  .stat { display: none; }
  .integrity { width: 90px; }
}
