  :root{
    --bg:#E8EAE5;
    --panel:#F7F8F4;
    --card:#FFFFFF;
    --ink:#171A1E;
    --muted:#5C6167;
    --line:#D3D6CC;
    --blue:#1D4ED8;
    --k2:#F0A62E;   /* slightly curvy */
    --k3:#E86A24;   /* curvy */
    --k4:#D42B2B;   /* very curvy */
    --k5:#7C1F44;   /* serpentines */
    --ok:#1E7F4F;
    --r:10px;
    font-size:15px;
  }
  *{box-sizing:border-box;margin:0;padding:0}
  html,body{height:100%}
  body{
    font-family:'Barlow',system-ui,sans-serif;
    background:var(--bg);color:var(--ink);
    height:100dvh;overflow:hidden;position:relative;
  }
  h1,h2,h3,.disp{font-family:'Barlow Condensed','Barlow',sans-serif;text-transform:uppercase;letter-spacing:.06em}

  /* ---------- Sidebar ---------- */
  aside{
    background:var(--panel);border-right:1px solid var(--line);
    overflow-y:auto;display:flex;flex-direction:column;
  }
  header.brand{
    padding:18px 20px 14px;border-bottom:2px solid var(--ink);
    display:flex;align-items:baseline;gap:10px;
  }
  header.brand h1{font-size:1.6rem;font-weight:700}
  header.brand span{color:var(--muted);font-size:.8rem;letter-spacing:.12em;text-transform:uppercase}

  section{padding:16px 20px;border-bottom:1px solid var(--line)}
  section h2{
    font-size:.85rem;font-weight:600;color:var(--muted);
    display:flex;align-items:center;gap:8px;margin-bottom:12px;
  }
  section h2::before{
    content:attr(data-step);
    display:inline-flex;align-items:center;justify-content:center;
    width:20px;height:20px;border:1.5px solid var(--ink);border-radius:50%;
    color:var(--ink);font-size:.72rem;letter-spacing:0;
  }

  .row{display:flex;gap:8px;align-items:center;margin-bottom:10px}
  .row:last-child{margin-bottom:0}
  label{font-size:.82rem;color:var(--muted)}
  .val{font-family:'Barlow Condensed';font-size:1.15rem;font-weight:600;min-width:64px;text-align:right}

  input[type=range]{flex:1;accent-color:var(--ink)}
  input[type=number]{
    width:74px;padding:7px 8px;border:1px solid var(--line);border-radius:6px;
    font:inherit;background:var(--card);
  }
  select{padding:7px 8px;border:1px solid var(--line);border-radius:6px;font:inherit;background:var(--card)}

  button{
    font-family:'Barlow Condensed';text-transform:uppercase;letter-spacing:.08em;
    font-size:.95rem;font-weight:600;cursor:pointer;border-radius:var(--r);
    padding:10px 14px;border:1.5px solid var(--ink);background:var(--card);color:var(--ink);
    transition:transform .05s ease, background .15s ease;
  }
  button:hover{background:#eef0ea}
  button:active{transform:translateY(1px)}
  button.primary{background:var(--ink);color:#fff}
  button.primary:hover{background:#000}
  button:disabled{opacity:.45;cursor:not-allowed;transform:none}
  button.small{padding:5px 10px;font-size:.8rem;border-width:1px;border-radius:6px}
  .btn-wide{width:100%}

  .hint{font-size:.78rem;color:var(--muted);line-height:1.45;margin-top:8px}

  /* Curviness scale (legend) */
  .skala{display:flex;gap:6px;margin-top:12px}
  .skala div{
    flex:1;text-align:center;font-family:'Barlow Condensed';font-weight:600;font-size:.78rem;
    color:#fff;padding:4px 0;border-radius:4px;letter-spacing:.05em;
    cursor:pointer;user-select:none;touch-action:manipulation;transition:opacity .15s ease, filter .15s ease;
  }
  .skala div.off{opacity:.35;filter:grayscale(.55)}   /* grade hidden from the map */

  /* Segment list — no own scroll; the card body is the single scroll region. */
  #segList{display:flex;flex-direction:column;gap:6px}
  .seg{
    display:flex;align-items:center;gap:10px;padding:8px 10px;background:var(--card);
    border:1px solid var(--line);border-radius:8px;cursor:pointer;font-size:.85rem;
  }
  .seg:hover{border-color:var(--ink)}
  .seg.sel{border:1.5px solid var(--blue);box-shadow:0 0 0 2px rgba(29,78,216,.15)}
  .seg .grade{
    font-family:'Barlow Condensed';font-weight:700;color:#fff;border-radius:4px;
    width:32px;text-align:center;padding:2px 0;flex-shrink:0;font-size:.8rem;
  }
  .seg .name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .seg .len{color:var(--muted);font-variant-numeric:tabular-nums;flex-shrink:0}

  /* Suggestion cards – roadbook stages */
  #propList{display:flex;flex-direction:column;gap:10px}
  .prop{
    background:var(--card);border:1px solid var(--line);border-radius:var(--r);
    padding:12px 14px;cursor:pointer;position:relative;overflow:hidden;
  }
  .prop::before{content:'';position:absolute;left:0;top:0;bottom:0;width:5px;background:var(--pc,var(--ink))}
  .prop.active{border-color:var(--ink);box-shadow:0 2px 10px rgba(0,0,0,.10)}
  .prop .top{display:flex;align-items:baseline;gap:10px}
  .prop .etappe{font-family:'Barlow Condensed';font-weight:700;font-size:1.15rem;text-transform:uppercase;letter-spacing:.05em}
  .prop .dist{margin-left:auto;font-family:'Barlow Condensed';font-weight:700;font-size:1.35rem;font-variant-numeric:tabular-nums}
  .prop .dist small{font-size:.75rem;color:var(--muted);font-weight:600}
  .prop .meta{font-size:.78rem;color:var(--muted);margin-top:4px;line-height:1.5}
  .prop .actions{margin-top:8px;display:flex;gap:8px}

  /* Status = floating toast, top-center over the map. */
  #status{
    position:fixed;top:12px;left:50%;transform:translateX(-50%);z-index:700;
    max-width:min(92vw,540px);padding:8px 14px;font-size:.8rem;color:var(--muted);
    background:var(--card);border:1px solid var(--line);border-radius:20px;
    box-shadow:0 2px 10px rgba(0,0,0,.12);display:flex;align-items:center;gap:8px;
  }
  #status.busy::before{
    content:'';width:12px;height:12px;border:2px solid var(--muted);border-top-color:transparent;
    border-radius:50%;animation:spin .8s linear infinite;flex-shrink:0;
  }
  #status.err{color:var(--k4)}
  @keyframes spin{to{transform:rotate(360deg)}}

  /* ---------- Map ---------- */
  /* The map is a real pane, not a full-screen backdrop: JS insets its left (desktop side
     panel) / bottom (mobile sheet) so it occupies only the free area, and Leaflet recenters
     into it. Leaflet's own controls (zoom, etc.) live inside #map, so they follow along. */
  #map{position:fixed;top:0;right:0;bottom:0;left:0;background:#dfe2da;z-index:0}
  .start-pin{
    width:16px;height:16px;border-radius:50%;background:var(--ink);
    border:3px solid #fff;box-shadow:0 1px 5px rgba(0,0,0,.4);
  }
  /* Hover tooltip = a MapLibre popup; strip its tip and chrome down to a compact label. */
  .segtip{pointer-events:none}
  .segtip .maplibregl-popup-content{
    font-family:'Barlow',sans-serif;font-size:.8rem;padding:4px 9px;border-radius:6px;
    box-shadow:0 1px 6px rgba(0,0,0,.28);white-space:nowrap;
  }
  .segtip .maplibregl-popup-tip{display:none}
  .seg-num{
    width:22px;height:22px;border-radius:50%;background:#171A1E;color:#fff;
    border:2px solid #fff;box-shadow:0 1px 4px rgba(0,0,0,.4);
    font-family:'Barlow Condensed';font-weight:700;font-size:.82rem;
    display:flex;align-items:center;justify-content:center;
  }
  .dir-arrow{
    width:0;height:0;border-left:5px solid transparent;border-right:5px solid transparent;
    border-bottom:11px solid #171A1E;filter:drop-shadow(0 0 1px rgba(255,255,255,.9));
    transform-origin:50% 60%;
  }

  /* ---------- Floating UI ---------- */
  .gone{display:none!important}

  /* Attribution pill — always visible (tile-license requirement). Bottom-center keeps it clear
     of the top status toast, the left side panel, and the bottom-right FABs. z above the
     coach-mark so the first-run tooltip never hides the license/legal links. */
  #attrib{
    position:fixed;left:50%;bottom:6px;transform:translateX(-50%);z-index:970;
    font-size:.66rem;color:var(--muted);text-align:center;max-width:calc(100vw - 20px);transition:bottom .24s ease;
    background:rgba(247,248,244,.86);padding:2px 8px;border-radius:10px;pointer-events:none;
  }
  #attrib a{color:inherit;pointer-events:auto}   /* pill ignores clicks (pass-through to map); links stay clickable */
  #attrib .beta-badge{font-size:.58rem;padding:0 4px;vertical-align:middle}   /* subtler in the thin footer */
  /* Fixed two-line layout: attributions + Beta on top, legal links below (no wrap coincidence). */
  #attrib .attrib-row{display:block;line-height:1.5;white-space:nowrap}

  /* FAB stack, bottom-right (JS lifts it above the route card when shown). */
  .fab-stack{position:fixed;right:16px;bottom:36px;z-index:900;display:flex;flex-direction:column;gap:12px;transition:bottom .24s ease}
  .fab{
    width:54px;height:54px;padding:0;border-radius:50%;display:flex;align-items:center;justify-content:center;
    background:var(--card);border:1.5px solid var(--ink);color:var(--ink);box-shadow:0 3px 12px rgba(0,0,0,.22);
  }
  .fab.primary{background:var(--ink);color:#fff}
  .fab svg{width:24px;height:24px}

  /* Hideable overlays: fade/rise in via .show. */
  .popover,.pin-bar,#crosshair{opacity:0;pointer-events:none;transition:opacity .18s ease, transform .18s ease}
  .popover.show,.pin-bar.show,#crosshair.show{opacity:1;pointer-events:auto}
  .popover.show{transform:none}

  /* One panel holds controls + route results. Google-Maps style: side panel on desktop
     (slides in from the left), bottom sheet on mobile (slides up). Slide via transform;
     .show toggles it. Base = desktop side panel; the mobile @media below overrides. */
  #panel{
    position:fixed;z-index:850;background:var(--panel);
    border-right:1px solid var(--line);
    box-shadow:0 8px 30px rgba(0,0,0,.20);display:flex;flex-direction:column;overflow:hidden;
    transition:transform .24s ease;
    top:0;left:0;bottom:0;width:min(370px,100vw);border-radius:0 16px 16px 0;  /* flush to top/left/bottom; only the map-facing edge is rounded */
    transform:translateX(-101%);                              /* hidden off-screen left (incl. shadow) */
  }
  #panel.show{transform:none}
  .grabber{display:none;flex:0 0 auto;height:22px;cursor:grab}
  .grabber::before{content:'';display:block;width:40px;height:4px;margin:9px auto 0;border-radius:2px;background:var(--line)}
  .card-head{
    flex:0 0 auto;display:flex;align-items:center;gap:8px;padding:12px 14px;
    border-bottom:1px solid var(--line);
  }
  .card-head h3{font-size:1.05rem;font-weight:700}
  .card-head .x{margin-left:auto;padding:4px 9px;border-width:1px;border-radius:6px;line-height:1}
  .card-body{flex:1 1 auto;overflow-y:auto;padding:14px;-webkit-overflow-scrolling:touch}
  /* Pinned footer holding the primary action, so it stays put while the body scrolls. */
  .card-foot{flex:0 0 auto;padding:12px 14px;border-top:1px solid var(--line);background:var(--panel)}
  /* Divider between the controls and the appended route results. */
  .sect-div{height:1px;background:var(--line);margin:16px -14px}
  .grp{margin-bottom:16px}
  .grp:last-child{margin-bottom:0}
  .grp-title{
    font-size:.8rem;font-weight:600;color:var(--muted);margin-bottom:8px;
    display:flex;align-items:center;gap:8px;
  }

  /* Location popover above the location FAB. */
  .popover{
    position:fixed;right:16px;z-index:950;background:var(--panel);border:1px solid var(--line);
    border-radius:12px;box-shadow:0 8px 30px rgba(0,0,0,.20);padding:8px;transform:translateY(10px);
    display:flex;flex-direction:column;gap:6px;min-width:190px;
  }
  .popover button{text-align:left}

  /* Coach-mark: first-run hint pointing at the Location FAB. Sits *below* the panel
     (z<850) so opening the plan sheet covers it instead of hovering over it — it
     reappears, undismissed, when the sheet closes. */
  .coach{
    position:fixed;z-index:840;max-width:225px;background:var(--ink);color:#fff;
    padding:10px 12px;border-radius:10px;box-shadow:0 6px 20px rgba(0,0,0,.28);
    font-size:.85rem;line-height:1.35;transform:translateY(-78%);
    opacity:0;pointer-events:none;transition:opacity .25s ease;
  }
  .coach.show{opacity:1;pointer-events:auto}
  .coach strong{display:block;font-family:'Barlow Condensed';font-weight:700;font-size:.95rem;margin-bottom:2px}
  .coach .coach-ok{
    margin-top:8px;padding:4px 12px;border:1px solid rgba(255,255,255,.6);border-radius:6px;
    background:transparent;color:#fff;font-size:.8rem;font-weight:600;cursor:pointer;
  }
  .coach::after{  /* arrow on the right edge, pointing at the FAB */
    content:"";position:absolute;right:-7px;top:78%;transform:translateY(-50%);
    border:7px solid transparent;border-left-color:var(--ink);border-right:0;
  }
  @media (prefers-reduced-motion: no-preference){
    .coach.show{animation:coachBob 1.7s ease-in-out infinite}
    @keyframes coachBob{0%,100%{transform:translateY(-78%) translateX(0)}50%{transform:translateY(-78%) translateX(-4px)}}
  }

  /* First-run welcome card: full-screen backdrop + centered card, above everything. */
  #welcome,#gmapsConfirm{
    position:fixed;inset:0;z-index:1000;display:flex;align-items:center;justify-content:center;
    padding:20px;background:rgba(23,26,30,.42);opacity:0;pointer-events:none;transition:opacity .2s ease;
  }
  #welcome.show,#gmapsConfirm.show{opacity:1;pointer-events:auto}
  .wcard{
    background:var(--panel);border:1px solid var(--line);border-radius:16px;
    box-shadow:0 14px 44px rgba(0,0,0,.32);width:100%;max-width:400px;padding:24px 24px 20px;
    transform:translateY(10px);transition:transform .2s ease;
  }
  #welcome.show .wcard,#gmapsConfirm.show .wcard{transform:none}
  /* Consent dialog: two-button action row. */
  .wcard .wbtns{display:flex;gap:8px;margin-top:4px}
  .wcard .wbtns button{flex:1}
  .wcard h2{font-family:'Barlow Condensed','Barlow',sans-serif;font-weight:700;font-size:2rem;
    letter-spacing:.05em;text-transform:uppercase;line-height:1;display:flex;align-items:center;gap:10px}
  /* "Beta" badge: quiet maturity signal next to the title + a persistent copy in the footer. */
  .beta-badge{
    font-family:'Barlow Condensed','Barlow',sans-serif;font-weight:700;font-size:.7rem;
    letter-spacing:.12em;text-transform:uppercase;color:var(--blue);
    border:1px solid var(--blue);border-radius:5px;padding:2px 6px;line-height:1;
  }
  .wcard .wtag{color:var(--muted);font-size:.78rem;letter-spacing:.14em;text-transform:uppercase;margin:4px 0 14px}
  /* Early-access + drive-safe note under the welcome steps. */
  .wcard .wnote{color:var(--muted);font-size:.76rem;line-height:1.45;margin:-6px 0 16px}
  .wcard p{font-size:.9rem;line-height:1.5;margin-bottom:16px}
  .wcard ol{list-style:none;display:flex;flex-direction:column;gap:11px;margin-bottom:20px}
  .wcard li{display:flex;gap:11px;align-items:flex-start;font-size:.86rem;line-height:1.4}
  .wcard li .wnum{
    flex:0 0 auto;width:22px;height:22px;border-radius:50%;background:var(--ink);color:#fff;
    font-family:'Barlow Condensed';font-weight:700;font-size:.82rem;
    display:flex;align-items:center;justify-content:center;
  }

  /* Set-Pin confirm bar, bottom-center. */
  .pin-bar{
    position:fixed;left:50%;bottom:52px;transform:translate(-50%,10px);z-index:950;
    display:flex;gap:8px;background:var(--panel);border:1px solid var(--line);
    border-radius:30px;box-shadow:0 6px 24px rgba(0,0,0,.22);padding:8px 10px;
  }
  .pin-bar.show{transform:translate(-50%,0)}

  /* Center crosshair for Set-Pin mode. */
  #crosshair{position:fixed;left:50%;top:50%;z-index:800;transform:translate(-50%,-50%);color:var(--ink)}
  #crosshair.show{transform:translate(-50%,-50%)}
  #crosshair svg{width:44px;height:44px;filter:drop-shadow(0 1px 3px rgba(255,255,255,.9))}

  /* Mobile: the panel becomes a bottom sheet that slides up. */
  @media (max-width:640px){
    #panel{
      top:auto;left:0;right:0;bottom:0;width:auto;max-height:82dvh;
      border-radius:18px 18px 0 0;border-bottom:none;
      transform:translateY(100%);                             /* hidden below the fold */
    }
    #panel.show{transform:none}
    .grabber{display:block}
  }
