:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #00001E;
  color: #FFFFFF;
  --surface: rgb(255 255 255 / 4%);
  --surface-raised: rgb(255 255 255 / 6%);
  --border: rgb(255 255 255 / 20%);
  --accent: #0099FF;
  --good: #00F3DB;
  --bad: #FF0095;
  --purple: #AD0AFD;
  --citrine: #CCFF00;
  --muted: rgb(255 255 255 / 65%);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 20rem;
  scroll-behavior: smooth;
}

body {
  min-width: 20rem;
  min-height: 100vh;
  margin: 0;
  background: #00001E;
  color: #FFFFFF;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

button {
  color: inherit;
}

#app {
  width: min(100% - 2rem, 76rem);
  margin: 0 auto;
  padding: clamp(1.25rem, 4vw, 3rem) 0 4rem;
}

.game-screen {
  display: grid;
  gap: 1.5rem;
}

.screen-header {
  position: relative;
  max-width: 56rem;
}

.eyebrow,
.hud-label,
.packet-label {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.5rem;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1.08;
}

h2 {
  margin-bottom: 0.75rem;
  font-size: clamp(1.25rem, 3vw, 1.65rem);
}

.screen-subtitle,
.control-hint,
.model-note {
  color: var(--muted);
}

.intro-card,
.briefing-card,
.packet-panel,
.routes-panel,
.feedback-card,
.summary-card,
.error-card {
  padding: clamp(1rem, 3vw, 1.75rem);
  border: 1px dashed rgb(255 255 255 / 15%);
  border-radius: 0.75rem;
  background: var(--surface);
}

.intro-card,
.briefing-card,
.summary-card,
.error-card {
  max-width: 58rem;
}

.intro-card > p,
.briefing-card > p,
.feedback-card > p,
.summary-card > p,
.error-card > p {
  line-height: 1.6;
}

.control-hint {
  padding: 0.8rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--surface-raised);
}

.primary-button,
.route-choice,
.secondary-button,
.mute-control {
  min-height: 2.8rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface-raised);
  cursor: pointer;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    transform 140ms ease;
}

.primary-button {
  padding: 0.7rem 1.15rem;
  border-color: var(--accent);
  background: rgb(0 153 255 / 15%);
  color: #FFFFFF;
  font-weight: 750;
}

.secondary-button {
  margin-left: 0.6rem;
  padding: 0.7rem 1.15rem;
  border-color: var(--border);
  background: var(--surface-raised);
}

.mute-control {
  position: absolute;
  top: 0;
  right: 0;
  min-height: 2.4rem;
  padding: 0.45rem 0.75rem;
  border-color: var(--border);
  background: var(--surface-raised);
}

.primary-button:hover,
.route-choice:hover,
.secondary-button:hover,
.mute-control:hover {
  border-color: var(--accent);
  background: rgb(0 153 255 / 25%);
}

.primary-button:active,
.route-choice:active {
  transform: translateY(1px);
}

.destination-line {
  padding: 0.8rem 1rem;
  border-radius: 0.6rem;
  background: var(--surface-raised);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
}

.explanation {
  padding: 0.85rem 1rem;
  border-left: 3px solid var(--good);
  background: var(--surface-raised);
  line-height: 1.55;
}

.model-note {
  font-size: 0.92rem;
  line-height: 1.5;
}

.run-hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.hud-metric {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface);
}

.hud-value {
  font-size: 1.35rem;
}

.packet-panel,
.routes-panel {
  min-width: 0;
}

.packet-progress {
  display: block;
  width: 100%;
  height: 0.55rem;
  margin-top: 1rem;
  border: 0;
  border-radius: 99px;
  background: rgb(255 255 255 / 15%);
  accent-color: var(--accent);
}

.packet-progress::-webkit-progress-bar {
  border-radius: inherit;
  background: rgb(255 255 255 / 15%);
}

.packet-progress::-webkit-progress-value {
  border-radius: inherit;
  background: var(--accent);
  transition: width 100ms linear;
}

.packet-progress::-moz-progress-bar {
  border-radius: inherit;
  background: var(--accent);
}

.packet-flight {
  position: relative;
  height: 8rem;
  overflow: hidden;
}

.packet-card {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  padding: 1.1rem;
  border: 1px solid var(--accent);
  border-radius: 0.5rem;
  background: rgb(0 153 255 / 12%);
  animation: packet-fall var(--fall-duration, 10000ms) linear var(--fall-delay, 0ms) both;
}

.packet-label {
  flex-basis: 100%;
}

.packet-destination {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(1.1rem, 4vw, 1.55rem);
  overflow-wrap: anywhere;
}

.packet-family {
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--purple);
  border-radius: 99px;
  background: rgb(173 10 253 / 12%);
  color: #FFFFFF;
  font-size: 0.75rem;
  font-weight: 750;
}

.route-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
}

.route-table th,
.route-table td {
  padding: 0.75rem 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.route-table th {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.route-table td:first-child {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  white-space: nowrap;
}

.protocol-badge {
  display: inline-block;
  padding: 0.18rem 0.45rem;
  border: 1px solid var(--purple);
  border-radius: 0.35rem;
  background: rgb(173 10 253 / 12%);
  color: #FFFFFF;
  font-size: 0.84em;
  white-space: nowrap;
}

.route-choice {
  padding: 0.45rem 0.65rem;
  text-align: left;
}

.route-choice[aria-pressed="true"] {
  border-color: var(--accent);
  background: rgb(0 153 255 / 15%);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.winning-route {
  background: rgb(0 243 219 / 10%);
}

.winning-route td:first-child {
  color: var(--good);
}

.status-panel {
  min-height: 1.5rem;
  margin: 1rem 0;
  color: var(--muted);
}

.status-warning {
  color: var(--bad);
}

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

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

.feedback-outcome {
  color: var(--good);
  font-size: 1.5rem;
  font-weight: 850;
}

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

.score-line {
  color: var(--muted);
  font-weight: 700;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes packet-fall {
  from {
    transform: translateY(0);
  }

  to {
    transform: translateY(5rem);
  }
}

@media (max-width: 42rem) {
  #app {
    width: min(100% - 1rem, 76rem);
  }

  .run-hud {
    gap: 0.4rem;
  }

  .hud-metric {
    display: grid;
    gap: 0.2rem;
    padding: 0.65rem;
  }

  .hud-value {
    font-size: 1.15rem;
  }

  .route-table {
    font-size: 0.82rem;
  }

  .route-table th,
  .route-table td {
    padding: 0.55rem 0.35rem;
  }

  .route-table th {
    font-size: 0.65rem;
  }

  .route-choice {
    padding: 0.4rem;
  }

  .secondary-button {
    margin: 0.65rem 0 0;
  }
}

@media (max-width: 27rem) {
  .route-table th:nth-child(4),
  .route-table td:nth-child(4) {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
