:root {
  --bg: #08080f;
  --panel: rgba(15, 15, 26, 0.92);
  --line: rgba(0, 245, 255, 0.24);
  --cyan: #00f5ff;
  --magenta: #ff006e;
  --yellow: #ffe600;
  --green: #00ff88;
  --danger: #ff3d71;
  --ink: #f7fbff;
  --muted: #9ca6bd;
  --radius: 8px;
  font-family: Inter, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 16%, rgba(0, 245, 255, 0.2), transparent 27%),
    radial-gradient(circle at 86% 15%, rgba(255, 0, 110, 0.18), transparent 27%),
    linear-gradient(135deg, #08080f 0%, #10101c 58%, #08080f 100%);
  color: var(--ink);
  touch-action: manipulation;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(0, 245, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 0, 110, 0.04) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, black, transparent 84%);
}

button {
  font: inherit;
}

.back-link {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 20;
  color: var(--cyan);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 900;
  text-shadow: 0 0 14px rgba(0, 245, 255, 0.65);
}

.shell {
  width: min(1240px, calc(100vw - 24px));
  min-height: 100dvh;
  margin: 0 auto;
  padding: 56px 0 24px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
}

.topbar,
.side-panel,
.route-panel,
.modal {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.42), inset 0 0 28px rgba(0, 245, 255, 0.04);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-radius: var(--radius);
}

.eyebrow,
.panel-title {
  margin: 0 0 8px;
  color: var(--yellow);
  font: 0.62rem "Press Start 2P", monospace;
}

h1,
h2 {
  margin: 0;
  font-family: "Press Start 2P", monospace;
  letter-spacing: 0;
  line-height: 1.25;
}

h1 {
  font-size: clamp(1.15rem, 2.8vw, 2rem);
  color: var(--cyan);
  text-shadow: 0 0 20px rgba(0, 245, 255, 0.65);
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(86px, 1fr));
  gap: 8px;
}

.hud-card,
.mini-stat,
.best-row > div,
.station-item {
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--radius);
  padding: 10px;
}

.hud-card span,
.mini-stat span,
.best-row span,
.station-item span {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 900;
}

.hud-card strong,
.mini-stat strong,
.best-row strong {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: 1.28rem;
  line-height: 1;
}

.game-stage {
  display: grid;
  grid-template-columns: 190px minmax(320px, 1fr) 230px;
  align-items: start;
  justify-content: center;
  gap: 16px;
}

.side-panel,
.route-panel {
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 12px;
}

.yard-wrap {
  position: relative;
  display: grid;
  gap: 10px;
}

#yardCanvas {
  width: 100%;
  aspect-ratio: 1.55;
  max-height: calc(100dvh - 170px);
  border: 1px solid rgba(0, 245, 255, 0.34);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.36);
  box-shadow: 0 0 35px rgba(0, 245, 255, 0.15);
  touch-action: none;
}

.switch-buttons {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.switch-btn {
  min-height: 46px;
  border: 1px solid rgba(0, 245, 255, 0.34);
  border-radius: var(--radius);
  color: var(--ink);
  background: rgba(0, 245, 255, 0.08);
  font-weight: 1000;
  cursor: pointer;
}

.switch-btn.on {
  color: #05050a;
  background: var(--green);
  box-shadow: 0 0 18px rgba(0, 255, 136, 0.36);
}

.switch-btn.danger {
  animation: danger-pulse 420ms ease;
}

@keyframes danger-pulse {
  50% {
    transform: translateY(-2px);
    border-color: var(--danger);
    box-shadow: 0 0 22px rgba(255, 61, 113, 0.55);
  }
}

.station-legend {
  display: grid;
  gap: 8px;
}

.station-item {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 8px;
}

.station-swatch {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--station-color);
  box-shadow: 0 0 14px var(--station-color);
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.primary-btn,
.secondary-btn,
.small-btn {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 12px;
  color: #040408;
  background: var(--cyan);
  font-weight: 1000;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(0, 245, 255, 0.35);
}

.secondary-btn,
.small-btn-ghost {
  color: var(--cyan);
  background: rgba(0, 245, 255, 0.08);
  border: 1px solid rgba(0, 245, 255, 0.35);
  box-shadow: none;
}

.pressure-meter {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  background: rgba(255, 255, 255, 0.06);
}

.pressure-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--danger));
  transition: width 160ms ease;
}

.feedback,
.hint,
.modal-copy {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
  margin: 0;
}

.feedback.good {
  color: var(--green);
}

.feedback.bad {
  color: var(--danger);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 4, 10, 0.78);
  backdrop-filter: blur(10px);
}

.overlay.hidden,
.hidden {
  display: none;
}

.modal {
  width: min(540px, 100%);
  display: grid;
  gap: 16px;
  padding: 24px;
  border-radius: var(--radius);
  text-align: center;
}

.modal h2 {
  color: var(--cyan);
  font-size: clamp(1.2rem, 5vw, 2rem);
}

.best-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.best-row.three {
  grid-template-columns: repeat(3, 1fr);
}

.score-hero {
  display: grid;
  gap: 4px;
}

.score-hero span {
  color: var(--yellow);
  font-weight: 900;
}

.score-hero strong {
  font-size: 3rem;
  color: var(--green);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.achievement-toast {
  border: 1px solid rgba(255, 230, 0, 0.5);
  border-radius: var(--radius);
  padding: 10px;
  color: var(--yellow);
  background: rgba(255, 230, 0, 0.08);
  font-weight: 900;
}

@media (max-width: 1040px) {
  .topbar,
  .game-stage {
    grid-template-columns: 1fr;
  }

  .hud {
    grid-template-columns: repeat(4, 1fr);
  }

  .side-panel,
  .route-panel {
    width: 100%;
  }

  .route-panel {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

@media (max-width: 680px) {
  .shell {
    width: min(100vw - 12px, 560px);
    padding-top: 50px;
  }

  .topbar {
    padding: 12px;
  }

  .hud,
  .route-panel,
  .controls,
  .button-row,
  .best-row,
  .best-row.three {
    grid-template-columns: 1fr 1fr;
  }

  .route-panel {
    grid-template-columns: 1fr;
  }

  .hud-card strong {
    font-size: 1.05rem;
  }

  #yardCanvas {
    max-height: none;
  }

  .switch-buttons {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 430px) {
  .hud,
  .controls,
  .button-row,
  .best-row,
  .best-row.three {
    grid-template-columns: 1fr;
  }
}
