:root {
  --bg: #ffffff;
  --fg: #1d1f23;
  --muted: #6b7078;
  --border: rgba(0, 0, 0, 0.12);
  --card: rgba(255, 255, 255, 0.94);
  --accent: #1f6feb;
  --warn-bg: #fff3c4;
  --warn-fg: #5a4300;
  --warn-border: #e0b400;
  --error: #c62828;
  --banner-h: 0px;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --fg: #e7e9ec;
    --muted: #9aa0a8;
    --border: rgba(255, 255, 255, 0.14);
    --card: rgba(30, 32, 36, 0.94);
    --accent: #58a6ff;
    --warn-bg: #4a3b00;
    --warn-fg: #ffe69a;
    --warn-border: #c79a00;
    --error: #ff7b72;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body { overflow: hidden; font-size: 14px; }
body.has-banner { --banner-h: 44px; }

#map { position: absolute; inset: var(--banner-h) 0 0 0; }
/* Train popups sit above the floating cards (z 10–11) but below the prototype banner (z 20). */
#map .maplibregl-popup { z-index: 15; }

.en, small { color: var(--muted); font-size: 0.78em; font-weight: normal; }

.proto-banner {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
  min-height: 44px; padding: 6px 16px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px 12px;
  background: var(--warn-bg); color: var(--warn-fg);
  border-bottom: 2px solid var(--warn-border);
  font-weight: 600; text-align: center;
}
.proto-banner[hidden] { display: none; }
.proto-banner .en { color: inherit; opacity: 0.85; }

.card {
  position: absolute; z-index: 10;
  background: var(--card); color: var(--fg);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  padding: 10px 12px;
  backdrop-filter: blur(6px);
}

/* Clock */
.left-col {
  position: absolute; z-index: 10; top: calc(var(--banner-h) + 10px); left: 10px; width: 270px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
}
.left-col .card { position: static; }
.left-col .card[hidden] { display: none; }
.clock { min-width: 230px; }
.clock .time { font-size: 1.6em; font-variant-numeric: tabular-nums; font-weight: 700; letter-spacing: 0.02em; }
.clock .meta { color: var(--muted); font-size: 0.85em; margin-bottom: 6px; }
.clock .modes, .clock .speeds { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0; }
.clock .sim { display: grid; gap: 4px; }
.clock .sim[hidden] { display: none; }
.clock .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.clock .sim-badge { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--accent); color: #fff; font-size: 0.75em; vertical-align: middle; }

button.seg, .clock input, .clock select {
  font: inherit; font-size: 0.9em; color: var(--fg);
  background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px;
}
button.seg { cursor: pointer; }
button.seg[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
button.seg[aria-pressed="true"] small { color: rgba(255, 255, 255, 0.85); }

/* Legend */
.legend { bottom: 30px; left: 10px; max-width: 300px; }
.legend h2, .panel h2 { font-size: 0.95em; margin: 0 0 6px; }
.legend ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.legend li { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; }
.legend .desc { display: block; color: var(--muted); font-size: 0.75em; line-height: 1.3; }
.legend .count { font-variant-numeric: tabular-nums; font-weight: 700; }
.legend .line-sample { display: flex; gap: 10px; margin-top: 8px; font-size: 0.8em; color: var(--muted); align-items: center; }

/* Panel */
.panel {
  top: calc(var(--banner-h) + 10px); right: 10px; bottom: 30px;
  width: 320px; overflow-y: auto;
}
.panel section + section { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
.panel h3 { font-size: 0.85em; margin: 8px 0 4px; color: var(--muted); }
.panel label.line { display: grid; grid-template-columns: auto 14px 1fr auto; gap: 6px; align-items: center; padding: 3px 0; cursor: pointer; }
.panel .swatch { width: 14px; height: 4px; border-radius: 2px; }
.panel .swatch.proto { background-image: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px) !important; opacity: 0.6; }
.panel .tcount { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.85em; }
.panel .kind-badge { font-size: 0.7em; padding: 0 4px; border-radius: 3px; border: 1px dashed var(--muted); color: var(--muted); margin-left: 4px; }
.panel details { margin: 4px 0; font-size: 0.85em; }
.panel details summary { cursor: pointer; }
.panel dl { margin: 4px 0 0 8px; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 8px; }
.panel dt { color: var(--muted); }
.panel dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.panel .error { color: var(--error); font-size: 0.85em; margin: 4px 0; word-break: break-word; }
.panel .status { color: var(--muted); font-size: 0.85em; }

.panel-toggle {
  display: none; position: absolute; z-index: 11;
  top: calc(var(--banner-h) + 10px); right: 10px;
  font: inherit; padding: 8px 12px; border-radius: 8px;
  background: var(--card); color: var(--fg); border: 1px solid var(--border); cursor: pointer;
}

@media (max-width: 700px) {
  body.has-banner { --banner-h: 64px; }
  .panel-toggle { display: block; }
  .panel { display: none; top: calc(var(--banner-h) + 56px); left: 10px; right: 10px; width: auto; }
  body.panel-open .panel { display: block; }
  .left-col { width: calc(100% - 110px); }
  .clock { min-width: 0; }
  .legend { max-width: calc(100% - 20px); bottom: 26px; }
  .legend .desc { display: none; }
}

/* Popup */
.maplibregl-popup-content { background: var(--card); color: var(--fg); border-radius: 8px; padding: 10px 12px; min-width: 220px; }
.maplibregl-popup-tip { border-top-color: var(--card) !important; border-bottom-color: var(--card) !important; }
.maplibregl-popup-close-button { color: var(--fg); font-size: 18px; }
.train-popup h3 { margin: 0 0 4px; font-size: 1em; display: flex; align-items: center; gap: 6px; }
.train-popup .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.train-popup dl { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 8px; font-size: 0.88em; }
.train-popup dt { color: var(--muted); }
.train-popup dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.train-popup .caveat { margin-top: 6px; padding: 4px 6px; border-radius: 4px; background: var(--warn-bg); color: var(--warn-fg); font-size: 0.82em; }
.train-popup .kind { font-weight: 700; }

.maplibregl-ctrl-attrib { background: var(--card) !important; color: var(--fg); }
/* One small line along the bottom edge; full credit text lives in the panel. */
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib {
  margin: 0 !important; padding: 1px 6px; border-radius: 4px 0 0 0;
  font-size: 10.5px; line-height: 1.6; opacity: 0.85;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: calc(100vw - 16px);
}
.maplibregl-ctrl-attrib a { color: var(--fg); }

.credits p { margin: 0 0 8px; font-size: 0.8em; line-height: 1.5; overflow-wrap: anywhere; }
.legend .line-sample.motion { flex-wrap: wrap; row-gap: 4px; }
.legend .line-sample.motion svg { flex: none; }

/* Explore card: rush-hour replay, running counter, delay board */
.rush-btn {
  width: 100%; font: inherit; font-weight: 700; cursor: pointer; padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
.rush-btn small { color: rgba(255, 255, 255, 0.85); }
.rush-note { font-size: 0.8em; color: var(--muted); margin-top: 4px; }
.rush-note[hidden] { display: none; }
.running { margin-top: 8px; }
.running-title { font-size: 0.9em; }
.running-title b { font-size: 1.3em; font-variant-numeric: tabular-nums; margin-left: 4px; }
.running ul { list-style: none; padding: 0; margin: 4px 0 0; display: grid; gap: 2px; font-size: 0.82em; }
.running li { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 4px; }
.running li b { font-variant-numeric: tabular-nums; }
.delays { margin-top: 8px; font-size: 0.88em; }
.delays summary { cursor: pointer; font-weight: 600; }
.delays .count { background: #d93025; color: #fff; border-radius: 9px; padding: 0 6px; font-size: 0.8em; }
.delays .count:empty { display: none; }
.delays table.stats { width: 100%; border-collapse: collapse; margin: 4px 0; }
.delays td { padding: 1px 2px; }
.delays td.num { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.late-list { list-style: none; padding: 0; margin: 4px 0 0; display: grid; gap: 2px; }
.late-list li { display: grid; grid-template-columns: 12px 1fr auto; gap: 4px; align-items: center; cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.late-list li:hover, .late-list li:focus { background: var(--border); outline: none; }
.meta { color: var(--muted); font-size: 0.85em; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.kindline { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0; }
.kind-chip { display: inline-flex; align-items: center; gap: 2px; font-size: 0.82em; font-weight: 600; }
.kind-chip svg { width: 16px; height: 16px; }
.delay { font-weight: 700; font-size: 0.85em; white-space: nowrap; }
.delay.ok { color: #188038; }
.delay.late { color: #d93025; }
@media (prefers-color-scheme: dark) { .delay.ok { color: #81c995; } .delay.late { color: #f28b82; } }
.src-badge { display: inline-block; font-size: 0.72em; padding: 0 4px; border-radius: 3px; margin-left: 4px; white-space: nowrap; border: 1px solid var(--border); }
.src-official { color: var(--fg); }
.src-live { border-color: #188038; color: #188038; }
.src-proto { border: 1px dashed var(--muted); color: var(--muted); }

/* Follow card */
.follow { font-size: 0.9em; border-color: var(--accent); }
.follow-head { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.follow-head button { margin-left: auto; }
.follow h4 { margin: 6px 0 2px; font-size: 0.85em; }
.stops { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
.stops li { display: flex; justify-content: space-between; gap: 6px; padding: 2px 0 2px 10px; border-left: 3px solid var(--border); }
.stops li.next { border-left-color: var(--accent); font-weight: 700; }
.stops .t, .board .t { font-variant-numeric: tabular-nums; }
.exp { color: #d93025; font-size: 0.85em; }
.follow-btn { margin-top: 6px; width: 100%; font: inherit; font-size: 0.9em; cursor: pointer; border-radius: 6px; padding: 4px; border: 1px solid var(--accent); background: transparent; color: var(--accent); }

/* Departure board popup */
.board-popup .maplibregl-popup-content { min-width: 300px; }
.board h3 { margin: 0 0 4px; font-size: 1em; }
.board table { width: 100%; border-collapse: collapse; font-size: 0.85em; }
.board th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); padding: 2px; }
.board td { padding: 3px 2px; border-bottom: 1px solid var(--border); vertical-align: top; }
.board td.t { font-weight: 700; font-size: 1.1em; }
.board tr.proto-row td { opacity: 0.75; font-style: italic; }
.board .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.line-chip { font-size: 0.75em; border-left: 4px solid var(--c); padding: 0 4px; background: var(--border); border-radius: 2px; }
.board .foot { margin: 6px 0 0; font-size: 0.75em; color: var(--muted); }
.proto-head { background: var(--warn-bg); color: var(--warn-fg); border: 1px dashed var(--warn-border); border-radius: 4px; padding: 3px 6px; font-weight: 700; font-size: 0.85em; margin-bottom: 4px; }

/* Sparklines in the line panel */
.panel .spark-row { grid-column: 2 / -1; display: flex; align-items: center; gap: 6px; }
.panel .spark-row:empty { display: none; }
.spark { color: var(--fg); flex: none; }
.spark-meta { font-size: 0.72em; color: var(--muted); }

.legend-details > summary { cursor: pointer; list-style: none; }
.legend-details > summary::-webkit-details-marker { display: none; }
.legend-details > summary h2 { display: inline; }
.legend-details > summary::after { content: " ▾"; color: var(--muted); }
.legend-details:not([open]) > summary::after { content: " ▸"; }
.legend-details[open] > summary { margin-bottom: 6px; }
.board-popup .maplibregl-popup-content { max-height: 55vh; overflow-y: auto; }

/* Always-visible note on what train positions are based on */
.basis-notice { margin: 2px 0 6px; padding: 4px 6px; border-left: 3px solid var(--accent); background: var(--border); border-radius: 4px; line-height: 1.35; }
.basis-notice .main { font-weight: 700; font-size: 0.9em; color: var(--fg); }
.basis-notice .sub { font-size: 0.78em; color: var(--fg); opacity: 0.85; }
.basis-notice .en { display: block; font-size: 0.7em; }
.basis-notice .sim-tag { display: inline-block; margin-right: 4px; padding: 0 5px; border-radius: 4px; background: var(--accent); color: #fff; font-size: 0.85em; }

/* Compact clock: one line; chevron expands to the full notice and controls */
.clock-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.clock-line .time { font-size: 1.6em; }
.clock.compact { padding: 6px 10px; min-width: 0; }
.clock.compact .time { font-size: 1.15em; }
.clock.compact .full-only, .clock:not(.compact) .compact-only { display: none; }
.clock:not(.is-sim) .sim-only { display: none; }
.clock-summary { font-size: 0.85em; color: var(--fg); white-space: nowrap; }
.clock-line .seg { padding: 1px 6px; }
.chevron { margin-left: auto; font: inherit; cursor: pointer; border: 1px solid var(--border); background: transparent; color: var(--fg); border-radius: 6px; padding: 0 8px; }
.basis-tag { font-size: 0.75em; font-weight: 700; padding: 1px 6px; border-radius: 4px; border-left: 3px solid var(--accent); background: var(--border); color: var(--fg); white-space: nowrap; cursor: help; }
.basis-tag .sim-tag { display: inline-block; margin-right: 3px; padding: 0 4px; border-radius: 3px; background: var(--accent); color: #fff; }
.left-col:has(.clock.compact) { width: auto; max-width: 360px; }

/* Explore card close button and collapsed pill */
.explore { position: relative; }
.left-col .explore { position: relative; }
.card-close { position: absolute; top: 4px; right: 4px; font: inherit; font-size: 0.85em; cursor: pointer; border: none; background: transparent; color: var(--muted); padding: 2px 6px; border-radius: 4px; }
.card-close:hover { background: var(--border); color: var(--fg); }
.rush-title { font-weight: 700; margin: 0 26px 6px 0; }
.rush-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.explore .rush-btn { width: 100%; padding: 6px 4px; line-height: 1.25; }
.rush-btn small { display: block; font-weight: 400; }
.rush-btn.active { outline: 2px solid var(--fg); outline-offset: 1px; }
.explore-pill { cursor: pointer; font: inherit; font-size: 0.85em; color: var(--fg); background: transparent; border: 1px solid var(--border); padding: 1px 8px; border-radius: 999px; display: inline-flex; gap: 4px; align-items: center; white-space: nowrap; }
.explore-pill.open { background: var(--accent); border-color: var(--accent); color: #fff; }
.clock-slot { display: inline-flex; }
.explore-pill b { font-variant-numeric: tabular-nums; }
.explore-pill .count { background: #d93025; color: #fff; border-radius: 9px; padding: 0 6px; font-size: 0.75em; }
.explore-pill .count:empty { display: none; }
.left-col .explore, .left-col .follow { width: 270px; max-width: 100%; }
@media (max-width: 700px) {
  .left-col, .left-col:has(.clock.compact) { width: auto; max-width: calc(100% - 110px); }
}

/* Real-timetables-only switch */
.panel .real-only { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: start; margin: 0 0 10px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.panel .real-only .desc { display: block; color: var(--muted); font-size: 0.75em; line-height: 1.3; }
.panel [data-lines].hide-proto .is-proto { display: none; }

/* Tip jar link in the About section (site.config.json tip.url) */
.tip-btn { display: inline-block; padding: 6px 12px; border-radius: 999px; background: #e8547a; color: #fff !important; font-weight: 700; text-decoration: none; }
.tip-btn:hover { filter: brightness(1.08); }
