:root {
  --paper: #F4F2EC;
  --card: #FBFAF6;
  --line: #D9D3C3;
  --line-soft: #E4DFD2;
  --ink: #1E2A24;
  --ink-2: #45524B;
  --muted: #5B6660;
  --green: #2F5D46;
  --pr: #D2461E;
  --other: #2C6FA8;
  --secret: #1E2A24;
  --danger: #A3261B;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: 'IBM Plex Sans', system-ui, sans-serif; color: var(--ink); background: var(--paper); font-size: 15px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.mono { font-family: var(--mono); font-size: 13px; color: var(--muted); }
h2 { font-size: 15px; margin: 22px 0 8px; }
h2 .hint { font-weight: 400; color: var(--muted); font-size: 13px; }

/* Header */
.top { height: 60px; display: flex; align-items: center; gap: 16px; padding: 0 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.tabs { display: flex; gap: 4px; margin-left: 12px; flex-wrap: wrap; }
.tab { height: 40px; padding: 0 14px; border-radius: 8px; border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center; text-decoration: none; }
.tab[aria-pressed="true"] { background: #E6EDE8; color: var(--ink); font-weight: 600; }
.save-state { margin-left: auto; font-size: 13px; color: var(--muted); }

/* Buttons and fields */
.btn { min-height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; font-size: 13px; padding: 0 10px; }
.btn.file { position: relative; }
.link { border: 0; background: none; color: var(--green); font: inherit; font-size: 14px; cursor: pointer; padding: 4px 0; text-decoration: underline; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; font-size: 14px; }
.time-box { display: flex; flex-direction: column; min-width: 0; }
.time-box label.check.est { margin-top: -6px; font-size: 13px; }
.hint { margin: -4px 0 12px 26px; font-size: 13px; color: #5b6660; }
input[type="text"], input[type="password"], input[type="search"], input[type="date"], input[type="time"], select, textarea {
  font: inherit; font-weight: 400; font-size: 14px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--other); outline-offset: 1px; }
fieldset { border: 0; padding: 0; margin: 0 0 12px; }
legend { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; margin-bottom: 8px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.error { color: var(--danger); font-size: 14px; min-height: 1em; }

/* Layout */
.layout { display: flex; height: calc(100vh - 60px); }
.side { width: 400px; flex-shrink: 0; overflow-y: auto; background: var(--card); border-right: 1px solid var(--line); }
.panel { padding: 18px 20px 28px; }
.mapwrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #CFDFE6; }

/* Atlas */
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.totals div { padding: 10px 12px; border-radius: 10px; background: #fff; border: 1px solid var(--line-soft); }
.totals b { display: block; font-size: 20px; }
.totals span { font-size: 12px; color: var(--muted); }
.tick-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tick { flex-direction: row; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; margin: 0; border: 1px solid var(--line); border-radius: 18px; background: #fff; font-weight: 400; font-size: 13px; cursor: pointer; }
.tick:has(input:checked) { border-color: var(--ink); }
.tick .count { color: var(--muted); }
.tick-actions { margin-top: 4px; font-size: 13px; color: var(--muted); }
.swatch { width: 16px; height: 4px; border-radius: 2px; display: inline-block; }
.swatch.pr { background: var(--pr); }
.swatch.other { background: var(--other); }
.swatch.secret { height: 0; border-top: 3px dashed var(--secret); border-radius: 0; }
.search { margin: 6px 0 12px; }
.hike-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.hike-item { width: 100%; text-align: left; display: flex; gap: 12px; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line-soft); background: #fff; font: inherit; color: inherit; cursor: pointer; }
.hike-item:hover { border-color: var(--ink-2); }
.hike-item .bar { width: 6px; border-radius: 3px; flex-shrink: 0; }
.hike-item .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.hike-item .top-line { display: flex; justify-content: space-between; gap: 8px; }
.hike-item .name { font-weight: 600; font-size: 14px; }
.hike-item .date { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.hike-item .meta { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.hike-item .tag { font-size: 12px; color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; padding: 12px 0; }

/* Hike form */
.back { margin-bottom: 10px; }
.days ol { margin: 0 0 8px; padding-left: 22px; }
.days li { margin-bottom: 6px; }
.days li .day-row { display: flex; gap: 6px; align-items: center; }
.stats { font-family: var(--mono); font-size: 13px; color: var(--ink-2); padding: 10px 12px; background: #fff; border: 1px solid var(--line-soft); border-radius: 8px; }
.seg-list, .wp-list { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 8px; }
.seg-list li, .wp-list li { font-size: 13px; }
.seg-card, .wp-card { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; border: 1px solid var(--line-soft); border-radius: 8px; background: #fff; }
.seg-card .line1, .wp-card .line1 { display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.seg-card .line2 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg-card select { width: auto; padding: 5px 8px; font-size: 13px; }
.seg-card label.check, .seg-card label { margin: 0; font-size: 13px; }
.wp-card { cursor: pointer; text-align: left; font: inherit; color: inherit; }
.wp-card .note { color: var(--ink-2); white-space: pre-line; }
.iconbtn { border: 0; background: none; color: var(--muted); cursor: pointer; font: inherit; font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.iconbtn:hover { color: var(--danger); background: #F6E9E7; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid var(--line); background: #fff; font: inherit; font-size: 13px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: #fff; }
.state { font-size: 14px; }
.state.ok { color: var(--green); }
.state.missing { color: var(--danger); }
table.seasons { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
table.seasons th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px; }
table.seasons td { padding: 3px; }
table.seasons input { padding: 6px 7px; font-size: 13px; }
#settingsPanel .btn { margin: 4px 6px 4px 0; }

/* Map overlays */
.toolbar { position: absolute; left: 60px; top: 12px; z-index: 500; width: 220px; padding: 8px; background: var(--card); border-radius: 14px; box-shadow: 0 6px 24px rgba(30,42,36,.18); display: flex; flex-direction: column; gap: 3px; }
.tb-title { font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 8px; letter-spacing: .04em; text-transform: uppercase; }
.tool { display: flex; flex-direction: column; align-items: flex-start; min-height: 46px; padding: 6px 10px; border-radius: 10px; border: 1px solid transparent; background: transparent; font: inherit; text-align: left; cursor: pointer; color: var(--ink); }
.tool b { font-size: 14px; }
.tool small { font-size: 12px; color: var(--muted); }
.tool:hover { background: #F0EDE4; }
.tool[aria-pressed="true"] { border-color: var(--ink); background: #E9E6DD; }
.toolbar hr { border: 0; border-top: 1px solid var(--line-soft); margin: 4px 6px; width: calc(100% - 12px); }
.tb-opt { padding: 0 8px; margin: 4px 0; }
.tb-opt select { padding: 6px 8px; font-size: 13px; }
.drawbar { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 500; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 16px; background: var(--ink); color: #F4F2EC; border-radius: 12px; font-size: 14px; }
.drawbar .btn { border-color: #3B4A42; background: #34433B; color: #fff; }
.drawbar .btn.primary { background: #fff; color: var(--ink); }
.toast { position: absolute; right: 16px; bottom: 24px; z-index: 1200; max-width: 360px; padding: 10px 14px; border-radius: 10px; background: var(--ink); color: #fff; font-size: 14px; }
.mapwrap.drawing .leaflet-container { cursor: crosshair; }

/* Waypoint markers */
.mhl-wp { background: none; border: 0; }
.mhl-wp-dot { width: 26px; height: 26px; border-radius: 13px; display: flex; align-items: center; justify-content: center; background: var(--c); color: #fff; font: 700 12px/1 'IBM Plex Sans', sans-serif; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.mhl-wp-dot.mhl-wp-secret { background: var(--secret); }
.mhl-wp-dot.mhl-wp-danger { background: #A3261B; }
.anchor-dot { width: 12px; height: 12px; border-radius: 6px; background: #fff; border: 3px solid var(--ink); }

/* Sign in */
.login { position: fixed; inset: 0; z-index: 2000; background: var(--paper); display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; padding: 28px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-card p { color: var(--muted); margin: 0 0 16px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; height: auto; }
  .side { width: 100%; border-right: 0; border-bottom: 1px solid var(--line); }
  .mapwrap { height: 70vh; }
  .top { height: auto; flex-wrap: wrap; padding: 10px 16px; }
  .layout { height: auto; }
}

/* Height profile */
.profile { margin: 10px 0 4px; padding: 10px 12px 8px; background: #fff; border: 1px solid var(--line-soft, #E4DFD2); border-radius: 10px; }
.profile-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.profile-head .mono { font-weight: 400; font-size: 12px; }
.profile-svg { display: block; width: 100%; height: auto; touch-action: none; cursor: crosshair; }
.profile-svg text { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-size: 9.5px; fill: #5B6660; }
.profile-svg .grid { stroke: #E4DFD2; stroke-width: 1; }
.profile-svg .cursor line { stroke: #1E2A24; stroke-width: 1; stroke-dasharray: 3 3; }
.profile-read { font-size: 12.5px; min-height: 1.3em; margin-top: 2px; color: #1E2A24; }
.profile-src { font-size: 11px; color: #5B6660; margin-top: 2px; }

/* Planner */
h2.first { margin-top: 0; font-size: 18px; }
.lead { color: var(--ink-2); font-size: 14px; line-height: 1.45; margin: 0 0 14px; }
.plan-items { margin-top: 16px; }
.plan-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 12px; position: relative; }
.plan-stats div { padding: 9px 10px; border-radius: 10px; background: #fff; border: 1px solid var(--line-soft); }
.plan-stats b { display: block; font-size: 17px; white-space: nowrap; }
.plan-stats span { font-size: 12px; color: var(--muted); }
.plan-stats .empty { grid-column: 1 / -1; margin: 0; padding: 4px 0; }
.plan-stats .busy { position: absolute; right: 0; top: -20px; font-size: 12px; color: var(--muted); }
.steep { margin-bottom: 10px; }
.steep-head { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.steep-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--line-soft); }
.steep-legend { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.steep-legend li { display: flex; align-items: center; gap: 8px; }
.steep-legend b { margin-left: auto; font-family: var(--mono); font-weight: 400; font-size: 12.5px; }
.steep-legend .sw { width: 14px; height: 10px; border-radius: 3px; }
.facts { list-style: none; padding: 0; margin: 10px 0 14px; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; line-height: 1.4; }
.facts li { padding-left: 14px; position: relative; }
.facts li::before { content: ''; position: absolute; left: 2px; top: 8px; width: 5px; height: 5px; border-radius: 3px; background: var(--muted); }
.facts .small { font-size: 12px; color: var(--muted); }
.planbar .tb-row { display: flex; gap: 6px; padding: 2px 8px; }
.planbar .tb-row .btn { flex: 1; white-space: nowrap; }
.small-link { font-size: 13px; padding: 4px 8px; align-self: flex-start; }
.tb-hint { margin: 4px 8px 2px; font-size: 12.5px; line-height: 1.4; color: var(--ink-2); }
.anchor-dot.plan { border-color: #6B3FA0; }

/* 3D */
.btn3d { width: 44px; height: 44px; border-radius: 8px; border: 2px solid rgba(0,0,0,.2); background: #fff; font: 700 14px/1 'IBM Plex Sans', sans-serif; color: var(--ink); cursor: pointer; background-clip: padding-box; }
.btn3d:hover { background: #F0EDE4; }
.map3d { position: absolute; inset: 0; z-index: 1100; background: #CFDFE6; }
.map3d #map3dCanvas { position: absolute; inset: 0; }
.map3d-panel { position: absolute; left: 16px; top: 16px; z-index: 2; width: 220px; padding: 8px 8px 10px; background: var(--card); border-radius: 14px; box-shadow: 0 6px 24px rgba(30,42,36,.18); display: flex; flex-direction: column; gap: 6px; }
.map3d-panel .btn { margin: 4px 8px 0; }
.m3-label { font-size: 12px; color: var(--muted); padding: 2px 8px 0; }
.seg-toggle { display: flex; margin: 0 8px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-toggle button { flex: 1; min-height: 34px; border: 0; background: #fff; font: inherit; font-size: 13px; cursor: pointer; color: var(--ink); }
.seg-toggle button + button { border-left: 1px solid var(--line); }
.seg-toggle button[aria-pressed="true"] { background: var(--green); color: #fff; font-weight: 600; }
.map3d .mhl-wp-dot { cursor: default; }

@media (max-width: 860px) {
  .plan-stats { grid-template-columns: repeat(2, 1fr); }
  .toolbar { width: 180px; left: 54px; top: 8px; }
  .map3d-panel { width: 190px; left: 8px; top: 8px; }
  .toolbar .tool small { display: none; }
}
