/* 리듬 점프 — 아케이드 게임. 캔버스 1장 + 오버레이 구조.
   팔레트는 자산에서 뽑았다: 큐브 시안 #23cdea · 가시 마젠타 #f53bab · 배경 보라 #300f5f. */
:root {
  --bg: #170a2e;
  --pill: #e0d5f5;
  --pill-ink: #35204f;
  --ink: #f0eaff;
  --dim: #b09ccc;
  --accent: #23cdea;
  --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: **가로 게임**(640×360) 프레임. 폰 가로에선 화면 전체,
   데스크톱에선 가운데 뜬 16:9 가로 폰 모양(아래 미디어쿼리).
   오버레이는 전부 이 안에 `position:absolute` 로 갇힌다 — fixed 를 쓰면 프레임 밖으로 샌다. */
#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

main { position: absolute; inset: 0; }

/* 캔버스는 프레임을 꽉 채운다. 16:9 레터박스는 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: .7rem;
  background: rgba(6, 9, 22, .82);
}
.overlay[hidden] { display: none; }

/* ⚠️ 가로 무대는 높이가 360 뿐이다 — 세로판 치수(패딩 1.5rem, 제목 2.6rem, 점수 3.4rem)를
   그대로 두면 시트가 화면보다 커서 스크롤바가 생긴다. **넓게·낮게** 간다. */
.sheet {
  width: 100%;
  max-width: 22rem;
  max-height: 100%;
  overflow-y: auto;
  background: linear-gradient(180deg, #3a2160, #211036);
  border-radius: 1rem;
  padding: .8rem .9rem;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .12), 0 1rem 2rem rgba(0, 0, 0, .5);
}

.sheet h1 { font-size: 1.1rem; margin-bottom: .4rem; color: var(--ink); }
.sheet > div {
  background: rgba(0, 0, 0, .28);
  border-radius: .7rem;
  padding: .5rem;
}

.sheet button {
  width: 100%;
  padding: .5rem;
  font-size: .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 #0e93ad;
  margin-top: .35rem;
}

.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; max-width: 20rem; }
.result-sheet h1 { margin-bottom: .25rem; }

#result-stats {
  color: #fff;
  margin: .5rem 0;
  background: rgba(0, 0, 0, .3);
}
.score-big {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  text-shadow: 0 .2rem .8rem rgba(0, 0, 0, .5);
}
.score-big span { font-size: .9rem; margin-left: .15rem; color: var(--dim); }
.score-best {
  margin-top: .3rem;
  font-size: .8rem;
  font-weight: 700;
  color: var(--dim);
}

#result-why {
  margin-bottom: .5rem;
  color: var(--dim);
  font-size: .82rem;
  font-weight: 600;
}

/* 부활은 결과창의 주인공 버튼이다 — 노란 금빛으로 강조. */
.sheet button#revive {
  background: linear-gradient(180deg, #ffe066, var(--gold));
  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); }
}

/* ── 홈 (가로 2단) ─────────────────────────────────── */
.home-sheet {
  display: flex;
  flex-direction: row;
  gap: .8rem;
  /* stretch 로 두면 오른쪽 패널 상자가 시트 높이만큼 늘어나 위아래가 텅 빈다(데스크톱 캡처). */
  align-items: center;
  max-width: 32rem;
  height: 100%;
  background: none;
  box-shadow: none;
  padding: .5rem;
  overflow: visible;
}
.home-sheet > div { background: none; padding: 0; }
.home-left {
  flex: 1 1 46%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  text-align: center;
}
.home-right {
  flex: 1 1 54%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: .4rem;
  background: rgba(20, 8, 40, .7) !important;
  border-radius: .8rem;
  padding: .6rem !important;
}

.home-title {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: .02em;
  color: #fff;
  line-height: 1;
  margin: 0;
  text-shadow: 0 .18rem 0 #2b1048, 0 0 1.6rem rgba(35, 205, 234, .55);
  cursor: pointer;
}
.home-sheet h1.home-title { font-size: 1.8rem; margin-bottom: 0; }

#homeHero {
  /* vw 단위는 데스크톱 폰 프레임 안에서 깨진다 — 시트 폭 기준 % 로. */
  width: 44%;
  max-width: 6.5rem;
  height: auto;
  margin: .2rem 0;
  cursor: pointer;
  filter: drop-shadow(0 .5rem 1rem rgba(0, 0, 0, .55));
  animation: bob 2.6s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

#homeMain { width: 100%; }

#tapToStart {
  display: block;
  width: 100%;
  padding: .6rem .8rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe066, var(--gold));
  color: #4a3200;
  font: inherit;
  font-size: 1.05rem;
  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.2rem;
  height: 2.2rem;
  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: 118%; margin-top: 22%; }
.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: .4rem;
  width: 100%;
}

.home-sheet .tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .1rem;
  padding: .3rem .2rem;
  border: 0;
  border-radius: .6rem;
  background: rgba(45, 22, 74, .62);
  color: #dfe5ff;
  font: inherit;
  font-size: .72rem;
  font-weight: 700;
  cursor: pointer;
}
.home-sheet .tab-btn b { font-size: .95rem; 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: .74rem; max-height: 11rem; overflow-y: auto; }
.shop-row, .mission-row {
  display: flex;
  justify-content: space-between;
  gap: .4rem;
  padding: .3rem .5rem;
  margin-bottom: .2rem;
  border-radius: .45rem;
  background: rgba(45, 22, 74, .62);
}
.sheet .panel .back {
  width: 100%;
  margin-top: .3rem;
  padding: .4rem;
  font-size: .8rem;
  border: 0;
  border-radius: 999px;
  background: var(--gold);
  color: #4a3200;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

/* ── 데스크톱 = 가운데 뜬 **가로** 폰 프레임 ─────────────────
   무대가 16:9(640×360)라 프레임도 16:9 다 → 데스크톱에는 레터박스 띠가 없다.
   (폰 가로 19.5:9 에서만 좌우 띠가 생기고, 그건 app.js 가 배경·지면으로 잇는다.) */
@media (min-width: 768px) and (min-height: 600px) {
  body {
    background:
      radial-gradient(120% 90% at 50% 0%, #4b2a86 0%, #22103f 45%, #0b0517 100%);
    gap: 1rem;
  }
  #app {
    width: min(880px, calc(100vw - 64px), calc((100vh - 96px) * 640 / 360));
    height: auto;
    aspect-ratio: 640 / 360;
    border-radius: 28px;
    box-shadow: 0 0 0 10px #170f24, 0 0 0 12px #3d2a5c, 0 40px 90px rgba(0, 0, 0, .6);
  }
  #stage { border-radius: 28px; }
  #kbdHint {
    display: block;
    margin: 0;
    color: var(--dim);
    font-size: .85rem;
    font-weight: 600;
    letter-spacing: .01em;
  }
}

/* 가로 전용 — 폰을 세로로 들면 돌리라고 한다 */
#rotate { display: none; }
@media (orientation: portrait) and (max-width: 767px) {
  #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-city-wide.webp). url 은 CSS 파일 기준 ../ (pipes 함정). */
#home {
  background-image:
    linear-gradient(180deg, rgba(23, 10, 46, .35), rgba(11, 5, 23, .78)),
    url("../assets/bg-city-wide.webp");
  background-size: cover;
  background-position: center;
}

/* 큐브(=hero.webp)는 시안이라 ahome.js 의 hue-rotate(파랑 210° 기준)와 어긋난다.
   칩의 색은 원형 배경(--chip)이 내고, 큐브는 형태만 얹는다(B조 방식). */
.home-sheet .skin-chip img {
  filter: grayscale(1) contrast(1.15) brightness(1.3) !important;
  mix-blend-mode: luminosity;
  width: 74%;
  margin-top: 0;
}

/* 홈 — 레벨 표시와 무한 모드 */
#homeInfo {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: .1rem 0;
}
#homeLevel {
  padding: .25rem .7rem;
  border-radius: 999px;
  background: rgba(45, 22, 74, .7);
  color: var(--ink);
  font-size: .82rem;
  font-weight: 800;
}
#endlessBtn {
  padding: .25rem .7rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #8de9fb, var(--accent));
  color: #06303a;
  font: inherit;
  font-size: .78rem;
  font-weight: 800;
  cursor: pointer;
}
#endlessBtn[hidden] { display: none; }
