:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
  --background: #101923;
  --panel: #182632;
  --border: #354958;
  --ink: #f3f5f4;
  --muted: #b6c6d1;
  --gold: #ffcb79;
  --blue: #91e8ff;
  --mono: "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 0, #243a46, var(--background) 65%);
}
.shell { width: min(calc(100% - 32px), 1080px, max(650px, calc((100dvh - 288px) * 960 / 510))); margin-inline: auto; }
.topbar { background: #101923; border-bottom: 1px solid var(--border); }
.topbar-inner { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; min-height: 62px; }
h1 { margin: 0; font: 750 clamp(1.4rem, 4vw, 2rem)/1.1 "Segoe UI", system-ui, sans-serif; letter-spacing: -.035em; }
.back { justify-self: start; }
#pause { justify-self: end; }
.control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 8px 14px;
  border: 1px solid #597285;
  border-radius: 8px;
  background: #233442;
  color: var(--ink);
  font: 650 .94rem/1.2 "Segoe UI", system-ui, sans-serif;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}
.control:not(:disabled):hover { border-color: #a8c9df; background: #334d60; }
.control:disabled { color: var(--muted); opacity: .65; cursor: default; }
.primary { color: #241a10; background: var(--gold); border-color: var(--gold); }
.primary:not(:disabled):hover { background: #ffe3b8; border-color: #ffe3b8; }
.primary:disabled { color: #241a10; }
:where(a, button, input, select):focus-visible { outline: 3px solid #fff1bc; outline-offset: 3px; }
main { padding-block: 14px 22px; }
.dispatch { border: 1px solid var(--border); border-radius: 14px; overflow: clip; background: var(--panel); box-shadow: 0 13px 35px #080b125c; }
.readouts {
  min-height: 70px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px clamp(14px, 2.6vw, 32px);
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
}
.readout, .departures { display: grid; align-content: center; gap: 4px; }
.label { color: var(--muted); font-weight: 650; font-size: .875rem; line-height: 1.2; }
.readout strong { font: 700 1.22rem/1 var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
#score { color: #8ce4c1; }
.departures ol { display: flex; gap: 5px; align-items: center; min-height: 25px; padding: 0; margin: 0; list-style: none; }
.departure {
  display: grid;
  place-items: center;
  min-width: 25px;
  height: 25px;
  border-radius: 4px;
  color: #152230;
  font: 800 .95rem/1 var(--mono);
}
.empty-queue { color: var(--muted); font-size: .875rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-inline-start: auto; }
.board { position: relative; background: #112630; }
#tracks { display: block; width: 100%; height: auto; aspect-ratio: 960 / 510; }
#traffic { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.switches { position: absolute; inset: 0; pointer-events: none; container-type: inline-size; }
.switch {
  position: absolute;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  gap: 0;
  align-content: center;
  width: clamp(46px, 7.2cqw, 72px);
  height: clamp(46px, 7.2cqw, 72px);
  padding: 4px;
  border: 2px solid #a4bac6;
  border-radius: 14px;
  background-color: #233945;
  color: #f4fafb;
  font: inherit;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  user-select: none;
  box-shadow: 0 3px 10px #07131aaf;
}
.switch.on-route { color: #231910; background-color: var(--gold); border-color: #ffe4b4; }
.switch:hover { color: #152230; background-color: #f3fbff; border-color: #f3fbff; }
.switch.preview-source { box-shadow: 0 0 0 3px var(--blue), 0 3px 10px #07131aaf; }
.switch-current { display: flex; align-items: center; gap: 4px; font: 800 clamp(.9rem, 2cqw, 1.25rem)/1.2 var(--mono); }
.switch-alt { font: 650 .75rem/1.25 "Segoe UI", system-ui, sans-serif; white-space: nowrap; }
.switch-symbol {
  position: relative;
  width: clamp(13px, 2.2cqw, 20px);
  height: 15px;
}
.switch-symbol::before, .switch-symbol::after {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-radius: 3px;
  content: "";
}
.switch-symbol::before { border-top: 3px solid; transform: rotate(-23deg); }
.switch-symbol::after { border-top: 2px dotted; transform: rotate(23deg); opacity: .55; }
.switch.lower .switch-symbol { transform: scaleY(-1); }
.route-guide {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 20px;
  padding: 9px 16px;
  border-top: 1px solid var(--border);
  background: #11212c;
  color: var(--muted);
  font-size: .875rem;
}
.route-key { display: inline-flex; align-items: baseline; gap: 7px; }
.route-key::before { flex: 0 0 19px; border-top: 3px solid var(--gold); content: ""; transform: translateY(-.2em); }
.alternate-route::before { border-top: 3px dashed var(--blue); }
.active-route { color: var(--gold); }
.alternate-route[data-preview] { color: var(--blue); }
#train-route { color: var(--ink); }
#train-route[data-match="true"] { color: #a2f2d2; }
#train-route[data-match="false"] { color: #ffc4cb; }
.feedback { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 4px 20px; padding: 10px 16px; border-top: 1px solid var(--border); }
.feedback p { margin: 0; font-size: .9rem; }
#goal { color: var(--muted); }
.settings { display: flex; flex-wrap: wrap; align-items: end; gap: 12px 16px; margin-top: 13px; }
.field { display: grid; gap: 5px; }
.field label { color: var(--muted); font-size: .9rem; font-weight: 650; }
.speed { flex: 1 1 150px; max-width: 310px; }
.speed label { display: flex; justify-content: space-between; gap: 12px; }
#speed-value { color: var(--gold); font-family: var(--mono); }
#speed { width: 100%; min-height: 46px; margin: 0; accent-color: var(--gold); cursor: pointer; }
select.control {
  appearance: none;
  padding-inline-end: 38px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-size: 6px 6px;
  background-position: right 18px center, right 12px center;
  background-repeat: no-repeat;
}
select.control:not(:disabled):hover { background-color: #334d60; }
.instructions { margin: 8px 0 0; color: var(--muted); font-size: .94rem; line-height: 1.5; }

@media (max-width: 590px) {
  .shell { width: calc(100% - 20px); }
  .topbar-inner { min-height: 56px; gap: 7px; }
  main { padding-top: 10px; }
  .readouts { gap: 8px 12px; padding: 9px 10px; }
  .actions { margin-inline-start: 0; }
  .feedback, .route-guide { padding-inline: 10px; }
}
