:root {
  color-scheme: dark;
  --panel: #18241fee;
  --line: #72837388;
  --ink: #f1f1df;
  --sub: #cad6c8;
  --accent: #d7f98b;
  --accent-dark: #202d18;
  --edge: clamp(12px, 1.6vw, 23px);
  --left: max(var(--edge), env(safe-area-inset-left));
  --right: max(var(--edge), env(safe-area-inset-right));
  --top: max(var(--edge), env(safe-area-inset-top));
  --bottom: max(calc(var(--edge) + 9px), calc(env(safe-area-inset-bottom) + 22px));
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: #18221e;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; overflow: hidden; }
[hidden] { display: none !important; }
button, input { font: inherit; }
button { cursor: pointer; color: inherit; }
button:disabled { cursor: wait; opacity: .55; }
button:focus-visible, a:focus-visible, label:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only, .model input { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); }

#viewport { position: relative; height: 100dvh; isolation: isolate; overflow: hidden; background: #b4b6a1; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
[data-view=drive] .map-controls, [data-view=garage] .in-game, [data-view=map] .drive-only { display: none; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 4px 20px #17251d3f; }

.garage {
  position: absolute;
  left: 50%;
  bottom: var(--bottom);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "title models join" "status status status";
  gap: 0 18px;
  align-items: center;
  max-width: calc(100vw - var(--left) - var(--right));
  padding: 10px 12px 10px 18px;
}
h1 { grid-area: title; margin: 0; font-size: 2.35rem; font-weight: 790; line-height: 1; letter-spacing: -.065em; }
fieldset { grid-area: models; border: 0; padding: 0; margin: 0; min-width: 0; display: flex; gap: 5px; }
.model { display: grid; justify-items: center; gap: 6px; min-width: 70px; padding: 8px 6px 6px; border: 1px solid transparent; border-radius: 8px; cursor: pointer; font-size: .76rem; font-weight: 640; color: var(--sub); }
.model:hover { background: #2b3c31; }
.model:has(:checked) { color: var(--ink); border-color: #a5c177; background: #2d3d2d; }
.car-icon { --paint: #d9efac; width: 30px; height: 16px; border-radius: 7px 5px 5px 7px; background: var(--paint); box-shadow: inset 0 -2px #0004, 0 3px #111b; position: relative; transform: rotate(-14deg); }
.car-icon::before { content: ""; position: absolute; inset: 3px 6px 3px 7px; border-radius: 5px 3px 3px 5px; border: solid #253c33; border-width: 1px 4px 1px 6px; }
.car-icon::after { content: ""; position: absolute; left: 1px; top: 3px; width: 3px; height: 3px; border-radius: 1px; background: #f9ffe7; box-shadow: 0 7px #f9ffe7; }
.sedan { --paint: #aaccdc; width: 34px; }
.van { --paint: #e7bd90; width: 32px; height: 17px; border-radius: 6px 3px 3px 6px; }
.van::before { right: 3px; border-right-width: 1px; }
.primary { border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-dark); font-weight: 760; }
.primary:hover:not(:disabled) { background: #e5ffa4; }
#join { grid-area: join; min-width: 88px; min-height: 44px; padding: 8px 14px; }
#status { grid-area: status; margin: 10px 0 2px; font-size: .88rem; color: var(--sub); }

.tools { position: absolute; right: var(--right); top: var(--top); display: grid; justify-items: end; gap: 8px; }
.tool-strip, .zoom { display: flex; padding: 2px; }
.zoom { flex-direction: column; }
.tools button { min-width: 42px; height: 42px; display: grid; place-items: center; background: transparent; border: 0; border-radius: 8px; }
.tools button:hover, .touch button:active { background: #3a4d41; }
.tools button[aria-pressed=true] { background: var(--accent); color: var(--accent-dark); }
button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.zoom button { font-size: 1.3rem; }
.help-button { font-weight: 720; font-size: 1.08rem; }
.screen-icon {
  width: 16px;
  height: 16px;
  background:
    linear-gradient(currentColor,currentColor) left top / 6px 2px,
    linear-gradient(currentColor,currentColor) left top / 2px 6px,
    linear-gradient(currentColor,currentColor) right top / 6px 2px,
    linear-gradient(currentColor,currentColor) right top / 2px 6px,
    linear-gradient(currentColor,currentColor) left bottom / 6px 2px,
    linear-gradient(currentColor,currentColor) left bottom / 2px 6px,
    linear-gradient(currentColor,currentColor) right bottom / 6px 2px,
    linear-gradient(currentColor,currentColor) right bottom / 2px 6px;
  background-repeat: no-repeat;
}
.keys { position: fixed; inset: calc(var(--top) + 53px) var(--right) auto auto; margin: 0; padding: 12px; color: var(--ink); font-size: .85rem; }
.keys:popover-open { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; }
.keys dd { margin: 0; color: var(--sub); }
kbd { border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; font: 650 .78rem ui-monospace, monospace; }

.compass, .presence { position: absolute; top: var(--top); left: var(--left); }
.compass { width: 39px; display: grid; justify-items: center; gap: 2px; padding: 4px 0 6px; font-size: .68rem; }
.compass i { width: 12px; height: 17px; clip-path: polygon(50% 0,100% 100%,50% 77%,0 100%); background: linear-gradient(90deg,var(--accent) 50%,#8ea980 50%); }
.presence { display: flex; gap: 7px; align-items: center; padding: 6px 9px; font-size: .78rem; font-variant-numeric: tabular-nums; }
.presence > span:first-child { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; }
.speed-panel { position: absolute; left: var(--left); bottom: var(--bottom); display: grid; gap: 3px; padding: 8px 11px; min-width: 64px; max-width: min(36vw, 340px); }
.speed { white-space: nowrap; line-height: 1; }
.speed strong { font-size: 1.8rem; letter-spacing: -.045em; font-variant-numeric: tabular-nums; }
.speed small, #street { color: var(--sub); font-size: .73rem; }
#street { font-weight: 630; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#minimap-button { position: absolute; right: var(--right); bottom: var(--bottom); padding: 2px; border-radius: 8px; overflow: hidden; }
#minimap { display: block; width: 116px; height: 82px; border-radius: 5px; }
.touch { display: none; }
.map-notice { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); padding: 10px 13px; white-space: nowrap; }
.attribution { position: absolute; right: max(0px, env(safe-area-inset-right)); bottom: env(safe-area-inset-bottom); background: #18241fea; border-radius: 5px 0 0; padding: 2px 6px; color: var(--sub); font-size: .65rem; white-space: nowrap; }
.attribution a { color: inherit; text-decoration: none; }
.attribution a:hover { text-decoration: underline; }

@media (max-width: 510px) {
  .garage { width: 320px; grid-template-columns: 1fr auto; grid-template-areas: "title join" "models models" "status status"; padding: 11px; gap: 9px 10px; }
  h1 { padding-left: 3px; font-size: 2rem; }
  .model { flex: 1; min-width: 0; }
}

@media (pointer: coarse), (max-width: 750px) {
  .touch { position: absolute; left: var(--left); right: var(--right); bottom: var(--bottom); display: flex; justify-content: space-between; gap: 4px; pointer-events: none; }
  .touch div { display: flex; gap: 5px; }
  .touch button { min-width: 42px; padding: 0 7px; height: 46px; touch-action: none; user-select: none; pointer-events: auto; font-size: .84rem; }
  .touch button.primary { min-width: 52px; box-shadow: 0 4px 20px #17251d3f; }
  .speed-panel, #minimap-button { bottom: calc(var(--bottom) + 54px); }
  .speed-panel { max-width: calc(100vw - var(--left) - var(--right) - 100px); }
  #minimap { width: 88px; height: 63px; }
}
@media (pointer: coarse) {
  .tools .help-button { display: none; }
}
