/* 원터치 레이스 — 아케이드 게임. 캔버스 1장 + 오버레이 구조.
   팔레트: 아스팔트 슬레이트 #1b2430 / 레이싱 옐로 #FFC21A / 연석 빨강 #E2382C. */
:root {
  --bg: #1b2430;
  --bg2: #10161e;
  --ink: #eef3fa;
  --dim: #93a3b8;
  --sun: #FFC21A;
  --sun-dark: #a97c00;
  --kerb: #E2382C;
  --pill: #d8dfea;
  --pill-ink: #22303f;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg2);
  color: var(--ink);
  font: 700 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ARCADE-FIT: 게임 프레임. 폰에선 화면 전체, 데스크톱에선 가운데 뜬 폰 모양(아래 미디어쿼리).
   오버레이는 전부 이 안에 `position:absolute` 로 갇힌다 — fixed 를 쓰면 프레임 밖으로 샌다. */
#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

main { position: absolute; inset: 0; }

/* 캔버스는 프레임을 꽉 채운다. 9:16 이 아닌 폰에서 남는 띠는 app.js 가 잔디를 이어 그려
   메운다 — 검은 띠를 만들지 않는다. */
#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#deskHint { display: none; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  background: rgba(8, 12, 18, .84);
}
.overlay[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 22rem;
  max-height: 100%;
  overflow-y: auto;
  background: linear-gradient(180deg, #2c3a4b, #18222e);
  border-radius: 1.4rem;
  padding: 1.4rem 1.2rem;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .12), 0 1rem 2rem rgba(0, 0, 0, .55);
}

.sheet h1 { font-size: 1.15rem; margin-bottom: 1rem; color: var(--ink); }

.sheet button {
  width: 100%;
  padding: .9rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe07a, var(--sun));
  color: #3a2a00;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .8), inset 0 -3px 0 var(--sun-dark);
  margin-top: .55rem;
}

.sheet button.ghost {
  background: linear-gradient(180deg, #eef2f8, var(--pill));
  color: var(--pill-ink);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .9), inset 0 -3px 0 #a9b4c4;
}
.sheet button.ghost[hidden] { display: none; }

/* ── 결과창 ───────────────────────────────────────── */
.result-sheet { text-align: center; }
.result-sheet h1 { margin-bottom: .4rem; }

.stars {
  display: flex;
  justify-content: center;
  gap: .35rem;
  margin: .1rem 0 .7rem;
  font-size: 2rem;
  line-height: 1;
}
.stars span { filter: grayscale(1) brightness(.55); }
.stars span.on { filter: none; text-shadow: 0 0 .7rem rgba(255, 200, 60, .8); }

#result-stats { display: flex; gap: .45rem; margin: .1rem 0 .8rem; }
#result-stats .stat {
  flex: 1;
  padding: .55rem .25rem;
  border-radius: .8rem;
  background: rgba(0, 0, 0, .3);
}
#result-stats .stat b { display: block; font-size: 1.45rem; color: #fff; line-height: 1.1; }
#result-stats .stat span { font-size: .7rem; font-weight: 700; color: var(--dim); }

#result-why { margin-bottom: .8rem; color: var(--dim); font-size: .88rem; font-weight: 600; }

/* 부활은 결과창의 주인공 버튼이다 — 금빛으로 강조. */
.sheet button#revive {
  background: linear-gradient(180deg, #ffe066, #ffb800);
  color: #4a3200;
  font-size: .95rem;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .85), inset 0 -3px 0 #c98a00,
    0 .35rem 1.1rem rgba(255, 179, 0, .45);
  animation: gold 1.8s ease-in-out infinite;
}
@keyframes gold {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

/* ── 업그레이드(코인 소비처) ───────────────────────── */
.up-head {
  display: flex;
  justify-content: space-between;
  margin: .9rem 0 .35rem;
  font-size: .78rem;
  color: var(--dim);
  letter-spacing: .02em;
}
.up-head #coinNow { color: var(--sun); }

.upgrades { display: flex; gap: .4rem; }
.upgrades .up {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
  padding: .5rem .2rem .45rem;
  border: 0;
  border-radius: .8rem;
  background: rgba(255, 255, 255, .08);
  color: var(--ink);
  font: inherit;
  font-size: .78rem;
  font-weight: 800;
  cursor: pointer;
  margin: 0;
  box-shadow: none;
}
.upgrades .up:disabled { opacity: .45; cursor: default; }
.upgrades .up .pips { display: flex; gap: 2px; }
.upgrades .up .pips i {
  width: 7px; height: 7px; border-radius: 2px;
  background: rgba(255, 255, 255, .22);
}
.upgrades .up .pips i.on { background: var(--sun); }
.upgrades .up .cost { font-size: .72rem; color: var(--sun); font-weight: 800; }
.upgrades .up.max .cost { color: var(--dim); }

/* ── 홈 ───────────────────────────────────────────── */
/* 캔버스에 트랙·광고판이 흐르므로 **반투명**이다. 예전엔 asphalt 를 깔아 꽉 막혀 있었다. */
#home {
  background: linear-gradient(180deg,
    rgba(16, 24, 34, .34) 0%,
    rgba(11, 17, 25, .66) 44%,
    rgba(8, 12, 18, .94) 78%);
}

.home-sheet {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  align-items: center;
  justify-content: flex-end;
  text-align: center;
  max-width: 20rem;
  height: 100%;
  background: none;
  box-shadow: none;
  padding: 1rem .6rem;
  overflow: visible;
}

.home-title {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -.01em;
  color: #fff;
  line-height: 1;
  margin: 0;
  text-shadow: 0 .16rem 0 #2a3646, 0 0 1.6rem rgba(255, 194, 26, .45);
  cursor: pointer;
}
.home-sheet h1.home-title { font-size: 2.5rem; margin-bottom: 0; }
.home-sub {
  font-size: .88rem;
  font-weight: 700;
  color: var(--sun);
  letter-spacing: .02em;
  opacity: .9;
}

#homeHero {
  width: 44%;
  max-width: 9.4rem;
  height: auto;
  margin: .3rem 0 0;
  cursor: pointer;
  filter: drop-shadow(0 .8rem 1.1rem rgba(0, 0, 0, .7));
  animation: bob 2.6s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-9px); }
}

#homeMain { width: 100%; }

#tapToStart {
  display: block;
  width: 100%;
  padding: .95rem 1rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe07a, var(--sun));
  color: #3a2a00;
  font: inherit;
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .85), inset 0 -4px 0 var(--sun-dark),
    0 .4rem 1.2rem rgba(255, 194, 26, .35);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

/* 트랙 고르기 — 세 코스는 시드 고정이라 외워서 탈 수 있다. 고른 것이 홈 배경에도 흐른다. */
.tracks {
  display: flex;
  gap: .4rem;
  width: 100%;
  margin: .1rem 0 .2rem;
}
.home-sheet .track {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .1rem;
  padding: .38rem .2rem;
  border: 2px solid rgba(255, 255, 255, .22);
  border-radius: .7rem;
  background: rgba(12, 17, 24, .55);
  color: #cbd6e6;
  font: inherit;
  cursor: pointer;
}
.home-sheet .track b { font-size: 1.05rem; font-weight: 900; line-height: 1; }
.home-sheet .track span { font-size: .62rem; opacity: .85; letter-spacing: -.02em; }
.home-sheet .track.on {
  border-color: var(--sun);
  background: rgba(255, 194, 26, .16);
  color: #fff;
}

.carousel {
  display: flex;
  gap: .45rem;
  width: 100%;
  overflow-x: auto;
  padding: .3rem .1rem;
  scrollbar-width: none;
}
.carousel::-webkit-scrollbar { display: none; }

.home-sheet .skin-chip {
  flex: 0 0 auto;
  width: 2.9rem;
  height: 2.9rem;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, .25);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--chip) 60%, #fff), var(--chip));
  cursor: pointer;
  overflow: hidden;
  display: grid;
  place-items: center;
}
/* ⚠️ ahome.js(공용 사본, 수정 금지)는 hero 를 **파랑 210° 기준**으로 hue-rotate 한다.
   우리 hero 는 노란 차(≈48°)라 그대로 두면 칩 색이 전부 어긋난다. 색은 칩 배경(--chip)이
   내고, 차 그림은 **명도만** 얹는다 — 인라인 filter 가 무엇이든 결과 색이 맞는다. */
.home-sheet .skin-chip img {
  width: 74%;
  mix-blend-mode: luminosity;
  opacity: .92;
}
.home-sheet .skin-chip.on { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 194, 26, .75); }
.home-sheet .skin-chip.locked { opacity: .38; }

#homeTabs { display: flex; gap: .5rem; width: 100%; margin-top: .3rem; }

.home-sheet .tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
  padding: .5rem .3rem;
  border: 0;
  border-radius: .9rem;
  background: rgba(38, 50, 66, .8);
  color: #dfe6f2;
  font: inherit;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.home-sheet .tab-btn b { font-size: 1.15rem; line-height: 1; font-weight: 400; }
.home-sheet .tab-btn:active, .home-sheet .tab-btn.active { background: var(--sun); color: #3a2a00; }

.panel { width: 100%; color: var(--ink); font-size: .9rem; }
.shop-row, .mission-row {
  display: flex;
  justify-content: space-between;
  padding: .5rem .7rem;
  margin-bottom: .3rem;
  border-radius: .6rem;
  background: rgba(38, 50, 66, .8);
}
.sheet .panel .back, .home-sheet .panel .back {
  width: 100%;
  margin-top: .5rem;
  padding: .7rem;
  border: 0;
  border-radius: 999px;
  background: var(--sun);
  color: #3a2a00;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

/* ── 데스크톱 = 가운데 뜬 폰 프레임 ─────────────────── */
@media (min-width: 768px) and (min-height: 600px) {
  body {
    background: radial-gradient(120% 90% at 50% 0%, #33465e 0%, #1b2430 45%, #05080c 100%);
    gap: 1rem;
  }
  #app {
    width: min(420px, calc((100vh - 72px) * 360 / 640));
    height: min(calc(100vh - 72px), calc(420px * 640 / 360));
    border-radius: 32px;
    box-shadow: 0 0 0 10px #0f151d, 0 0 0 12px #2a3646, 0 40px 90px rgba(0, 0, 0, .65);
  }
  #stage { border-radius: 32px; }
  #deskHint {
    display: block;
    margin: 0;
    color: var(--dim);
    font-size: .85rem;
    font-weight: 600;
    letter-spacing: .01em;
  }
}

/* 세로 전용 */
#rotate { display: none; }
@media (orientation: landscape) and (max-height: 520px) {
  #app, #deskHint { display: none !important; }
  #rotate {
    display: flex;
    position: fixed;
    inset: 0;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    color: var(--dim);
    font-size: 1.05rem;
    line-height: 1.6;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
