:root {
  --bg: #0b1210;
  --bg-panel: #121c18;
  --ink: #d7e6d8;
  --muted: #7f9a86;
  --accent: #c4a35a;
  --accent-hot: #e8c878;
  --danger: #c45c4a;
  --ok: #5fad7a;
  --artery: #b33a3a;
  --vein: #6b4a8a;
  --lymph: #c47a2e;
  --crt: #1a2e24;
  --line: rgba(196, 163, 90, 0.28);
  --font-display: "Special Elite", "Courier New", monospace;
  --font-mono: "Share Tech Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(1200px 600px at 70% -10%, #1a2a22 0%, transparent 55%),
    radial-gradient(900px 500px at 10% 100%, #1c1810 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
}

html { height: 100%; }

#app {
  min-height: 100dvh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
}

body.mode-surgery {
  overflow: hidden;
}

body.mode-surgery #app {
  max-width: none;
  height: 100dvh;
  padding: 0.5rem 0.75rem 0.6rem;
}

body.mode-surgery .foot { display: none; }

body.mode-surgery .topbar {
  margin-bottom: 0.4rem;
  padding: 0.35rem 0.15rem 0.45rem;
}

body.mode-surgery main {
  flex: 1;
  min-height: 0;
  display: flex;
}

body.mode-surgery #screen-surgery.active {
  display: flex;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.75rem;
  margin-bottom: 1.25rem;
}

.brand-mark {
  font-family: var(--font-display);
  letter-spacing: 0.12em;
  color: var(--accent-hot);
  margin-right: 0.5rem;
}

.brand-sub { color: var(--muted); font-size: 0.85rem; }

.hud-live {
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--accent);
}
.hud-live[hidden] { display: none !important; }

.screen { display: none; }
.screen.active { display: block; animation: fade 0.35s ease; }

@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

#screen-title {
  display: none;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 1.5rem;
  align-items: center;
  min-height: 58vh;
}
#screen-title.active { display: grid; }

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--accent);
  margin: 0 0 0.5rem;
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  font-weight: 400;
  margin: 0 0 0.75rem;
  letter-spacing: 0.04em;
}

h2 {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.04em;
  margin: 0 0 0.75rem;
}

.lede { line-height: 1.55; max-width: 36rem; }
.lede.quiet { color: var(--muted); font-size: 0.92rem; }
.hint { color: var(--muted); font-size: 0.88rem; }
.hint.tight { margin-top: 0.75rem; font-size: 0.78rem; }

.hero-viz {
  background: linear-gradient(160deg, #15241c, #0d1512 60%);
  border: 1px solid var(--line);
  padding: 0.5rem;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45);
}

.hero-viz canvas { width: 100%; height: auto; display: block; opacity: 0.95; }

.btn {
  font-family: var(--font-mono);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 0.65rem 1.1rem;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent-hot); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1408;
  margin-top: 1rem;
}
.btn.primary:hover { background: var(--accent-hot); }
.btn.ghost { margin-top: 1rem; }
.btn.fire {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  width: 100%;
  margin-top: 0.5rem;
}

.patient-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.patient-card {
  text-align: left;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.9rem;
  cursor: pointer;
  font-family: var(--font-mono);
}
.patient-card:hover,
.patient-card:focus {
  border-color: var(--accent);
  outline: none;
}
.patient-card .num {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--accent-hot);
}
.patient-card .meta { color: var(--muted); font-size: 0.8rem; margin-top: 0.35rem; }

.chart-wrap {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1.25rem;
  margin: 1rem 0;
}

.status-chart {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-panel);
  border: 1px solid var(--line);
}
.status-chart th,
.status-chart td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.status-chart th { color: var(--muted); font-weight: 400; }
.cond-good { color: var(--ok); }
.cond-fair { color: #b7c98a; }
.cond-serious { color: var(--accent-hot); }
.cond-critical { color: var(--danger); }
.cond-terminal { color: #fff; background: var(--danger); }

.chart-side {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  padding: 1rem;
}

.surgery-frame {
  display: grid;
  grid-template-columns: 1fr 160px;
  gap: 0.75rem;
  align-items: stretch;
  width: 100%;
  min-height: 0;
}

body.mode-surgery .surgery-frame {
  flex: 1;
  min-height: 0;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  height: 100%;
  background: #070c0a;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#game {
  width: 100%;
  height: auto;
  max-height: 100%;
  background: #070c0a;
  display: block;
  image-rendering: pixelated;
  cursor: crosshair;
}

body.mode-surgery #game {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.surgery-rail {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  padding: 0.65rem;
  overflow: auto;
}

.tool-group { display: grid; gap: 0.35rem; }
.tool {
  font-family: var(--font-mono);
  background: #0e1612;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.45rem;
  cursor: pointer;
}
.tool.active {
  border-color: var(--accent-hot);
  color: var(--accent-hot);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.legend {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.25rem; }
.swatch {
  width: 0.7rem;
  height: 0.7rem;
  display: inline-block;
  border-radius: 1px;
}
.swatch.artery { background: var(--artery); }
.swatch.vein { background: var(--vein); }
.swatch.lymph { background: var(--lymph); }
.swatch.exit { background: #7ec8e8; }

.bill {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--accent-hot);
}

.end-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

.foot {
  margin-top: 2rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
}

@media (max-width: 820px) {
  #screen-title.active,
  .chart-wrap,
  .patient-grid {
    grid-template-columns: 1fr;
  }
  .surgery-frame {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  body.mode-surgery .surgery-rail {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    max-height: 28vh;
  }
  body.mode-surgery .tool-group {
    display: flex;
    gap: 0.35rem;
  }
  .hud-live { flex-direction: column; gap: 0.2rem; }
}

.btn.fs {
  margin-left: auto;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
}
