/* ==========================================================================
   SketchMap — utility dashboard
   Left column: control panel. Right column: unobstructed map.
   Nothing floats over the map (keeps it readable, and keeps ads compliant).
   ========================================================================== */

:root {
  --bg:          #0b0f14;
  --panel:       #111820;
  --panel-2:     #161f2a;
  --line:        #23303e;
  --line-soft:   #1b2531;
  --text:        #e6edf5;
  --text-dim:    #93a4b8;
  --text-faint:  #64748b;
  --accent:      #38bdf8;
  --accent-ink:  #04212f;
  --ok:          #34d399;
  --error:       #f87171;
  --pin-a:       #34d399;
  --pin-b:       #f472b6;

  --panel-w: 360px;
  --radius: 10px;
  --radius-sm: 7px;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  color-scheme: dark;
}

/* Theme resolution, in precedence order:
   1. dark values above are the default
   2. system preference, only while no explicit choice is set
   3. an explicit day/night choice, which must beat the media query - so both
      selectors appear after it, including the night one that merely restates
      the defaults.
   An inline script in <head> stamps data-theme before first paint, so the
   page never flashes the wrong theme. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg:         #eef2f6;
    --panel:      #ffffff;
    --panel-2:    #f4f7fa;
    --line:       #d8e0e9;
    --line-soft:  #e6ecf2;
    --text:       #0f1b26;
    --text-dim:   #506274;
    --text-faint: #7b8b9c;
    --accent:     #0284c7;
    --accent-ink: #ffffff;
    --ok:         #059669;
    --error:      #dc2626;
    color-scheme: light;
  }
}

:root[data-theme="day"] {
  --bg:         #eef2f6;
  --panel:      #ffffff;
  --panel-2:    #f4f7fa;
  --line:       #d8e0e9;
  --line-soft:  #e6ecf2;
  --text:       #0f1b26;
  --text-dim:   #506274;
  --text-faint: #7b8b9c;
  --accent:     #0284c7;
  --accent-ink: #ffffff;
  --ok:         #059669;
  --error:      #dc2626;
  color-scheme: light;
}

:root[data-theme="night"] {
  --bg:         #0b0f14;
  --panel:      #111820;
  --panel-2:    #161f2a;
  --line:       #23303e;
  --line-soft:  #1b2531;
  --text:       #e6edf5;
  --text-dim:   #93a4b8;
  --text-faint: #64748b;
  --accent:     #38bdf8;
  --accent-ink: #04212f;
  --ok:         #34d399;
  --error:      #f87171;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Any element in this file that sets `display` would otherwise beat the
   `hidden` attribute's UA rule. The map's loading overlay is `display: flex`,
   so without this it never actually hides and covers the map. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

/* ── shell ───────────────────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  height: 100%;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: inherit;
}

.brand__mark {
  width: 18px; height: 18px;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--pin-a), var(--accent) 55%, var(--pin-b));
}

.brand__name {
  font-weight: 650;
  letter-spacing: -0.01em;
  font-size: 15px;
}

.panel__toggle { display: none; }

.panel__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.panel__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--text-faint);
}

.panel__foot nav { display: flex; gap: 12px; }
.panel__foot a { color: var(--text-dim); text-decoration: none; }
.panel__foot a:hover { color: var(--accent); text-decoration: underline; }

/* ── blocks ──────────────────────────────────────────────────────────── */

.block {
  padding: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.block__title {
  margin: 0 0 12px;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.block__header .block__title { margin-bottom: 0; }

/* ── fields ──────────────────────────────────────────────────────────── */

.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }

.field__label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

.field__label--row { justify-content: space-between; }
.field__label--row output { font-family: var(--mono); color: var(--text); font-size: 12px; }

.field__control {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.field__between {
  display: flex;
  justify-content: flex-end;
  margin: -4px 0 8px;
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex: none;
}
.dot--a { background: var(--pin-a); }
.dot--b { background: var(--pin-b); }

.input {
  flex: 1;
  min-width: 0;
  padding: 9px 11px;
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}

.input::placeholder { color: var(--text-faint); }

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.input--mono { font-family: var(--mono); font-size: 12px; }

select.input { appearance: none; cursor: pointer; padding-right: 28px; }

/* ── buttons ─────────────────────────────────────────────────────────── */

svg {
  width: 16px; height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn,
.ghost-btn,
.transport__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-dim);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color .12s, border-color .12s, background .12s;
}

.icon-btn { width: 34px; height: 34px; flex: none; }
.ghost-btn { padding: 5px 10px; font: inherit; font-size: 12px; background: none; border-color: transparent; }
.ghost-btn svg { width: 14px; height: 14px; }

.icon-btn:hover,
.ghost-btn:hover,
.transport__btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.icon-btn.is-done { color: var(--ok); border-color: var(--ok); }

.primary-btn {
  position: relative;
  width: 100%;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: filter .12s;
}

.primary-btn:hover:not(:disabled) { filter: brightness(1.08); }
.primary-btn:disabled { cursor: progress; opacity: .75; }
.primary-btn.is-busy .primary-btn__label { visibility: hidden; }
.primary-btn.is-busy .spinner { display: block; }

.spinner {
  display: none;
  position: absolute;
  inset: 0;
  margin: auto;
  width: 15px; height: 15px;
  border: 2px solid color-mix(in srgb, var(--accent-ink) 35%, transparent);
  border-top-color: var(--accent-ink);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── chips / segmented controls ──────────────────────────────────────── */

.chips { display: flex; gap: 6px; }

.chip {
  flex: 1;
  padding: 7px 4px;
  font: inherit;
  font-size: 12.5px;
  color: var(--text-dim);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color .12s, border-color .12s, background .12s;
}

.chip:hover { color: var(--text); }

.chip.is-active {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.units {
  display: inline-flex;
  padding: 2px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.units__btn {
  padding: 3px 9px;
  font: inherit;
  font-size: 11.5px;
  font-family: var(--mono);
  color: var(--text-faint);
  background: none;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}

.units__btn.is-active { color: var(--accent-ink); background: var(--accent); }

/* ── stats ───────────────────────────────────────────────────────────── */

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  background: var(--panel);
}

.stat__label {
  font-size: 10.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.stat__value {
  font-family: var(--mono);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ── playback ────────────────────────────────────────────────────────── */

.transport {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.transport__btn { width: 38px; height: 38px; }

.transport__btn--primary {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}
.transport__btn--primary:hover { color: var(--accent-ink); filter: brightness(1.08); }
.transport__btn--primary svg { fill: currentColor; stroke: none; }

.i-pause { display: none; }
.transport__btn.is-playing .i-play { display: none; }
.transport__btn.is-playing .i-pause { display: block; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}

.switch input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

.range {
  width: 100%;
  height: 4px;
  appearance: none;
  background: var(--line);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}

.range::-webkit-slider-thumb {
  appearance: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--panel);
  cursor: grab;
}

.range::-moz-range-thumb {
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--panel);
  cursor: grab;
}

/* ── autocomplete ────────────────────────────────────────────────────── */

.ac {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: 260px;
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 28px rgba(0, 0, 0, .35);
}

.ac__item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 7px 9px;
  border-radius: 5px;
  cursor: pointer;
}

.ac__item:hover,
.ac__item.is-active { background: color-mix(in srgb, var(--accent) 18%, transparent); }

.ac__main { font-size: 13px; color: var(--text); }
.ac__secondary { font-size: 11.5px; color: var(--text-faint); }

/* ── status / hints ──────────────────────────────────────────────────── */

.status {
  margin: 10px 0 0;
  min-height: 17px;
  font-size: 12px;
  color: var(--text-dim);
}
.status--ok { color: var(--ok); }
.status--error { color: var(--error); }

.hint {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--text-faint);
}

/* ── stop list ───────────────────────────────────────────────────────── */

.stops {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stop {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 7px;
  align-items: center;
}

.stop .input { padding: 8px 10px; }

.stop__badge {
  display: grid;
  place-items: center;
  width: 22px; height: 22px;
  font: 650 11px/1 var(--font);
  color: #04212f;
  background: var(--pin-a);
  border-radius: 50%;
  flex: none;
}

.stop__badge--via { background: var(--accent); }
.stop__badge--b { background: var(--pin-b); }

.field__label .stop__badge { margin-right: 6px; }

.stop__actions { display: flex; gap: 2px; }

.stop__btn {
  width: 22px; height: 26px;
  padding: 0;
  font: 400 15px/1 var(--font);
  color: var(--text-faint);
  background: none;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  transition: color .12s, background .12s;
}

.stop__btn:hover:not(:disabled) { color: var(--text); background: var(--panel-2); }
.stop__btn:disabled { opacity: .28; cursor: default; }

.stop-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 8px 0 12px;
}

.stop-actions .ghost-btn { border-color: var(--line); }
.stop-actions .ghost-btn:disabled { opacity: .4; cursor: default; }

/* ── leg breakdown ───────────────────────────────────────────────────── */

.legs {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.leg {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 11px;
  background: var(--panel);
  font-size: 12.5px;
}

.leg__route {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--text-dim);
}

.leg__figures {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ── collapsible control groups ──────────────────────────────────────── */

.group {
  border-bottom: 1px solid var(--line-soft);
}

.group__summary {
  padding: 13px 16px;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-faint);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.group__summary::-webkit-details-marker { display: none; }

.group__summary::after {
  content: '';
  width: 7px; height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform .15s;
}

.group[open] > .group__summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
.group__summary:hover { color: var(--text-dim); }
.group__body { padding: 0 16px 16px; }

.checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 10px;
  margin-top: 8px;
}

.switch--block {
  display: flex;
  margin-bottom: 10px;
}

.progress-bar {
  height: 4px;
  margin-top: 10px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .18s linear;
}

/* ── on-map stats overlay ────────────────────────────────────────────── */

.map-stats {
  position: absolute;
  left: 16px;
  bottom: 26px;
  z-index: 4;
  display: flex;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .35);
}

.map-stats__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 14px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(6px);
}

.map-stats__item span {
  font-size: 9.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.map-stats__item strong {
  font-family: var(--mono);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}

/* ── ads ─────────────────────────────────────────────────────────────── */

.ad { padding: 16px; }

.ad__label {
  display: block;
  margin-bottom: 6px;
  font-size: 9.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.ad__frame { min-height: 250px; }

.ad__placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 250px;
  text-align: center;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--text-faint);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
}

/* ── map canvas ──────────────────────────────────────────────────────── */

.canvas {
  position: relative;
  min-width: 0;
  background: var(--panel-2);
}

#map { position: absolute; inset: 0; }

.canvas__overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.canvas__msg {
  max-width: 42ch;
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
}

.canvas__overlay.is-error .canvas__msg { color: var(--error); }

/* Map overlay content — injected by the renderer, so these live at :root. */
.pp-pin {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  font: 650 12px/1 var(--font);
  color: #04212f;
  background: var(--pin-a);
  border: 2px solid rgba(255, 255, 255, .92);
  border-radius: 50%;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .45);
}
.pp-pin--b { background: var(--pin-b); }

/* Leading marker for the completion trail. --head-color is set by the
   renderer so the marker always matches the trail colour. */
.pp-head {
  --head-color: var(--accent);
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--head-color);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .5);
}

.pp-head--pulse {
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--head-color) 28%, transparent),
              0 2px 10px rgba(0, 0, 0, .5);
  animation: pp-pulse 1.6s ease-out infinite;
}

.pp-head--dot {
  background: var(--head-color);
  border-color: rgba(255, 255, 255, .9);
}

.pp-head--ring {
  background: transparent;
  border-width: 4px;
  width: 18px; height: 18px;
}

@keyframes pp-pulse {
  0%   { box-shadow: 0 0 0 3px color-mix(in srgb, var(--head-color) 45%, transparent), 0 2px 10px rgba(0,0,0,.5); }
  70%  { box-shadow: 0 0 0 14px color-mix(in srgb, var(--head-color) 0%, transparent), 0 2px 10px rgba(0,0,0,.5); }
  100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--head-color) 0%, transparent), 0 2px 10px rgba(0,0,0,.5); }
}

/* A/B marker: optional banner stacked above the pin. The marker's bottom
   centre is what Maps anchors to the coordinate, so the pin must come last. */
.pp-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.pp-banner {
  max-width: 220px;
  padding: 4px 9px;
  font: 600 12px/1.35 var(--font);
  color: #e9f1f8;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: rgba(9, 14, 20, .88);
  border: 1.5px solid var(--pin-a);
  border-radius: 6px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, .45);
}

.pp-banner--via { border-color: var(--accent); }
.pp-banner--b { border-color: var(--pin-b); }

.pp-pin--via {
  width: 21px; height: 21px;
  font-size: 10.5px;
  background: var(--accent);
}

.noscript {
  padding: 16px;
  text-align: center;
  background: var(--error);
  color: #fff;
}

/* ── static document pages ───────────────────────────────────────────── */

.doc {
  max-width: 72ch;
  margin: 0 auto;
  padding: 40px 24px 72px;
}

.doc__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  margin-bottom: 32px;
  border-bottom: 1px solid var(--line);
}

.doc__head nav { display: flex; gap: 14px; font-size: 13px; }
.doc h1 { font-size: 26px; letter-spacing: -0.02em; margin: 0 0 6px; }
.doc h2 { font-size: 16px; margin: 32px 0 8px; }
.doc p, .doc li { color: var(--text-dim); }
.doc a { color: var(--accent); }
.doc ul { padding-left: 20px; }
.doc code { font-family: var(--mono); font-size: 12.5px; color: var(--text); }
.doc__meta { font-size: 12px; color: var(--text-faint); }
.doc__foot {
  margin-top: 48px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--text-faint);
}

/* ── mobile ──────────────────────────────────────────────────────────── */

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 62vh;
  }

  .panel__toggle {
    display: inline-block;
    padding: 6px 12px;
    font: inherit;
    font-size: 12px;
    color: var(--text-dim);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    cursor: pointer;
  }

  .panel__body,
  .panel__foot { display: none; }

  body.panel-open .panel__body { display: block; }
  body.panel-open .panel__foot { display: flex; }

  .ad__frame, .ad__placeholder { min-height: 100px; height: auto; }
  .ad__placeholder { padding: 24px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}
