:root {
  --primary: #ff2d55;
  --accent: #00d4ff;
  --bg-dark: #111;
  --text: #fff;
  --hud-bg: rgba(0,0,0,0.6);
  --hud-border: rgba(255,255,255,0.3);
  --touch-btn-bg: rgba(255,255,255,0.15);
  --touch-btn-active: rgba(255,255,255,0.4);
  --touch-size: clamp(56px, 12vw, 80px);
}
* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html, body { width:100%; height:100%; overflow:hidden; background:#000; font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; user-select:none; -webkit-user-select:none; touch-action:none; }
#game { width:100%; height:100%; display:block; }
.hidden { display:none !important; }

#hud {
  position:fixed; top:0; left:0; width:100%; height:100%;
  pointer-events:none; z-index:10;
}
.hud-top { display:flex; justify-content:space-between; align-items:flex-start; padding:10px; gap:8px; flex-wrap:wrap; }
.hud-box {
  background:var(--hud-bg); border:1px solid var(--hud-border); border-radius:8px;
  padding:6px 10px; color:var(--text); font-size:clamp(14px, 3vw, 20px); font-weight:bold;
  min-width:50px; text-align:center;
}
.hud-left, .hud-right, .hud-center { display:flex; gap:6px; align-items:center; }
.hud-bottom { position:fixed; bottom:10px; left:10px; right:10px; display:flex; gap:10px; align-items:flex-end; justify-content:space-between; pointer-events:none; }
#health-bar-container {
  flex:1; max-width:250px; height:26px; position:relative; overflow:hidden;
  background:rgba(0,0,0,0.7); border-radius:13px; border:1px solid var(--hud-border);
}
#health-bar-fill { height:100%; background: linear-gradient(90deg, #ff2d55, #00d4ff); width:100%; transition: width 0.2s; }
#health-text { position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); font-size:12px; color:#fff; }
#boost-meter-container {
  flex:1; max-width:150px; height:20px; position:relative; overflow:hidden;
  background:rgba(0,0,0,0.7); border-radius:10px; border:1px solid var(--hud-border);
}
#boost-meter-fill { height:100%; background: linear-gradient(90deg, #ff9500, #ffcc00); width:100%; transition: width 0.2s; }
#boost-meter-container span { position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); font-size:10px; color:#000; font-weight:bold; }

.hud-btn {
  position:fixed; pointer-events:auto; background:var(--hud-bg); border:1px solid var(--hud-border); border-radius:50%;
  width:44px; height:44px; color:#fff; font-size:20px; display:flex; align-items:center; justify-content:center;
  cursor:pointer; backdrop-filter: blur(4px);
}
#btn-camera { top:10px; right:10px; }
#btn-pause { top:60px; right:10px; }
#btn-reset { top:110px; right:10px; }

#message-popup {
  position:fixed; top:50%; left:50%; transform:translate(-50%, -50%);
  background:rgba(0,0,0,0.85); border:2px solid var(--accent); border-radius:12px; padding:16px 24px;
  color:#fff; font-size:clamp(16px, 4vw, 24px); font-weight:bold; text-align:center;
  pointer-events:none; z-index:20; animation:popIn 0.3s ease-out;
}
@keyframes popIn {
  from { opacity:0; transform:translate(-50%,-50%) scale(0.5); }
  to { opacity:1; transform:translate(-50%,-50%) scale(1); }
}

/* Touch controls */
#touch-controls {
  position:fixed; bottom:20px; left:0; right:0; display:flex; justify-content:space-between; align-items:flex-end;
  padding:0 15px; pointer-events:none; z-index:15;
}
.touch-left, .touch-right { display:flex; gap:10px; pointer-events:auto; }
.touch-btn {
  width:var(--touch-size); height:var(--touch-size); border-radius:50%;
  background:var(--touch-btn-bg); border:2px solid rgba(255,255,255,0.4); color:#fff;
  font-size:clamp(14px, 2.5vw, 18px); font-weight:bold; display:flex; align-items:center; justify-content:center;
  cursor:pointer; touch-action:none; backdrop-filter: blur(4px);
}
.touch-btn:active, .touch-btn.active { background:var(--touch-btn-active); transform:scale(0.95); }
.touch-btn.gas { background:rgba(0,200,0,0.3); border-color:#00c853; }
.touch-btn.brake { background:rgba(255,0,0,0.3); border-color:#ff1744; }
.touch-btn.handbrake { background:rgba(255,150,0,0.3); border-color:#ff9800; }
.touch-btn.boost { background:rgba(255,200,0,0.3); border-color:#ffd600; }

/* Hide touch on desktop */
@media (hover: hover) and (pointer: fine) {
  #touch-controls { display:none !important; }
}

/* Landscape phone */
@media (orientation: landscape) and (max-width: 800px) {
  :root { --touch-size: 52px; }
  .hud-box { font-size: clamp(12px, 2vw, 16px); padding:4px 8px; }
}