:root {
  color-scheme: dark;
  --black: #080a0c;
  --black-soft: #11161a;
  --panel: rgba(8, 10, 12, 0.96);
  --ink: #fff8dc;
  --muted: #b9c1bc;
  --red: #ff3b35;
  --cyan: #55e6ec;
  --yellow: #ffd85a;
  --green: #70ec8c;
  font-family: Consolas, "Courier New", monospace;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden], .is-hidden { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: #080a0c;
  color: var(--ink);
}

button, input { font: inherit; letter-spacing: 0; }

button {
  min-height: 44px;
  border: 3px solid var(--ink);
  border-radius: 0;
  background: #080a0c;
  color: var(--ink);
  padding: 8px 12px;
  font-weight: 900;
  cursor: pointer;
}

button:hover, button:focus-visible { border-color: var(--yellow); color: var(--yellow); outline: 0; }
button:disabled { border-color: #4e5857; color: #697372; cursor: not-allowed; }
button.primary { border-color: var(--red); background: var(--red); color: #080a0c; }
button.primary:hover, button.primary:focus-visible { border-color: var(--ink); background: var(--ink); color: #080a0c; }

input {
  width: 100%;
  min-height: 46px;
  border: 2px solid #596362;
  border-radius: 0;
  background: #050607;
  color: var(--ink);
  padding: 10px 12px;
  font-size: 15px;
  text-transform: uppercase;
}

input:focus { border-color: var(--cyan); outline: 0; }
input:disabled { border-color: #3c4445; color: #697372; }

.boot-screen {
  position: relative;
  min-height: 100vh;
  display: grid;
  align-items: end;
  overflow: hidden;
  background: #080a0c url("./assets/reactor-title.png") center / cover no-repeat;
  image-rendering: pixelated;
}

.boot-shade { position: absolute; inset: 0; background: rgba(5, 7, 8, 0.48); }
.boot-content { position: relative; width: min(560px, calc(100% - 40px)); margin: 0 0 6vh 6vw; text-shadow: 3px 3px 0 #050607; }
.eyebrow { margin: 0; color: var(--cyan); font-size: 14px; font-weight: 900; }
.boot-content h1 { margin: 14px 0 18px; font-size: 126px; line-height: 0.72; letter-spacing: 0; }
.boot-content h1 span { color: var(--red); }
.boot-copy { margin: 0 0 24px; font-size: 19px; line-height: 1.5; }

.join-box {
  width: min(460px, 100%);
  border: 4px solid var(--ink);
  background: rgba(8, 10, 12, 0.96);
  padding: 18px;
  text-shadow: none;
}

.join-box label { display: grid; gap: 7px; margin-bottom: 13px; color: var(--muted); font-size: 12px; font-weight: 900; }
.menu-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.stats-menu-button { width: 100%; margin-top: 9px; }
.connection-status {
  min-height: 18px;
  margin: 12px 0 0;
  color: var(--red);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.4;
}

.game-shell {
  width: min(1280px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px;
}

.game-bar {
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto minmax(120px, auto) auto auto auto auto 42px 42px 42px;
  align-items: center;
  gap: 18px;
  border: 3px solid var(--ink);
  border-bottom: 0;
  background: var(--black);
  padding: 7px 12px;
}

.game-brand { font-size: 18px; font-weight: 900; }
.game-brand span { color: var(--red); }
.status-role { color: var(--cyan); font-size: 13px; font-weight: 900; }
.status-scenario { color: var(--yellow); font-size: 11px; font-weight: 900; text-align: center; }
.status-room, .status-strikes { color: var(--muted); font-size: 12px; }
.status-room strong, .status-strikes strong { color: var(--ink); }
.status-time { min-width: 72px; color: var(--yellow); font-size: 22px; font-weight: 900; text-align: center; }
.module-dots { display: flex; gap: 7px; }
.module-dot { width: 14px; height: 14px; border: 2px solid #73807d; background: #080a0c; }
.module-dot.done { border-color: var(--green); background: var(--green); }
.module-dot.active:not(.done) { border-color: var(--yellow); animation: module-pulse 700ms steps(2, end) infinite; }
.icon-button { position: relative; width: 42px; min-height: 38px; padding: 0; font-size: 26px; line-height: 1; }
.icon-button.is-muted::after {
  content: "";
  position: absolute;
  width: 30px;
  height: 3px;
  left: 5px;
  top: 18px;
  background: var(--red);
  transform: rotate(-45deg);
}

.arena-frame { border: 3px solid var(--ink); background: var(--black); box-shadow: 9px 9px 0 #232a2d; }
.canvas-stage { position: relative; overflow: hidden; aspect-ratio: 16 / 9; background: #171b1d var(--scenario-bg, url("./assets/reactor-room-v2.png")) center / 100% 100% no-repeat; image-rendering: pixelated; }
.canvas-stage[data-scenario="cryo"] { box-shadow: inset 0 0 0 3px rgba(140, 236, 255, 0.48); }
.canvas-stage[data-scenario="signal"] { box-shadow: inset 0 0 0 3px rgba(112, 236, 140, 0.48); }
.canvas-stage::after { content: ""; position: absolute; z-index: 7; inset: 0; pointer-events: none; opacity: 0; }
.canvas-stage.outcome-lost { animation: reactor-shake 80ms steps(2, end) 16; }
.canvas-stage.outcome-lost::after { background: rgba(255, 35, 28, 0.38); animation: alarm-flash 260ms steps(2, end) 5; }
.canvas-stage.outcome-won::after { border: 8px solid rgba(112, 236, 140, 0.72); animation: stable-frame 900ms steps(4, end) 2; }

#game {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#game:focus { outline: 0; }

.station-label {
  position: absolute;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 2px solid var(--ink);
  background: rgba(8, 10, 12, 0.9);
  padding: 6px 9px;
  font-size: 13px;
  font-weight: 900;
  pointer-events: none;
}

.station-label i { width: 10px; height: 10px; background: currentColor; }
.station-wires { left: 7%; top: 17%; color: var(--red); }
.station-glyphs { right: 6%; top: 17%; color: var(--cyan); }
.station-coolant { left: 50%; bottom: 7%; color: var(--yellow); transform: translateX(-50%); }
.station-label.is-done { color: var(--green); }

.objective-card {
  position: absolute;
  z-index: 4;
  left: 18px;
  bottom: 18px;
  width: min(470px, calc(100% - 36px));
  border: 3px solid var(--ink);
  border-left: 8px solid var(--yellow);
  background: var(--panel);
  padding: 13px 15px;
}

.objective-card strong { display: block; margin-bottom: 7px; color: var(--yellow); font-size: 13px; }
.objective-card p { margin: 0; color: var(--ink); font-size: 16px; line-height: 1.45; }

.module-console {
  position: absolute;
  z-index: 6;
  top: 18px;
  right: 18px;
  width: min(390px, calc(100% - 36px));
  max-height: calc(100% - 80px);
  overflow: auto;
  border: 4px solid var(--ink);
  background: var(--panel);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.7);
}

.module-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 3px solid var(--ink); padding: 11px 13px; }
.module-head span { color: var(--muted); font-size: 11px; font-weight: 900; }
.module-head h2 { margin: 3px 0 0; font-size: 23px; }
.key-help { color: var(--yellow) !important; }
.intel-content { padding: 13px; }
.intel-content p { margin: 0; color: var(--ink); font-size: 15px; line-height: 1.45; }
.intel-content strong { color: var(--cyan); }
.data-list { display: grid; border-top: 2px solid #56605e; }
.data-row { min-height: 42px; display: grid; grid-template-columns: 1fr minmax(90px, auto); align-items: center; gap: 12px; border-bottom: 2px solid #394240; font-size: 14px; }
.data-row strong { color: var(--cyan); text-align: right; overflow-wrap: anywhere; }
.action-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 0 13px 13px; }
.action-grid p { grid-column: 1 / -1; margin: 0; color: var(--green); font-size: 15px; }
.action-grid p.locked-action { color: var(--red); }
.action-grid button { min-height: 50px; text-align: left; font-size: 14px; }
.action-grid kbd { display: inline-grid; place-items: center; width: 25px; height: 25px; margin-right: 6px; border: 2px solid currentColor; font: inherit; }

.proximity-hint {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  border: 2px solid var(--ink);
  background: rgba(8, 10, 12, 0.9);
  padding: 8px 12px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  pointer-events: none;
}

.story-line {
  min-height: 88px;
  display: grid;
  grid-template-columns: 130px 1fr;
  align-items: center;
  gap: 16px;
  border-top: 4px solid var(--ink);
  background: var(--black);
  padding: 14px 18px;
}

.story-line strong { color: var(--red); font-size: 14px; }
.story-line span { color: var(--ink); font-size: 17px; line-height: 1.45; }

.end-overlay {
  position: absolute;
  z-index: 8;
  inset: 50% auto auto 50%;
  width: min(520px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  border: 5px solid var(--ink);
  background: #080a0c;
  padding: 24px;
  text-align: center;
}

.end-overlay span { color: var(--muted); font-size: 13px; }
.end-overlay h2 { margin: 10px 0 12px; color: var(--green); font-size: 30px; }
.end-overlay p { margin: 0 auto 14px; max-width: 420px; color: var(--ink); font-size: 15px; line-height: 1.45; }
.end-overlay.is-lost { border-color: var(--red); animation: end-reveal 360ms 1100ms steps(4, end) both; }
.end-overlay.is-lost h2 { color: var(--red); }
.end-overlay.is-won { border-color: var(--green); animation: end-reveal 360ms 700ms steps(4, end) both; }
.end-overlay.is-won h2 { color: var(--green); }
.end-stats { margin-bottom: 18px; border-top: 2px solid #4e5857; border-bottom: 2px solid #4e5857; padding: 10px; color: var(--yellow); font-size: 13px; font-weight: 900; }
.end-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.lobby {
  position: fixed;
  z-index: 20;
  inset: 50% auto auto 50%;
  width: min(720px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  border: 5px solid var(--ink);
  background: #080a0c;
  box-shadow: 12px 12px 0 rgba(0, 0, 0, 0.65);
  padding: 20px;
}

.lobby header { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.lobby header span { color: var(--cyan); font-size: 12px; }
.lobby h2 { margin: 5px 0 0; font-size: 28px; }
.lobby header p { max-width: 340px; margin: 0; color: var(--muted); font-size: 14px; }
.players { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.player { min-width: 0; display: grid; grid-template-columns: 40px 1fr; align-items: center; gap: 10px; border: 2px solid #5a6462; padding: 8px; font-size: 14px; }
.player-copy { min-width: 0; display: grid; gap: 5px; }
.player-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-copy em { color: var(--yellow); font-size: 9px; font-style: normal; font-weight: 900; }
.player small { color: var(--cyan); }
.role-avatar { position: relative; width: 40px; height: 60px; overflow: hidden; image-rendering: pixelated; }
.role-avatar img { position: absolute; top: 0; width: 120px; height: 60px; max-width: none; image-rendering: pixelated; }
.role-avatar.role-operator img { left: 0; }
.role-avatar.role-lookout img, .role-avatar.role-observer img { left: -40px; }
.role-avatar.role-scribe img { left: -80px; }
.role-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.role-row button { min-height: 70px; display: grid; align-content: center; gap: 6px; text-align: left; }
.role-row button strong { font-size: 14px; }
.role-row button small { color: var(--muted); font-size: 10px; line-height: 1.35; }
.role-row button:hover small, .role-row button:focus-visible small { color: currentColor; }
.lobby > .primary { width: 100%; }

.relay { display: grid; grid-template-columns: 1fr minmax(320px, 0.65fr); gap: 10px; margin-top: 14px; border: 3px solid var(--ink); background: var(--black); padding: 12px; }
.relay-head { display: flex; justify-content: space-between; grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
.relay-head strong { color: var(--cyan); }
.log { min-height: 90px; max-height: 120px; overflow: auto; display: grid; align-content: end; gap: 5px; font-size: 13px; }
.log-line { color: var(--muted); line-height: 1.35; }
.log-line.success { color: var(--green); }
.log-line.danger { color: var(--red); }
.log-line.chat { color: var(--ink); }
.log-line.ping { color: var(--yellow); }
.chat-form { display: grid; grid-template-columns: 1fr 48px; gap: 6px; }
.quick-pings { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; grid-column: 2; }
.quick-pings button { min-height: 34px; padding: 4px; font-size: 10px; }

.stats-panel {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
}
.stats-panel[hidden] { display: none; }
.stats-backdrop { position: absolute; inset: 0; background: rgba(3, 5, 6, 0.88); }
.stats-dialog {
  position: relative;
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  border: 4px solid var(--ink);
  background: #080a0c;
  box-shadow: 12px 12px 0 #232a2d;
  padding: 18px;
}
.stats-header, .stats-footer, .stats-row, .stats-history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.stats-header span { color: var(--cyan); font-size: 11px; font-weight: 900; }
.stats-header h2 { margin: 5px 0 0; font-size: 26px; }
.stats-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 18px; border-block: 3px solid #4e5857; }
.stats-cell { min-width: 0; padding: 14px 10px; border-right: 2px solid #4e5857; }
.stats-cell:last-child { border-right: 0; }
.stats-cell span, .stats-row span, .stats-history-row span { display: block; color: var(--muted); font-size: 10px; font-weight: 900; }
.stats-cell strong { display: block; margin-top: 6px; color: var(--cyan); font-size: 24px; overflow-wrap: anywhere; }
.stats-details { margin-top: 12px; }
.stats-row, .stats-history-row { min-height: 38px; border-bottom: 1px solid #3d4646; padding: 7px 2px; }
.stats-row strong, .stats-history-row strong { max-width: 68%; color: var(--ink); font-size: 12px; text-align: right; }
.stats-breakdown { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 18px; }
.stats-breakdown h3, .stats-history h3 { margin: 0; color: var(--yellow); font-size: 12px; }
.stats-history { margin-top: 18px; }
.stats-history-row.is-win strong { color: var(--green); }
.stats-history-row.is-loss strong { color: var(--red); }
.stats-empty { color: var(--muted); font-size: 12px; padding: 14px 0; }
.stats-footer { margin-top: 18px; }
.stats-footer p { max-width: 460px; margin: 0; color: var(--muted); font-size: 11px; line-height: 1.4; }

.touch {
  display: none;
  grid-template-columns: repeat(3, 58px);
  grid-template-areas: ". up ." "left down right";
  justify-content: center;
  gap: 7px;
  margin-top: 14px;
}

.touch [data-move="up"] { grid-area: up; }
.touch [data-move="left"] { grid-area: left; }
.touch [data-move="down"] { grid-area: down; }
.touch [data-move="right"] { grid-area: right; }

@keyframes module-pulse {
  0%, 100% { background: #080a0c; }
  50% { background: var(--yellow); }
}

@keyframes reactor-shake {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-4px, 3px); }
  50% { transform: translate(4px, -2px); }
  75% { transform: translate(-2px, -3px); }
  100% { transform: translate(0, 0); }
}

@keyframes alarm-flash {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}

@keyframes stable-frame {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}

@keyframes end-reveal {
  from { opacity: 0; transform: translate(-50%, -46%) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@media (max-width: 820px) {
  .game-bar { grid-template-columns: 1fr auto auto auto 42px 42px 42px; gap: 9px; }
  .status-scenario, .status-room, .status-strikes { display: none; }
  .station-label { font-size: 10px; padding: 4px 6px; }
  .station-label i { width: 7px; height: 7px; }
  .objective-card { left: 10px; bottom: 10px; width: min(400px, calc(100% - 20px)); padding: 9px 11px; }
  .objective-card p { font-size: 13px; }
  .module-console { top: 10px; right: 10px; max-height: calc(100% - 20px); }
  .proximity-hint { top: 10px; font-size: 10px; }
  .touch { display: grid; }
  .relay { grid-template-columns: 1fr; }
  .quick-pings { grid-column: auto; }
}

@media (max-width: 560px) {
  .boot-content { width: calc(100% - 24px); margin: 0 12px 18px; }
  .boot-content h1 { font-size: 62px; }
  .boot-copy { font-size: 15px; }
  .menu-actions { grid-template-columns: 1fr; }
  .game-shell { padding: 6px; }
  .game-brand { display: none; }
  .game-bar { min-height: 50px; grid-template-columns: 1fr auto auto 38px 38px 38px; }
  .status-time { font-size: 18px; }
  .station-label span { display: none; }
  .station-label { border: 0; background: transparent; }
  .station-label i { width: 13px; height: 13px; border: 2px solid var(--ink); }
  .objective-card { left: 0; bottom: -94px; width: 100%; border-width: 0; border-top: 3px solid var(--ink); border-left: 7px solid var(--yellow); }
  .canvas-stage { overflow: visible; margin-bottom: 94px; }
  .module-console { position: fixed; inset: auto 6px 6px; width: auto; max-height: 72vh; }
  .proximity-hint { top: auto; bottom: 8px; white-space: nowrap; }
  .story-line { grid-template-columns: 82px 1fr; min-height: 80px; padding: 10px 12px; }
  .story-line strong { font-size: 11px; }
  .story-line span { font-size: 13px; }
  .lobby header { display: grid; }
  .players, .role-row { grid-template-columns: 1fr; }
  .relay { margin-top: 8px; }
  .stats-dialog { padding: 14px; }
  .stats-header h2 { font-size: 20px; }
  .stats-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-cell:nth-child(2) { border-right: 0; }
  .stats-cell:nth-child(-n + 2) { border-bottom: 2px solid #4e5857; }
  .stats-breakdown { grid-template-columns: 1fr; gap: 16px; }
  .stats-footer { align-items: stretch; flex-direction: column; }
}
