/* =====================================================================
   Car Racing — Mithun GamesZone (dark gaming theme)
   ===================================================================== */
:root {
  --bg: #0b1020; --bg2: #121a30; --card: #161f38; --line: #26314f;
  --text: #eef2ff; --dim: #9aa6c6; --accent: #ef4444; --accent2: #f59e0b; --good: #22c55e; --blue: #3b82f6;
  --font: "Hind Siliguri", "Noto Sans Bengali", "Nirmala UI", "SolaimanLipi", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
.hidden { display: none !important; }
.muted { color: var(--dim); }
.small { font-size: 0.82rem; }
.center { text-align: center; }
button, input, select { font-family: inherit; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 12px 18px; cursor: pointer; text-decoration: none;
  background: linear-gradient(135deg, #ef4444, #f97316); color: #fff; font-weight: 700; font-size: 1rem;
  box-shadow: 0 6px 18px rgba(239, 68, 68, .28); transition: transform .12s, filter .12s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: grayscale(.4); }
.btn-outline { background: transparent; border: 1.5px solid #3a4770; box-shadow: none; color: var(--text); }
.btn-ghost { background: transparent; box-shadow: none; color: var(--dim); }
.btn-big { width: 100%; padding: 15px; font-size: 1.1rem; margin-top: 8px; }
.btn-sm { padding: 7px 12px; font-size: .9rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.btn-row .btn { flex: 1 1 160px; }
.btn-col { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

/* =====================================================================
   LOBBY
   ===================================================================== */
.lobby-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 0%, rgba(239, 68, 68, .18), transparent 40%),
    radial-gradient(circle at 90% 10%, rgba(59, 130, 246, .16), transparent 40%),
    repeating-linear-gradient(90deg, transparent 0 60px, rgba(255, 255, 255, .015) 60px 61px), var(--bg);
}
.back-pill {
  position: fixed; top: 12px; left: 12px; z-index: 50; padding: 8px 14px; border-radius: 999px;
  background: rgba(22, 31, 56, .9); color: var(--text); text-decoration: none; font-size: .9rem; border: 1px solid var(--line);
}
.lobby { max-width: 860px; margin: 0 auto; padding: 64px 16px 40px; }
.lobby-head { text-align: center; margin-bottom: 18px; }
.lobby-flags { font-size: 1.6rem; letter-spacing: 6px; }
.lobby-head h1 {
  margin: 4px 0; font-size: clamp(2rem, 6vw, 3rem);
  background: linear-gradient(90deg, #fca5a5, #f59e0b, #fde68a); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lobby-head p { color: var(--dim); margin: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px; margin-bottom: 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.card h2 { margin: 0 0 12px; font-size: 1.15rem; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; flex: 1; min-width: 0; }
.field label, .garage-pick > label { font-size: .85rem; color: var(--dim); }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { min-width: 150px; }
input[type=text], select {
  width: 100%; background: var(--bg2); color: var(--text); border: 1.5px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font-size: 1rem; outline: none;
}
input[type=text]:focus, select:focus { border-color: #f97316; }
.code-input { text-transform: uppercase; letter-spacing: 3px; font-weight: 700; }
.garage { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.preview { width: 100%; aspect-ratio: 4 / 3; border-radius: 14px; background: radial-gradient(circle at 50% 70%, #1e2a48, #0b1020); display: block; touch-action: pan-y; cursor: grab; }
.preview.no-gl { display: none; }
.garage-pick { display: flex; flex-direction: column; gap: 8px; }
.model-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.model-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border-radius: 10px; cursor: pointer;
  background: var(--bg2); border: 1.5px solid var(--line); color: var(--text); font-size: .8rem;
}
.model-btn span { font-size: 1.4rem; }
.model-btn.sel { border-color: #f97316; background: rgba(249, 115, 22, .15); }
.color-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.color-btn { aspect-ratio: 1; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .15); cursor: pointer; min-height: 30px; }
.color-btn.sel { border-color: #fff; box-shadow: 0 0 0 3px #f97316; }
.custom-color { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--dim); }
.custom-color input { width: 44px; height: 30px; border: 0; background: none; padding: 0; cursor: pointer; }
.tabs { display: flex; gap: 6px; background: var(--bg2); padding: 5px; border-radius: 12px; margin-bottom: 14px; }
.tab { flex: 1; border: 0; background: transparent; color: var(--dim); padding: 10px 6px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: .92rem; }
.tab.active { background: linear-gradient(135deg, #ef4444, #f97316); color: #fff; }
.round-info { background: var(--bg2); border-radius: 10px; padding: 10px 12px; font-size: .9rem; color: var(--dim); }
.round-info b { color: var(--text); }
.lobby-error { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: rgba(239, 68, 68, .15); border: 1px solid rgba(239, 68, 68, .5); color: #fecaca; }
.rejoin { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: rgba(34, 197, 94, .12); border: 1px solid rgba(34, 197, 94, .45); padding: 10px 14px; border-radius: 14px; margin-bottom: 16px; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.help ul { margin: 6px 0 0; padding-left: 18px; color: var(--dim); font-size: .9rem; line-height: 1.8; }
kbd { background: #26314f; border-radius: 5px; padding: 1px 6px; font-family: inherit; font-size: .8rem; color: var(--text); border-bottom: 2px solid #111827; }
#sessionAdmin { margin-top: 10px; }
@media (max-width: 640px) {
  .garage, .help-grid { grid-template-columns: 1fr; }
  .tab { font-size: .8rem; }
}

/* =====================================================================
   RACE PAGE
   ===================================================================== */
.race-page { position: fixed; inset: 0; overflow: hidden; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; background: #000; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.tags { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.name-tag {
  position: absolute; left: 0; top: 0; white-space: nowrap; font-size: 13px; font-weight: 700; color: #fff;
  background: rgba(0, 0, 0, .55); padding: 2px 8px 2px 6px; border-radius: 999px; display: flex; align-items: center; gap: 5px;
  transform-origin: 50% 100%; text-shadow: 0 1px 2px #000;
}
.name-tag i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; border: 1px solid #fff; }

/* top bar */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; height: calc(48px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 8px 0;
  display: flex; align-items: center; gap: 6px; z-index: 80;
  background: linear-gradient(180deg, rgba(5, 8, 18, .75), rgba(5, 8, 18, 0));
}
.tb-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, .15); background: rgba(15, 20, 38, .7);
  color: #fff; font-size: 18px; cursor: pointer; position: relative; flex: 0 0 auto;
}
.tb-title { flex: 1; text-align: center; font-weight: 700; font-size: .95rem; text-shadow: 0 1px 3px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { position: absolute; top: -5px; right: -5px; background: #ef4444; color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }

/* HUD */
.hud { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
.hud-tl { position: absolute; top: calc(54px + env(safe-area-inset-top)); left: 10px; display: flex; gap: 10px; align-items: stretch; }
.hud-pos {
  background: rgba(8, 12, 26, .72); border-radius: 14px; padding: 4px 12px; display: flex; align-items: baseline; border: 1px solid rgba(255, 255, 255, .12);
}
.hud-pos b { font-size: 2.3rem; line-height: 1.1; color: #fde047; text-shadow: 0 2px 8px rgba(0, 0, 0, .6); }
.hud-pos small { font-size: 1rem; color: #cbd5e1; margin-left: 2px; }
.hud-rows { background: rgba(8, 12, 26, .72); border-radius: 14px; padding: 5px 12px; font-size: .82rem; border: 1px solid rgba(255, 255, 255, .12); display: flex; flex-direction: column; justify-content: center; }
.hud-rows div { display: flex; justify-content: space-between; gap: 12px; }
.hud-rows span { color: #9aa6c6; }
.hud-board { position: absolute; top: calc(122px + env(safe-area-inset-top)); left: 10px; margin: 0; padding: 0; list-style: none; font-size: .8rem; }
.hud-board li { display: flex; align-items: center; gap: 6px; background: rgba(8, 12, 26, .6); margin-bottom: 3px; padding: 3px 9px; border-radius: 8px; max-width: 170px; }
.hud-board li.me { background: rgba(249, 115, 22, .55); }
.hud-board li b { width: 14px; }
.hud-board li i { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; border: 1px solid #fff; }
.hud-board li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-board li em { font-style: normal; margin-left: auto; }
.minimap { position: absolute; top: calc(54px + env(safe-area-inset-top)); right: 10px; width: 150px; height: 150px; background: rgba(8, 12, 26, .55); border-radius: 16px; border: 1px solid rgba(255, 255, 255, .12); }
.speedo {
  position: absolute; bottom: calc(16px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: rgba(8, 12, 26, .72); border-radius: 16px; padding: 6px 18px 8px; text-align: center; min-width: 130px; border: 1px solid rgba(255, 255, 255, .12);
}
.speedo b { font-size: 2rem; line-height: 1; font-variant-numeric: tabular-nums; }
.speedo small { display: block; font-size: .7rem; color: #9aa6c6; }
.speedo .bar { height: 5px; background: rgba(255, 255, 255, .12); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.speedo .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #22c55e, #facc15, #ef4444); }

.big-msg { position: absolute; top: 34%; left: 0; right: 0; text-align: center; z-index: 25; pointer-events: none; font-weight: 800; color: #fff; text-shadow: 0 4px 18px rgba(0, 0, 0, .7); }
.big-msg.count { font-size: clamp(5rem, 18vw, 9rem); color: #fde047; animation: pop .9s ease-out; }
.big-msg.go { font-size: clamp(4rem, 14vw, 7rem); color: #4ade80; animation: pop .6s ease-out; }
.big-msg.intro { font-size: clamp(2rem, 7vw, 3.4rem); }
.big-msg small { display: block; font-size: .5em; color: #fde68a; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.sub-msg {
  position: absolute; top: 24%; left: 50%; transform: translateX(-50%); z-index: 25; pointer-events: none; opacity: 0; transition: opacity .2s;
  background: rgba(8, 12, 26, .8); padding: 8px 16px; border-radius: 12px; font-weight: 600; max-width: 90vw; text-align: center;
}
.sub-msg.show { opacity: 1; }

.toasts { position: absolute; top: calc(60px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 85; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: min(90vw, 420px); }
.toast { background: rgba(15, 20, 38, .92); border: 1px solid rgba(255, 255, 255, .15); padding: 8px 14px; border-radius: 12px; font-size: .92rem; transition: opacity .5s, transform .5s; max-width: 100%; overflow-wrap: anywhere; }
.toast.good { border-color: #22c55e; }
.toast.bad { border-color: #ef4444; }
.toast.chat { border-color: #3b82f6; }
.toast.out { opacity: 0; transform: translateY(-8px); }

/* touch controls */
.touch { position: absolute; inset: 0; z-index: 30; pointer-events: none; }
.t-left, .t-right { position: absolute; bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; gap: 12px; pointer-events: auto; }
.t-left { left: calc(14px + env(safe-area-inset-left)); }
.t-right { right: calc(14px + env(safe-area-inset-right)); }
.t-btn {
  width: 78px; height: 78px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .35); background: rgba(15, 20, 38, .45);
  color: #fff; font-size: 30px; display: flex; flex-direction: column; align-items: center; justify-content: center; touch-action: none;
  -webkit-tap-highlight-color: transparent; backdrop-filter: blur(2px);
}
.t-btn small { font-size: 11px; font-weight: 700; margin-top: -2px; }
.t-btn.on { background: rgba(249, 115, 22, .6); border-color: #fff; transform: scale(.95); }
.t-gas { width: 92px; height: 92px; background: rgba(34, 197, 94, .35); }
.t-brake { background: rgba(239, 68, 68, .3); align-self: flex-end; }
.t-mid { position: absolute; bottom: calc(100px + env(safe-area-inset-bottom)); right: calc(14px + env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 6px; pointer-events: auto; }
.t-small { border: 1px solid rgba(255, 255, 255, .3); background: rgba(15, 20, 38, .6); color: #fff; border-radius: 10px; padding: 7px 10px; font-size: 12px; font-weight: 700; }
.t-small.on { background: rgba(34, 197, 94, .6); }

/* voice buttons (shared module) — move them out of the steering area */
.race-page .voice-controls { left: auto; right: 10px; bottom: auto; top: calc(212px + env(safe-area-inset-top)); flex-direction: column; }
.race-page .voice-perm-hint { bottom: auto; top: calc(60px + env(safe-area-inset-top)); }

/* chat */
.chat-panel {
  position: absolute; z-index: 90; right: 10px; top: calc(54px + env(safe-area-inset-top)); width: min(360px, calc(100vw - 20px)); max-height: min(70vh, 460px);
  background: rgba(13, 18, 36, .96); border: 1px solid var(--line); border-radius: 16px; display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.x-btn { background: none; border: 0; color: var(--dim); font-size: 18px; cursor: pointer; }
.chat-log { flex: 1; overflow-y: auto; padding: 8px 12px; font-size: .92rem; min-height: 120px; user-select: text; -webkit-user-select: text; }
.chat-msg { margin-bottom: 6px; overflow-wrap: anywhere; }
.chat-msg.mine span { color: #fde68a; }
.chat-emojis { display: flex; gap: 4px; padding: 4px 10px; flex-wrap: wrap; }
.chat-emojis button { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; font-size: 18px; padding: 3px 6px; cursor: pointer; }
.chat-form { display: flex; gap: 6px; padding: 8px 10px 10px; }
.chat-form input { flex: 1; background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; font-size: 16px; min-width: 0; }
.chat-form button { background: #3b82f6; color: #fff; border: 0; border-radius: 10px; padding: 0 14px; font-weight: 700; cursor: pointer; }

/* overlays */
.overlay { position: absolute; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; padding: calc(54px + env(safe-area-inset-top)) 16px 16px; background: rgba(4, 6, 14, .55); overflow-y: auto; }
#waitOv { background: linear-gradient(180deg, rgba(4, 6, 14, .15), rgba(4, 6, 14, .6)); align-items: flex-end; }
.ov-card {
  width: min(520px, 100%); background: rgba(18, 26, 48, .96); border: 1px solid var(--line); border-radius: 20px; padding: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .55); max-height: calc(100% - 20px); overflow-y: auto; margin: auto;
}
.ov-card.slim { width: min(380px, 100%); text-align: center; }
.ov-card h2 { margin: 0 0 12px; text-align: center; font-size: 1.3rem; }
.room-code-box { display: flex; flex-direction: column; align-items: center; background: var(--bg2); border: 1.5px dashed #3a4770; border-radius: 14px; padding: 10px; margin-bottom: 10px; }
.room-code-box span { font-size: .8rem; color: var(--dim); }
.room-code-box b { font-size: 2rem; letter-spacing: 5px; color: #fde68a; }
#btnShare { width: 100%; margin-bottom: 10px; }
.player-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.pl-row { display: flex; align-items: center; gap: 10px; background: var(--bg2); border-radius: 12px; padding: 8px 10px; border: 1px solid transparent; }
.pl-row.me { border-color: #f97316; }
.pl-car { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex: 0 0 auto; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .25); }
.pl-name { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.pl-name small { display: block; font-weight: 400; color: var(--dim); font-size: .78rem; }
.pl-on { font-size: .75rem; color: #f87171; }
.pl-on.on { color: #4ade80; }
.pl-empty { text-align: center; color: var(--dim); font-size: .85rem; padding: 6px; border: 1px dashed var(--line); border-radius: 12px; }
.host-box { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.host-box label { font-size: .9rem; color: var(--dim); }
.host-box select { width: auto; flex: 1; min-width: 120px; }
#btnStart { width: 100%; font-size: 1.1rem; padding: 14px; }
#btnQuit { width: 100%; margin-top: 6px; }
.res-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.res-table th { color: var(--dim); font-weight: 600; font-size: .78rem; text-align: left; padding: 6px; border-bottom: 1px solid var(--line); }
.res-table td { padding: 8px 6px; border-bottom: 1px solid rgba(255, 255, 255, .05); }
.res-table tr.me td { background: rgba(249, 115, 22, .15); }
.res-table .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; border: 1px solid #fff; }
.res-table small { color: var(--dim); }
.keys-help { font-size: .8rem; line-height: 1.7; margin-top: 12px; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .15); border-top-color: #f97316; margin: 6px auto 12px; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#loadOv { background: #0b1020; z-index: 100; }
#msgOv { z-index: 95; }
#carOv .model-grid { margin-bottom: 12px; }

/* small / landscape phones */
@media (max-width: 700px), (max-height: 500px) {
  .hud-pos b { font-size: 1.7rem; }
  .hud-rows { font-size: .72rem; padding: 3px 9px; }
  .minimap { width: 104px; height: 104px; }
  .hud-board { top: calc(100px + env(safe-area-inset-top)); font-size: .72rem; }
  .hud-board li { max-width: 130px; padding: 2px 7px; }
  .race-page .voice-controls { top: calc(54px + env(safe-area-inset-top)); right: 122px; flex-direction: row; }
  .speedo { min-width: 100px; padding: 4px 12px 6px; }
  .speedo b { font-size: 1.5rem; }
  .t-btn { width: 68px; height: 68px; font-size: 26px; }
  .t-gas { width: 80px; height: 80px; }
}
@media (max-height: 500px) {
  .big-msg { top: 22%; }
  .t-mid { flex-direction: row; bottom: calc(96px + env(safe-area-inset-bottom)); }
}
@media (pointer: coarse) {
  .speedo { bottom: calc(10px + env(safe-area-inset-bottom)); }
}
@media (pointer: coarse) and (max-width: 560px) {
  .speedo { bottom: calc(100px + env(safe-area-inset-bottom)); }
}
