/* 차 3매치 — 아케이드 게임. 캔버스 1장 + 오버레이 구조. */
:root {
  --bg: #12182c;
  --pill: #d5dcf5;
  --pill-ink: #2a3050;
  --ink: #e6eaff;
  --dim: #9aa3cc;
  --accent: #8fa0ff;
  --gold: #ffb800;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  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;
}

main { position: absolute; inset: 0; }

/* 캔버스는 프레임을 꽉 채운다. 9:16 레터박스는 app.js 의 resizeCanvas 가
   setTransform 으로 가운데 정렬해 만들고, 남는 띠는 하늘로 이어 그린다. */
#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#kbdHint { display: none; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.4rem;
  background: rgba(6, 9, 22, .82);
}
.overlay[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 22rem;
  max-height: 100%;
  overflow-y: auto;
  background: linear-gradient(180deg, #2a3157, #1b2140);
  border-radius: 1.4rem;
  padding: 1.5rem 1.3rem;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .12), 0 1rem 2rem rgba(0, 0, 0, .5);
}

.sheet h1 { font-size: 1.15rem; margin-bottom: 1rem; color: var(--ink); }
.sheet > div {
  background: rgba(0, 0, 0, .28);
  border-radius: .9rem;
  padding: .6rem;
}

.sheet button {
  width: 100%;
  padding: .95rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #c3ccff, var(--accent));
  color: #171c38;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .8), inset 0 -3px 0 #6474d8;
  margin-top: .6rem;
}

.sheet button.ghost {
  background: linear-gradient(180deg, #eef1ff, var(--pill));
  color: var(--pill-ink);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .9), inset 0 -3px 0 #adb6dd;
}
.sheet button.ghost[hidden] { display: none; }

/* ── 결과창 ───────────────────────────────────────── */
.result-sheet { text-align: center; }
.result-sheet h1 { margin-bottom: .35rem; }

#result-stats {
  color: #fff;
  margin: .9rem 0;
  background: rgba(0, 0, 0, .3);
}
.score-big {
  font-size: 3.4rem;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  text-shadow: 0 .2rem .8rem rgba(0, 0, 0, .5);
}
.score-big span { font-size: 1.2rem; margin-left: .15rem; color: var(--dim); }
.score-best {
  margin-top: .35rem;
  font-size: .85rem;
  font-weight: 700;
  color: var(--dim);
}

#result-why {
  margin-bottom: 1.1rem;
  color: var(--dim);
  font-size: .9rem;
  font-weight: 600;
}

/* 부활은 결과창의 주인공 버튼이다 — 노란 금빛으로 강조. */
.sheet button#revive {
  background: linear-gradient(180deg, #ffe066, var(--gold));
  color: #4a3200;
  font-size: 1.05rem;
  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); }
}

/* ── 홈 ───────────────────────────────────────────── */
.home-sheet {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  max-width: 20rem;
  height: 100%;
  background: none;
  box-shadow: none;
  padding: 1rem .6rem;
  overflow: visible;
}
.home-sheet > div { background: none; padding: 0; }

.home-title {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: .02em;
  color: #fff;
  line-height: 1;
  margin: 0;
  text-shadow: 0 .18rem 0 #1b2140, 0 .5rem 1.4rem rgba(0, 0, 0, .6);
  cursor: pointer;
}
.home-sheet h1.home-title { font-size: 2.6rem; margin-bottom: 0; }

#homeHero {
  /* vw 단위는 데스크톱 폰 프레임 안에서 깨진다 — 시트 폭 기준 % 로.
     주차 대란의 주인공은 세로로 긴 차라 계단 캐릭터보다 좁게 잡는다. */
  width: 24%;
  max-width: 4.6rem;
  height: auto;
  margin: .1rem 0 -.1rem;
  cursor: pointer;
  filter: drop-shadow(0 .8rem 1.4rem rgba(0, 0, 0, .55));
  animation: bob 2.6s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* 레벨 격자만 남는 자리를 먹는다. 나머지(제목·차·칩·탭)는 줄어들면 안 된다 —
   flex 기본값(shrink:1)이라 격자가 크면 스킨 캐러셀이 실오라기로 눌렸다. */
#homeMain { width: 100%; flex: 1 1 auto; min-height: 0; display: flex; }
.home-sheet > *:not(#homeMain) { flex: 0 0 auto; }
.home-sheet { gap: .35rem; }
.home-sheet h1.home-title { font-size: 2.3rem; }

#tapToStart {
  display: block;
  width: 100%;
  padding: .95rem 1rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe066, var(--gold));
  color: #4a3200;
  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 #c98a00,
    0 .4rem 1.2rem rgba(255, 179, 0, .4);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

.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) 55%, #fff), var(--chip));
  cursor: pointer;
  overflow: hidden;
  display: grid;
  place-items: center;
}
/* 칩 그림은 app.js 의 paintChips 가 빨강(0°) 기준으로 색을 돌려 넣는다 —
   ahome 사본은 파랑(210°) 기준이라 우리 hero(빨강)에는 안 맞는다(교훈 12).
   여기서 filter 를 덮어쓰면 그 색까지 지워지므로 건드리지 않는다. */
.home-sheet .skin-chip img { width: 64%; margin-top: 0; }
.home-sheet .skin-chip.on { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 224, 102, .7); }
.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(20, 28, 56, .6);
  color: #dfe5ff;
  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(--gold); color: #4a3200; }

.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(20, 28, 56, .6);
}
.sheet .panel .back {
  width: 100%;
  margin-top: .5rem;
  padding: .7rem;
  border: 0;
  border-radius: 999px;
  background: var(--gold);
  color: #4a3200;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

/* ── 데스크톱 = 가운데 뜬 폰 프레임 ─────────────────── */
@media (min-width: 768px) and (min-height: 600px) {
  body {
    background:
      radial-gradient(120% 90% at 50% 0%, #2a3a7a 0%, #131a3c 45%, #070a18 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 #15182a, 0 0 0 12px #2b3050, 0 40px 90px rgba(0, 0, 0, .6);
  }
  #stage { border-radius: 32px; }
  #kbdHint {
    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, #kbdHint { 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; }
}

/* 홈 배경(assets/lot-night.webp — 탑다운 주차장). url 은 CSS 파일 기준 ../ (pipes 함정). */
#home {
  background-image:
    linear-gradient(180deg, rgba(12, 18, 40, 0.35), rgba(8, 12, 30, 0.7)),
    url("../assets/lot-night.webp");
  background-size: cover;
  background-position: center;
}


/* ── 결과창 별 ─────────────────────────────────────── */
.stars {
  font-size: 2.1rem;
  letter-spacing: .12em;
  color: var(--gold);
  background: none !important;
  padding: 0 !important;
  line-height: 1.1;
}

/* ── 홈 레벨 격자 ──────────────────────────────────── */
.lv-wrap {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
}
.lv-head {
  font-size: .78rem;
  font-weight: 700;
  color: #cdd5f5;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .7);
}
.lv-grid {
  /* position:relative 가 없으면 칩의 offsetParent 가 #home 이 되어
     "현재 레벨로 스크롤" 이 엉뚱한 값(=판 전체 위치)을 쓴다 — Lv.1 인데 51번이 보였다. */
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .3rem;
  flex: 1 1 auto;
  min-height: 4rem;
  overflow-y: auto;
  padding: .35rem;
  border-radius: .8rem;
  background: rgba(10, 15, 34, .62);
  box-shadow: inset 0 -1.2rem 1.2rem -1rem rgba(0, 0, 0, .55);
  scrollbar-width: thin;
}
.lv-chip {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .05rem;
  width: 100%;
  margin: 0 !important;
  padding: .3rem .1rem !important;
  border: 0;
  border-radius: .55rem !important;
  background: linear-gradient(180deg, #4a5482, #333c66) !important;
  color: #eef1ff !important;
  font: inherit;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18) !important;
}
.lv-chip b { font-size: .92rem; font-weight: 800; line-height: 1; }
.lv-chip i {
  font-style: normal;
  font-size: .5rem;
  letter-spacing: .04em;
  color: var(--gold);
  line-height: 1;
}
.lv-chip.cur {
  background: linear-gradient(180deg, #ffe066, var(--gold)) !important;
  color: #4a3200 !important;
}
.lv-chip.cur i { color: #6b4a00; }
.lv-chip.locked { opacity: .42; cursor: default; }
.lv-chip.locked i { color: #aab2d8; }

/* 시작 버튼은 격자 아래에 붙는다 */
.lv-wrap #tapToStart { margin-top: .1rem; padding: .7rem 1rem; font-size: 1.05rem; }


/* ── 실패 연출 (교훈 39) ────────────────────────────
   실패는 크게 보여 준다 — 광고가 실패 장면을 쓰는 이유와 같다.
   승리 시트와 색·글자 크기가 확실히 달라야 "졌다" 가 0.2초 안에 읽힌다. */
#result.lose .result-sheet {
  background: linear-gradient(180deg, #3a1620, #210d14);
  box-shadow: 0 0 0 2px rgba(255, 90, 90, .5), 0 1.4rem 2.4rem rgba(0, 0, 0, .55);
}
#result.lose #result-title {
  color: #ff6b6b;
  font-size: 1.9rem;
  letter-spacing: -.01em;
  text-shadow: 0 2px 12px rgba(255, 60, 60, .45);
}
#result.lose .stars { display: none; }
#result.lose .score-big { color: #ffb3b3; }
#result.lose #again {
  background: linear-gradient(180deg, #ff8787, #e03131);
  color: #fff;
  animation: again-pulse 1.1s ease-in-out infinite;
}
@keyframes again-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}
@media (prefers-reduced-motion: reduce) {
  #result.lose #again { animation: none; }
}

/* 홈의 주인공 차는 세로로 길다 — 레벨 격자가 자리를 먹으니 더 작게 */
.home-sheet #homeHero { width: 21%; max-width: 4.1rem; }
