:root {
  --sign-green: #0B6B3A;   /* expressway sign */
  --sign-blue: #1D4F9C;    /* JKR direction sign, route line */
  --marking: #F5C400;      /* yellow road marking */
  --asphalt: #23272B;
  --asphalt-2: #4A5158;
  --paper: #F3F5F2;
  --panel: #FFFFFF;
  --line: #DADFDB;
  --slow: #F0A202;
  --heavy: #E2522F;
  --stop: #9B1C1C;
  --radius-panel: 18px;
  --radius-ctl: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--asphalt); font-family: var(--font); -webkit-font-smoothing: antialiased; }
body { overflow: hidden; }
#map { position: fixed; inset: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--marking); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- search ---------- */
.top { position: fixed; top: calc(12px + var(--safe-top)); left: 12px; right: 12px; z-index: 5; max-width: 420px; }
.searchbox { background: var(--panel); border-radius: var(--radius-panel); box-shadow: 0 2px 10px rgba(35,39,43,.18), 0 0 0 1px rgba(35,39,43,.06); overflow: hidden; }
.field { display: flex; align-items: center; gap: 10px; padding: 0 6px 0 16px; min-height: 54px; }
.field + .field { border-top: 1px solid var(--line); }
#fromRow + .field { border-top: 1px solid var(--line); }
.field input { flex: 1; border: 0; outline: 0; font-size: 17px; background: transparent; color: var(--asphalt); min-width: 0; padding: 14px 0; }
.field input::placeholder { color: #7B848C; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.dot.to { background: var(--sign-blue); box-shadow: 0 0 0 3px rgba(29,79,156,.18); }
.dot.from { background: #fff; border: 3px solid var(--asphalt-2); }
.iconbtn { border: 0; background: none; width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; color: var(--asphalt-2); }
.iconbtn:hover { background: var(--paper); }
.results { list-style: none; margin: 0; padding: 4px 0 8px; border-top: 1px solid var(--line); max-height: 52vh; overflow: auto; }
.results li { display: flex; gap: 12px; align-items: center; padding: 10px 16px; cursor: pointer; }
.results li[aria-selected="true"], .results li:hover { background: var(--paper); }
.results .ic { width: 32px; height: 32px; border-radius: 9px; background: #E8ECEF; display: grid; place-items: center; flex: none; font-size: 15px; }
.results .ic.road { background: #E4EAF5; color: var(--sign-blue); }
.results .nm { font-size: 16px; line-height: 1.25; }
.results .sub { font-size: 13px; color: #6A737B; }

/* ---------- navigation sign ---------- */
.sign { position: fixed; top: calc(10px + var(--safe-top)); left: 10px; right: 10px; z-index: 6; max-width: 560px; }
.sign-inner { background: var(--sign-green); color: #fff; border-radius: 16px; padding: 14px 18px; display: flex; gap: 16px; align-items: center;
  box-shadow: inset 0 0 0 3px var(--sign-green), inset 0 0 0 5px rgba(255,255,255,.92), 0 6px 18px rgba(0,0,0,.25); }
.sign.local .sign-inner { background: var(--sign-blue); box-shadow: inset 0 0 0 3px var(--sign-blue), inset 0 0 0 5px rgba(255,255,255,.92), 0 6px 18px rgba(0,0,0,.25); }
.sign-arrow { width: 64px; height: 64px; flex: none; }
.sign-arrow svg { width: 100%; height: 100%; }
.sign-dist { font-size: 34px; font-weight: 800; letter-spacing: -.01em; line-height: 1; font-variant-numeric: tabular-nums; }
.sign-road { font-size: 20px; font-weight: 600; line-height: 1.2; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lanes { display: flex; justify-content: center; margin: -10px 14px 0; padding: 12px 10px 6px; background: #0A5A31; border-radius: 0 0 14px 14px; box-shadow: 0 6px 14px rgba(0,0,0,.2); }
.sign.local .lanes { background: #183F7C; }
.lane { width: 40px; height: 38px; display: grid; place-items: center; }
.lane + .lane { border-left: 2px dashed rgba(255,255,255,.45); }
.lane svg { width: 30px; height: 30px; }
.lane.off svg { opacity: .32; }
.sign-next { margin: 6px 0 0 12px; display: inline-flex; gap: 8px; align-items: center; background: #0A5A31; color: #fff; padding: 6px 12px 6px 8px; border-radius: 10px; font-size: 15px; font-weight: 600; box-shadow: 0 3px 10px rgba(0,0,0,.2); }
.sign.local .sign-next { background: #183F7C; }
.sign-next svg { width: 22px; height: 22px; }

/* ---------- floating buttons ---------- */
.fabs { position: fixed; right: 12px; bottom: calc(var(--sheet-h, 120px) + 14px); z-index: 4; display: flex; flex-direction: column; gap: 12px; transition: bottom .25s ease; }
.fab { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--panel); display: grid; place-items: center; color: var(--asphalt); box-shadow: 0 2px 10px rgba(35,39,43,.22); }
.fab.report { width: 60px; height: 60px; background: var(--marking); color: var(--asphalt); }

/* ---------- bottom sheet ---------- */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--panel); border-radius: 22px 22px 0 0; box-shadow: 0 -4px 20px rgba(35,39,43,.16);
  padding: 8px 16px calc(14px + var(--safe-bottom)); max-height: 62vh; overflow: auto; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: #D3D8DC; margin: 0 auto 10px; }
.sheet h3 { margin: 2px 0 2px; font-size: 20px; line-height: 1.25; }
.sheet .muted { color: #636C74; font-size: 14px; line-height: 1.4; }
.row { display: flex; gap: 10px; align-items: center; }
.row.space { justify-content: space-between; }
.btn { border: 0; border-radius: var(--radius-ctl); padding: 13px 18px; font-size: 16px; font-weight: 650; background: var(--sign-blue); color: #fff; }
.btn.go { background: var(--sign-green); }
.btn.ghost { background: #EDF0F2; color: var(--asphalt); }
.btn.danger { background: #B3261E; }
.btn.wide { width: 100%; margin-top: 14px; }
.btn:disabled { opacity: .5; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 12px; }
.chip { border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 600; color: var(--asphalt-2); }
.chip[aria-pressed="true"] { border-color: var(--asphalt); background: var(--asphalt); color: #fff; }

.routes { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 12px; }
.rcard { text-align: left; border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px; background: #fff; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.rcard[aria-pressed="true"] { border-color: var(--sign-blue); background: #F4F7FC; }
.rcard .eta { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.rcard .lbl { justify-self: end; align-self: start; font-size: 13px; font-weight: 700; color: var(--sign-blue); }
.rcard .meta { grid-column: 1 / -1; font-size: 14px; color: #555E66; line-height: 1.45; }
.delay { color: var(--heavy); font-weight: 650; }
.delay.ok { color: var(--sign-green); }
.toll { display: inline-block; font-size: 12px; font-weight: 750; padding: 1px 7px; border-radius: 6px; background: #FFF4C7; color: #5C4A00; margin-left: 4px; vertical-align: 1px; }
.toll.free { background: #E3F1E8; color: var(--sign-green); }

.navbar { display: flex; align-items: center; gap: 14px; }
.navbar .big { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.navbar .grow { flex: 1; }
.navbar .muted { font-size: 15px; }

/* ---------- dialogs ---------- */
.dlg { border: 0; border-radius: 22px; padding: 20px; width: min(440px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 10px 40px rgba(0,0,0,.3); color: var(--asphalt); }
.dlg::backdrop { background: rgba(20,24,28,.45); }
.dlg h2 { margin: 0 0 14px; font-size: 22px; }
.rgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.rtile { border: 0; border-radius: 16px; padding: 14px 6px 12px; background: #F1F3F4; display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 14px; font-weight: 650; }
.rtile:hover { background: #E7EAEC; }
.rtile .ico { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; color: #fff; }
.menu-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 16px; }
.menu-row input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--sign-green); }
.seg { display: inline-flex; background: #EDF0F2; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 7px 10px; border-radius: 8px; font-size: 14px; font-weight: 600; }
.seg button[aria-pressed="true"] { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.privacy { margin-top: 16px; padding: 14px 16px; background: #EEF5F0; border-radius: 14px; }
.privacy h3 { margin: 0 0 6px; font-size: 16px; color: var(--sign-green); }
.privacy p { margin: 6px 0 0; font-size: 14px; line-height: 1.45; }
.stats { margin-top: 12px; font-size: 13px; color: #636C74; line-height: 1.6; }

/* ---------- toast & popups ---------- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--sheet-h, 120px) + 16px); z-index: 7; background: var(--asphalt); color: #fff; padding: 12px 16px; border-radius: 12px;
  font-size: 15px; max-width: calc(100vw - 100px); box-shadow: 0 6px 18px rgba(0,0,0,.25); display: flex; gap: 12px; align-items: center; }
.toast button { background: var(--marking); color: var(--asphalt); border: 0; border-radius: 8px; padding: 6px 12px; font-weight: 700; }
.maplibregl-popup-content { border-radius: 14px; padding: 12px 14px; font-family: var(--font); color: var(--asphalt); box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.pop h4 { margin: 0 0 2px; font-size: 16px; }
.pop .muted { font-size: 13px; color: #636C74; }
.pop .row { margin-top: 10px; }
.pop .btn { padding: 8px 12px; font-size: 14px; }
.marker-report { width: 34px; height: 34px; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg); display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0,0,0,.3); border: 2px solid #fff; cursor: pointer; }
.marker-report > span { transform: rotate(45deg); display: grid; place-items: center; }
.me { width: 22px; height: 22px; border-radius: 50%; background: var(--sign-blue); border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(29,79,156,.22), 0 2px 6px rgba(0,0,0,.3); }
.me.nav { width: 0; height: 0; border-radius: 0; background: none; border: 0; box-shadow: none; }
.me.nav::after { content: ""; display: block; width: 34px; height: 34px; margin: -17px; background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M20 3 34 35 20 27 6 35Z' fill='%231D4F9C' stroke='white' stroke-width='3' stroke-linejoin='round'/%3E%3C/svg%3E"); filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
.attrib { position: fixed; left: 8px; bottom: calc(var(--sheet-h, 120px) + 4px); z-index: 3; font-size: 11px; color: #5A636B; background: rgba(255,255,255,.75); padding: 1px 6px; border-radius: 6px; }

/* ---------- wide screens: sheet becomes a side panel ---------- */
@media (min-width: 900px) {
  .top { width: 400px; }
  .sheet { left: 12px; right: auto; bottom: 12px; width: 400px; border-radius: var(--radius-panel); max-height: calc(100vh - 110px); }
  .grab { display: none; }
  .fabs { bottom: 24px; }
  .toast { bottom: 24px; }
  .attrib { left: auto; right: 80px; bottom: 6px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
