:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #000;
  color: var(--hud-body);
}
* { box-sizing: border-box; }
body { margin: 0; overflow: hidden; background: #000; user-select: none; }
canvas { position: fixed; inset: 0; width: 100%; height: 100%; }
#hud { pointer-events: none; z-index: 1; }
[hidden] { display: none !important; }
a { color: var(--hud-label); }
kbd {
  display: inline-block;
  min-width: 1.35em;
  padding: 1px 5px;
  font: 700 11px/1.3 inherit;
  text-align: center;
  color: var(--hud-label);
  background: rgba(255, 255, 255, 0.14);
  border-radius: 3px;
}

#perf {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  margin: 0;
  padding: 4px 8px;
  font: 10px/1.3 ui-monospace, Menlo, monospace;
  color: #e8f0ff;
  background: rgba(0, 0, 0, 0.78);
  border-radius: 4px;
  pointer-events: none;
}

#topbar {
  position: fixed;
  top: 12px;
  left: 16px;
  right: 16px;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }

.mode-switch, .pill-group, .tool-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: rgba(10, 12, 16, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
}

.mode-switch button,
.pill-group button,
.tool-btn,
.ghost-btn {
  appearance: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 6px 9px;
  font: 600 12px/1.2 inherit;
  letter-spacing: 0.02em;
  color: var(--hud-body-dim);
  background: transparent;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.mode-switch button:hover,
.pill-group button:hover,
.tool-btn:hover,
.ghost-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}
.mode-switch button[aria-pressed="true"],
.pill-group button[aria-current="true"],
.tool-btn[aria-pressed="true"] {
  color: #fff;
  background: rgba(196, 0, 0, 0.78);
  border-color: rgba(255, 96, 80, 0.55);
}

.stage-buttons { display: flex; align-items: center; gap: 4px; }
.stage-btn .stage-pts {
  margin-left: 5px;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}
.stage-btn.done { color: var(--hud-pass); }
.stage-btn.done[aria-current="true"] { color: #fff; }
.total-badge {
  padding: 0 8px;
  font: 700 12px/1 inherit;
  font-variant-numeric: tabular-nums;
  color: #fff;
  white-space: nowrap;
  border-left: 1px solid rgba(255, 255, 255, 0.14);
}

#car-menu {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: 4;
  width: min(300px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(10, 12, 16, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  backdrop-filter: blur(12px);
}
.car-menu-section { display: flex; flex-direction: column; gap: 6px; }
.car-menu-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font: 700 10px/1.2 inherit;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--hud-body-dim);
}
.car-menu-row { display: flex; gap: 5px; }
.car-opt {
  flex: 1;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: var(--hud-body-dim);
  font: 600 11px/1.2 inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.car-opt:hover { color: #fff; background: rgba(255, 255, 255, 0.1); }
.car-opt[aria-pressed="true"] {
  color: #fff;
  background: rgba(196, 0, 0, 0.78);
  border-color: rgba(255, 96, 80, 0.55);
}

#objective {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 8px 16px;
  background: rgba(10, 12, 16, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 10px;
  pointer-events: none;
  max-width: min(640px, calc(100vw - 32px));
}
.obj-main { display: flex; align-items: baseline; gap: 12px; }
.obj-title { font: 700 13px/1.2 inherit; letter-spacing: 0.06em; text-transform: uppercase; color: #fff; }
.obj-clock { font: 700 16px/1.2 inherit; font-variant-numeric: tabular-nums; color: var(--hud-text); }
.obj-prompt { font-size: 12px; color: var(--hud-body-dim); text-align: center; }
.obj-steps { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.step-chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--hud-body-dim);
}
.step-chip.done {
  background: rgba(108, 231, 149, 0.18);
  color: var(--hud-pass);
}

#pause-banner {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: rgba(10, 12, 16, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  color: #fff;
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
}
#pause-banner[hidden] { display: none; }
.pause-title { font: 700 13px/1 inherit; letter-spacing: 0.16em; color: var(--hud-warning); }
.pause-hint { font-size: 12px; color: var(--hud-body-dim); }

#telemetry {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 22px;
  background: rgba(10, 12, 16, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  pointer-events: none;
}
.gauge { display: flex; flex-direction: column; gap: 3px; }
.speed-gauge { flex-direction: row; align-items: baseline; gap: 6px; padding-right: 16px; border-right: 1px solid rgba(255, 255, 255, 0.12); }
.gauge-num { font: 700 32px/1 inherit; font-variant-numeric: tabular-nums; color: #fff; min-width: 2.2ch; text-align: right; }
.gauge-unit { font: 700 11px/1 inherit; letter-spacing: 0.1em; color: var(--hud-body-dim); }
.gauge-label { font: 700 10px/1 inherit; letter-spacing: 0.12em; color: var(--hud-body-dim); }
.gauge-val { font: 600 13px/1.1 inherit; font-variant-numeric: tabular-nums; color: #fff; white-space: nowrap; }
.gauge-val.good { color: var(--hud-pass); }
.gauge-val.warn { color: var(--hud-warning); }
.gauge-val.unlimited { color: var(--hud-what-if); }
.tank-bar-wrap { display: flex; align-items: center; gap: 8px; }
.tank-bar { width: 88px; height: 7px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); overflow: hidden; }
.tank-fill { height: 100%; width: 100%; background: var(--hud-fill); transition: width 0.08s linear; }
.tank-bar[hidden] { display: none; }
.damage-gauge { padding-left: 16px; border-left: 1px solid rgba(255, 255, 255, 0.12); }

.panel {
  position: fixed;
  top: 64px;
  right: 16px;
  bottom: 18px;
  z-index: 4;
  width: min(390px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 18px;
  overflow-y: auto;
  background: rgba(10, 11, 14, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
}
.stage-result { padding-bottom: 14px; border-bottom: 1px solid rgba(255, 255, 255, 0.12); }
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.verdict-tag {
  padding: 3px 9px;
  border-radius: 999px;
  font: 700 11px/1.2 inherit;
  letter-spacing: 0.1em;
  background: rgba(108, 231, 149, 0.2);
  color: var(--hud-pass);
}
.verdict-tag.miss { background: rgba(255, 206, 108, 0.2); color: var(--hud-warning); }
.result-score { font: 700 24px/1 inherit; font-variant-numeric: tabular-nums; color: #fff; }
.result-headline { margin: 0 0 10px; font-size: 13px; color: var(--hud-body); line-height: 1.4; }
.result-rows { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 5px; font-size: 12px; }
.result-rows li { display: flex; justify-content: space-between; gap: 8px; color: var(--hud-body-dim); }
.result-rows .row-pts { font-variant-numeric: tabular-nums; font-weight: 600; color: #fff; }
.result-rows .row-pts.good { color: var(--hud-pass); }
.panel-actions { display: flex; gap: 8px; }

.primary-btn, .secondary-btn {
  appearance: none;
  border-radius: 8px;
  padding: 8px 14px;
  font: 600 12px/1.2 inherit;
  cursor: pointer;
}
.primary-btn {
  flex: 1;
  border: 0;
  color: #fff;
  background: var(--hud-fill);
}
.primary-btn:disabled { opacity: 0.45; cursor: default; }
.secondary-btn {
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.board-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.board-head h2 { margin: 4px 0 0; font: 600 15px/1.2 inherit; color: #fff; }
.my-summary { display: flex; gap: 6px; margin-bottom: 8px; }
.my-chip {
  flex: 1;
  padding: 6px 8px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 11px;
  color: var(--hud-body-dim);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.my-chip strong { font-size: 14px; font-variant-numeric: tabular-nums; color: #fff; }
.board-rank { margin: 0 0 8px; font-size: 12px; color: var(--hud-label); }
#board-form { display: flex; gap: 8px; margin-bottom: 6px; }
#board-form input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font: 13px inherit;
  user-select: text;
}
#board-form input:focus { outline: 1px solid var(--hud-rule); }
.board-status { min-height: 16px; margin: 0 0 8px; font-size: 12px; color: var(--hud-body-dim); }
.board-status[data-kind="good"] { color: var(--hud-pass); }
.board-status[data-kind="bad"] { color: var(--hud-warning); }
.board-section table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.board-section th { text-align: left; font-weight: 600; color: var(--hud-body-dim); border-bottom: 1px solid rgba(255, 255, 255, 0.14); padding: 5px 4px; }
.board-section td { padding: 6px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); color: var(--hud-body); }
.board-section th:last-child, .board-section td:last-child { text-align: right; font-weight: 700; color: #fff; }
.board-section tr[data-mine="true"] td { color: var(--hud-pass); }
.board-footnote { margin: 10px 0 0; font-size: 11px; color: var(--hud-body-dim); line-height: 1.4; }

#start, #error, .modal {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.78);
}
body[data-state="loading"] #start { background: #000; }
.card {
  width: min(560px, 100%);
  padding: 28px 32px;
  background: rgba(14, 15, 19, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
}
.start-card { width: min(760px, 100%); }
.wordmark { font-size: 11px; font-weight: 700; letter-spacing: 0.45em; color: var(--hud-dim); }
h1 { margin: 10px 0 8px; font: 400 28px/1.2 inherit; color: #fff; }
.lede { margin: 0 0 18px; font-size: 14px; color: var(--hud-body-dim); line-height: 1.5; }
.load-status { margin: 0 0 14px; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--hud-body-dim); }
.start-modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 680px) { .start-modes { grid-template-columns: 1fr; } }
.mode-card {
  appearance: none;
  text-decoration: none;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s, border-color 0.12s;
}
.mode-card:focus { outline: none; }
.mode-card:focus-visible { outline: 2px solid rgba(255, 255, 255, 0.65); outline-offset: 2px; }
.mode-card:hover:not(:disabled) { transform: translateY(-1px); background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.32); }
.mode-card.accent { background: rgba(196, 0, 0, 0.22); border-color: rgba(205, 0, 0, 0.65); }
.mode-card.accent:hover:not(:disabled) { background: rgba(196, 0, 0, 0.36); }
.mode-card:disabled { opacity: 0.45; cursor: progress; }
.mode-name { font: 700 16px/1.2 inherit; color: #fff; }
.mode-desc { font-size: 12px; color: var(--hud-body-dim); line-height: 1.4; }

.controls-card { width: min(640px, 100%); max-height: 85vh; overflow-y: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
#controls-list { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
#controls-list h3 { margin: 0 0 8px; font: 700 11px/1.2 inherit; letter-spacing: 0.12em; text-transform: uppercase; color: var(--hud-dim); }
#controls-list dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; font-size: 12px; }
#controls-list dt { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
#controls-list dd { margin: 0; color: var(--hud-body); }
