:root {
  --ink: #1f2c36; --soft: #5d6d79; --line: #d5dde3; --line2: #e9eef2; --bg: #ffffff;
  --accent: #1f5f86; --magenta: #b0127a; --err: #b42318; --warn: #b54708;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --row: 44px;          /* menu rows and targets: 44 px for fingers, 36 px with a mouse */
  --rail: 60px;         /* width of the control column on the right */
  --status-h: 36px;     /* height of the bottom row (credits, scale), kept current by app.js */
  --shadow: 0 1px 4px rgba(20, 30, 40, .14);
}
@media (pointer: fine) { :root { --row: 36px; } }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 13px/1.4 var(--font); color: var(--ink); background: #f1ebdc; overflow: hidden; }
#map { position: absolute; inset: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
svg { flex: none; }

/* Layout: the map's edges hold what you read (legends, credits and the scale at the bottom);
   the right edge holds what you use (Layers, Measure, Link, PNG; zoom and compass lower down).
   The panel opens to the left of that column, so its buttons never move. */
.rail, .zoom, .panel, .mbar { position: absolute; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }

/* ---- right column ---- */
.rail { z-index: 6; top: 10px; right: 10px; width: var(--rail); display: flex; flex-direction: column; padding: 2px; gap: 2px; }
.rail button, .zoom button {
  position: relative; border: 0; background: none; border-radius: 6px; color: var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.rail button { height: 54px; font-size: 11px; }
.rail button:hover, .zoom button:hover { background: var(--line2); }
.rail button[aria-expanded="true"] { background: #e3edf4; color: var(--accent); }
.rail button.active { background: var(--magenta); color: #fff; } /* a measuring tool is in use */
.rail button[aria-busy="true"] { cursor: progress; color: var(--accent); } /* an export is being made */
.zoom { z-index: 6; right: 10px; bottom: calc(var(--status-h) + 10px); width: var(--rail); display: flex; flex-direction: column; padding: 2px; gap: 2px; }
.zoom button { height: 54px; } /* square, like the buttons above */

/* ---- layers panel, left of the column ---- */
.panel {
  /* as tall as its content, up to the space above the bottom row */
  z-index: 4; top: 10px; right: calc(var(--rail) + 20px); max-height: calc(100% - var(--status-h) - 20px);
  width: min(340px, calc(100vw - var(--rail) - 40px)); display: flex; flex-direction: column; overflow: hidden;
}
.panel header { display: flex; align-items: center; gap: 8px; padding: 0 0 0 16px; min-height: 48px; border-bottom: 1px solid var(--line); flex: none; }
.panel h1 { font-size: 15px; margin: 0; letter-spacing: .02em; }
.lview { display: flex; flex-direction: column; flex: 0 1 auto; min-height: 0; }
/* the map's settings, at the head of Layers: ‹ time › Now, then the depth (on the next line if need be) */
.when { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); background: #f6f8fa; }
.when input, .when select, .when button { min-height: var(--row); border: 1px solid var(--line); border-radius: 6px; background: #fff; padding: 0 8px; }
.when input { flex: 1; min-width: 0; }
.when button { min-width: var(--row); }
.when [data-step] { font-size: 18px; padding: 0; }
/* the depth on a row of its own: the time line keeps its width, however long the depth control is */
.when .depthsel { flex: 1 0 100%; display: flex; align-items: center; gap: 8px; color: var(--soft); font-size: 12px; }
.when .depthsel select { flex: 1; }
.handle { display: none; }
.spin { width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; visibility: hidden; }
body.loading .spin { visibility: visible; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.x { margin-left: auto; border: 0; background: none; font-size: 20px; line-height: 1; width: 44px; height: 44px; border-radius: 6px; color: var(--soft); flex: none; }
.x:hover { background: var(--line2); color: var(--ink); }
#menu { overflow-y: auto; flex: 0 1 auto; min-height: 0; padding-bottom: 6px; overscroll-behavior: contain; }
.view { overflow-y: auto; flex: 0 1 auto; min-height: 0; padding: 10px 12px; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 6px; }

#menu details { border-bottom: 1px solid var(--line2); }
#menu summary {
  display: flex; align-items: center; gap: 8px; min-height: var(--row); padding: 0 16px; cursor: pointer; user-select: none;
  font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--soft); list-style: none;
}
#menu summary::-webkit-details-marker { display: none; }
#menu summary::after { content: ""; width: 6px; height: 6px; border-right: 1.5px solid; border-bottom: 1.5px solid; transform: rotate(-45deg); transition: transform .15s; }
#menu details[open] > summary::after { transform: rotate(45deg); }
#menu summary .gname { flex: 1; }
#menu summary .count { font-weight: 600; font-size: 11px; letter-spacing: 0; color: var(--accent); background: #e3edf4; border-radius: 9px; padding: 0 7px; line-height: 18px; }
#menu summary .count:empty { display: none; }
#menu ul { list-style: none; margin: 0; padding: 0 0 4px; }

/* base: two cards; the satellite source and the provenance below them */
.bases { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 2px 16px 8px; }
.basecard { border: 2px solid var(--line); background: #fff; border-radius: 8px; padding: 4px; display: flex; flex-direction: column; gap: 4px; font-weight: 600; text-align: left; min-height: 44px; }
.basecard .thumb { height: 44px; border-radius: 5px; }
.basecard[data-base="chart"] .thumb { background: linear-gradient(115deg, #f1ebdc 0 38%, #2b3a46 38% 39%, #cfe6f7 39% 62%, #a5cdec 62% 80%, #86b9e2 80%); }
.basecard[data-base="sat"] .thumb { background: linear-gradient(115deg, #4d6b3c 0 30%, #8a8f6a 30% 40%, #1d3550 40% 75%, #13263b 75%); }
.basecard span { padding: 0 4px 2px; }
.basecard[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* a layer row: name (the whole row toggles), status hint, details button, switch on the right */
.item { padding: 0 8px 0 16px; }
.item .line { display: flex; align-items: center; gap: 6px; min-height: var(--row); }
/* Ocean data: a menu for colours, one for arrows */
.pick .line { gap: 8px; padding-right: 8px; }
.pick .name { flex: none; width: 60px; }
.pick select { flex: 1; min-width: 0; min-height: var(--row); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; background: #fff; }
.pick.error .name::after, .pick.partial .name::after { content: " ⚠"; color: var(--err); }
.pick.partial .name::after { color: var(--warn); }
.item label.name { flex: 1; cursor: pointer; align-self: stretch; display: flex; align-items: center; gap: 8px; }
.item .hint { font-size: 11px; color: var(--warn); font-family: var(--mono); }
.item.dim label.name { color: var(--soft); }
.item.error .name { color: var(--err); }
.item.error .hint::after, .item.partial .hint::after { content: "⚠"; margin-left: 4px; color: var(--err); }
.item.partial .hint::after { color: var(--warn); }
.switch {
  appearance: none; -webkit-appearance: none; margin: 0 4px 0 0; flex: none; cursor: pointer;
  width: 34px; height: 20px; border-radius: 10px; background: #c3ccd3; position: relative; transition: background .15s;
}
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(14px); }
.more { border: 0; background: none; width: var(--row); height: var(--row); border-radius: 6px; color: var(--soft); flex: none; padding: 0; display: grid; place-items: center; }
.more:hover { background: var(--line2); color: var(--ink); }
.more[aria-expanded="true"] { background: var(--line2); color: var(--accent); }
.controls { display: grid; gap: 6px; padding: 0 8px 8px 0; }
.controls select, .controls input[type=number] {
  width: 100%; min-height: var(--row); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; background: #fff;
}
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: #fff; min-height: var(--row); padding: 0 6px; font-size: 12px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }

.opacity { display: flex; align-items: center; gap: 8px; color: var(--soft); font-size: 12px; }
.opacity span { flex: none; min-width: 52px; }
.opacity input[type=range] { flex: 1; height: var(--row); accent-color: var(--accent); margin: 0; }
.info { margin: 0 8px 8px 0; padding: 6px 8px; background: #f6f8fa; border-left: 2px solid var(--accent); font-size: 12px; color: var(--soft); }
.info p { margin: 2px 0; }
.info .opacity { margin: 0 0 4px; }
.info b { color: var(--ink); font-weight: 600; }
.info a { color: var(--accent); }

.view > .item { padding: 0 0 0 4px; } /* Measure: a switch line, as in Layers */
.view h2 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--soft); margin: 4px 4px 0; }
.action { border: 0; background: none; border-radius: 6px; min-height: 44px; padding: 0 10px; display: flex; align-items: center; gap: 10px; text-align: left; width: 100%; }
.action:hover { background: var(--line2); }
.tools3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tools3 button { border: 1px solid var(--line); background: #fff; border-radius: 8px; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 12px; }
.tools3 button:hover { border-color: var(--accent); }
.tools3 button[aria-pressed="true"] { background: var(--magenta); border-color: var(--magenta); color: #fff; }
.mlist { list-style: none; margin: 0; padding: 0; }
.mlist .item { padding: 0; }
.mlist label.name { font-family: var(--mono); font-size: 12px; }
.mlist .item input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; margin: 0 4px; flex: none; }
.mlist .x { font-size: 18px; width: var(--row); height: var(--row); }
.mlist .empty { padding: 4px; color: var(--soft); }
.note { margin: 2px 4px; font-size: 11.5px; color: var(--soft); }

/* ---- search, top left: a place or coordinates ---- */
.search {
  position: absolute; z-index: 7; top: 10px; left: 10px; width: min(380px, calc(100vw - var(--rail) - 40px));
  display: flex; align-items: center; gap: 6px; padding: 0 0 0 12px; min-height: 46px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); color: var(--soft);
}
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; height: 44px; font-size: 14px; color: var(--ink); }
.search input::-webkit-search-cancel-button { display: none; }
.search:focus-within { border-color: var(--accent); }
.results { position: absolute; top: calc(100% + 4px); left: -1px; right: -1px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; max-height: 60vh; overflow-y: auto; }
.results ul { list-style: none; margin: 0; padding: 0; }
.results li { min-height: 44px; padding: 5px 10px; border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; justify-content: center; color: var(--ink); }
.results li small { color: var(--soft); font-size: 11.5px; }
.results li[aria-selected="true"], .results li:hover { background: #e3edf4; }
.results li.none { cursor: default; color: var(--soft); background: none; }
.pin { width: 18px; height: 18px; border-radius: 50%; background: var(--magenta); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
/* the depth at a clicked point */
.depthpop .maplibregl-popup-content { padding: 8px 26px 8px 10px; font: 13px/1.35 var(--font); color: var(--ink); }
.depthpop b { display: block; font-size: 15px; }
.depthpop small { color: var(--soft); }

/* ---- measuring bar: under the search box, only while drawing ---- */
.mbar { z-index: 7; top: 66px; left: 10px; display: flex; align-items: center; gap: 6px; padding: 4px 4px 4px 12px; max-width: calc(100vw - var(--rail) - 40px); }
.mbar .what { font-weight: 600; white-space: nowrap; }
.mbar .val { font-family: var(--mono); white-space: nowrap; }
.mbar .tip { color: var(--soft); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (pointer: coarse) { .keys-hint { display: none; } } /* no keys on a touch screen: the bar's buttons */
.mbar button { border: 1px solid var(--line); background: #fff; border-radius: 6px; min-height: 44px; padding: 0 12px; flex: none; }
.mbar button.done { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---- legends, stacked bottom left above the credits ---- */
.legends { position: absolute; z-index: 3; left: 10px; bottom: calc(var(--status-h) + 8px); display: flex; flex-direction: column; align-items: flex-start; gap: var(--legend-gap, 6px); pointer-events: none; }
.legends:empty { display: none; }
.legends canvas { display: block; outline: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); } /* an outline, not a border: it moves no pixel of the canvas */

/* ---- bottom row: credits left; scale note, position and scale right. No bar: the row is
   transparent (clicks reach the map) and each item carries its own light backing. ---- */
.status {
  position: absolute; z-index: 5; left: 0; right: 0; bottom: 0; pointer-events: none;
  display: flex; align-items: flex-end; gap: 4px 12px; padding: 0 10px 6px;
  font-size: 11px; color: var(--soft);
}
.status > *, .readout > *, .credits > * { pointer-events: auto; }
.pos, .scalenote { background: rgba(255,255,255,.85); border-radius: 4px; padding: 1px 6px; }
.pos { font: 11.5px var(--mono); color: var(--ink); white-space: nowrap; }
.pos:empty { display: none; }
.scalenote { color: var(--warn); }
.nfn { font-weight: 600; white-space: nowrap; }
.scalenote:empty { display: none; }
.readout { display: flex; align-items: flex-end; gap: 8px; margin-left: auto; flex: none; }
/* credits: always on screen, on one line ending in "…" where they do not fit; a tap shows them all */
.credits { display: flex; flex: 0 1 auto; min-width: 0; padding: 1px 6px; border-radius: 4px; background: rgba(255,255,255,.85); }
.credits.foldable { cursor: pointer; }
.credits-text { display: block; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.credits.open .credits-text { white-space: normal; }
.credits a { color: var(--ink); text-decoration: none; }
.credits a:hover { text-decoration: underline; }
.maplibregl-ctrl-scale { border-color: var(--ink); color: var(--ink); background: rgba(255, 255, 255, .85); font: 11px var(--font); }
/* double scale (as on OpenSeaMap): km bar open at the top, NM bar hanging below the same line */
.scales { display: flex; flex-direction: column; align-items: flex-start; }
.scales .maplibregl-ctrl-scale { margin: 0 !important; }
.scales .maplibregl-ctrl-scale + .maplibregl-ctrl-scale { border-top: 2px solid var(--ink); border-bottom: 0; margin-top: -2px !important; }

/* ---- about ---- */
dialog { border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px rgba(20,30,40,.25); max-width: min(460px, calc(100vw - 32px)); padding: 16px 20px; color: var(--ink); }
dialog::backdrop { background: rgba(20,30,40,.35); }
dialog h2 { margin: 0 0 8px; font-size: 17px; }
dialog h3 { margin: 12px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--soft); }
dialog .keys { margin: 0; padding-left: 18px; }
kbd { font: 11px var(--mono); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: #f6f8fa; }
dialog .action { justify-content: center; border: 1px solid var(--line); margin-top: 12px; }

/* ---- phones: sheets from the bottom, pinch instead of zoom buttons ---- */
@media (max-width: 720px) {
  .zoom { background: none; border: 0; box-shadow: none; }
  #zoom-in, #zoom-out { display: none; }
  #compass { background: var(--bg); border: 1px solid var(--line); box-shadow: var(--shadow); }
  /* a sheet from the bottom, as tall as its content up to 85% of the screen */
  .panel { z-index: 8; top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 85%; border-radius: 12px 12px 0 0; transition: transform .2s; }
  .panel.dragging { transition: none; }
  .handle { display: block; position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 88px; height: 22px; border: 0; background: none; cursor: grab; touch-action: none; }
  .handle::after { content: ""; position: absolute; left: 28px; right: 28px; top: 8px; height: 5px; border-radius: 3px; background: #c3ccd3; }
  .panel header { padding-top: 10px; }
  body.menu-open .legends { display: none; }
  .mbar { right: calc(var(--rail) + 20px); flex-wrap: wrap; }
  .mbar .tip, .mbar .what { display: none; } /* the tool is lit in the column: room for the buttons on one line */
  .pos:not(.shown) { display: none; } /* no cursor on a phone; the time shown stays */
  /* two lines: the credits and the scale; not for navigation, the scale note and the time */
  .status { flex-wrap: wrap; }
  .readout { display: contents; }
  .credits { order: 1; flex: 1 1 0; }
  .scales { order: 2; }
  .status::after { content: ""; order: 3; flex-basis: 100%; }
  .nfn, .scalenote, .shown { order: 4; }
  .nfn { margin-left: auto; }
}
