:root {
  color-scheme: light;
  font-family: system-ui, sans-serif;
  --page: #f1f4ed;
  --surface: #fffdf7;
  --surface-muted: #e9f0e7;
  --field: #fff;
  --ink: #18332f;
  --muted: #526660;
  --line: #c8d4ca;
  --control-border: #83998f;
  --primary: #285d50;
  --primary-hover: #19493e;
  --on-primary: #fff;
  --focus: #225e85;
  --accent: #a84828;
  --masthead: #173b35;
  --on-masthead: #f6f7ee;
  --masthead-focus: #ffe198;
  --warning: #fff0d6;
  --warning-ink: #60430b;
  --warning-line: #b67a23;
  --success: #e3efe4;
  --success-ink: #224e3e;
  --water: #e4f0f7;
  --water-ink: #204c65;
  --error: #8f3322;
  --error-bg: #f9e6df;
  --link: #225e50;
  --map-base: #dce5db;
  --overlay-shadow: #12292240;
  color: var(--ink);
  background: var(--page);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #141d1b;
  --surface: #1d2926;
  --surface-muted: #293a35;
  --field: #131f1c;
  --ink: #eaf3ed;
  --muted: #baccc3;
  --line: #42584f;
  --control-border: #77968a;
  --primary: #a0dbc3;
  --primary-hover: #c0ebd9;
  --on-primary: #132d25;
  --focus: #ffcd80;
  --accent: #f0a083;
  --masthead: #112a24;
  --warning: #3a2c17;
  --warning-ink: #ffdaa0;
  --warning-line: #d6a24e;
  --success: #223b31;
  --success-ink: #c4edd6;
  --water: #203a48;
  --water-ink: #badff1;
  --error: #ffac99;
  --error-bg: #462822;
  --link: #a0dbc3;
  --map-base: #303e38;
  --overlay-shadow: #0008;
}

:root[data-palette="river"]:not([data-theme="dark"]) {
  --page: #edf4f9;
  --surface: #f8fcff;
  --surface-muted: #e1edf5;
  --ink: #153344;
  --muted: #405e70;
  --line: #c4d6e2;
  --control-border: #718899;
  --primary: #175971;
  --primary-hover: #10445c;
  --focus: #175971;
  --masthead: #123b54;
  --success: #deedf5;
  --success-ink: #214b61;
  --water: #d9edf7;
  --water-ink: #194d66;
  --link: #155674;
  --map-base: #dce8ef;
}
:root[data-palette="river"][data-theme="dark"] {
  --page: #121e29;
  --surface: #1b2a38;
  --surface-muted: #283e50;
  --field: #111f2a;
  --ink: #eff6ff;
  --muted: #bfd1df;
  --line: #415b70;
  --control-border: #829caf;
  --primary: #99d8f1;
  --primary-hover: #bce9fb;
  --on-primary: #102d3e;
  --focus: #99d8f1;
  --masthead: #142b43;
  --success: #263e50;
  --success-ink: #cee8f7;
  --water: #193e50;
  --water-ink: #c2e8fa;
  --link: #99d8f1;
  --map-base: #2a3e4b;
}
:root[data-palette="copper"]:not([data-theme="dark"]) {
  --page: #f6efe5;
  --surface: #fffaf1;
  --surface-muted: #f0e5d6;
  --field: #fffdf8;
  --ink: #3b2e27;
  --muted: #645448;
  --line: #ddc9b8;
  --control-border: #977e6d;
  --primary: #854924;
  --primary-hover: #663718;
  --focus: #854924;
  --masthead: #533522;
  --success: #ede0cf;
  --success-ink: #684525;
  --water: #f5e2d2;
  --water-ink: #743c21;
  --link: #79401f;
  --map-base: #eadcc9;
}
:root[data-palette="copper"][data-theme="dark"] {
  --page: #251c17;
  --surface: #332720;
  --surface-muted: #46352b;
  --field: #251d18;
  --ink: #fff2e6;
  --muted: #dfcbb9;
  --line: #624b3c;
  --control-border: #b19480;
  --primary: #efb588;
  --primary-hover: #ffd1ab;
  --on-primary: #3d2417;
  --focus: #efb588;
  --masthead: #422b20;
  --success: #49372a;
  --success-ink: #f0d4b6;
  --water: #503529;
  --water-ink: #ffdbc1;
  --link: #efb588;
  --map-base: #47392e;
}

* { box-sizing: border-box; }
body { margin: 0; }
.masthead .masthead-inner, main {
  width: min(1060px, calc(100% - 36px));
  margin-inline: auto;
}
main { padding: clamp(18px, 4vw, 42px) 0 42px; }
h1 {
  margin: 0;
  font: 740 clamp(1.85rem, 4vw, 3rem)/1.12 system-ui, sans-serif;
  letter-spacing: -.035em;
}
h2 { font-size: 1.13rem; }
a { color: var(--link); }
::selection { color: var(--on-primary); background: var(--primary); }

.masthead { background: var(--masthead); color: var(--on-masthead); border-bottom: 1px solid var(--line); }
.masthead .masthead-inner {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
  font-weight: 720;
}
.masthead a { display: inline-flex; align-items: center; min-height: 44px; color: inherit; }
.masthead a:hover { text-decoration-thickness: 2px; }
.masthead-brand { font-size: 1.15rem; letter-spacing: -.02em; text-decoration: none; }
#site-menu {
  position: absolute;
  inset-block-start: 100%;
  inset-inline-end: 0;
  z-index: 1200;
  display: grid;
  min-inline-size: min(14rem, 100%);
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 8px 26px var(--overlay-shadow);
}
#site-menu[hidden] { display: none; }
#site-menu a { padding-inline: 12px; border-radius: 6px; font-size: .95rem; text-decoration: none; }
#site-menu a:hover { background: var(--surface-muted); }
.masthead #site-menu a[aria-current] { color: var(--on-primary); background: var(--primary); }
#site-menu a:focus-visible { outline-color: var(--focus); }
.masthead .site-menu-toggle { color: var(--on-masthead); background: transparent; border: 1px solid currentColor; }
.masthead .site-menu-toggle:hover { background: #ffffff1c; }
.theme-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-weight: 650; }
.theme-picker[hidden] { display: none; }
.theme-picker select {
  width: auto;
  min-height: 44px;
  padding: 5px 8px;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background: var(--field);
}
.settings-panel { max-inline-size: 38rem; margin-top: 18px; padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.settings-panel h2 { margin: 0; }
.settings-panel p { color: var(--muted); }
.settings-panel .theme-picker + .theme-picker { margin-top: 12px; }
.palette-preview { display: inline-flex; gap: 4px; }
.palette-preview i { width: 1.4rem; height: 1.4rem; border: 1px solid var(--control-border); border-radius: 50%; background: var(--page); }
.palette-preview i:nth-child(2) { background: var(--masthead); }
.palette-preview i:nth-child(3) { background: var(--primary); }

.action-icon { inline-size: 20px; block-size: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-button:not([hidden]) {
  display: inline-grid;
  place-items: center;
  inline-size: 44px;
  min-inline-size: 44px;
  min-block-size: 44px;
  padding: 0;
  border-radius: 8px;
  cursor: pointer;
}
.labeled-icon { display: inline-flex; align-items: center; gap: 6px; }
.field-note { color: var(--muted); font-size: .85em; font-weight: 450; }
.photo-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 155px), 1fr)); gap: 8px; }
.photo-list:not(:empty) { margin-block: 8px; }
.photo-card { min-width: 0; padding: 6px; border: 1px solid var(--line); border-radius: 8px; }
.photo-card p, .photo-feedback { color: var(--muted); font-size: .85rem; margin: 6px 0; }
.photo-feedback:empty, #trip-photo-progress:empty { display: none; }
.photo-preview-button { display: block; width: 100%; padding: 0; overflow: hidden; }
.photo-preview-button img { display: block; width: 100%; height: 100px; object-fit: cover; }
.photo-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 6px; }
.observation-actions { border-top: 1px solid var(--line); padding-top: 8px; }
.photo-drag-handle { padding-inline: 4px; cursor: grab; }
@media (pointer: coarse) { .photo-drag-handle { display: none; } }
.photo-viewer { max-width: min(94vw, 1000px); max-height: 94vh; color: var(--ink); background: var(--surface); border: 1px solid var(--control-border); border-radius: 10px; }
.photo-viewer::backdrop { background: #0009; }
.photo-viewer img:not([hidden]) { display: block; max-width: 100%; max-height: 74vh; margin-top: 8px; }
.equipment-cover { width: 38px; height: 38px; flex: none; border-radius: 50%; object-fit: cover; margin-inline-end: 10px; }
progress { accent-color: var(--primary); }

/* Keep the native picker, but size its outer box like the other form fields on iOS. */
input:is([type="date"], [type="time"], [type="datetime-local"]) {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  box-sizing: border-box;
  min-inline-size: 0;
  max-inline-size: 100%;
}

button, .button, input::file-selector-button, .import input::file-selector-button {
  border-color: var(--control-border);
  background: var(--surface);
  color: var(--ink);
}
button:not(:disabled):hover, .button:hover, input::file-selector-button:hover,
.import input::file-selector-button:hover {
  background: var(--surface-muted);
}
button.primary, .button.primary, #new-trip, .point-picker-actions .primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
button.primary:not(:disabled):hover, .button.primary:hover, #new-trip:hover, .point-picker-actions .primary:not(:disabled):hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
button.danger-button { border-color: var(--error); color: var(--error); }
button.danger-button:not(:disabled):hover { background: var(--error-bg); }
:is(a, button, input, select, textarea, summary):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.masthead :is(a, button):focus-visible { outline-color: var(--masthead-focus); }
:is(input, textarea)::placeholder { color: var(--muted); opacity: 1; }
input[type="checkbox"], input[type="radio"], .wizard-progress { accent-color: var(--primary); }
.wizard-progress {
  appearance: none;
  -webkit-appearance: none;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: var(--surface-muted);
}
.wizard-progress::-webkit-progress-bar { background: var(--surface-muted); }
.wizard-progress::-webkit-progress-value { background: var(--primary); }
.wizard-progress::-moz-progress-bar { background: var(--primary); }

.home-panel, .wizard-card, .map-panel, .archive, .boat-panel {
  background: var(--surface);
  border-color: var(--line);
}
.trip-row, .wizard-header, .wizard-navigation, .trip-step, .archive-form,
.archive-form fieldset, .segment-card, .observation-card, .reading-card, .track-item {
  border-color: var(--line);
}
.wizard-step :is(input, select, textarea), .trip-step :is(input, select, textarea),
.archive-form :is(input, select, textarea), .garmin-actions select {
  background: var(--field);
  border-color: var(--control-border);
}
.trip-readonly, .track-item, .segment-tracks { background: var(--surface-muted); }
.segment-tracks { border-color: var(--primary); }
.trip-export-feedback[data-error], #archive-note[data-error], .import-note[data-error],
.archive-note[data-error], #status[data-error] { color: var(--error); }
.public-warning {
  padding: 10px 12px;
  border-inline-start: 4px solid var(--warning-line);
  border-radius: 8px;
  background: var(--warning);
  color: var(--warning-ink);
}

/* Preserve OSM tiles and track/marker colors; only the map's surrounding UI is themed. */
#map { background: var(--map-base); }
.point-picker-overlay, #map .leaflet-popup-content-wrapper, #map .leaflet-popup-tip {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 5px 18px var(--overlay-shadow);
}
.point-picker-overlay { border-color: var(--control-border); }
#map .leaflet-bar,
#map .leaflet-bar a { border-color: var(--control-border); }
#map .leaflet-bar a, #map .leaflet-control-attribution {
  background: var(--surface);
  color: var(--ink);
}
#map .leaflet-bar a:hover, #map .leaflet-bar a.leaflet-disabled { background: var(--surface-muted); }
#map .leaflet-bar a.leaflet-disabled { color: var(--muted); }
#map .leaflet-control-attribution a, #map .leaflet-popup-content a,
#map a.leaflet-popup-close-button { color: var(--link); }
#map a:focus-visible { outline-offset: -3px; }
.legend .symbol:not(.line) { outline: 1px solid var(--control-border); }

@media (max-width: 520px) {
  .masthead .masthead-inner, main { width: calc(100% - 28px); }
}
