/* Shady Garage & Speed — UI styles */
:root {
  --accent: #ff5d3b;
  --accent-dark: #e04a2c;
  --panel-bg: rgba(15, 18, 26, 0.86);
  --card: #1f2430;
  --card-2: #262c3a;
  --text: #f3f4f6;
  --muted: #9aa3b2;
  --good: #22c55e;
  --warn: #eab308;
  --bad: #ef4444;
  --t1: #9ca3af;
  --t2: #3b82f6;
  --t3: #a855f7;
  --t4: #f59e0b;
}

* {
  box-sizing: border-box; margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  background: #0b0e14;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  user-select: none;
  -webkit-touch-callout: none;
}

/* keep text inputs usable */
input, textarea {
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

#app, #app canvas { position: fixed; inset: 0; display: block; touch-action: none; }

.hidden { display: none !important; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; z-index: 10; }
.screen.overlay {
  background: rgba(8, 10, 16, 0.55);
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto;
}
.screen.hud { pointer-events: none; }
.screen.hud .panel, .screen.hud button { pointer-events: auto; }

/* ---------- panels & cards ---------- */
.panel {
  background: var(--panel-bg);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 14px 16px;
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}

.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(6, 8, 12, 0.66);
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
}
.modal-card {
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 18px;
  padding: 26px 30px;
  width: min(560px, 94vw);
  max-height: 86vh;
  max-height: 86dvh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-card h2 { margin-bottom: 14px; }
.modal-card h3 { margin: 12px 0 8px; }
.modal-card .row { margin-top: 18px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.howto-list { list-style: none; margin: 8px 0 4px; }
.howto-list li { padding: 4px 0; color: var(--muted); line-height: 1.45; }
.howto-list b { color: var(--text); }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 700;
  color: #fff; background: var(--accent);
  border: none; border-radius: 12px;
  padding: 10px 20px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s;
}
.btn:hover:not(:disabled) { background: var(--accent-dark); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn.big { padding: 14px 30px; font-size: 18px; min-height: 48px; }
.btn.small { padding: 7px 14px; font-size: 14px; border-radius: 10px; }
.btn.tiny { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { background: transparent; border: 2px solid rgba(255,255,255,0.35); }
.btn.ghost:hover:not(:disabled) { background: rgba(255,255,255,0.12); }

/* ---------- menu ---------- */
.menu-box { text-align: center; padding: 20px; }
.title {
  font-size: clamp(34px, 7vw, 72px);
  letter-spacing: 3px; font-weight: 900;
  text-shadow: 0 6px 24px rgba(0,0,0,0.55);
}
.title span { color: var(--accent); }
.subtitle { color: var(--muted); margin: 10px 0 30px; font-size: 18px; }
.menu-buttons { display: flex; flex-direction: column; gap: 12px; width: min(320px, 86vw); margin: 0 auto; }

/* ---------- setup ---------- */
.setup-box {
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 18px;
  padding: 26px 30px;
  width: min(680px, 94vw);
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
}
.setup-box h2 { margin-bottom: 16px; }
.name-label { display: block; font-weight: 700; margin-bottom: 14px; }
#input-name {
  display: block; margin-top: 6px; width: 100%; max-width: 260px;
  font: inherit; padding: 9px 12px;
  border-radius: 10px; border: 2px solid rgba(255,255,255,0.2);
  background: var(--card-2); color: var(--text);
}
#input-name:focus { outline: none; border-color: var(--accent); }
.pick-label { color: var(--muted); margin-bottom: 10px; }
#setup-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 18px; }
.char-card {
  background: var(--card-2);
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 14px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.char-card:hover { transform: translateY(-2px); }
.char-card.selected { border-color: var(--accent); }
.char-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  margin: 0 auto 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 900; color: #fff;
}
.char-name { font-weight: 800; }
.char-tag { color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.char-desc { color: var(--muted); font-size: 12px; margin-top: 5px; line-height: 1.35; }
.setup-box .row { display: flex; justify-content: space-between; gap: 10px; }

/* ---------- garage HUD ---------- */
.topbar {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 22px;
  padding: 10px 18px;
  white-space: nowrap;
  max-width: 96vw;
}
.stat { font-weight: 800; font-size: 17px; }
.susp-wrap { display: flex; align-items: center; gap: 8px; }
.susp-title { font-size: 13px; color: var(--muted); font-weight: 700; text-transform: uppercase; }
#susp-bar {
  width: 150px; height: 12px;
  background: rgba(255,255,255,0.12);
  border-radius: 8px; overflow: hidden;
}
#susp-fill {
  height: 100%; width: 0%;
  background: var(--good);
  border-radius: 8px;
  transition: width 0.35s ease, background 0.3s;
}
#susp-bar.mid #susp-fill { background: var(--warn); }
#susp-bar.danger #susp-fill { background: var(--bad); animation: susp-pulse 0.5s infinite alternate; }
@keyframes susp-pulse { from { opacity: 1; } to { opacity: 0.45; } }
#susp-label { font-weight: 800; min-width: 26px; }
.topbar-buttons { display: flex; gap: 8px; }

.prompt {
  position: absolute; bottom: calc(26px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--panel-bg);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 10px 22px; border-radius: 999px;
  font-weight: 700;
  pointer-events: none;
  max-width: 92vw;
  text-align: center;
}

#job-panel {
  position: absolute; top: 76px; right: 14px;
  width: min(330px, 92vw);
  max-height: calc(100vh - 100px);
  max-height: calc(100dvh - 100px);
  overflow-y: auto;
}
#job-panel h3 { margin-bottom: 10px; }
.job-row {
  background: var(--card-2);
  border-radius: 10px;
  padding: 9px 10px;
  margin-bottom: 8px;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
.job-row.selected { border-color: var(--accent); }
.job-part { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.part-name { font-weight: 800; }
.cond { font-size: 12px; }
.cond-ok { color: var(--good); }
.cond-bad { color: var(--warn); }
.job-actions { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.job-actions .steal { background: #7c3aed; }
.job-actions .steal:hover:not(:disabled) { background: #6d28d9; }
.note { color: var(--muted); font-size: 11px; font-style: italic; }
.job-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; gap: 8px; }

/* ---------- tier badges ---------- */
.badge {
  display: inline-block;
  font-size: 11px; font-weight: 800;
  padding: 2px 9px; border-radius: 999px;
  color: #0b0e14;
}
.badge.t1 { background: var(--t1); }
.badge.t2 { background: var(--t2); color: #fff; }
.badge.t3 { background: var(--t3); color: #fff; }
.badge.t4 { background: var(--t4); }

/* ---------- build bay ---------- */
#build-panel {
  position: absolute; top: 14px; left: 14px; bottom: 14px;
  width: min(350px, 92vw);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
}
.build-head { display: flex; justify-content: space-between; align-items: center; }
.bars { display: flex; flex-direction: column; gap: 7px; }
.bar-row { display: flex; align-items: center; gap: 8px; }
.bar-name { width: 66px; font-size: 13px; font-weight: 700; color: var(--muted); }
.bar { flex: 1; height: 12px; background: rgba(255,255,255,0.1); border-radius: 8px; overflow: hidden; }
.bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), #ffb020);
  border-radius: 8px;
  transition: width 0.4s ease;
}
.bar-row b { width: 28px; text-align: right; }
.chassis-box { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--card-2); border-radius: 10px; padding: 10px 12px; flex-wrap: wrap; }
.slots { display: flex; flex-direction: column; gap: 6px; }
.slot {
  background: var(--card-2);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.slot .empty { color: var(--muted); font-style: italic; font-size: 13px; }
.inv-title { margin-top: 2px; }
#inventory-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.inv-empty { color: var(--muted); font-size: 13px; grid-column: 1 / -1; }
.inv-card {
  background: var(--card-2);
  border-radius: 10px;
  padding: 9px;
  display: flex; flex-direction: column; gap: 6px;
  align-items: flex-start;
}
.inv-head { display: flex; align-items: center; gap: 7px; }
.inv-icon { font-size: 20px; }
.inv-type { font-size: 12px; color: var(--muted); }
.inv-btns { display: flex; gap: 6px; }
#btn-build-back { margin-top: auto; }

/* ---------- race HUD ---------- */
#race-timer {
  position: absolute; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(30px, 4.5vw, 46px); font-weight: 800;
  text-shadow: 0 3px 12px rgba(0,0,0,0.6);
}
#race-speed {
  position: absolute; right: calc(26px + env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom));
  font-size: clamp(44px, 6vw, 68px); font-weight: 900;
  text-shadow: 0 3px 12px rgba(0,0,0,0.6);
}
#race-speed .unit { font-size: 18px; font-weight: 700; color: var(--muted); margin-left: 6px; }
#race-hint {
  position: absolute; bottom: calc(22px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  color: rgba(255,255,255,0.75); font-size: 13px; font-weight: 600;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
body.touch #race-hint { display: none; }
#race-countdown {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%);
  font-size: clamp(80px, 16vw, 170px); font-weight: 900;
  color: var(--accent);
  text-shadow: 0 8px 40px rgba(0,0,0,0.7);
}
#race-countdown.pop { animation: cd-pop 0.9s ease-out; }
@keyframes cd-pop {
  0% { transform: translate(-50%, -50%) scale(1.6); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(0.92); opacity: 0.9; }
}

/* ---------- race touch controls (coarse pointers only) ---------- */
#race-touch { display: none; }
body.touch #race-touch { display: block; position: absolute; inset: 0; pointer-events: none; }
.touch-cluster {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex; gap: 16px;
}
.touch-cluster.left { left: calc(16px + env(safe-area-inset-left)); }
.touch-cluster.right { right: calc(16px + env(safe-area-inset-right)); }
.tc-btn {
  pointer-events: auto;
  width: 74px; height: 74px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.45);
  background: rgba(20,24,32,0.45);
  color: #fff; font-size: 26px; font-weight: 900; font-family: inherit;
  touch-action: none;
  backdrop-filter: blur(4px);
}
.tc-btn.gas { background: rgba(34,197,94,0.4); font-size: 17px; }
.tc-btn.brk { background: rgba(239,68,68,0.4); font-size: 17px; }
.tc-btn.active { background: rgba(255,93,59,0.65); border-color: #fff; }
.tc-btn.gas.active { background: rgba(34,197,94,0.75); }
.tc-btn.brk.active { background: rgba(239,68,68,0.75); }

#btn-forfeit {
  display: none;
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  width: 46px; height: 46px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(20,24,32,0.55);
  color: #fff; font-size: 20px; font-weight: 900;
  pointer-events: auto;
}
body.touch #btn-forfeit { display: block; }

body.touch #race-speed {
  bottom: calc(106px + env(safe-area-inset-bottom));
  right: calc(16px + env(safe-area-inset-right));
  font-size: clamp(34px, 8vw, 54px);
}

/* ---------- results ---------- */
.res-rows { margin: 10px 0 4px; }
.res-row {
  display: flex; justify-content: space-between;
  padding: 9px 4px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 17px;
}
.res-row span { color: var(--muted); }
.res-row .gold { color: var(--t4); }
.res-row .good { color: var(--good); }

/* ---------- minigame ---------- */
#mg-bar {
  position: relative;
  height: 34px;
  margin: 18px 0 8px;
  background: rgba(239,68,68,0.35);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.15);
}
.mg-zone { position: absolute; top: 0; bottom: 0; }
#mg-yellow-l, #mg-yellow-r { background: rgba(234,179,8,0.55); }
#mg-green { background: rgba(34,197,94,0.75); }
#mg-marker {
  position: absolute; top: -3px; bottom: -3px;
  width: 4px; left: 0;
  background: #fff;
  box-shadow: 0 0 8px #fff;
  border-radius: 2px;
}
#mg-bar.flash-green { box-shadow: 0 0 0 3px var(--good), 0 0 24px var(--good); }
#mg-bar.flash-yellow { box-shadow: 0 0 0 3px var(--warn), 0 0 24px var(--warn); }
#mg-bar.flash-red { box-shadow: 0 0 0 3px var(--bad), 0 0 24px var(--bad); }
#mg-hint { color: var(--muted); font-size: 13px; margin-bottom: 14px; }

/* ---------- toasts ---------- */
#toasts {
  position: fixed;
  left: calc(16px + env(safe-area-inset-left));
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 60;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--panel-bg);
  border: 1px solid rgba(255,255,255,0.1);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 700; font-size: 14px;
  max-width: min(320px, 80vw);
  animation: toast-in 0.25s ease-out;
  transition: opacity 0.35s, transform 0.35s;
  backdrop-filter: blur(6px);
}
.toast.good { border-left-color: var(--good); }
.toast.warn { border-left-color: var(--warn); }
.toast.bad { border-left-color: var(--bad); }
.toast.out { opacity: 0; transform: translateX(-16px); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ================================================================
   Shared compact rules: portrait phones AND landscape phones
   ================================================================ */
@media (max-width: 700px), (max-height: 520px) {
  .topbar { gap: 8px 14px; padding: 8px 12px; flex-wrap: wrap; justify-content: center; }
  .stat { font-size: 14px; }
  .susp-title { font-size: 11px; }
  #susp-bar, #heat-bar { width: 90px; }
  .btn { min-height: 44px; }
  .btn.small { padding: 8px 12px; }
  .btn.tiny { padding: 10px 14px; min-height: 44px; }

  /* job + build panels become bottom sheets */
  #job-panel, #build-panel {
    top: auto;
    left: calc(8px + env(safe-area-inset-left));
    right: calc(8px + env(safe-area-inset-right));
    bottom: calc(8px + env(safe-area-inset-bottom));
    width: auto;
    max-height: 45vh;
    max-height: 45dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #btn-build-back { margin-top: 4px; }

  /* prompt + toasts sit above the sheets */
  .prompt {
    bottom: calc(45vh + 10px + env(safe-area-inset-bottom));
    bottom: calc(45dvh + 10px + env(safe-area-inset-bottom));
    font-size: 13px;
    padding: 8px 16px;
  }
  #toasts {
    bottom: calc(45vh + 12px + env(safe-area-inset-bottom));
    bottom: calc(45dvh + 12px + env(safe-area-inset-bottom));
    left: calc(8px + env(safe-area-inset-left));
  }

  .modal-card { padding: 18px 20px; }
}

/* ================================================================
   Portrait / narrow phones
   ================================================================ */
@media (max-width: 700px) {
  .title { font-size: clamp(30px, 9vw, 48px); }
  .subtitle { font-size: 15px; margin: 8px 0 20px; }
  .setup-box { padding: 18px; }
  #setup-cards { grid-template-columns: 1fr 1fr; }
  .char-avatar { width: 40px; height: 40px; font-size: 18px; }
  .char-card { padding: 10px 8px; }
  #race-timer { font-size: clamp(24px, 7vw, 38px); }
}

/* ================================================================
   Landscape phones (short viewport)
   ================================================================ */
@media (max-height: 520px) {
  .title { font-size: clamp(26px, 9vh, 52px); }
  .subtitle { font-size: 14px; margin: 6px 0 14px; }
  .menu-buttons { flex-direction: row; flex-wrap: wrap; justify-content: center; width: auto; max-width: 92vw; }
  .menu-buttons .btn { min-width: 150px; }
  .setup-box { max-height: 96vh; max-height: 96dvh; padding: 16px 20px; }
  #setup-cards { grid-template-columns: repeat(4, 1fr); }
  .char-avatar { width: 36px; height: 36px; font-size: 16px; margin-bottom: 4px; }
  .char-card { padding: 8px 6px; }
  .char-desc { font-size: 11px; }
  #race-timer { font-size: clamp(20px, 8vh, 36px); top: calc(8px + env(safe-area-inset-top)); }
  #race-speed { font-size: clamp(28px, 9vh, 48px); }
  .tc-btn { width: 64px; height: 64px; }
  body.touch #race-speed { bottom: calc(92px + env(safe-area-inset-bottom)); }
  #race-countdown { font-size: clamp(60px, 22vh, 120px); }
}

/* ================================================================
   Feature additions: heat, NOS, minimap, conditions, leaderboard
   ================================================================ */

/* --- heat bar (garage topbar) --- */
#heat-bar {
  width: 150px; height: 12px;
  background: rgba(255,255,255,0.12);
  border-radius: 8px; overflow: hidden;
}
#heat-fill {
  height: 100%; width: 0%;
  background: #f97316;
  border-radius: 8px;
  transition: width 0.35s ease;
}
#heat-bar.hot #heat-fill { animation: susp-pulse 0.5s infinite alternate; }
#heat-label { font-weight: 800; min-width: 26px; }

/* --- race condition label --- */
#race-conditions {
  position: absolute;
  top: calc(66px + env(safe-area-inset-top));
  left: 50%; transform: translateX(-50%);
  font-size: 13px; font-weight: 800; letter-spacing: 2px;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
  white-space: nowrap;
}

/* --- minimap --- */
#minimap {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  width: 140px; height: 140px;
  background: rgba(10, 14, 20, 0.55);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
}

/* --- NOS meter --- */
#nos-wrap {
  position: absolute;
  right: calc(28px + env(safe-area-inset-right));
  bottom: calc(100px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 8px;
}
#nos-bar {
  width: 120px; height: 10px;
  background: rgba(255,255,255,0.15);
  border-radius: 6px; overflow: hidden;
}
#nos-fill {
  height: 100%; width: 100%;
  background: #22d3ee;
  border-radius: 6px;
  transition: width 0.12s linear;
}
.nos-label {
  font-size: 12px; font-weight: 900; letter-spacing: 1px;
  color: #7dd3fc;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
}
body.touch #nos-wrap {
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(176px + env(safe-area-inset-bottom));
}

/* --- NOS touch button --- */
.tc-btn.nos { background: rgba(59,130,246,0.4); font-size: 15px; }
.tc-btn.nos.active { background: rgba(59,130,246,0.75); }

/* --- leaderboard (results) --- */
#res-best-badge {
  display: inline-block;
  background: var(--t4); color: #0b0e14;
  font-size: 12px; font-weight: 900;
  padding: 3px 12px; border-radius: 999px;
  vertical-align: middle;
}
#res-board { margin-top: 14px; }
.board-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 15px;
}
.board-row .rank { width: 30px; color: var(--muted); font-weight: 700; }
.board-row .rname { flex: 1; }
.board-row .rtime { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; }
.board-row.you {
  background: rgba(255,93,59,0.22);
  border: 1px solid rgba(255,93,59,0.5);
  font-weight: 800;
}
.res-place { color: var(--muted); margin-top: 8px; font-size: 14px; }

/* --- cop modal --- */
.cop-text { color: var(--muted); line-height: 1.45; margin: 4px 0; }

/* --- compact screens --- */
@media (max-width: 700px), (max-height: 520px) {
  #minimap { width: 96px; height: 96px; }
  #race-conditions { top: calc(56px + env(safe-area-inset-top)); font-size: 11px; }
  #nos-bar { width: 90px; }
}
