* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; overscroll-behavior: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #0c0f14; color: #f2f4f7;
  touch-action: none; user-select: none;
}

#sky {
  position: fixed; inset: 0; z-index: 0;
  background: linear-gradient(180deg, #7fb3e0 0%, #bcdcf2 45%, #dcecf5 62%, #8f9294 62%, #55575a 100%);
}

#scene { position: fixed; inset: 0; z-index: 1; display: block; width: 100%; height: 100%; }

/* ---------- Car cabin frame ---------- */
:root { --dash-h: 40%; --dash-h-min: 150px; }
#cabin { position: fixed; inset: 0; z-index: 2; pointer-events: none; display: none; }
#cabin-art {
  position: absolute; inset: 0;
  background-image: url('assets/cabin.png?v=3');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  transition: transform 0.2s;
}
#cabin-art.mirrored { transform: scaleX(-1); }
#wheel-img {
  position: absolute; width: 21%; left: 19%; bottom: 2%;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.5));
  transform-origin: 50% 42%;
}
.mirror {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 120px; height: 22px; background: #17191d;
  border-radius: 0 0 16px 16px; box-shadow: 0 3px 8px rgba(0,0,0,0.45);
}
.mirror::after {
  content: ''; position: absolute; inset: 6px 10px; border-radius: 0 0 10px 10px;
  background: linear-gradient(180deg, #3a4550, #262c33);
}
#dashboard {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--dash-h); min-height: var(--dash-h-min);
}
.cluster {
  position: absolute; bottom: 10%; left: 50%; transform: translateX(-50%);
  display: flex; gap: 26px;
}
.dash-icon { color: #454951; transition: color 0.25s, filter 0.25s; }
.dash-icon.lit { color: #55e08a; filter: drop-shadow(0 0 5px rgba(85,224,138,0.85)); }
.dash-icon.fault { color: #ff5b5b; filter: drop-shadow(0 0 5px rgba(255,91,91,0.9)); }
.dash-icon.blink { animation: dashblink 0.45s steps(1) infinite; }
@keyframes dashblink { 50% { opacity: 0.2; } }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 3; pointer-events: none; display: none; }
#hud-top {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: 0; right: 0;
  display: flex; justify-content: flex-start; align-items: flex-start;
  padding: 0 17%;
}
#hud-speed {
  background: rgba(10,14,20,0.55); backdrop-filter: blur(6px);
  border-radius: 10px; padding: 8px 14px; display: flex; align-items: baseline; gap: 6px;
}
#speed-value { font-size: 26px; font-weight: 600; }
#hud-speed .unit { font-size: 12px; opacity: 0.7; }

#hud-banner {
  position: absolute; bottom: max(calc(var(--dash-h) + 26px), calc(var(--dash-h-min) + 26px)); left: 0; right: 0;
  display: flex; justify-content: center; pointer-events: none;
}
#hud-banner .msg {
  font-size: 15px; font-weight: 600; padding: 10px 18px; border-radius: 10px;
  background: rgba(226,75,74,0.85); color: #fff; letter-spacing: 0.02em;
  animation: pulse 0.6s ease-in-out infinite alternate;
}
#hud-banner .msg.ok { background: rgba(60,190,140,0.9); animation: none; }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.6; } }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6,8,12,0.72); backdrop-filter: blur(4px);
  padding: 20px;
}
.screen.hidden { display: none; }

.panel {
  width: 100%; max-width: 440px; max-height: 92vh; overflow-y: auto;
  background: #14181f; border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px; padding: 28px 26px;
}

h1 { font-size: 21px; font-weight: 600; margin: 0 0 10px; }
h2 { font-size: 19px; font-weight: 600; margin: 0 0 8px; }
.lede { font-size: 14px; line-height: 1.55; color: #b7bcc6; margin: 0 0 20px; }
.kicker { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: #7fb3e0; }
.hint { font-size: 12px; color: #7d8290; margin: 8px 0 0; }

.field { margin-bottom: 22px; }
.field > label { display: block; font-size: 12px; font-weight: 600; color: #9aa0ac; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.04em; }

.segmented { display: flex; flex-direction: column; gap: 8px; }
.segmented button {
  text-align: left; padding: 11px 14px; border-radius: 10px;
  background: #1c212b; border: 1px solid rgba(255,255,255,0.08); color: #e6e8ec;
  font-size: 14px; font-weight: 500; cursor: pointer;
}
.segmented button span { display: block; font-size: 11px; font-weight: 400; color: #868c98; margin-top: 2px; }
.segmented button.active { border-color: #4a90d9; background: #1d2b3d; }
.segmented button.active span { color: #7fb3e0; }

.primary-btn {
  width: 100%; padding: 14px; border-radius: 10px; border: none;
  background: #3a7bd5; color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
  margin-top: 6px;
}
.primary-btn:active { background: #2f66b3; }
.secondary-btn {
  width: 100%; padding: 11px; border-radius: 10px; margin-top: 10px;
  background: transparent; border: 1px solid rgba(255,255,255,0.18); color: #e6e8ec;
  font-size: 13px; font-weight: 500; cursor: pointer;
}
.hidden { display: none !important; }

.controls-key { display: flex; gap: 14px; margin: 6px 0 22px; }
.key { flex: 1; background: #1c212b; border-radius: 10px; padding: 14px 10px; text-align: center; font-size: 12px; color: #cfd3da; }
.key i { display: block; width: 26px; height: 26px; margin: 0 auto 8px; border-radius: 6px; }
.icon-steer { border: 2px solid #7fb3e0; border-radius: 50%; }
.icon-brake { background: #e24b4a; border-radius: 6px; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.stat-card { background: #1c212b; border-radius: 10px; padding: 12px 14px; }
.stat-card .label { font-size: 11px; color: #868c98; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .value { font-size: 19px; font-weight: 600; margin-top: 3px; }
.stat-card.warn .value { color: #ff8b8b; }
.stat-card.good .value { color: #6fdba6; }

/* ---------- On-screen controls ---------- */
#onscreen-controls { position: fixed; inset: 0; z-index: 4; pointer-events: none; display: none; }
#drag-wheel {
  position: absolute; bottom: max(calc(var(--dash-h) + 10px), calc(var(--dash-h-min) + 10px)); left: 14px;
  width: 96px; height: 96px; border-radius: 50%;
  background: rgba(20,24,31,0.55); border: 2px solid rgba(255,255,255,0.25);
  pointer-events: auto; touch-action: none;
}
#drag-wheel-inner {
  position: absolute; top: 50%; left: 50%; width: 60px; height: 60px; margin: -30px 0 0 -30px;
  border-radius: 50%; border: 4px solid rgba(255,255,255,0.55);
}
#brake-btn {
  position: absolute; bottom: max(calc(var(--dash-h) + 10px), calc(var(--dash-h-min) + 10px)); right: 14px;
  width: 80px; height: 80px; border-radius: 50%;
  background: rgba(226,75,74,0.85); border: 2px solid rgba(255,255,255,0.3); color: #fff;
  font-size: 13px; font-weight: 700; letter-spacing: 0.03em;
  pointer-events: auto; touch-action: none;
}
#brake-btn:active, #brake-btn.pressed { background: #ff3b3a; }

#orientation-notice {
  position: fixed; inset: 0; z-index: 50; background: #0c0f14; color: #fff;
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 30px;
  font-size: 15px;
}

@media (min-width: 720px) {
  #drag-wheel, #brake-btn { transform: scale(0.85); }
}

/* ---------- Compact landscape-phone layout ---------- */
@media (max-height: 460px) {
  .screen { padding: 10px; align-items: stretch; }
  .panel { max-width: none; max-height: none; height: 100%; padding: 14px 20px; display: flex; flex-direction: column; justify-content: center; }
  h1 { font-size: 17px; margin-bottom: 4px; }
  h2 { font-size: 16px; margin-bottom: 4px; }
  .lede { font-size: 12.5px; margin-bottom: 10px; line-height: 1.4; }
  .field { margin-bottom: 10px; }
  .field > label { margin-bottom: 5px; }
  .segmented { flex-direction: row; }
  .segmented button { padding: 8px 10px; font-size: 12.5px; }
  .segmented button span { font-size: 10px; }
  .hint { margin-top: 4px; font-size: 11px; }
  .controls-key { margin: 4px 0 12px; }
  .key { padding: 8px 6px; font-size: 11px; }
  .key i { width: 20px; height: 20px; margin-bottom: 4px; }
  .stats-grid { gap: 6px; margin-bottom: 10px; }
  .stat-card { padding: 8px 10px; }
  .stat-card .value { font-size: 15px; }
  .primary-btn { padding: 10px; font-size: 14px; }
  .secondary-btn { padding: 8px; }
}
