* { box-sizing: border-box; }
:root {
  color-scheme: dark;
  --bg: #111423;
  --panel: #1a1e30;
  --border: #2b3047;
  --text: #f4f4fa;
  --lime: #cdf681;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  background: radial-gradient(ellipse at 42% -20%, #282841 0, transparent 62%), var(--bg);
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 2px solid var(--lime); outline-offset: 3px; z-index: 1; }
.shell { width: min(815px, calc(100% - 50px)); margin: 0 auto; padding: 18px 0; }
.masthead, .identity, .mast-actions, .panel-top { display: flex; align-items: center; }
.masthead { justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.identity { gap: 11px; min-width: 0; }
.logo {
  background: var(--lime); color: #242d26; width: 43px; height: 43px; border-radius: 12px;
  display: grid; place-items: center; flex: 0 0 auto; box-shadow: inset 0 1px 0 #f2ffc5;
}
.logo svg { width: 25px; height: 25px; }
h1, h2 { margin: 0; }
h1 { font-size: clamp(24px, 3.4vw, 37px); letter-spacing: -.055em; line-height: 1.04; font-weight: 820; }
.mast-actions { gap: 6px; }
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 39px;
  padding: 0 13px; border-radius: 10px; background: #22263a; border: 1px solid #363b53; font-weight: 650;
}
.button:hover { background: #2c324a; }
.icon-button { padding: 0; width: 39px; flex: 0 0 auto; }
.button svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.sound-button[aria-pressed="true"] .sound-off,
.sound-button[aria-pressed="false"] .sound-waves { display: none; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 17px; box-shadow: 0 8px 26px #090b1750; }
.station { min-width: 0; padding: 0 7px 7px; }
.panel-top { min-height: 48px; padding: 4px; justify-content: flex-end; }
.speed-toggle svg { width: 19px; height: 19px; stroke: none; }
.speed-toggle[aria-pressed="true"] { color: #22291f; background: var(--lime); border-color: var(--lime); }
.map { position: relative; overflow: hidden; border-radius: 12px; isolation: isolate; background: #236357; }
.map canvas { display: block; width: 100%; aspect-ratio: 2 / 3; }
.bus-controls, .gate-controls { position: absolute; inset: 0; pointer-events: none; }
.gate-button {
  position: absolute; top: 0; width: 26.5%; height: 21.3%;
  clip-path: polygon(12% 0, 44% 0, 44% 66%, 48% 72%, 56% 75%, 100% 75%, 100% 100%, 47% 100%, 31% 96%, 19% 84%, 12% 70%);
  touch-action: manipulation; pointer-events: auto;
  border: 1px solid transparent; background: transparent; padding: 0; border-radius: 9px;
}
#gate-left { left: 0; }
#gate-right { right: 0; transform: scaleX(-1); }
.gate-button:focus-visible { background: #d3fac51c; }
.depot-bus {
  position: absolute; padding: 0; border-radius: 18%;
  transform: translate(-50%, -50%) rotate(var(--angle)); touch-action: manipulation;
  background: transparent; border: 1px solid transparent; pointer-events: auto;
}
.depot-bus::before { content: ""; position: absolute; inset: -4px -3px; }
.depot-bus:hover { border-color: #e4f8d389; background: #e4f8d314; }
.depot-bus:active { border-color: #f0ffce; background: #f0ffce3c; }
dialog {
  width: min(420px, calc(100% - 32px)); max-height: calc(100dvh - 32px); padding: 24px;
  background: #22263a; border: 1px solid #40465f; border-radius: 18px; color: var(--text); box-shadow: 0 24px 80px #080915b0;
}
dialog::backdrop { background: #0a0c1abd; backdrop-filter: blur(4px); }
dialog h2 { font-size: 1.5rem; }
dialog li { color: #d4d8ea; line-height: 1.48; }
dialog ol { padding-left: 21px; margin: 15px 0; }
dialog li + li { margin-top: 8px; }
dialog .primary { background: var(--lime); color: #212a20; border-color: var(--lime); padding: 0 16px; }
dialog .primary:hover { background: #e1ffa9; }
.close-dialog { position: absolute; top: 12px; right: 12px; font-size: 23px; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
#restart-description { color: #d4d8ea; margin: 10px 0 20px; }
#result-dialog { text-align: center; width: min(220px, calc(100% - 32px)); }
.result-icon { display: grid; place-items: center; width: 45px; height: 45px; margin: 0 auto 13px; border-radius: 14px; font-size: 24px; font-weight: 800; color: #212a20; background: var(--lime); }
.result-icon.loss { background: #ffc474; }
#result-dialog.victory {
  --medal: var(--lime);
  --glow: #c8f08b35;
  width: min(390px, calc(100% - 32px)); padding: clamp(24px, 7vw, 37px) 20px 29px;
  border-color: #687e76; border-radius: 24px;
  background: radial-gradient(ellipse at 50% -4%, #47655d, transparent 68%), linear-gradient(160deg, #242d42, #191d2f);
  box-shadow: 0 25px 88px #070914d9, inset 0 1px 0 #e8ffd32e;
}
#result-dialog.final-victory { --medal: #ffda7c; --glow: #ffc4744d; border-color: #a38a59; }
#result-dialog.victory[open] { animation: victory-reveal 260ms ease-out both; }
.victory .result-icon {
  position: relative; width: 72px; height: 72px; margin-bottom: 24px; border-radius: 50%;
  font-size: 40px; background: linear-gradient(155deg, #f8ffda, var(--medal) 62%);
  box-shadow: 0 0 0 6px var(--glow), 0 0 0 13px #dfffac12, 0 0 35px var(--glow);
}
.victory[open] .result-icon { animation: victory-medal 480ms cubic-bezier(.15,.7,.25,1.3) 50ms both; }
.victory h2 { position: relative; font-size: clamp(1.55rem, 6vw, 2rem); line-height: 1.12; letter-spacing: -.035em; }
.victory .primary { position: relative; margin-top: 21px; min-height: 44px; padding: 0 19px; }
.final-victory .primary { background: var(--medal); border-color: var(--medal); }
.final-victory .primary:hover { background: #ffe6a4; }
.result-confetti { display: none; }
.victory .result-confetti { position: absolute; inset: 0 0 auto; height: 130px; overflow: hidden; display: block; pointer-events: none; }
.result-confetti span {
  position: absolute; left: var(--x); top: var(--y); width: 7px; height: 11px; border-radius: 2px;
  background: var(--color); opacity: .8; transform: rotate(var(--spin));
}
.result-confetti span:nth-child(3n) { width: 6px; height: 6px; border-radius: 50%; }
.victory[open] .result-confetti span { animation: victory-confetti 920ms cubic-bezier(.16,.7,.24,1) var(--delay) both; }
@keyframes victory-reveal {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes victory-medal {
  from { opacity: 0; transform: scale(.58); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes victory-confetti {
  from { opacity: 0; transform: translate(var(--drift), 48px) rotate(0) scale(.4); }
  32% { opacity: 1; }
  to { opacity: .8; transform: rotate(var(--spin)); }
}
@media (prefers-reduced-motion: reduce) {
  #result-dialog.victory[open], .victory[open] .result-icon, .victory[open] .result-confetti span { animation: none; }
}
@media (min-width: 551px) {
  .shell { max-width: max(395px, calc((100dvh - 146px) * .667 + 16px)); }
  h1 { font-size: clamp(24px, min(3.4vw, 4.2dvh), 37px); }
}
@media (max-width: 550px) {
  .shell { width: calc(100% - 16px); padding: 11px 0; }
  .masthead { gap: 9px; margin-bottom: 9px; }
  .identity { gap: 8px; }
  .logo { width: 37px; height: 37px; border-radius: 10px; }
  .logo svg { width: 22px; height: 22px; }
  .mast-actions .button { width: 35px; min-height: 35px; }
  .station { padding: 0 4px 4px; }
  .panel { border-radius: 12px; }
  .panel-top { min-height: 42px; padding: 2px; }
  .speed-toggle { width: 35px; min-height: 35px; }
  .map { border-radius: 8px; }
}
