:root {
  color-scheme: dark;
  --bg: #0a101a; --red: #f34c54; --cyan: #6ce5ed;
  --yellow: #f5d35d; --text: #e8e5e6; --muted: #a3b2b9;
  --panel: rgba(9, 15, 25, .97); --border: #80333d;
  font: 15px/1.35 system-ui, sans-serif;
  color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
#app {
  --gap: 10px; --top: max(var(--gap), env(safe-area-inset-top));
  --left: max(var(--gap), env(safe-area-inset-left));
  --right: max(var(--gap), env(safe-area-inset-right));
  --bottom: calc(max(6px, env(safe-area-inset-bottom)) + 30px);
  --rail: clamp(300px, 29vw, 420px);
  position: fixed; inset: 0 auto auto 0; width: 100%; height: 100vh; height: 100dvh;
  overflow: hidden; isolation: isolate;
}
#map { position: absolute; z-index: 0; inset: 0; background: #10131c; }
.hud {
  position: absolute; z-index: 2; inset: var(--top) var(--right) var(--bottom) var(--left);
  display: grid; grid-template-columns: minmax(0, var(--rail)) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr); gap: var(--gap); pointer-events: none;
}
.rail { display: flex; flex-direction: column; min-height: 0; min-width: 0; gap: var(--gap); }
.panel, .tools { pointer-events: auto; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--border); border-top: 2px solid var(--red); box-shadow: 0 8px 28px #0005; }
button, input, select { font: inherit; }
button { cursor: pointer; color: var(--text); background: #111d2a; border: 1px solid #33434d; min-height: 44px; padding: 8px 12px; touch-action: manipulation; }
@media (hover: hover) { button:hover { border-color: var(--cyan); color: var(--cyan); } }
button:focus-visible, summary:focus-visible, .sheet-scroll:focus-visible { outline: 2px solid var(--cyan); outline-offset: -2px; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--yellow); color: #18150b; border-color: var(--yellow); font-weight: 750; }
button[aria-pressed=true] { border-color: var(--cyan); color: var(--cyan); }
[hidden] { display: none !important; }
.search { display: flex; flex-direction: column; flex: 0 0 auto; min-height: 0; max-height: 100%; }
.search form { display: flex; flex: none; padding: 3px 5px; align-items: center; }
input { min-width: 0; width: 100%; background: transparent; border: 0; padding: 10px; font-size: 16px; color: var(--text); outline: none; }
.search form:focus-within { box-shadow: inset 0 -1px var(--cyan); }
input::placeholder { color: var(--muted); }
.search button { min-width: 44px; color: var(--cyan); background: transparent; border: 0; }
#closeResults { display: none; font-size: 24px; line-height: 1; padding: 0; }
.search:has(.results:not(:empty)) #closeResults { display: block; }
.quick, .placeactions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; padding: 0 5px 3px; }
.quick { flex: none; }
.quick button, .placeactions button, .linkbutton { min-height: 44px; font-size: 13px; padding: 4px; color: var(--cyan); background: none; border: 0; }
.quick button { min-width: 0; overflow-wrap: anywhere; }
.placeactions { padding: 2px 0; }
.linkbutton { padding-left: 0; }
.results { min-height: 0; overflow: auto; overscroll-behavior: contain; max-height: min(48vh, 420px); }
.results:empty { display: none; }
.result { display: block; text-align: left; width: 100%; border-top: 1px solid #4c303b!important; padding: 10px 12px!important; color: var(--text)!important; overflow-wrap: anywhere; }
.result strong { display: block; font-size: 14px; }
.result small, .muted { color: var(--muted); font-size: 12px; }
.notice { padding: 10px 12px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.nearbyrow { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; }
.nearbyrow button { font-size: 12px; border: 1px solid #33434d!important; padding: 5px 9px!important; }
.tools { grid-column: 2; grid-row: 1; justify-self: end; align-self: start; display: grid; gap: 6px; }
.tools button { width: 46px; height: 46px; padding: 0; background: var(--panel); border-color: var(--border); color: var(--cyan); display: grid; place-items: center; font-weight: 700; }
.tools svg, .search svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.sheet { display: flex; flex-direction: column; min-height: 0; overflow: hidden; padding: 0; }
#sheet { flex: 0 1 auto; }
/* Search results get the rail temporarily, leaving map and search picking usable. */
.rail:has(.results:not(:empty)) #sheet { display: none; }
.heading { display: flex; flex: none; align-items: flex-start; gap: 8px; justify-content: space-between; padding: 10px 12px 4px; }
.heading > div { min-width: 0; flex: 1; }
.heading h2 { font-size: 19px; margin: 0 0 3px; overflow-wrap: anywhere; color: var(--yellow); line-height: 1.2; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.heading button { border: 0; background: none; color: var(--red); padding: 0; min-height: 44px; min-width: 44px; font-size: 26px; line-height: 1; }
.detail { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; padding-bottom: 4px; }
.sheet-scroll { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 12px 7px; scrollbar-width: thin; }
.origin { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 13px; }
.origin span { flex: 1; min-width: 0; overflow-wrap: anywhere; color: var(--cyan); }
.origin button { padding: 5px 10px; font-size: 13px; }
.modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; margin: 6px 0; }
.modes button { min-width: 0; padding: 6px 4px; font-size: 13px; }
.route-summary { color: var(--yellow); font-size: 18px; font-weight: 750; margin: 7px 0 2px; overflow-wrap: anywhere; }
.status { font-size: 12px; color: var(--muted); margin: 4px 0 8px; overflow-wrap: anywhere; }
.status:empty, #summary:empty { display: none; }
.actions { display: flex; align-items: center; flex: none; gap: 7px; padding: 8px 12px 10px; border-top: 1px solid #4c303b; background: var(--panel); }
.actions button { flex: 1; min-width: 0; }
.actions #summary { flex: 1; min-width: 0; margin: 0; font-size: 16px; }
.stoprow, .routechoice { display: flex; gap: 4px; align-items: center; margin: 5px 0; }
.stoprow span { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 13px; }
.stoprow button { padding: 4px; min-width: 44px; }
.routechoice { width: 100%; text-align: left; justify-content: space-between; font-size: 13px; overflow-wrap: anywhere; }
.routechoice[aria-pressed=true] { color: var(--yellow); border-color: var(--yellow); }
#stepsPanel { font-size: 13px; margin: 8px 0; }
#stepsPanel summary { cursor: pointer; color: var(--cyan); padding: 10px 0; min-height: 44px; }
#stepList { padding-left: 20px; margin: 5px 0; }
#stepList li { padding: 4px 0; overflow-wrap: anywhere; }
.navtop { flex: none; }
.turn { display: flex; align-items: center; gap: 10px; padding: 12px; }
.turn > div:last-child { min-width: 0; }
.turn-icon { font-size: 42px; min-width: 46px; text-align: center; color: var(--yellow); line-height: 1; }
.turn-distance { font-size: clamp(23px, 3vw, 30px); line-height: 1.1; font-weight: 750; color: var(--yellow); }
.turn-text { font-size: 16px; overflow-wrap: anywhere; margin-top: 5px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
#navBottom { flex: none; padding: 10px 12px; }
.navbottom { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.navbottom > div:first-child { min-width: 0; }
.navbottom .route-summary { margin: 0; }
.navbuttons { display: flex; gap: 5px; flex: none; }
.navbuttons button { padding: 6px 9px; min-width: 44px; }
#navStatus { max-height: 3em; overflow: auto; }
.toast { position: absolute; z-index: 5; bottom: 45%; left: 50%; transform: translateX(-50%); max-width: calc(100% - 24px); width: max-content; background: #111d2a; border-left: 3px solid var(--cyan); padding: 10px 14px; color: var(--text); pointer-events: none; overflow-wrap: anywhere; }
.loading { position: absolute; z-index: 4; inset: 0; display: grid; place-content: center; text-align: center; padding: 25px; background: #0a101ae8; color: var(--cyan); pointer-events: none; }
.loading.error { pointer-events: auto; color: var(--red); cursor: pointer; }
.pin { width: 23px; height: 23px; border: 2px solid var(--yellow); background: #382e10; transform: rotate(45deg); display: grid; place-items: center; box-shadow: 0 0 0 4px #f5d35d22; }
.pin:after { content: ''; width: 6px; height: 6px; background: var(--yellow); }
.gpspin { width: 24px; height: 24px; border: 1px solid var(--cyan); border-radius: 50%; display: grid; place-items: center; background: #6ce5ed33; }
.gpspin:after { content: ''; width: 9px; height: 9px; background: var(--cyan); border-radius: 50%; }
.gpspin.arrow:after { width: 15px; height: 19px; border-radius: 0; clip-path: polygon(50% 0,100% 100%,50% 75%,0 100%); transform: rotate(var(--heading,0deg)); }
.originpin { width: 13px; height: 13px; border: 2px solid var(--cyan); border-radius: 50%; background: #152b36; }
.stoppin { width: 22px; height: 22px; background: #131925; color: var(--yellow); border: 1px solid var(--yellow); border-radius: 50%; display: grid; place-items: center; font-weight: bold; font-size: 12px; }
.maplibregl-ctrl-attrib { font-size: 10px!important; background: #09111dcc!important; color: #b7c9cd!important; }
.maplibregl-ctrl-attrib a { color: #9bd0d8!important; }
#map .maplibregl-ctrl-bottom-right { bottom: max(2px, env(safe-area-inset-bottom)); right: max(4px, env(safe-area-inset-right)); }
#map .maplibregl-ctrl-bottom-left { bottom: max(2px, env(safe-area-inset-bottom)); left: max(4px, env(safe-area-inset-left)); }
/* Stacked phone/tablet layout. Short landscape screens use the rail instead. */
@media (max-width: 760px) and (min-height: 521px), (max-width: 559px) {
  #app { --gap: 8px; }
  .hud { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(46px, 1fr) auto; }
  .rail { display: contents; }
  .search, .navtop { grid-column: 1; grid-row: 1; max-height: min(calc(var(--app-height, 100dvh) * .56), 460px); }
  .search:has(.results:not(:empty)) { max-height: min(calc(var(--app-height, 100dvh) * .70), 580px); }
  .sheet { grid-column: 1; grid-row: 3; max-height: min(calc(var(--app-height, 100dvh) * .49), 480px); }
  #navBottom { max-height: none; }
  .hud:has(#query:focus) #sheet { display: none; }
  .tools { grid-column: 1; grid-row: 2; align-self: start; grid-auto-flow: column; }
  .hud:has(.results:not(:empty)) .tools { align-self: end; }
  .results { max-height: none; }
  #app.keyboard-open .hud { bottom: var(--gap); }
  #app.keyboard-open .search { max-height: 100%; }
  #app.keyboard-open .hud { grid-template-rows: minmax(0, 1fr); }
  #app.keyboard-open .tools, #app.keyboard-open #sheet { display: none; }
  #app.keyboard-open .search { align-self: start; }
}
@media (min-width: 560px) and (max-height: 520px) {
  #app { --rail: clamp(250px, 42vw, 360px); --gap: 6px; }
  .search form { padding: 0 4px; }
  .quick button { font-size: 12px; }
  .heading { padding: 5px 8px 2px; }
  .heading h2 { font-size: 16px; -webkit-line-clamp: 1; }
  .sheet-scroll { padding: 0 8px 4px; }
  .actions { padding: 4px 8px; }
  .turn { padding: 8px; }
  .turn-text { -webkit-line-clamp: 2; }
  #navBottom { padding: 6px 8px; }
  /* Search occupies a single row when a destination is selected. */
  .rail:has(#sheet:not([hidden])) .search:not(:has(.results:not(:empty))) .quick { display: none; }
}
@media (max-width: 360px) {
  .quick button { font-size: 12px; }
  .heading h2 { font-size: 17px; }
  .navbottom .route-summary { font-size: 16px; }
  .navbuttons button { padding: 5px; }
  .turn { padding: 8px; }
}
@media (max-width: 559px) and (max-height: 520px) {
  .quick button { min-height: 40px; }
  .sheet { max-height: min(calc(var(--app-height, 100dvh) * .55), 480px); }
  .heading { padding: 4px 8px 0; }
  .heading h2 { -webkit-line-clamp: 1; font-size: 16px; }
  .rail:has(#sheet:not([hidden])) .search:not(:has(.results:not(:empty))) .quick { display: none; }
  #navBottom { max-height: none; }
  .actions { padding: 4px 8px; }
  .turn-text { -webkit-line-clamp: 2; }
  .turn { padding: 6px 8px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto!important; } }
/* Visual viewport can shrink without changing CSS viewport media queries (iOS keyboard). */
.search:focus-within #closeResults,
.search:has(input[placeholder^="Tìm điểm"]) #closeResults { display: block; }
#app.keyboard-open .hud { bottom: var(--gap); }
#app.keyboard-open #sheet, #app.keyboard-open .tools { display: none; }
#app.keyboard-open .search, #app.keyboard-open .results { max-height: 100%; }
/* Search as-you-type: dense, readable result rows; no additional permanent HUD. */
.search-section { padding: 8px 12px 5px; color: var(--cyan); font-size: 12px; font-weight: 650; letter-spacing: .02em; }
.result.suggestion { display: grid; grid-template-columns: 24px minmax(0,1fr); gap: 9px; align-items: start; padding: 10px 11px!important; min-height: 62px; }
.suggestion-icon { display:grid; place-items:center; width:24px; height:26px; color:var(--cyan); font-size:20px; line-height:1; }
.suggestion-text { min-width:0; display:grid; gap:3px; }
.suggestion-text strong { line-height:1.25; }
.suggestion-text small { display:block; line-height:1.3; }
.suggestion-meta { color:#8eb7c0!important; font-size:11px!important; }
.suggestion.keyboard-active { background:#17303a; box-shadow:inset 3px 0 var(--cyan); }
.search-attribution { font-size:10px; color:var(--muted); padding:6px 12px; overflow-wrap:anywhere; }

.place-source { color: var(--muted); font-size: 11px; overflow-wrap:anywhere; }
.place-source:empty { display:none; }
