:root {
  color-scheme: light;
  --paper: #f5f7f8;
  --paper-2: #ffffff;
  --ink: #14263b;
  --ink-2: #3c4f63;
  --muted: #627284;
  --rule: #d6dee5;
  --pen: #2a46a0;           /* ballpoint blue of the paper log */
  --day: #dfeaf2;           /* strip: daylight */
  --night: #1a2c46;         /* strip + route casing: dark */
  --rail: #e1e8ee;          /* strip: the track between passages */
  --critical: #c42b2b;
  --focus: #2a78d6;
  --font-ui: "IBM Plex Sans Condensed", "Arial Narrow", system-ui, sans-serif;
  --font-text: "Literata", Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #0f1a26;
    --paper-2: #152332;
    --ink: #e5ecf3;
    --ink-2: #bccad8;
    --muted: #8fa0b2;
    --rule: #263a4e;
    --pen: #a9bcff;
    --day: #2a3f55;
    --night: #070e18;
    --rail: #1b2a3a;
    --critical: #ef6b62;
    --focus: #6aa6ef;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0f1a26;
  --paper-2: #152332;
  --ink: #e5ecf3;
  --ink-2: #bccad8;
  --muted: #8fa0b2;
  --rule: #263a4e;
  --pen: #a9bcff;
  --day: #2a3f55;
  --night: #070e18;
  --rail: #1b2a3a;
  --critical: #ef6b62;
  --focus: #6aa6ef;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.45 var(--font-ui);
  font-variant-numeric: tabular-nums;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100dvh;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- map ---------- */
#map { grid-column: 1; grid-row: 1; position: relative; background: #b9d3e6; }
.leaflet-container { font: 13px/1.35 var(--font-ui); }
.map-title { display: none; }
.leaflet-control-attribution { font-size: 10px; }
.leaflet-control-layers, .leaflet-bar a { color: #14263b; }
.leaflet-control-layers-expanded { font: 13px/1.5 var(--font-ui); }

.route-dim { opacity: .28; }
.port-label, .inc-label {
  background: rgba(255,255,255,.92); border: 0; border-radius: 4px; box-shadow: 0 1px 2px rgba(20,38,59,.25);
  color: #14263b; font: 500 12px/1.2 var(--font-ui); padding: 2px 6px;
}
.port-label::before, .inc-label::before { display: none; }
.inc-label { color: #8f1717; font-weight: 600; }
.no-labels .port-label, .no-labels .inc-label { display: none; }
.port-icon svg { display: block; filter: drop-shadow(0 1px 1px rgba(20,38,59,.4)); }
.inc-icon {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: #c42b2b; color: #fff; font: 700 14px/1 var(--font-ui); border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(20,38,59,.45);
}
.boat-icon svg { display: block; transition: transform .15s linear; filter: drop-shadow(0 1px 2px rgba(0,0,0,.45)); }
.entry-tip { font: 500 12px/1.2 var(--font-ui); }

/* legend */
.legend {
  background: rgba(255,255,255,.94); color: #14263b; border-radius: 6px; padding: 8px 10px; box-shadow: 0 1px 4px rgba(20,38,59,.3);
  font: 12px/1.35 var(--font-ui); max-width: 230px;
}
.legend summary { cursor: pointer; font-weight: 600; list-style: none; }
.legend summary::-webkit-details-marker { display: none; }
.legend summary::after { content: " +"; color: #627284; }
.legend[open] summary::after { content: " −"; }
.legend ul { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 3px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend .sw { flex: none; width: 30px; height: 10px; display: block; }
.legend .modes { display: flex; gap: 4px; margin-top: 6px; }
.legend .modes button {
  border: 1px solid #c3cfd9; background: #fff; border-radius: 4px; padding: 2px 8px; cursor: pointer; font-size: 12px;
}
.legend .modes button[aria-pressed="true"] { background: #14263b; color: #fff; border-color: #14263b; }

/* detail card over the map */
.detail {
  position: absolute; z-index: 1001; left: 12px; bottom: 12px; width: 340px; max-height: calc(100% - 24px); overflow: auto;
  background: var(--paper-2); color: var(--ink); border-radius: 8px; box-shadow: 0 4px 18px rgba(20,38,59,.28);
  padding: 14px 16px 14px;
}
.detail-close {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border: 0; background: transparent; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--muted); border-radius: 6px;
}
.detail-close:hover { background: var(--rule); }
.detail h3 { margin: 0 34px 2px 0; font: 600 17px/1.3 var(--font-text); }
.detail .when { color: var(--muted); margin: 0 0 8px; }
.detail table { border-collapse: collapse; width: 100%; margin: 6px 0 4px; }
.detail th { text-align: left; font-weight: 400; color: var(--muted); padding: 3px 10px 3px 0; white-space: nowrap; vertical-align: top; width: 1%; }
.detail td { padding: 3px 0; border-bottom: 1px solid var(--rule); }
.detail tr:last-child td { border-bottom: 0; }
.unsure { color: var(--muted); font-size: 12px; white-space: nowrap; }
.pen { font: italic 400 15.5px/1.45 var(--font-text); color: var(--pen); margin: 8px 0 4px; }
.fine { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-weight: 600; white-space: nowrap;
}
.chip i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.chip .names { font-weight: 400; color: var(--ink-2); }

/* ---------- timeline ---------- */
#timeline {
  grid-column: 1; grid-row: 2; background: var(--paper); border-top: 1px solid var(--rule);
  padding: 8px 12px 10px; min-width: 0;
}
.tl-head { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.play {
  flex: none; width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--ink); color: var(--paper);
  display: grid; place-items: center; cursor: pointer;
}
.play svg { width: 16px; height: 16px; fill: currentColor; }
.play .i-pause { display: none; }
.play[aria-pressed="true"] .i-play { display: none; }
.play[aria-pressed="true"] .i-pause { display: inline; }
.readout { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 14px; row-gap: 2px; min-width: 0; }
.readout .t { font-weight: 600; font-size: 16px; }
.readout .muted { color: var(--muted); }
.readout .moon { color: var(--ink-2); }
.tl-scroll { overflow-x: auto; overflow-y: hidden; margin-top: 6px; scrollbar-width: thin; }
.strip { position: relative; touch-action: pan-x; cursor: pointer; outline-offset: 3px; }
.strip svg { display: block; }
.strip text { font: 500 11px var(--font-ui); fill: var(--muted); }
.strip .wl { font: 600 12px var(--font-text); pointer-events: none; }
.tl { font-family: var(--font-text); font-weight: 600; }
.strip .cursor-line { stroke: var(--ink); stroke-width: 2; }
.strip .cursor-knob { fill: var(--ink); stroke: var(--paper); stroke-width: 2; }
.strip .sel { fill: none; stroke: var(--ink); stroke-width: 1.5; }

/* ---------- panel ---------- */
#panel {
  grid-column: 2; grid-row: 1 / span 2; overflow-y: auto; border-left: 1px solid var(--rule);
  background: var(--paper);
}
.head { padding: 22px 22px 10px; }
.head-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
h1 { font: 600 34px/1.1 var(--font-text); margin: 0; letter-spacing: -.01em; }
.grow { display: none; }
.sub { margin: 4px 0 0; font: 400 17px/1.35 var(--font-text); color: var(--ink-2); }
.routeline { margin: 10px 0 0; color: var(--ink-2); }
.totals {
  display: grid; grid-template-columns: repeat(4, auto); justify-content: start; column-gap: 22px; row-gap: 0;
  margin: 18px 0 0; padding: 12px 0 0; border-top: 1px solid var(--rule);
}
.totals div { display: flex; flex-direction: column-reverse; }
.totals dt { color: var(--muted); font-size: 13px; line-height: 1.25; }
.totals dd { margin: 0; font: 600 24px/1.15 var(--font-text); }
.note { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

.tabs {
  position: sticky; top: 0; z-index: 2; display: flex; gap: 2px; padding: 0 16px; background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.tabs button {
  border: 0; background: none; padding: 10px 8px 9px; cursor: pointer; color: var(--muted); font-weight: 500; font-size: 15px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.pane { padding: 6px 22px 28px; }

/* passages */
.plist { list-style: none; margin: 0; padding: 0; counter-reset: p; }
.plist li { border-bottom: 1px solid var(--rule); }
.prow {
  display: grid; grid-template-columns: 28px 1fr; column-gap: 8px; width: 100%; text-align: left; background: none; border: 0;
  padding: 14px 0 13px; cursor: pointer;
}
.prow .n { font: 600 20px/1.2 var(--font-text); color: var(--muted); }
.prow[aria-pressed="true"] .n { color: var(--ink); }
.prow h3 { margin: 0; font: 600 18px/1.3 var(--font-text); }
.prow .when { color: var(--muted); margin-top: 1px; }
.pstats { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 6px; }
.pstats span b { font-weight: 600; font-size: 16px; }
.pstats span { color: var(--ink-2); }
.flag { margin-top: 6px; color: var(--muted); font-size: 13px; }
.flag.warn { color: var(--critical); }
.prow[aria-pressed="true"] { box-shadow: inset 3px 0 0 var(--ink); padding-left: 10px; margin-left: -10px; width: calc(100% + 10px); }

/* log */
.day { margin: 18px 0 4px; font: 600 16px/1.3 var(--font-text); }
.day small { font: 400 13px var(--font-ui); color: var(--muted); margin-left: 6px; }
.erow {
  display: grid; grid-template-columns: 52px 1fr; column-gap: 10px; width: 100%; text-align: left; background: none; border: 0;
  border-top: 1px solid var(--rule); padding: 9px 0; cursor: pointer;
}
.erow .tm { font-weight: 600; font-size: 16px; }
.erow .data { color: var(--ink-2); }
.erow .pen { margin: 3px 0 0; font-size: 15px; }
.erow[aria-pressed="true"] { background: color-mix(in srgb, var(--focus) 9%, transparent); }

/* crew */
.ctable { width: 100%; border-collapse: collapse; margin-top: 10px; }
.ctable th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--rule); }
.ctable td { padding: 9px 8px 9px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.ctable td.num, .ctable th.num { text-align: right; padding-right: 0; }
.ctable .who { font: 600 16px/1.3 var(--font-text); }
.teams-cell { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.pane h4 { font: 600 16px/1.3 var(--font-text); margin: 22px 0 4px; }
.pane p { margin: 6px 0; }

/* events */
.vrow {
  display: grid; grid-template-columns: 22px 1fr; column-gap: 10px; width: 100%; text-align: left; background: none; border: 0;
  border-top: 1px solid var(--rule); padding: 11px 0; cursor: pointer;
}
.vrow .mark { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font: 700 12px/1 var(--font-ui); margin-top: 2px; }
.vrow .mark.inc { background: var(--critical); color: #fff; }
.vrow .mark.evt { border: 2px solid var(--muted); }
.vrow h3 { margin: 0; font: 600 16px/1.3 var(--font-text); }
.vrow .when { color: var(--muted); font-size: 13px; }
.vrow p { margin: 3px 0 0; color: var(--ink-2); }

/* ---------- small screens ---------- */
@media (max-width: 899px) {
  body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 46dvh auto minmax(0, 1fr);
  }
  body.tall { grid-template-rows: 26dvh auto minmax(0, 1fr); }
  #map { grid-column: 1; grid-row: 1; }
  #timeline { grid-column: 1; grid-row: 2; padding: 6px 10px 8px; }
  #panel { grid-column: 1; grid-row: 3; border-left: 0; border-top: 1px solid var(--rule); }
  .map-title {
    display: flex; flex-direction: column; position: absolute; z-index: 800; top: 10px; left: 10px;
    background: rgba(255,255,255,.92); color: #14263b; border-radius: 6px; padding: 5px 9px; box-shadow: 0 1px 3px rgba(20,38,59,.3);
    font: 12px/1.25 var(--font-ui); pointer-events: none;
  }
  .map-title b { font: 600 15px/1.2 var(--font-text); }
  .head { padding: 14px 16px 8px; }
  h1 { font-size: 26px; }
  .sub { font-size: 15px; }
  .grow {
    display: inline-block; border: 1px solid var(--rule); background: var(--paper-2); border-radius: 6px; padding: 4px 10px;
    font-size: 13px; cursor: pointer; white-space: nowrap;
  }
  .totals { grid-template-columns: repeat(2, auto); row-gap: 10px; margin-top: 12px; }
  .totals dd { font-size: 21px; }
  .tabs { padding: 0 8px; overflow-x: auto; }
  .tabs button { padding: 10px 8px 9px; }
  .pane { padding: 4px 16px 28px; }
  .detail { left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 56%; padding: 12px 14px; }
  .detail h3 { font-size: 16px; }
  .detail th, .detail td { padding-top: 2px; padding-bottom: 2px; }
  .pen { font-size: 15px; }
  .readout .t { font-size: 15px; }
  .legend { max-width: 190px; padding: 6px 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .boat-icon svg { transition: none; }
}

/* wind from the log */
.wind-icon { background: none; border: 0; }
.wind { position: relative; width: 72px; height: 72px; pointer-events: none; }
.wind svg { display: block; }
.wind span {
  position: absolute; white-space: nowrap; pointer-events: auto;
  background: rgba(255,255,255,.9); color: #14263b; border-radius: 4px; padding: 0 4px;
  font: 500 11.5px/1.35 var(--font-ui); box-shadow: 0 1px 2px rgba(20,38,59,.2);
}
.wind, .wind * { pointer-events: none !important; }
.no-labels .wind span { display: none; }

/* dividers */
.tool-btn { display: grid !important; place-items: center; color: #14263b; }
.tool-btn[aria-pressed="true"] { background: #b01d8a !important; color: #fff !important; }
.measuring .leaflet-grab, .measuring .leaflet-interactive { cursor: crosshair; }
.measuring .leaflet-marker-icon, .measuring path.leaflet-interactive { pointer-events: none; }
.measure-box {
  position: absolute; z-index: 1002; top: 10px; left: 50%; transform: translateX(-50%); width: min(420px, calc(100% - 140px));
  background: rgba(255,255,255,.96); color: #14263b; border-radius: 8px; box-shadow: 0 2px 10px rgba(20,38,59,.3);
  padding: 8px 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font: 14px/1.35 var(--font-ui);
}
.measure-box .mb-text { flex: 1 1 180px; }
.measure-box b { font: 600 17px/1.2 var(--font-text); }
.measure-box .mb-actions { display: flex; gap: 6px; }
.measure-box button {
  border: 1px solid #c3cfd9; background: #fff; color: #14263b; border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 13px;
}
.measure-box button[data-act="done"] { background: #14263b; color: #fff; border-color: #14263b; }
.measure-box button:disabled { opacity: .45; cursor: default; }
.measure-label {
  background: #b01d8a; color: #fff; border: 0; border-radius: 4px; padding: 1px 6px; box-shadow: none;
  font: 600 12px/1.3 var(--font-ui); white-space: nowrap;
}
.measure-label::before { display: none; }
@media (max-width: 899px) {
  .measure-box { left: 8px; right: 56px; transform: none; width: auto; top: 8px; }
  .measuring .map-title { display: none; }
}
.measure-box[hidden] { display: none; }
.measuring .leaflet-pane > svg path.leaflet-interactive { pointer-events: none; }

.mb-hint { color: #627284; font-size: 12px; margin-top: 3px; }
.pin-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; max-height: 120px; overflow: auto; }
.pin-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 500; }
.measure-box .pin-x { border: 0; background: none; font-size: 18px; line-height: 1; padding: 0 6px; color: #627284; }
.pin-label {
  background: #fff; color: #14263b; border: 1.5px solid #b01d8a; border-radius: 4px; padding: 1px 6px; box-shadow: 0 1px 2px rgba(20,38,59,.25);
  font: 600 12px/1.3 var(--font-ui); white-space: nowrap;
}
.pin-label::before { display: none; }
/* text in the card and the tool box can be selected and copied */
.detail, .measure-box { cursor: auto; -webkit-user-select: text; user-select: text; }
.detail button, .measure-box button { cursor: pointer; }
.measure-box { padding-right: 38px; }
.measure-box .mb-close {
  position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border: 0; background: none; border-radius: 6px;
  font-size: 20px; line-height: 1; color: #627284; padding: 0;
}
.measure-box .mb-close:hover { background: #e7edf2; }
.measure-box .pin-x { font-size: 12px; color: #8f1717; text-decoration: underline; padding: 0 2px; }

/* bearings */
.bearing-label {
  background: #fff; color: #8a1670; border: 1px solid #b01d8a; border-radius: 4px; padding: 0 5px; box-shadow: none;
  font: 600 11.5px/1.35 var(--font-ui); white-space: nowrap;
}
.bearing-label::before, .light-label::before { display: none; }
.no-labels .bearing-label, .no-labels .light-label { display: none; }

/* timeline as a scrubber: one track, a grab handle and a time bubble */
.tl-scroll { overflow: hidden; }
.strip { cursor: grab; touch-action: none; -webkit-user-select: none; user-select: none; }
.strip.dragging { cursor: grabbing; }
.strip .rail { fill: var(--rail); }
.strip .gap text { fill: var(--muted); font-size: 13px; }
.strip .bubble rect, .strip .bubble path { fill: var(--ink); }
.strip .bubble text { fill: var(--paper); font: 600 12px var(--font-ui); }
.strip .cursor-line { stroke: var(--ink); stroke-width: 2; }
.strip .cursor-knob { fill: var(--paper-2); stroke: var(--ink); stroke-width: 2.5; filter: drop-shadow(0 1px 2px rgba(20,38,59,.35)); }
.strip .cursor-grip { stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; }
.strip #ghost line { stroke: var(--ink); stroke-opacity: .45; stroke-dasharray: 2 2; }
.strip #ghost text { fill: var(--ink-2); font-weight: 600; }
