:root {
  --midnight: #0B0D14;
  --crypt: #141826;
  --crypt-2: #121622;
  --line: #1E2436;
  --line-2: #2A3147;
  --ghost: #E8EAF2;
  --soft: #C9CEDC;
  --muted: #9AA3B8;
  --faint: #6B7389;
  --accent: #FF7A1A;
  --accent-ink: #140A02;
  --danger: #FF6B6B;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--midnight);
  color: var(--ghost);
  font: 400 15px/1.45 'Space Grotesk', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
svg { flex: none; }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.ghost { width: 32px; height: 32px; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ghost circle { fill: var(--accent); stroke: none; }
.wordmark { font-family: 'Creepster', cursive; font-size: 32px; letter-spacing: 1px; color: var(--accent); line-height: 1; }
.tagline { color: var(--muted); font-size: 13px; flex: 1; min-width: 160px; }
.top-actions { display: flex; gap: 8px; }

.banner { padding: 10px 20px; background: #1C1530; color: #D9CCFF; font-size: 14px; border-bottom: 1px solid #2E2450; }

/* Buttons */
.btn {
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line-2);
  background: transparent; color: var(--ghost); font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
.btn:hover { border-color: #3A4260; }
.btn:focus-visible, .link-btn:focus-visible, input:focus-visible, select:focus-visible, .segmented button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.big { width: 100%; min-height: 52px; font-size: 17px; }
.btn.dashed { border-style: dashed; color: var(--soft); width: 100%; }
.btn.dashed svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.btn.dashed[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); border-style: solid; background: rgba(255,122,26,.08); }
.link-btn { background: none; border: none; color: var(--accent); padding: 6px 0; min-height: 32px; cursor: pointer; align-self: flex-start; font-size: 14px; }

/* Layout */
.layout { flex: 1; display: flex; min-height: 0; }
.panel {
  width: 420px; flex: none; overflow-y: auto; padding: 20px 20px 40px;
  border-right: 1px solid var(--line);
}
.panel > section { display: flex; flex-direction: column; gap: 18px; }
.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; z-index: 0; background: #0E111B; }

@media (max-width: 820px) {
  body { min-height: auto; }
  .layout { flex-direction: column; }
  .map-wrap { order: -1; height: 46vh; min-height: 300px; flex: none; }
  .panel { width: auto; border-right: none; overflow: visible; }
  .tagline { display: none; }
  .topbar { padding: 10px 14px; }
  .wordmark { font-size: 26px; }
  .top-actions .btn { padding: 0 12px; font-size: 14px; }
}

/* Form bits */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
label, .label { font-size: 12px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--muted); }
input[type="text"], select {
  width: 100%; min-height: 46px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line-2); background: var(--crypt); color: var(--ghost); font-size: 16px;
}
input::placeholder { color: #8891A7; }
select { appearance: none; padding-right: 30px; font-size: 15px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 20px, calc(100% - 11px) 20px; background-size: 5px 5px; background-repeat: no-repeat; }
.settings { display: flex; flex-direction: column; gap: 14px; padding: 14px; border-radius: 14px; background: var(--crypt-2); border: 1px solid var(--line); }
.row { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; border-radius: 12px; background: var(--midnight); border: 1px solid var(--line); }
.segmented button { min-height: 40px; border-radius: 8px; border: none; background: transparent; color: var(--muted); cursor: pointer; }
.segmented button[aria-checked="true"] { background: #262C40; color: #fff; font-weight: 700; }

.search-wrap { position: relative; }
.results {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none;
  background: var(--crypt); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.5);
  max-height: 280px; overflow-y: auto;
}
.results li { padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.results li[aria-selected="true"], .results li:hover { background: #222840; }
.results li.none { color: var(--muted); cursor: default; }

.status { margin: -6px 0 0; min-height: 1em; font-size: 14px; color: var(--soft); }
.status.error { color: var(--danger); }

/* Lists */
.list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.list-head h2 { margin: 0; font-size: 20px; }
.muted { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); font-size: 14px; margin: 0; }
#nightsList { display: flex; flex-direction: column; gap: 14px; }

.night { border-radius: 14px; background: var(--crypt-2); border: 1px solid var(--line); overflow: hidden; }
.night.drop-target { border-color: var(--c); box-shadow: 0 0 0 1px var(--c); }
.night-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c, #5A637C); box-shadow: 0 0 10px var(--c, transparent); flex: none; }
.night-name { font-weight: 700; font-size: 16px; }
.night-stats { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--soft); margin-left: auto; }
.night-stats.over { color: var(--danger); }
.night-foot { padding: 8px 14px 14px; }
.night-foot .btn { width: 100%; border-color: var(--c); color: var(--c); }

.houses { list-style: none; margin: 0; padding: 4px 0; }
.house { display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 14px; min-height: 48px; }
.house[draggable="true"] { cursor: grab; }
.house.dragging { opacity: .4; }
.num {
  width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--c, #5A637C); color: var(--c, var(--soft));
  display: flex; align-items: center; justify-content: center; font: 500 12px 'JetBrains Mono', monospace; flex: none;
}
.house-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.house-addr { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who {
  border: none; background: transparent; color: var(--muted); padding: 0; min-height: 24px; font-size: 13px; width: 100%;
}
.who:focus { outline: none; color: var(--ghost); border-bottom: 1px solid var(--line-2); }
.move { width: auto; min-height: 36px; font-size: 13px; padding: 0 26px 0 8px; background-position: calc(100% - 14px) 15px, calc(100% - 9px) 15px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 8px; border: none; background: transparent; color: var(--faint);
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex: none;
}
.icon-btn:hover { color: var(--danger); background: #1C2030; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* Drive mode */
.drive-head { display: flex; align-items: center; gap: 10px; }
.drive-head h2 { margin: 0; font-size: 22px; }
.next-card { padding: 18px; border-radius: 16px; background: var(--crypt); border: 1px solid var(--c, var(--accent)); display: flex; flex-direction: column; gap: 4px; }
.next-addr { font-size: 24px; font-weight: 700; line-height: 1.2; }
.next-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.next-actions .btn { min-height: 50px; }
.drive-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.drive-list li { display: flex; align-items: center; gap: 12px; padding: 10px 4px; min-height: 48px; border-bottom: 1px solid var(--line); }
.drive-list li.done { color: var(--faint); }
.drive-list li.done .house-addr { text-decoration: line-through; }
.drive-list li.current { color: #fff; font-weight: 700; }
.drive-list button { margin-left: auto; }
.check svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Map overlays */
.map-stats {
  position: absolute; top: 14px; left: 14px; z-index: 5; display: flex; gap: 20px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: 14px; background: rgba(11,13,20,.88); border: 1px solid #262C40; max-width: calc(100% - 28px);
}
.map-stats .v { font: 500 20px 'JetBrains Mono', monospace; color: #fff; }
.map-stats .k { font-size: 12px; color: var(--muted); }
.style-picker {
  position: absolute; left: 14px; bottom: 14px; z-index: 5; display: flex; gap: 4px; padding: 4px;
  border-radius: 12px; background: rgba(11,13,20,.88); border: 1px solid #262C40;
}
.style-picker button {
  min-height: 36px; padding: 0 12px; border: none; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 13px; cursor: pointer;
}
.style-picker button[aria-checked="true"] { background: #262C40; color: #fff; font-weight: 700; }
.style-picker button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 820px) { .style-picker button { padding: 0 10px; } }
.pin-hint {
  position: absolute; bottom: 70px; left: 50%; transform: translateX(-50%); z-index: 5; max-width: calc(100% - 28px);
  padding: 10px 16px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 14px; text-align: center;
}

.marker-stop {
  width: 28px; height: 28px; border-radius: 50%; background: var(--midnight); border: 2.5px solid var(--c, #8891A7);
  color: var(--c, #C9CEDC); font: 500 12px 'JetBrains Mono', monospace; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 12px var(--c, transparent); cursor: pointer;
}
.marker-stop.done { opacity: .45; }
.marker-stop.next { width: 34px; height: 34px; background: var(--c); color: var(--midnight); font-size: 14px; }
.marker-home {
  width: 36px; height: 36px; border-radius: 10px; background: var(--ghost); display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 3px var(--midnight), 0 4px 16px rgba(0,0,0,.6);
}
.marker-home svg { width: 22px; height: 22px; fill: none; stroke: var(--midnight); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.maplibregl-ctrl-group { background: var(--crypt) !important; border: 1px solid var(--line-2); }
.maplibregl-ctrl-group button + button { border-top-color: var(--line-2) !important; }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1) brightness(.9); }
.maplibregl-ctrl-attrib { background: rgba(11,13,20,.8) !important; color: var(--muted); }
.maplibregl-ctrl-attrib a { color: var(--soft); }
.maplibregl-ctrl-attrib-button { filter: invert(1); }
.maplibregl-popup-content { background: var(--crypt); color: var(--ghost); border-radius: 10px; font-size: 14px; }
.maplibregl-popup-tip { border-top-color: var(--crypt) !important; border-bottom-color: var(--crypt) !important; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  padding: 12px 18px; border-radius: 12px; background: var(--ghost); color: var(--midnight); font-weight: 700; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}

@media (prefers-reduced-motion: no-preference) {
  .marker-stop.next { animation: pulse 1.6s ease-in-out infinite; }
  @keyframes pulse { 50% { box-shadow: 0 0 24px var(--c); } }
}
