/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #0a1628;
  font-family: 'Inter', sans-serif;
  -webkit-font-smoothing: antialiased;
  /* Disable page-level gesture handling so throttle/brake taps do not scroll
     the page on mobile. Buttons inside the HUD re-enable touch-action. */
  touch-action: none;
  overscroll-behavior: none;
}

/* ── Brand tokens ───────────────────────────────────────────── */
:root {
  --kd-blue:    #0F4DA8;
  --kd-yellow:  #FFC72C;
  --kd-cream:   #F4F1EA;
  --kd-charcoal: #222;
  --mono: 'JetBrains Mono', 'IBM Plex Mono', monospace;
  --ui-radius: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.45);
}

/* ── Canvas ─────────────────────────────────────────────────── */
#game {
  display: block;
  width: 100%;
  height: 100%;
  position: fixed;
  inset: 0;
  touch-action: none;
}

/* Re-enable touch handling on actual interactive UI controls so taps on
   menus/buttons aren't suppressed. */
button, input, select, textarea, a {
  touch-action: manipulation;
}

/* ── UI root overlay ────────────────────────────────────────── */
#ui-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  /* children re-enable pointer-events where needed */
}

/* ── Utility ────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ════════════════════════════════════════════════════════════
   SPLASH
   ════════════════════════════════════════════════════════════ */
#splash {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, #1a5fcc 0%, #0F4DA8 60%, #082558 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  pointer-events: auto;
  animation: splash-fade-in 0.4s ease-out, splash-fade-out 0.5s ease-in 2.5s forwards;
}

.splash-content {
  text-align: center;
  animation: splash-slide-in 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.splash-title {
  font: 700 64px/1 'Inter', sans-serif;
  color: #fff;
  letter-spacing: 0.04em;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.splash-subtitle {
  font: italic 400 28px/1.2 'Inter', sans-serif;
  color: #FFC72C;
  margin-top: 12px;
  letter-spacing: 0.02em;
}

.splash-train {
  margin-top: 32px;
  opacity: 0.95;
  animation: splash-train-slide 2.2s cubic-bezier(0.4, 0, 0.6, 1);
}

.splash-author {
  position: absolute;
  bottom: 32px;
  font: 400 14px 'JetBrains Mono', monospace;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.06em;
}

.splash-chevron {
  position: absolute;
  left: 0;
  width: 100%;
  height: 8px;
  background: #FFC72C;
}

.splash-chevron-top {
  top: 0;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 60% 60%, 40% 100%, 0 100%);
}

.splash-chevron-bottom {
  bottom: 0;
  clip-path: polygon(0 0, 40% 0, 60% 40%, 100% 0, 100% 100%, 0 100%);
}

@keyframes splash-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes splash-fade-out {
  from { opacity: 1; }
  to   { opacity: 0; visibility: hidden; pointer-events: none; }
}

@keyframes splash-slide-in {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes splash-train-slide {
  from { transform: translateX(-200px); opacity: 0; }
  30%  { opacity: 1; }
  100% { transform: translateX(200px); }
}

#splash.dismissed { display: none !important; }

button {
  cursor: pointer;
  border: none;
  font-family: inherit;
}

/* ════════════════════════════════════════════════════════════
   MENU
   ════════════════════════════════════════════════════════════ */
#menu {
  pointer-events: auto;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 22, 40, 0.82);
  backdrop-filter: blur(3px);
}

.menu-card {
  background: var(--kd-blue);
  border-radius: var(--ui-radius);
  box-shadow: var(--shadow);
  width: min(480px, 92vw);
  overflow: hidden;
}

.menu-accent {
  height: 6px;
  background: var(--kd-yellow);
}

.menu-body {
  padding: 28px 32px 32px;
}

.menu-title {
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 900;
  color: #fff;
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.menu-subtitle {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--kd-yellow);
  margin-top: 4px;
  letter-spacing: 0.06em;
}

.menu-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(255,255,255,0.55);
  margin: 24px 0 10px;
}

/* ── Player setting rows (animation density + difficulty) ─────── */
.menu-settings { margin: 16px 0 4px; }
.menu-setting {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.menu-setting-label {
  font: 600 12px var(--mono);
  color: var(--kd-cream);
  min-width: 86px;
  text-align: right;
}
.menu-setting-buttons { display: flex; gap: 4px; }
.menu-setting-btn {
  font: 500 12px 'Inter', sans-serif;
  padding: 4px 12px;
  border: 1px solid var(--kd-yellow);
  background: transparent;
  color: var(--kd-cream);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  pointer-events: auto;
}
.menu-setting-btn:hover { background: rgba(255, 199, 44, 0.1); }
.menu-setting-btn.selected { background: var(--kd-yellow); color: var(--kd-charcoal); }

/* ── Route ticket buttons ───────────────────────────────────── */
.route-btn {
  display: block;
  width: 100%;
  background: #fff;
  border: 2px dashed #ccc;
  border-radius: 6px;
  padding: 0;
  margin-bottom: 10px;
  text-align: left;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  pointer-events: auto;
}

.route-btn:hover,
.route-btn:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
  outline: none;
}

.route-btn:active {
  transform: translateY(-1px);
}

.route-ticket-stripe {
  height: 5px;
  background: var(--kd-yellow);
}

.route-ticket-body {
  padding: 10px 14px 12px;
}

.route-ticket-name {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--kd-charcoal);
  line-height: 1.4;
}

.route-ticket-kd {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--kd-blue);
  letter-spacing: 0.08em;
  margin-top: 2px;
}

/* ── Per-route highscores in menu ───────────────────────────── */
.route-highscores {
  margin-top: 6px;
  padding: 6px 14px 10px;
  border-top: 1px solid #eee;
}

.route-highscores-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #aaa;
  margin-bottom: 4px;
}

.route-highscore-row {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: #444;
  display: flex;
  justify-content: space-between;
  line-height: 1.6;
}

.route-highscores-empty {
  font-size: 0.72rem;
  color: #bbb;
  font-style: italic;
}

/* ════════════════════════════════════════════════════════════
   HUD
   ════════════════════════════════════════════════════════════ */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* ── Speed — top left ───────────────────────────────────────── */
.hud-speed {
  position: absolute;
  top: 16px;
  left: 16px;
  background: rgba(10,22,40,0.72);
  border-radius: var(--ui-radius);
  padding: 8px 14px 6px;
  min-width: 90px;
  text-align: center;
}

.hud-speed-value {
  font-family: var(--mono);
  font-size: 2.2rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  letter-spacing: -1px;
}

.hud-speed-label {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: rgba(255,255,255,0.55);
  letter-spacing: 0.1em;
  margin-top: 2px;
}

/* ── Lang toggle — top center ───────────────────────────────── */
.hud-lang {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: auto;
  display: flex;
  gap: 0;
  background: rgba(10,22,40,0.72);
  border-radius: 99px;
  padding: 3px;
}

.hud-lang-btn {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 99px;
  background: transparent;
  color: rgba(255,255,255,0.55);
  transition: background 0.15s, color 0.15s;
}

.hud-lang-btn.active {
  background: var(--kd-yellow);
  color: var(--kd-charcoal);
}

/* ── Satisfaction — top right ───────────────────────────────── */
.hud-satisfaction {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(10,22,40,0.72);
  border-radius: var(--ui-radius);
  padding: 8px 14px 8px;
  min-width: 210px;
}

.hud-satisfaction-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: rgba(255,255,255,0.55);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 5px;
  white-space: nowrap;
}

.hud-satisfaction-track {
  width: 200px;
  height: 10px;
  background: rgba(255,255,255,0.15);
  border-radius: 99px;
  overflow: hidden;
}

.hud-satisfaction-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.3s ease, background-color 0.3s ease;
  background: #4caf50; /* updated dynamically via JS */
}

/* ── Next station — bottom center ───────────────────────────── */
.hud-next-station {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10,22,40,0.72);
  border-radius: var(--ui-radius);
  padding: 8px 16px;
  text-align: center;
  white-space: nowrap;
}

.hud-next-label {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(255,255,255,0.45);
  margin-bottom: 3px;
}

.hud-next-name {
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
}

.hud-next-dist {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--kd-yellow);
  margin-top: 2px;
}

/* ── Score — bottom right ───────────────────────────────────── */
.hud-score {
  position: absolute;
  bottom: 20px;
  right: 16px;
  background: rgba(10,22,40,0.72);
  border-radius: var(--ui-radius);
  padding: 8px 14px;
  text-align: right;
}

.hud-score-label {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.45);
  margin-bottom: 2px;
}

.hud-score-value {
  font-family: var(--mono);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--kd-yellow);
  line-height: 1;
}

/* ── Mobile HUD adjustments ─────────────────────────────────── */
@media (max-width: 480px) {
  .hud-speed-value { font-size: 1.5rem; }
  .hud-satisfaction { min-width: unset; right: 8px; }
  .hud-satisfaction-track { width: 140px; }
  .hud-score { right: 8px; bottom: 12px; }
  .hud-score-value { font-size: 1.3rem; }
  .hud-next-station { bottom: 12px; max-width: 55vw; white-space: normal; text-align: center; }
  .hud-speed { left: 8px; top: 8px; }
  .hud-satisfaction { top: 8px; }
  .hud-lang { top: 8px; }
}

/* ════════════════════════════════════════════════════════════
   STATION CARD — postcard style
   ════════════════════════════════════════════════════════════ */
#station-card {
  pointer-events: auto;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10,22,40,0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

/* ── Card entrance animation ─────────────────────────────── */
@keyframes card-slide-in {
  from {
    opacity: 0;
    transform: translateY(28px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.station-card-box {
  background: var(--kd-cream);
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.55), 0 2px 8px rgba(0,0,0,0.3);
  width: min(480px, 92vw);
  overflow: hidden;
  /* Postcard dashed border */
  outline: 2px dashed var(--kd-blue);
  outline-offset: -6px;
}

.station-card-box.card-animate-in {
  animation: card-slide-in 0.38s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* ── Illustration area ───────────────────────────────────── */
.station-card-illustration {
  width: 100%;
  aspect-ratio: 240 / 160;
  overflow: hidden;
  border-radius: 8px 8px 0 0;
  border-bottom: 3px solid var(--kd-blue);
  line-height: 0;
}

.station-card-illustration svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Postcard body split layout ──────────────────────────── */
.station-card-postcard {
  display: flex;
  gap: 0;
  padding: 14px 16px 12px;
  border-bottom: 1px dashed rgba(15,77,168,0.35);
}

.station-card-postcard-left {
  flex: 1;
  min-width: 0;
  padding-right: 14px;
  border-right: 1px dashed rgba(15,77,168,0.35);
}

.station-card-postcard-right {
  width: 100px;
  flex-shrink: 0;
  padding-left: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* ── Tier badge ──────────────────────────────────────────── */
.station-card-tier-badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--kd-yellow);
  background: var(--kd-blue);
  padding: 2px 8px;
  border-radius: 3px;
  margin-bottom: 6px;
}

/* ── City name ───────────────────────────────────────────── */
.station-card-title {
  font-family: var(--mono);
  font-size: clamp(1.05rem, 3.5vw, 1.35rem);
  font-weight: 700;
  color: var(--kd-blue);
  line-height: 1.2;
  margin-bottom: 4px;
}

/* ── KD sub-badge ────────────────────────────────────────── */
.station-card-kd-badge {
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: rgba(15,77,168,0.55);
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* ── Fact text ───────────────────────────────────────────── */
.station-card-fact {
  font-size: 0.82rem;
  line-height: 1.6;
  color: #333;
}

/* ── Postcard stamp ──────────────────────────────────────── */
.station-card-stamp {
  width: 54px;
  height: 64px;
  border: 2.5px solid var(--kd-blue);
  border-radius: 4px;
  /* perforated edge simulation */
  outline: 1.5px dashed rgba(15,77,168,0.4);
  outline-offset: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
}

.station-card-stamp-inner {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--kd-blue);
  letter-spacing: -0.04em;
}

/* ── Distance badge ──────────────────────────────────────── */
.station-card-distance {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--kd-blue);
  background: var(--kd-yellow);
  padding: 3px 8px;
  border-radius: 3px;
  text-align: center;
  white-space: nowrap;
}

/* ── Address lines (decorative) ──────────────────────────── */
.station-card-lines {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 2px;
}

.station-card-line {
  height: 1.5px;
  background: rgba(15,77,168,0.22);
  border-radius: 1px;
}

/* ── Continue button ─────────────────────────────────────── */
.station-card-continue {
  display: block;
  width: 100%;
  padding: 13px;
  background: var(--kd-yellow);
  color: var(--kd-charcoal);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  border: none;
  border-radius: 0 0 8px 8px;
  transition: filter 0.15s, transform 0.1s;
  cursor: pointer;
}

.station-card-continue:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.station-card-continue:active {
  transform: translateY(0);
  filter: brightness(0.96);
}

/* ── Mobile adjustments ──────────────────────────────────── */
@media (max-width: 480px) {
  .station-card-postcard-right {
    width: 76px;
  }
  .station-card-stamp {
    width: 42px;
    height: 50px;
  }
  .station-card-fact {
    font-size: 0.78rem;
  }
  .station-card-title {
    font-size: 1rem;
  }
}

/* ════════════════════════════════════════════════════════════
   PAUSE
   ════════════════════════════════════════════════════════════ */
#pause {
  pointer-events: auto;
  position: absolute;
  inset: 0;
  background: rgba(10,22,40,0.78);
  backdrop-filter: blur(5px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.pause-title {
  font-family: var(--mono);
  font-size: clamp(2.5rem, 10vw, 5rem);
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.15em;
  text-shadow: 0 2px 16px rgba(0,0,0,0.5);
}

.pause-btn {
  padding: 12px 36px;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 700;
  min-width: 180px;
  letter-spacing: 0.04em;
  transition: filter 0.15s, transform 0.15s;
}

.pause-btn:hover { filter: brightness(1.1); transform: translateY(-2px); }
.pause-btn:active { transform: translateY(0); }

.pause-resume {
  background: var(--kd-yellow);
  color: var(--kd-charcoal);
}

.pause-menu {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
}

/* ════════════════════════════════════════════════════════════
   GAME OVER
   ════════════════════════════════════════════════════════════ */
#gameover {
  pointer-events: auto;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10,22,40,0.82);
  backdrop-filter: blur(4px);
}

.gameover-card {
  background: #fff;
  border-radius: var(--ui-radius);
  box-shadow: var(--shadow);
  width: min(480px, 92vw);
  overflow: hidden;
}

.gameover-accent {
  height: 6px;
  background: var(--kd-yellow);
}

.gameover-body {
  padding: 28px 28px 32px;
  text-align: center;
}

.gameover-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #999;
}

.gameover-score {
  font-family: var(--mono);
  font-size: clamp(3rem, 14vw, 5.5rem);
  font-weight: 700;
  color: var(--kd-blue);
  line-height: 1;
  margin: 6px 0 4px;
}

.gameover-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin: 16px 0 20px;
  flex-wrap: wrap;
}

.gameover-stat {
  text-align: center;
}

.gameover-stat-value {
  font-family: var(--mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--kd-charcoal);
}

.gameover-stat-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #aaa;
  margin-top: 2px;
}

/* ── Highscore list ─────────────────────────────────────────── */
.gameover-hs-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #bbb;
  margin-bottom: 8px;
  text-align: left;
}

.gameover-hs-list {
  list-style: none;
  margin-bottom: 20px;
}

.gameover-hs-row {
  font-family: var(--mono);
  font-size: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid #f0f0f0;
  color: #444;
}

.gameover-hs-row.current-run {
  color: var(--kd-blue);
  font-weight: 700;
}

.gameover-hs-rank {
  width: 20px;
  color: #bbb;
  flex-shrink: 0;
}

.gameover-hs-name {
  flex: 1;
  padding: 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gameover-hs-score {
  flex-shrink: 0;
  color: var(--kd-blue);
}

/* ── Gameover buttons ───────────────────────────────────────── */
.gameover-actions {
  display: flex;
  gap: 12px;
  margin-top: 4px;
}

.gameover-btn {
  flex: 1;
  padding: 12px 8px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  transition: filter 0.15s, transform 0.15s;
}

.gameover-btn:hover { filter: brightness(1.08); transform: translateY(-2px); }
.gameover-btn:active { transform: translateY(0); }

.gameover-restart {
  background: var(--kd-yellow);
  color: var(--kd-charcoal);
}

.gameover-menu {
  background: var(--kd-blue);
  color: #fff;
}

/* ════════════════════════════════════════════════════════════
   ROUTE STRIP
   ════════════════════════════════════════════════════════════ */
#route-strip {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  /* Leave room for HUD speed (left ~140px) and satisfaction bar (right ~240px) */
  width: calc(100vw - 380px);
  min-width: 320px;
  max-width: 1200px;
  height: 96px;
  background: rgba(15, 30, 60, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 0 0 10px 10px;
  /* Top accent line in KD yellow */
  border-top: 3px solid var(--kd-yellow);
  padding: 0 10px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
  z-index: 10;
  /* Do NOT set pointer-events:auto — it's informational only */
}

/* The KD branding badge — sits above the rail line at top-left of the strip */
.rs-brand {
  position: absolute;
  left: 8px;
  top: 4px;
  font-family: var(--mono);
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--kd-yellow);
  letter-spacing: 0.12em;
  white-space: nowrap;
  user-select: none;
  line-height: 1;
  background: rgba(15, 30, 60, 0.6);
  padding: 2px 4px;
  border-radius: 3px;
  z-index: 2;
}

/* SVG fills the strip */
.rs-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Station dots: transitions for the "just passed" animation */
.rs-dot {
  transition: fill 0.5s ease, stroke 0.5s ease;
}

/* Station name labels */
.rs-name {
  font-family: 'JetBrains Mono', 'IBM Plex Mono', monospace;
  font-size: 9px;
  fill: #fff;
  transition: fill 0.4s ease;
}

.rs-name.passed {
  fill: rgba(255, 255, 255, 0.38);
}

/* Distance labels */
.rs-dist {
  font-family: 'JetBrains Mono', 'IBM Plex Mono', monospace;
  font-size: 9px;
  fill: var(--kd-yellow);
}

/* Train marker pulse animation */
@keyframes rs-pulse {
  0%   { opacity: 1;   transform: scale(1); }
  50%  { opacity: 0.7; transform: scale(1.25); }
  100% { opacity: 1;   transform: scale(1); }
}

.rs-train-marker {
  animation: rs-pulse 1.8s ease-in-out infinite;
  transform-origin: center;
  transform-box: fill-box;
}

/* Medium screens (700-1200px): strip uses rotated/truncated approach — handled in JS */
@media (max-width: 1200px) and (min-width: 701px) {
  #route-strip {
    width: calc(100vw - 300px);
  }
}

/* Compact mode: hide names on narrow viewports — JS also sets a flag */
@media (max-width: 700px) {
  #route-strip {
    height: 44px;
    width: calc(100vw - 80px);
  }
  .rs-name,
  .rs-dist,
  .rs-brand {
    display: none;
  }
}

/* Push HUD speed + satisfaction below the strip on larger screens */
@media (min-width: 701px) {
  .hud-speed {
    top: 100px;
  }
  .hud-satisfaction {
    top: 100px;
  }
  .hud-lang {
    top: 100px;
  }
}

/* ════════════════════════════════════════════════════════════
   MOBILE CONTROLS
   ════════════════════════════════════════════════════════════ */

/* By default hide mobile controls on desktop */
#mobile-controls { display: none; }

@media (max-width: 900px) {
  #mobile-controls {
    display: flex;
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 50;
    pointer-events: auto;
    touch-action: none;
  }

  .mc-btn {
    width: 64px;
    height: 64px;
    border: none;
    border-radius: 50%;
    font-size: 28px;
    font-weight: 700;
    color: var(--kd-charcoal);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.05s;
    cursor: pointer;
  }

  .mc-btn:active { transform: scale(0.92); }

  .mc-throttle { background: var(--kd-yellow); }
  .mc-brake    { background: #e85040; color: #fff; }
  .mc-horn     { background: var(--kd-blue); color: #fff; width: 48px; height: 48px; font-size: 22px; }

  /* Reduce HUD font sizes on small screens to reclaim vertical space */
  .hud-speed-value  { font-size: 36px !important; }
  .hud-score-value  { font-size: 24px !important; }

  /* Shift HUD elements to respect safe areas on notched phones */
  .hud-speed, .hud-satisfaction, .hud-lang {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(8px, env(safe-area-inset-left));
  }

  /* Push score + next-station widgets left so they don't sit under the buttons */
  .hud-score {
    right: max(96px, calc(env(safe-area-inset-right) + 96px));
  }
  .hud-next-station {
    right: max(96px, calc(env(safe-area-inset-right) + 96px));
    left: unset;
    transform: none;
  }
}

/* Very small phones */
@media (max-width: 480px) {
  .mc-btn  { width: 56px; height: 56px; font-size: 24px; }
  .mc-horn { width: 42px; height: 42px; font-size: 18px; }
}

/* Landscape on phones (short viewport) — arrange buttons in a row */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  #mobile-controls {
    flex-direction: row;
    bottom: max(8px, env(safe-area-inset-bottom));
    right: max(8px, env(safe-area-inset-right));
  }
  .mc-btn  { width: 50px; height: 50px; font-size: 22px; }
  .mc-horn { width: 38px; height: 38px; font-size: 17px; }
}

/* Disable text selection / context menu on game canvas */
#game {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Safe area padding for notch/home-indicator phones (portrait) */
body {
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* ════════════════════════════════════════════════════════════
   TUTORIAL
   ════════════════════════════════════════════════════════════ */
#tutorial { position: fixed; inset: 0; z-index: 900; pointer-events: auto; }
.tutorial-overlay {
  position: absolute; inset: 0;
  background: rgba(10, 22, 40, 0.75);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: tut-fade-in 0.25s ease-out;
}
.tutorial-card {
  background: var(--kd-cream);
  border: 4px solid var(--kd-yellow);
  border-radius: 18px;
  padding: 32px 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
  position: relative;
}
.tutorial-icon { font-size: 80px; line-height: 1; margin-bottom: 16px; }
.tutorial-text { font: 600 18px/1.4 'Inter', sans-serif; color: var(--kd-charcoal); margin-bottom: 16px; }
.tutorial-progress { font: 600 12px 'JetBrains Mono', monospace; color: var(--kd-blue); margin-bottom: 16px; opacity: 0.6; }
.tutorial-next {
  background: var(--kd-yellow); color: var(--kd-charcoal);
  border: none; padding: 12px 24px; border-radius: 10px;
  font: 700 16px 'Inter', sans-serif; cursor: pointer;
  margin-right: 8px;
  touch-action: manipulation;
}
.tutorial-next:hover { transform: translateY(-1px); }
.tutorial-skip {
  background: transparent; color: var(--kd-charcoal);
  border: none; padding: 12px 16px;
  font: 400 14px 'Inter', sans-serif; cursor: pointer;
  opacity: 0.6;
  touch-action: manipulation;
}
@keyframes tut-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* PLAY AGAIN BUTTON (gameover) */
.gameover-play-again {
  background: var(--kd-yellow);
  color: var(--kd-navy);
  font-weight: 800;
  font-size: 18px;
  padding: 14px 32px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(255,199,44,0.4);
  transition: transform 0.15s, box-shadow 0.15s;
  touch-action: manipulation;
  margin-bottom: 8px;
}
.gameover-play-again:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(255,199,44,0.55);
}

/* SOUND BUTTON */
.hud-sound-btn { font-size: 16px; padding: 4px 10px; }
.hud-sound-btn.muted { opacity: 0.5; }

/* ════════════════════════════════════════════════════════════
   ACCESSIBILITY & REDUCED MOTION
   ════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Visible focus ring for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--kd-yellow);
  outline-offset: 2px;
}

/* Focus trap helpers — keep focus inside modal dialogs */
#pause:not(.hidden),
#gameover:not(.hidden),
#station-card:not(.hidden),
#tutorial:not(.hidden) {
  /* These containers get pointer-events: auto when visible */
}

/* GDPR / data notice */
.legal-note {
  font: 400 11px 'Inter', sans-serif;
  color: rgba(255, 255, 255, 0.45);
  text-align: center;
  margin-top: 8px;
}
