:root {
  --paper: #edf1f4;
  --surface: #ffffff;
  --ink: #14202b;
  --muted: #5a6875;
  --rule: #cfd7de;
  --grid: #dde4ea;
  --stop-fill: #ffffff;
  --line-linear: #d7263d;
  --line-trees: #1b6ca8;
  --line-graphs: #2e9e5b;
  --line-sched: #e08a00;
  --line-dp: #00897b;
  --line-bits: #7a5c3e;
  --easy: #2e9e5b;
  --medium: #c77700;
  --hard: #d7263d;
  --focus: #1b6ca8;
  --sign-bg: #14202b;
  --sign-ink: #edf1f4;
  --radius: 10px;
  --font: "Overpass", system-ui, sans-serif;
  --mono: "Overpass Mono", ui-monospace, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0e1821;
    --surface: #15222d;
    --ink: #e6edf2;
    --muted: #93a3b1;
    --rule: #26384a;
    --grid: #1a2a37;
    --stop-fill: #0e1821;
    --line-linear: #ff5a6e;
    --line-trees: #4fa3e8;
    --line-graphs: #4cc983;
    --line-sched: #ffb43c;
    --line-dp: #2fc4b2;
    --line-bits: #c49a6c;
    --easy: #4cc983;
    --medium: #ffb43c;
    --hard: #ff5a6e;
    --focus: #4fa3e8;
    --sign-bg: #070f16;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #0e1821;
  --surface: #15222d;
  --ink: #e6edf2;
  --muted: #93a3b1;
  --rule: #26384a;
  --grid: #1a2a37;
  --stop-fill: #0e1821;
  --line-linear: #ff5a6e;
  --line-trees: #4fa3e8;
  --line-graphs: #4cc983;
  --line-sched: #ffb43c;
  --line-dp: #2fc4b2;
  --line-bits: #c49a6c;
  --easy: #4cc983;
  --medium: #ffb43c;
  --hard: #ff5a6e;
  --focus: #4fa3e8;
  --sign-bg: #070f16;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
}

button, input { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Header: a station sign — ink band, white type, roundel. */
.sign {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--sign-bg);
  color: var(--sign-ink);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.roundel { width: 30px; height: 30px; }
.roundel circle { fill: var(--sign-ink); stroke: var(--line-linear); stroke-width: 6; }
.brand-name { font-weight: 900; font-size: 1.25rem; letter-spacing: -0.01em; }
.brand-host { font-family: var(--mono); font-size: 0.8rem; opacity: 0.7; }
.sign-controls { display: flex; align-items: center; gap: 10px; }

.service {
  display: flex;
  border: 1.5px solid color-mix(in srgb, var(--sign-ink) 40%, transparent);
  border-radius: 999px;
  padding: 3px;
}
.service button {
  border: 0; background: transparent; color: var(--sign-ink);
  padding: 5px 14px; border-radius: 999px; cursor: pointer; font-weight: 600;
}
.service button[aria-checked="true"] { background: var(--sign-ink); color: var(--sign-bg); }
.service .count { font-family: var(--mono); font-size: 0.78rem; opacity: 0.75; }

.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px;
  border: 1.5px solid color-mix(in srgb, var(--sign-ink) 40%, transparent);
  background: transparent; border-radius: 999px; cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; fill: var(--sign-ink); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-areas: "map rail" "stops rail";
  gap: 20px;
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px;
  align-items: start;
}
.map-panel { grid-area: map; }
.rail { grid-area: rail; display: grid; gap: 14px; position: sticky; top: 16px; }
.stops { grid-area: stops; }

.panel-head h1 { margin: 0; font-size: 1.6rem; font-weight: 900; letter-spacing: -0.02em; }
.hint { margin: 2px 0 10px; color: var(--muted); font-size: 0.92rem; }

.map-scroll {
  overflow-x: auto;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 38px 38px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 38px 38px,
    var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
#map { display: block; width: 100%; min-width: 720px; height: auto; }

.track { pointer-events: none; fill: none; stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; }
.track.dim { opacity: 0.28; }

.stop { cursor: pointer; }
.stop .ring-bg { fill: var(--stop-fill); stroke-width: 5; }
.stop .fill { fill: none; stroke-width: 12; transform: rotate(-90deg); transform-box: fill-box; transform-origin: center; transition: stroke-dashoffset 400ms ease; }
.stop .core { fill: var(--stop-fill); }
.stop .done-mark { fill: var(--stop-fill); font-family: var(--mono); font-weight: 600; font-size: 13px; }
.stop text.name { fill: var(--ink); font-weight: 800; font-size: 17px; letter-spacing: -0.01em; paint-order: stroke; stroke: var(--surface); stroke-width: 5px; stroke-linejoin: round; }
.stop text.tally { fill: var(--muted); font-family: var(--mono); font-size: 12.5px; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.stop:hover .ring-bg, .stop:focus-visible .ring-bg { stroke-width: 7; }
.stop:focus { outline: none; }
.stop:focus-visible .halo, .stop.selected .halo { opacity: 1; }
.stop .halo { fill: none; stroke: var(--ink); stroke-width: 2; stroke-dasharray: 4 4; opacity: 0; }
.stop.empty { opacity: 0.35; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; list-style: none; padding: 0; margin: 10px 0 0; font-size: 0.85rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 22px; height: 6px; border-radius: 3px; }

/* Rail cards */
.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.eyebrow {
  margin: 0 0 6px; font-family: var(--mono); font-size: 0.74rem; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.total { margin: 0 0 12px; display: flex; align-items: baseline; gap: 8px; }
#solved-total { font-size: 3rem; font-weight: 900; line-height: 1; letter-spacing: -0.03em; }
.of { font-family: var(--mono); color: var(--muted); }
.diffs { display: grid; gap: 8px; }
.diff-row { display: grid; grid-template-columns: 64px 1fr 56px; align-items: center; gap: 10px; font-size: 0.88rem; }
.diff-row .bar { height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; }
.diff-row .bar span { display: block; height: 100%; border-radius: 4px; transition: width 400ms ease; }
.diff-row .n { font-family: var(--mono); text-align: right; color: var(--muted); }

.next-stop { display: block; text-decoration: none; color: inherit; margin-bottom: 8px; }
.next-stop .station { font-size: 0.82rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.next-stop .station i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.next-stop strong { display: block; font-size: 1.15rem; font-weight: 800; line-height: 1.25; margin-top: 2px; }
.next-stop:hover strong { text-decoration: underline; text-underline-offset: 3px; }

.text-btn {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--focus); font-weight: 600; font-size: 0.9rem;
  text-decoration: underline; text-underline-offset: 3px;
}
.text-btn.danger { color: var(--hard); }
.file-btn input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.file-btn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.data-btns { display: flex; gap: 16px; flex-wrap: wrap; }
.fine { margin: 6px 0; font-size: 0.8rem; color: var(--muted); }
.fine:empty { display: none; }

/* Streak: a punched ticket */
.streak-nums { display: flex; gap: 24px; margin-bottom: 10px; }
.streak-nums p { margin: 0; font-weight: 600; }
.streak-nums span:first-child { font-size: 1.8rem; font-weight: 900; }
.streak-nums .sub { display: block; font-family: var(--mono); font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.punches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; padding: 10px; border: 1.5px dashed var(--rule); border-radius: 8px; }
.punch { aspect-ratio: 1; border-radius: 50%; border: 1.5px solid var(--rule); }
.punch.hit { background: var(--paper); border-color: var(--ink); box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 9px var(--ink); }
.punch.today { border-color: var(--focus); border-width: 2.5px; }
.punch.future { border-style: dotted; opacity: 0.4; }

/* Stop detail */
.stops-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.stops-head h2 { margin: 0; font-size: 1.6rem; font-weight: 900; letter-spacing: -0.02em; }
#stop-line { display: flex; align-items: center; gap: 6px; }
#stop-line i { width: 22px; height: 6px; border-radius: 3px; display: inline-block; }
.search input {
  width: min(280px, 100%); padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 8px;
}
.search input:focus-visible { outline-offset: 0; }

.plist { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }
.plist li { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto auto; align-items: center; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--rule); }
.plist li:first-child { border-top: 0; }
.plist li.solved .ptitle { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.plist input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--ink); cursor: pointer; }
.ptitle { color: var(--ink); text-decoration: none; font-weight: 600; overflow-wrap: anywhere; }
.ptitle:hover { text-decoration: underline; text-underline-offset: 3px; }
.ptitle .ext { font-size: 0.75em; color: var(--muted); margin-left: 4px; }
.pdate { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); }
.chip { font-family: var(--mono); font-size: 0.74rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1.5px solid currentColor; }
.chip.E { color: var(--easy); }
.chip.M { color: var(--medium); }
.chip.H { color: var(--hard); }
.group-title { margin: 18px 0 6px; font-size: 1rem; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.group-title:first-child { margin-top: 0; }
.group-title i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.empty-note { padding: 18px; background: var(--surface); border: 1px dashed var(--rule); border-radius: var(--radius); color: var(--muted); margin: 0; }

.foot { max-width: 1360px; margin: 0 auto; padding: 0 24px 32px; font-size: 0.8rem; color: var(--muted); }

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "map" "stops" "rail"; padding: 16px; }
  .rail { position: static; }
  .sign { padding: 12px 16px; }
  .brand-host { display: none; }
  .foot { padding: 0 16px 24px; }
}
@media (max-width: 520px) {
  .plist li { grid-template-columns: 28px minmax(0, 1fr) auto; padding: 10px 12px; }
  .pdate { display: none; }
  .service button { padding: 5px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
