:root {
  --accent: #00e5ff;
  --accent2: #ff3d7f;
  --bg: #05060f;
  --panel: rgba(10, 14, 30, 0.62);
  --ok: #3dff9e;
  font-family: "Segoe UI", system-ui, -apple-system, "Apple SD Gothic Neo", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 5;
}

.panel {
  position: absolute; top: 18px; left: 18px;
  display: flex; gap: 22px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 12px 20px;
}
.stat { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1; }
.stat .label { font-size: 10px; letter-spacing: 2px; color: var(--accent); opacity: .8; }
.stat .value { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .unit { font-size: 10px; opacity: .5; }

.wheel-wrap {
  position: absolute; bottom: 40px; left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
#wheel {
  width: 150px; height: auto; display: block;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,.5)) drop-shadow(0 0 18px rgba(0,229,255,.25));
  transition: transform .06s linear;
}
.pedal {
  font-size: 12px; font-weight: 800; letter-spacing: 2px;
  padding: 4px 14px; border-radius: 20px;
  background: rgba(255,255,255,.08); color: #fff; opacity: .75;
  transition: all .15s;
}
.pedal.gas  { background: var(--ok); color: #04210f; opacity: 1; box-shadow: 0 0 18px rgba(61,255,158,.6); }
.pedal.brake{ background: var(--accent2); color: #fff; opacity: 1; }

/* ---------- Webcam preview ---------- */
#cam-wrap {
  position: fixed; bottom: 18px; right: 18px;
  width: 260px; height: 195px;
  border-radius: 14px; overflow: hidden;
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  z-index: 6; background: #000;
}
#video, #overlay {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  transform: scaleX(-1); /* 거울 모드 */
  object-fit: cover;
}
#video { opacity: .9; }
#cam-status {
  position: absolute; bottom: 0; left: 0; right: 0;
  font-size: 11px; text-align: center; padding: 4px;
  background: rgba(0,0,0,.55); color: var(--accent);
}

/* ---------- Overlays ---------- */
#start-screen, #gameover {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, rgba(0,40,80,.55), rgba(5,6,15,.92));
  backdrop-filter: blur(6px);
}
.hidden { display: none !important; }

.start-card {
  text-align: center; max-width: 460px; padding: 36px 40px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.start-card h1 {
  font-size: 56px; font-weight: 900; letter-spacing: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.start-card h1 span { -webkit-text-fill-color: #fff; color:#fff; }
.tag { opacity: .8; margin: 6px 0 22px; font-size: 15px; }
.how { text-align: left; margin: 0 auto 26px; max-width: 360px; line-height: 1.9; font-size: 14px; opacity: .92; }
.how li { list-style: none; }
button {
  pointer-events: auto; cursor: pointer;
  font-size: 17px; font-weight: 800; letter-spacing: 1px;
  padding: 14px 34px; border: none; border-radius: 40px;
  color: #04121f;
  background: linear-gradient(90deg, var(--accent), #6cf);
  box-shadow: 0 6px 24px rgba(0,229,255,.4);
  transition: transform .12s;
}
button:hover { transform: translateY(-2px) scale(1.03); }
.btn-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(0,229,255,.5);
  box-shadow: none;
}
button.ghost:hover { background: rgba(0,229,255,.12); }
button.ghost.small { font-size: 13px; padding: 9px 18px; }
.note { font-size: 11px; opacity: .5; margin-top: 16px; line-height: 1.6; }

/* ===== 두 창 모드 ===== */
#dash { display: none; }
#remote-cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }

/* 계기판 */
#gauge { filter: drop-shadow(0 0 16px rgba(0,229,255,.3)); width: min(86vw, 360px); height: auto; }
#gauge-needle { transition: transform .09s linear; transform-origin: 100px 108px; filter: drop-shadow(0 0 4px #ff3d7f); }
#gauge-fill { transition: stroke-dashoffset .12s linear; filter: drop-shadow(0 0 5px rgba(0,229,255,.5)); }
.g-spd { fill: #fff; font: 900 42px "Segoe UI", system-ui, sans-serif; }
.g-unit { fill: #7fd7e6; font-size: 11px; letter-spacing: 3px; }
.dash-row { display: flex; gap: 22px; }
.dash-cell {
  display: flex; flex-direction: column; align-items: center; line-height: 1.15;
  background: var(--panel); border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px; padding: 8px 22px; min-width: 92px;
}
.dl { font-size: 10px; letter-spacing: 2px; color: var(--accent); opacity: .8; }
.dv { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.du { font-size: 9px; opacity: .5; }
.gas-wrap { display: flex; align-items: center; gap: 12px; width: min(80vw, 340px); }
.gas-track { flex: 1; height: 14px; border-radius: 8px; overflow: hidden;
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12); }
#gas-fill { height: 100%; width: 0%; border-radius: 8px;
  background: linear-gradient(90deg, var(--ok), var(--accent)); transition: width .08s; box-shadow: 0 0 12px rgba(61,255,158,.5); }
#dash-pedal-label.brake { color: var(--accent2); }

/* --- 컨트롤러(콕핏) 뷰: 게임/스탯/캠 숨기고 계기판+핸들 크게 --- */
body.view-control #game,
body.view-control #stats { display: none; }
/* 캠 미리보기는 화면 밖으로(스트리밍용 비디오는 계속 디코딩되어야 함) */
body.view-control #cam-wrap { left: -9999px; top: 0; bottom: auto; opacity: 0; pointer-events: none; }
body.view-control { background: radial-gradient(circle at 50% 8%, #0a1428, #02030a 70%); }

/* 계기판 클러스터 */
#cluster { width: min(94vw, 920px); height: auto; filter: drop-shadow(0 10px 40px rgba(0,40,90,.5)); }
.tick-num { fill: #cfe0ff; font: 700 21px "Segoe UI", system-ui, sans-serif; }
.ndl { filter: drop-shadow(0 0 5px #4aa0ff) drop-shadow(0 0 2px #bfe0ff); transition: transform .1s linear; }
.odo-num { fill: #7fb4ff; font: 800 30px "Consolas", "Menlo", monospace; letter-spacing: 4px; }
.odo-cap { fill: #4a6da0; font: 700 12px "Segoe UI", sans-serif; letter-spacing: 3px; }
.gauge-cap { fill: #6f9ad8; font: 700 13px "Segoe UI", sans-serif; letter-spacing: 3px; }

body.view-control #dash {
  display: flex; justify-content: center;
  position: fixed; left: 0; right: 0; top: 4vh; z-index: 6;
}
/* 핸들 2배 크기, 클러스터 아래 중앙 */
/* 겹칠 경우 핸들이 계기판(#dash, z6)보다 위 레이어 */
body.view-control #hud { z-index: 12; }
body.view-control .wheel-wrap { bottom: 2vh; }
body.view-control #wheel { width: min(150vw, 1440px); height: auto; }
body.view-control .pedal { display: none; }
body.view-control #keyboard-btn,
body.view-control #twowin-btn { display: none; }

/* --- 게임 뷰 --- */
/* 컨트롤러 모드 게임 창엔 핸들 HUD 숨김 */
body.view-game .wheel-wrap { display: none; }
/* 로컬 캠 숨기고, 스트리밍 캠을 원형 마스킹으로 우측하단 */
body.view-game #video,
body.view-game #overlay,
body.view-game #cam-status { display: none; }
body.view-game #cam-wrap {
  width: 380px; height: 380px; border-radius: 50%;
  border: 3px solid rgba(0,229,255,.55);
  box-shadow: 0 0 22px rgba(0,229,255,.35), inset 0 0 18px rgba(0,0,0,.4);
}
body.view-game #remote-cam { display: block; border-radius: 50%; }

/* 두 창 모드 배지 */
.mode-badge {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 8; pointer-events: none;
  font-size: 12px; letter-spacing: 1px; font-weight: 700;
  padding: 7px 16px; border-radius: 20px;
  background: var(--panel); border: 1px solid rgba(0,229,255,.3); color: var(--accent);
  backdrop-filter: blur(6px);
}
.mode-badge.warn { color: var(--accent2); border-color: rgba(255,61,127,.4); }

#loading {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column; gap: 16px;
  align-items: center; justify-content: center;
  background: rgba(5,6,15,.85); color: var(--accent); font-size: 14px;
}
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 4px solid rgba(0,229,255,.2); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
