/* 도깨비 특급 — 가로 640×360 캔버스 1장 + 오버레이. 프레임 규격은 artillery 와 같다(교훈 3·26). */
:root {
  --bg: #0b0a1f;
  --ink: #fff3dd;
  --dim: #cbb9e0;
  --gold: #ffd24a;
  --accent: #f2c230;
  --mint: #6fd6a0;
  --panel: #2a2146;
  --panel2: #1b1533;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font: 700 16px/1.4 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", 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: #07061a radial-gradient(120% 90% at 50% 10%, #2a2150 0%, #120e2c 50%, #05040f 100%);
}
#app { position: relative; width: 100vw; height: 100vh; overflow: hidden; background: #070a22; }
main { position: absolute; inset: 0; }
#stage { display: block; width: 100%; height: 100%; touch-action: none; }

.overlay {
  position: absolute; inset: 0; z-index: 10;               /* fixed 금지 — 프레임 밖으로 샌다 */
  display: flex; align-items: center; justify-content: center;
  padding: .8rem; background: rgba(8, 6, 22, .72);
}
.overlay.clear { background: linear-gradient(180deg, rgba(8,6,22,.1), rgba(8,6,22,.55)); }
/* 타이틀: 키 아트(bg.ch1.title)의 하루가 가운데에 있어 로고는 왼쪽 위 빈 하늘에 둔다 */
#title { justify-content: flex-start; align-items: flex-start; padding: 4% 4%; background: linear-gradient(100deg, rgba(8,6,22,.6), rgba(8,6,22,0) 45%); }
/* 밤 선택: 맵(bg.ch1.map)이 보이게 아래쪽 한 줄로 */
/* 구역 선택: 서울 지도(캔버스)의 표지 칩을 누를 수 있게 오버레이는 클릭을 통과시키고, 시트는 오른쪽 아래(표지가 없는 자리) */
#select { align-items: flex-end; justify-content: flex-end; background: none; pointer-events: none; }
#select .sheet { pointer-events: auto; }
#select .sheet.wide { max-width: 23rem; background: linear-gradient(180deg, rgba(42,33,70,.9), rgba(27,21,51,.94)); padding: .45rem .6rem; }
#select .night small { font-size: .62rem; }
#select .night b { font-size: .8rem; }
#select .head h1 { font-size: .9rem; }
#select .toggle { margin-top: .3rem; font-size: .72rem; }
#select .nights { grid-template-columns: repeat(6, 1fr); gap: .25rem; }   /* 한 줄 — 지도 표지(종로 48% 높이)를 가리지 않게 */
#select .chips { display: none; }   /* 구역 고르기는 지도 표지 칩으로 */
#select .chips { margin-bottom: .35rem; }
#select .toggle { margin-top: .4rem; }
.overlay[hidden] { display: none; }

.sheet {
  width: 100%; max-width: 22rem; max-height: 100%; overflow-y: auto;
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  border-radius: 1.1rem; padding: .9rem 1.1rem;
  box-shadow: inset 0 2px 0 rgba(255,235,200,.14), 0 1rem 2rem rgba(0,0,0,.55);
  text-align: center;
}
.sheet.wide { max-width: 34rem; }
.sheet h1 { font-size: 1.15rem; margin-bottom: .5rem; }
.sheet button, .big {
  width: 100%; padding: .6rem; border: 0; border-radius: 999px;
  background: linear-gradient(180deg, #ffe08a, var(--accent)); color: #3b2406;
  font: inherit; font-weight: 800; cursor: pointer; margin-top: .5rem;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.7), inset 0 -3px 0 #b88a16;
}
.sheet button.plain { background: rgba(255,255,255,.12); color: var(--ink); box-shadow: inset 0 1px 0 rgba(255,255,255,.2); }
.sheet button.ghost {
  background: linear-gradient(180deg, #b8f5d4, var(--mint)); color: #0f3a22;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.8), inset 0 -3px 0 #2ea26a;
  animation: pulse 1.1s ease-in-out infinite;
}
.sheet button[hidden] { display: none; }
@keyframes pulse { 50% { transform: scale(1.035); } }
.row { display: flex; gap: .5rem; align-items: center; }
.row.btns button { flex: 1; }
.head { justify-content: space-between; margin-bottom: .4rem; }
.head h1 { margin: 0; font-size: 1.05rem; }
.sheet .icon { width: 2.2rem; flex: none; margin: 0; padding: .35rem; }
.coins { color: var(--gold); min-width: 3rem; text-align: right; }
.coins::before { content: "● "; font-size: .8em; }

/* 타이틀 */
.title-box { text-align: left; width: min(46%, 22rem); }
.title-box .big { max-width: 12rem; }
.kicker { color: var(--dim); font-size: .85rem; letter-spacing: .08em; }
.logo {
  font-size: clamp(2.2rem, 9vh, 3.6rem); line-height: 1.05; margin: .2rem 0 .7rem;
  color: #fff4d8; text-shadow: 0 4px 0 #3a1a08, 0 0 24px rgba(255,180,80,.45);
}
.logo span { color: var(--accent); }
.big { max-width: 14rem; font-size: 1.1rem; padding: .7rem; }
.sub { margin-top: .5rem; color: rgba(255,255,255,.45); font-size: .75rem; }

/* 밤 선택 */
.chips { display: flex; gap: .35rem; overflow-x: auto; margin-bottom: .5rem; }
.chips span { flex: none; padding: .2rem .6rem; border-radius: 999px; font-size: .75rem; background: rgba(255,255,255,.1); color: var(--dim); }
.chips span.on { background: var(--accent); color: #3b2406; }
.chips span.open { cursor: pointer; color: var(--ink); }
.sheet .night.soon { opacity: .55; background: repeating-linear-gradient(135deg, #2a1f3f 0 8px, #241a36 8px 16px); }
.nights { display: grid; grid-template-columns: repeat(3, 1fr); gap: .45rem; }
.sheet .night {
  width: auto; margin: 0; border: 0; border-radius: .8rem; padding: .45rem .3rem; font: inherit; cursor: pointer;
  background: linear-gradient(180deg, #3a2e60, #28204a); color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.15);
}
.sheet .night:focus-visible, .sheet .night:hover { outline: 2px solid var(--accent); }
.night b { display: block; font-size: .95rem; }
.night small { display: block; font-size: .72rem; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.night .st { color: var(--gold); letter-spacing: .1em; font-size: .85rem; }
.sheet .night.boss { background: linear-gradient(180deg, #6a3a1a, #3a1f10); }
.sheet .night:disabled { opacity: .4; cursor: default; }
#pause .sheet { max-width: 30rem; }
.skins-title { margin-top: .5rem; font-size: .8rem; color: var(--dim); }
.skins { display: grid; grid-template-columns: repeat(3, 1fr); gap: .3rem; }
.sheet .skin { margin: 0; padding: .35rem .2rem; font-size: .75rem; background: rgba(255,255,255,.1); color: var(--ink); box-shadow: none; border-radius: .6rem; }
.sheet .skin small { display: block; font-size: .6rem; color: var(--dim); }
.sheet .skin.on { background: linear-gradient(180deg, #ffe08a, var(--accent)); color: #3b2406; }
.sheet .skin:disabled { opacity: .5; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .6rem; margin-top: .4rem; }
.toggles .toggle { margin-top: .3rem; justify-content: flex-start; }
.toggle { display: flex; gap: .4rem; align-items: center; justify-content: center; margin-top: .6rem; font-size: .8rem; color: var(--dim); }

/* 결과 */
.result-sheet h1 { font-size: 1.6rem; color: #ffe6b0; text-shadow: 0 3px 0 rgba(0,0,0,.35); margin-bottom: .2rem; }
.fail-title { color: #ffb0a0 !important; }
.shake { animation: shake .4s ease-out 1; }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }
.stars { font-size: 1.9rem; color: var(--gold); letter-spacing: .15em; }
.stars i { font-style: normal; color: rgba(255,255,255,.18); }
#resultStats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .3rem; margin: .4rem 0; font-size: .8rem; }
#resultStats div { background: rgba(0,0,0,.28); border-radius: .6rem; padding: .3rem; }
#resultStats b { display: block; font-size: 1rem; color: #fff; }
#resultStats .tips b { color: var(--gold); }
.story { font-size: .8rem; color: var(--dim); background: rgba(255,255,255,.06); border-radius: .6rem; padding: .45rem .6rem; text-align: left; }
.story b { color: var(--ink); }
#failWhy { color: var(--dim); font-size: .9rem; }

#deskHint { display: none; }
@media (min-width: 768px) and (min-height: 600px) {
  #app {
    width: min(960px, calc(100vw - 64px), calc((100vh - 96px) * 640 / 360));
    height: auto; aspect-ratio: 640 / 360; border-radius: 28px;
    box-shadow: 0 0 0 10px #15142a, 0 0 0 12px #2b2850, 0 40px 90px rgba(0,0,0,.6);
  }
  #stage { border-radius: 28px; }
  #deskHint {
    display: block; position: fixed; left: 0; right: 0; bottom: 22px;
    text-align: center; font-size: .82rem; color: rgba(255,232,200,.55);
  }
}
/* 가로 전용 — 폰을 세로로 들면 안내 */
#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; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* 일시정지 — 크레딧(CC BY 표기) */
.credits { margin-top: 10px; font-size: 12px; opacity: .85; text-align: left; max-width: 420px; }
.credits summary { cursor: pointer; padding: 6px 0; }
.credits ul { margin: 4px 0; padding-left: 18px; }
.credits a { color: inherit; }

/* 7차: 진행방식 아이콘 · 조건 카드 · 돌쇠네 상점 */
.night .mode { display: block; font-size: .58rem; color: #ffe27a; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet .shop-btn { width: auto; flex: none; margin: 0 .35rem 0 0; padding: .25rem .55rem; font-size: .72rem; background: linear-gradient(180deg, #ffcf6a, #e89a2a); color: #3b2406; }
.cards-sub { font-size: .75rem; color: var(--dim); margin-bottom: .45rem; }
.card-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: .45rem; margin-bottom: .45rem; }
.sheet .card { margin: 0; padding: .55rem .4rem; min-height: 6.2rem; display: flex; flex-direction: column; justify-content: center; gap: .25rem;
  background: linear-gradient(180deg, #3b2c63, #241a40); color: var(--ink); border: 1px solid rgba(255,226,122,.35); box-shadow: 0 4px 0 rgba(0,0,0,.35); }
.sheet .card b { font-size: .95rem; color: #ffe27a; }
.sheet .card small { font-size: .68rem; color: var(--ink); opacity: .9; white-space: normal; }
.sheet .card.forced { border-color: #ff9a6a; }
.shop-sheet .head { align-items: center; gap: .5rem; }
.shop-face { width: 3.2rem; height: 3.2rem; object-fit: cover; object-position: top; border-radius: .6rem; background: rgba(255,255,255,.08); flex: none; }
.shop-talk { flex: 1; display: flex; flex-direction: column; font-size: .72rem; text-align: left; }
.shop-talk b { font-size: .9rem; }
.shop-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: .35rem; margin: .45rem 0; }
.shop-item { display: flex; align-items: center; gap: .4rem; padding: .35rem .45rem; border-radius: .6rem; background: rgba(255,255,255,.07); text-align: left; }
.shop-item div { flex: 1; font-size: .72rem; }
.shop-item div b { display: block; font-size: .8rem; }
.shop-item .pips { color: #ffe27a; letter-spacing: .08em; font-size: .7rem; }
.sheet .shop-item button { width: auto; margin: 0; padding: .3rem .5rem; font-size: .72rem; flex: none; }

#select .sheet.wide { max-width: 28rem; }
#select .head h1 { font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }

/* 8차: 스킬 장착(밤 목록 아래) */
.skill-row { display: flex; align-items: center; gap: .35rem; margin-top: .35rem; font-size: .72rem; }
.skill-row > span { font-weight: 800; color: var(--gold); }
.skill-row small { color: var(--dim); font-size: .6rem; }
.skill-pick { display: flex; gap: .3rem; }
.sheet .sk { position: relative; width: 2.1rem; height: 2.1rem; margin: 0; padding: 0; border-radius: 50%; font-size: .8rem; font-weight: 900; color: #1a1030;
  box-shadow: none; border: 2px solid rgba(255,255,255,.25); background-size: cover; background-position: center; }
.sheet .sk.on { border-color: #ffe27a; box-shadow: 0 0 0 2px rgba(255,226,122,.45); }
.sheet .sk b { position: absolute; right: -.25rem; top: -.3rem; font-size: .55rem; background: #ffe27a; color: #3b2406; border-radius: .5rem; padding: 0 .2rem; }
.sheet .sk:disabled { opacity: .3; }
.newskill { margin-top: .4rem; padding: .3rem .5rem; border-radius: .5rem; background: rgba(255,226,122,.15); color: #ffe27a; font-size: .78rem; }
