    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
    :root {
      --blue: #2563eb; --red: #ef4444;
      /* Urgency colours (cards, banner, legend); the map paint lives in core.js URGENCY. */
      --urg-today: #ef4444; --urg-tomorrow: #f97316; --urg-safe: #2563eb;
      --bg: #f8fafc; --card: #ffffff; --text: #1e293b;
      --muted: #64748b; --border: #e2e8f0;
      --sheet-peek: 40px;  /* collapsed bottom-sheet handle height */
      --panel-w: min(360px, calc(100vw - 24px));  /* info card + sheet width (mobile) */
      --inset-b: env(safe-area-inset-bottom, 0px);
      --info-h: 0px;  /* info card height, set from JS */

      /* Layers: crosshair 15 < info card, place banner 20 < sheet 25 < GPS popup 30
         < hover 90 < ctx menu 200 < toast 9999. */
    }
    html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
    /* Keep map drags from scrolling/rubber-banding the page behind it. */
    html, body { overflow: hidden; overscroll-behavior: none; }

    [hidden] { display: none !important; }
    button { display: block; width: 100%; padding: 10px; margin-top: 16px; background: var(--blue); color: #fff; border: none; border-radius: 10px; font-size: .95rem; font-weight: 600; cursor: pointer; transition: opacity .15s; }
    button:disabled { opacity: .5; cursor: default; }
    button:not(:disabled):hover { opacity: .9; }

    /* ── App ── */
    #app-screen { display: flex; flex-direction: column; height: 100dvh; }

    /* ── Topbar ── */
    #topbar {
      display: flex; align-items: center; gap: 5px;
      padding: calc(6px + env(safe-area-inset-top, 0px)) max(10px, env(safe-area-inset-right, 0px))
              6px max(10px, env(safe-area-inset-left, 0px)); background: var(--card);
      border-bottom: 1px solid var(--border); flex-shrink: 0;
      overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch;
    }
    .app-title { font-size: .88rem; font-weight: 700; flex-shrink: 0; }
    .tb-sep { width: 1px; height: 18px; background: var(--border); flex-shrink: 0; align-self: center; margin: 0 3px; }
    .tb-select, .tb-btn {
      display: inline-flex; align-items: center; width: auto;
      height: 26px; box-sizing: border-box; padding: 0 8px; margin: 0;
      font-size: .78rem; font-weight: 600; border-radius: 6px; flex-shrink: 0;
    }
    .tb-select { border: 1px solid var(--border); background: var(--bg); color: var(--text); outline: none; }
    #region-select { max-width: 90px; }
    #status-text   { flex: 1; font-size: .78rem; font-weight: 600; text-align: center; padding: 0 4px; overflow: hidden; text-overflow: ellipsis; min-width: 60px; }
    #status-text.today    { color: #b91c1c; }
    #status-text.tomorrow { color: #c2410c; }
    #status-text.safe     { color: #1d4ed8; }
    #status-text.idle     { color: var(--muted); }
    #btn-locate        { background: var(--card); color: var(--muted); border: 1px solid var(--border); }
    #btn-locate.ip     { background: #eef1f7; color: #94a3b8; border-color: #d1d9ea; }
    #btn-locate.gps    { background: var(--blue); color: #fff; border-color: var(--blue); }
    #locate-info { font-size: .72rem; color: var(--muted); flex-shrink: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }

    /* ── Map container ── */
    #map-container { flex: 1; min-height: 0; position: relative; }
    #map { width: 100%; height: 100%; touch-action: none; }
    #map canvas, #map img { -webkit-user-drag: none; user-select: none; }

    /* ── MapLibre attribution ── */
    .maplibregl-ctrl-bottom-right,
    .maplibregl-ctrl-bottom-left { display: none !important; }

    /* ── Place banner (tap-to-place mode) ── */
    #place-banner {
      position: absolute; bottom: calc(var(--inset-b) + 12px + var(--sheet-peek) + 8px);
      left: 50%; transform: translateX(-50%);
      z-index: 20; display: none; align-items: center; gap: 8px;
      background: rgba(37,99,235,.92); color: #fff;
      border-radius: 20px; padding: 7px 14px;
      font-size: .82rem; font-weight: 600;
      box-shadow: 0 2px 12px rgba(0,0,0,.25);
      white-space: nowrap; pointer-events: auto;
    }
    #place-banner.active { display: flex; }
    #btn-confirm-place, #btn-cancel-place {
      width: auto; margin: 0; padding: 3px 12px; border-radius: 12px;
      font-size: .75rem; font-weight: 600;
    }
    #btn-confirm-place { background: #fff; color: var(--blue); border: none; }
    #btn-cancel-place {
      background: rgba(255,255,255,.2); color: #fff;
      border: 1px solid rgba(255,255,255,.4); font-weight: 500;
    }

    /* ── Context menu (right-click) ── */
    #ctx-menu, #account-menu {
      position: fixed; z-index: 200; display: none;
      background: var(--card); border: 1px solid var(--border);
      border-radius: 10px; box-shadow: 0 4px 14px rgba(0,0,0,.14);
      overflow: hidden; min-width: 140px;
    }
    .ctx-item { padding: 7px 14px; cursor: pointer; font-size: .85rem; }
    .ctx-item:hover { background: var(--bg); }
    .ctx-item.ctx-note { color: var(--muted); cursor: default; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .ctx-item.ctx-note:hover { background: none; }
    #btn-account.signed-in { background: var(--blue); color: #fff; border: 1px solid var(--blue); }
    #btn-account:not(.signed-in) { background: var(--card); color: var(--muted); border: 1px solid var(--border); }

    /* ── Bottom sheet (cars & homes) ──
       Mobile: floating card, bottom-center, clear of the home indicator, same width
       as the info card. Collapses to a handle so the map and target stay clear. */
    #sheet {
      position: absolute; left: 50%; bottom: calc(var(--inset-b) + 12px); transform: translateX(-50%);
      z-index: 25; width: var(--panel-w);
      display: flex; flex-direction: column;
      background: var(--card); border: 1px solid var(--border);
      border-radius: 14px;
      box-shadow: 0 3px 16px rgba(0,0,0,.2);
      /* Stays below the info card (top of the map) so the two never overlap. */
      max-height: min(62%, calc(100% - var(--info-h) - var(--inset-b) - 44px));
      pointer-events: auto;
    }
    #sheet-handle {
      flex-shrink: 0; display: flex; align-items: center; gap: 8px;
      padding: 7px 14px 8px; cursor: pointer; user-select: none;
      position: relative;
    }
    #sheet-grip {
      position: absolute; top: 5px; left: 50%; transform: translateX(-50%);
      width: 34px; height: 4px; border-radius: 2px; background: var(--border);
    }
    #sheet-summary { flex: 1; font-size: .8rem; font-weight: 600; color: var(--text); padding-top: 3px; }
    #sheet-chevron { font-size: .8rem; color: var(--muted); padding-top: 3px; transition: transform .15s; }
    #sheet.collapsed #sheet-chevron { transform: rotate(180deg); }
    #sheet.collapsed #cars-panel { display: none; }

    #cars-panel {
      display: flex; flex-direction: column; gap: 8px;
      padding: 0 12px 12px; overflow-y: auto;
      pointer-events: auto; scrollbar-gutter: stable;
    }
    .cars-legend {
      background: var(--bg); border: 1px solid var(--border);
      border-radius: 8px; padding: 6px 10px; overflow: hidden;
      font-size: .7rem; display: flex; gap: 8px; flex-wrap: wrap;
      box-shadow: 0 2px 6px rgba(0,0,0,.08);
      user-select: none; width: 100%; flex-shrink: 0;
    }
    .cars-legend span { white-space: nowrap; font-weight: 500; }
    .urg-today { color: var(--urg-today); } .urg-tomorrow { color: var(--urg-tomorrow); }
    .urg-safe { color: var(--urg-safe); }
    .car-entry {
      position: relative;
      background: var(--card); border: 1px solid var(--border);
      border-radius: 10px; padding: 10px 12px; overflow: hidden;
      box-shadow: 0 2px 10px rgba(0,0,0,.10);
      width: 100%; flex-shrink: 0; display: flex; flex-direction: column; gap: 5px;
      cursor: pointer; transition: border .12s, background .12s;
    }
    .car-entry.selected {
      border: 2px solid var(--car-color);
      padding: 9px 11px;
    }
    /* Urgency tint — theme-aware (light vs dark) so text stays readable. */
    .car-entry[data-urgency="today"]    { background: #fee2e2; }
    .car-entry[data-urgency="tomorrow"] { background: #ffedd5; }
    body.dark .car-entry[data-urgency="today"]    { background: #3b2020; }
    body.dark .car-entry[data-urgency="tomorrow"] { background: #3b2e1a; }
    .ce-header { display: flex; align-items: center; gap: 6px; padding-right: 16px; }
    .ce-dot {
      width: 10px; height: 10px; border-radius: 50%;
      background: var(--car-color, #3b82f6); flex-shrink: 0;
    }
    .ce-name {
      flex: 1; font-weight: 600; font-size: .84rem; outline: none;
      cursor: default; border-bottom: 1px solid transparent; min-width: 0;
      user-select: none;
    }
    .ce-name[contenteditable="true"] { cursor: text; border-bottom-color: var(--blue); user-select: text; }
    .ce-remove {
      position: absolute; top: 6px; right: 8px;
      width: 18px; height: 18px; margin: 0; padding: 0;
      display: flex; align-items: center; justify-content: center;
      background: transparent; border: none; color: var(--muted);
      font-size: .8rem; cursor: pointer; opacity: .55; line-height: 1;
    }
    .ce-remove:hover { opacity: 1; color: var(--red); }
    .ce-addr {
      font-size: .75rem; color: var(--muted); outline: none;
      cursor: default; border-bottom: 1px solid transparent; min-height: 1em;
      user-select: none;
    }
    .ce-addr[contenteditable="true"] { cursor: text; color: var(--text); border-bottom-color: var(--blue); user-select: text; }
    .ce-addr:empty::before { content: 'double-click to set address'; opacity: .45; font-size: .7rem; }
    .ce-sched { font-size: .73rem; line-height: 1.45; }
    .ce-sched-urgency { font-weight: 600; }
    .ce-sched-header  { font-size: .68rem; font-weight: 600; color: var(--muted); margin-top: 4px; white-space: nowrap; }
    .ce-sched-item    { font-size: .73rem; color: var(--muted); padding-left: 4px; line-height: 1.4; }
    .ce-actions { display: flex; gap: 5px; margin-top: 3px; }
    .ce-btn {
      flex: 1; width: auto; margin: 0; padding: 4px 6px;
      font-size: .71rem; font-weight: 500; border-radius: 6px; white-space: nowrap;
      background: transparent; border: 1px solid var(--border);
      color: var(--text); cursor: pointer; text-align: center;
    }
    .ce-btn:hover { background: var(--bg); }

    /* ── GPS pin popup (add car here) ── */
    #gps-pin-popup {
      position: absolute; z-index: 30; display: none;
      align-items: center; gap: 6px;
      background: var(--card); border: 1px solid var(--border); border-radius: 10px;
      padding: 8px 8px; box-shadow: 0 2px 10px rgba(0,0,0,.14);
      transform: translate(-50%, calc(-100% - 24px));
      white-space: nowrap; overflow: visible;
    }
    #btn-gps-add { width: auto; margin: 0; padding: 4px 10px; font-size: .76rem; font-weight: 600; border-radius: 6px; }
    /* Shared top-right corner close button for popups/boxes. */
    .popup-close {
      position: absolute; top: 4px; right: 4px;
      width: 20px; height: 20px; margin: 0; padding: 0;
      display: flex; align-items: center; justify-content: center;
      background: transparent; border: none; color: var(--muted);
      font-size: .85rem; line-height: 1; cursor: pointer; border-radius: 5px;
    }
    .popup-close:hover { background: var(--bg); color: var(--text); }
    /* Inline variant: ✕ rides the far right of a flex row instead of reserving
       a top strip of its own. */
    .popup-close.inline-close { position: static; flex: 0 0 auto; margin-left: 2px; }

    /* ── Name box (arrow popup anchored at the new car's spot) ── */
    .name-popup .maplibregl-popup-content {
      background: var(--card); border: 1px solid var(--border);
      border-radius: 10px; padding: 8px;
      box-shadow: 0 4px 14px rgba(0,0,0,.18); min-width: 220px;
    }
    .name-popup .maplibregl-popup-tip {
      border-top-color: var(--card); border-bottom-color: var(--card);
    }
    .np-row { display: flex; gap: 6px; align-items: center; }
    #name-panel-input { flex: 1; padding: 4px 7px; border: 1px solid var(--border); border-radius: 6px; font-size: .85rem; outline: none; min-width: 0; width: 0; background: var(--bg); color: var(--text); }
    #name-panel-input:focus { border-color: var(--blue); }
    #btn-np-save { margin: 0; padding: 4px 8px; width: auto; min-width: 30px; border-radius: 6px; font-size: 1rem; line-height: 1; font-weight: 700; }

    /* ── + Add car button (cars panel) ── */
    .add-car-btn {
      width: 100%; flex-shrink: 0; margin: 0; padding: 8px 12px;
      background: var(--blue); color: #fff; border: none; border-radius: 10px;
      font-size: .82rem; font-weight: 600; cursor: pointer;
      box-shadow: 0 2px 10px rgba(0,0,0,.12);
    }
    .add-car-btn:hover { opacity: .92; }
    /* "Add home" shares the add-car shape but takes the home green. */
    .add-home-btn { background: #16a34a; }

    /* ── Info card: street under the target + sweep calendar ──
       Mobile: top-center of the map. Desktop: bottom-left (see media query). */
    #info-card {
      position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
      z-index: 20; width: var(--panel-w); pointer-events: auto;
      background: var(--card); color: var(--text);
      border: 1px solid var(--border); border-radius: 12px;
      box-shadow: 0 3px 12px rgba(0,0,0,.22); font-size: .8rem;
      padding: 0 12px 10px; cursor: pointer;
    }
    #info-card.expanded { cursor: default; }
    #ic-head {
      display: flex; align-items: center; gap: 8px; user-select: none;
      padding: 8px 0 6px; font-weight: 600; font-size: .8rem;
    }
    #info-card.expanded #ic-head { cursor: pointer; }
    #ic-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #ic-chevron { color: var(--muted); font-size: .8rem; transition: transform .15s; }
    #info-card.expanded #ic-chevron { transform: rotate(180deg); }
    #ic-lines { margin-bottom: 6px; max-height: 5.6em; overflow-y: auto; }
    .sc-line { font-size: .74rem; line-height: 1.4; white-space: nowrap; overflow-x: auto; scrollbar-width: none; }
    .sc-line::-webkit-scrollbar { display: none; }
    .sc-muted, .cal-muted { font-size: .72rem; color: var(--muted); }

    .sw-strip { display: grid; grid-template-columns: repeat(14, 1fr); gap: 2px; }
    .sw-cell, .cal-day {
      display: flex; flex-direction: column; align-items: center; justify-content: center;
      border-radius: 4px; font-size: .62rem; line-height: 1.15; color: var(--text);
      font-variant-numeric: tabular-nums;
    }
    .sw-cell { padding: 1px 0; }
    .sw-cell i { font-style: normal; font-size: .52rem; color: var(--muted); }
    .sw-day { background: var(--red); color: #fff; }
    .sw-day i { color: #fff; opacity: .85; }
    .sw-today { font-weight: 700; outline: 2px solid var(--blue); outline-offset: -1px; }
    /* One dot per car with sweeping that day, in the car's colour. */
    .cal-dots { display: flex; justify-content: center; gap: 2px; height: 5px; margin-top: 1px; }
    .cal-dot { width: 5px; height: 5px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(255,255,255,.9); }

    .cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
    .cal-nav, .cal-day {
      width: auto; margin: 0; padding: 0; border: none; border-radius: 4px;
      background: transparent; cursor: pointer; font: inherit; color: inherit;
    }
    .cal-nav { font-size: 1.1rem; padding: 0 8px; color: var(--muted); }
    .cal-nav:hover { color: var(--text); }
    .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; text-align: center; }
    .cal-wd { font-size: .62rem; color: var(--muted); font-weight: 600; }
    .cal-day { font-size: .75rem; aspect-ratio: 1.5; min-width: 0; }
    .cal-day.cal-out { opacity: .4; }
    .cal-day.cal-sel { text-decoration: underline; text-underline-offset: 2px; font-weight: 700; }
    .cal-detail { margin-top: 6px; font-size: .74rem; line-height: 1.4; max-height: 6.5em; overflow-y: auto; }
    .cal-legend { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: .68rem; color: var(--muted); margin-top: 4px; }
    .cal-key { display: inline-block; width: 9px; height: 9px; border-radius: 2px; vertical-align: -1px; margin-right: 4px; }
    .cal-round { border-radius: 50%; }
    /* Short phones: tighter month grid keeps the card above the center target. */
    @media (max-height: 740px) {
      .cal-day { aspect-ratio: 2.1; }
      .cal-detail { max-height: 3.8em; }
    }

    /* ── Custom hover tooltip ── */
    #custom-hover {
      position: fixed; z-index: 90; display: none; pointer-events: none;
      background: var(--card); border: 1px solid var(--border); border-radius: 10px;
      padding: 7px 10px; line-height: 1.45;
      /* Each schedule line stays on one line; the box sizes to the widest. */
      white-space: nowrap; max-width: 90vw;
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      font-size: .76rem; color: var(--text);
      box-shadow: 0 3px 10px rgba(0,0,0,.12);
    }

    /* ── Zone detail popup (click a section) ── */
    .zone-detail-popup .maplibregl-popup-content {
      background: var(--card); color: var(--text);
      border: 1px solid var(--border); border-radius: 10px;
      padding: 10px 26px 11px 12px; font-size: .78rem; line-height: 1.5;
      box-shadow: 0 4px 14px rgba(0,0,0,.18);
    }
    .zone-detail-popup .maplibregl-popup-tip {
      border-top-color: var(--card); border-bottom-color: var(--card);
    }
    .zone-detail-popup .maplibregl-popup-close-button {
      position: absolute; top: 4px; right: 6px; left: auto; bottom: auto;
      width: 22px; height: 22px; padding: 0;
      display: flex; align-items: center; justify-content: center;
      font-size: 1.05rem; line-height: 1; color: var(--muted); border-radius: 5px;
    }
    .zone-detail-popup .maplibregl-popup-close-button:hover { color: var(--text); background: var(--bg); }

    /* ── Car marker (MapLibre HTML element) ── */
    .car-marker {
      border-radius: 50%; border: 3px solid white;
      box-shadow: 0 2px 8px rgba(0,0,0,.45);
      cursor: pointer; transition: width .12s, height .12s, border-color .12s;
    }

    /* Home pin — emoji marker, distinct from the round car dots. */
    .home-marker {
      font-size: 22px; line-height: 1; cursor: pointer;
      filter: drop-shadow(0 2px 3px rgba(0,0,0,.5));
    }
    .ce-dot-home { background: transparent !important; font-size: 14px; line-height: 1; }

    /* ── Spinner ── */
    .spinner { width: 11px; height: 11px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; margin-right: 3px; }
    @keyframes spin { to { transform: rotate(360deg); } }

    /* ── Dark mode ── */
    body.dark {
      --bg: #0f172a; --card: #1e293b; --text: #e2e8f0;
      --muted: #94a3b8; --border: #334155;
    }
    body.dark .maplibregl-map { filter: brightness(.92); }

    /* ── Toast notifications ── */
    #toast-container {
      position: fixed; bottom: calc(var(--inset-b) + 12px + var(--sheet-peek) + 16px);
      left: 50%; transform: translateX(-50%);
      z-index: 9999; display: flex; flex-direction: column; gap: 8px;
      pointer-events: none; align-items: center;
    }
    .toast {
      background: #1e293b; color: #f1f5f9; padding: 9px 16px;
      border-radius: 20px; font-size: .82rem; font-weight: 500;
      box-shadow: 0 4px 14px rgba(0,0,0,.35); pointer-events: none;
      animation: toast-in .2s ease, toast-out .3s ease 2.7s forwards;
      white-space: nowrap;
    }
    .toast.error { background: #7f1d1d; }
    @keyframes toast-in  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
    @keyframes toast-out { from { opacity: 1; } to { opacity: 0; } }

    /* ── Center target (tiny always-on dot marking the point the banner reads) ── */
    #center-crosshair {
      position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
      z-index: 15; display: none; width: 5px; height: 5px; border-radius: 50%;
      background: rgba(15,23,42,.75); box-shadow: 0 0 0 1.5px rgba(255,255,255,.85);
      pointer-events: none;
    }
    #center-crosshair.visible { display: block; }
    body.dark #center-crosshair {
      background: rgba(226,232,240,.9); box-shadow: 0 0 0 2px rgba(0,0,0,.6);
    }
    /* Placement: emphasize the target so it reads as the spot being set. */
    #center-crosshair.placing {
      width: 16px; height: 16px; background: transparent;
      border: 2px solid var(--blue);
      box-shadow: 0 0 0 2px rgba(255,255,255,.9), 0 0 0 3.5px var(--blue);
    }
    body.dark #center-crosshair.placing { box-shadow: 0 0 0 2px rgba(0,0,0,.6), 0 0 0 3.5px var(--blue); }

    /* ── Desktop: cars/homes dock as a narrow panel top-right; the info card sits
       bottom-left, so the two never overlap and the center stays clear. ── */
    @media (min-width: 768px) {
      #sheet {
        left: auto; right: 12px; bottom: auto; top: 12px;
        transform: none; width: 300px; max-height: calc(100% - 24px);
        border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
      }
      #sheet-grip { display: none; }            /* bottom-sheet drag affordance */
      #sheet-handle { padding-top: 8px; }
      #info-card { top: auto; bottom: 12px; left: 12px; transform: none; width: 340px; }
      #place-banner { bottom: auto; top: 10px; }
      #toast-container { bottom: 24px; }
    }
