/* Race ETA Planner: map-first, high contrast, large numbers. */

:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --text: #0f1115;
  --muted: #5b6270;
  --border: #e2e5ea;
  /* Milers Colonia red (milers.run). --accent fills and borders, --accent-text for red text. */
  --accent: #c31b23;
  --accent-ink: #ffffff;
  --accent-text: #c31b23;
  --accent-soft: #fdecec;
  --focus: #1a5cff;
  --danger: #c62828;
  --header-bg: #0f1115;
  --header-ink: #ffffff;
  --shadow: 0 1px 2px rgba(15, 17, 21, .06), 0 8px 24px rgba(15, 17, 21, .08);
  --radius: 14px;
  --sidebar: 368px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d10;
    --surface: #15181d;
    --surface-2: #1c2027;
    --text: #f2f4f7;
    --muted: #a3aab7;
    --border: #2a2f38;
    --accent: #c31b23;
    --accent-ink: #ffffff;
    --accent-text: #ef5a5f; /* brand red is too dark as text on dark surfaces (3:1); this tint reaches 5.3:1 */
    --accent-soft: #2c1415;
    --focus: #7aa2ff;
    --danger: #ff7a70;
    --header-bg: #000000;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
h1, h2, p { margin: 0; }
svg { flex: none; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------------ layout */

.app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "header header" "sidebar map";
  height: 100vh;
  height: 100dvh;
}

.app-header {
  grid-area: header;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--header-bg);
  color: var(--header-ink);
  z-index: 1001;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 30px; height: 25px; }
.brand h1 { font-size: 1.05rem; font-weight: 750; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-header .btn-ghost { color: var(--header-ink); border-color: rgba(255,255,255,.22); background: transparent; }
.app-header .btn-ghost:hover { background: rgba(255,255,255,.08); }
.header-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.btn-icon { width: 44px; padding: 0; }
.btn-icon svg { width: 22px; height: 22px; }
.btn-lang { font-size: .85rem; letter-spacing: .04em; }

/* ------------------------------------------------------------------ intro dialog */

.intro {
  width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 0; border-radius: 20px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.intro::backdrop { background: rgba(15, 17, 21, .55); }
.intro-inner { padding: 22px 22px 20px; display: flex; flex-direction: column; gap: 12px; }
.intro h2 { font-size: 1.3rem; font-weight: 800; letter-spacing: -.01em; }
.intro-steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 10px; }
.intro-steps li { counter-increment: step; display: grid; grid-template-columns: 28px 1fr; gap: 10px; line-height: 1.45; }
.intro-steps li::before {
  content: counter(step); display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: .9rem;
}
.intro .note { margin-top: 0; }
.intro-privacy { display: flex; gap: 8px; align-items: flex-start; font-size: .88rem; color: var(--muted); line-height: 1.4; }
.intro-privacy svg { width: 18px; height: 18px; margin-top: 1px; flex: none; }
.intro .btn-block { margin-top: 4px; }

.map-wrap { grid-area: map; position: relative; min-height: 0; background: var(--surface-2); }
#map { position: absolute; inset: 0; background: var(--surface-2); }

.sidebar {
  grid-area: sidebar;
  overflow-y: auto;
  padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
  border-right: 1px solid var(--border);
  background: var(--bg);
}

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 12px;
}
.note { color: var(--muted); font-size: .88rem; line-height: 1.4; margin-top: 8px; }
.track-name { font-weight: 650; font-size: 1.02rem; margin-bottom: 10px; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-weight: 650; font-size: .95rem;
  cursor: pointer; user-select: none; text-decoration: none;
  transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-link { background: none; color: var(--text); text-decoration: underline; text-underline-offset: 3px; font-weight: 600; }
.btn-sm { min-height: 44px; padding: 0 12px; font-size: .88rem; }
.btn-block { width: 100%; margin-top: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 12px; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

.chip {
  min-height: 44px; min-width: 56px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 650; font-variant-numeric: tabular-nums; cursor: pointer;
}
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }

/* ------------------------------------------------------------------ form */

.race-form { display: flex; flex-direction: column; gap: 12px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field-label .hint { font-weight: 500; opacity: .8; margin-left: 4px; }
.field input, .save-form input, .jump-form input {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums;
  -webkit-appearance: none; appearance: none;
}
.field input:focus, .save-form input:focus, .jump-form input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 30%, transparent); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
#target-time { font-size: 1.35rem; letter-spacing: .02em; }
.field-error { color: var(--danger); font-size: .85rem; font-weight: 600; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; }

.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 0; }
.kv > div { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.kv dt { font-size: .78rem; color: var(--muted); font-weight: 600; }
.kv dd { margin: 2px 0 0; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 750; font-variant-numeric: tabular-nums; }
.kv dd small { font-size: .75rem; color: var(--muted); font-weight: 600; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-weight: 600; font-size: .92rem; position: relative; }
.switch input { position: absolute; opacity: 0; width: 44px; height: 26px; margin: 0; cursor: pointer; }
.switch-track { width: 44px; height: 26px; border-radius: 999px; background: var(--border); position: relative; transition: background .15s; flex: none; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------------ result */

.result { border: 2px solid var(--text); padding: 14px 16px 16px; }
.result-hint { font-size: 1.05rem; line-height: 1.4; }
.result-warn { font-size: 1.1rem; font-weight: 700; color: var(--danger); margin: 6px 0 4px; }
.result-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin: -4px -8px 0 0; }
.km { display: flex; align-items: baseline; gap: 8px; }
.km-label { font-size: .85rem; font-weight: 800; letter-spacing: .1em; color: var(--accent-text); }
.km-value { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }

.eta-block { margin: 2px 0 12px; }
.eta-time { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 2px; font-variant-numeric: tabular-nums; line-height: 1; }
.eta-hm { font-size: clamp(3.4rem, 9vw, 4.4rem); font-weight: 850; letter-spacing: -.035em; }
.eta-sec { font-size: 1.6rem; font-weight: 700; color: var(--muted); }
.eta-day { margin-left: 10px; font-size: .85rem; font-weight: 700; background: var(--accent-soft); color: var(--accent-text); padding: 4px 8px; border-radius: 999px; align-self: center; }
.eta-label { font-size: .95rem; font-weight: 650; margin-top: 6px; }
.muted { color: var(--muted); font-weight: 500; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 0 0 12px; }
.stats > div { background: var(--surface-2); border-radius: 12px; padding: 8px 12px; }
.stats dt { font-size: .75rem; color: var(--muted); font-weight: 650; }
.stats dd { margin: 2px 0 0; font-size: 1.15rem; font-weight: 750; font-variant-numeric: tabular-nums; }

.also { margin: 0 0 12px; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); }
.also-label { display: block; font-size: .82rem; font-weight: 700; color: var(--accent-text); margin-bottom: 8px; }
.also-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-alt { background: var(--surface); }

.save-form { display: flex; gap: 8px; }
.save-form input { flex: 1; min-width: 0; font-size: 1rem; font-weight: 500; }
.save-form .btn { flex: none; }

.jump-form { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.jump-form label { font-size: .88rem; font-weight: 650; color: var(--muted); white-space: nowrap; }
.jump-form input { min-height: 44px; font-size: 1rem; max-width: 120px; }

/* ------------------------------------------------------------------ spectator points */

.points { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.point { display: flex; align-items: center; gap: 4px; background: var(--surface-2); border-radius: 12px; border: 2px solid transparent; }
.point.is-selected { border-color: var(--accent); }
.point-main {
  flex: 1; min-width: 0; min-height: 56px; display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 12px;
}
.point-eta { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; min-width: 4.2ch; }
.point-meta { display: flex; flex-direction: column; min-width: 0; }
.point-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.point-sub { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.privacy-footer { display: flex; gap: 8px; align-items: flex-start; font-size: .82rem; color: var(--muted); line-height: 1.4; padding: 4px 4px 12px; }
.privacy-footer svg { width: 16px; height: 16px; margin-top: 1px; }
.legal-links { padding: 0 4px 16px; margin-top: -8px; display: flex; flex-wrap: wrap; align-items: center; gap: 0 18px; }
.tip-link { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font-size: .85rem; font-weight: 600; color: var(--accent-text); text-decoration: underline; text-underline-offset: 3px; }
.tip-link svg { width: 18px; height: 18px; flex: none; }
.link-btn { background: none; border: 0; padding: 12px 0; min-height: 44px; font: inherit; font-size: .85rem; font-weight: 600; color: var(--text); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* Privacy policy dialog: German or English section, following the UI language. */
.legal-dialog { width: min(680px, calc(100vw - 32px)); }
.legal-dialog .intro-inner { position: relative; overflow-y: auto; max-height: calc(100dvh - 32px); }
.legal-close { position: absolute; top: 10px; right: 10px; }
html[lang="de"] .legal[data-lang="en"], html:not([lang="de"]) .legal[data-lang="de"] { display: none; }
.legal { display: flex; flex-direction: column; gap: 8px; line-height: 1.5; font-size: .92rem; }
.legal h2 { padding-right: 44px; }
.legal h3 { font-size: 1rem; font-weight: 750; margin: 10px 0 0; }
.legal a { color: var(--accent-text); }

/* ------------------------------------------------------------------ map overlays */

/* Start screen ("landing"): fills the map area until a course is loaded; also reused as the
   course picker when reopened over a loaded course. */
.empty-state {
  position: absolute; inset: 0; z-index: 900; overflow-y: auto;
  background: var(--bg);
  display: flex; justify-content: center; align-items: flex-start;
  padding: clamp(20px, 5vh, 56px) 16px 32px;
}
.app:not([data-state="EMPTY"]) .empty-state { background: color-mix(in srgb, var(--bg) 88%, transparent); }
.landing { position: relative; width: 100%; max-width: 920px; display: flex; flex-direction: column; gap: 18px; }
.picker-close { position: absolute; top: -8px; right: -4px; }
.landing-title { font-size: clamp(1.7rem, 3.6vw, 2.6rem); font-weight: 850; letter-spacing: -.025em; line-height: 1.1; padding-right: 44px; }
.landing-lead { color: var(--muted); font-size: 1.05rem; line-height: 1.45; max-width: 60ch; margin-top: -6px; }

.landing-steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.landing-steps li {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  font-weight: 650; font-size: .92rem; line-height: 1.3;
}
.step-icon { flex: none; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); }
.step-icon svg { width: 20px; height: 20px; }

.landing-section { font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 8px 0 -6px; }
.race-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.race-grid li { display: flex; }
.race-tile {
  width: 100%; min-height: 128px; padding: 16px 18px; cursor: pointer; text-align: left;
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  background: var(--surface); color: var(--text); font: inherit;
  border: 2px solid var(--border); border-left: 6px solid var(--accent); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: border-color .15s, transform .1s;
}
.race-tile:hover { border-color: var(--accent); }
.race-tile:active { transform: translateY(1px); }
.race-tile[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }
.race-kind { font-size: .78rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--accent-text); font-variant-numeric: tabular-nums; }
.race-name { font-size: 1.12rem; font-weight: 800; letter-spacing: -.01em; line-height: 1.25; }
.race-when { margin-top: auto; display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.race-when > span { display: inline-flex; align-items: center; gap: 6px; }
.race-when svg { width: 16px; height: 16px; }
.race-tile-own { border-style: dashed; border-left: 2px dashed var(--border); box-shadow: none; background: transparent; justify-content: center; }
.race-tile-own:hover { border-color: var(--accent); border-left-color: var(--accent); }
.race-own-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--surface-2); color: var(--text); }
.race-own-icon svg { width: 20px; height: 20px; }
.race-own-sub { color: var(--muted); font-size: .9rem; line-height: 1.35; }


@media (max-width: 700px) {
  .landing-steps { grid-template-columns: 1fr; gap: 6px; }
  .landing-steps li { padding: 8px 12px; }
  .step-icon { width: 32px; height: 32px; }
  .race-tile { min-height: 0; }
}

.drop-overlay {
  position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 22%, transparent); border: 4px dashed var(--accent);
  pointer-events: none;
}
.drop-overlay span { background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 1.3rem; padding: 14px 22px; border-radius: 14px; }
.map-loading { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 950; background: var(--text); color: var(--surface); padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: .9rem; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 3000; max-width: calc(100vw - 32px);
  background: var(--text); color: var(--surface);
  padding: 12px 18px; border-radius: 12px; font-weight: 650; box-shadow: var(--shadow);
}
.toast.is-error { background: var(--danger); color: #fff; }

/* ------------------------------------------------------------------ leaflet markers */

.leaflet-container { font-family: var(--font); background: var(--surface-2); }
/* Map controls use the app's tokens so they keep contrast in light and dark mode.
   (A blanket `.leaflet-container a { color: inherit }` made the zoom glyphs light-on-white in dark mode.) */
.leaflet-bar, .leaflet-touch .leaflet-bar { border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 12px; overflow: hidden; }
.leaflet-bar a, .leaflet-touch .leaflet-bar a {
  width: 44px; height: 44px; line-height: 44px;
  background: var(--surface); color: var(--text);
  border-bottom: 1px solid var(--border);
  font-size: 22px; font-weight: 700;
}
.leaflet-bar a:last-child { border-bottom: 0; }
.leaflet-bar a:hover, .leaflet-bar a:focus-visible { background: var(--surface-2); color: var(--text); }
.leaflet-bar a.leaflet-disabled { background: var(--surface-2); color: var(--muted); opacity: .6; }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 85%, transparent) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--text); }
.leaflet-popup-content a { color: inherit; }

.sf-marker span {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  font-weight: 850; font-size: 13px; color: #fff; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45);
}
.sf-marker.start span { background: #0f9d58; }
.sf-marker.finish span { background: #0f1115; }

.km-marker span {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; color: #0f1115; border: 2px solid #0f1115;
  font-size: 10px; font-weight: 800; font-variant-numeric: tabular-nums;
}

.sel-marker span {
  display: block; width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); border: 4px solid #fff;
  box-shadow: 0 0 0 3px rgba(15,17,21,.85), 0 3px 10px rgba(0,0,0,.4);
  cursor: grab;
}
.sel-marker:focus-visible { outline: none; }
.sel-marker:focus-visible span { box-shadow: 0 0 0 3px var(--focus), 0 3px 10px rgba(0,0,0,.4); }

.spot-marker { position: relative; }
.spot-marker .dot { position: absolute; inset: 0; border-radius: 50%; background: #1a5cff; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45); }
.spot-marker .lbl {
  position: absolute; left: 20px; top: 50%; transform: translateY(-50%);
  background: #fff; color: #0f1115; padding: 2px 8px; border-radius: 8px; white-space: nowrap;
  font-size: 12px; font-weight: 700; box-shadow: 0 1px 4px rgba(0,0,0,.3);
  max-width: 160px; overflow: hidden; text-overflow: ellipsis;
}

.pp { min-width: 150px; font-family: var(--font); }
.pp-km { font-weight: 850; font-size: 1.05rem; margin-bottom: 4px; }
.pp-row { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.pp-row span { color: #5b6270; }

/* ------------------------------------------------------------------ tablet and mobile */

@media (max-width: 900px) {
  .app { display: block; height: auto; min-height: 100dvh; }
  .app-header { position: sticky; top: 0; }
  .map-wrap { height: 55vh; height: 55svh; min-height: 300px; }
  /* Before a course is loaded the landing takes the map's place and grows with its content. */
  .app[data-state="EMPTY"] .map-wrap { height: auto; min-height: 0; }
  .app[data-state="EMPTY"] #map { display: none; }
  .app[data-state="EMPTY"] .empty-state { position: static; }
  .sidebar {
    border-right: 0; overflow: visible; padding: 0 12px 12px;
    display: grid; grid-template-columns: 1fr 1fr; align-items: start; gap: 12px;
  }
  .sidebar > * { grid-column: 1 / -1; }
  /* Result card as a bottom sheet pulled over the lower edge of the map. */
  .result {
    position: relative; z-index: 950; margin-top: -18px;
    border-radius: 20px 20px var(--radius) var(--radius);
    border-width: 0; border-top: 4px solid var(--accent);
    box-shadow: 0 -8px 24px rgba(0,0,0,.18);
  }
  .result::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--border); margin: -6px auto 10px; }
  .app[data-state="EMPTY"] .sidebar { padding-top: 12px; }
}

@media (min-width: 600px) and (max-width: 900px) {
  .sidebar > .card:not(.result) { grid-column: auto; }
  .sidebar > #points-card { grid-column: 1 / -1; }
}

@media (max-width: 599px) {
  .brand h1 { font-size: .98rem; }
  .app-header { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .brand { gap: 8px; }
  .brand-mark { width: 22px; height: 22px; }
  .header-actions { gap: 6px; }
  .app-header .btn-load span { display: none; }
  .app-header .btn-load { padding: 0 10px; }
  .app-header .btn-load svg { width: 20px; height: 20px; }
  .app-header .btn-load::after { content: "GPX"; font-size: .9rem; }
}

@media (max-width: 419px) {
  /* Narrow phones: upload becomes icon-only so the title fits. */
  .app-header .btn-load { width: 44px; padding: 0; }
  .app-header .btn-load::after { content: none; }
  .card { padding: 14px; }
  .km-value { font-size: 1.8rem; }
  .save-form { flex-direction: column; }
  .save-form .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
