:root {
  color-scheme: dark;
  font-family: "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #8ed5ff; touch-action: none; }
button, a { font: inherit; }
#race-stage { position: fixed; inset: 0; display: block; width: 100%; height: 100%; }

.map-select {
  position: fixed; inset: 0; z-index: 10; display: grid; align-items: center; justify-items: start;
  padding: 24px 24px 24px clamp(24px, 5vw, 96px); background: linear-gradient(90deg, rgba(7,20,15,.78), rgba(7,20,15,.22) 62%, transparent);
}
.map-select.hidden { display: none; }
.map-panel { position: relative; width: min(480px, 100%); padding: 30px; border: 1px solid rgba(226,255,210,.32); border-radius: 26px; color: #fff; background: rgba(13,31,22,.88); box-shadow: 0 24px 90px rgba(0,0,0,.42); backdrop-filter: blur(14px); }
.map-kicker { color: #a8ff70; font-size: 12px; font-weight: 1000; letter-spacing: .24em; }
.map-panel h1 { margin: 6px 0 18px; font-size: clamp(25px, 4vw, 38px); }

/* 주행 화면 표시는 경기장 안에서만 띄운다. 맵을 고르는 동안 속도계와 게이지가
   뒤에 비쳐 보이면 고르는 화면이 지저분해진다. */
body:not(.racing) .race-head,
body:not(.racing) .minimap-panel,
body:not(.racing) #race-hud,
body:not(.racing) .controls-help,
body:not(.racing) #race-touch,
body:not(.racing) #countdown,
body:not(.racing) #race-again { display: none; }
.map-card { width: 100%; display: grid; grid-template-columns: 105px 1fr auto; align-items: center; gap: 15px; padding: 12px; border: 2px solid #9cef67; border-radius: 19px; color: #fff; text-align: left; background: rgba(102,172,69,.18); cursor: pointer; }
.map-thumb { position: relative; display: grid; place-items: center; width: 105px; height: 78px; overflow: hidden; border-radius: 13px; background: linear-gradient(145deg, #68ba47, #34774e); box-shadow: inset 0 0 24px rgba(5,31,16,.45); }
/* 코스가 세로로 길어 그림 칸만 조금 높다. 판 색은 다른 칸과 같다. */
.map-card .map-thumb { width: 105px; height: 112px; }
.map-thumb canvas { width: 100%; height: 100%; filter: drop-shadow(0 2px 3px rgba(0,0,0,.5)); }
.map-copy { display: grid; gap: 6px; }
.map-copy strong { font-size: 18px; }
.map-copy small { color: #d5e5d0; line-height: 1.4; }
.map-check { align-self: start; padding: 5px 8px; border-radius: 9px; color: #17320c; background: #b9f486; font-size: 11px; font-weight: 1000; }
.map-card + .map-card { margin-top: 10px; }
.map-card.hidden { display: none; }
.map-card:not(.selected) { border-color: rgba(226,255,210,.22); background: rgba(255,255,255,.05); }
/* 뱃지를 지우지 않고 숨긴다. display:none 으로 빼면 그 칸이 접혀 카드마다 글자 폭이 달라진다. */
.map-card:not(.selected) .map-check { visibility: hidden; }
#start-race { width: 100%; margin-top: 16px; padding: 14px; border: 0; border-radius: 14px; color: #16320c; background: linear-gradient(135deg, #d3ff92, #79e348); font-weight: 1000; cursor: pointer; box-shadow: 0 7px 24px rgba(119,231,73,.28); }
.settings-btn {
  position: absolute; top: 16px; right: 16px; z-index: 2;
  width: 38px; height: 38px; padding: 0; border: 1px solid rgba(226,255,210,.3); border-radius: 12px;
  color: #dff7cd; font-size: 17px; line-height: 1; background: rgba(255,255,255,.06); cursor: pointer;
}
.settings-btn:hover { background: rgba(255,255,255,.13); }
.settings-btn[aria-expanded="true"] { color: #16320c; background: #b9f486; border-color: #b9f486; }
/* 설정 서랍. 맵 고르는 화면 위쪽에 접혀 있다가 단추를 누르면 펴진다. */
.settings-box {
  display: grid; gap: 10px; margin: 0 0 14px; padding: 13px 14px;
  border: 1px solid rgba(226,255,210,.22); border-radius: 15px; background: rgba(255,255,255,.05);
}
.settings-box.hidden { display: none; }
.set-row { display: grid; grid-template-columns: 74px 1fr 44px; align-items: center; gap: 10px; font-size: 13px; cursor: pointer; }
.set-row b { color: #caff9e; font-variant-numeric: tabular-nums; text-align: right; }
.set-row input[type="range"] { width: 100%; accent-color: #9cef67; }
.set-check { grid-template-columns: 20px 1fr; }
.set-check input { width: 18px; height: 18px; accent-color: #9cef67; }
.set-check small { display: block; color: #a9c4a2; font-size: 11px; line-height: 1.5; }
.map-panel > a { display: block; margin-top: 13px; color: #d9e4d7; text-align: center; text-decoration: none; font-size: 13px; }

.race-head {
  position: fixed; top: max(18px, env(safe-area-inset-top)); left: 22px; z-index: 2;
  display: flex; align-items: center; gap: 14px; color: #fff; text-shadow: 0 2px 5px #000;
}
.race-head a { color: #fff; text-decoration: none; background: rgba(20,28,25,.72); border: 1px solid rgba(255,255,255,.3); border-radius: 13px; padding: 9px 13px; }
.race-head div { display: grid; }
.race-head strong { color: #d7ffad; font-size: 24px; }
.race-head small { opacity: .82; }

#race-hud {
  position: fixed; right: 24px; bottom: 26px; z-index: 2;
  width: min(330px, 38vw); color: #fff; text-shadow: 0 2px 5px #000;
}
.speed {
  --speed-angle: 0deg; position: relative; display: grid; place-content: center; justify-items: center;
  width: 138px; height: 138px; margin-left: auto; border-radius: 50%; overflow: hidden;
  background: conic-gradient(from 225deg, #56e4ff var(--speed-angle), rgba(255,255,255,.16) 0 270deg, transparent 0);
  filter: drop-shadow(0 5px 13px rgba(0,0,0,.35));
}
.speed::before { content: ""; position: absolute; inset: 9px; border-radius: inherit; background: rgba(16,24,29,.84); border: 1px solid rgba(255,255,255,.28); }
.speed b, .speed span { position: relative; }
.speed b { font-size: 54px; line-height: .88; font-variant-numeric: tabular-nums; }
.speed span { margin-top: 7px; font-size: 12px; font-weight: 900; opacity: .9; }
.race-time { display: flex; justify-content: flex-end; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.race-time span { color: #9fe8ff; font-size: 11px; font-weight: 1000; }
.race-time b { font-size: 18px; font-variant-numeric: tabular-nums; }
.lap { display: flex; justify-content: flex-end; align-items: baseline; gap: 6px; margin-bottom: 8px; }
.lap b { font-size: 22px; font-variant-numeric: tabular-nums; }
.lap span { color: #caff9e; font-size: 12px; font-weight: 1000; }
.meter { margin-top: 13px; padding: 13px; border-radius: 16px; background: rgba(17,25,23,.76); border: 1px solid rgba(255,255,255,.18); }
.meter-row { display: flex; justify-content: space-between; font-size: 13px; font-weight: 800; }
.meter-track { height: 13px; margin-top: 7px; overflow: hidden; border-radius: 9px; background: rgba(255,255,255,.12); }
.meter-track i { display: block; width: 0; height: 100%; background: linear-gradient(90deg, #7ce751, #eaff55); box-shadow: 0 0 12px #8cff58; }
.boost-slots { display: flex; justify-content: flex-end; gap: 7px; margin-top: 9px; }
.boost-slots i { display: grid; place-items: center; width: 62px; height: 28px; border: 2px solid rgba(123,224,255,.55); border-radius: 7px; background: rgba(50,106,116,.35); font-style: normal; }
.boost-slots i::after { content: "N₂O"; color: rgba(255,255,255,.45); font-size: 12px; font-weight: 1000; }
.boost-slots i.on { background: linear-gradient(135deg, #148dd3, #67ecff); box-shadow: 0 0 13px #4ce3ff; }
.boost-slots i.on::after { color: #fff; }

.minimap-panel { position: fixed; left: 22px; bottom: 105px; z-index: 2; width: 190px; padding: 9px; border: 1px solid rgba(255,255,255,.24); border-radius: 15px; color: #fff; background: rgba(14,25,30,.72); box-shadow: 0 8px 25px rgba(0,0,0,.28); }
.minimap-panel span { display: block; color: #bdefff; font-size: 10px; font-weight: 1000; letter-spacing: .12em; }
.minimap-panel canvas { display: block; width: 100%; height: 190px; }

#countdown {
  position: fixed; inset: 50% auto auto 50%; z-index: 3; transform: translate(-50%,-50%);
  color: #fff; font-size: clamp(74px, 15vw, 160px); font-weight: 1000; font-style: italic;
  text-shadow: 0 5px 0 #214b36, 0 0 28px #9aff5a; pointer-events: none;
}
/* 숫자 한 글자가 아니라 글이 들어갈 때는 좁은 화면에서 넘치지 않게 줄인다. */
#countdown.wordy { font-size: clamp(30px, 7vw, 74px); white-space: nowrap; }
/* 판이 끝났을 때만 나오는 버튼. 카운트다운 문구 바로 아래에 둔다. */
#race-again {
  position: fixed; left: 50%; top: calc(50% + 78px); z-index: 4; transform: translateX(-50%);
  padding: 13px 26px; border: 0; border-radius: 14px; color: #16320c; font-size: 16px; font-weight: 1000;
  background: linear-gradient(135deg, #d3ff92, #79e348); box-shadow: 0 7px 24px rgba(119,231,73,.32); cursor: pointer;
}
#race-again.hidden { display: none; }
.controls-help { position: fixed; left: 22px; bottom: 24px; z-index: 2; max-width: 550px; padding: 12px 15px; border-radius: 14px; color: #edf8ef; background: rgba(15,24,21,.72); line-height: 1.65; font-size: 13px; }
.controls-help b { color: #d5ff93; }

#race-touch { display: none; }
@media (pointer: coarse) {
  .controls-help { display: none; }
  .minimap-panel { top: 70px; left: 15px; bottom: auto; width: 120px; padding: 6px; }
  .minimap-panel span { display: none; }
  .minimap-panel canvas { height: 135px; }
  #race-hud { top: 15px; right: 15px; bottom: auto; width: 245px; }
  .speed { width: 92px; height: 92px; }
  .speed b { font-size: 35px; }
  .meter { margin-top: 6px; padding: 8px 10px; }
  #race-touch { position: fixed; inset: 0; z-index: 4; display: flex; justify-content: space-between; align-items: flex-end; padding: 0 18px max(18px, env(safe-area-inset-bottom)); pointer-events: none; }
  #race-touch > div { display: flex; gap: 9px; pointer-events: auto; }
  #race-touch button { min-width: 68px; height: 68px; border: 1px solid rgba(255,255,255,.35); border-radius: 50%; color: #fff; background: rgba(22,35,30,.72); font-weight: 900; }
  #race-touch button.on { transform: scale(.92); background: rgba(108,177,72,.88); }
  #race-touch .touch-actions { align-items: flex-end; }
  #race-touch .drift { width: 78px; height: 78px; }
  #race-touch .boost { color: #d9fbff; border-color: #60dcff; }
  #race-touch .gas { width: 88px; height: 88px; background: rgba(71,132,48,.78); }
}
@media (max-width: 760px) {
  .map-select { justify-items: center; padding: 18px; }
  .map-panel { padding: 21px; }
  .map-card { grid-template-columns: 82px 1fr; }
  .map-thumb { width: 82px; height: 68px; }
  .map-card .map-thumb { width: 82px; height: 92px; }
  .map-check { display: none; }
  .race-head div { display: none; }
}
