:root {
  --red: #e8352e;
  --yellow: #ffc400;
  --blue: #1f6fe0;
  --ink: #1d2340;
  --panel: rgba(255, 255, 255, 0.94);
  --font-num: 'Russo One', 'Segoe UI', Arial, sans-serif;
  --font-kr: 'Black Han Sans', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  --font-ui: 'Segoe UI', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  /* 노치·홈 표시줄 안전 영역 (viewport-fit=cover) + 화면 가장자리 여백 */
  --sa-t: env(safe-area-inset-top, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
  --gap: 16px;
}
/* 휴대폰 (세로 좁은 화면 · 가로로 눕힌 낮은 화면): 가장자리 여백을 조금 줄임 */
@media (max-width: 480px), (max-height: 500px) {
  :root { --gap: 12px; }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #8fd0ff;
  font-family: var(--font-ui);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- 공통 패널 */
/* 화면 = 보이는 영역(주소창 제외) 전체. 안쪽 여백 = 가장자리 여백 + 안전 영역, 패널은 그 안에 딱 맞게 (넘치면 패널 안에서 스크롤) */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  padding: calc(var(--gap) + var(--sa-t)) calc(var(--gap) + var(--sa-r)) calc(var(--gap) + var(--sa-b)) calc(var(--gap) + var(--sa-l));
  z-index: 10;
  /* 한글은 낱말 중간에서 줄바꿈하지 않음 (너무 긴 낱말만 쪼갬) */
  word-break: keep-all;
  overflow-wrap: break-word;
}
#menu, #lobby { justify-content: flex-start; padding-left: calc(max(var(--gap), 4vw) + var(--sa-l)); }
#results, #pause { justify-content: center; background: rgba(10, 20, 50, 0.35); }
/* 100vh 는 휴대폰 주소창이 숨었을 때 높이라 화면보다 커질 수 있음 → 화면(.screen) 안쪽 높이에 맞춤 */
.screen > .panel { max-height: 100%; overscroll-behavior: contain; }

.panel {
  background: var(--panel);
  border-radius: 22px;
  padding: 22px 24px;
  box-shadow: 0 18px 50px rgba(0, 30, 80, 0.35), inset 0 -5px 0 rgba(0, 0, 0, 0.06);
  width: min(440px, 100%);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  border: 4px solid #fff;
}

.logo {
  margin: 0;
  font-family: var(--font-num);
  font-style: italic;
  font-size: 46px;
  line-height: 1;
  letter-spacing: 1px;
  display: flex;
  gap: 10px;
  align-items: baseline;
  transform: skewX(-6deg);
}
.logo span { text-shadow: 0 3px 0 rgba(0, 0, 0, 0.18); }
.logo .l1 { color: var(--red); }
.logo .l2 { color: var(--blue); }
.logo .l3 {
  color: #fff;
  background: var(--yellow);
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 30px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}
.sub { margin: 6px 0 14px; color: #5a6385; font-size: 14px; }

.label { font-weight: 800; font-size: 13px; color: #5a6385; margin: 10px 0 6px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 800; font-size: 13px; color: #5a6385; }
input, select {
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 2px solid #d5dbef;
  background: #fff;
  color: var(--ink);
  outline: none;
}
input:focus, select:focus { border-color: var(--blue); }

.btn {
  font: inherit;
  font-weight: 800;
  font-size: 16px;
  padding: 12px 16px;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  background: #eef1fb;
  color: var(--ink);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.12);
  transition: transform 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn.primary { background: linear-gradient(180deg, #ff5148, var(--red)); color: #fff; }
.btn.small { padding: 7px 12px; font-size: 13px; }

.menu-buttons, .lobby-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
/* 로비·결과의 시작/나가기 버튼: 내용이 길어 패널이 스크롤돼도 아래에 붙어 늘 보임 */
.lobby-panel .lobby-buttons, .results-panel .lobby-buttons {
  position: sticky;
  bottom: -22px;
  z-index: 2;
  margin: 14px -24px -22px;
  padding: 10px 24px 18px;
  background: inherit;
  border-radius: 0 0 18px 18px;
}
.menu-row { display: flex; gap: 8px; }
.menu-row .btn { flex: 1; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: 4px; font-family: var(--font-num); min-width: 0; }

/* 캐릭터 선택: 20명 (기본 8 + 십이지 묶음 표지 + 십이지 12) = 6열 × 4줄 딱 맞게 */
.char-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.char-card {
  position: relative;
  min-width: 0;
  font: inherit;
  border: 3px solid transparent;
  background: #f1f4fc;
  border-radius: 12px;
  padding: 6px 1px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform 0.1s;
}
.char-card:hover { transform: translateY(-2px); }
.char-card.selected { border-color: var(--kc); background: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15); }
.char-face {
  font-size: 25px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--kc);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.15);
}
.char-name { font-size: 11.5px; font-weight: 800; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.char-zodiac {
  position: absolute; top: 2px; right: 2px; width: 15px; height: 15px; border-radius: 50%;
  display: grid; place-items: center; font: normal 900 10px/1 "Batang", "Noto Serif KR", "Noto Serif CJK KR", serif;
  color: #9a1622; background: #f6d96a; box-shadow: 0 0 0 1.5px #d9a520; pointer-events: none;
}
.char-group {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0;
  border-radius: 12px; border: 2px dashed #e0b040; background: linear-gradient(135deg, #fff8e0, #ffe8ad);
  color: #9a1622; font-weight: 900; font-size: 11px; line-height: 1.25; text-align: left; padding: 4px;
}
.char-group b { font: 900 17px/1 "Batang", "Noto Serif KR", "Noto Serif CJK KR", serif; letter-spacing: 2px; }
.stats-title .zd { font-size: 11px; color: #b8202e; font-weight: 800; }
.char-grid.small { gap: 5px; }
.char-grid.small .char-card { padding: 4px 1px 3px; }
.char-grid.small .char-face { width: 32px; height: 32px; font-size: 20px; }
.char-grid.small .char-name { font-size: 10.5px; }
.char-grid.small .char-group b { font-size: 14px; }
@media (max-width: 420px) {
  .char-grid { gap: 4px; }
  .char-card { border-width: 2px; padding: 4px 0 3px; border-radius: 10px; }
  .char-face, .char-grid.small .char-face { width: 32px; height: 32px; font-size: 20px; }
  .char-name, .char-grid.small .char-name { font-size: 12px; letter-spacing: -0.03em; }
  .char-zodiac { width: 14px; height: 14px; font-size: 9.5px; top: 1px; right: 1px; }
  .char-group { gap: 5px; font-size: 12px; }
  .char-group b, .char-grid.small .char-group b { font-size: 13px; letter-spacing: 1px; }
}
.char-stats { margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; }
.stats-title { grid-column: 1 / -1; font-weight: 900; }
/* 메뉴·로비 이름표 아래 한 줄: 캐릭터에는 능력치가 없고 차량이 정함 */
.stats-note { grid-column: 1 / -1; font-size: 11px; font-weight: 700; color: #6a7396; }
.stat { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; color: #5a6385; }
.stat span { width: 42px; }
.stat .bar { flex: 1; height: 8px; border-radius: 4px; background: #e2e7f5; overflow: hidden; }
.stat .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--yellow), #ff8a00); border-radius: 4px; }

.help { margin-top: 14px; font-size: 13px; color: #4a5275; }
.help summary { cursor: pointer; font-weight: 800; }
.help table { border-collapse: collapse; margin: 8px 0; }
.help td { padding: 3px 8px 3px 0; vertical-align: top; }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid #c9d0e6;
  box-shadow: 0 2px 0 #c9d0e6;
  font-family: var(--font-ui);
  font-size: 12px;
  text-align: center;
  margin-right: 2px;
}

/* 로비 */
.room-head { display: flex; justify-content: space-between; align-items: center; font-weight: 800; color: #5a6385; }
.room-head b { font-family: var(--font-num); font-size: 30px; letter-spacing: 4px; color: var(--blue); margin-left: 6px; }
#player-list { margin: 12px 0; display: flex; flex-direction: column; gap: 6px; }
.player-row { display: flex; align-items: center; gap: 10px; background: #f1f4fc; border-radius: 12px; padding: 6px 10px; }
.player-row.me { background: #fff6d6; }
.pface { width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 20px; flex: none; }
.pname { font-weight: 800; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pchar { font-size: 12px; color: #6a7396; }
.crown { font-size: 12px; font-weight: 800; color: #b07a00; }
.lobby-settings { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.lobby-settings label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 800; color: #5a6385; }
.lobby-settings label.check { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; padding-bottom: 10px; }
.lobby-settings select { padding: 7px 10px; }
.lobby-settings label.wide { flex: 1 1 180px; }
.lobby-settings label.wide select { width: 100%; }
.lobby-settings.ta .race-only, .lobby-settings:not(.ta) .ta-only { display: none; }
#lobby-status { margin-top: 12px; font-size: 13px; color: #5a6385; font-weight: 700; }

/* 결과 */
.results-panel h2, .pause-panel h2 { margin: 0 0 12px; font-family: var(--font-kr); font-weight: 400; font-size: 30px; }
#results-table { width: 100%; border-collapse: separate; border-spacing: 0 5px; }
#results-table td { padding: 6px 8px; background: #f1f4fc; }
#results-table td:first-child { border-radius: 12px 0 0 12px; }
#results-table td:last-child { border-radius: 0 12px 12px 0; }
#results-table tr.me td { background: #fff1b8; }
#results-table .place { font-family: var(--font-num); font-size: 22px; width: 56px; }
#results-table .place small { font-size: 12px; }
#results-table .r1 .place { color: #e0a800; }
#results-table .r2 .place { color: #8a94a8; }
#results-table .r3 .place { color: #c0703a; }
#results-table .rname { font-weight: 800; }
#results-table .rtime { font-family: var(--font-num); text-align: right; }
.pause-panel { display: flex; flex-direction: column; gap: 10px; width: min(340px, 100%); }

/* 그래픽 설정 */
.gfx-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.gfx-head h2 { margin: 0; font-family: var(--font-kr); font-weight: 400; font-size: 30px; }
.gfx-presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.gfx-custom { font-size: 12px; font-weight: 800; color: #9aa3c0; padding: 5px 9px; border-radius: 9px; border: 2px dashed #d5dbef; }
.gfx-custom.on { color: var(--blue); border-color: var(--blue); }
.gfx-chips { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.gfx-chip { font: inherit; font-size: 12px; font-weight: 800; padding: 6px 9px; border-radius: 9px; border: 2px solid #d5dbef; background: #fff; color: var(--ink); cursor: pointer; }
.gfx-chip:hover { border-color: #9fb3e6; }
.gfx-chip.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.gfx-chip.preset { font-size: 14px; padding: 8px 16px; }
.gfx-chip.preset.on { background: linear-gradient(180deg, #ff5148, var(--red)); border-color: var(--red); }
#fps { position: fixed; left: calc(10px + var(--sa-l)); bottom: calc(8px + var(--sa-b)); z-index: 30; font: 12px var(--font-num); color: #fff; background: rgba(0, 0, 0, 0.45); padding: 3px 8px; border-radius: 8px; pointer-events: none; }
@media (max-width: 560px) {
  .gfx-chips { justify-content: flex-start; }
  .gfx-head h2 { font-size: 24px; }
}

/* ---------------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; font-family: var(--font-num); }
.outline {
  color: #fff;
}
#hud-item { position: absolute; top: calc(16px + var(--sa-t)); left: calc(16px + var(--sa-l)); display: flex; flex-direction: column; align-items: center; gap: 4px; }
#item-frame {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.2));
  border: 6px solid #fff;
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.35), inset 0 0 18px rgba(0, 0, 0, 0.25);
  display: grid;
  place-items: center;
  position: relative;
}
#item-icon { width: 72px; height: 72px; display: grid; place-items: center; }
#item-icon svg { width: 72px; height: 72px; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.35)); }
#item-icon .triple { display: flex; width: 80px; flex-wrap: wrap; justify-content: center; }
#item-icon .triple svg { width: 36px; height: 36px; }
#item-icon.got { animation: pop 0.3s ease-out; }
#item-icon.rolling svg { filter: blur(0.6px); }
#item-count { position: absolute; right: -6px; bottom: -4px; font-size: 22px; color: #fff; -webkit-text-stroke: 1.5px #000; }
#item-name { font-family: var(--font-ui); font-weight: 800; font-size: 13px; color: #fff; text-shadow: 0 1px 3px #000; min-height: 18px; }
/* 앞 칸을 쓰고 뒤 칸 아이템이 앞으로 옴: 오른쪽 작은 칸에서 미끄러져 들어옴 */
#item-icon.got.advance { animation: slot-advance 0.32s cubic-bezier(0.3, 1.4, 0.5, 1); }
@keyframes slot-advance {
  0% { transform: translate(52px, -12px) scale(0.5); opacity: 0.4; }
  100% { transform: none; opacity: 1; }
}
/* 뒤 칸 (다음 아이템): 큰 칸 오른쪽 위에 살짝 겹쳐, 큰 칸 뒤에 놓임. 차량(2칸)일 때만 보임 */
#item-slots { position: relative; }
#item-frame2 {
  position: absolute;
  left: calc(100% - 16px);
  top: -4px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.12));
  border: 4px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.3), inset 0 0 10px rgba(0, 0, 0, 0.22);
  display: none;
  place-items: center;
}
#hud-item.two #item-frame2 { display: grid; }
#item-icon2 { width: 38px; height: 38px; display: grid; place-items: center; }
#item-icon2 svg { width: 38px; height: 38px; filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.35)); }
#item-icon2 .triple { display: flex; width: 42px; flex-wrap: wrap; justify-content: center; }
#item-icon2 .triple svg { width: 20px; height: 20px; }
#item-icon2.got { animation: pop 0.3s ease-out; }
#item-icon2.rolling svg { filter: blur(0.5px); }
#item-count2 { position: absolute; right: -8px; bottom: -7px; font-size: 17px; color: #fff; -webkit-text-stroke: 1.3px #000; }

#hud-coins {
  position: absolute;
  top: calc(158px + var(--sa-t));
  left: calc(30px + var(--sa-l));
  font-size: 26px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  -webkit-text-stroke: 1.5px #000;
}
.coin-ico {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff2a8, #ffc81e 55%, #c98c00);
  border: 2px solid #8a5a00;
}

#hud-top-right { position: absolute; top: calc(14px + var(--sa-t)); right: calc(18px + var(--sa-r)); text-align: right; color: #fff; }
#hud-lap { font-size: 40px; font-style: italic; -webkit-text-stroke: 2px #1d2340; text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25); }
#hud-lap small { font-size: 26px; }
#hud-time { font-size: 24px; -webkit-text-stroke: 1.2px #1d2340; }

#hud-ranks { position: absolute; top: calc(120px + var(--sa-t)); right: calc(16px + var(--sa-r)); display: flex; flex-direction: column; gap: 3px; width: 168px; }
.rank {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(20, 30, 60, 0.55);
  color: #fff;
  border-radius: 10px;
  padding: 3px 8px;
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 13px;
}
.rank.me { background: rgba(255, 196, 0, 0.9); color: #1d2340; }
.rank .rp { font-family: var(--font-num); width: 16px; }
.rank .dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; flex: none; }
.rank .rn { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

#minimap { position: absolute; left: calc(14px + var(--sa-l)); bottom: calc(14px + var(--sa-b)); width: 210px; height: 210px; opacity: 0.95; }

#hud-pos {
  position: absolute;
  right: calc(26px + var(--sa-r));
  bottom: calc(18px + var(--sa-b));
  font-style: italic;
  line-height: 1;
  transform: skewX(-6deg);
}
#pos-num { font-size: 120px; }
#pos-suffix { font-size: 48px; }
#hud-pos span {
  background: linear-gradient(180deg, #ffffff, #b9c6ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 3px #1d2340;
  filter: drop-shadow(0 5px 0 rgba(0, 0, 0, 0.25));
}
#hud-pos.p1 span { background-image: linear-gradient(180deg, #fff7a1, #ffc400 55%, #ff8a00); }
#hud-pos.p2 span { background-image: linear-gradient(180deg, #ffffff, #c2cbe0 55%, #8a94a8); }
#hud-pos.p3 span { background-image: linear-gradient(180deg, #ffd9b0, #e08a4a 55%, #a85a20); }
#hud-pos.bump { animation: pop 0.35s ease-out; }

#hud-speed {
  position: absolute;
  bottom: calc(22px + var(--sa-b));
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 30px;
  -webkit-text-stroke: 1.2px #1d2340;
  display: flex;
  align-items: baseline;
  gap: 4px;
  flex-direction: column;
  align-items: center;
}
#hud-speed small { font-size: 13px; -webkit-text-stroke: 0; text-shadow: 0 1px 2px #000; }
#drift-meter { width: 120px; height: 8px; border-radius: 4px; margin-top: 4px; background: rgba(0, 0, 0, 0.25); opacity: 0; transition: opacity 0.2s; }
#drift-meter.lv0, #drift-meter.lv1, #drift-meter.lv2, #drift-meter.lv3 { opacity: 1; }
#drift-meter.lv0 { background: #e9e9e9; }
#drift-meter.lv1 { background: #3a9bff; box-shadow: 0 0 12px #3a9bff; }
#drift-meter.lv2 { background: #ff8a1a; box-shadow: 0 0 12px #ff8a1a; }
#drift-meter.lv3 { background: #c34dff; box-shadow: 0 0 14px #c34dff; }
#drift-meter.ready { opacity: 1; background: #fff; box-shadow: 0 0 16px #7ff3ff; animation: quick-ready 0.16s steps(2) infinite; }
@keyframes quick-ready { 50% { background: #7ff3ff; } }

#quick-pop {
  position: absolute;
  left: 50%;
  bottom: 118px;
  transform: translateX(-50%) scale(0.6);
  font-size: 34px;
  font-style: italic;
  color: #7ff3ff;
  -webkit-text-stroke: 2px #1d2340;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  font-family: var(--font-num), var(--font-kr);
}
#cam-pop {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(16, 20, 40, 0.62);
  color: #fff;
  font: 800 20px var(--font-ui);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}
#cam-pop small { margin-left: 8px; font-size: 13px; opacity: 0.7; }
#cam-pop.show { animation: cam-pop 1.6s ease-out; }
@keyframes cam-pop {
  0% { opacity: 0; transform: translate(-50%, 8px); }
  12%, 70% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 0); }
}
#drift-meter.ready { transform-origin: left center; }
#quick-pop.pop { animation: quick-pop 0.8s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes quick-pop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.5); }
  18% { opacity: 1; transform: translateX(-50%) scale(1.1); }
  70% { opacity: 1; transform: translate(-50%, -10px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -26px) scale(0.95); }
}

#banner {
  position: absolute;
  top: 24%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  font-size: min(64px, 11vw, 15vh);
  font-style: italic;
  color: #fff;
  -webkit-text-stroke: 3px #1d2340;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
  opacity: 0;
  /* 좁은 화면에서는 긴 한글 문구가 두 줄로 (화면 밖으로 넘치지 않게) */
  width: max-content;
  max-width: calc(100% - 24px);
  text-align: center;
  line-height: 1.1;
  word-break: keep-all;
  transition: opacity 0.2s, transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
  font-family: var(--font-num), var(--font-kr);
}
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#banner.final { color: #ff4a3d; }
#banner.finish { color: #ffc400; font-size: min(96px, 15vw, 20vh); }
#banner.good { color: #5cf08a; }
#banner.bad { color: #ff7a6a; }

#countdown {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: min(170px, 38vw, 40vh);
  font-style: italic;
  color: #fff;
  -webkit-text-stroke: 5px #1d2340;
  text-shadow: 0 10px 0 rgba(0, 0, 0, 0.25);
  opacity: 0;
}
#countdown.show { opacity: 1; }
#countdown.pop { animation: count 0.9s ease-out forwards; }
#countdown.go { color: #ffc400; }

#wrongway {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #e8352e;
  color: #fff;
  font-family: var(--font-kr);
  font-size: min(42px, 9vw);
  white-space: nowrap;
  padding: 8px 28px;
  border-radius: 16px;
  border: 4px solid #fff;
  opacity: 0;
  transition: opacity 0.2s;
}
#wrongway.show { opacity: 1; animation: blink 0.6s infinite; }

#flash { position: absolute; inset: 0; background: #fff; opacity: 0; }
#flash.on { animation: flash 0.6s ease-out; }
#flash.wreck { background: radial-gradient(circle, #fff3c4 0%, #ffa040 45%, #c8360f 100%); }

/* 테이크다운 */
#banner.takedown { color: #ffb22e; font-size: min(84px, 13vw, 18vh); -webkit-text-stroke: 3px #3a0d02; }
#wreck-hud {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 16vh;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 40%, rgba(60, 8, 0, 0.6) 100%);
}
#wreck-hud.show { opacity: 1; }
#wreck-hud b {
  font: italic 900 86px var(--font-num), var(--font-kr);
  color: #ff5a1f;
  letter-spacing: 3px;
  -webkit-text-stroke: 3px #240800;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), 0 0 34px rgba(255, 110, 30, 0.7);
}
#wreck-hud.show b { animation: wreck-in 0.55s cubic-bezier(0.3, 1.6, 0.5, 1); }
#wreck-by { margin-top: 2px; color: #fff; font: 800 20px var(--font-ui); text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6); }
#wreck-count {
  margin-top: 10px;
  font: italic 72px var(--font-num), var(--font-kr);
  color: #fff;
  -webkit-text-stroke: 2px #1d2340;
  text-shadow: 0 5px 0 rgba(0, 0, 0, 0.3);
}
#wreck-count.tick { animation: wreck-tick 0.9s ease-out; }
#wreck-hud small { color: rgba(255, 255, 255, 0.85); font: 700 15px var(--font-ui); text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6); }
@keyframes wreck-in {
  0% { transform: scale(2.2) rotate(-6deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes wreck-tick {
  0% { transform: scale(1.5); opacity: 0.3; }
  25% { transform: scale(1); opacity: 1; }
}
@media (max-width: 700px) {
  #wreck-hud b { font-size: 54px; }
  #wreck-count { font-size: 52px; }
}

#touch-controls { display: none; }
@media (pointer: coarse) {
  #touch-controls {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    position: absolute;
    inset: auto 0 0 0;
    padding: 12px calc(12px + var(--sa-r)) calc(12px + var(--sa-b)) calc(12px + var(--sa-l));
    pointer-events: none;
  }
  #touch-controls button {
    pointer-events: auto;
    font: 800 14px var(--font-ui);
    color: #fff;
    background: rgba(20, 30, 60, 0.45);
    border: 3px solid rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    width: 74px;
    height: 74px;
    padding: 0;
    white-space: nowrap;
    letter-spacing: -0.04em;
  }
  #touch-controls button.active { background: rgba(255, 196, 0, 0.75); }
  #cam-pop .key { display: none; }
  #touch-controls #t-cam { position: fixed; top: calc(112px + var(--sa-t)); right: calc(16px + var(--sa-r)); width: 48px; height: 48px; font-size: 22px; border-radius: 50%; }
  #touch-controls #t-respawn { position: fixed; top: calc(112px + var(--sa-t)); right: calc(72px + var(--sa-r)); width: 48px; height: 48px; font-size: 24px; border-radius: 50%; }
  #hud-ranks { top: calc(170px + var(--sa-t)); }
  .tc-right { display: flex; gap: 10px; }
  .tc-right { flex-wrap: wrap; width: 242px; justify-content: flex-end; }
  /* 오른쪽 버튼은 조이스틱 영역보다 위 (겹쳐도 버튼이 먼저) */
  #touch-controls .tc-right { position: relative; z-index: 2; margin-left: auto; }
  /* 가상 조이스틱: 왼쪽 아래 영역에 엄지를 대면 받침이 생기고 손잡이가 따라감 (stick-fixed 면 제자리) */
  #t-stick-zone { position: fixed; left: 0; bottom: 0; width: 50vw; height: 60vh; pointer-events: auto; touch-action: none; z-index: 1; }
  #t-stick {
    --sd: calc(128px * var(--tc-scale, 1));
    position: absolute;
    left: calc(var(--sd) / 2 + 18px + var(--sa-l));
    top: calc(100% - var(--sd) / 2 - 18px - var(--sa-b));
    width: var(--sd);
    height: var(--sd);
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(20, 30, 60, 0.18) 0%, rgba(20, 30, 60, 0.42) 70%);
    border: 3px solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.18), inset 0 0 14px rgba(0, 0, 0, 0.25);
    opacity: calc(var(--tc-opacity, 1) * 0.55);
    transition: opacity 0.15s;
    pointer-events: none;
  }
  #t-stick::before, #t-stick::after {
    content: '◀';
    position: absolute;
    top: 50%;
    left: 9%;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.55);
    font-size: calc(14px * var(--tc-scale, 1));
  }
  #t-stick::after { content: '▶'; left: auto; right: 9%; }
  #t-stick.active, #touch-controls.stick-fixed #t-stick { opacity: var(--tc-opacity, 1); }
  #t-stick .ts-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 46%;
    height: 46%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(circle at 38% 32%, #fff 0%, #e8ecf6 45%, #aab4cc 100%);
    border: 3px solid rgba(29, 35, 64, 0.55);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
    transition: transform 0.12s cubic-bezier(0.3, 1.6, 0.5, 1);
  }
  #t-stick.active .ts-knob { transition: none; background: radial-gradient(circle at 38% 32%, #fff6c8 0%, #ffd23a 50%, #e09a00 100%); }
  #minimap { bottom: auto; top: calc(200px + var(--sa-t)); width: 140px; height: 140px; }
  #hud-pos { bottom: calc(190px + var(--sa-b)); }
  #hud-speed { display: none; }
}
@media (pointer: coarse) and (max-width: 480px) {
  #touch-controls button { width: 62px; height: 62px; font-size: 12px; }
  .tc-right { width: 206px; }
  #t-stick { --sd: calc(116px * var(--tc-scale, 1)); }
}
/* 가로로 눕힌 휴대폰: 미니맵을 아이템 칸 옆 위쪽으로 (왼쪽 아래는 조이스틱 자리),
   📷·↺ 는 위쪽 랩 표시 왼편으로 (순위 숫자와 겹치지 않게), 순위 목록은 오른쪽 버튼과 겹치므로 숨김 */
@media (pointer: coarse) and (max-height: 500px) {
  #minimap { top: calc(10px + var(--sa-t)); left: calc(136px + var(--sa-l)); width: 110px; height: 110px; }
  /* 아이템 칸이 2개면 미니맵을 뒤 칸 오른쪽으로 (낮은 화면은 아이템 칸이 작은 크기) */
  #hud-item.two ~ #minimap { left: calc(144px + var(--sa-l)); }
  #t-stick-zone { height: 62vh; }
  #touch-controls #t-cam { top: calc(14px + var(--sa-t)); right: calc(180px + var(--sa-r)); }
  #touch-controls #t-respawn { top: calc(14px + var(--sa-t)); right: calc(236px + var(--sa-r)); }
  #hud-ranks { display: none; }
}
/* 좁은 가로 화면은 아이템 칸이 작으므로 미니맵을 덜 밀어냄 */
@media (pointer: coarse) and (max-height: 500px) and (max-width: 700px) {
  #hud-item.two ~ #minimap { left: calc(144px + var(--sa-l)); }
}

/* 좁은 화면 + 가로로 눕힌 휴대폰(높이가 낮음): HUD 를 작게 */
@media (max-width: 700px), (pointer: coarse) and (max-height: 500px) {
  #hud-ranks { display: none; }
  #pos-num { font-size: 80px; }
  #hud-lap { font-size: 30px; }
  #item-frame { width: 80px; height: 80px; }
  #item-frame2 { width: 46px; height: 46px; left: calc(100% - 12px); top: -3px; border-width: 3px; }
  #item-icon2, #item-icon2 svg { width: 30px; height: 30px; }
  #item-icon2 .triple { width: 34px; }
  #item-icon2 .triple svg { width: 16px; height: 16px; }
  #item-count2 { font-size: 15px; }
  #hud-coins { top: calc(128px + var(--sa-t)); }
}
@media (max-width: 700px) {
  .logo { font-size: 36px; }
}

/* 토스트 / 로딩 */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(30px + var(--sa-b));
  transform: translate(-50%, 30px);
  background: rgba(20, 30, 60, 0.9);
  color: #fff;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 50;
  width: max-content;
  max-width: calc(100% - 32px - var(--sa-l) - var(--sa-r));
  text-align: center;
  word-break: keep-all;
  overflow-wrap: anywhere;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#loading {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, #4ea8ff, #8fd0ff);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  text-align: center;
  padding: calc(24px + var(--sa-t)) calc(24px + var(--sa-r)) calc(24px + var(--sa-b)) calc(24px + var(--sa-l));
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 7px solid rgba(255, 255, 255, 0.35); border-top-color: #fff; animation: spin 0.9s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { 0% { transform: scale(0.5); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes count {
  0% { transform: translate(-50%, -50%) scale(2.2); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(0.85); opacity: 0; }
}
@keyframes blink { 50% { opacity: 0.4; } }
@keyframes flash { 0% { opacity: 0.9; } 100% { opacity: 0; } }

/* ---------------------------------------------------------------- 타임어택 */
#hud.ta #hud-pos, #hud.ta #hud-ranks, #hud.ta #hud-item, #hud.ta #hud-coins { display: none; }
#ta-hud { position: absolute; inset: 0; pointer-events: none; }
.ta-panel {
  position: absolute; left: calc(16px + var(--sa-l)); top: calc(16px + var(--sa-t)); width: 230px;
  background: rgba(20, 26, 48, 0.62); color: #fff; border-radius: 14px; padding: 10px 12px;
  font-size: 12px; backdrop-filter: blur(6px); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.ta-title { font-family: var(--font-kr); font-size: 15px; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ta-medal { display: flex; align-items: center; gap: 6px; opacity: 0.6; padding: 1px 0; }
.ta-medal.got { opacity: 1; font-weight: 800; }
.ta-medal i { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35); }
.ta-medal span { margin-left: auto; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.ta-pb { margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(255, 255, 255, 0.2); }
.ta-pb b { font-family: var(--font-num); float: right; }
.ta-hint { margin-top: 6px; opacity: 0.7; font-size: 11px; }
.ta-hint kbd, .tr-hint kbd { background: rgba(255, 255, 255, 0.18); border-radius: 4px; padding: 0 4px; font-size: 10px; }
.ta-split {
  position: absolute; left: 50%; top: 18%; transform: translateX(-50%) scale(0.8); opacity: 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: var(--font-num); color: #fff; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  transition: opacity 0.2s, transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.ta-split.show { opacity: 1; transform: translateX(-50%) scale(1); }
.ta-split b { font-size: 26px; }
.ta-split span { font-size: 20px; padding: 2px 10px; border-radius: 8px; }
.ta-split.faster span { background: rgba(30, 160, 255, 0.85); }
.ta-split.slower span { background: rgba(232, 53, 46, 0.85); }
.ta-timer { position: absolute; top: calc(96px + var(--sa-t)); right: calc(16px + var(--sa-r)); color: #fff; font: 16px var(--font-num); text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5); }
.ta-board { position: absolute; right: calc(16px + var(--sa-r)); top: calc(124px + var(--sa-t)); width: 210px; background: rgba(20, 26, 48, 0.55); border-radius: 12px; padding: 6px 8px; color: #fff; font-size: 12px; }
.ta-board .tb { display: flex; gap: 6px; padding: 2px 0; }
.ta-board .tb.me { color: #ffd84a; font-weight: 800; }
.ta-board .tb .n { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ta-board .tb b { font-family: var(--font-num); }
.ta-result {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  background: rgba(20, 26, 48, 0.78); color: #fff; border-radius: 20px; padding: 18px 28px; text-align: center;
  backdrop-filter: blur(8px); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35); min-width: min(260px, calc(100% - 24px)); max-width: calc(100% - 24px);
}
.ta-result.hidden { display: none; }
.tr-time { font: 44px var(--font-num); letter-spacing: 1px; }
.tr-delta { font: 18px var(--font-num); margin-top: 2px; }
.tr-delta.faster { color: #5fc3ff; }
.tr-delta.slower { color: #ff8a80; }
.tr-medal { margin-top: 8px; font-family: var(--font-kr); font-size: 22px; color: var(--mc); }
.tr-rank { margin-top: 6px; font-size: 14px; min-height: 18px; }
.tr-hint { margin-top: 8px; font-size: 12px; opacity: 0.75; }
.ta-restart-btn { display: none; }
@media (max-width: 700px) {
  .ta-panel { left: calc(8px + var(--sa-l)); top: calc(8px + var(--sa-t)); transform: scale(0.85); transform-origin: top left; }
}
/* 터치: 재시작 버튼은 📷·📍 버튼 줄 왼쪽 끝에 (조이스틱·미니맵과 겹치지 않게), 키보드 안내는 숨김.
   남은 시간·방 순위표는 그 버튼 줄 아래로 */
@media (pointer: coarse) {
  .ta-restart-btn {
    display: block; position: absolute; right: calc(128px + var(--sa-r)); top: calc(112px + var(--sa-t)); pointer-events: auto;
    width: 48px; height: 48px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.7);
    background: rgba(20, 30, 60, 0.45); color: #fff; font-size: 24px; padding: 0;
  }
  .ta-panel { width: 180px; font-size: 12px; }
  .ta-hint { display: none; }
  .ta-timer { top: calc(168px + var(--sa-t)); }
  .ta-board { top: calc(194px + var(--sa-t)); width: min(210px, calc(50% - 24px)); }
}
/* 가로로 눕힌 휴대폰: 버튼 줄이 화면 위쪽 → 재시작도 그 줄에, 미니맵은 타임어택 패널 오른쪽 */
@media (pointer: coarse) and (max-height: 500px) {
  .ta-restart-btn { top: calc(14px + var(--sa-t)); right: calc(292px + var(--sa-r)); }
  .ta-timer { top: calc(92px + var(--sa-t)); }
  .ta-board { top: calc(116px + var(--sa-t)); max-height: calc(100% - 290px - var(--sa-t) - var(--sa-b)); overflow: hidden; }
  #hud.ta #minimap { left: calc(206px + var(--sa-l)); }
}
@media (pointer: coarse) and (max-height: 500px) and (max-width: 700px) {
  #hud.ta #minimap { left: calc(172px + var(--sa-l)); }
}

/* ---------------------------------------------------------------- 맵 목록 · 랭킹 · 개인 설정 */
#tracks, #profile { justify-content: center; background: rgba(10, 20, 50, 0.4); z-index: 12; }
.tracks-panel { width: min(980px, 100%); height: min(680px, 100%); display: flex; flex-direction: column; }
.tracks-body { display: flex; gap: 14px; flex: 1; min-height: 0; margin-top: 10px; }
.tracks-side { width: 280px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.track-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 4px; }
.tl-item { font: inherit; text-align: left; border: 2px solid transparent; background: #f1f4fc; border-radius: 12px; padding: 8px 10px; cursor: pointer; position: relative; }
.tl-item.on { border-color: var(--blue); background: #e7efff; }
.tl-name { display: block; font-weight: 800; font-size: 14px; }
.tl-meta { display: block; font-size: 11px; color: #6a7391; margin-top: 2px; }
.tl-medal { position: absolute; right: 10px; top: 12px; width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 2px #fff, 0 1px 3px rgba(0, 0, 0, 0.3); }
.tl-empty { color: #6a7391; font-size: 13px; padding: 14px 4px; text-align: center; }
.track-detail { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-y: auto; }
.td-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.td-head h3 { margin: 0; font-family: var(--font-kr); font-weight: 400; font-size: 26px; }
.td-meta { font-size: 13px; color: #5a6385; margin-top: 2px; }
.td-medals { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.td-medal { display: flex; align-items: center; gap: 6px; background: #f1f4fc; border-radius: 10px; padding: 6px 10px; font-size: 12px; font-weight: 800; opacity: 0.6; }
.td-medal.got, .td-medal.pb { opacity: 1; }
.td-medal i { width: 12px; height: 12px; border-radius: 50%; }
.td-medal b { font-family: var(--font-num); font-weight: 400; }
.td-board-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 6px; }
.seg { display: flex; background: #eef1fb; border-radius: 10px; padding: 3px; }
.seg button { font: inherit; font-size: 12px; font-weight: 800; border: none; background: none; padding: 5px 10px; border-radius: 8px; cursor: pointer; color: #5a6385; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.td-board { display: flex; flex-direction: column; gap: 2px; }
.tb-row { display: grid; grid-template-columns: 36px 26px 1fr auto 34px; align-items: center; gap: 4px; padding: 5px 8px; border-radius: 8px; font-size: 13px; }
.tb-row:nth-child(odd) { background: #f6f8fd; }
.tb-row.me { background: #fff4c7; font-weight: 800; }
.tb-row .r { font-family: var(--font-num); color: #5a6385; }
.tb-row .n { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tb-row b { font-family: var(--font-num); font-weight: 400; }
.tb-row .gh { font: inherit; border: none; background: none; cursor: pointer; opacity: 0.45; font-size: 16px; }
.tb-row .gh.on { opacity: 1; filter: drop-shadow(0 0 4px #ffd84a); }
.tb-me { margin-top: 8px; font-size: 13px; padding: 6px 8px; background: #e7efff; border-radius: 8px; }
.td-ghost-hint { font-size: 11px; color: #6a7391; margin-top: 8px; }
.profile-panel { width: min(420px, 100%); display: flex; flex-direction: column; gap: 10px; }
.pf-account { font-size: 13px; color: #3a4466; background: #f1f4fc; border-radius: 10px; padding: 8px 10px; overflow-wrap: anywhere; }
.pf-account code { word-break: break-all; }
.pf-note { font-size: 12px; color: #6a7391; }
#editor-root { position: fixed; inset: 0; z-index: 14; }
@media (max-width: 760px) and (max-aspect-ratio: 3/2) {
  .tracks-body { flex-direction: column; }
  .tracks-side { width: auto; max-height: 34%; }
  .td-head { flex-direction: column; }
}
.tracks-panel, .profile-panel { background: #fbfcff; }

/* ---------------------------------------------------------------- 설정 (사운드 · 컨트롤러 · 카메라 · 그래픽) */
#settings {
  justify-content: flex-start;
  align-items: stretch;
  z-index: 12;
  padding-left: calc(max(var(--gap), 2vw) + var(--sa-l));
  background: linear-gradient(90deg, rgba(10, 20, 50, 0.5) 0, rgba(10, 20, 50, 0.2) 50%, transparent 75%);
}
#settings[data-tab='camera'] { background: none; }
body.settings-open #menu { visibility: hidden; }
body.cam-preview #hud { visibility: hidden; }
.set-panel { position: relative; z-index: 2; flex: none; width: min(560px, 100%); height: 100%; max-height: none; display: flex; flex-direction: column; overflow: hidden; }
.set-tabs { display: flex; gap: 4px; margin: 12px 0 10px; padding: 4px; background: #eef1fa; border-radius: 14px; }
.set-tab { flex: 1; min-width: 0; font: inherit; font-size: 13px; font-weight: 800; padding: 9px 4px; border: 0; border-radius: 10px; background: transparent; color: #5b6488; cursor: pointer; white-space: nowrap; }
.set-tab i { font-style: normal; }
.set-tab:hover { color: var(--ink); }
.set-tab.on { background: #fff; color: var(--blue); box-shadow: 0 2px 6px rgba(0, 30, 80, 0.15); }
.set-body { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -8px; padding: 0 8px 8px; }
.set-pane > .sub:first-child { margin-top: 0; }
.set-pane kbd { font: 700 11px var(--font-ui); padding: 1px 5px; border-radius: 5px; background: #fff; border: 1px solid #c9d0e6; }
.set-h { margin: 18px 0 6px; font-size: 15px; }
.set-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 10px; background: #f4f6fc; border-radius: 12px; margin-bottom: 6px; }
.set-row.disabled { opacity: 0.55; }
.set-label b { display: block; font-size: 14px; }
.set-label small { display: block; font-size: 11px; color: #7a83a3; line-height: 1.3; margin-top: 2px; }
.set-slider { display: flex; align-items: center; gap: 6px; }
.set-slider input[type='range'] { width: 150px; accent-color: var(--blue); }
.set-num { width: 64px; padding: 4px 6px; font: 700 13px var(--font-ui); text-align: right; border-radius: 8px; }
.set-unit { width: 14px; font-size: 12px; color: #7a83a3; }
.set-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.key-table { display: flex; flex-direction: column; gap: 4px; }
.key-row { display: grid; grid-template-columns: minmax(0, 1fr) 112px 112px; gap: 6px; align-items: center; padding: 5px 8px; background: #f4f6fc; border-radius: 10px; }
.key-act { font-size: 13px; font-weight: 700; }
.key-slot { font: 800 12px var(--font-ui); padding: 7px 6px; border-radius: 9px; border: 2px solid #d5dbef; background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.key-slot:hover { border-color: #9fb3e6; }
.key-slot.empty { color: #b3bad2; }
.key-slot.capturing { border-color: var(--blue); background: #e8f0ff; color: var(--blue); animation: key-wait 0.8s infinite; }
@keyframes key-wait { 50% { background: #fff; } }
.key-msg { min-height: 18px; font-size: 12px; color: var(--blue); font-weight: 700; margin: 6px 2px 4px; }
.pad-status { font-size: 12px; padding: 8px 10px; background: #f4f6fc; border-radius: 10px; margin-bottom: 6px; }
.pad-map { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 12px; padding: 8px 10px; background: #f4f6fc; border-radius: 10px; margin-bottom: 6px; }
.pad-map span { color: #7a83a3; }

.cam-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.cam-card { display: flex; flex-direction: column; border-radius: 12px; border: 2px solid #d5dbef; background: #fff; overflow: hidden; }
.cam-card.custom { border-style: dashed; }
.cam-card.on { border: 2px solid var(--blue); box-shadow: 0 0 0 2px rgba(31, 111, 224, 0.22); }
.cam-pick { position: relative; font: inherit; color: var(--ink); border: 0; background: none; cursor: pointer; padding: 10px 6px 5px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.cam-pick:hover { background: #f4f6fc; }
.cam-card.on .cam-pick { background: #e8f0ff; }
.cam-num { position: absolute; left: 7px; top: 5px; font: 12px var(--font-num); color: #9aa3c0; }
.cam-card.on .cam-num { color: var(--blue); }
.cam-ico { font-size: 22px; line-height: 1.15; }
.cam-nm { font-size: 12px; font-weight: 800; text-align: center; line-height: 1.2; }
.cam-tag { font-size: 10px; color: #7a83a3; }
.cam-cyc { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 11px; font-weight: 700; color: #5b6488; padding: 4px; border-top: 1px solid #eef1fa; cursor: pointer; }
.cam-cyc input { margin: 0; accent-color: var(--blue); }
.cam-detail-head { display: flex; align-items: center; gap: 8px; margin: 4px 0 2px; }
.cam-detail-icon { font-size: 24px; }
.cam-detail-name { font-size: 17px; }
.cam-name { flex: 1; min-width: 0; font: 800 16px var(--font-ui); padding: 6px 10px; }
.cam-lock { margin-left: auto; font-size: 11px; font-weight: 800; color: #7a83a3; background: #eef1fa; padding: 4px 8px; border-radius: 8px; white-space: nowrap; }
.cam-desc { font-size: 12px; color: #5b6488; margin-bottom: 8px; }
.cam-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.cam-note { font-size: 12px; color: #5b6488; }
.cam-from { padding: 6px 8px; font: 700 12px var(--font-ui); }

/* 카메라 탭 오른쪽: 실제 게임 화면을 창 비율 그대로 축소한 프레임(바깥은 어둡게) + 카메라 위치도 */
/* 설정 패널 옆(좁은 세로 화면은 위)을 채우는 flex 칸 — 화면 여백·안전 영역은 #settings 안쪽 여백이 맡음 */
#cam-side { display: none; }
#settings[data-tab='camera'] #cam-side {
  display: flex;
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  margin-left: 20px;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.cam-stage-bar { position: relative; z-index: 2; pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 7px 8px 7px 14px; background: rgba(14, 20, 44, 0.92); color: #fff; border-radius: 12px; }
.cam-live { font-size: 12px; font-weight: 800; color: #ff7b72; white-space: nowrap; }
#cam-title { flex: 1; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#cam-stage { position: relative; z-index: 1; flex: 1; min-height: 0; }
#cam-frame { position: absolute; border-radius: 6px; outline: 3px solid rgba(255, 255, 255, 0.95); box-shadow: 0 0 0 200vmax rgba(8, 12, 30, 0.62); }
#cam-info { position: relative; z-index: 2; flex: none; height: 200px; display: flex; flex-direction: column; gap: 5px; pointer-events: auto; }
#cam-diagram { flex: 1; min-height: 0; width: 100%; display: block; }
.cam-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11px; font-weight: 700; padding: 0 4px; }
.lg-cam { color: #ffd84a; }
.lg-live { color: #6edcff; }

/* 좁은 세로 화면(휴대폰·세로 태블릿): 미리보기가 위, 설정이 아래 */
@media (max-width: 980px) and (max-aspect-ratio: 3/2) {
  #settings[data-tab='camera'] { flex-direction: column; padding-left: calc(var(--gap) + var(--sa-l)); }
  #settings[data-tab='camera'] .set-panel { height: 56%; width: 100%; }
  #settings[data-tab='camera'] #cam-side { order: -1; margin: 0 0 10px; }
  #cam-info { display: none; }
}
/* 가로로 눕힌 휴대폰(낮은 화면): 설정은 왼쪽, 미리보기는 오른쪽 (위치도는 숨김) */
@media (max-height: 500px) and (min-aspect-ratio: 3/2) {
  #settings[data-tab='camera'] .set-panel { width: min(560px, 56%); }
  #settings[data-tab='camera'] #cam-side { margin-left: 12px; gap: 8px; }
  #cam-info, .cam-live { display: none; }
}
@media (max-width: 600px) {
  .set-panel { width: 100%; padding: 16px; }
  .set-row.slider { grid-template-columns: 1fr; gap: 6px; }
  .set-slider input[type='range'] { flex: 1; width: auto; }
  .set-tab { font-size: 12px; }
  .key-row { grid-template-columns: minmax(0, 1fr) 92px 92px; }
  .cam-list { grid-template-columns: repeat(2, 1fr); }
}

/* 터치 버튼 크기·불투명도 (설정 > 컨트롤러). 조이스틱은 #t-stick 이 --tc-scale 로 크기를 정함 */
.tc-right { transform: scale(var(--tc-scale, 1)); transform-origin: right bottom; }
#touch-controls button { opacity: var(--tc-opacity, 1); }

/* ---------------------------------------------------------------- 내가 만든 캐릭터 (메뉴·로비) */
.custom-char-row { display: flex; gap: 8px; overflow-x: auto; padding: 8px 2px 4px; scrollbar-width: thin; }
.custom-char-row:empty { display: none; }
.cc-card { position: relative; flex: none; width: 86px; display: flex; flex-direction: column; border-radius: 14px; border: 3px solid #e3e7f3; background: #f6f8fd; overflow: hidden; }
.cc-card.selected { border-color: var(--kc, var(--blue)); background: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15); }
.cc-pick, .cc-new { font: inherit; color: var(--ink); border: 0; background: none; cursor: pointer; padding: 6px 4px 6px; display: flex; flex-direction: column; align-items: center; gap: 3px; width: 100%; }
.cc-new { width: 86px; flex: none; border: 3px dashed #c9d0e6; border-radius: 14px; background: #fff; }
.cc-new:hover { border-color: var(--blue); }
.cc-thumb { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; display: flex; align-items: center; justify-content: center; font-size: 30px; background: #e9eefb; }
img.cc-thumb { display: block; }
.cc-name { font-size: 11px; font-weight: 800; max-width: 78px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cc-edit { position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, 0.92); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2); font-size: 12px; cursor: pointer; padding: 0; }
.custom-char-row.small .cc-card { width: 70px; }
.custom-char-row.small .cc-thumb { width: 40px; height: 40px; font-size: 22px; }

/* ---------------------------------------------------------------- 차고 (차량 고르기) */
.vehicle-btn { display: flex; align-items: center; gap: 10px; width: 100%; margin-top: 10px; text-align: left; padding: 10px 14px; }
.vehicle-btn .vb-ico { font-size: 24px; }
.vehicle-btn .vb-text { flex: 1; min-width: 0; font-size: 13px; color: #5b6488; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vehicle-btn .vb-text b { color: var(--ink); font-size: 15px; margin-left: 4px; }
.vehicle-btn .vb-go { font-size: 12px; font-weight: 800; color: var(--blue); }
.vehicle-btn.small { margin-top: 6px; padding: 7px 12px; }
#garage {
  justify-content: flex-start;
  align-items: stretch;
  z-index: 12;
  padding-left: calc(max(var(--gap), 2vw) + var(--sa-l));
  background: linear-gradient(90deg, rgba(10, 20, 50, 0.5) 0, rgba(10, 20, 50, 0.15) 50%, transparent 72%);
}
body.garage-open #menu, body.garage-open #lobby { visibility: hidden; }
.garage-panel { width: min(600px, 100%); height: 100%; max-height: none; display: flex; flex-direction: column; overflow: hidden; }
/* 넓은 화면에서는 감싸는 칸이 없는 것처럼 (필터 고정, 목록만 스크롤) */
.garage-scroll { display: contents; }
.garage-kinds { display: flex; gap: 4px; margin: 12px 0 8px; padding: 4px; background: #eef1fa; border-radius: 14px; }
.gk-tab { flex: 1; font: inherit; font-size: 13px; font-weight: 800; padding: 8px 4px; border: 0; border-radius: 10px; background: transparent; color: #5b6488; cursor: pointer; white-space: nowrap; }
.gk-tab small { font-weight: 700; opacity: 0.6; }
.gk-tab.on { background: #fff; color: var(--blue); box-shadow: 0 2px 6px rgba(0, 30, 80, 0.15); }
.garage-classes { justify-content: flex-start; margin-bottom: 8px; max-height: 64px; overflow-y: auto; }
.garage-filter { display: flex; gap: 6px; margin-bottom: 8px; }
.garage-filter input { flex: 1; min-width: 0; }
.garage-filter select { max-width: 45%; }
.garage-list { flex: 1; min-height: 120px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 8px; align-content: start; padding: 2px; }
.gv-card { position: relative; font: inherit; color: var(--ink); display: flex; flex-direction: column; align-items: stretch; gap: 2px; padding: 6px; border-radius: 14px; border: 3px solid #e3e7f3; background: #f6f8fd; cursor: pointer; text-align: left; }
.gv-card:hover { border-color: #b8c6ea; }
.gv-card.selected { border-color: var(--blue); background: #fff; box-shadow: 0 4px 14px rgba(31, 111, 224, 0.25); }
.gv-pick { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; display: flex; flex-direction: column; gap: 2px; text-align: left; }
.gv-thumb { display: flex; align-items: center; justify-content: center; height: 72px; border-radius: 10px; background: linear-gradient(180deg, #e9eefb, #dfe6f6); font-size: 30px; overflow: hidden; }
.gv-thumb img { width: 100%; height: 100%; object-fit: cover; }
.gv-spin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid #c9d0e6; border-top-color: var(--blue); animation: gv-spin 0.8s linear infinite; }
@keyframes gv-spin { to { transform: rotate(360deg); } }
.gv-name { font-size: 12px; font-weight: 800; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gv-meta { font-size: 10px; color: #7a83a3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gv-new { border-style: dashed; background: #fff; }
.garage-detail { flex: none; margin-top: 10px; padding: 10px 12px; border-radius: 14px; background: #f4f6fc; }
.gd-head b { font-size: 17px; }
.gd-head small { display: block; font-size: 12px; color: #5b6488; margin-top: 2px; }
.gd-desc { margin: 4px 0 6px; font-size: 12px; color: #5b6488; min-height: 0; }
.gd-desc:empty { display: none; }
.gd-stats { margin-top: 4px; }
.gd-stats em { font-style: normal; font-weight: 800; font-size: 11px; }
.gd-stats em.up { color: #18a058; }
.gd-stats em.down { color: #e8352e; }
.bar.g7 { position: relative; }
.bar.g7 .plus, .bar.g7 .minus { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.bar.g7 .plus { background: #34d17a; }
.bar.g7 .minus { background: rgba(232, 53, 46, 0.35); }
.gd-colors { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.gd-swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px #c9d0e6; cursor: pointer; font: 800 9px var(--font-ui); color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); padding: 0; }
.gd-swatch.on { box-shadow: 0 0 0 3px var(--blue); }
.gd-pick { width: 34px; height: 34px; padding: 0; border: 0; background: none; cursor: pointer; }
.gd-note { font-size: 12px; color: #5b6488; }
/* 무게 → 최고속 규칙 (가벼울수록 빠름) */
.gd-rule { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 8px; padding: 6px 8px; border-radius: 10px; background: #f1f4fc; font-size: 12px; font-weight: 700; color: #5b6488; }
.gd-rule b { color: var(--ink); }
.gd-rule b.up { color: #18a058; }
.gd-rule b.down { color: #e8352e; }
.gd-rule small { flex-basis: 100%; font-size: 11px; font-weight: 600; color: #7a83a3; }
.gd-scale { position: relative; width: 64px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #34d17a, #f2c12e 50%, #e8352e); flex: none; }
.gd-scale i { position: absolute; top: -3px; width: 4px; height: 14px; margin-left: -2px; border-radius: 2px; background: #1d2230; box-shadow: 0 0 0 1.5px #fff; }
.gv-thumb.gv-foot { position: relative; background: linear-gradient(180deg, #fff3d6, #ffe0a8); font-size: 38px; }
.gv-thumb.gv-foot small { position: absolute; right: 18%; bottom: 8%; font-size: 20px; }
@media (max-width: 600px) {
  .garage-panel { padding: 16px; }
  .garage-list { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
}
.gd-stats .stat span { width: 66px; white-space: nowrap; }
@media (max-width: 900px) and (max-aspect-ratio: 3/2) {
  /* 좁은 세로 화면: 위쪽은 미리보기 카트, 아래쪽이 차고 목록 */
  #garage { flex-direction: column; justify-content: flex-end; padding-left: calc(var(--gap) + var(--sa-l)); background: linear-gradient(180deg, transparent 0, transparent 30%, rgba(10, 20, 50, 0.35) 40%); }
  .garage-panel { width: 100%; height: 64%; }
}

/* ---------------------------------------------------------------- 코인 지갑 · 차량 등급 · 잠금 */
.vehicle-row { display: flex; gap: 8px; align-items: stretch; }
.vehicle-row .vehicle-btn { flex: 1; min-width: 0; }
.vehicle-row .wallet-chip { margin-top: 10px; }
.vehicle-row .vehicle-btn.small + .wallet-chip { margin-top: 6px; }
.wallet-chip { display: inline-flex; align-items: center; justify-content: center; gap: 4px; flex: none; padding: 4px 12px; border-radius: 999px; background: linear-gradient(180deg, #fff6c9, #ffe27a); border: 2px solid #f2c12e; color: #6b4a00; font: 800 15px var(--font-num); white-space: nowrap; box-shadow: inset 0 -2px 0 rgba(160, 110, 0, 0.18); cursor: default; }
.wallet-chip:empty { display: none; }
.wallet-chip.bump { animation: pop 0.35s ease-out; }
.garage-panel .gfx-head .wallet-chip { margin-left: auto; }
/* 등급 배지: S 금 · A 보라 · B 파랑 · C 초록 · D 청록 · E 회색 · F 연한 색 · 기본(카트·달리기) */
.grade-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 20px; padding: 0 5px; border-radius: 6px; font: 400 13px var(--font-num); line-height: 1; color: #fff; background: #8a93a8; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18); flex: none; }
.grade-badge.g-S { background: linear-gradient(180deg, #ffe066, #f2b705); color: #5a3d00; box-shadow: 0 0 0 1.5px #c98c00, 0 1px 4px rgba(242, 183, 5, 0.6); }
.grade-badge.g-A { background: #8a5cf6; }
.grade-badge.g-B { background: #1f6fe0; }
.grade-badge.g-C { background: #22b35a; }
.grade-badge.g-D { background: #14a3a3; }
.grade-badge.g-E { background: #8a93a8; }
.grade-badge.g-F { background: #eef1f7; color: #5b6488; box-shadow: 0 0 0 1px #d5dbef; }
.grade-badge.g-basic { background: #fff; color: var(--blue); font: 800 11px var(--font-ui); box-shadow: 0 0 0 1.5px #b8c6ea; }
.vehicle-btn .grade-badge { margin-right: -2px; }
.gv-card .gv-grade { position: absolute; top: 9px; left: 9px; z-index: 1; }
.gv-card.locked .gv-thumb { filter: grayscale(0.75) brightness(0.92); opacity: 0.6; }
.gv-card.locked .gv-name { color: #7a83a3; }
.gv-card.focus:not(.selected) { border-color: #9fb3e6; background: #fff; }
.gv-lock { position: absolute; top: 9px; right: 9px; z-index: 1; padding: 2px 7px; border-radius: 999px; background: rgba(29, 35, 64, 0.82); color: #ffe27a; font: 800 11px var(--font-ui); white-space: nowrap; }
.gv-lock.ok { background: #18a058; color: #fff; }
.gv-card.custom-locked .gv-pick { opacity: 0.6; }
.garage-grades { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-bottom: 8px; }
.garage-grades .gfx-chip { min-width: 34px; padding: 4px 8px; display: inline-flex; align-items: center; gap: 4px; }
.garage-grades .gfx-chip .grade-badge { min-width: 18px; height: 17px; font-size: 11px; }
.garage-grades .gfx-chip.on .grade-badge { box-shadow: 0 0 0 1.5px #fff; }
.garage-grades .gg-open { margin-left: auto; }
.gd-head { display: flex; align-items: flex-start; gap: 8px; }
.gd-head > div { flex: 1; min-width: 0; }
.gd-head .grade-badge { height: 26px; min-width: 30px; font-size: 17px; border-radius: 8px; }
.gd-unlock { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 8px; padding: 8px 10px; border-radius: 12px; background: #fff7d6; border: 2px solid #f2d36b; font-size: 12px; font-weight: 700; color: #6b4a00; }
.gd-unlock .btn { padding: 8px 14px; font-size: 14px; }
.gd-unlock .btn:disabled { opacity: 0.55; cursor: not-allowed; filter: grayscale(0.4); }
.gd-unlock small { flex-basis: 100%; font-size: 11px; font-weight: 600; color: #8a6a1a; }
.gd-unlock.confirm { background: #fff1e0; border-color: #ff9a1a; }
.gd-unlock.confirm > span { flex-basis: 100%; }
.gd-unlock.open { background: #e8f8ef; border-color: #8fdcae; color: #146b3a; }
/* 차량 만들기의 기준 차량 고르기: 잠긴 차량 */
.ve-vcard { position: relative; }
.ve-vcard .grade-badge { position: absolute; top: 4px; right: 4px; min-width: 18px; height: 16px; font-size: 10px; }
.ve-vcard.locked { opacity: 0.55; filter: grayscale(0.5); cursor: not-allowed; }
.ve-vcard.locked::after { content: '🔒'; position: absolute; top: 3px; right: 26px; font-size: 12px; }
/* 결과 화면의 코인 정산 */
.results-coins { margin: 8px 0 2px; padding: 8px 12px; border-radius: 12px; background: linear-gradient(180deg, #fff6c9, #ffe8a0); border: 2px solid #f2c12e; color: #6b4a00; font-weight: 800; font-size: 15px; text-align: center; }
.results-coins b { font: 400 18px var(--font-num); }
.results-coins small { display: block; font-size: 11px; font-weight: 700; color: #8a6a1a; }
.results-coins.muted { background: #f1f4fc; border-color: #d5dbef; color: #5b6488; }
/* 레이스 HUD: 이번 레이스에서 주운 코인 (지갑용) */
#coin-earned { font: 400 15px var(--font-num); color: #ffe27a; -webkit-text-stroke: 1px #000; align-self: flex-end; margin-bottom: 2px; }
#coin-earned:empty { display: none; }
#coin-earned.pop { animation: pop 0.3s ease-out; }

/* 화면을 가리지 않는 진행 표시 (캐릭터·차량 불러오기) */
#busy-pill {
  position: fixed;
  top: calc(14px + var(--sa-t));
  left: 50%;
  z-index: 40;
  max-width: calc(100% - 32px);
  white-space: nowrap;
  transform: translate(-50%, -8px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 8px 12px;
  border-radius: 999px;
  background: rgba(16, 22, 46, 0.82);
  color: #fff;
  font: 700 13px var(--font-ui);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
}
#busy-pill.show { opacity: 1; transform: translate(-50%, 0); }
#busy-pill::before { content: ''; width: 14px; height: 14px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.3); border-top-color: #fff; animation: gv-spin 0.8s linear infinite; }
.cc-card.loading { border-color: var(--blue); }
.cc-card.loading .cc-thumb { opacity: 0.45; }
.cc-card.loading::after { content: ''; position: absolute; left: 50%; top: 30px; width: 20px; height: 20px; margin-left: -10px; border-radius: 50%; border: 3px solid rgba(31, 111, 224, 0.25); border-top-color: var(--blue); animation: gv-spin 0.8s linear infinite; }

/* 혼자 하기 서킷 고르기 */
.solo-track { display: flex; align-items: center; gap: 8px; margin-top: -4px; font-size: 13px; font-weight: 800; color: #5b6488; }
.solo-track select { flex: 1; min-width: 0; padding: 7px 10px; }

/* ================================================================ 반응형 (휴대폰 · 태블릿)
   기준: 휴대폰 세로 max-width 480px (캐릭터 칸 420px) · 좁은 화면 600 / 760 / 900 / 980px (+ 세로형 max-aspect-ratio 3/2) ·
   가로로 눕힌 휴대폰 max-height 500px + min-aspect-ratio 3/2 (화면 키보드로 세로 화면이 낮아져도 가로 배치로 바뀌지 않게) ·
   터치 pointer: coarse (터치 대상 40px 이상) */

/* 작은 글자는 12px 이상 (데스크톱에서도 거의 그대로 보이는 1px 차이) */
.stats-note, .char-group, .cc-name, .results-coins small, .tl-meta, .td-ghost-hint, .set-label small, .set-pane kbd,
.cam-tag, .cam-cyc, .cam-lock, .cam-legend, .gk-tab small, .gv-meta, .gv-lock, .gd-unlock small, .gd-rule small, .gd-stats em { font-size: 12px; }
.grade-badge.g-basic { font-size: 12px; }
.char-name, .char-grid.small .char-name { font-size: 12px; letter-spacing: -0.02em; }
.garage-grades .gfx-chip .grade-badge { font-size: 12px; }
.gd-swatch { font-size: 12px; letter-spacing: -0.06em; }
/* 내가 만든 캐릭터 저장 칸 수 (📦 모델 · 🧱 직접 만들기): 좁은 카드에서는 두 줄 */
.custom-char-row .cc-count { display: flex; flex-wrap: wrap; justify-content: center; column-gap: 5px; font-size: 12px; white-space: normal; line-height: 1.25; }
/* 긴 이름은 말줄임 */
#results-table .rname { max-width: 1px; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#results-table .rtime { white-space: nowrap; }
.room-head { flex-wrap: wrap; gap: 6px 10px; }
.room-head .btn, .pchar, .crown { white-space: nowrap; }
.gfx-head h2 { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gfx-head .btn { flex: none; white-space: nowrap; }

/* 터치 화면: 누르는 곳은 40px 이상 */
@media (pointer: coarse) {
  .screen .btn.small, .screen .gfx-chip, .set-tab, .gk-tab, .key-slot, .seg button { min-height: 40px; }
  .screen .gfx-chip { min-width: 40px; }
  .screen select, .screen input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='color']) { min-height: 40px; }
  .garage-grades .gfx-chip { min-width: 40px; justify-content: center; }
  .gd-unlock .btn { min-height: 40px; }
  .set-num { min-height: 40px; }
  .set-slider input[type='range'] { height: 32px; }
  .seg button { padding: 6px 14px; }
  .cam-cyc { min-height: 40px; }
  .cam-cyc input, .lobby-settings input[type='checkbox'] { width: 20px; height: 20px; }
  .lobby-settings label.check { min-height: 40px; padding-bottom: 0; }
  .help summary { padding: 12px 0; }
  .tb-row { grid-template-columns: 36px 26px 1fr auto 40px; }
  .tb-row .gh { min-width: 40px; min-height: 40px; }
  .gd-swatch { width: 40px; height: 40px; font-size: 12px; }
  .gd-pick { width: 44px; height: 44px; }
  /* ✏️ 고치기: 카드 그림을 덜 가리도록 보이는 크기는 작게, 누르는 영역만 넓게 */
  .cc-edit { width: 30px; height: 30px; font-size: 14px; }
  .cc-edit::after { content: ''; position: absolute; inset: -6px; }
}

/* 휴대폰 세로: 패널 안쪽 여백·세로 간격을 줄여 한 화면에 더 많이 */
@media (max-width: 480px) {
  .screen > .panel { padding: 16px 16px 18px; border-width: 3px; border-radius: 18px; }
  .lobby-panel .lobby-buttons, .results-panel .lobby-buttons { bottom: -18px; margin: 12px -16px -18px; padding: 10px 16px 14px; border-radius: 0 0 15px 15px; }
  #menu, #lobby { justify-content: center; padding-left: calc(var(--gap) + var(--sa-l)); }
  .logo { font-size: 8.4vw; gap: 2vw; }
  .logo .l3 { font-size: 0.66em; padding: 2px 8px; border-radius: 8px; }
  .sub { margin: 4px 0 10px; }
  .label { margin: 8px 0 5px; }
  .field { gap: 4px; }
  .menu-panel .field input { padding: 8px 12px; }
  .char-stats { margin-top: 6px; }
  .menu-buttons, .lobby-buttons { gap: 8px; margin-top: 10px; }
  .vehicle-btn { margin-top: 8px; padding: 8px 12px; }
  .vehicle-row .wallet-chip { margin-top: 8px; }
  .help { margin-top: 6px; }
  #player-list { margin: 10px 0; gap: 5px; }
  .player-row { gap: 8px; padding: 5px 8px; }
  .room-head b { font-size: 26px; }
  /* 내가 만든 캐릭터: 작은 카드, 「캐릭터 만들기」는 그림 옆에 글자 (세로로 길지 않게) */
  .custom-char-row { gap: 6px; padding: 6px 2px 2px; }
  .custom-char-row .cc-card { width: 72px; border-radius: 12px; border-width: 2px; }
  .custom-char-row .cc-pick { padding: 5px 3px; }
  .custom-char-row .cc-thumb { width: 40px; height: 40px; font-size: 22px; border-radius: 10px; }
  .custom-char-row .cc-name { max-width: 66px; }
  .custom-char-row .cc-new { display: grid; grid-template-columns: 40px auto; column-gap: 8px; align-items: center; justify-items: start; align-content: center; width: auto; padding: 5px 12px 5px 6px; }
  .custom-char-row .cc-new .cc-thumb { grid-row: span 2; }
  .custom-char-row .cc-new .cc-name { max-width: none; }
  .custom-char-row .cc-new .cc-count { justify-content: flex-start; }
  /* 결과 표 */
  #results-table td { padding: 5px 6px; }
  #results-table .place { width: 44px; font-size: 18px; }
  #results-table .pface { width: 28px; height: 28px; font-size: 17px; }
  .results-panel h2, .pause-panel h2 { font-size: 26px; }
  /* 설정: 칩 줄은 이름 아래로 */
  .set-row { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .set-row .gfx-chips { justify-content: flex-start; }
  .tracks-panel .td-head .btn { align-self: stretch; }
}
/* 아주 좁은 화면: 설정 탭은 아이콘 위·이름 아래 */
@media (max-width: 420px) {
  .set-tab { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 2px; font-size: 12px; line-height: 1.15; }
  .set-tab i { font-size: 17px; }
}

/* 차고 (좁은 세로 화면): 필터와 목록은 함께 스크롤, 자세히 칸은 아래에 붙은 시트 (잠금 해제·색이 먼저) */
@media (max-width: 900px) and (max-aspect-ratio: 3/2) {
  .garage-scroll { display: block; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; margin: 0 -6px; padding: 0 6px 6px; }
  .garage-list { overflow: visible; min-height: 0; flex: none; }
  .garage-kinds { margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
  .gk-tab { flex: 1 0 auto; padding: 8px 10px; }
  .garage-classes, .garage-grades { flex-wrap: nowrap; overflow-x: auto; max-height: none; scrollbar-width: none; }
  .garage-classes .gfx-chip, .garage-grades .gfx-chip { flex: none; white-space: nowrap; }
  .garage-grades .gg-open { margin-left: 0; }
  .garage-panel { height: 68%; }
  .garage-detail { display: flex; flex-direction: column; max-height: 38%; overflow-y: auto; overscroll-behavior: contain; margin-top: 8px; padding: 8px 10px; box-shadow: 0 -4px 12px rgba(0, 30, 80, 0.1); }
  .garage-detail > .gd-head { order: 0; }
  .garage-detail > .gd-unlock { order: 1; }
  /* 색 고르기는 한 줄로 옆으로 밀어 보기 */
  .garage-detail > .gd-colors { order: 2; flex-wrap: nowrap; overflow-x: auto; flex: none; padding: 2px 3px 4px; scrollbar-width: none; }
  .gd-colors > * { flex: none; }
  .garage-detail > .gd-desc { order: 3; margin-top: 6px; }
  .garage-detail > .gd-stats { order: 4; }
  .garage-detail > .gd-rule { order: 5; }
}
/* 작은 휴대폰(세로 720px 이하): 미리보기 카트 자리를 줄이고 목록·자세히를 크게 */
@media (max-width: 900px) and (max-aspect-ratio: 3/2) and (max-height: 720px) {
  .garage-panel { height: 78%; }
  .garage-detail { max-height: 44%; }
}
/* 화면 키보드가 올라와 세로 화면이 낮아짐 (검색 입력 중): 패널을 화면 가득, 검색 중에는 자세히 칸을 접어 결과 목록이 보이게 */
@media (max-width: 900px) and (max-aspect-ratio: 3/2) and (max-height: 500px) {
  .garage-panel { height: 100%; }
  .garage-detail { max-height: 34%; }
  .garage-panel:has(#garage-search:focus) .garage-detail { display: none; }
}
/* 레이스 중 터치 화면(세로): 알림은 아래쪽 버튼들 위로 */
@media (pointer: coarse) and (max-aspect-ratio: 3/2) {
  #hud:not(.hidden) ~ #toast { bottom: calc(150px + var(--sa-b)); }
}

/* 가로로 눕힌 휴대폰 (높이 500px 이하): 패널은 화면 높이를 다 쓰고 세로 간격을 줄임 */
@media (max-height: 500px) and (min-aspect-ratio: 3/2) {
  .screen > .panel { padding: 12px 16px 14px; border-width: 3px; border-radius: 18px; }
  .lobby-panel .lobby-buttons, .results-panel .lobby-buttons { bottom: -14px; margin: 10px -16px -14px; padding: 8px 16px 10px; border-radius: 0 0 15px 15px; }
  .lobby-buttons { flex-direction: row; }
  .lobby-buttons .btn { flex: 1; }
  .gfx-head h2, .results-panel h2, .pause-panel h2 { font-size: 24px; }
  .results-panel h2 { margin-bottom: 6px; }
  #results-table td { padding: 4px 8px; }
  #results-table .place { font-size: 18px; }
  .pause-panel { gap: 8px; }
  .pause-panel .sub { margin: 0 0 4px; }
  .set-tabs { margin: 8px 0 6px; }
  /* 맵 목록: 목록·자세히를 나란히 */
  .tracks-body { margin-top: 6px; gap: 10px; }
  .tracks-side { width: min(280px, 40%); }
  .td-head h3 { font-size: 22px; }
  .td-medals { margin: 8px 0; }
  /* 차고: 왼쪽 패널 안에서 목록(왼쪽)·자세히(오른쪽) 두 칸, 오른쪽 빈 곳에 미리보기 카트 */
  .garage-panel { width: min(680px, 70%); display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); column-gap: 12px; }
  .garage-panel > .gfx-head { grid-column: 1 / -1; }
  .garage-scroll { display: block; min-height: 0; overflow-y: auto; overscroll-behavior: contain; margin-top: 8px; padding-right: 2px; }
  .garage-list { overflow: visible; min-height: 0; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .garage-kinds { margin: 0 0 6px; overflow-x: auto; scrollbar-width: none; }
  .gk-tab { flex: 1 0 auto; padding: 7px 8px; }
  .garage-filter select { max-width: 40%; }
  .garage-detail { display: flex; flex-direction: column; }
  .garage-detail > .gd-unlock { order: 1; }
  .garage-detail > .gd-colors { order: 2; }
  .garage-detail > .gd-desc { order: 3; margin-top: 6px; }
  .garage-detail > .gd-stats { order: 4; }
  .garage-detail > .gd-rule { order: 5; }
  .garage-classes, .garage-grades { flex-wrap: nowrap; overflow-x: auto; max-height: none; scrollbar-width: none; }
  .garage-classes .gfx-chip, .garage-grades .gfx-chip { flex: none; white-space: nowrap; }
  .garage-grades .gg-open { margin-left: 0; }
  .garage-detail { margin-top: 8px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  .gd-stats { grid-template-columns: minmax(0, 1fr); }
}
