:root {
  --bg-void: #05080f;
  --bg-grid: #090d16;
  --surface-panel: rgba(11, 17, 30, 0.94);
  --surface-elevated: rgba(18, 28, 48, 0.96);
  --border-tech: #243451;
  --border-bright: #3b537e;
  --accent-chrono: #10b981;
  --accent-chrono-glow: rgba(16, 185, 129, 0.28);
  --accent-tungsten: #f97316;
  --accent-tungsten-glow: rgba(249, 115, 22, 0.3);
  --accent-threat: #ef4444;
  --accent-shield: #38bdf8;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --font-display: "Bahnschrift", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", "SFMono-Regular", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-void);
  color: var(--text-primary);
  font-family: var(--font-display);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

#viewport-root {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 45%, #0c1424 0%, #05080f 75%);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#stage {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  container-type: inline-size;
  background-color: var(--bg-grid);
  border: 1px solid var(--border-tech);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.72), 0 0 0 1px rgba(16, 185, 129, 0.08);
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* Chamfered Architectural Geometry */
.chamfered {
  clip-path: polygon(
    14px 0,
    calc(100% - 14px) 0,
    100% 14px,
    100% calc(100% - 14px),
    calc(100% - 14px) 100%,
    14px 100%,
    0 calc(100% - 14px),
    0 14px
  );
}

.chamfered-sm {
  clip-path: polygon(
    8px 0,
    calc(100% - 8px) 0,
    100% 8px,
    100% calc(100% - 8px),
    calc(100% - 8px) 100%,
    8px 100%,
    0 calc(100% - 8px),
    0 8px
  );
}

/* Top HUD Bar */
.hud-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 7.5%;
  padding: 0 1.6cqw;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1cqw;
  background: linear-gradient(180deg, rgba(7, 11, 20, 0.96) 0%, rgba(9, 13, 22, 0.88) 100%);
  border-bottom: 1px solid var(--border-tech);
  z-index: 10;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 0.9cqw;
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: 0.45cqw;
}

.hud-label {
  font-size: clamp(11px, 1.05cqw, 15px);
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.hud-value {
  font-size: clamp(12px, 1.2cqw, 17px);
  font-weight: 700;
  color: var(--text-primary);
}

.hud-divider {
  width: 1px;
  height: 1.5cqw;
  background: var(--border-tech);
}

.hud-icon {
  width: 0.95cqw;
  height: 0.95cqw;
  min-width: 10px;
  min-height: 10px;
  display: inline-block;
  flex-shrink: 0;
}

.icon-armor {
  background: var(--accent-chrono);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

.icon-rail {
  background: var(--accent-tungsten);
  clip-path: polygon(15% 0%, 100% 50%, 15% 100%, 35% 50%);
}

.icon-dash {
  background: var(--accent-shield);
  clip-path: polygon(0% 50%, 55% 0%, 100% 50%, 55% 100%);
}

.pip-row {
  display: flex;
  align-items: center;
  gap: 0.25cqw;
}

.pip {
  width: 0.95cqw;
  height: 0.65cqw;
  min-width: 9px;
  min-height: 6px;
  background: rgba(148, 163, 184, 0.2);
  border: 1px solid rgba(148, 163, 184, 0.35);
  transition: transform 0.14s ease-out, background-color 0.14s ease-out;
}

.pip.armor.filled {
  background: var(--accent-chrono);
  border-color: #6ee7b7;
  box-shadow: 0 0 6px var(--accent-chrono-glow);
}

.pip.armor.low {
  background: var(--accent-threat);
  border-color: #fca5a5;
}

.pip.rail.filled {
  background: var(--accent-tungsten);
  border-color: #fdba74;
  box-shadow: 0 0 6px var(--accent-tungsten-glow);
}

.pip.dash.filled {
  background: var(--accent-shield);
  border-color: #bae6fd;
}

.hud-center {
  flex-direction: column;
  gap: 0.25cqw;
  min-width: 16cqw;
}

.sector-readout {
  display: flex;
  align-items: center;
  gap: 0.7cqw;
}

.hud-sector {
  font-size: clamp(12px, 1.15cqw, 16px);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.06em;
}

.chrono-badge {
  font-size: clamp(10px, 0.92cqw, 13px);
  font-weight: 700;
  padding: 0.12cqw 0.45cqw;
  border: 1px solid var(--accent-chrono);
  color: #6ee7b7;
  background: rgba(16, 185, 129, 0.14);
}

.chrono-badge[data-mode="live"] {
  border-color: var(--accent-tungsten);
  color: #fdba74;
  background: rgba(249, 115, 22, 0.16);
}

.chrono-bar-track {
  width: 100%;
  height: 0.28cqw;
  min-height: 3px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}

.chrono-bar-fill {
  height: 100%;
  width: 8%;
  background: var(--accent-chrono);
  transition: width 0.08s linear, background-color 0.12s linear;
}

.chips-strip {
  display: flex;
  align-items: center;
  gap: 0.3cqw;
}

.chip-badge {
  font-family: var(--font-mono);
  font-size: clamp(10px, 0.85cqw, 12px);
  font-weight: 700;
  padding: 0.15cqw 0.4cqw;
  background: rgba(249, 115, 22, 0.15);
  border: 1px solid rgba(249, 115, 22, 0.55);
  color: #fed7aa;
}

.hud-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.3cqw;
  height: 2.3cqw;
  min-width: 28px;
  min-height: 28px;
  background: rgba(20, 30, 50, 0.9);
  border: 1px solid var(--border-tech);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.hud-btn:hover {
  border-color: var(--accent-chrono);
  background: rgba(16, 185, 129, 0.16);
}

.hud-btn:focus-visible,
button:focus-visible,
input:focus-visible,
.draft-card:focus-visible {
  outline: 2px solid var(--accent-chrono);
  outline-offset: 2px;
}

/* Boss Bar */
.boss-hud {
  position: absolute;
  top: 8.6%;
  left: 50%;
  transform: translateX(-50%);
  width: 34cqw;
  padding: 0.45cqw 0.9cqw;
  background: rgba(9, 13, 22, 0.88);
  border: 1px solid rgba(239, 68, 68, 0.6);
  z-index: 9;
  pointer-events: none;
}

.boss-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.3cqw;
}

.boss-name {
  font-size: clamp(11px, 1cqw, 14px);
  font-weight: 700;
  color: #fca5a5;
  letter-spacing: 0.08em;
}

.boss-hp-text {
  font-size: clamp(11px, 1cqw, 14px);
  color: var(--text-primary);
}

.boss-bar-track {
  width: 100%;
  height: 0.55cqw;
  min-height: 6px;
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.boss-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ef4444 0%, #f97316 100%);
  transition: width 0.12s ease-out;
}

/* Overlay Screens */
.overlay-screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 15, 0.72);
  backdrop-filter: blur(4px);
  z-index: 20;
  padding: 2cqw;
}

.title-screen {
  background: linear-gradient(90deg, rgba(5, 8, 15, 0.9) 0%, rgba(5, 8, 15, 0.65) 58%, rgba(5, 8, 15, 0.35) 100%);
  justify-content: flex-start;
  padding: 4cqw 5cqw;
  backdrop-filter: blur(2px);
}

.title-frame {
  position: relative;
  width: min(56cqw, 92%);
  padding: 2.6cqw 3cqw;
  background: rgba(9, 13, 22, 0.88);
  border: 1px solid var(--border-bright);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}

.title-grid-accent .corner-mark {
  position: absolute;
  width: 14px;
  height: 14px;
  border-color: var(--accent-chrono);
  border-style: solid;
  pointer-events: none;
}

.corner-mark.tl { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.corner-mark.tr { top: -1px; right: -1px; border-width: 2px 2px 0 0; }
.corner-mark.bl { bottom: -1px; left: -1px; border-width: 0 0 2px 2px; }
.corner-mark.br { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }

.title-kicker {
  font-size: clamp(11px, 1cqw, 14px);
  color: var(--accent-chrono);
  letter-spacing: 0.14em;
  margin-bottom: 0.6cqw;
}

.game-title {
  display: flex;
  flex-direction: column;
  line-height: 0.94;
  margin-bottom: 1.1cqw;
}

.title-main {
  font-size: clamp(32px, 4.6cqw, 64px);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text-primary);
}

.title-sub {
  font-size: clamp(18px, 2.2cqw, 30px);
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--accent-tungsten);
  margin-top: 0.25cqw;
}

.title-tagline {
  font-size: clamp(13px, 1.35cqw, 18px);
  line-height: 1.45;
  color: var(--text-secondary);
  max-width: 46ch;
  margin-bottom: 1.8cqw;
}

.title-tagline strong {
  color: var(--accent-chrono);
}

.title-actions {
  display: flex;
  flex-direction: column;
  gap: 0.9cqw;
  margin-bottom: 1.8cqw;
}

.title-secondary-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1cqw;
}

.best-record {
  font-size: clamp(11px, 1cqw, 14px);
  color: var(--text-muted);
}

.controls-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6cqw 1.4cqw;
  padding-top: 1.2cqw;
  border-top: 1px solid var(--border-tech);
  font-size: clamp(11px, 1cqw, 14px);
}

.control-item {
  display: flex;
  align-items: center;
  gap: 0.55cqw;
  color: var(--text-secondary);
}

kbd {
  display: inline-block;
  padding: 0.15cqw 0.45cqw;
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid var(--border-bright);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.92em;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-ghost {
  font-family: var(--font-display);
  font-size: clamp(13px, 1.35cqw, 18px);
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0.85cqw 1.8cqw;
  border: none;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease, background-color 0.15s ease;
}

.btn-primary {
  background: var(--accent-chrono);
  color: #04130e;
  align-self: flex-start;
  box-shadow: 0 0 24px rgba(16, 185, 129, 0.35);
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--accent-tungsten);
  color: #1c0a02;
}

.btn-secondary:hover {
  filter: brightness(1.08);
}

.btn-ghost {
  background: rgba(21, 31, 52, 0.92);
  color: var(--text-primary);
  border: 1px solid var(--border-bright);
  padding: 0.7cqw 1.3cqw;
  font-size: clamp(12px, 1.15cqw, 16px);
}

.btn-ghost:hover {
  border-color: var(--accent-chrono);
  background: rgba(16, 185, 129, 0.14);
}

/* Modal Panels */
.modal-panel {
  width: min(72cqw, 94%);
  background: var(--surface-panel);
  border: 1px solid var(--border-bright);
  padding: 2cqw 2.4cqw;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.8);
}

.pause-panel,
.end-panel {
  width: min(46cqw, 92%);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1cqw;
  margin-bottom: 1.4cqw;
}

.modal-title {
  font-size: clamp(20px, 2.3cqw, 32px);
  font-weight: 800;
  color: var(--text-primary);
}

.modal-subtitle {
  font-size: clamp(13px, 1.25cqw, 17px);
  color: var(--text-secondary);
  margin-top: 0.3cqw;
}

.sector-pill {
  font-size: clamp(11px, 1cqw, 14px);
  font-weight: 700;
  padding: 0.3cqw 0.75cqw;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid var(--accent-chrono);
  color: #6ee7b7;
  white-space: nowrap;
}

/* Overclock Chip Draft Cards */
.draft-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.2cqw;
  margin-bottom: 1.3cqw;
}

.draft-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.85cqw;
  padding: 1.3cqw;
  background: var(--surface-elevated);
  border: 1px solid var(--border-bright);
  text-align: left;
  color: var(--text-primary);
  cursor: pointer;
  transition: transform 0.14s ease-out, border-color 0.14s ease-out, box-shadow 0.14s ease-out;
}

.draft-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-tungsten);
  box-shadow: 0 10px 28px rgba(249, 115, 22, 0.22);
}

.draft-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5cqw;
}

.draft-hotkey {
  font-family: var(--font-mono);
  font-size: clamp(11px, 0.95cqw, 13px);
  padding: 0.15cqw 0.45cqw;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border-bright);
  color: var(--accent-tungsten);
}

.draft-tag {
  font-family: var(--font-mono);
  font-size: clamp(10px, 0.88cqw, 12px);
  color: var(--accent-chrono);
}

.draft-card-title {
  font-size: clamp(15px, 1.55cqw, 21px);
  font-weight: 800;
  color: var(--text-primary);
  margin-top: 0.2cqw;
}

.draft-card-desc {
  font-size: clamp(12px, 1.15cqw, 16px);
  line-height: 1.4;
  color: var(--text-secondary);
}

.draft-card-cta {
  font-family: var(--font-mono);
  font-size: clamp(11px, 0.95cqw, 13px);
  color: #fdba74;
  padding-top: 0.6cqw;
  border-top: 1px solid rgba(148, 163, 184, 0.18);
}

.draft-footer {
  font-size: clamp(11px, 1cqw, 14px);
  color: var(--text-muted);
  text-align: center;
}

/* Settings Modal */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 0.9cqw;
  margin-bottom: 1.6cqw;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.2cqw;
  padding: 0.8cqw 1cqw;
  background: rgba(17, 26, 44, 0.85);
  border: 1px solid var(--border-tech);
  cursor: pointer;
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 0.18cqw;
}

.setting-name {
  font-size: clamp(13px, 1.25cqw, 17px);
  font-weight: 700;
  color: var(--text-primary);
}

.setting-desc {
  font-size: clamp(11px, 1cqw, 14px);
  color: var(--text-muted);
}

.setting-control {
  display: flex;
  align-items: center;
  gap: 0.6cqw;
}

.setting-val {
  min-width: 3.8ch;
  text-align: right;
  font-size: clamp(12px, 1.1cqw, 15px);
  color: var(--accent-chrono);
}

input[type="range"] {
  accent-color: var(--accent-chrono);
  width: 9cqw;
  cursor: pointer;
}

.toggle-input {
  width: 1.5cqw;
  height: 1.5cqw;
  min-width: 18px;
  min-height: 18px;
  accent-color: var(--accent-chrono);
  cursor: pointer;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8cqw;
}

/* End Screen Stats */
.end-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9cqw;
  margin: 1.4cqw 0 1.8cqw;
}

.end-stat-box {
  display: flex;
  flex-direction: column;
  gap: 0.3cqw;
  padding: 0.9cqw;
  background: rgba(17, 26, 44, 0.9);
  border: 1px solid var(--border-tech);
}

.end-stat-label {
  font-size: clamp(10px, 0.95cqw, 13px);
  color: var(--text-muted);
}

.end-stat-val {
  font-size: clamp(14px, 1.4cqw, 20px);
  font-weight: 700;
  color: var(--text-primary);
}

/* Mobile Touch Controls */
.touch-controls {
  position: absolute;
  inset: 7.5% 0 0 0;
  pointer-events: none;
  z-index: 8;
}

.touch-pad {
  position: absolute;
  bottom: 3cqw;
  width: 12cqw;
  height: 12cqw;
  min-width: 96px;
  min-height: 96px;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.touch-move {
  left: 3cqw;
}

.touch-right-cluster {
  position: absolute;
  right: 3cqw;
  bottom: 3cqw;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1.2cqw;
  pointer-events: none;
}

.touch-aim {
  position: relative;
  bottom: 0;
}

.touch-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(16, 185, 129, 0.45);
  background: rgba(9, 13, 22, 0.45);
}

.aim-ring {
  border-color: rgba(249, 115, 22, 0.45);
}

.touch-knob {
  width: 42%;
  height: 42%;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.65);
  border: 2px solid #a7f3d0;
  transform: translate(0, 0);
}

.aim-knob {
  background: rgba(249, 115, 22, 0.65);
  border-color: #fed7aa;
}

.touch-hint {
  position: absolute;
  bottom: -1.8cqw;
  font-size: clamp(10px, 0.9cqw, 12px);
  color: var(--text-muted);
}

.touch-action-btn {
  pointer-events: auto;
  padding: 0.9cqw 1.6cqw;
  background: rgba(56, 189, 248, 0.25);
  border: 1px solid #38bdf8;
  color: var(--text-primary);
  font-size: clamp(11px, 1.1cqw, 15px);
  font-weight: 700;
  border-radius: 6px;
}
