/* 구슬 튕기기 — 아케이드 **세로** 게임(360×640, 9:16). 캔버스 1장 + 오버레이 구조.
   색은 블루프린트 7절: 하늘 #9ED8FF · 나무 #A0522D.
   ⚠️ `vw/vh` 는 데스크톱 폰 프레임 안에서 깨진다(프레임이 화면보다 작다). 시트에는 %/rem 만. */
:root {
  --bg: #9ed8ff;
  --deep: #2c4a6b;
  --ink: #17324a;
  --paper: #fff6e6;
  --dim: #7c93a8;
  --wood: #a0522d;
  --wood-dark: #6d3618;
  --gold: #ffb800;
  --grass: #6cbf4b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0f2033;
  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: 세로 게임 프레임. 폰에선 화면 전체, 데스크톱에선 가운데 뜬 9:16 폰 프레임.
   오버레이는 전부 이 안에 `position:absolute` 로 갇힌다 — fixed 를 쓰면 프레임 밖으로 샌다. */
#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

main { position: absolute; inset: 0; }

/* 캔버스는 프레임을 꽉 채운다. 레터박스는 app.js 의 resizeCanvas 가 setTransform 으로
   가운데 정렬해 만들고, 남는 띠는 배경을 이어 그린다(검은 띠 금지). */
#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: 1rem;
  background: rgba(10, 26, 42, .72);
}
.overlay[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 22rem;
  max-height: 100%;
  overflow-y: auto;
  background: linear-gradient(180deg, #fffaf0, #ffe9c9);
  border-radius: 1.3rem;
  padding: 1.1rem 1.2rem;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .9), 0 1rem 2rem rgba(0, 0, 0, .5);
}

.sheet h1 { font-size: 1.35rem; margin-bottom: .8rem; color: var(--ink); }
.sheet > div {
  background: rgba(160, 82, 45, .12);
  border-radius: .9rem;
  padding: .6rem;
}

.sheet button {
  width: 100%;
  padding: .7rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #c9e9ff, #6fb6e8);
  color: #10304a;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .85), inset 0 -3px 0 #3d84b8;
  margin-top: .45rem;
}

.sheet button.ghost {
  background: linear-gradient(180deg, #fff3dd, #f0dcbd);
  color: #6d4a22;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .9), inset 0 -3px 0 #c9ab84;
}
.sheet button[hidden] { display: none; }

/* ── 결과창 ───────────────────────────────────────── */
.result-sheet { text-align: center; }
.result-sheet h1 { margin-bottom: .25rem; font-size: 1.4rem; }

#result-stats {
  color: var(--ink);
  margin: .55rem 0;
  background: rgba(160, 82, 45, .12);
}

/* 별 세 개 — 남은 구슬 수가 곧 별이다. */
.stars { display: flex; justify-content: center; gap: .35rem; }
.stars i {
  width: 2.6rem;
  height: 2.6rem;
  font-style: normal;
  font-size: 2.2rem;
  line-height: 2.6rem;
  color: #d9c6a8;
  text-shadow: 0 .1rem 0 rgba(0, 0, 0, .12);
}
.stars i.on {
  color: var(--gold);
  text-shadow: 0 .12rem 0 #c98a00, 0 0 1.1rem rgba(255, 184, 0, .75);
  animation: pop .45s cubic-bezier(.2, 1.6, .5, 1) backwards;
}
.stars i.on:nth-child(2) { animation-delay: .12s; }
.stars i.on:nth-child(3) { animation-delay: .24s; }
@keyframes pop { from { transform: scale(0) rotate(-40deg); } to { transform: scale(1); } }

.res-row { display: flex; justify-content: space-around; margin-top: .55rem; font-size: .85rem; color: #6d4a22; }
.res-row b { display: block; font-size: 1.2rem; color: var(--ink); }

#result-why {
  margin-bottom: .55rem;
  color: #7a5c38;
  font-size: .92rem;
  font-weight: 600;
}

/* 리워드와 "다음 판"이 결과창의 주인공 버튼이다 — 금빛으로 강조. */
.sheet button#revive, .sheet button#next {
  background: linear-gradient(180deg, #ffe066, var(--gold));
  color: #4a3200;
  font-size: 1rem;
  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 { background: none; padding: 0; }
.home-sky {
  position: absolute;
  inset: 0;
  background: #9ed8ff url("../assets/bg-meadow.webp") center 45% / cover no-repeat;
}
/* 위쪽 낙하 레일 — 게임 화면의 "여기서 놓는다" 띠와 같은 자리에 둔다.
   ⚠️ 예전엔 대포 그림(launcher.webp)이 있었다. 대포를 없앤 뒤(2026-09-10) 홈에도
      같은 조작을 보여 준다 — 레일 위에서 구슬이 좌우로 떠 있다가 떨어지는 그림. */
.home-rail {
  position: absolute;
  left: 12%;
  right: 12%;
  top: 12%;
  height: .5rem;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 255, 255, .15), rgba(255, 255, 255, .8), rgba(255, 255, 255, .15));
  box-shadow: 0 .2rem .6rem rgba(0, 0, 0, .35);
}
/* 부유하는 구슬 — 레일 아래에서 천천히 떠다닌다. 탭하면 시작(ahome 이 연결한다). */
.home-marble {
  position: absolute;
  left: 50%;
  top: 22%;
  height: 11%;
  width: auto;
  cursor: pointer;
  transform: translateX(-50%);
  filter: drop-shadow(0 .6rem 1rem rgba(0, 0, 0, .38));
  animation: bob 2.8s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateX(-50%) translateY(0) rotate(-10deg); }
  50% { transform: translateX(-50%) translateY(-12px) rotate(12deg); }
}
/* 못 밭 — 홈에서도 이 게임이 뭔지 한눈에 보이게.
   ⚠️ peg-wood.webp 를 타일로 깔아 봤더니 CSS 는 **타일 간격 = background-size** 라
      원판이 서로 딱 붙어 나무 벽이 됐다(캡처에서 잡았다). 스프라이트에 여백이 없으면
      간격을 못 준다 — 그래서 간격이 자유로운 radial-gradient 로 원판을 그린다
      (위쪽 하이라이트 + 테두리로 게임 안의 못과 같은 인상을 낸다). */
.home-pegs {
  position: absolute;
  left: 0; right: 0;
  top: 33%;
  height: 24%;
  background-image: radial-gradient(circle at 50% 38%,
    #f4d3a6 0 20%, #e0ab6e 21% 33%, #b8813f 34% 39%, rgba(0, 0, 0, 0) 40%);
  background-size: 56px 56px;
  background-position: 16px 4px;
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .3));
  -webkit-mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0), #000 16%, #000 72%, rgba(0, 0, 0, 0));
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0), #000 16%, #000 72%, rgba(0, 0, 0, 0));
}

.home-sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  align-items: center;
  text-align: center;
  max-width: none;
  background: linear-gradient(180deg, rgba(10, 26, 42, 0), rgba(10, 26, 42, .55) 22%, rgba(10, 26, 42, .78));
  box-shadow: none;
  border-radius: 0;
  padding: 1.6rem 1rem 1.1rem;
  overflow: visible;
}
.home-sheet > div { background: none; padding: 0; }

.home-title {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: .01em;
  color: #fff;
  line-height: 1;
  margin: 0;
  text-shadow:
    0 .18rem 0 var(--wood-dark), 0 .32rem 0 rgba(109, 54, 24, .55),
    0 .6rem 1.4rem rgba(0, 0, 0, .45);
  cursor: pointer;
}
.home-sheet h1.home-title { font-size: 2.5rem; margin-bottom: 0; }

.home-level {
  margin: 0;
  padding: .25rem 1rem;
  border-radius: 999px;
  background: rgba(23, 50, 74, .55);
  color: #fff6e6;
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: .02em;
}

#homeMain { width: 100%; max-width: 20rem; }

#tapToStart {
  display: block;
  width: 100%;
  padding: .8rem 1rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe066, var(--gold));
  color: #4a3200;
  font: inherit;
  font-size: 1.15rem;
  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;
  flex-wrap: wrap;
  justify-content: center;
  gap: .35rem;
  width: 100%;
  max-width: 20rem;
  padding: .1rem;
}

.home-sheet .skin-chip {
  flex: 0 0 auto;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, .55);
  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;
  box-shadow: 0 .2rem .5rem rgba(0, 0, 0, .25);
}
/* ⚠️ ahome.js(_shared 사본, 수정 금지)는 hero.webp 를 파랑(210°) 기준으로 hue-rotate 한다.
   그래서 assets/hero.webp 는 marble-blue(파란 유리구슬) 사본이다. */
.home-sheet .skin-chip img { width: 104%; }
.home-sheet .skin-chip.on { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 224, 102, .85); }
.home-sheet .skin-chip.locked { opacity: .4; }

#homeTabs {
  display: flex;
  gap: .45rem;
  width: 100%;
  max-width: 20rem;
}

.home-sheet .tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .12rem;
  padding: .45rem .3rem;
  border: 0;
  border-radius: .85rem;
  background: rgba(255, 250, 240, .86);
  color: #6d4a22;
  font: inherit;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 .2rem .5rem rgba(0, 0, 0, .18);
}
.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: .84rem; }
.shop-row, .mission-row {
  display: flex;
  justify-content: space-between;
  padding: .4rem .6rem;
  margin-bottom: .25rem;
  border-radius: .5rem;
  background: rgba(255, 250, 240, .92);
  box-shadow: 0 .15rem .4rem rgba(0, 0, 0, .15);
}
.sheet .panel .back {
  width: 100%;
  margin-top: .4rem;
  padding: .55rem;
  border: 0;
  border-radius: 999px;
  background: var(--gold);
  color: #4a3200;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

/* ── 데스크톱 = 가운데 뜬 **세로** 폰 프레임 ───────────
   무대가 9:16(360×640)이라 프레임도 9:16 다 → 데스크톱에는 레터박스 띠가 없다.
   (폰 9:19.5 에서만 위아래 띠가 생기고, 그건 app.js 가 배경으로 잇는다.) */
@media (min-width: 768px) and (min-height: 600px) {
  body {
    background: radial-gradient(120% 90% at 50% 0%, #2f5f8c 0%, #16304a 45%, #071018 100%);
    gap: 1rem;
  }
  #app {
    width: min(420px, calc(100vw - 64px), calc((100vh - 110px) * 360 / 640));
    height: auto;
    aspect-ratio: 360 / 640;
    border-radius: 32px;
    box-shadow: 0 0 0 10px #14202c, 0 0 0 12px #2c4a6b, 0 40px 90px rgba(0, 0, 0, .6);
  }
  #stage, #home { border-radius: 32px; overflow: hidden; }
  #deskHint {
    display: block;
    margin: 0;
    color: #9fc0d8;
    font-size: .82rem;
    font-weight: 600;
    letter-spacing: .01em;
    text-align: center;
  }
}

/* 세로 전용 — 폰을 가로로 눕히면 안내를 띄운다. max-height 로 폰만 걸러야 한다.
   안 걸면 넓고 낮은 데스크톱 창에서도 안내가 뜬다. */
#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: #9fc0d8;
    font-size: 1.05rem;
    line-height: 1.6;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
