/* Palette: "Monsoon teal". The yellow milestone cap and check-in button stay in every theme. */
:root {
  --ground: #EAF1F2;
  --surface: #FFFFFF;
  --ink: #122326;
  --muted: #50656A;
  --line: #CFDDE0;
  --brand: #0E6670;
  --on-brand: #FFFFFF;
  --yellow: #F2B705;
  --on-yellow: #1C1500;
  --danger: #B3261E;
  --ms-body: #FFFFFF;
  --ms-ink: #122326;
  --shadow: 0 1px 2px rgba(18, 35, 38, .08), 0 4px 16px rgba(18, 35, 38, .06);
  --backdrop: rgba(6, 16, 18, .5);
  --font-display: 'Barlow Condensed', 'Arial Narrow', 'Roboto Condensed', sans-serif;
  --font-body: 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  color-scheme: light;
}
/* Dark theme: when the phone is dark and the user hasn't picked Light, or when they picked Dark.
   The two blocks must stay identical (CSS can't share one block across both conditions). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0D1517;
    --surface: #152024;
    --ink: #E1ECEE;
    --muted: #93A9AE;
    --line: #283A3F;
    --brand: #4FB7C1;
    --on-brand: #061416;
    --danger: #F2877F;
    --ms-body: #E6EEF0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --backdrop: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ground: #0D1517;
  --surface: #152024;
  --ink: #E1ECEE;
  --muted: #93A9AE;
  --line: #283A3F;
  --brand: #4FB7C1;
  --on-brand: #061416;
  --danger: #F2877F;
  --ms-body: #E6EEF0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --backdrop: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 16px/1.5 var(--font-body);
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
[hidden] { display: none !important; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* Top bar */
.bar {
  position: sticky; top: 0; z-index: 500;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--brand); color: var(--on-brand);
}
.bar-title {
  flex: 1; margin: 0; min-width: 0;
  font: 700 24px/1.1 var(--font-display); letter-spacing: .02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar-btn {
  min-height: 40px; min-width: 40px; padding: 0 10px;
  border: 0; border-radius: 8px; background: transparent; color: inherit;
  font-size: 15px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
#backBtn { font-size: 32px; line-height: 1; padding: 0 6px 4px; }
.bar-link { text-decoration: none; border: 1.5px solid currentColor; opacity: .92; }
.bar-icon { padding: 0; width: 44px; height: 44px; border-radius: 50%; }
.bar-icon .ico-sun, .bar-icon.is-dark .ico-moon { display: none; }
.bar-icon.is-dark .ico-sun { display: block; }

.view {
  max-width: 640px; margin: 0 auto;
  padding: 16px 16px 8px;
  display: flex; flex-direction: column; gap: 20px;
}

/* Type */
.eyebrow {
  margin: 0; font: 600 13px/1.2 var(--font-body);
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
.sec { margin: 0 0 10px; font: 700 20px/1.2 var(--font-display); letter-spacing: .03em; text-transform: uppercase; }
h2, h3 { text-wrap: balance; }
.meta { margin: 0; color: var(--muted); font-size: 15px; }
.fine { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

/* Buttons */
.btn {
  min-height: 44px; padding: 0 16px;
  border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 15px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.row { display: flex; flex-wrap: wrap; gap: 10px; }

/* Panels */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.panel h2 { margin: 0; font: 700 22px/1.15 var(--font-display); letter-spacing: .02em; }
.panel p { margin: 0; }

/* Active trip card */
.active { border: 2px solid var(--brand); box-shadow: var(--shadow); }
.active h2 { font-size: 28px; }

/* Start form */
.field { display: flex; flex-direction: column; gap: 6px; }
label, legend { font-weight: 600; font-size: 14px; }
input[type=text], input[type=datetime-local], textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--ground); color: var(--ink);
}
textarea { resize: vertical; min-height: 76px; }
input:focus, textarea:focus { border-color: var(--brand); outline: none; }

/* Nudge */
.nudge {
  display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center;
  padding: 10px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--yellow) 22%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--yellow) 60%, var(--line));
  font-size: 15px;
}
.nudge a { font-weight: 600; }

/* Milestone marker: yellow cap, white stone, number */
.ms {
  width: 34px; height: 42px; flex: none;
  border-radius: 17px 17px 5px 5px;
  background: linear-gradient(to bottom, var(--yellow) 0 42%, var(--ms-body) 42% 100%);
  border: 1.5px solid color-mix(in srgb, var(--ms-ink) 35%, transparent);
  display: grid; align-items: end; justify-items: center; padding-bottom: 4px;
  font: 600 13px/1 var(--font-mono); color: var(--ms-ink);
  font-variant-numeric: tabular-nums;
}
.ms.is-hidden { background: repeating-linear-gradient(135deg, var(--ms-body) 0 4px, color-mix(in srgb, var(--ms-ink) 18%, var(--ms-body)) 4px 8px); }
.ms-pin { position: relative; width: 24px; height: 30px; border-radius: 12px 12px 4px 4px; font-size: 11px; padding-bottom: 3px; box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.pin-wrap { background: none; border: 0; }
/* Stop type badge on the map pin's shoulder */
.pin-type {
  position: absolute; top: -6px; right: -10px;
  width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand); color: var(--on-brand);
  border: 1.5px solid var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.pin-type .ico { width: 11px; height: 11px; stroke-width: 2.4; }

/* Stop type icons */
.ico { width: 15px; height: 15px; flex: none; }

/* Trip list */
.trips { display: flex; flex-direction: column; gap: 8px; }
.trip-row {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); cursor: pointer;
}
.trip-row h3 { margin: 0 0 2px; font: 700 20px/1.15 var(--font-display); letter-spacing: .02em; }
.trip-row .meta { font-size: 14px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--line); color: var(--muted); }

.empty { text-align: left; padding: 18px; border: 1.5px dashed var(--line); border-radius: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.empty p { margin: 0; }

/* Trip view */
.trip-head { display: flex; flex-direction: column; gap: 6px; }
.trip-title { margin: 0; font: 700 34px/1.05 var(--font-display); letter-spacing: .01em; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 0; }
.stats div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.stats dt { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.stats dd { margin: 0; font: 600 18px/1.3 var(--font-mono); font-variant-numeric: tabular-nums; }

.map { height: 280px; border-radius: 14px; border: 1px solid var(--line); overflow: hidden; background: var(--surface); z-index: 0; }
.map-note { margin: 0; padding: 10px 14px; border: 1.5px dashed var(--line); border-radius: 12px; color: var(--muted); font-size: 14px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.stop-btn {
  width: 100%; display: grid; grid-template-columns: 34px 1fr; gap: 12px;
  text-align: left; padding: 10px 12px 10px 0; background: none; border: 0; cursor: pointer;
  border-radius: 10px;
}
.stop-btn:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); }
.stop-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.stop-time { font-size: 13px; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px 1px 7px; border-radius: 999px; background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--ink); font-size: 13px; font-weight: 600; }
.stop h3 { margin: 2px 0 0; font: 600 18px/1.25 var(--font-body); }
.stop h3.unnamed { color: var(--muted); font-style: italic; font-weight: 400; }
.stop-note { margin: 4px 0 0; font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.stars-view { color: var(--yellow); letter-spacing: 1px; font-size: 14px; }
.stars-view .off { color: var(--line); }
.gap {
  margin-left: 16px; border-left: 2px dashed var(--line);
  padding: 6px 0 6px 26px; color: var(--muted);
  font: 400 13px/1.3 var(--font-mono); font-variant-numeric: tabular-nums;
}

/* "More" menu sheet */
.menu { display: flex; flex-direction: column; gap: 4px; }
.menu-title { margin: 0 0 8px; font: 700 24px/1.15 var(--font-display); letter-spacing: .02em; }
.menu-item {
  min-height: 52px; padding: 0 14px; border: 0; border-radius: 10px;
  background: none; text-align: left; font-size: 17px; font-weight: 600; cursor: pointer;
}
.menu-item:hover { background: var(--ground); }
.menu-item.danger { color: var(--danger); }
.menu .btn { margin-top: 8px; }

/* Backup page */
.import-result { display: flex; flex-direction: column; gap: 8px; color: var(--muted); font-size: 15px; }
.import-result:empty { display: none; }
.import-result p { margin: 0; }
.import-list, .plain-list { margin: 0; padding-left: 20px; }
.import-list li { color: var(--ink); font-weight: 600; }
.plain-list li + li { margin-top: 4px; }

/* Footer */
.foot {
  max-width: 640px; margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  text-align: center; color: var(--muted); font-size: 13px;
}
body.has-checkbar .foot { padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px)); }

/* Check-in bar */
.checkbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 600;
  padding: 18px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to bottom, transparent, var(--ground) 40%);
  display: flex; justify-content: center;
}
.checkin {
  width: 100%; max-width: 608px; min-height: 68px;
  border: 0; border-radius: 16px 16px 8px 8px;
  background: var(--yellow); color: var(--on-yellow);
  box-shadow: 0 6px 20px rgba(242, 183, 5, .35), 0 1px 0 rgba(0,0,0,.2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  cursor: pointer;
}
.checkin-main { font: 700 28px/1 var(--font-display); text-transform: uppercase; letter-spacing: .05em; }
.checkin-sub { font-size: 13px; font-weight: 600; opacity: .8; }
.checkin:active { transform: translateY(1px); }
.checkin.busy { opacity: .75; }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: var(--backdrop); }
.sheet-panel {
  position: relative; width: 100%; max-width: 640px; margin: 0 auto;
  max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}
.sheet-form { display: flex; flex-direction: column; gap: 14px; }
.sheet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.sheet-head h2, .sheet-title { margin: 0; font: 700 26px/1.1 var(--font-display); }
.sheet-panel h2[tabindex="-1"]:focus { outline: none; }
.notice { margin: 0; padding: 10px 12px; border-radius: 10px; font-size: 15px; background: color-mix(in srgb, var(--yellow) 22%, var(--surface)); }
.err { color: var(--danger); font-size: 14px; margin: 0; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip-opt { position: relative; }
.chip-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip-opt span {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px 0 12px;
  border: 1.5px solid var(--line); border-radius: 999px; font-size: 15px; font-weight: 600;
}
.chip-opt input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.chip-opt input:focus-visible + span { outline: 3px solid var(--yellow); outline-offset: 2px; }
.stars { display: flex; gap: 4px; margin-top: 4px; }
.star {
  width: 44px; height: 44px; border: 0; background: none; cursor: pointer;
  font-size: 30px; line-height: 1; color: var(--line); padding: 0;
}
.star[aria-pressed=true] { color: var(--yellow); }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; font-size: 15px; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--brand); }
.coords-line { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; font-size: 13px; color: var(--muted); }
.sheet-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding-top: 4px; }
.grow { flex: 1; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom, 0px)); z-index: 1100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px;
  background: var(--ink); color: var(--ground); font-weight: 600; font-size: 15px;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

.leaflet-container { font-family: var(--font-body); }
