/* 배달 가게 — 아이들 아케이드. 캔버스 1장 + 오버레이 구조.
   퍼즐군(어두운 남색)과 문법을 다르게: 크림 바탕 · 토마토 강조의 밝은 매장 톤. */
:root {
  --bg: #FFF4E0;
  --ink: #4a3524;
  --dim: #9c8467;
  --accent: #E76F51;
  --accent-dark: #b8452b;
  --gold: #F4A259;
  --card: #fffaf0;
}

* { 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;
  background: var(--bg);
}

main { position: absolute; inset: 0; }

/* 캔버스는 프레임을 꽉 채운다. 레터박스는 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: 1.4rem;
  background: rgba(72, 48, 28, .55);
}
.overlay[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 22rem;
  max-height: 100%;
  overflow-y: auto;
  background: linear-gradient(180deg, #fffdf7, var(--card));
  border-radius: 1.4rem;
  padding: 1.5rem 1.3rem;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .9), 0 1rem 2rem rgba(90, 55, 25, .35);
}

.sheet h1 { font-size: 1.2rem; margin-bottom: 1rem; color: var(--ink); }
.sheet > div {
  background: rgba(231, 111, 81, .1);
  border-radius: .9rem;
  padding: .6rem;
}

.sheet button {
  width: 100%;
  padding: .95rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff9a7a, var(--accent));
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .5), inset 0 -3px 0 var(--accent-dark);
  margin-top: .6rem;
}

.sheet button.ghost {
  background: linear-gradient(180deg, #ffd9a0, var(--gold));
  color: #5a3a12;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .8), inset 0 -3px 0 #cf7c33;
  animation: gold 1.8s ease-in-out infinite;
}
.sheet button.ghost[hidden] { display: none; }
@keyframes gold {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

/* ── 오프라인 수입 시트 ────────────────────────────── */
.result-sheet { text-align: center; }
.result-sheet h1 { margin-bottom: .35rem; }

#offline-stats {
  color: var(--ink);
  margin: .9rem 0;
  display: flex;
  justify-content: center;
  gap: 1.2rem;
}
#offline-stats .stat { background: none; padding: 0; }
#offline-stats .stat b {
  display: block;
  font-size: 2rem;
  line-height: 1.05;
  color: var(--accent-dark);
}
#offline-stats .stat span { font-size: .8rem; color: var(--dim); }

#offline-why {
  margin-bottom: .9rem;
  color: var(--dim);
  font-size: .88rem;
  font-weight: 600;
}

/* ── 마감 결산 시트 ────────────────────────────────── */
/* ⚠️ 가로 폰은 높이가 390px 뿐이다. 오프라인 시트 크기 그대로 뒀더니 "다음 날 →" 버튼이
   화면 밖으로 밀려 **첫 화면에서 안 보였다**(캡처 13 을 눈으로 보고 고쳤다). 전부 한 단씩 줄인다. */
#dayend .sheet { padding: .9rem 1.1rem; }
#dayend h1 { font-size: 1.05rem; margin-bottom: .2rem; }
#dayend button { padding: .62rem; margin-top: .38rem; font-size: .92rem; }

#dayend-stats {
  color: var(--ink);
  margin: .45rem 0;
  display: flex;
  justify-content: center;
  gap: 1rem;
  background: none;
  padding: 0;
}
#dayend-stats .stat { background: none; padding: 0; }
#dayend-stats .stat b {
  display: block;
  font-size: 1.3rem;
  line-height: 1.05;
  color: var(--accent-dark);
}
#dayend-stats .stat span { font-size: .74rem; color: var(--dim); }
#dayend-stats .stat.bad b { color: #c0392b; }

/* 별 셋 — 못 받은 별은 회색으로 **자리를 남긴다**(무엇을 놓쳤는지 보여야 한다). */
.stars {
  background: none !important;
  padding: 0 !important;
  display: flex;
  justify-content: center;
  gap: .5rem;
  font-size: 1.7rem;
  line-height: 1;
  margin: .1rem 0 0;
}
.stars i { font-style: normal; filter: grayscale(1) opacity(.32); }
.stars i.on { filter: none; animation: starpop .5s cubic-bezier(.2, 1.5, .5, 1) backwards; }
.stars i.on:nth-child(2) { animation-delay: .12s; }
.stars i.on:nth-child(3) { animation-delay: .24s; }
@keyframes starpop {
  0% { transform: scale(0.1) rotate(-40deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.goals {
  background: rgba(231, 111, 81, .1);
  border-radius: .8rem;
  padding: .4rem .6rem !important;
  font-size: .74rem;
  font-weight: 700;
  color: var(--dim);
  text-align: left;
}
.goals div { display: flex; justify-content: space-between; padding: .12rem 0; }
.goals div.on { color: var(--accent-dark); }
.goals div.on::before { content: '✓ '; }
.goals div::before { content: '· '; }

#dayend-coin {
  margin: .38rem 0 .1rem;
  font-weight: 800;
  color: #a2600f;
  font-size: .84rem;
  line-height: 1.25;
}

.coin-chip {
  position: absolute;
  top: .55rem;
  right: .7rem;
  background: rgba(255, 250, 240, .92);
  color: #a2600f;
  font-weight: 800;
  font-size: .82rem;
  border-radius: 999px;
  padding: .22rem .6rem;
  box-shadow: 0 2px 6px rgba(90, 55, 25, .2);
  z-index: 2;
}
.coin-chip.warn { background: #ffe0d4; color: #b8452b; }
.mission-row.done { color: var(--accent-dark); }
.mission-row.done::after { content: ' ✓'; }

/* ── 홈 ───────────────────────────────────────────── */
/* 가로 홈: 점원 그림이 왼쪽에 서고, 글씨·버튼은 오른쪽 열에 앉는다.
   ⚠️ vh 로 밀면 폰 프레임(#app)이 아니라 브라우저 창 기준이 된다 — 프레임 기준 %/rem 으로. */
.home-sheet {
  display: grid;
  grid-template-columns: minmax(0, 10.5rem) minmax(0, 1fr);
  grid-template-areas:
    "hero title"
    "hero main"
    "hero carousel"
    "hero tabs";
  align-items: center;
  align-content: center;
  gap: .35rem .9rem;
  text-align: center;
  max-width: 34rem;
  height: 100%;
  background: none;
  box-shadow: none;
  padding: .7rem .8rem;
  overflow: visible;
}
.home-title { grid-area: title; }
#homeHero { grid-area: hero; }
#homeMain { grid-area: main; }
#skinCarousel { grid-area: carousel; }
#homeTabs { grid-area: tabs; }
.home-sheet .panel { grid-area: main; }
.home-sheet > div { background: none; padding: 0; }

.home-title {
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: .01em;
  color: #fff;
  line-height: 1;
  margin: 0;
  text-shadow: 0 .16rem 0 var(--accent-dark), 0 .5rem 1.2rem rgba(80, 40, 20, .55);
  cursor: pointer;
}
.home-sheet h1.home-title { font-size: 2.1rem; margin-bottom: 0; }

#homeHero {
  /* vw 단위는 데스크톱 폰 프레임 안에서 깨진다 — 시트 폭 기준 % 로.
     가로 홈에서는 왼쪽 칸(8.5rem)을 통째로 쓴다. 높이가 낮으니 세로를 프레임에 맞춰 묶는다. */
  width: 100%;
  max-height: 16rem;
  object-fit: contain;
  height: auto;
  margin: .2rem 0;
  cursor: pointer;
  filter: drop-shadow(0 .8rem 1.2rem rgba(80, 45, 20, .4));
  animation: bob 2.6s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

#homeMain { width: 100%; }

#tapToStart {
  display: block;
  width: 100%;
  padding: .7rem 1rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff9a7a, var(--accent));
  color: #fff;
  font: inherit;
  font-size: 1.15rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .5), inset 0 -4px 0 var(--accent-dark),
    0 .4rem 1.2rem rgba(180, 70, 40, .35);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

/* 가로 홈은 오른쪽 열 폭이 좁다 — 칩 12개를 한 줄로 밀면 끝이 잘린다(스크롤을 모른다).
   두 줄로 접어 다 보여 준다. */
.carousel {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .4rem;
  width: 100%;
  padding: .3rem .1rem;
  scrollbar-width: none;
}
.carousel::-webkit-scrollbar { display: none; }

/* 칩 그림은 assets/hero.webp — clerk 을 파랑(210°)으로 돌려 저장한 것이다.
   ahome.js 가 "원본은 210°" 를 전제로 hue-rotate 하기 때문(js/ahome.js 는 _shared 사본이라 못 고친다). */
.home-sheet .skin-chip {
  flex: 0 0 auto;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, .6);
  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;
}
/* 칩은 얼굴이 보여야 한다 — 위쪽 정렬이면 모자만 나온다(원본 104×192 세로 스프라이트). */
.home-sheet .skin-chip img { width: 135%; margin-top: -24%; }
.home-sheet .skin-chip.on { border-color: #fff; box-shadow: 0 0 0 3px rgba(244, 162, 89, .9); }
.home-sheet .skin-chip.locked { opacity: .38; }

#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: .35rem .3rem;
  border: 0;
  border-radius: .7rem;
  background: rgba(255, 250, 240, .82);
  color: #6b4a2c;
  font: inherit;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.home-sheet .tab-btn b { font-size: 1rem; line-height: 1; font-weight: 400; }
.home-sheet .tab-btn:active, .home-sheet .tab-btn.active { background: var(--accent); color: #fff; }

.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(255, 250, 240, .9);
}
.sheet .panel .back {
  width: 100%;
  margin-top: .5rem;
  padding: .7rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

/* ── 데스크톱 = 가로 폰 프레임 ───────────────────────
   무대가 16:9(640×360)라 프레임도 16:9 다 → 데스크톱에는 레터박스 띠가 없다. */
@media (min-width: 768px) and (min-height: 600px) {
  body {
    background: radial-gradient(120% 90% at 50% 0%, #ffe6c2 0%, #e9c9a0 48%, #b98d63 100%);
    gap: 1rem;
  }
  #app {
    width: min(900px, calc(100vw - 64px), calc((100vh - 96px) * 640 / 360));
    height: auto;
    aspect-ratio: 640 / 360;
    border-radius: 32px;
    box-shadow: 0 0 0 10px #4b3524, 0 0 0 12px #7a5636, 0 40px 90px rgba(70, 40, 15, .45);
  }
  #stage { border-radius: 32px; }
  #kbdHint {
    display: block;
    margin: 0;
    color: #6b4a2c;
    font-size: .85rem;
    font-weight: 600;
    letter-spacing: .01em;
  }
}

/* 가로 전용 — 폰을 세로로 들면 안내를 띄운다. max-width 로 폰만 걸러야 한다.
   안 걸면 좁고 높은 데스크톱 창에서도 안내가 뜬다(artillery 에서 겪었다). */
#rotate { display: none; }
@media (orientation: portrait) and (max-width: 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; }
}

/* 홈 배경 — 매장 나무 바닥. url 은 CSS 파일 기준 ../ (pipes 함정). */
#home {
  background-image:
    linear-gradient(180deg, rgba(255, 244, 224, .55), rgba(120, 70, 35, .78)),
    url("../assets/floor-wood.webp");
  background-size: auto, 190px 190px;
  background-position: center;
}
