:root {
  --bg: #0f1216; --panel: #181c22; --panel-2: #20252d; --line: #2c323b; --text: #e8ebf0; --muted: #98a1ae;
  --accent: #4aa3ff; --accent-ink: #04121f; --danger: #ef5b52; --map: #0d1015;
  --radius: 10px; --shadow: 0 6px 24px #0008, 0 1px 0 #ffffff0d inset;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { display: flex; flex-direction: column; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }

/* The top bar is thin: the map is the page */
.topbar { display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex: none; z-index: 5; }
.brand { letter-spacing: .02em; }
.goto { display: flex; gap: 6px; margin-left: 12px; }
.goto input { width: 78px; }
.status { margin-left: auto; color: var(--muted); font-size: 13px; }
main { flex: 1; min-height: 0; position: relative; }
#map-wrap { position: absolute; inset: 0; background: var(--map); }
canvas { width: 100%; height: 100%; display: block; touch-action: none; }

/* Everything on top of the map floats, so the map is never narrowed by a panel */
.card { position: absolute; background: #181c22ee; backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

input, select, button { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px; }
input:focus, select:focus { border-color: var(--accent); outline: none; }
button { cursor: pointer; transition: background .12s, border-color .12s; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
button.active, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover:not(:disabled) { color: var(--text); background: var(--panel-2); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
label.inline { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { margin: 0; font-size: 14px; }
hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font: 12px ui-monospace, monospace; }

/* The tools: a slim bar down the left of the map */
.tools { position: absolute; top: 12px; left: 12px; width: 58px; display: flex; flex-direction: column; gap: 4px; padding: 6px; background: #181c22ee; backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 2; }
.tools hr { margin: 2px 0; }
.tools button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px 4px; border-color: transparent; background: transparent; font-size: 11px; color: var(--muted); }
.tools button:hover:not(:disabled) { background: var(--panel-2); color: var(--text); border-color: transparent; }
.tools button.active { background: var(--accent); color: var(--accent-ink); }
.tools svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tools #tool-select svg { fill: currentColor; stroke-width: 1; }

/* The list of roads and stops opens next to the tools, over the map, when it is wanted */
#list-panel { top: 12px; left: 82px; bottom: 12px; width: 300px; display: flex; flex-direction: column; gap: 8px; padding: 10px; z-index: 2; }
#list-panel[hidden] { display: none; }
#road-list { overflow-y: auto; flex: 1; min-height: 0; }

/* The properties are only there when there is something to set: a selection, or a tool that has settings */
#props-panel { top: 12px; right: 12px; width: 268px; max-height: calc(54% - 12px); overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; z-index: 2; }
#props-panel:not(:has(#draw-settings:not([hidden]), #round-settings:not([hidden]), #stop-settings:not([hidden]), #stop-selection:not([hidden]), #sel-form:not([hidden]))) { display: none; }
#props-panel section { display: flex; flex-direction: column; gap: 8px; }
#props-panel section[hidden], #sel-form[hidden] { display: none; }
#sel-form { display: flex; flex-direction: column; gap: 8px; }
#props-panel > .note { display: none; }
.note { color: var(--muted); font-size: 12px; margin: 0; }

.hint, .coords { position: absolute; padding: 3px 9px; background: #0009; border-radius: 999px; color: var(--muted); pointer-events: none; font-size: 12px; }
.hint { top: 12px; left: 50%; transform: translateX(-50%); color: var(--text); max-width: 60%; }
.hint:empty { display: none; }
.coords:empty { display: none; }
.coords { bottom: 12px; left: 82px; font-variant-numeric: tabular-nums; }

.help { top: 56px; right: 12px; width: 380px; max-width: calc(100% - 24px); padding: 12px 14px; z-index: 4; }
.help[hidden] { display: none; }
.help dl { display: grid; grid-template-columns: 90px 1fr; gap: 6px 10px; margin: 8px 0 0; font-size: 13px; }
.help dt { color: var(--muted); }
.help dd { margin: 0; }

.filters { display: flex; gap: 6px; } .filters input { flex: 1; min-width: 0; }
.filters select { width: 110px; flex: none; }
.list-actions { display: flex; gap: 6px; align-items: center; } #count { margin-left: auto; color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 4px; padding: 3px; background: var(--bg); border-radius: 8px; }
.tabs button { flex: 1; border-color: transparent; background: transparent; }
.tabs button.active { background: var(--panel-2); color: var(--text); border-color: var(--line); }
ul { list-style: none; margin: 0; padding: 0; }
#road-list li { display: flex; gap: 8px; align-items: center; padding: 5px 7px; border-radius: 6px; cursor: pointer; }
#road-list li:hover { background: var(--panel-2); }
#road-list li.selected { background: #1f3a57; }
#road-list .swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }
#road-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#road-list .meta { color: var(--muted); font-size: 12px; }

.overlay { position: fixed; inset: 0; background: var(--bg); display: none; align-items: center; justify-content: center; z-index: 10; }
.overlay.open { display: flex; }
#login-form { display: flex; flex-direction: column; gap: 10px; width: min(340px, 90vw); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }

/* The layers and legend: a button in the corner that opens upwards */
.legend { right: 12px; bottom: 12px; width: 240px; max-height: calc(42% - 12px); overflow-y: auto; padding: 4px; display: flex; flex-direction: column-reverse; z-index: 2; }
.legend > button { width: 100%; text-align: left; border: 0; background: transparent; font-weight: 600; }
#legend-panel[hidden] { display: none; }
.legend h3 { margin: 8px 6px 2px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.legend-row { flex-direction: row; align-items: center; gap: 8px; padding: 3px 6px; border-radius: 6px; color: var(--text); cursor: pointer; }
.legend-row:hover { background: var(--panel-2); }
.legend-row input[type=range] { width: 70px; padding: 0; }
.legend-name { flex: 1; }
.legend-count { color: var(--muted); font-size: 12px; }
.line { width: 26px; height: var(--thickness, 3px); min-height: 3px; border-radius: 2px; background: var(--color); flex: none; }
.line.rail { height: 9px; border-radius: 1px; background:
  repeating-linear-gradient(90deg, #fff 0 3px, transparent 3px 6px), linear-gradient(var(--color), var(--color)); }

/* A stop mark: the colour and the first letter of what it is, in a shape for each kind */
.badge { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; flex: none; color: #fff; font: 700 11px/1 system-ui; border: 2px solid #fff; box-shadow: 0 0 0 1px #10141a; }
.badge.shape-circle { border-radius: 50%; }
.badge.shape-square { border-radius: 6px; }
.badge.shape-hexagon { border: 0; box-shadow: none; clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%); }
.badge.shape-diamond { border: 0; box-shadow: none; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
#road-list .badge { width: 22px; height: 22px; }

@media (max-width: 760px) {
  #list-panel { left: 12px; right: 12px; top: auto; bottom: 12px; height: 45%; width: auto; }
  #props-panel { width: calc(100% - 24px); max-height: 45%; top: auto; bottom: 12px; }
  .legend { bottom: auto; top: 12px; right: 76px; }
  .brand, .goto { display: none; }
}

.row { display: flex; gap: 6px; }
.row[hidden], .note[hidden] { display: none; }
.row button { flex: 1; padding-inline: 4px; }

details { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 8px; }
.details-body { display: flex; flex-direction: column; gap: 8px; }
