:root {
  --rc-accent: #ff5500;
  --rc-cyan: #00e5ff;
  --rc-gold: #ffc400;
  --rc-dark: #0b0f19;
}
* {
  box-sizing: border-box;
  user-select: none;
}
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #070b12;
  color: #f8fafc;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}
.font-racing {
  font-family: 'Orbitron', 'Inter', sans-serif;
  letter-spacing: 0.04em;
}
#viewport-container {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  background: radial-gradient(circle at center, #1a2436 0%, #070b12 100%);
}
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.ui-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.interactive {
  pointer-events: auto;
}
.glass-panel {
  background: rgba(12, 18, 30, 0.84);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
}
.glass-card {
  background: rgba(20, 29, 47, 0.78);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}
.glass-card:hover {
  border-color: rgba(0, 229, 255, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(0, 229, 255, 0.16);
}
.rc-btn {
  position: relative;
  overflow: hidden;
  transition: all 0.16s ease;
  cursor: pointer;
}
.rc-btn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.01);
  filter: brightness(1.1);
}
.rc-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.99);
}
.rc-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.rc-btn-primary {
  background: linear-gradient(135deg, #ff5500 0%, #ff8800 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 8px 24px rgba(255, 85, 0, 0.38);
}
.rc-btn-cyan {
  background: linear-gradient(135deg, #00b4d8 0%, #0077b6 100%);
  color: #ffffff;
  border: 1px solid rgba(0, 229, 255, 0.4);
  box-shadow: 0 8px 24px rgba(0, 180, 216, 0.3);
}
.rc-btn-secondary {
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.28);
}
.rc-btn-secondary:hover:not(:disabled) {
  background: rgba(51, 65, 85, 0.95);
  border-color: rgba(0, 229, 255, 0.55);
  color: #ffffff;
}
.screen-view {
  display: none !important;
}
.screen-view.active {
  display: flex !important;
}
.custom-scroll::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.custom-scroll::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.5);
  border-radius: 9999px;
}
.custom-scroll::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.6);
  border-radius: 9999px;
}
.speed-lines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.15s ease;
  background: radial-gradient(circle at center, transparent 48%, rgba(0, 229, 255, 0.18) 88%, rgba(255, 85, 0, 0.28) 100%);
}
.racer-tag {
  position: absolute;
  transform: translate(-50%, -100%);
  pointer-events: none;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(10, 15, 28, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
#screen-race .glass-panel, #screen-race .glass-card {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* Fit the visual viewport, including browser bars and phone safe areas. */
html, body, .ui-layer, #viewport-container { height: 100dvh; }
.ui-layer { min-height: 0; }
.screen-view { min-height: 0; }
input, textarea { user-select: text; -webkit-user-select: text; }
button, input { touch-action: manipulation; }
button:focus-visible { outline: 2px solid var(--rc-cyan); outline-offset: 3px; }
#top-bar { flex-shrink: 0; padding-top: max(10px, env(safe-area-inset-top)); }
#screen-lobby > div, #screen-map-select > div, #screen-results > div,
#screen-settings > div { max-height: 100%; }
#screen-lobby, #screen-map-select, #screen-results, #screen-settings { overflow: hidden; }
[id^="modal-"] > div { max-height: 100%; overflow-y: auto; }
#toast-container { max-width: calc(100% - 24px); bottom: max(24px, env(safe-area-inset-bottom)); }
#btn-lobby-sim-join { display: none; }
#lobby-network-badge { display: block; }
#mobile-controls, #mobile-controls[hidden] { display: none; }
.touch-btn { touch-action: none; -webkit-touch-callout: none; user-select: none;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  width: 64px; height: 64px; border-radius: 20px; color: white;
  border: 1px solid #ffffff40; background: #0c1629d9; font-weight: 800;
  box-shadow: 0 4px 18px #0005; font-size: 24px; }
.touch-btn small { font-size: 9px; letter-spacing: .04em; }
.touch-btn.pressed { background: #007e98; border-color: #00e5ff; transform: scale(.96); }
.touch-gas { background: #dd4a08dc; }
.touch-nitro { background: #006e92dc; height: 48px; font-size: 16px; }
.touch-utility { width: 48px; height: 48px; font-size: 19px; border-radius: 16px; }
.touch-cluster { display: flex; gap: 10px; align-items: end; }
#mobile-controls { position: absolute; left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom));
  align-items: end; justify-content: space-between; pointer-events: none; }
#mobile-controls button { pointer-events: auto; }
@media (max-width: 767px) {
  #top-bar { padding-left: 12px; padding-right: 12px; gap: 8px; }
  #btn-brand-home { gap: 8px; }
  #btn-brand-home > div:last-child > div { font-size: 11px; letter-spacing: 0; }
  #btn-brand-home > div:last-child p, #btn-brand-home span.bg-cyan-500\/20,
  #btn-top-car-badge { display: none; }
  #top-bar > div:last-child { gap: 6px; }
  #top-bar > div:last-child > div { padding: 6px; }
  #top-bar > div:last-child > div > div:last-child > div:first-child { display: none; }
  #btn-top-lang, #btn-top-mute { padding: 10px 8px; min-height: 42px; }
  #screen-main-menu { padding: 12px; overflow-y: auto; align-items: start; }
  #screen-main-menu > div:first-child { padding: 18px; margin: auto; }
  #screen-lobby, #screen-map-select, #screen-results, #screen-settings { padding: 10px; }
  #screen-lobby > div, #screen-map-select > div, #screen-results > div,
  #screen-settings > div { padding: 16px; gap: 16px; }
  #screen-lobby h2, #screen-map-select h2 { font-size: 20px; }
  #screen-lobby .flex, #screen-map-select .flex, #screen-results .flex,
  #screen-settings .flex { min-width: 0; }
  #screen-lobby .flex:not(.flex-col), #screen-map-select .flex:not(.flex-col),
  #screen-results .flex:not(.flex-col), #screen-settings .flex:not(.flex-col) { flex-wrap: wrap; }
  #screen-lobby > div > *, #screen-map-select > div > *,
  #screen-results > div > *, #screen-settings > div > * { flex-shrink: 0; }
  #lobby-player-slots > div { padding: 10px; }
  #screen-lobby > div > div:last-child > div { width: 100%; gap: 8px; }
  #btn-lobby-start-race { flex: 1; padding: 12px; }
  #screen-garage { padding: 10px; gap: 12px; overflow-y: auto; display: none;
    flex-direction: column; pointer-events: auto; }
  #screen-garage > div { width: 100%; max-width: none; flex-shrink: 0; max-height: none; }
  #screen-garage > div:first-child { gap: 12px; }
  #garage-stat-bars { display: none; }
  #garage-overview-tires { grid-template-columns: 1fr; }
  #screen-results > div > div:first-child { gap: 12px; }
  #results-standings-list > div { padding: 10px; gap: 8px; }
  #screen-settings > div > .flex { gap: 12px; }
  #input-player-name, #input-room-code { font-size: 16px; }
  #input-room-code { font-size: 28px; }
}
@media (pointer: coarse), (max-width: 900px) {
  #screen-race { padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 150px max(10px, env(safe-area-inset-left)); }
  #mobile-controls { display: flex; }
  #race-top { gap: 6px; }
  #race-telemetry { gap: 5px; flex-wrap: wrap; }
  #race-telemetry > div { padding: 8px; min-width: 58px; border-radius: 12px; }
  #race-telemetry .text-3xl { font-size: 22px; }
  #hud-timer { font-size: 16px; }
  #race-map-info { display: none; }
  #race-minimap { width: 80px; padding: 4px; border-radius: 12px; }
  #minimap-canvas { width: 70px; height: 70px; }
  #race-minimap > div { display: none; }
  #race-right { gap: 6px; }
  #btn-hud-pause { padding: 12px; font-size: 0; }
  #btn-hud-pause::after { content: '⏸'; font-size: 18px; }
  #race-bottom { justify-content: center; }
  #race-keyboard-hint, #race-progress { display: none; }
  #race-speed { padding: 7px 12px; border-radius: 14px; gap: 12px; }
  #race-speed > div:first-child { width: 100px; }
  #race-speed > div:last-child { min-width: 64px; padding-left: 10px; }
  #hud-speed { font-size: 22px; }
  #race-speed > div:first-child > div:first-child { font-size: 10px; gap: 6px; }
  #countdown-number { font-size: clamp(48px, 12vw, 80px); }
  #toast-container { bottom: auto; top: max(80px, env(safe-area-inset-top)); }
}
@media (max-width: 767px) {
  #mobile-pilot-label { display: block !important; }
  #menu-keyboard-hint { display: none; }
  #input-mobile-player-name { font-size: 16px; }
}
@media (max-width: 380px) {
  .touch-btn { width: 54px; height: 58px; border-radius: 16px; }
  .touch-utility { width: 40px; height: 44px; }
  .touch-nitro { height: 44px; }
  .touch-cluster { gap: 8px; }
  #btn-brand-home > div:first-child { width: 30px; height: 34px; }
  #btn-brand-home > div:last-child > div { font-size: 9px; }
  #top-bar > div:last-child { gap: 4px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  #top-bar { padding-top: 4px; padding-bottom: 4px; }
  #screen-main-menu > div:first-child { padding: 12px; gap: 6px; }
  #screen-race { padding-bottom: 12px; }
  #race-bottom { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); width: auto; }
  .touch-btn { width: 58px; height: 54px; border-radius: 16px; }
  .touch-nitro { height: 40px; }
  .touch-utility { width: 42px; height: 42px; }
}
