/* 포격 결투 — 아케이드 게임. 캔버스 1장 + 오버레이 구조. */
:root {
  --bg: #16102c;
  --pill: #f4e3c0;
  --pill-ink: #4a2c14;
  --ink: #fff3dd;
  --dim: #d3b995;
  --sand: #f1d9a6;
  --accent: #ff9a3c;
}

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

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  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;
  align-items: center;
  justify-content: center;
  background: #0c0716;
  background-image: radial-gradient(125% 85% at 50% 12%, #4a2447 0%, #23133a 42%, #0b0614 100%);
}

/* ARCADE-FIT: 가로 게임(640×360). 폰 가로에서는 화면 전체,
   데스크톱에서는 아래 미디어쿼리가 **가로 폰 프레임**으로 줄인다. */
#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

main { position: absolute; inset: 0; }

#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  /* 남는 위아래 띠는 app.js 가 하늘·땅으로 이어 칠한다(검은 띠 금지). */
}

.overlay {
  /* ⚠️ fixed 금지 — #app(폰 프레임) 밖으로 새어 나간다. */
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(10, 7, 20, .78);
}
.overlay[hidden] { display: none; }

/* ⚠️ 가로 무대는 높이가 360 뿐이다 — 세로판 치수(패딩 1.5rem, 제목 2.6rem)를 그대로 두면
   결과 시트가 화면보다 커서 스크롤바가 생긴다. 넓게·낮게 잡는다. */
.sheet {
  width: 100%;
  max-width: 26rem;
  max-height: 100%;
  overflow-y: auto;
  background: linear-gradient(180deg, #3a2b52, #241a3c);
  border-radius: 1.2rem;
  padding: 1.1rem 1.3rem;
  box-shadow: inset 0 2px 0 rgba(255, 235, 200, .16), 0 1rem 2rem rgba(0, 0, 0, .55);
}

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

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

.sheet button.ghost {
  background: linear-gradient(180deg, #b8f5c4, #4fd47a);
  color: #10391f;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .8), inset 0 -3px 0 #2ea253;
  animation: revivePulse 1.1s ease-in-out infinite;
}
.sheet button.ghost[hidden] { display: none; }

@keyframes revivePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

/* ── 결과창 ─────────────────────────────────────────────── */
.result-sheet { text-align: center; }
.result-sheet h1 {
  font-size: 2rem;
  line-height: 1.05;
  margin-bottom: .4rem;
  color: #ffe6b0;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .35);
}

#result-stats {
  background: rgba(0, 0, 0, .3);
  border-radius: .9rem;
  padding: .55rem;
  margin: .6rem 0;
}
.res-hp {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
  color: #fff;
}
.res-cap {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--dim);
  margin-top: .2rem;
}

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

/* ── 홈 ─────────────────────────────────────────────────── */
#home {
  /* 힉스필드 배경(assets/bg.webp — 노을 하늘). url 은 CSS 파일 기준 ../ (pipes 함정). */
  background-image:
    linear-gradient(180deg, rgba(20, 10, 40, .10) 0%, rgba(20, 10, 40, .30) 55%, rgba(40, 16, 20, .55) 100%),
    url("../assets/bg.webp");
  background-size: cover;
  /* bg.webp(720×1280 세로)의 **위쪽**이 노을 분홍이다. 가운데(34%)로 내려 봤더니
     한밤 남색이 나와 홈이 침침했다 — 홈은 위를 쓴다.
     (게임 캔버스는 반대로 가운데 띠를 쓴다. 거긴 하늘 위·지평선 아래가 다 필요하다.) */
  background-position: center top;
  overflow: hidden;
}

/* 지평선 모래 언덕 — 전차가 허공에 뜨지 않게 바닥을 깐다.
   가로에서는 화면이 낮아 30% 면 언덕이 화면을 반 잡아먹는다. */
.home-dune {
  position: absolute;
  left: -6%;
  right: -6%;
  bottom: 0;
  height: 26%;
  border-radius: 50% 50% 0 0 / 40% 40% 0 0;
  background: linear-gradient(180deg, #f1d9a6 0%, #dfae72 22%, #b3743c 60%, #6b3f22 100%);
  box-shadow: inset 0 3px 0 rgba(255, 250, 230, .65);
}

/* 가로 홈: 두 전차가 좌우 끝에서 마주보고, 가운데 열(제목·시작·탭)은 비워 둔다.
   폭 26% 라 760px 프레임에서 양쪽 396px 을 쓰고 가운데 360px 이 남는다 — 시트(304px)가 들어간다. */
.home-tank {
  position: absolute;
  bottom: 7%;
  width: 26%;
  max-width: 11rem;
  z-index: 1;
  filter: drop-shadow(0 .7rem .5rem rgba(60, 25, 10, .5));
  pointer-events: none;
}
.home-tank.left { left: 1%; }
.home-tank.right { right: 1%; }

.home-sheet {
  /* 아래쪽 전차 구도를 비워 두고 글씨는 위쪽 1/3 에 앉힌다.
     ⚠️ vh 로 밀면 폰 프레임(#app)이 아니라 브라우저 창 기준이 된다 — 프레임 기준 % 로 앉힌다. */
  position: absolute;
  top: 7%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: .8rem;
  align-items: center;
  text-align: center;
  width: 100%;
  /* 좌우 전차(각 11rem) 사이에 남는 폭. 760px 프레임에서 24.5rem 이 비므로 23rem 까지 안전하다. */
  max-width: 23rem;
  background: none;
  box-shadow: none;
  overflow: visible;
  padding: 0;
}

#homeTitle {
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: -.02em;
  color: #ffe9bd;
  text-shadow: 0 2px 0 #8a3c14, 0 4px 0 #5c2409, 0 .7rem 1.2rem rgba(0, 0, 0, .55);
  margin: 0;
}

.carousel {
  display: flex;
  gap: .45rem;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 22rem; /* 가로에선 폭이 남는다 — 스킨 칩을 한 줄로 편다 */
}
.skin-chip {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  display: inline-block;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .28), 0 0 0 2px rgba(255, 240, 210, .35);
}
.skin-chip.on { box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .28), 0 0 0 3px #ffe9bd; }

#homeMain { width: 100%; }

#tapToStart {
  font-size: 1.7rem;
  font-weight: 900;
  color: #fff4dc;
  text-shadow: 0 2px 0 rgba(120, 50, 12, .8), 0 .5rem 1rem rgba(0, 0, 0, .5);
  margin: 1.1rem 0 .3rem;
  cursor: pointer;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: .62; transform: scale(.985); }
  50% { opacity: 1; transform: scale(1.045); }
}

#homeTabs {
  display: flex;
  gap: .5rem;
  width: 100%;
  position: absolute;
  left: 0;
  top: 100%;
  margin-top: .4rem;
}

.tab-btn {
  flex: 1;
  padding: .65rem;
  border: 0;
  border-radius: .8rem;
  background: rgba(24, 12, 30, .55);
  color: var(--sand);
  font: inherit;
  font-size: .88rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, .25);
}
.tab-btn.active, .tab-btn:active {
  background: var(--accent);
  color: #3b1d06;
}

.panel { display: grid; gap: .4rem; }
.shop-row, .mission-row {
  display: flex;
  justify-content: space-between;
  background: rgba(24, 12, 30, .6);
  border-radius: .7rem;
  padding: .6rem .8rem;
  font-size: .9rem;
  color: var(--sand);
}
.panel .back {
  margin-top: .6rem;
  padding: .8rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd08a, var(--accent));
  color: #3b1d06;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

/* ── 데스크톱 = 가로 폰 프레임 ──────────────────────────────
   무대가 16:9(640×360)라 프레임도 16:9 다 → 데스크톱에는 레터박스 띠가 없다.
   (폰 가로 19.5:9 에서만 좌우 띠가 생기고, 그건 app.js 가 하늘·땅으로 잇는다.) */
#deskHint { display: none; }

@media (min-width: 768px) and (min-height: 600px) {
  #app {
    width: min(760px, calc(100vw - 64px), calc((100vh - 96px) * 640 / 360));
    height: auto;
    aspect-ratio: 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; }
  #deskHint {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 26px;
    text-align: center;
    font-size: .82rem;
    font-weight: 700;
    letter-spacing: .01em;
    color: rgba(255, 232, 200, .55);
  }
}

/* 가로 전용 — 폰을 세로로 들면 안내를 띄운다(2026-09-07 세로→가로 전환으로 조건이 뒤집혔다).
   max-width 로 폰만 걸러야 한다. 안 걸면 좁고 높은 데스크톱 창에서도 안내가 뜬다. */
#rotate { display: none; }
@media (orientation: portrait) and (max-width: 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: var(--dim);
    font-size: 1.05rem;
    line-height: 1.6;
  }
}

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