:root {
  --bg: #08080f;
  --panel: #10101d;
  --panel-2: #171727;
  --cyan: #00f5ff;
  --magenta: #ff006e;
  --yellow: #ffe600;
  --green: #00ff88;
  --ink: #f6fbff;
  --muted: #a6adc7;
  --line: rgba(255, 255, 255, 0.13);
  --danger: #ff3158;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, sans-serif;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 14%, rgba(0, 245, 255, 0.14), transparent 30%),
    radial-gradient(circle at 84% 20%, rgba(255, 0, 110, 0.12), transparent 28%),
    linear-gradient(135deg, #08080f 0%, #11111f 54%, #070710 100%);
}

button {
  font: inherit;
}

.scanlines {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  background-image: linear-gradient(rgba(255, 255, 255, 0.032) 50%, transparent 50%);
  background-size: 100% 4px;
  mix-blend-mode: overlay;
  opacity: 0.3;
}

.back-link {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 70;
  color: var(--cyan);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 800;
  padding: 10px 12px;
  border: 1px solid rgba(0, 245, 255, 0.35);
  background: rgba(8, 8, 15, 0.84);
  box-shadow: 0 0 18px rgba(0, 245, 255, 0.18);
}

.shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 72px 0 28px;
}

.hud,
.arena,
.achievements {
  border: 1px solid var(--line);
  background: rgba(15, 15, 26, 0.88);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
}

.eyebrow,
.stat span,
.scoreline span,
.result-stats span {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

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

h1 {
  margin-top: 8px;
  color: var(--cyan);
  font-size: clamp(1.25rem, 4vw, 2.25rem);
  text-shadow: 0 0 20px rgba(0, 245, 255, 0.45);
}

.stats,
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(84px, 1fr));
  gap: 10px;
}

.stat,
.result-stats div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.stat strong,
.scoreline strong,
.result-stats strong {
  display: block;
  margin-top: 6px;
  color: var(--yellow);
  font-family: "Press Start 2P", monospace;
  font-size: 1rem;
}

.arena {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 310px;
  gap: 18px;
  margin-top: 18px;
  padding: 18px;
}

.board-zone {
  display: grid;
  gap: 12px;
  align-content: center;
}

.route-meter {
  width: 100%;
  height: 10px;
  border: 1px solid rgba(0, 245, 255, 0.45);
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

#route-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--green), var(--cyan), var(--yellow));
  box-shadow: 0 0 18px rgba(0, 245, 255, 0.65);
  transform-origin: left center;
}

.board {
  width: min(70vh, 100%);
  max-width: 650px;
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: clamp(4px, 0.85vw, 8px);
  padding: clamp(8px, 1.5vw, 14px);
  border: 1px solid rgba(0, 245, 255, 0.35);
  touch-action: none;
  user-select: none;
  background:
    linear-gradient(rgba(0, 245, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 245, 255, 0.08) 1px, transparent 1px),
    rgba(4, 6, 14, 0.78);
  background-size: 28px 28px;
  box-shadow: inset 0 0 30px rgba(0, 245, 255, 0.12), 0 0 44px rgba(0, 245, 255, 0.12);
}

.cell {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.11);
  background: rgba(255, 255, 255, 0.045);
  color: #fff;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 160ms ease, box-shadow 160ms ease;
}

.cell::before,
.cell::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 900;
  line-height: 1;
}

.cell.start {
  border-color: rgba(0, 245, 255, 0.8);
  background: rgba(0, 245, 255, 0.18);
  box-shadow: 0 0 20px rgba(0, 245, 255, 0.3);
}

.cell.start::before {
  content: "D";
  color: var(--cyan);
}

.cell.dropoff {
  border-color: rgba(0, 255, 136, 0.8);
  background: rgba(0, 255, 136, 0.15);
  box-shadow: 0 0 20px rgba(0, 255, 136, 0.26);
}

.cell.dropoff::before {
  content: "X";
  color: var(--green);
}

.cell.cargo::before {
  content: "";
  inset: 28%;
  background: var(--yellow);
  box-shadow: 0 0 16px rgba(255, 230, 0, 0.72);
}

.cell.gate::before {
  content: "";
  inset: 18% 34%;
  border-left: 3px solid var(--cyan);
  border-right: 3px solid var(--magenta);
}

.cell.hazard {
  border-color: rgba(255, 49, 88, 0.7);
  background: repeating-linear-gradient(135deg, rgba(255, 49, 88, 0.24) 0 5px, rgba(255, 49, 88, 0.05) 5px 10px);
}

.cell.hazard::before {
  content: "!";
  color: var(--danger);
}

.cell.path {
  border-color: rgba(0, 245, 255, 0.76);
  background: rgba(0, 245, 255, 0.18);
  box-shadow: inset 0 0 0 2px rgba(0, 245, 255, 0.24);
}

.cell.current {
  transform: scale(1.05);
  border-color: #fff;
  box-shadow: 0 0 22px rgba(255, 255, 255, 0.32), inset 0 0 0 2px rgba(255, 255, 255, 0.22);
}

.cell.runner::after {
  content: "";
  inset: 30%;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 18px #fff, 0 0 28px var(--cyan);
}

.cell.fail {
  animation: fail 280ms ease;
}

.cell.success {
  animation: success 360ms ease;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 16px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
}

.scoreline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.scoreline.danger strong {
  color: var(--danger);
}

.message {
  min-height: 74px;
  margin: 0;
  color: #dce7ff;
  line-height: 1.45;
  font-weight: 700;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: auto;
}

.actions button {
  min-height: 44px;
  border: 1px solid rgba(0, 245, 255, 0.44);
  background: rgba(0, 245, 255, 0.12);
  color: var(--ink);
  font-weight: 900;
  text-transform: uppercase;
  cursor: pointer;
}

.actions button:hover,
.actions button:focus-visible {
  outline: none;
  background: rgba(0, 245, 255, 0.24);
}

.actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.achievements {
  margin-top: 18px;
  padding: 16px;
}

.achievements h2 {
  font-size: 0.9rem;
  color: var(--green);
}

.achievement-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.badge {
  min-height: 48px;
  padding: 9px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.badge.unlocked {
  color: var(--ink);
  border-color: rgba(0, 255, 136, 0.46);
  background: rgba(0, 255, 136, 0.1);
  box-shadow: 0 0 18px rgba(0, 255, 136, 0.12);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 60;
  transform: translate(-50%, 80px);
  padding: 11px 16px;
  background: var(--cyan);
  color: #001015;
  font-weight: 900;
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

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

.overlay.hidden {
  display: none;
}

.result-card {
  width: min(520px, 100%);
  padding: 22px;
  border: 1px solid rgba(0, 245, 255, 0.38);
  background: #10101d;
  box-shadow: 0 0 50px rgba(0, 245, 255, 0.18);
}

.result-card h2 {
  margin-top: 10px;
  color: var(--cyan);
  font-size: 1.2rem;
}

.result-card p:not(.eyebrow) {
  color: #dce7ff;
  line-height: 1.5;
}

.result-stats {
  margin: 16px 0;
}

@keyframes fail {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

@keyframes success {
  0% {
    transform: scale(0.94);
  }

  65% {
    transform: scale(1.09);
  }

  100% {
    transform: scale(1);
  }
}

@media (max-width: 840px) {
  .shell {
    width: min(100vw - 18px, 700px);
    padding-top: 66px;
  }

  .hud {
    align-items: stretch;
    flex-direction: column;
  }

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

  .arena {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .board {
    width: min(100%, 72vh);
  }

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

  .message,
  .actions {
    grid-column: 1 / -1;
  }
}

@media (max-width: 540px) {
  .back-link {
    top: 8px;
    left: 8px;
    padding: 8px 10px;
    font-size: 0.74rem;
  }

  .shell {
    width: calc(100vw - 12px);
    padding-top: 56px;
  }

  h1 {
    font-size: 1.08rem;
  }

  .hud,
  .arena,
  .achievements {
    padding: 10px;
  }

  .stat {
    padding: 9px;
  }

  .stat span,
  .scoreline span,
  .result-stats span {
    font-size: 0.62rem;
  }

  .stat strong,
  .scoreline strong,
  .result-stats strong {
    font-size: 0.78rem;
  }

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

  .achievement-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
