:root {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --ink: #1b1d22;
  --muted: #6a6f78;
  --line: #e2ded4;
  --navy: #0f2a4a;
  --accent: #e8402f;
  --course: #e8402f;
  --good: #1f8a4c;
  --warn: #b7791f;
  --chip-border: rgba(0, 0, 0, .35);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418; --surface: #1a1e24; --ink: #eef0f3; --muted: #9aa1ab; --line: #2a3038;
    --navy: #0b1e35; --chip-border: rgba(255, 255, 255, .55); color-scheme: dark;
  }
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }
}
:root[data-theme="dark"] {
  --bg: #111418; --surface: #1a1e24; --ink: #eef0f3; --muted: #9aa1ab; --line: #2a3038;
  --navy: #0b1e35; --chip-border: rgba(255, 255, 255, .55); color-scheme: dark;
}
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-weight: 500; -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; min-height: 100dvh;
}
button { font: inherit; color: inherit; cursor: pointer; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--navy); color: #fff;
}
.brand { min-width: 0; }
.top h1 { margin: 0; font-size: 1.2rem; font-weight: 900; letter-spacing: .04em; white-space: nowrap; }
.top h1 span { background: var(--accent); padding: 1px 8px; border-radius: 4px; margin-left: 4px; font-size: .9rem; vertical-align: 2px; }
.top p { margin: 2px 0 0; font-size: .75rem; opacity: .75; }
.clock { display: flex; align-items: center; gap: 12px; text-align: right; }
.clock small { display: block; font-size: .65rem; opacity: .7; }
.clock b { font-size: 1.6rem; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.pill { font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: rgba(255, 255, 255, .15); white-space: nowrap; }
.pill.live { background: var(--accent); }
.pill.live::before { content: "●"; margin-right: 4px; animation: blink 1.4s infinite; }
.pill.demo { background: #f5c518; color: #222; }
@keyframes blink { 50% { opacity: .2; } }

.layout { flex: 1; display: grid; grid-template-columns: 1fr 400px; min-height: 0; }
.mapwrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--bg); }
.mapbtn {
  position: absolute; right: 12px; bottom: 24px; z-index: 500;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; font-size: .8rem; font-weight: 700; box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
.panel { background: var(--surface); border-left: 1px solid var(--line); overflow-y: auto; padding: 14px 16px 24px; }
.panel h2 { font-size: .8rem; color: var(--muted); letter-spacing: .1em; margin: 4px 0 8px; }

.demo { background: #fff6d6; color: #4a3b00; border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; font-size: .8rem; }
.demo p { margin: 0 0 8px; }
.speeds { display: flex; gap: 6px; flex-wrap: wrap; }
.speeds button { border: 1px solid #d9c46b; background: #fff; border-radius: 6px; padding: 4px 10px; font-size: .78rem; }
.speeds button.on { background: #4a3b00; color: #fff; border-color: #4a3b00; }

.standings { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 10px;
  padding: 10px 6px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 8px;
}
.row:hover, .row.sel { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.rank { font-size: 1.35rem; font-weight: 900; text-align: center; font-variant-numeric: tabular-nums; }
.who { min-width: 0; }
.name { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: .98rem; }
.chip {
  flex: none; width: 22px; height: 22px; border-radius: 5px; display: grid; place-items: center;
  font-size: .72rem; font-weight: 900; border: 1.5px solid var(--chip-border);
}
.cls { font-size: .62rem; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.where { font-size: .76rem; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.where b { color: var(--ink); font-weight: 700; }
.bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 2px; }
.gap { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; font-size: .95rem; white-space: nowrap; }
.gap small { display: block; font-size: .68rem; color: var(--muted); font-weight: 500; }
.gap.lead { color: var(--accent); }
.gap.fin { color: var(--good); }
.stale .where::after { content: " ・電波待ち"; color: var(--warn); }
.empty { color: var(--muted); font-size: .85rem; }

.legs { margin-top: 18px; font-size: .8rem; }
.legs summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.legs table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.legs th, .legs td { text-align: left; padding: 5px 4px; border-bottom: 1px solid var(--line); }
.legs th { color: var(--muted); font-weight: 500; font-size: .7rem; }
.legs td:nth-child(4), .legs td:nth-child(5) { font-variant-numeric: tabular-nums; white-space: nowrap; }
.legs tr.now td { background: color-mix(in srgb, var(--accent) 10%, transparent); font-weight: 700; }
.note { font-size: .7rem; color: var(--muted); margin-top: 16px; line-height: 1.6; }

/* 地図上のマーカー */
.tm {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font: 900 13px/1 "Zen Kaku Gothic New", sans-serif; border: 2px solid #1b1d22;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .45); transition: transform .2s;
}
.tm.sel { transform: scale(1.35); }
.tm.stale { opacity: .5; }
.relay {
  background: #fff; border: 2px solid var(--navy); color: var(--navy); border-radius: 4px;
  font: 700 10px/1 "Zen Kaku Gothic New", sans-serif; padding: 3px 4px; white-space: nowrap;
  transform: translate(-50%, -50%); position: absolute; left: 0; top: 0;
}
.relay.goal { background: var(--navy); color: #fff; }
.leaflet-container { font-family: inherit; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 46dvh auto; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .clock { gap: 8px; }
  .clock b { font-size: 1.2rem; }
  .top h1 { font-size: 1rem; }
  .top h1 span { font-size: .75rem; padding: 1px 6px; }
  .top p { font-size: .68rem; }
}
