:root {
  --bg: #0b0e14;
  --panel: rgba(16, 20, 30, 0.86);
  --accent: #ffcc33;
  --text: #eef2f8;
}

/* No text/element selection anywhere: long-press-and-drag is a game
   gesture (hold to walk), so selection callouts, loupes and tap
   highlights must never trigger. The chat input re-enables it below. */
* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

img {
  -webkit-user-drag: none;
  pointer-events: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#game {
  position: fixed;
  inset: 0;
  /* A <canvas> is a replaced element, so `inset: 0` alone won't stretch it —
     it needs an explicit size. On an installed iOS PWA `height: 100%` (and
     `100vh`) resolve to the shorter layout viewport, leaving a black strip
     over the home indicator; `dvh`/`dvw` cover the physical screen, safe
     areas included. The vh/vw line is the fallback for iOS < 15.4. */
  width: 100vw;
  height: 100vh;
  width: 100dvw;
  height: 100dvh;
  display: block;
  touch-action: none;
  background: #9fc0e8;
}

/* Character select overlay */
/* Splash: logo floating over the live city backdrop. */
#splash {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  cursor: pointer;
  background: radial-gradient(120% 120% at 50% 30%, rgba(11,14,20,0.0) 40%, rgba(11,14,20,0.55));
}
#splash-logo {
  width: min(560px, 78vw);
  max-height: 55vh;
  object-fit: contain;
  filter: drop-shadow(0 10px 40px rgba(0,0,0,0.65));
}
#splash-hint {
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-shadow: 0 2px 10px rgba(0,0,0,0.8);
  animation: splashPulse 1.6s ease-in-out infinite;
}
@keyframes splashPulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

#menu {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom);
  background: radial-gradient(120% 120% at 50% 20%, rgba(11,14,20,0.55), rgba(11,14,20,0.9));
  text-align: center;
  z-index: 10;
}

#menu-logo {
  width: min(300px, 56vw);
  object-fit: contain;
  filter: drop-shadow(0 6px 22px rgba(0,0,0,0.55));
}

#menu h1 {
  margin: 0;
  font-size: clamp(38px, 9vw, 84px);
  letter-spacing: 3px;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 4px 24px rgba(0,0,0,0.6);
}

.tagline {
  margin: 0 0 14px;
  opacity: 0.85;
  font-size: clamp(14px, 3.5vw, 18px);
}

.cards {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
}

.card {
  width: 150px;
  padding: 16px 14px;
  background: var(--panel);
  border: 2px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  backdrop-filter: blur(6px);
}
.card:hover, .card:focus {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  outline: none;
}

.avatar {
  width: 84px;
  height: 84px;
  margin: 0 auto 10px;
  border-radius: 12px;
}
/* Blocky avatar previews echoing the in-game character colors. */
.avatar-0 {
  background:
    linear-gradient(#ec3459 0 55%, #262838 55% 100%);
  box-shadow: inset 0 0 0 6px rgba(0,0,0,0.15);
}
.avatar-1 {
  background:
    linear-gradient(#268c80 0 55%, #33333d 55% 100%);
  box-shadow: inset 0 0 0 6px rgba(0,0,0,0.15);
}

.char-name { font-weight: 700; font-size: 18px; }
.char-role { opacity: 0.6; font-size: 13px; margin-top: 2px; }

/* Multiplayer lobby roster */
#lobby {
  margin-top: 14px;
  min-width: 240px;
  max-width: 340px;
  padding: 10px 16px 12px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  backdrop-filter: blur(6px);
}
#lobby-status {
  font-size: 13px;
  font-weight: 700;
  opacity: 0.85;
}
#lobby-status.online { color: #7ee787; opacity: 1; }
#lobby-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  font-size: 13px;
  text-align: left;
  max-height: 120px;
  overflow-y: auto;
}
#lobby-list li {
  padding: 2px 0;
  opacity: 0.9;
}
#lobby-list li .who { font-weight: 700; }
#lobby-list li .what { opacity: 0.65; }

.hint {
  margin-top: 18px;
  max-width: 520px;
  font-size: clamp(11px, 3vw, 14px);
  line-height: 1.6;
  opacity: 0.8;
}
.hint b { color: var(--accent); }

.fatal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  font-size: 18px;
  color: #ff8080;
}

/* In-game HUD */
#hud {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  top: max(14px, env(safe-area-inset-top));
  z-index: 5;
  display: none;
  pointer-events: none;
}
#hud-status {
  display: inline-block;
  padding: 8px 14px;
  background: var(--panel);
  border-radius: 10px;
  font-weight: 700;
  font-size: clamp(13px, 3.5vw, 16px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
#hud-prompt {
  margin-top: 8px;
  display: inline-block;
  padding: 6px 12px;
  background: var(--accent);
  color: #201a00;
  border-radius: 8px;
  font-weight: 700;
  font-size: clamp(12px, 3.2vw, 15px);
  visibility: hidden;
}

/* Clock / weather / online count, top-right */
#hud-clock {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  top: max(14px, env(safe-area-inset-top));
  z-index: 5;
  display: none;
  padding: 8px 14px;
  background: var(--panel);
  border-radius: 10px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 600;
  font-size: clamp(12px, 3.2vw, 15px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  pointer-events: none;
}

/* Cash balance, top-right under the clock */
#hud-cash {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  top: calc(max(14px, env(safe-area-inset-top)) + 44px);
  z-index: 5;
  display: none;
  padding: 6px 14px;
  background: var(--panel);
  border-radius: 10px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 700;
  font-size: clamp(12px, 3.2vw, 15px);
  color: #7ddf7d;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  pointer-events: none;
}

/* Minimap, bottom-right */
#minimap {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 5;
  display: none;
  cursor: pointer; /* tap/click (or M) cycles the zoom level */
  touch-action: none;
  /* Scales with the shorter viewport edge: full 216px on desktop, ~99px
     on phones in either orientation (vh alone left portrait full-size). */
  width: clamp(86px, 26.4vmin, 216px);
  height: clamp(86px, 26.4vmin, 216px);
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.18);
  box-shadow: 0 4px 16px rgba(0,0,0,0.45);
  opacity: 0.92;
}

/* QR share: toggle button perched above the minimap corner, the code
   canvas swapping into the minimap's exact spot. */
#qr-toggle {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + clamp(86px, 26.4vmin, 216px) + 10px);
  z-index: 6;
  display: none; /* shown while playing */
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(20, 22, 32, 0.82);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
#qr-toggle svg { display: block; margin: 0 auto; }
#qr-toggle.on { background: #d9a11c; color: #1a1a1a; }
#qr-map {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 5;
  display: none; /* swapped in for the minimap */
  cursor: pointer; /* click copies the link */
  width: clamp(86px, 26.4vmin, 216px);
  height: clamp(86px, 26.4vmin, 216px);
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.18);
  box-shadow: 0 4px 16px rgba(0,0,0,0.45);
  background: #fff;
}
#qr-toast {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + clamp(86px, 26.4vmin, 216px) + 52px);
  z-index: 6;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(20, 22, 32, 0.92);
  color: #7ee787;
  font: 600 13px system-ui, sans-serif;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}

/* Character editor */
.edit-btn {
  margin-top: 10px;
  padding: 5px 10px;
  width: 100%;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.edit-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Character-slot extras: cash line + the empty "new character" card */
.char-cash {
  margin-top: 2px;
  font-size: 12px;
  font-weight: 700;
  color: #7ddf7d;
}
.card.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  font-size: 15px;
  font-weight: 700;
  opacity: 0.7;
  border-style: dashed;
}
.card.empty:hover { opacity: 1; }

/* The editor's name field */
#ed-name {
  flex: 1;
  padding: 6px 10px;
  border-radius: 9px;
  border: 2px solid #4a4f63;
  background: #262a3a;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  min-width: 0;
}
#ed-name:focus { outline: none; border-color: var(--accent); }

#editor {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 7, 12, 0.7);
}
#editor-box {
  width: min(92vw, 380px);
  padding: 18px 20px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  backdrop-filter: blur(8px);
  text-align: center;
}
#editor-title { font-weight: 800; font-size: 20px; margin-bottom: 10px; }
#editor-preview {
  width: 200px;
  height: 200px;
  margin: 0 auto 12px;
  border-radius: 12px;
  background-size: cover;
  background-position: center;
  background-color: #10131c;
}
.ed-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}
.ed-label {
  width: 46px;
  text-align: right;
  font-size: 13px;
  opacity: 0.75;
  flex-shrink: 0;
}
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.sw {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.18);
  cursor: pointer;
  padding: 0;
}
.sw.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255,204,51,0.35); }
/* Text option buttons (height / build). */
.opts { display: flex; gap: 6px; flex-wrap: wrap; }
.opt {
  padding: 4px 12px;
  border-radius: 9px;
  border: 2px solid #4a4f63;
  background: #262a3a;
  color: #cfd3e0;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.opt.sel {
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 2px rgba(255,204,51,0.35);
}
#editor-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}
#editor-actions button {
  padding: 8px 18px;
  border-radius: 10px;
  border: none;
  font-weight: 700;
  cursor: pointer;
}
#ed-shuffle { background: rgba(255,255,255,0.12); color: var(--text); }
#ed-done { background: var(--accent); color: #201a00; }

/* --- Vehicle customization shop ---------------------------------------- */
#shop {
  position: fixed;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: min(78vw, 300px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  backdrop-filter: blur(8px);
}
#shop-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
#shop-title { font-weight: 800; font-size: 18px; }
#shop-cash { color: var(--accent); font-weight: 700; }
#shop-tabs { display: flex; gap: 5px; flex-wrap: wrap; }
#shop-tabs .opt { font-size: 12px; padding: 3px 9px; }
#shop-opts {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-content: flex-start;
}
#shop-opts .opt {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
}
#shop-opts .price { opacity: 0.7; }
#shop-opts .swatches { padding: 2px 0; }
#shop-actions { display: flex; gap: 10px; }
#shop-actions button {
  flex: 1;
  padding: 9px 0;
  border-radius: 10px;
  border: none;
  font-weight: 700;
  cursor: pointer;
}
#shop-buy { background: var(--accent); color: #201a00; }
#shop-buy:disabled { opacity: 0.45; cursor: default; }
#shop-done { background: rgba(255,255,255,0.12); color: var(--text); }
#shop-repair {
  padding: 9px 0;
  border-radius: 10px;
  border: none;
  font-weight: 700;
  cursor: pointer;
  background: #b3402e;
  color: #fff;
}
#shop-repair:disabled { opacity: 0.45; cursor: default; }

/* --- Chat + speech bubbles -------------------------------------------- */
#chat-open {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 30;
  display: none; /* shown in-game */
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(20, 22, 32, 0.82);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
#cam-toggle {
  position: fixed;
  left: 64px;
  bottom: 12px;
  z-index: 30;
  display: none; /* shown in-game */
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(20, 22, 32, 0.82);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
#cam-toggle.on { background: var(--accent); }
/* Siren toggle: only visible inside a vehicle that has one. */
#siren-toggle {
  position: fixed;
  left: 116px;
  bottom: 12px;
  z-index: 30;
  display: none; /* shown in siren vehicles */
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(20, 22, 32, 0.82);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
#siren-toggle.on {
  background: var(--accent);
  animation: sirenPulse 0.6s linear infinite;
}
/* Taxi call: shares the cam button's spot (cam is vehicle-only, taxi is
   on-foot-only). */
#taxi-call {
  position: fixed;
  left: 64px;
  bottom: 12px;
  z-index: 30;
  display: none; /* shown on foot */
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(20, 22, 32, 0.82);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
/* Taxi destination map */
#bigmap {
  position: fixed;
  inset: 0;
  z-index: 22;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 7, 12, 0.7);
}
#bigmap-box {
  padding: 14px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#bigmap-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 800;
  font-size: 16px;
}
#bigmap-fare { color: var(--accent); font-weight: 700; }
#bigmap-canvas {
  width: min(74vmin, 540px);
  height: min(74vmin, 540px);
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.18);
  cursor: crosshair;
}
#bigmap-actions { display: flex; gap: 10px; }
#bigmap-actions button {
  flex: 1;
  padding: 9px 0;
  border-radius: 10px;
  border: none;
  font-weight: 700;
  cursor: pointer;
}
#bigmap-go { background: var(--accent); color: #201a00; }
#bigmap-go:disabled { opacity: 0.45; cursor: default; }
#bigmap-stay { background: rgba(255,255,255,0.12); color: var(--text); }

/* Full-screen fade for screen transitions */
#fade {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
@keyframes sirenPulse {
  0%, 100% { box-shadow: 0 0 10px 2px rgba(255, 60, 60, 0.8); }
  50% { box-shadow: 0 0 10px 2px rgba(80, 120, 255, 0.8); }
}
#chat {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 31;
  width: min(340px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#chat-suggest {
  display: flex;
  flex-direction: column-reverse;
  gap: 4px;
  max-height: 40vh;
  overflow-y: auto;
}
.chat-phrase {
  text-align: left;
  padding: 7px 12px;
  border: none;
  border-radius: 10px;
  background: rgba(20, 22, 32, 0.82);
  color: #e8eaf2;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.chat-phrase:hover { background: rgba(60, 64, 84, 0.9); }
#chat-bar {
  display: flex;
  gap: 6px;
}
#chat-input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #4a4f63;
  background: rgba(16, 18, 26, 0.92);
  color: #fff;
  font: inherit;
  font-size: 15px;
  outline: none;
}
#chat-input:focus { border-color: var(--accent); }
#chat-send {
  width: 44px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #222;
  font-size: 17px;
  cursor: pointer;
}
#bubbles {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  overflow: hidden;
}

/* Crew bar: round face portraits + names of everyone sharing your ride,
   bottom center; the driver's card gets an accent ring and tag. */
#crew {
  position: fixed;
  left: 50%;
  bottom: max(12px, calc(env(safe-area-inset-bottom) + 6px));
  transform: translateX(-50%);
  z-index: 20;
  display: none; /* flex while riding with others */
  gap: 12px;
  pointer-events: none;
}
.crew-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.crew-face {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background-size: cover;
  background-position: center;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
}
.crew-card.driver .crew-face { border-color: var(--accent); }
.crew-name {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
  max-width: 68px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crew-tag {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.09em;
  color: var(--accent);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

/* "Rotate to landscape" hint: a phone icon that tips over sideways.
   Sits above the crew bar's row so the two never overlap. */
#rotate-hint {
  position: fixed;
  left: 50%;
  bottom: max(104px, calc(env(safe-area-inset-bottom) + 92px));
  transform: translateX(-50%);
  z-index: 30;
  padding: 10px 12px;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.45);
  color: var(--accent);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s, visibility 0.4s;
}
#rotate-hint.show {
  opacity: 1;
  visibility: visible;
}
#rotate-hint svg {
  display: block;
  width: 36px;
  height: 36px;
}
#rotate-hint.show svg {
  animation: rotateHint 1.8s ease-in-out infinite;
}
@keyframes rotateHint {
  0%, 18% { transform: rotate(0deg); }
  55%, 82% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}
.bubble {
  position: absolute;
  transform: translate(-50%, -100%);
  max-width: 220px;
  padding: 6px 11px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.75);
  color: #16181f;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(255, 255, 255, 0.75);
  border-bottom: none;
}
.bubble .who {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #7a5b12;
}
