:root {
  --bg: #f6f6f3;
  --fg: #1b1c1e;
  --muted: #5f6166;
  --rule: #d9dad6;
  --panel: #ffffff;
  --sea: #eef1f3;
  --land: #d8d9d3;
  --coast: #c4c6bf;
  --us: #2a78d6;          /* navy slot 1 */
  --cn: #c8302f;          /* navy slot 2 */
  --uk: #4a3aa7; --fr: #1baf7a; --jp: #e87ba4; --in: #eda100; /* slots 3-6: also told apart by flag and label */
  --inactive: #8d8f93;
  --gap: #b0503a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141517; --fg: #ecedee; --muted: #a2a5ab; --rule: #2f3134; --panel: #1b1c1f;
    --sea: #171a1e; --land: #2c2e31; --coast: #3a3d41; --us: #3987e5; --cn: #e5484d; --uk: #a35fd6; --fr: #199e70; --jp: #f09ac8; --in: #c98500; --inactive: #7b7e84; --gap: #e0846c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141517; --fg: #ecedee; --muted: #a2a5ab; --rule: #2f3134; --panel: #1b1c1f;
  --sea: #171a1e; --land: #2c2e31; --coast: #3a3d41; --us: #3987e5; --cn: #e5484d; --uk: #a35fd6; --fr: #199e70; --jp: #f09ac8; --in: #c98500; --inactive: #7b7e84; --gap: #e0846c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0 auto;
  max-width: 1400px;
  padding: 24px 16px 48px;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1 { font: 600 2rem/1.1 ui-serif, Georgia, serif; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 8px; }
.lede { margin: 0 0 16px; color: var(--muted); max-width: 60ch; }
a { color: var(--us); }
button, select { font: inherit; color: var(--fg); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--us); outline-offset: 1px; }

/* ---------- time controls ---------- */
.controls {
  display: grid; grid-template-columns: auto auto auto auto 1fr auto auto; align-items: center; gap: 8px 10px;
  position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 8px 0 4px; margin-bottom: 8px;
}
.controls > button {
  width: 34px; height: 34px; border: 1px solid var(--rule); border-radius: 6px; background: var(--panel); cursor: pointer;
}
.controls .play { width: 42px; }
.controls .date { font: 600 1.25rem/1 ui-sans-serif, system-ui, sans-serif; font-variant-numeric: tabular-nums; min-width: 9.5ch; text-align: center; }
.controls label { font-size: 0.85rem; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.controls .speed { grid-column: 6; }
.controls select { background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: 4px 6px; }
.controls .toggles { grid-column: 7; display: flex; gap: 12px; }
.range { grid-column: 1 / -1; justify-self: start; display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; background: var(--panel); }
.range button { border: 0; background: none; padding: 4px 10px; font-size: 0.8rem; cursor: pointer; }
.range button + button { border-left: 1px solid var(--rule); }
.range button[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
.slider { grid-column: 1 / -1; position: relative; padding-bottom: 16px; }
.slider input { width: 100%; margin: 0; accent-color: var(--us); }
.ticks { position: absolute; left: 8px; right: 8px; bottom: 0; height: 14px; font-size: 0.7rem; color: var(--muted); }
.ticks span { position: absolute; transform: translateX(-50%); font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 700px) {
  .controls { grid-template-columns: auto auto 1fr auto; }
  .controls .speed, .controls .toggles { grid-column: auto; }
}

/* ---------- layout ---------- */
main { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
@media (max-width: 960px) { main { grid-template-columns: 1fr; } }

/* ---------- map ---------- */
.map { margin: 0; position: relative; }
.map > svg { width: 100%; height: auto; display: block; background: var(--sea); border-radius: 8px; cursor: grab; touch-action: none; }
.map > svg:active { cursor: grabbing; }
.zoom { position: absolute; top: 8px; right: 8px; display: flex; flex-direction: column; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; background: var(--panel); z-index: 1; }
.zoom button { font-size: 1rem; line-height: 1; width: 30px; height: 30px; border: 0; border-bottom: 1px solid var(--rule); background: none; cursor: pointer; }
.zoom button:last-child { border-bottom: 0; }
.zoom button:hover { background: var(--rule); }

.land { fill: var(--land); stroke: var(--coast); stroke-width: 0.5; vector-effect: non-scaling-stroke; }
.graticule { fill: none; stroke: var(--rule); stroke-width: 0.5; vector-effect: non-scaling-stroke; opacity: 0.6; }
.halo { fill: var(--us); fill-opacity: 0.07; stroke: var(--us); stroke-opacity: 0.35; stroke-width: 0.75; stroke-dasharray: 2 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.trail { fill: none; stroke: var(--us); stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.track { fill: none; stroke: var(--us); stroke-width: 2; stroke-linecap: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.track.future { stroke-opacity: 0.35; stroke-dasharray: 1 4; }
.navy-CN.trail, .navy-CN.track, .trail-key.navy-CN { stroke: var(--cn); }
.navy-UK.trail, .navy-UK.track, .trail-key.navy-UK, .arrow.navy-UK { stroke: var(--uk); }
.navy-FR.trail, .navy-FR.track, .trail-key.navy-FR, .arrow.navy-FR { stroke: var(--fr); }
.navy-JP.trail, .navy-JP.track, .trail-key.navy-JP, .arrow.navy-JP { stroke: var(--jp); }
.navy-IN.trail, .navy-IN.track, .trail-key.navy-IN, .arrow.navy-IN { stroke: var(--in); }
.trail.hl { stroke-opacity: 0.95; stroke-width: 2.6px; }
.trail.faded { stroke-opacity: 0.06; }
.arrow { fill: none; stroke: var(--us); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.arrow.navy-CN { stroke: var(--cn); }
.trail-hit { fill: none; stroke: transparent; stroke-width: 12px; stroke-linecap: round; vector-effect: non-scaling-stroke; pointer-events: stroke; cursor: pointer; }
.navy-CN.halo { fill: var(--cn); stroke: var(--cn); }
.navy-UK.halo { fill: var(--uk); stroke: var(--uk); }
.navy-FR.halo { fill: var(--fr); stroke: var(--fr); }
.navy-JP.halo { fill: var(--jp); stroke: var(--jp); }
.navy-IN.halo { fill: var(--in); stroke: var(--in); }
.track.gap, .trail.gap { stroke: var(--gap); stroke-dasharray: 4 4; stroke-opacity: 0.8; }

/* markers: a navy's flag; its size and saturation say what the ship is doing */
.ship { cursor: pointer; }
.ship .hit { fill: transparent; }
.ship .ring { fill: none; stroke: none; }
.ship.sel .ring { stroke: var(--fg); stroke-width: 1.5; }
.tier-port .flag { opacity: 0.75; }
.tier-yard .flag { filter: grayscale(1); opacity: 0.7; }
.tier-inactive .flag { filter: grayscale(1); opacity: 0.4; }
.ship text { font: 600 10px ui-sans-serif, system-ui, sans-serif; fill: var(--fg); paint-order: stroke; stroke: var(--sea); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.ship:not(.tier-underway) text { font-size: 9px; font-weight: 500; fill: var(--muted); }
.ship.sel text { font-size: 12px; fill: var(--fg); }
.ship.dim { opacity: 0.35; }
.halo-key { fill: var(--us); fill-opacity: 0.07; stroke: var(--us); stroke-opacity: 0.5; stroke-dasharray: 2 2; }
.gap-key { stroke: var(--gap); stroke-width: 2; stroke-dasharray: 4 3; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; font-size: 0.78rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .tier-yard, .legend .tier-inactive { filter: grayscale(1); }
.legend .tier-port { opacity: 0.75; }
.legend .tier-yard { opacity: 0.7; }
.legend .tier-inactive { opacity: 0.4; }
.trail-key { stroke: var(--us); stroke-width: 2; }

/* ---------- side panel ---------- */
.panel { background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 12px 14px; max-height: 78vh; overflow: auto; }
.ships { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; }
.offscreen { margin: 10px 6px 0; font-size: 0.78rem; color: var(--muted); }
.offscreen button { border: 0; background: none; padding: 0; color: var(--us); cursor: pointer; font: inherit; }
.ships li { display: grid; grid-template-columns: calc(4.6em + 22px) 1fr; gap: 0 8px; padding: 6px 6px; border-radius: 6px; cursor: pointer; }
.ships li:hover, .ships li.hl { background: var(--bg); }
.ships .tier-head { display: block; cursor: default; padding: 10px 6px 2px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.ships .tier-head:first-child { padding-top: 0; }
.ships .tier-head:hover { background: none; }
.ships li.tier-port, .ships li.tier-yard { opacity: 0.85; }
.ships li.tier-inactive { opacity: 0.6; }
.ships .flag-icon { margin-right: 6px; vertical-align: -1px; border-radius: 1px; }
.ships .hull { white-space: nowrap; font-weight: 600; font-variant-numeric: tabular-nums; }
.ships .name { font-weight: 600; }
.ships .where { grid-column: 2; color: var(--muted); }
.ships .what { grid-column: 2; color: var(--muted); font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.state { display: inline-block; font-size: 0.7rem; padding: 0 5px; border-radius: 3px; border: 1px solid var(--rule); margin-left: 4px; color: var(--muted); }

.log .back { border: 0; background: none; color: var(--us); padding: 0; cursor: pointer; margin-bottom: 8px; }
.ship-photo { margin: 0 0 10px; }
.ship-photo img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; background: var(--rule); }
.ship-photo figcaption { font-size: 0.7rem; margin-top: 3px; }
.ship-photo figcaption a { color: var(--muted); }
.ship-about { font-size: 0.82rem; color: var(--muted); margin: 0 0 10px; }
.ship-about .wiki { white-space: nowrap; }
.log-title { font: 600 1.1rem/1.2 ui-serif, Georgia, serif; text-transform: none; letter-spacing: 0; color: var(--fg); }
.entries { list-style: none; margin: 0; padding: 0; font-size: 0.82rem; }
.entries li { display: grid; grid-template-columns: 6.5em 1fr; gap: 0 8px; padding: 4px 4px; border-radius: 4px; cursor: pointer; }
.entries li:hover { background: var(--bg); }
.entries .src { display: block; font-size: 0.72rem; color: var(--muted); }
.entries li.now { background: var(--bg); box-shadow: inset 3px 0 0 var(--us); }
.entries time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.75rem; padding-top: 1px; }
.entries .place { color: var(--muted); font-size: 0.75rem; }
.entries .unplaced { font-style: italic; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 10; max-width: 320px;
  background: var(--panel); color: var(--fg); border: 1px solid var(--rule); border-radius: 6px;
  padding: 8px 10px; font-size: 0.8rem; box-shadow: 0 4px 16px rgb(0 0 0 / 0.15);
}
.tooltip b { display: block; font-size: 0.95rem; }
.tooltip .where { font-weight: 600; margin-top: 2px; }
.tooltip .note { color: var(--muted); margin-top: 4px; }

footer { margin-top: 32px; border-top: 1px solid var(--rule); padding-top: 16px; font-size: 0.85rem; color: var(--muted); }
footer ul { padding-left: 18px; max-width: 90ch; }
footer li { margin-bottom: 6px; }
footer strong { color: var(--fg); }
