html, body { margin: 0; height: 100%; font: 14px/1.45 system-ui, sans-serif; }
#map { position: absolute; inset: 0; }
.panel {
    position: absolute; z-index: 1000; background: rgba(255, 255, 255, .92);
    padding: 8px 12px; border-radius: 6px; box-shadow: 0 1px 6px rgba(0, 0, 0, .3);
}
#hud { top: 10px; right: 10px; min-width: 240px; }
#hud b { font-size: 22px; }
#help { bottom: 24px; left: 10px; font-size: 13px; }
#help input { vertical-align: middle; }
#msg {
    position: absolute; z-index: 1001; top: 40%; left: 50%; transform: translateX(-50%);
    background: #c62828; color: #fff; padding: 10px 20px; border-radius: 6px; font-size: 20px;
}
.train-canvas { position: absolute; top: 0; left: 0; z-index: 450; pointer-events: none; }
#search { top: 10px; left: 56px; padding: 6px; }
#search input { width: 260px; font: inherit; padding: 4px 8px; border: 1px solid #bbb; border-radius: 4px; }

/* On-screen controls: shown on touch devices only. */
#controls {
    display: none; position: absolute; z-index: 1000;
    right: calc(10px + env(safe-area-inset-right)); bottom: calc(24px + env(safe-area-inset-bottom));
    flex-direction: column; align-items: flex-end; gap: 8px;
    touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#controls .row { display: flex; gap: 8px; align-items: flex-end; }
#controls .pedals { display: flex; flex-direction: column; gap: 8px; }
#controls button {
    font: 600 15px system-ui, sans-serif; color: #222; background: rgba(255, 255, 255, .92);
    border: 0; border-radius: 10px; padding: 12px 14px; min-width: 64px;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .35); touch-action: none;
}
#controls button.big { width: 76px; height: 76px; font-size: 32px; }
#controls button.stop { background: #c62828; color: #fff; width: 76px; height: 76px; }
#controls button.active { filter: brightness(.8); transform: scale(.96); }

@media (pointer: coarse) {
    #controls { display: flex; }
    #help { display: none; }
}
@media (max-width: 600px) {
    #search { left: 52px; right: 10px; }
    #search input { width: 100%; box-sizing: border-box; }
    #hud { top: 62px; right: 10px; left: auto; min-width: 0; font-size: 12px; padding: 6px 10px; }
    #hud b { font-size: 18px; }
    #msg { font-size: 16px; }
}
