/* 벽돌 폭풍 — 캔버스 1장 + 오버레이. 레트로 CRT 색: 남색 #080b16 / 청록 #35e0ff / 금 #ffc531.
   자산 그림이 없는 게임이라 홈 배경도 **CSS 로 그린 벽돌**이다(그라디언트 격자 + 발광). */
:root {
  --bg: #080b16;
  --panel: #141b2e;
  --ink: #eaf1ff;
  --dim: #8d9bbb;
  --accent: #35e0ff;
  --accent2: #ff4d80;
  --gold: #ffc531;
}

* { 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.4rem;
  background: rgba(4, 7, 14, .86);
}
.overlay[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 22rem;
  max-height: 100%;
  overflow-y: auto;
  background: linear-gradient(180deg, #1d2740, #101728);
  border-radius: 1.4rem;
  padding: 1.5rem 1.3rem;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .1), 0 1rem 2rem rgba(0, 0, 0, .6);
}

.sheet h1 { font-size: 1.15rem; margin-bottom: 1rem; color: var(--ink); }
.sheet > div {
  background: rgba(0, 0, 0, .3);
  border-radius: .9rem;
  padding: .6rem;
}

.sheet button {
  width: 100%;
  padding: .95rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #7ceeff, var(--accent));
  color: #04222b;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .6), inset 0 -3px 0 #159cba;
  margin-top: .6rem;
}

.sheet button.ghost {
  background: linear-gradient(180deg, #e7eef6, #c6d2de);
  color: #22303c;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .9), inset 0 -3px 0 #96a5b3;
}
.sheet button.ghost[hidden] { display: none; }

/* ── 결과창 ───────────────────────────────────────── */
.result-sheet { text-align: center; }
.result-sheet h1 { margin-bottom: .35rem; font-size: 2.1rem; letter-spacing: .02em; }

/* 교훈 39 — **실패도 연출이다.** 붉은 DEFEAT 를 크게 + 한 번 흔든다. */
#result-title.defeat {
  color: #ff5470;
  text-shadow: 0 .16rem 0 #46091a, 0 0 1.6rem rgba(255, 60, 100, .55);
  animation: defeatShake .5s ease-out 1;
}
#result-title.clear {
  color: var(--gold);
  text-shadow: 0 .16rem 0 #4a3200, 0 0 1.6rem rgba(255, 197, 49, .55);
  animation: clearPop .5s ease-out 1;
}
@keyframes defeatShake {
  0%, 100% { transform: translateX(0) scale(1); }
  12% { transform: translateX(-9px) scale(1.1); }
  28% { transform: translateX(8px) scale(1.08); }
  46% { transform: translateX(-6px) scale(1.04); }
  66% { transform: translateX(4px) scale(1.02); }
}
@keyframes clearPop {
  0% { transform: scale(.6); opacity: 0; }
  60% { transform: scale(1.14); opacity: 1; }
  100% { transform: scale(1); }
}

#result-stats {
  color: #fff;
  margin: .9rem 0;
  background: rgba(0, 0, 0, .32);
}
.score-big {
  font-size: 3.2rem;
  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);
}
/* 파괴율 막대 — 결과창에서 "얼마나 무너뜨렸나" 가 한눈에 보이게 */
.bar {
  position: relative;
  height: .7rem;
  margin: .5rem .2rem .1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, .12);
  overflow: hidden;
}
.bar i {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
}

#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: 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, .4);
  animation: gold 1.8s ease-in-out infinite;
}
@keyframes gold {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

/* ── 홈 ───────────────────────────────────────────── */
.home-sheet {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  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-sheet > div { background: none; padding: 0; }

.home-title {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: .04em;
  color: #fff;
  line-height: 1;
  margin: 0;
  text-shadow: 0 .18rem 0 #071018, 0 0 1.4rem rgba(53, 224, 255, .55), 0 .5rem 1.4rem rgba(0, 0, 0, .7);
  cursor: pointer;
}
.home-sheet h1.home-title { font-size: 2.5rem; margin-bottom: 0; }

/* 주인공은 공. vw 는 데스크톱 폰 프레임 안에서 깨지니 % 로. */
#homeHero {
  width: 30%;
  max-width: 6.6rem;
  height: auto;
  margin: .3rem 0 0;
  cursor: pointer;
  filter: drop-shadow(0 .8rem 1.4rem rgba(0, 0, 0, .6));
  animation: bob 2.2s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-11px); }
}

#homeMain { width: 100%; }

#tapToStart {
  display: block;
  width: 100%;
  padding: .95rem 1rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #7ceeff, var(--accent));
  color: #04222b;
  font: inherit;
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .7), inset 0 -4px 0 #159cba,
    0 .4rem 1.2rem rgba(53, 224, 255, .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, .22);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 30%, 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: 92%;
  margin: 0;
  mix-blend-mode: multiply;
  filter: none !important;   /* ahome.js 의 hue-rotate 는 안 쓴다 — 칩 배경색이 곧 스킨 색이다 */
}
.home-sheet .skin-chip.on { border-color: #fff; box-shadow: 0 0 0 3px rgba(53, 224, 255, .8); }
.home-sheet .skin-chip.locked { opacity: .35; }

#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, 27, 46, .75);
  color: #dbe6f0;
  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(--accent); color: #04222b; }

.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, 27, 46, .75);
}
.sheet .panel .back {
  width: 100%;
  margin-top: .5rem;
  padding: .7rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #04222b;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

/* 홈 배경 — **캔버스가 뒤에서 다음 판의 그림을 실제로 그린다**(app.js drawIdle).
   그래서 오버레이는 위가 비치고 아래만 어두워지는 그라디언트다. */
#home {
  background: linear-gradient(180deg,
    rgba(6, 10, 20, .12) 0%,
    rgba(6, 10, 20, .34) 34%,
    rgba(5, 8, 16, .82) 62%,
    rgba(4, 6, 12, .96) 100%);
}

/* ── 결과 시트의 업그레이드 4칸 ─────────────────────── */
.result-sheet .wallet {
  margin: 0 0 .5rem;
  padding: .35rem;
  font-size: .9rem;
  color: var(--dim);
  background: rgba(0, 0, 0, .28);
  border-radius: .6rem;
}
.result-sheet .wallet b { color: var(--gold); font-size: 1.05rem; }

.upg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .4rem;
  background: none !important;
  padding: 0 !important;
}
.sheet .upg-grid .upg {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  width: 100%;
  margin: 0;
  padding: .5rem .35rem;
  border-radius: .8rem;
  background: linear-gradient(180deg, #ffe9a8, #ffc24d);
  color: #43310a;
  font: inherit;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .7), inset 0 -3px 0 #c98a00;
}
.sheet .upg-grid .upg.off {
  background: linear-gradient(180deg, #37415e, #262f47);
  color: rgba(226, 236, 245, .55);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .08);
}
.upg-grid .upg b { font-size: .88rem; font-weight: 800; }
.upg-grid .upg b i { font-style: normal; opacity: .65; font-size: .78rem; }
.upg-grid .upg em { font-style: normal; font-size: .74rem; font-weight: 700; opacity: .8; }
.upg-grid .upg span { font-size: .8rem; font-weight: 800; }

/* ── 데스크톱 = 가운데 뜬 폰 프레임 ─────────────────── */
@media (min-width: 768px) and (min-height: 600px) {
  body {
    background: radial-gradient(120% 90% at 50% 0%, #1d3350 0%, #0e1526 45%, #04060c 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 #0c1220, 0 0 0 12px #26314c, 0 40px 90px rgba(0, 0, 0, .7);
  }
  #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; }
}
