:root {
  --ink: #f5ecdc;
  --ink-2: #cdbfa6;
  --ink-3: #9a8c75;
  --glass: rgba(30, 24, 18, 0.74);
  --glass-2: rgba(48, 39, 30, 0.86);
  --line: rgba(245, 236, 220, 0.12);
  --copper: #d4844a;
  --copper-2: #b8682f;
  --pistachio: #a7c95a;
  --ground: #d8cba9;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(20, 14, 8, 0.28), 0 1px 0 rgba(255, 255, 255, 0.04) inset;
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Fraunces', Georgia, serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ground); font-family: var(--font); color: var(--ink); -webkit-font-smoothing: antialiased; }
body.night { background: #141a26; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: var(--copper); }
svg { display: block; }

#map { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; }
#map.grabbing { cursor: grabbing; }

.glass { background: var(--glass); backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- top bar ---------- */
.top { position: fixed; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; display: grid; grid-template-columns: auto minmax(0, 420px) auto; justify-content: space-between; gap: 10px; align-items: start; pointer-events: none; z-index: 5; }
.top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 7px 14px 7px 8px; text-decoration: none; color: var(--ink); }
.logo { width: 34px; height: 34px; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-family: var(--display); font-weight: 700; font-size: 17px; letter-spacing: 0.1px; white-space: nowrap; }
#live { font-size: 11.5px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; margin-top: 3px; white-space: nowrap; font-weight: 500; }
#live i { width: 7px; height: 7px; border-radius: 50%; background: var(--pistachio); box-shadow: 0 0 0 0 rgba(167, 201, 90, 0.6); animation: pulse 2.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(167, 201, 90, 0.55); } 70% { box-shadow: 0 0 0 7px rgba(167, 201, 90, 0); } 100% { box-shadow: 0 0 0 0 rgba(167, 201, 90, 0); } }

.search { position: relative; display: flex; align-items: center; gap: 8px; padding: 0 12px; height: 46px; width: 100%; }
.search svg { width: 18px; height: 18px; fill: none; stroke: var(--ink-2); stroke-width: 2; stroke-linecap: round; flex: none; }
.search input { flex: 1; min-width: 0; height: 100%; background: none; border: 0; outline: none; color: var(--ink); font: inherit; font-size: 15px; }
.search input::placeholder { color: var(--ink-3); }
.search input::-webkit-search-cancel-button { filter: invert(0.8); }
.search:focus-within { border-color: rgba(212, 132, 74, 0.6); }
#results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: 6px; list-style: none; max-height: min(60vh, 420px); overflow: auto; background: var(--glass-2); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(14px); }
#results li { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 9px 10px; border-radius: 9px; cursor: pointer; font-size: 14.5px; }
#results li small { color: var(--ink-3); font-size: 12px; white-space: nowrap; }
#results li[aria-selected='true'], #results li:hover { background: rgba(212, 132, 74, 0.18); }
#results li.empty { color: var(--ink-3); cursor: default; background: none; }

.tools { display: flex; align-items: center; gap: 2px; padding: 4px; height: 46px; }
.icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; transition: background 0.15s; }
.icon svg { width: 20px; height: 20px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon:hover, .pill:hover { background: rgba(245, 236, 220, 0.1); }
.icon[aria-expanded='true'] { background: rgba(212, 132, 74, 0.25); }
.pill { display: flex; align-items: center; gap: 7px; height: 38px; padding: 0 12px 0 10px; border-radius: 10px; font-weight: 600; font-size: 14px; }
.pill svg { width: 18px; height: 18px; fill: none; stroke: var(--ink); stroke-width: 1.8; }

/* ---------- settings ---------- */
.popover { position: fixed; top: calc(max(12px, env(safe-area-inset-top)) + 54px); right: 12px; width: 240px; padding: 12px; z-index: 6; }
.popover h3 { margin: 4px 4px 8px; font-size: 11px; letter-spacing: 1.1px; text-transform: uppercase; color: var(--ink-3); font-weight: 700; }
.popover h3:not(:first-child) { margin-top: 14px; }
.popover label { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 6px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.popover label:hover { background: rgba(245, 236, 220, 0.06); }
.popover label span { order: -1; }
.popover input[type='checkbox'] { appearance: none; width: 34px; height: 20px; border-radius: 10px; background: rgba(245, 236, 220, 0.18); position: relative; cursor: pointer; transition: background 0.2s; flex: none; margin: 0; }
.popover input[type='checkbox']::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--ink); transition: transform 0.2s; }
.popover input[type='checkbox']:checked { background: var(--copper); }
.popover input[type='checkbox']:checked::after { transform: translateX(14px); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 3px; background: rgba(0, 0, 0, 0.2); border-radius: 10px; }
.seg button { padding: 7px 0; border-radius: 8px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.seg button[aria-checked='true'] { background: var(--copper); color: #1c130b; }

/* ---------- about ---------- */
dialog#about { width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px); padding: 20px 22px; color: var(--ink); background: var(--glass-2); overflow: auto; }
dialog#about::backdrop { background: rgba(20, 14, 8, 0.4); backdrop-filter: blur(2px); }
.about-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.about-head .logo { width: 46px; height: 46px; }
.about-head h2 { margin: 0; font-family: var(--display); font-size: 22px; }
.about-head p { margin: 2px 0 0; color: var(--ink-2); font-size: 13.5px; }
.about-head .close { margin-left: auto; align-self: flex-start; }
#about-body p { font-size: 14.5px; line-height: 1.6; color: var(--ink-2); }
#about-body b { color: var(--ink); }
#about-body .muted { font-size: 13px; color: var(--ink-3); border-top: 1px solid var(--line); padding-top: 12px; }

/* ---------- map controls ---------- */
.ctrl { position: fixed; right: 12px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; padding: 4px; gap: 2px; z-index: 4; }
.ctrl .sep { height: 1px; background: var(--line); margin: 3px 6px; }

/* ---------- info card ---------- */
#card { position: fixed; left: 12px; top: calc(max(12px, env(safe-area-inset-top)) + 64px); width: min(340px, calc(100vw - 24px)); padding: 16px 18px 14px; z-index: 4; animation: rise 0.25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
#card .close { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; }
#card .kind { display: inline-block; font-size: 11px; letter-spacing: 1px; text-transform: uppercase; font-weight: 700; color: var(--copper); }
#card h2 { margin: 4px 30px 6px 0; font-family: var(--display); font-weight: 600; font-size: 21px; line-height: 1.2; }
#card .blurb { margin: 0 0 8px; font-size: 14px; line-height: 1.55; color: var(--ink-2); }
#card .blurb:empty, #card .facts:empty { display: none; }
#card .facts { margin: 0; font-size: 12.5px; color: var(--ink-3); }

/* ---------- labels & pin ---------- */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
.lbl { position: absolute; left: 0; top: 0; white-space: nowrap; font-size: 12.5px; font-weight: 700; color: #2b2017; padding: 3px 8px 3px 6px; border-radius: 999px; background: rgba(250, 244, 232, 0.88); box-shadow: 0 2px 8px rgba(40, 28, 16, 0.22); pointer-events: auto; cursor: pointer; display: flex; align-items: center; gap: 5px; will-change: transform; transition: opacity 0.2s; }
.lbl::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--copper)); flex: none; }
.lbl.district { background: none; box-shadow: none; color: rgba(60, 44, 28, 0.78); font-weight: 800; letter-spacing: 1.6px; text-transform: uppercase; font-size: 11px; text-shadow: 0 0 4px rgba(250, 244, 232, 0.9), 0 0 2px rgba(250, 244, 232, 1); pointer-events: none; }
.lbl.district::before { display: none; }
.lbl.small { font-size: 11px; font-weight: 600; padding: 2px 7px 2px 5px; }
.lbl.stop::before { border-radius: 2px; }
body.night .lbl { background: rgba(28, 24, 20, 0.85); color: var(--ink); }
body.night .lbl.district { color: rgba(245, 236, 220, 0.7); text-shadow: 0 0 4px #000; background: none; }
#pin { position: fixed; left: 0; top: 0; z-index: 3; pointer-events: none; will-change: transform; }
#pin span { position: absolute; left: -9px; top: -9px; width: 18px; height: 18px; border-radius: 50%; background: var(--copper); border: 3px solid #fff7ea; box-shadow: 0 0 0 0 rgba(212, 132, 74, 0.7); animation: ping 1.6s infinite; }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(212, 132, 74, 0.7); } 80% { box-shadow: 0 0 0 18px rgba(212, 132, 74, 0); } 100% { box-shadow: 0 0 0 0 rgba(212, 132, 74, 0); } }

/* ---------- bottom: dock + minimap ---------- */
.bottom { position: fixed; left: 12px; right: 12px; bottom: max(14px, env(safe-area-inset-bottom)); display: flex; align-items: flex-end; justify-content: center; gap: 12px; pointer-events: none; z-index: 3; }
.bottom > * { pointer-events: auto; }
.dock { display: flex; gap: 6px; padding: 6px; overflow-x: auto; scrollbar-width: none; max-width: min(100%, 1000px); background: var(--glass); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); scroll-snap-type: x proximity; }
.dock::-webkit-scrollbar { display: none; }
.dock button { position: relative; flex: none; width: 112px; height: 72px; border-radius: 11px; overflow: hidden; background: linear-gradient(135deg, #b8a57f, #8f7c5a); scroll-snap-align: start; outline-offset: 2px; transition: transform 0.15s; }
.dock button:hover { transform: translateY(-2px); }
.dock button img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.4s; }
.dock button img.ready { opacity: 1; }
.dock button span { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 7px 5px; font-size: 11.5px; font-weight: 700; line-height: 1.15; text-align: left; color: #fff; background: linear-gradient(transparent, rgba(20, 14, 8, 0.82)); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); }
.dock button.active { box-shadow: 0 0 0 2px var(--copper); }
#minimap { width: 200px; height: 150px; flex: none; cursor: crosshair; padding: 0; margin-left: auto; position: absolute; right: 0; bottom: 0; }
.no-minimap #minimap { display: none; }
.no-sat .sat-attr { display: none; }
.attrib { position: fixed; left: 12px; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 3; font-size: 11px; color: rgba(43, 32, 23, 0.85); background: rgba(250, 244, 232, 0.7); padding: 3px 8px; border-radius: 6px; }
.attrib a { color: inherit; }
body.night .attrib { background: rgba(20, 18, 16, 0.7); color: var(--ink-2); }

#toast { position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); background: var(--glass-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 9; box-shadow: var(--shadow); animation: rise 0.2s ease-out; }

/* ---------- loader ---------- */
#loader { position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; gap: 10px; background: radial-gradient(ellipse at 50% 40%, #e7dcc2, #cdbd98); color: #3b2b1c; transition: opacity 0.6s; }
#loader.hide { opacity: 0; pointer-events: none; }
#loader .logo.big { width: 84px; height: 84px; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px); } }
#loader h1 { margin: 6px 0 0; font-family: var(--display); font-size: 30px; }
#loader p { margin: 0; color: #6b5843; font-size: 14px; min-height: 1.4em; }
#loader .bar { width: 220px; height: 4px; border-radius: 2px; background: rgba(59, 43, 28, 0.15); overflow: hidden; margin-top: 6px; }
#loader .bar i { display: block; height: 100%; width: 0; background: var(--copper-2); transition: width 0.3s; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .brand-text b { font-size: 15px; }
  .top { grid-template-columns: auto auto; }
  .search { grid-column: 1 / -1; grid-row: 2; height: 42px; }
  .pill span { display: none; }
  .pill { width: 38px; padding: 0; justify-content: center; }
  #card { top: auto; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 96px); }
  .ctrl { top: auto; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 230px); transform: none; }
  .bottom { flex-direction: column; align-items: stretch; }
  #minimap { width: 132px; height: 99px; position: static; align-self: flex-end; order: -1; }
  .dock { max-width: 100%; }
  .dock button { width: 96px; height: 64px; }
  .attrib { bottom: auto; top: calc(max(12px, env(safe-area-inset-top)) + 106px); font-size: 10px; }
}
@media (min-width: 861px) {
  .bottom { padding-right: 212px; padding-left: 0; }
  .dock { margin: 0 auto; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---- ride mode ---- */
.popover .hint { margin: 0 4px 10px; font-size: 12.5px; color: var(--ink-3); line-height: 1.4; }
.ride-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ride-grid button { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 10px; background: rgba(245, 236, 220, 0.06); border: 1px solid var(--line); color: var(--ink); font: inherit; font-size: 13.5px; cursor: pointer; text-align: left; }
.ride-grid button:hover { background: rgba(245, 236, 220, 0.13); }
.ride-grid i, #ride .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--c, var(--copper)); flex: none; }
#ride-menu { width: 280px; }
#ride[hidden] { display: none; }
#ride { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 5; display: flex; align-items: center; gap: 14px; padding: 8px 8px 8px 14px; max-width: calc(100vw - 24px); }
#ride .ride-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
#ride .ride-info div { display: flex; flex-direction: column; min-width: 0; }
#ride .ride-info b { font-size: 14.5px; white-space: nowrap; }
#ride .ride-info small { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
#ride .ride-speed { display: flex; align-items: baseline; gap: 4px; font-variant-numeric: tabular-nums; }
#ride .ride-speed b { font-size: 22px; min-width: 2ch; text-align: right; }
#ride .ride-speed small { font-size: 11px; color: var(--ink-3); }
#ride .ride-views { display: flex; }
#ride .ride-views button { padding: 7px 12px; }
#ride .ride-views button[aria-pressed='true'] { background: var(--copper); color: #1d140c; }
body.riding #dock, body.riding #card { display: none; }
body.ride-persp #labels, body.ride-persp #pin, body.ride-persp .ctrl { display: none; }
body.ride-persp #map { cursor: grab; }
@media (max-width: 860px) {
  #ride { flex-wrap: wrap; justify-content: space-between; gap: 8px; width: calc(100vw - 24px); bottom: max(10px, env(safe-area-inset-bottom)); }
  #ride .ride-views { order: 3; width: 100%; }
  #ride .ride-views button { flex: 1; }
  body.riding #minimap { display: none; }
}
