:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #f2f2ed;
  --muted: #a7a7a1;
  --dim: #70706c;
  --canvas: #080808;
  --panel: #111111;
  --panel-2: #1b1b1a;
  --line: #30302d;
  --steel: #e33b32;
  --steel-strong: #b82221;
  --amber: #f2c84b;
  --danger: #e33b32;
  --success: #f2c84b;
  --map-base: #d5e0df;
  --white: #ffffff;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 22px 60px rgb(0 0 0 / 28%);
  --train-roof-ed4m: #aeb1ad;
  --train-roof-lastochka: #ecece5;
  --train-window: #152a31;
  --train-lamp: #fff5c4;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

.start-screen { min-height: 100vh; max-width: 980px; margin: auto; padding: clamp(38px, 8vw, 90px) 22px; display: flex; flex-direction: column; justify-content: center; background: radial-gradient(circle at 12% 10%, rgb(35 170 189 / 13%), transparent 32%), radial-gradient(circle at 100% 92%, rgb(242 183 102 / 9%), transparent 28%); }
.brand-mark { display: flex; gap: 6px; align-items: end; height: 32px; margin-bottom: 26px; }
.brand-mark span { width: 7px; background: var(--steel); display: block; transform: skew(-24deg); }
.brand-mark span:nth-child(1) { height: 18px; opacity: .5; }
.brand-mark span:nth-child(2) { height: 26px; opacity: .78; }
.brand-mark span:nth-child(3) { height: 32px; }
.eyebrow, .panel-eyebrow, .mode-kicker, .status-label { margin: 0; color: var(--steel); font-size: 10px; letter-spacing: .2em; font-weight: 800; }
.start-screen h1 { max-width: 800px; margin: 10px 0 18px; color: var(--white); font-size: clamp(52px, 11vw, 112px); letter-spacing: -.075em; line-height: .88; font-weight: 800; }
.start-lead { max-width: 580px; margin: 0; color: var(--muted); font-size: clamp(17px, 2.4vw, 23px); line-height: 1.45; }
.mode-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; max-width: 700px; margin-top: 42px; }
.mode-card { text-align: left; color: var(--muted); background: rgb(17 38 56 / 52%); border: 1px solid var(--line); border-radius: var(--radius); padding: 21px; min-height: 178px; display: flex; flex-direction: column; gap: 9px; transition: .2s ease; }
.mode-card:hover, .mode-card.is-selected { border-color: var(--steel); background: var(--panel-2); transform: translateY(-2px); }
.mode-card strong { color: var(--white); font-size: 21px; }
.mode-card span:not(.mode-kicker):not(.mode-value) { line-height: 1.4; font-size: 13px; }
.mode-value { color: var(--amber); font-size: 12px; font-weight: 700; margin-top: auto; }
.start-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin-top: 28px; }
.button { min-height: 44px; border: 0; border-radius: 9px; padding: 0 18px; font-weight: 750; transition: .18s ease; }
.button-primary { color: var(--canvas); background: var(--steel); }
.button-primary:hover { background: var(--white); transform: translateY(-1px); }
.button-large { min-height: 52px; padding: 0 24px; }
.button-quiet, .text-button { border: 0; color: var(--steel); background: transparent; font-weight: 700; }
.button-quiet:hover, .text-button:hover { color: var(--white); }
.form-note { color: var(--dim); font-size: 12px; margin: 18px 0 0; }

.game-screen { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { min-height: 64px; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; padding: 0 20px; gap: 16px; }
.topbar-brand { color: var(--white); display: flex; align-items: center; gap: 10px; font-size: 12px; letter-spacing: .17em; font-weight: 800; white-space: nowrap; }
.mini-mark { height: 20px; width: 26px; border-top: 3px solid var(--steel); border-bottom: 3px solid var(--amber); transform: skew(-26deg); position: relative; }
.mini-mark::after { content: ""; position: absolute; left: 9px; right: 2px; top: 6px; border-top: 3px solid var(--steel); }
.topbar-status { display: flex; align-items: center; gap: 10px; }
.topbar-action { min-height: 36px; padding: 0 11px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); color: var(--amber); font-size: 11px; font-weight: 800; }
.topbar-action:hover { border-color: var(--amber); color: var(--white); }
.status-chip { display: flex; flex-direction: column; gap: 2px; padding-right: 13px; border-right: 1px solid var(--line); }
.status-chip strong { color: var(--white); font-size: 13px; }
.balance-chip strong { color: var(--amber); }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--muted); font-size: 18px; }
.icon-button:hover { border-color: var(--steel); color: var(--white); }
.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 246px minmax(360px, 1fr) 315px; }
.sidebar { background: var(--panel); overflow-y: auto; }
.left-panel { border-right: 1px solid var(--line); padding: 26px 18px 20px; }
.right-panel { border-left: 1px solid var(--line); padding: 22px 16px; }
.panel-heading, .section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
h2 { color: var(--white); font-size: 17px; letter-spacing: -.02em; margin: 5px 0 0; }
.panel-copy { color: var(--muted); font-size: 12px; line-height: 1.55; margin: 18px 0 20px; }
.step-badge, .count-label { color: var(--amber); font-size: 11px; font-weight: 800; letter-spacing: .1em; }
.tool-list { display: grid; gap: 5px; }
.tool-button { width: 100%; min-height: 56px; display: flex; align-items: center; gap: 12px; padding: 8px 10px; border: 1px solid transparent; border-radius: 9px; color: var(--muted); background: transparent; text-align: left; }
.tool-button:hover, .tool-button.is-active { background: var(--panel-2); border-color: var(--line); color: var(--white); }
.tool-button.is-active { border-left-color: var(--steel); }
.tool-button b, .tool-button small { display: block; }
.tool-button b { color: inherit; font-size: 13px; }
.tool-button small { color: var(--dim); font-size: 10px; margin-top: 3px; line-height: 1.25; }
.tool-icon { flex: 0 0 30px; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 7px; background: var(--line); color: var(--steel); font-size: 13px; font-weight: 900; }
.tool-icon.pointer { font-size: 20px; color: var(--amber); }
.tool-icon.track { font-size: 22px; transform: rotate(-15deg); }
.legend-box { border-top: 1px solid var(--line); margin-top: 26px; padding-top: 18px; }
.legend-row { display: flex; align-items: center; gap: 8px; margin-top: 11px; color: var(--muted); font-size: 11px; }
.legend-dot { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; font-size: 9px; font-weight: 800; border: 2px solid; }
.depot-dot { color: var(--amber); border-color: var(--amber); }.station-dot { color: var(--steel); border-color: var(--steel); }.terminal-dot { color: var(--amber); border-color: var(--amber); }
.legend-line { flex: 1; border-top: 1px solid var(--line); }

.map-stage { position: relative; min-height: 590px; background: var(--map-base); }
#map { position: absolute; inset: 0; z-index: 1; }
.leaflet-container { font-family: inherit; background: var(--map-base); }
.leaflet-tile-pane { filter: saturate(.62) sepia(.12) brightness(.92); }
.leaflet-control-zoom { border: 1px solid rgb(7 19 31 / 25%) !important; box-shadow: none !important; }
.leaflet-control-zoom a { color: var(--canvas) !important; background: rgb(255 255 255 / 82%) !important; }
.leaflet-control-attribution { font-size: 8px !important; opacity: .56; }
.map-topline { position: absolute; z-index: 500; left: 18px; top: 17px; display: flex; align-items: center; gap: 8px; padding: 8px 11px; background: rgb(7 19 31 / 86%); border-radius: 6px; color: var(--white); font-size: 10px; font-weight: 800; letter-spacing: .14em; box-shadow: 0 8px 20px rgb(0 0 0 / 14%); }
.map-topline #mapHint { color: var(--muted); font-weight: 500; letter-spacing: 0; text-transform: none; margin-left: 7px; }
.live-dot, .event-pulse { width: 7px; height: 7px; background: var(--success); border-radius: 50%; display: inline-block; box-shadow: 0 0 0 4px rgb(122 201 160 / 16%); }
.map-zoom-note { position: absolute; z-index: 500; bottom: 16px; left: 16px; background: rgb(7 19 31 / 76%); color: var(--white); padding: 7px 10px; border-radius: 5px; font-size: 10px; }
.event-toast { position: absolute; z-index: 600; top: 70px; left: 18px; right: 18px; max-width: 420px; display: flex; align-items: flex-start; gap: 10px; padding: 13px; border: 1px solid var(--amber); border-radius: 9px; background: rgb(13 29 43 / 95%); box-shadow: var(--shadow); }
.entity-editor { position: absolute; z-index: 700; top: 72px; right: 18px; width: min(280px, calc(100% - 36px)); padding: 14px; border: 1px solid var(--steel); border-radius: 10px; background: rgb(17 17 17 / 96%); box-shadow: var(--shadow); }
.entity-editor-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.entity-editor h2 { max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-close { width: 30px; height: 30px; border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; }
.editor-close:hover { color: var(--white); }
.editor-actions { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-top: 12px; }
.button-danger { color: var(--white); background: var(--steel-strong); }
.button-danger:hover { background: var(--danger); }
.event-toast strong, .event-toast span { display: block; }.event-toast strong { color: var(--amber); font-size: 12px; }.event-toast span { color: var(--muted); font-size: 11px; line-height: 1.35; margin-top: 4px; }.event-toast > div { flex: 1; }.event-toast button { border: 0; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; }
.custom-marker { position: relative; width: 34px; height: 34px; border-radius: 11px 11px 15px 15px; display: grid; place-items: center; color: var(--white); border: 3px solid var(--canvas); box-shadow: 0 3px 0 rgb(0 0 0 / 20%), 0 4px 12px rgb(0 0 0 / 38%); font-size: 11px; font-weight: 950; transform: rotate(-3deg); }.custom-marker::after { content: ""; position: absolute; bottom: -7px; width: 11px; height: 11px; background: inherit; border-right: 3px solid var(--canvas); border-bottom: 3px solid var(--canvas); transform: rotate(45deg); z-index: -1; }.custom-marker.depot { background: var(--amber); color: var(--canvas); border-radius: 50% 50% 12px 12px; }.custom-marker.station { background: var(--steel); }.custom-marker.terminal { background: var(--canvas); color: var(--amber); border-color: var(--amber); border-radius: 8px; }.city-marker { display: block; width: 13px; height: 13px; background: var(--steel); border: 3px solid var(--canvas); border-radius: 50%; box-shadow: 0 0 0 3px rgb(227 59 50 / 28%), 0 2px 6px rgb(0 0 0 / 55%); }.city-label { color: var(--canvas); text-shadow: 0 1px 2px var(--white); font-size: 10px; font-weight: 900; white-space: nowrap; }

.panel-section { padding-bottom: 20px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }.panel-section:last-child { border-bottom: 0; }.event-section { padding-bottom: 17px; }.timer-label { color: var(--amber); font-size: 11px; }.event-card { display: flex; align-items: center; gap: 10px; margin-top: 14px; min-height: 55px; padding: 10px; border-radius: 8px; background: var(--panel-2); }.event-card-icon { width: 27px; height: 27px; display: grid; place-items: center; border: 1px solid var(--steel); color: var(--steel); border-radius: 50%; font-weight: 700; }.event-card strong { font-size: 12px; color: var(--white); }.event-card p { color: var(--muted); font-size: 10px; line-height: 1.3; margin: 4px 0 0; }
.field-label { color: var(--dim); display: block; font-size: 10px; font-weight: 700; margin: 14px 0 6px; }.select-field, input { width: 100%; height: 36px; color: var(--ink); background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 0 9px; font-size: 12px; }.select-field:disabled { opacity: .55; }.train-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 9px; }.train-card { text-align: left; min-height: 105px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--muted); padding: 8px; }.train-card:hover { border-color: var(--steel); background: var(--panel-2); }.train-code { display: block; color: var(--steel); font-size: 16px; font-weight: 800; }.train-code.fast { color: var(--amber); }.train-name { display: block; font-size: 9px; margin-top: 4px; }.train-price { display: block; color: var(--dim); font-size: 9px; margin-top: 5px; }.train-visual { position: relative; height: 25px; margin: 1px 4px 8px 0; border-bottom: 3px solid var(--canvas); border-radius: 8px 18px 3px 3px; background: currentColor; opacity: .95; overflow: visible; }.train-visual::before { content: ""; position: absolute; left: 7px; right: 12px; top: 5px; height: 8px; background: var(--canvas); border-radius: 2px; box-shadow: 13px 0 0 var(--canvas), 26px 0 0 var(--canvas); opacity: .85; }.train-visual::after { content: ""; position: absolute; right: -2px; bottom: -7px; width: 8px; height: 8px; border-radius: 50%; background: var(--canvas); box-shadow: -43px 0 0 var(--canvas), -22px 0 0 var(--canvas); }.train-visual.ed4m { color: var(--steel); }.train-visual.lastochka { color: var(--amber); border-radius: 15px 22px 3px 3px; clip-path: polygon(0 18%, 78% 0, 100% 20%, 100% 100%, 0 100%); }.compact-list { margin-top: 10px; display: grid; gap: 5px; }.list-row { display: flex; align-items: center; justify-content: space-between; gap: 7px; border-radius: 7px; background: rgb(27 27 26 / 75%); padding: 8px 9px; font-size: 10px; }.list-row strong { color: var(--white); }.list-row span { color: var(--muted); }.empty-mini { color: var(--dim); font-size: 11px; padding: 7px 0; }.route-hint { color: var(--muted); font-size: 11px; line-height: 1.45; margin: 13px 0; }.route-draft { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 10px; border: 1px dashed var(--steel); color: var(--white); font-size: 11px; margin: 10px 0; }.route-draft-body { min-width: 0; flex: 1; }.route-draft-label { display: block; color: var(--steel); font-size: 9px; font-weight: 800; letter-spacing: .12em; margin-bottom: 6px; }.route-stops-draft { display: grid; gap: 3px; max-height: 92px; overflow: auto; }.draft-stop { color: var(--white); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }.route-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin: 9px 0 12px; }.route-inputs label span { color: var(--dim); display: block; font-size: 10px; margin-bottom: 5px; }.full-button { width: 100%; }.route-list { max-height: 260px; overflow: auto; }.route-list .list-row { align-items: flex-start; }.route-list small { display: block; margin-top: 4px; line-height: 1.35; }.route-kind { color: var(--amber) !important; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }.route-kind.lastochka { color: var(--amber) !important; }.route-stops { color: var(--muted) !important; }.moving-train { position: relative; display: block; width: 34px; height: 18px; border: 2px solid var(--canvas); border-radius: 5px 12px 3px 3px; background: var(--steel); box-shadow: 0 2px 7px rgb(0 0 0 / 48%); transform: rotate(-2deg); }.moving-train::before { content: ""; position: absolute; left: 5px; right: 5px; top: 4px; height: 5px; background: var(--canvas); border-radius: 2px; box-shadow: 9px 0 0 var(--canvas); }.moving-train::after { content: ""; position: absolute; width: 6px; height: 6px; border-radius: 50%; background: var(--canvas); left: 4px; bottom: -5px; box-shadow: 19px 0 0 var(--canvas); }.moving-train.lastochka { background: var(--amber); border-radius: 6px 15px 3px 3px; transform: rotate(2deg); }.moving-train i { position: absolute; right: -5px; top: 4px; width: 5px; height: 7px; background: currentColor; clip-path: polygon(0 0, 100% 50%, 0 100%); }.metrics-section { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }.metric span, .metric strong { display: block; }.metric span { color: var(--dim); font-size: 9px; }.metric strong { color: var(--white); margin-top: 5px; font-size: 12px; }.status-bar { min-height: 29px; padding: 7px 18px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); font-size: 10px; }

@media (max-width: 1080px) { .workspace { grid-template-columns: 215px minmax(300px, 1fr) 280px; }.left-panel { padding-left: 12px; padding-right: 12px; }.right-panel { padding-left: 12px; padding-right: 12px; } }
@media (max-width: 820px) { .workspace { display: flex; flex-direction: column; }.map-stage { order: 1; min-height: 54vh; }.left-panel { order: 2; border-right: 0; border-top: 1px solid var(--line); }.right-panel { order: 3; border-left: 0; border-top: 1px solid var(--line); }.tool-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }.legend-box { display: none; }.right-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }.route-section, .metrics-section { grid-column: 1 / -1; }.event-section { grid-column: 1 / -1; } }
@media (max-width: 540px) { .mode-grid { grid-template-columns: 1fr; }.start-screen { justify-content: flex-start; padding-top: 58px; }.start-screen h1 { font-size: 64px; }.topbar { padding: 0 12px; }.topbar-brand { font-size: 10px; }.status-chip:first-child { display: none; }.balance-chip { border: 0; }.map-stage { min-height: 58vh; }.map-topline { left: 10px; right: 10px; font-size: 9px; }.map-topline #mapHint { display: none; }.right-panel { display: block; }.metrics-section { display: grid; }.tool-list { grid-template-columns: 1fr; } }

/* Map-first command deck: the railway is the stage, controls stay within reach. */
.game-screen { position: relative; min-height: 100vh; }
.topbar { position: absolute; z-index: 1000; inset: 0 0 auto; min-height: 68px; background: linear-gradient(180deg, rgb(8 8 8 / 94%), rgb(8 8 8 / 62%), transparent); border-bottom: 0; padding: 0 18px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.topbar-status { margin-left: auto; }
.workspace { position: relative; display: block; min-height: 100vh; }
.map-stage { position: absolute; inset: 0; min-height: 0; }
.map-topline { top: 78px; }
.map-zoom-note { display: none; }
.left-panel, .right-panel { position: absolute; z-index: 800; bottom: 14px; max-height: 35vh; overflow-y: auto; border: 1px solid rgb(242 200 75 / 26%); border-radius: 14px; background: rgb(8 8 8 / 91%); box-shadow: 0 18px 50px rgb(0 0 0 / 30%); backdrop-filter: blur(14px); }
.left-panel { left: 14px; width: calc(56% - 21px); padding: 13px 15px; }
.left-panel .panel-heading, .left-panel .panel-copy, .legend-box { display: none; }
.tool-list { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.tool-button { min-height: 54px; padding: 7px 9px; background: rgb(27 27 26 / 68%); border-color: rgb(255 255 255 / 7%); }
.tool-button.is-active { border-color: var(--steel); box-shadow: inset 3px 0 var(--steel); }
.tool-button small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.right-panel { right: 14px; width: calc(44% - 7px); padding: 13px 15px; }
.right-panel .event-section { position: fixed; z-index: 950; top: 78px; right: 14px; width: min(340px, calc(44vw - 20px)); max-height: 160px; overflow: auto; margin: 0; padding: 13px; border: 1px solid var(--amber); border-radius: 12px; background: rgb(8 8 8 / 93%); box-shadow: var(--shadow); backdrop-filter: blur(14px); }
.right-panel .event-section .event-card { margin-top: 9px; }
.right-panel .panel-section { padding-bottom: 12px; margin-bottom: 12px; }
.right-panel .field-label { margin-top: 8px; }
.right-panel .train-cards { margin-top: 6px; }
.right-panel .compact-list { margin-top: 6px; }
.event-toast { top: 250px; left: auto; right: 14px; max-width: 340px; }
.speed-control { min-width: 44px; height: 36px; padding: 0 8px; border: 1px solid var(--amber); border-radius: 7px; background: rgb(8 8 8 / 80%); color: var(--amber); font-size: 12px; font-weight: 900; }
.speed-control:hover { background: var(--amber); color: var(--canvas); }
.custom-marker { width: 40px; height: 40px; border-width: 3px; font-size: 12px; box-shadow: 0 4px 0 rgb(0 0 0 / 22%), 0 5px 16px rgb(0 0 0 / 45%); }
.custom-marker::after { bottom: -8px; width: 13px; height: 13px; }
.custom-marker.station { background: var(--steel); border-radius: 50% 50% 12px 12px; }
.custom-marker.depot { background: var(--steel); color: var(--white); border-color: var(--canvas); }
.custom-marker.terminal { background: var(--amber); color: var(--canvas); border-color: var(--canvas); }
.city-marker { width: 18px; height: 18px; border-width: 3px; box-shadow: 0 0 0 4px rgb(227 59 50 / 30%), 0 3px 8px rgb(0 0 0 / 60%); }
.city-label { font-size: 11px; text-shadow: 0 1px 0 var(--white), 1px 0 0 var(--white), -1px 0 0 var(--white); }
.leaflet-overlay-pane path { vector-effect: non-scaling-stroke; }

@media (max-width: 820px) {
  .topbar { padding: 0 11px; }
  .topbar-brand { font-size: 10px; }
  .left-panel { left: 10px; right: 10px; bottom: 10px; width: auto; max-height: 31vh; padding: 10px; }
  .right-panel { left: 10px; right: 10px; bottom: calc(31vh + 20px); width: auto; max-height: 27vh; padding: 10px; }
  .right-panel .event-section { right: 10px; width: min(320px, calc(100vw - 20px)); }
  .tool-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tool-button { min-height: 50px; }
  .tool-button b { font-size: 11px; }
  .tool-button small { font-size: 9px; }
  .event-toast { right: 10px; top: 245px; }
}
@media (max-width: 540px) {
  .topbar-brand { max-width: 128px; overflow: hidden; text-overflow: ellipsis; }
  .topbar-action { font-size: 10px; padding: 0 7px; }
  .status-chip { display: none; }
  .balance-chip { display: flex; }
  .map-topline { top: 72px; left: 10px; right: 10px; }
  .right-panel { max-height: 26vh; }
  .right-panel .event-section { top: 72px; max-height: 132px; }
  .right-panel .event-section .event-card p { display: none; }
  .left-panel { max-height: 32vh; }
  .tool-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tool-button { min-height: 48px; }
  .tool-button small { display: none; }
  .event-toast { top: 214px; }
}
.entity-editor { top: 122px; right: auto; left: 14px; z-index: 960; }
@media (max-width: 540px) { .entity-editor { top: 170px; left: 10px; } }
.status-bar { position: absolute; z-index: 910; left: 14px; top: 116px; width: min(360px, calc(56% - 35px)); min-height: 0; padding: 9px 12px; border: 1px solid rgb(242 200 75 / 35%); border-radius: 8px; background: rgb(8 8 8 / 84%); box-shadow: 0 8px 20px rgb(0 0 0 / 20%); }
@media (max-width: 820px) { .status-bar { left: 10px; top: 116px; width: min(360px, calc(100% - 20px)); } }

/* Information hierarchy: summary stays in the upper-right, route board stays at the bottom. */
.summary-panel { top: 78px; right: 14px; bottom: auto; width: min(340px, calc(44% - 7px)); max-height: 42vh; padding: 13px 15px; }
.summary-panel .event-section { position: static; top: auto; right: auto; width: auto; max-height: none; overflow: visible; margin: 0; padding: 0 0 12px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; box-shadow: none; backdrop-filter: none; }
.summary-panel .event-section .event-card { margin-top: 9px; }
.summary-panel .panel-section { padding-bottom: 12px; margin-bottom: 12px; }
.route-dock { position: absolute; z-index: 820; right: 14px; bottom: 14px; width: min(620px, calc(44% - 7px)); max-height: 34vh; overflow-y: auto; padding: 13px 15px; border: 1px solid rgb(242 200 75 / 34%); border-radius: 14px; background: rgb(8 8 8 / 93%); box-shadow: 0 18px 50px rgb(0 0 0 / 34%); backdrop-filter: blur(14px); }
.route-dock .route-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.route-dock .route-settings .field-label { margin-top: 8px; }
.route-dock .route-settings .select-field { min-width: 0; }
.route-dock .route-settings .route-inputs, .route-dock .route-settings .full-button { grid-column: 1 / -1; }
.route-dock .route-list { max-height: 22vh; overflow-y: auto; }
.route-dock .route-row { align-items: flex-start; }

@media (max-width: 820px) {
  .summary-panel { top: 72px; left: auto; right: 10px; bottom: auto; width: min(330px, calc(100% - 20px)); max-height: 24vh; }
  .route-dock { left: 10px; right: 10px; bottom: 10px; width: auto; max-height: 34vh; }
  .left-panel { left: 10px; right: 10px; bottom: calc(34vh + 20px); width: auto; max-height: 22vh; }
  .route-dock .route-list { max-height: 19vh; }
}

@media (max-width: 540px) {
  .summary-panel { top: 70px; right: 10px; max-height: 23vh; padding: 10px; }
  .summary-panel .event-card { min-height: 42px; }
  .summary-panel .event-card p { display: none; }
  .route-dock { bottom: 10px; max-height: 38vh; padding: 10px; }
  .left-panel { bottom: calc(38vh + 18px); max-height: 25vh; }
  .route-dock .route-settings { display: block; }
  .route-dock .route-settings .field-label { margin-top: 7px; }
  .route-dock .route-list { max-height: 16vh; }
}

/* Compact command layout: the map remains dominant while route operations stay readable. */
.summary-panel { right: 14px; width: min(292px, calc(33% - 12px)); max-height: 28vh; padding: 10px 12px; overflow-y: auto; }
.summary-panel .panel-section { padding-bottom: 8px; margin-bottom: 8px; }
.summary-panel .event-section { padding-bottom: 8px; }
.summary-panel .event-card { min-height: 40px; margin-top: 6px; padding: 7px; gap: 8px; }
.summary-panel .event-card p { display: none; }
.summary-panel .event-card-icon { width: 23px; height: 23px; font-size: 12px; }
.summary-panel .field-label { margin: 5px 0 4px; }
.summary-panel .select-field { height: 30px; font-size: 11px; }
.summary-panel .train-cards { gap: 5px; margin-top: 5px; }
.summary-panel .train-card { min-height: 76px; padding: 6px; }
.summary-panel .train-visual { height: 20px; margin-bottom: 5px; }
.summary-panel .train-name { max-height: 22px; overflow: hidden; line-height: 1.2; }
.summary-panel .train-price { margin-top: 3px; }
.summary-panel .compact-list { max-height: 44px; overflow: auto; margin-top: 5px; }
.summary-panel .list-row { padding: 5px 7px; font-size: 9px; }
.summary-panel .metrics-section { padding-bottom: 0; margin-bottom: 0; }
.summary-panel .metric strong { margin-top: 2px; font-size: 10px; }
.summary-panel .metric span { font-size: 8px; }

.route-dock { left: 14px; right: 14px; width: auto; max-height: 27vh; padding: 10px 13px; }
.route-dock .section-head { position: sticky; top: -10px; z-index: 2; padding-bottom: 6px; background: rgb(8 8 8 / 95%); }
.route-dock .route-hint { margin: 6px 0; font-size: 10px; }
.route-dock .route-draft { margin: 6px 0; padding: 7px 9px; }
.route-dock .route-settings { grid-template-columns: 1fr 1fr; gap: 0 10px; }
.route-dock .route-settings .field-label { margin-top: 5px; }
.route-dock .route-settings .select-field { height: 32px; }
.route-dock .route-inputs { margin: 6px 0 7px; }
.route-dock .route-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 5px; max-height: 11vh; }
.route-dock .route-list .list-row { min-width: 0; padding: 6px 8px; }
.route-dock .route-list small { margin-top: 2px; font-size: 9px; }
.route-dock .full-button { min-height: 36px; }
.left-panel { bottom: calc(27vh + 28px); max-height: 27vh; }

/* Recognisable silhouettes: red-and-grey ED4M commuter stock and the yellow streamlined Lastochka. */
.train-visual { height: 27px; border: 2px solid var(--canvas); border-bottom-width: 3px; background: var(--steel); border-radius: 5px 10px 3px 3px; }
.train-visual::before { left: 8px; right: 8px; top: 5px; height: 9px; background: #202020; border-radius: 2px; box-shadow: 13px 0 0 #202020, 26px 0 0 #202020, 39px 0 0 #202020; }
.train-visual::after { width: 7px; height: 7px; right: 4px; bottom: -7px; background: var(--canvas); box-shadow: -38px 0 0 var(--canvas), -19px 0 0 var(--canvas); }
.train-visual.ed4m { color: var(--steel); box-shadow: inset 0 4px 0 #bcbcbc, inset 0 -4px 0 #262626; }
.train-visual.ed4m::before { background: #131313; box-shadow: 13px 0 0 #131313, 26px 0 0 #131313, 39px 0 0 #131313; }
.train-visual.lastochka { color: var(--amber); border-radius: 8px 19px 3px 3px; clip-path: polygon(0 20%, 18% 12%, 78% 0, 100% 18%, 100% 100%, 0 100%); box-shadow: inset 0 4px 0 #e8e8e8, inset 0 -4px 0 #171717; }
.train-visual.lastochka::before { left: 12px; top: 6px; right: 9px; background: #171717; box-shadow: 13px 0 0 #171717, 26px 0 0 #171717; }

.moving-train { width: 56px; height: 24px; border: 2px solid var(--canvas); border-radius: 5px 13px 4px 4px; box-shadow: 0 3px 10px rgb(0 0 0 / 60%), 0 0 0 2px rgb(255 255 255 / 20%); transition: transform .1s linear; }
.moving-train::before, .moving-train::after { content: none; }
.moving-train i { position: absolute; display: block; box-sizing: border-box; clip-path: none; }
.moving-train .train-cab { left: 3px; top: 3px; width: 48px; height: 14px; background: var(--steel); border-radius: 3px 9px 2px 2px; border-top: 3px solid #bdbdbd; border-bottom: 3px solid #262626; }
.moving-train .train-window { left: 10px; top: 7px; width: 10px; height: 5px; background: #101010; border-radius: 1px; box-shadow: 14px 0 0 #101010, 28px 0 0 #101010; }
.moving-train .train-window.second { left: 17px; opacity: .8; }
.moving-train .train-wheel { left: 8px; bottom: -5px; width: 7px; height: 7px; border-radius: 50%; background: var(--canvas); box-shadow: 30px 0 0 var(--canvas); }
.moving-train .train-wheel.second { display: none; }
.moving-train .train-tail { right: -4px; top: 5px; width: 5px; height: 9px; background: var(--steel); border-radius: 0 4px 4px 0; }
.moving-train.lastochka { border-radius: 6px 17px 4px 4px; background: var(--amber); }
.moving-train.lastochka .train-cab { left: 4px; width: 47px; background: var(--amber); border-top-color: #f3f3ef; border-bottom-color: #171717; clip-path: polygon(0 18%, 79% 0, 100% 25%, 100% 100%, 0 100%); }
.moving-train.lastochka .train-window { left: 18px; top: 7px; width: 9px; box-shadow: 13px 0 0 #101010, 26px 0 0 #101010; }
.moving-train.lastochka .train-tail { background: var(--amber); }

@media (max-width: 820px) {
  .summary-panel { width: min(290px, calc(100% - 20px)); max-height: 22vh; }
  .route-dock { left: 10px; right: 10px; max-height: 31vh; }
  .left-panel { bottom: calc(31vh + 18px); max-height: 23vh; }
  .route-dock .route-list { max-height: 10vh; }
}

@media (max-width: 540px) {
  .summary-panel { width: min(270px, calc(100% - 20px)); max-height: 20vh; }
  .route-dock { max-height: 36vh; }
  .left-panel { bottom: calc(36vh + 16px); max-height: 23vh; }
  .route-dock .route-list { grid-template-columns: 1fr; max-height: 13vh; }
}

/* Final compact map-first layout: controls are a slim dock, not a wall over the map. */
.left-panel { bottom: 10px; max-height: 88px; overflow: hidden; padding: 8px 10px; }
.left-panel .tool-list { gap: 5px; }
.left-panel .tool-button { min-height: 68px; padding: 6px 7px; gap: 7px; }
.left-panel .tool-icon { flex-basis: 24px; width: 24px; height: 24px; font-size: 11px; }
.left-panel .tool-button b { font-size: 11px; }
.left-panel .tool-button small { display: none; }
.summary-panel { top: 76px; width: min(290px, calc(44% - 7px)); max-height: 30vh; overflow-y: auto; padding: 9px 11px; }
.summary-panel .panel-section { padding-bottom: 8px; margin-bottom: 8px; }
.summary-panel .event-section { padding-bottom: 8px; }
.summary-panel .event-card { min-height: 38px; margin-top: 5px; padding: 6px 8px; }
.summary-panel .event-card p { display: none; }
.summary-panel .train-cards { margin-top: 4px; }
.summary-panel .train-card { min-height: 66px; padding: 5px; }
.summary-panel .train-visual { height: 17px; margin-bottom: 4px; }
.summary-panel .field-label { margin: 5px 0 3px; }
.summary-panel .select-field { height: 29px; }
.route-dock { right: 10px; bottom: 10px; width: min(620px, calc(44% - 7px)); max-height: 22vh; padding: 8px 10px; }
.route-dock .route-hint { margin: 4px 0; font-size: 10px; }
.route-dock .route-list { max-height: 10vh; }
.route-dock .route-settings .field-label { margin-top: 5px; }
.route-dock .route-settings .select-field { height: 29px; }
.route-dock .route-inputs { margin: 5px 0; }
.route-dock .button { min-height: 34px; }

@media (max-width: 820px) {
  .left-panel { left: 10px; right: 10px; bottom: 10px; width: auto; max-height: 82px; }
  .left-panel .tool-button { min-height: 58px; }
  .summary-panel { top: 70px; right: 10px; width: min(290px, calc(100% - 20px)); max-height: 23vh; }
  .route-dock { left: 10px; right: 10px; bottom: 10px; width: auto; max-height: 23vh; }
  .left-panel { bottom: calc(23vh + 18px); }
  .route-dock .route-list { max-height: 10vh; }
}

@media (max-width: 540px) {
  .left-panel { max-height: 78px; bottom: calc(23vh + 16px); }
  .left-panel .tool-button { min-height: 52px; }
  .left-panel .tool-icon { flex-basis: 22px; width: 22px; height: 22px; }
  .summary-panel { top: 70px; max-height: 19vh; }
  .route-dock { max-height: 23vh; }
}

/* Collapsible map panels: keep the map open and restore tools with one tap. */
.panel-heading-tools { display: flex; align-items: center; gap: 8px; }
.panel-close { width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 7px; background: rgb(17 17 17 / 76%); color: var(--muted); font-size: 20px; line-height: 1; }
.panel-close:hover { color: var(--white); border-color: var(--amber); background: var(--panel-2); }
.left-panel .panel-heading { display: flex; }
.left-panel .panel-heading > div:first-child { display: none; }
.left-panel .panel-heading { justify-content: flex-end; min-height: 0; margin-bottom: 3px; }
.left-panel .panel-heading .panel-heading-tools { width: 100%; justify-content: flex-end; }
.left-panel .panel-heading .step-badge { display: none; }
.floating-panel-head { display: flex; justify-content: space-between; align-items: center; min-height: 28px; margin-bottom: 3px; }
.floating-panel-head .panel-close { flex: 0 0 auto; }
.panel-reopen { position: absolute; z-index: 940; top: 78px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 5px; padding: 5px 6px; border: 1px solid rgb(7 19 31 / 28%); border-radius: 8px; background: rgb(8 8 8 / 86%); box-shadow: 0 8px 18px rgb(0 0 0 / 16%); backdrop-filter: blur(10px); }
.panel-reopen-label { padding: 0 5px; color: var(--amber); font-size: 9px; font-weight: 800; letter-spacing: .12em; }
.panel-reopen button { min-height: 28px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel-2); color: var(--muted); padding: 0 7px; font-size: 10px; font-weight: 700; }
.panel-reopen button:hover { color: var(--white); border-color: var(--steel); }
.summary-panel { max-height: 27vh; }
.summary-panel .floating-panel-head { margin-bottom: 3px; }
.route-dock { max-height: 20vh; }
.route-dock .section-head { min-height: 30px; }
.route-dock .route-list { max-height: 8vh; }
.left-panel { bottom: 10px; max-height: 86px; }
.left-panel .tool-list { margin-top: 0; }

/* More legible silhouettes for the two train families at map scale. */
.moving-train { width: 72px; height: 29px; border-radius: 6px 15px 4px 4px; }
.moving-train .train-cab { left: 3px; top: 3px; width: 64px; height: 19px; border-top-width: 4px; border-bottom-width: 4px; }
.moving-train .train-window { left: 10px; top: 9px; width: 11px; height: 6px; box-shadow: 15px 0 0 #101010, 30px 0 0 #101010, 45px 0 0 #101010; }
.moving-train .train-wheel { left: 11px; bottom: -6px; width: 8px; height: 8px; box-shadow: 40px 0 0 var(--canvas); }
.moving-train .train-tail { right: -5px; top: 6px; width: 7px; height: 13px; }
.moving-train.ed4m { background: #b8b8b2; }
.moving-train.ed4m .train-cab { background: var(--steel); border-top-color: #d1d1cb; border-bottom-color: #262626; box-shadow: inset 0 -3px 0 #6f6f6b; }
.moving-train.ed4m .train-window { background: #18242a; box-shadow: 15px 0 0 #18242a, 30px 0 0 #18242a, 45px 0 0 #18242a; }
.moving-train.lastochka { width: 74px; height: 29px; border-radius: 7px 21px 4px 4px; background: #d8d8d0; }
.moving-train.lastochka .train-cab { left: 4px; width: 65px; height: 19px; background: var(--amber); border-top-color: #faf9ee; border-bottom-color: #4f4a2a; clip-path: polygon(0 18%, 70% 4%, 92% 17%, 100% 43%, 100% 100%, 0 100%); }
.moving-train.lastochka .train-window { left: 19px; top: 9px; width: 10px; box-shadow: 14px 0 0 #15232a, 28px 0 0 #15232a, 42px 0 0 #15232a; }
.moving-train.lastochka .train-wheel { left: 17px; box-shadow: 39px 0 0 var(--canvas); }
.moving-train.lastochka .train-tail { right: -5px; background: #d8d8d0; }

@media (max-width: 820px) {
  .panel-reopen { top: 72px; max-width: calc(100% - 20px); overflow-x: auto; }
  .panel-reopen-label { display: none; }
  .left-panel { bottom: calc(20vh + 16px); max-height: 82px; }
  .route-dock { max-height: 20vh; }
  .route-dock .route-list { max-height: 7vh; }
  .summary-panel { max-height: 22vh; }
}
@media (max-width: 540px) {
  .panel-reopen { top: 66px; left: 10px; right: 10px; transform: none; justify-content: center; }
  .panel-reopen button { flex: 1 0 auto; }
  .left-panel { bottom: calc(20vh + 14px); max-height: 76px; }
  .route-dock { max-height: 20vh; }
  .summary-panel { max-height: 19vh; }
}

/* Keep every construction action reachable while staying below the map. */
.left-panel { max-height: 154px; overflow-y: auto; overflow-x: hidden; }
.left-panel .panel-heading { position: sticky; top: -8px; z-index: 2; padding-top: 2px; background: rgb(8 8 8 / 94%); }
@media (max-width: 820px) {
  .left-panel { max-height: 154px; bottom: calc(20vh + 16px); }
}
@media (max-width: 540px) {
  .left-panel { max-height: 145px; bottom: calc(20vh + 14px); }
}

.train-visual.ed4m { background: linear-gradient(180deg, #c9c9c3 0 18%, var(--steel) 19% 74%, #343434 75%); box-shadow: inset 0 0 0 1px #111, inset 0 -4px 0 #222; }
.train-visual.ed4m::before { background: linear-gradient(180deg, #273d46 0 45%, #111 46%); box-shadow: 13px 0 0 #111, 26px 0 0 #111, 39px 0 0 #111; }
.train-visual.lastochka { background: linear-gradient(180deg, #f0f0e8 0 14%, var(--amber) 15% 77%, #3d3a27 78%); box-shadow: inset 0 0 0 1px #111, inset 0 -4px 0 #171717; }
.train-visual.lastochka::before { background: linear-gradient(135deg, #253b43, #101719); box-shadow: 13px 0 0 #101719, 26px 0 0 #101719; }

/* Touch drawing and visible moving rolling stock. */
#map.track-drawing { touch-action: none; cursor: crosshair; }
.moving-train { display: block; position: relative; transform-origin: 50% 50%; pointer-events: none; }

@media (max-width: 820px) {
  /* The route board has its own slot above the construction dock. */
  .left-panel { left: 10px; right: 10px; bottom: 10px; width: auto; max-height: 122px; }
  .left-panel .tool-list { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
  .left-panel .tool-button { min-height: 45px; padding: 4px 5px; gap: 5px; }
  .left-panel .tool-icon { flex-basis: 21px; width: 21px; height: 21px; }
  .left-panel .tool-button b { font-size: 10px; }
  .route-dock { left: 10px; right: 10px; bottom: 144px; width: auto; max-height: 22vh; }
}
@media (max-width: 540px) {
  .left-panel { bottom: 8px; max-height: 116px; }
  .left-panel .panel-heading { margin-bottom: 0; }
  .left-panel .tool-button { min-height: 43px; }
  .route-dock { bottom: 134px; max-height: 23vh; }
}

/* Final layout contract: construction and route controls have separate slots.
   The route board never sits on top of the construction controls. */
@media (min-width: 821px) {
  .left-panel { left: 14px !important; right: auto !important; bottom: 14px !important; width: min(370px, 35vw) !important; max-height: 154px !important; }
  .route-dock { left: min(398px, calc(35vw + 24px)) !important; right: 14px !important; bottom: 14px !important; width: auto !important; max-height: 20vh !important; }
  .summary-panel { top: 78px !important; right: 14px !important; bottom: auto !important; width: min(292px, 29vw) !important; max-height: 27vh !important; }
}
@media (max-width: 820px) {
  .route-dock { left: 10px !important; right: 10px !important; bottom: 10px !important; width: auto !important; max-height: min(22vh, 190px) !important; }
  .left-panel { left: 10px !important; right: 10px !important; bottom: calc(min(22vh, 190px) + 22px) !important; width: auto !important; max-height: 122px !important; }
}
@media (max-width: 540px) {
  .route-dock { bottom: 8px !important; max-height: min(25vh, 184px) !important; }
  .left-panel { bottom: calc(min(25vh, 184px) + 18px) !important; max-height: 116px !important; }
}

/* Realistic map-scale consists: separate car bodies, dark window bands,
   bogies and couplers, while staying small enough not to hide the map. */
.moving-train { width: 76px !important; height: 28px !important; gap: 1px; filter: drop-shadow(0 2px 2px rgb(0 0 0 / 55%)); }
.moving-train.lastochka { width: 88px !important; height: 28px !important; }
.moving-train .train-car { flex: 0 0 18px; width: 18px; height: 17px; margin: 0; border: 1px solid #171717; border-radius: 2px; box-shadow: inset 0 2px 0 rgb(255 255 255 / 42%), inset 0 -3px 0 rgb(0 0 0 / 42%); }
.moving-train .train-car::before { left: -3px; top: 7px; width: 3px; height: 3px; border-radius: 50%; box-shadow: 19px 0 0 #171717; }
.moving-train .train-car::after { left: 2px; right: 2px; bottom: -4px; height: 4px; background: radial-gradient(circle at 3px 1px, #101010 0 2px, transparent 2.5px), radial-gradient(circle at 13px 1px, #101010 0 2px, transparent 2.5px); }
.moving-train .train-car b { left: 2px; right: 2px; top: 4px; height: 6px; background: repeating-linear-gradient(90deg, #14272e 0 4px, #0b1215 4px 5px, transparent 5px 6px); }
.moving-train .train-car em { left: -2px; right: -2px; bottom: 1px; height: 1px; }
.moving-train .train-car.front { clip-path: polygon(0 0, 72% 0, 100% 28%, 100% 100%, 0 100%); }
.moving-train.ed4m .train-car { background: linear-gradient(180deg, #c9c9c3 0 16%, #c3312f 17% 72%, #272727 73%); }
.moving-train.ed4m .train-car.front, .moving-train.ed4m .train-car.rear { background: linear-gradient(180deg, #d8d8d0 0 16%, #b82221 17% 72%, #272727 73%); }
.moving-train.lastochka .train-car { flex-basis: 17px; width: 17px; background: linear-gradient(180deg, #f2f2ed 0 18%, #bd2d32 19% 32%, #d8d8d2 33% 72%, #282828 73%); }
.moving-train.lastochka .train-car.front, .moving-train.lastochka .train-car.rear { background: linear-gradient(180deg, #fafaf4 0 18%, #c52e32 19% 36%, #deded8 37% 72%, #282828 73%); }
.moving-train.lastochka .train-car b { background: repeating-linear-gradient(90deg, #152a31 0 3px, #101719 3px 4px, transparent 4px 5px); }
.train-visual.lastochka { background: linear-gradient(180deg, #f1f1eb 0 16%, #bd2d32 17% 31%, #d8d8d2 32% 77%, #303030 78%); }
.train-visual.lastochka::before { background: #18282f; box-shadow: 13px 0 0 #18282f, 26px 0 0 #18282f; }

/* Final non-overlapping desktop slots: construction owns the left edge,
   routes own the centre/right bottom edge, and the summary stays above. */
@media (min-width: 821px) {
  .left-panel { left: 14px; right: auto; bottom: 14px; width: min(370px, 35vw); max-height: 154px; }
  .route-dock { left: min(398px, calc(35vw + 24px)); right: 14px; bottom: 14px; width: auto; max-height: 20vh; }
  .summary-panel { top: 78px; right: 14px; bottom: auto; width: min(292px, 29vw); max-height: 27vh; }
}

/* Rolling stock: a visible consist of separate cars, windows, couplers and
   bogies. Both train families use a cab car at each end and reverse at the
   terminal instead of disappearing. */
.moving-train {
  display: flex !important;
  align-items: flex-end;
  gap: 1px;
  position: relative;
  width: 122px !important;
  height: 40px !important;
  transform-origin: 50% 50%;
  transition: transform .1s linear;
  filter: drop-shadow(0 3px 3px rgb(0 0 0 / 58%));
  pointer-events: none;
}
.moving-train.lastochka { width: 142px !important; height: 40px !important; }
.moving-train .train-car {
  position: relative;
  display: block;
  flex: 0 0 29px;
  height: 25px;
  margin: 0;
  border: 2px solid #151515;
  border-radius: 3px 3px 2px 2px;
  background: linear-gradient(180deg, #d4d4ce 0 17%, #a8a8a2 18% 72%, #252525 73%);
  box-shadow: inset 0 3px 0 rgb(255 255 255 / 42%), inset 0 -4px 0 rgb(0 0 0 / 35%);
}
.moving-train .train-car::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 9px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #171717;
  box-shadow: 31px 0 0 #171717;
}
.moving-train .train-car::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: -5px;
  height: 5px;
  background: radial-gradient(circle at 4px 2px, #101010 0 3px, transparent 3.5px), radial-gradient(circle at 20px 2px, #101010 0 3px, transparent 3.5px);
}
.moving-train .train-car b {
  position: absolute;
  z-index: 1;
  left: 4px;
  right: 4px;
  top: 6px;
  height: 7px;
  border-radius: 1px;
  background: repeating-linear-gradient(90deg, #16262d 0 6px, #111 6px 7px, transparent 7px 8px);
}
.moving-train .train-car em {
  position: absolute;
  z-index: 2;
  left: -3px;
  right: -3px;
  bottom: 2px;
  height: 2px;
  background: #101010;
}
.moving-train .train-car.front,
.moving-train .train-car.rear { border-radius: 5px 9px 2px 2px; }
.moving-train .train-car.front { clip-path: polygon(0 0, 76% 0, 100% 28%, 100% 100%, 0 100%); }
.moving-train.ed4m .train-car { background: linear-gradient(180deg, #c9c9c3 0 16%, #c3312f 17% 72%, #282828 73%); }
.moving-train.ed4m .train-car.front,
.moving-train.ed4m .train-car.rear { background: linear-gradient(180deg, #d2d2cc 0 16%, #b82221 17% 72%, #282828 73%); }
.moving-train.lastochka .train-car { flex-basis: 27px; background: linear-gradient(180deg, #f0f0e8 0 18%, #d5b738 19% 31%, #d7d7cf 32% 73%, #282828 74%); }
.moving-train.lastochka .train-car.front,
.moving-train.lastochka .train-car.rear { background: linear-gradient(180deg, #f7f7ef 0 18%, #f2c84b 19% 35%, #d8d8d0 36% 73%, #282828 74%); }
.moving-train.lastochka .train-car b { background: repeating-linear-gradient(90deg, #152a31 0 5px, #111 5px 6px, transparent 6px 7px); }
.moving-train.is-idle { opacity: .9; }
.moving-train.is-idle::after { content: ""; position: absolute; left: 50%; bottom: -9px; width: 5px; height: 5px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 3px rgb(242 200 75 / 22%); }

@media (max-width: 820px) {
  .route-dock { bottom: 144px; }
  .left-panel { bottom: 10px; }
}
@media (max-width: 540px) {
  .route-dock { bottom: 134px; }
  .left-panel { bottom: 8px; }
}

/* Map-scale rolling stock: compact, separate cars instead of one oversized bar. */
.leaflet-marker-icon:has(.moving-train) { overflow: visible; }
.moving-train {
  width: 38px !important;
  height: 17px !important;
  gap: 1px;
  align-items: flex-end;
  filter: drop-shadow(0 2px 2px rgb(0 0 0 / 58%));
}
.moving-train.lastochka { width: 46px !important; height: 17px !important; }
.moving-train .train-car {
  flex: 0 0 8px;
  width: 8px;
  height: 10px;
  border: 1px solid #151515;
  border-radius: 2px;
  background: linear-gradient(180deg, #c9c9c3 0 18%, #b82221 19% 72%, #282828 73%);
  box-shadow: inset 0 2px 0 rgb(255 255 255 / 42%), inset 0 -2px 0 rgb(0 0 0 / 35%);
}
.moving-train .train-car::before {
  left: -2px;
  top: 4px;
  width: 2px;
  height: 2px;
  border-radius: 0;
  background: #101010;
  box-shadow: 9px 0 0 #101010;
}
.moving-train .train-car::after {
  left: 1px;
  right: 1px;
  bottom: -3px;
  height: 3px;
  background: radial-gradient(circle at 1px 1px, #101010 0 1.5px, transparent 1.8px), radial-gradient(circle at 6px 1px, #101010 0 1.5px, transparent 1.8px);
}
.moving-train .train-car b {
  left: 2px;
  right: 2px;
  top: 3px;
  height: 3px;
  border-radius: 0;
  background: repeating-linear-gradient(90deg, #16262d 0 3px, #111 3px 3.5px, transparent 3.5px 4px);
}
.moving-train .train-car em {
  left: -2px;
  right: -2px;
  bottom: 1px;
  height: 1px;
}
.moving-train .train-car.front,
.moving-train .train-car.rear { border-radius: 2px 4px 2px 2px; }
.moving-train .train-car.front { clip-path: polygon(0 0, 72% 0, 100% 28%, 100% 100%, 0 100%); }
.moving-train.ed4m .train-car.front,
.moving-train.ed4m .train-car.rear { background: linear-gradient(180deg, #d2d2cc 0 18%, #b82221 19% 72%, #282828 73%); }
.moving-train.lastochka .train-car {
  flex-basis: 8px;
  width: 8px;
  background: linear-gradient(180deg, #f7f7ef 0 20%, #f2c84b 21% 34%, #d8d8d0 35% 73%, #282828 74%);
}
.moving-train.lastochka .train-car.front,
.moving-train.lastochka .train-car.rear {
  background: linear-gradient(180deg, #f7f7ef 0 20%, #f2c84b 21% 38%, #d8d8d0 39% 73%, #282828 74%);
}
.moving-train.lastochka .train-car b { background: repeating-linear-gradient(90deg, #152a31 0 3px, #111 3px 3.5px, transparent 3.5px 4px); }

/* Explicit slots keep the construction dock and route board physically apart. */
@media (max-width: 820px) {
  .left-panel { bottom: 10px; max-height: 122px; }
  .route-dock { bottom: 144px; max-height: min(22vh, 190px); }
}
@media (max-width: 540px) {
  .left-panel { bottom: 8px; max-height: 116px; }
  .route-dock { bottom: 134px; max-height: min(23vh, 180px); }
}

.leaflet-marker-icon.train-icon { overflow: visible; }
.moving-train {
  width: 38px !important;
  height: 17px !important;
  min-width: 38px;
  min-height: 17px;
  transform-origin: 50% 50%;
  will-change: transform;
}
.moving-train.lastochka { width: 46px !important; min-width: 46px; height: 17px !important; }
.moving-train .train-car { overflow: visible; }
.moving-train .train-car b.car-roof {
  z-index: 3;
  left: 1px;
  right: 1px;
  top: 1px;
  height: 2px;
  border-radius: 1px 1px 0 0;
  background: var(--train-roof-ed4m);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 48%);
}
.moving-train .train-car b.car-windows {
  z-index: 1;
  left: 2px;
  right: 2px;
  top: 4px;
  height: 4px;
  border-radius: 1px;
  background: repeating-linear-gradient(90deg, var(--train-window) 0 3px, #0d171b 3px 3.5px, transparent 3.5px 4px);
  box-shadow: none;
}
.moving-train .train-car .car-lamp, .moving-train .train-car .car-sign {
  position: absolute;
  display: none;
  z-index: 4;
  pointer-events: none;
}
.moving-train .train-car.front .car-lamp, .moving-train .train-car.rear .car-lamp {
  display: block;
  top: 8px;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: var(--train-lamp);
  box-shadow: 0 0 2px var(--train-lamp);
}
.moving-train .train-car.front .car-lamp { right: 1px; }
.moving-train .train-car.rear .car-lamp { left: 1px; }
.moving-train .train-car.front .car-sign, .moving-train .train-car.rear .car-sign {
  display: block;
  top: 3px;
  width: 2px;
  height: 3px;
  background: var(--steel);
}
.moving-train .train-car.front .car-sign { right: 2px; }
.moving-train .train-car.rear .car-sign { left: 2px; }
.moving-train.ed4m .train-car b.car-roof { background: var(--train-roof-ed4m); }
.moving-train.ed4m .train-car.front .car-sign, .moving-train.ed4m .train-car.rear .car-sign { background: var(--steel-strong); }
.moving-train.lastochka .train-car b.car-roof { background: var(--train-roof-lastochka); }
.moving-train.lastochka .train-car.front .car-sign, .moving-train.lastochka .train-car.rear .car-sign { background: var(--steel-strong); }
.moving-train.lastochka .train-car { background: linear-gradient(180deg, #f4f4ee 0 18%, var(--steel-strong) 19% 32%, #d9d9d3 33% 73%, #282828 74%); }
.moving-train.lastochka .train-car.front, .moving-train.lastochka .train-car.rear { background: linear-gradient(180deg, #fafaf4 0 18%, var(--steel-strong) 19% 36%, #deded8 37% 73%, #282828 74%); }
.train-visual.lastochka { background: linear-gradient(180deg, #f4f4ee 0 16%, var(--steel-strong) 17% 31%, #d9d9d3 32% 77%, #303030 78%); }
.train-visual.lastochka::before { background: var(--train-window); box-shadow: 13px 0 0 var(--train-window), 26px 0 0 var(--train-window); }
