/* 블록 탈출 — 캔버스 1장 + 오버레이 구조. */
:root {
  --bg: #171a33;
  --pill: #d5dcf5;
  --pill-ink: #2a3050;
  --ink: #e9ecff;
  --dim: #a0a7cf;
  --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; }

#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.2rem;
  background: rgba(10, 12, 28, .84);
}
.overlay[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 22rem;
  max-height: 100%;
  overflow-y: auto;
  background: linear-gradient(180deg, #2d3560, #1c2242);
  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, .5);
}

.sheet h1 { font-size: 1.35rem; margin-bottom: .6rem; color: var(--ink); }

.sheet button {
  width: 100%;
  padding: .9rem;
  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: .5rem;
}
.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-stars {
  font-size: 2.5rem;
  line-height: 1.1;
  letter-spacing: .1em;
  color: #ffd43b;
  text-shadow: 0 .2rem .9rem rgba(255, 184, 0, .45);
  animation: punch .5s cubic-bezier(.2, 1.6, .4, 1);
}
/* 교훈 39 — 못 낸 별도 연출한다. 1별은 흔들려서 "아쉽다" 가 느껴지게. */
#result-stars.s1 { color: #ffb0b0; text-shadow: none; animation: nope .5s ease; }
@keyframes punch { 0% { transform: scale(.5); opacity: 0; } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes nope { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-9px); } 45% { transform: translateX(8px); } 70% { transform: translateX(-4px); } }

#result-stats {
  color: #fff;
  margin: .7rem 0 .3rem;
  background: rgba(0, 0, 0, .28);
  border-radius: .9rem;
  padding: .6rem;
}
.score-big { font-size: 2.9rem; font-weight: 800; line-height: 1; color: #fff; }
.score-big span { font-size: 1rem; margin-left: .2rem; color: var(--dim); }
.score-best { margin-top: .3rem; font-size: .82rem; font-weight: 700; color: var(--dim); }

#result-why {
  margin: .4rem 0 .9rem;
  color: var(--dim);
  font-size: .88rem;
  font-weight: 600;
}

.sheet button#revive {
  background: linear-gradient(180deg, #ffe066, var(--gold));
  color: #4a3200;
  font-size: 1.02rem;
  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: .45rem;
  align-items: center;
  justify-content: center;
  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: .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.5rem; margin-bottom: 0; }

#homeHero {
  /* vw 단위는 데스크톱 폰 프레임 안에서 깨진다 — 시트 폭 기준 % 로. */
  width: 54%;
  max-width: 12rem;
  height: auto;
  margin: .1rem 0 .1rem;
  cursor: pointer;
  filter: drop-shadow(0 .7rem 1.2rem rgba(0, 0, 0, .5));
  animation: bob 2.8s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-9px) rotate(2deg); }
}

#homeMain { width: 100%; }

/* 레벨 격자 — 5칸 4줄. 잠긴 판은 자물쇠. */
#levelGrid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .35rem;
  width: 100%;
  margin-bottom: .6rem;
}
#levelGrid .lv {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: .7rem;
  background: rgba(28, 36, 70, .8);
  color: #dfe5ff;
  font: inherit;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .3);
}
#levelGrid .lv b { font-size: .95rem; font-weight: 800; }
#levelGrid .lv i { font-size: .5rem; font-style: normal; color: var(--gold); line-height: 1; }
#levelGrid .lv.now { background: linear-gradient(180deg, #6d7dff, #4453c9); color: #fff; }
#levelGrid .lv.locked { opacity: .42; cursor: default; }

#tapToStart {
  display: block;
  width: 100%;
  padding: .9rem 1rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe066, var(--gold));
  color: #4a3200;
  font: inherit;
  font-size: 1.2rem;
  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.04); } }

.carousel {
  display: flex;
  gap: .4rem;
  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.7rem;
  height: 2.7rem;
  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;
}
.home-sheet .skin-chip img { width: 108%; }
.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: .2rem; }

.home-sheet .tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
  padding: .45rem .3rem;
  border: 0;
  border-radius: .9rem;
  background: rgba(22, 30, 60, .7);
  color: #dfe5ff;
  font: inherit;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
}
.home-sheet .tab-btn b { font-size: 1.1rem; 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(22, 30, 60, .7);
}
.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%, #3b4488 0%, #1a2044 45%, #0a0d1c 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;
  }
}

/* 세로 전용 */
#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/bg-tray.webp) 를 어둡게 깔았다. url 은 CSS 파일 기준 ../ (pipes 함정). */
#home {
  background-image:
    linear-gradient(180deg, rgba(14, 18, 42, .82), rgba(9, 12, 30, .92)),
    url("../assets/bg-tray.webp");
  background-size: cover;
  background-position: center;
}
