:root {
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f8fafc;
  --accent: #2563eb;
  --danger: #b91c1c;
  --panel-width: 340px;
  --topbar-height: 52px;
}

* { box-sizing: border-box; }

/* A class that sets `display` silently beats the UA's `[hidden]` rule, which
   is how an empty toast ended up on screen showing a bare "Dismiss" button.
   Everything in this app is shown and hidden via the `hidden` attribute, so
   the attribute wins outright. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; text-decoration: none; color: var(--ink); }
.brand span { color: var(--accent); }

.topbar nav { display: flex; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 18px; }
.inline { display: inline; margin: 0; }

/* Units switch — global, so the choice is one click away from any page. */
.unit-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.unit-switch button {
  border: none;
  border-radius: 0;
  padding: 4px 12px;
  font-size: 13px;
  color: var(--muted);
  background: #fff;
}
.unit-switch button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.unit-switch button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

button, .button {
  font: inherit;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button { display: inline-block; text-decoration: none; }

.linkish {
  border: none;
  background: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
}
.linkish.danger { color: var(--danger); }

/* --- editor / share layout ------------------------------------------------ */

.editor {
  display: flex;
  height: calc(100vh - var(--topbar-height));
}

.map-wrap { flex: 1; min-width: 0; position: relative; }
#map { position: absolute; inset: 0; }

/* Place search, floating over the map */
.map-search { position: absolute; top: 12px; left: 12px; width: min(320px, calc(100% - 70px)); z-index: 5; }
.map-search input {
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.12);
}
.search-results {
  list-style: none;
  margin: 4px 0 0;
  padding: 4px;
  max-height: 260px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
}
.search-results li { padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.search-results li:hover, .search-results li.highlight { background: #eff6ff; }

.panel {
  width: var(--panel-width);
  flex: 0 0 var(--panel-width);
  padding: 16px;
  overflow-y: auto;
  background: #fff;
  border-left: 1px solid var(--line);
}

.panel section { margin-bottom: 18px; }

.route-title { font-size: 18px; margin: 0 0 8px; }

.distance { display: flex; align-items: baseline; gap: 6px; }
.distance .value { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.distance .unit { font-size: 15px; color: var(--muted); }
.climb { color: var(--muted); font-size: 13px; }
.climb [data-unit-label] { margin-left: 2px; }

.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: #cbd5e1; stroke-width: 1; }
.chart .area { fill: rgba(37, 99, 235, 0.16); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .cursor { stroke: var(--ink); stroke-width: 1; }
.chart .tick { font-size: 9px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .axis-label { font-size: 9px; fill: var(--muted); font-weight: 600; }
.chart-readout { font-size: 12px; color: var(--muted); min-height: 18px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.save-form label, .share-box label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.save-form input[type="text"], .share-box input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 7px 9px;
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.visibility { display: flex; align-items: center; gap: 8px; color: var(--ink) !important; }

.nearby-head { display: flex; align-items: center; justify-content: space-between; }
.nearby h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0; }
.switch { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }

#nearby-list { list-style: none; margin: 8px 0 0; padding: 0; }
#nearby-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.dist { color: var(--muted); font-variant-numeric: tabular-nums; }

.toast {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: 6px;
  font-size: 13px;
}

.hint { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-size: 13px; }

/* --- pages ---------------------------------------------------------------- */

.page { max-width: 820px; margin: 32px auto; padding: 0 16px; }
.page.narrow { max-width: 380px; }
.empty { color: var(--muted); }

.route-list { list-style: none; padding: 0; }
.route-row {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.route-row .rename { display: flex; gap: 8px; align-items: center; }
.route-row .rename input {
  flex: 1;
  padding: 6px 8px;
  font: inherit;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
}
.route-row .rename input:focus { border-color: var(--line); background: #fff; }
.route-row .meta { display: flex; gap: 12px; font-size: 13px; color: var(--muted); margin: 4px 0; }
.vis.private { color: var(--danger); }
.row-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; font-size: 13px; }
.row-actions form { display: inline; }

/* --- auth modal ----------------------------------------------------------- */

.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 20; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.45); }
.modal-card {
  position: relative;
  width: min(380px, calc(100vw - 32px));
  padding: 22px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
}
.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: none;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
}

.auth-tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.auth-tabs button { flex: 1; }
.auth-tabs button.active { border-color: var(--accent); color: var(--accent); }
.auth-lede { font-size: 13px; color: var(--muted); }
.auth-form label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.auth-form input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.auth-form button[type="submit"] { width: 100%; }

.share-cta { border-top: 1px solid var(--line); padding-top: 14px; }

@media (max-width: 720px) {
  .editor { flex-direction: column; height: auto; }
  .map-wrap { height: 55vh; flex: none; }
  .panel { width: 100%; flex: none; border-left: none; border-top: 1px solid var(--line); }
  .topbar-right { gap: 12px; }
}
