/* Slime Burst S0 — 논리 360×800 무대(#stage)를 JS가 배율로 맞춘다. 좌표는 S0 계약 v4 1장, 색은 2장(E안). */
:root {
  --sky: #9ce4fc;
  --grass: #b4de7e;
  --cream: #fcf6ea;
  --grid: #e9e1d2;
  --ink: #1f1d24;
  --ink-soft: #6a6470;
  --coral: #f66648;
  --gold: #fccc36;
  --moves: #fceaa8;
  --yellow: #fde070;
  --blue: #84dbfc;
  --green: #9ce48d;
  --letterbox: #8fd6ee;
  --font: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--letterbox);
  color: var(--ink);
  font: 15px/1.4 var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}

#safe-probe {
  position: fixed; inset: 0; visibility: hidden; pointer-events: none;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

#stage {
  position: fixed; left: 0; top: 0; width: 360px; height: 800px;
  transform-origin: 0 0; overflow: hidden; background: var(--sky);
}

#game-canvas, #fx-top { position: absolute; left: 0; top: 0; width: 360px; height: 800px; display: block; }
#game-canvas { touch-action: none; }
#fx-top { pointer-events: none; z-index: 5; }

/* HUD는 판 입력을 가리지 않게 pointer-events 없음 — 버튼만 받는다 */
#top-bar, #mission-card, #moves-card, #chain-badge, #name-bubble, #score-line, #hint-text, #bottom-bar { position: absolute; pointer-events: none; }
button, .overlay, input, label, #debug-tools { pointer-events: auto; }

/* ── 위 한 줄 y 12~60 ── */
#top-bar { left: 0; top: 12px; width: 360px; height: 48px; }
.round-btn {
  position: absolute; top: 2px; width: 44px; height: 44px; border-radius: 14px;
  border: 3px solid var(--ink); background: var(--cream); color: var(--ink);
  display: grid; place-items: center; cursor: pointer; padding: 0;
  box-shadow: 0 3px 0 rgba(31, 29, 36, 0.25);
}
.round-btn:active { transform: translateY(2px) scale(0.96); box-shadow: 0 1px 0 rgba(31, 29, 36, 0.25); }
.round-btn svg { width: 24px; height: 24px; fill: none; stroke: var(--ink); stroke-width: 2.8; stroke-linecap: round; stroke-linejoin: round; }
#btn-back { left: 12px; }
#btn-settings { left: 304px; }
#title-box { position: absolute; left: 70px; width: 220px; top: 0; height: 48px; text-align: center; }
.logo {
  display: inline-block; padding: 1px 14px 0; height: 28px; line-height: 26px; border: 3px solid var(--ink); border-radius: 16px; background: var(--cream);
  font: 900 18px/24px "Arial Rounded MT Bold", "Arial Black", var(--font); letter-spacing: 0.5px;
}
.logo .l1 { color: #48b7ee; -webkit-text-stroke: 1px var(--ink); }
.logo .l2 { color: var(--gold); -webkit-text-stroke: 1px var(--ink); }
#stage-pill {
  margin: -3px auto 0; width: max-content; padding: 0 10px; height: 20px; line-height: 15px;
  border: 2.5px solid var(--ink); border-radius: 10px; background: var(--cream);
  font: 800 12px/15px var(--font); letter-spacing: 0.5px;
}

/* 코덱스 UI 그림이 있을 때(app.js applyUiArt): 흰 실루엣 아이콘을 잉크색으로(마스크), 로고 그림, 금색 별 */
.has-art svg { display: none; }
.ui-icon {
  display: block; width: 28px; height: 28px; background: var(--ink);
  -webkit-mask-position: center; mask-position: center; -webkit-mask-size: contain; mask-size: contain; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
}
.round-btn .ui-icon { width: 24px; height: 24px; }
.has-logo .logo {
  width: 132px; height: 41px; padding: 0; border: 0; border-radius: 0; background: url(../assets/art/logo-slime-burst.png) center / contain no-repeat;
  font-size: 0; color: transparent;
}
.has-logo .logo span { display: none; }
.has-logo #stage-pill { margin-top: -11px; position: relative; }
.has-ui-star .star.on { clip-path: none; background: url(../assets/art/ui-star.png) center / contain no-repeat; }

/* ── 미션 카드 x 16~262 · y 70~130, 이동 카드 x 272~344 ── */
#mission-card {
  left: 16px; top: 70px; width: 246px; height: 60px; border: 3px solid var(--ink); border-radius: 16px; background: var(--cream);
}
#mission-list { list-style: none; margin: 0; padding: 0; position: absolute; inset: 0; }
.mission { position: absolute; top: 0; height: 54px; display: flex; align-items: center; justify-content: center; gap: 4px; }
.mission + .mission::before { content: ""; position: absolute; left: 0; top: 12px; height: 30px; border-left: 2px solid var(--grid); }
.mission canvas { width: 32px; height: 32px; display: block; transition: transform 90ms ease-out; }
.mission .chip { min-width: 34px; height: 26px; padding: 0 5px; border-radius: 9px; background: var(--coral); color: #fff; font: 900 12px/26px var(--font); text-align: center; -webkit-text-stroke: 0.3px var(--ink); }
.mission .count { font: 900 24px/1 var(--font); font-variant-numeric: tabular-nums; min-width: 22px; text-align: left; }
.mission.done .count { color: #3f9a46; }
.mission.bump canvas, .mission.bump .chip { transform: scale(1.18); }
.mission.flash { outline: 2px solid var(--gold); outline-offset: -4px; border-radius: 10px; }

#moves-card {
  left: 272px; top: 70px; width: 72px; height: 60px; border: 3px solid var(--ink); border-radius: 16px; background: var(--moves);
  text-align: center;
}
#moves-label { display: block; margin-top: 3px; font: 800 12px/14px var(--font); }
#moves-count { display: block; font: 900 30px/32px var(--font); font-variant-numeric: tabular-nums; }
#moves-bonus { position: absolute; right: -6px; top: -12px; padding: 0 6px; height: 20px; border-radius: 10px; border: 2px solid var(--ink); background: #bff0b3; font: 900 11px/16px var(--font); }
#moves-card.low #moves-count { color: #d0402a; animation: moves-blink 0.9s steps(2, start) infinite; }
#moves-card.chain #moves-count { color: var(--ink); animation: none; }
@keyframes moves-blink { 50% { opacity: 0.35; } }

/* ── 연쇄 배지 y 138~200, 중심 (180, 169) ── */
#chain-badge {
  left: 30px; top: 138px; width: 300px; height: 62px; text-align: center; transform-origin: 50% 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 4;
}
#chain-badge[hidden] { display: none; }
#badge-title {
  font: 900 40px/1 "Arial Rounded MT Bold", var(--font); color: var(--coral);
  -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill;
  text-shadow: 0 0 0 #fff, 2px 2px 0 #fff, -2px -2px 0 #fff, 2px -2px 0 #fff, -2px 2px 0 #fff, 0 4px 0 rgba(31, 29, 36, 0.2);
}
#badge-sub { margin-top: 2px; font: 900 15px/1 var(--font); color: var(--ink); background: var(--cream); border: 2px solid var(--ink); border-radius: 10px; padding: 2px 8px; }
#badge-sub:empty { display: none; }
#chain-badge.deep #badge-title { color: #e2432a; }
#chain-badge.party #badge-title { color: var(--gold); }
/* 연쇄 세기 단계 색(D-048): 1 작은 셈 · 2 크림 · 3 금 · 4 코랄 + 빛 · 5 무지개 테 · 6+ 더 굵게 · 8+ 파티 금 */
#badge-row { position: relative; display: inline-block; z-index: 0; }
#badge-star {
  position: absolute; right: -24px; top: -8px; width: 20px; height: 20px; background: var(--gold); transform-origin: 50% 50%;
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
}
/* 1 · 2(크림)는 하늘색 위에서 읽히게 짙은 외곽 */
#chain-badge.lv1 #badge-title, #chain-badge.lv2 #badge-title {
  text-shadow: 2px 2px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 0 2px 0 var(--ink), 0 -2px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 5px 0 rgba(31, 29, 36, 0.25);
}
#chain-badge.lv1 #badge-title { font-size: 32px; color: var(--cream); }
#chain-badge.lv1 #badge-star { width: 14px; height: 14px; right: -18px; top: -5px; }
#chain-badge.lv2 #badge-title { color: #fff4d8; }
#chain-badge.lv3 #badge-title { color: var(--gold); }
#chain-badge.lv4 #badge-title { color: var(--coral); text-shadow: 2px 2px 0 #fff, -2px -2px 0 #fff, 2px -2px 0 #fff, -2px 2px 0 #fff, 0 0 14px rgba(246, 102, 72, 0.85), 0 0 26px rgba(252, 204, 54, 0.7); }
/* 5단+ 무지개 테: 글 뒤 알약(배치는 그대로 — 판 위 얼굴 쪽으로 밀지 않음) · 6단+ 더 굵게 */
#chain-badge.lv5 #badge-row::before, #chain-badge.lv6 #badge-row::before, #chain-badge.lv7 #badge-row::before, #chain-badge.lv8 #badge-row::before {
  content: ""; position: absolute; inset: -5px -14px -3px; z-index: -1; border-radius: 26px; border: 4px solid transparent;
  background: linear-gradient(#fffdf6, #fffdf6) padding-box, linear-gradient(90deg, #f66648, #fccc36, #9ce48a, #7ed8fc, #a98bf0) border-box;
}
#chain-badge.lv6 #badge-row::before, #chain-badge.lv7 #badge-row::before { border-width: 6px; inset: -6px -16px -4px; }
#chain-badge.lv8 #badge-row::before { border-width: 7px; inset: -7px -18px -5px; }
#chain-badge.lv5 #badge-title { color: var(--coral); }
#chain-badge.lv6 #badge-title, #chain-badge.lv7 #badge-title { color: #e2432a; font-size: 42px; -webkit-text-stroke: 2.5px var(--ink); }
#chain-badge.lv8 #badge-title { color: var(--gold); }
#chain-badge.lv6 #badge-star, #chain-badge.lv7 #badge-star, #chain-badge.lv8 #badge-star { width: 26px; height: 26px; right: -28px; top: -10px; }
#mission-card { transition: transform 90ms ease-out; transform-origin: 50% 50%; }
#mission-card.bump { transform: scale(1.04); }
#chain-badge.ring::after, #chain-badge.big::after, #chain-badge.tail::after, #chain-badge.deep::after, #chain-badge.party::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
  border: 3px solid rgba(252, 204, 54, 0.9); opacity: var(--ring-a, 0); transform: scale(var(--ring-s, 0.5)); pointer-events: none;
}

/* ── 모양 보기 이름표(판 위 말풍선) ── */
#name-bubble {
  z-index: 6; left: 0; top: 0; max-width: 220px; padding: 5px 10px 6px; border: 2.5px solid var(--ink); border-radius: 12px; background: #fffdf6;
  font: 700 12px/1.3 var(--font); text-align: center; transform: translate(-50%, -100%); white-space: normal; box-shadow: 0 3px 0 rgba(31, 29, 36, 0.18);
}
#name-bubble[hidden] { display: none; }
#name-bubble::after { content: ""; position: absolute; left: 50%; bottom: -8px; margin-left: -6px; border: 6px solid transparent; border-top-color: var(--ink); border-bottom: 0; }
#name-bubble.below { transform: translate(-50%, 0); }
#name-bubble.below::after { bottom: auto; top: -8px; border-top: 0; border-bottom: 6px solid var(--ink); border-top-color: transparent; }
#bubble-name { display: block; font: 900 14px/1.2 var(--font); }

/* ── 점수 줄 x 30~330 · y 624~656, 안내 y 660~702 ── */
#score-line {
  left: 30px; top: 624px; width: 300px; height: 32px; border: 3px solid var(--ink); border-radius: 16px; background: var(--cream);
  display: flex; align-items: center; justify-content: center; gap: 12px;
}
.score-label { font: 900 14px/1 "Arial Rounded MT Bold", var(--font); letter-spacing: 0.5px; }
#score-value { font: 900 18px/1 "Arial Rounded MT Bold", var(--font); font-variant-numeric: tabular-nums; letter-spacing: 1px; min-width: 76px; }
#score-stars, #result-stars { display: flex; gap: 4px; }
.star {
  display: inline-block; width: 20px; height: 20px; background: #e2dccf;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 92%, 50% 71%, 21% 92%, 32% 57%, 2% 35%, 39% 35%);
}
.star.on { background: var(--gold); }
#hint-text {
  left: 16px; width: 328px; top: 660px; height: 42px; margin: 0; display: flex; align-items: center; justify-content: center; text-align: center;
  font: 800 15px/1.25 var(--font); color: var(--ink); white-space: pre-line; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}
#hint-text.multi { font-size: 13px; }

/* ── 하단 버튼 3: y 708~776, 96×68, 중심 x 70 · 180 · 290 ── */
#bottom-bar { left: 0; top: 708px; width: 360px; height: 68px; }
.big-btn {
  position: absolute; top: 0; width: 96px; height: 68px; border: 3px solid var(--ink); border-radius: 18px; color: var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer;
  font: 900 14px/1.1 var(--font); box-shadow: 0 4px 0 rgba(31, 29, 36, 0.28); padding: 0;
}
.big-btn:active { transform: translateY(3px) scale(0.97); box-shadow: 0 1px 0 rgba(31, 29, 36, 0.28); }
.big-btn svg { width: 28px; height: 28px; fill: none; stroke: var(--ink); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.big-btn.yellow { left: 22px; background: var(--yellow); }
.big-btn.blue { left: 132px; background: var(--blue); }
.big-btn.green { left: 242px; background: var(--green); }

button:focus-visible { outline: 3px solid #3e95e6; outline-offset: 2px; }

/* ── 겹침 화면 ── */
.overlay { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; background: rgba(31, 29, 36, 0.42); }
.overlay[hidden] { display: none; }
#settings-screen, #quit-screen { z-index: 12; }
#levels-screen, #help-screen { z-index: 14; }
.card {
  width: 304px; max-height: 740px; overflow: auto; background: var(--cream); border: 3px solid var(--ink); border-radius: 22px; padding: 18px 16px 16px;
  display: flex; flex-direction: column; gap: 9px; text-align: center; box-shadow: 0 8px 0 rgba(31, 29, 36, 0.22);
}
.card.wide { width: 340px; }
.card h2 { margin: 0 0 2px; font: 900 22px/1.2 var(--font); }
.card p { margin: 0 0 4px; color: var(--ink-soft); font-weight: 600; }
.card button {
  height: 46px; border-radius: 14px; border: 2.5px solid var(--ink); background: #fff; color: var(--ink);
  font: 800 15px/1 var(--font); cursor: pointer; flex: none;
}
.card button.primary { background: var(--coral); color: #fff; }
.card button.small { height: 32px; font-size: 13px; width: 96px; align-self: center; }
.card .note { color: var(--ink-soft); font-size: 12px; }
.opt { display: flex; align-items: center; gap: 10px; justify-content: flex-start; padding: 4px 4px; font: 700 15px/1.2 var(--font); }
.opt input { width: 22px; height: 22px; }
.opt-text { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; }
.opt-text small { font: 600 11.5px/1.2 var(--font); color: var(--ink-soft); }
.opt-group { display: flex; flex-direction: column; gap: 6px; text-align: left; padding: 6px 4px; border-top: 2px dashed var(--grid); }
.opt-title { font: 800 15px/1.2 var(--font); }
.opt-title em { font-style: normal; margin-left: 6px; padding: 1px 8px; border-radius: 10px; border: 2px solid var(--ink); background: #fff; font-size: 12px; }
.seg { display: flex; gap: 6px; }
.seg label { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; height: 36px; border: 2.5px solid var(--ink); border-radius: 12px; background: #fff; font: 800 14px/1 var(--font); }
.seg label:has(input:checked) { background: var(--yellow); }
.seg input { width: 16px; height: 16px; margin: 0; }
.sat canvas { width: 260px; height: 48px; align-self: center; }
.sat input[type="range"] { width: 100%; accent-color: var(--coral); }
.sat-ends { display: flex; justify-content: space-between; color: var(--ink-soft); }

.tabs { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; flex: none; }
.tabs button { height: 32px; padding: 0 10px; font-size: 12px; border-radius: 10px; white-space: nowrap; flex: none; }
.tabs button[aria-selected="true"] { background: var(--yellow); }

#level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; padding: 4px 2px; }
.level-btn {
  height: 58px !important; padding: 2px 0 !important; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: #fff; font-size: 17px !important; font-weight: 900 !important; position: relative;
}
.level-btn .stars { display: flex; gap: 1px; }
.level-btn .star { width: 11px; height: 11px; }
.level-btn.cleared { background: #fff6cf; }
.level-btn.boss { border-width: 3.5px !important; background: #ffe2da; }
.level-btn.current { box-shadow: 0 0 0 3px var(--coral); }
.level-btn.locked { background: #e9e4da !important; color: #9b958e !important; }
.level-btn.notready { border-style: dashed !important; background: transparent !important; color: #9b958e !important; font-size: 11px !important; }
.level-btn small { font-size: 9px; font-weight: 700; color: var(--ink-soft); }
.chapter-note { grid-column: 1 / -1; font: 700 12px/1.3 var(--font); color: var(--ink-soft); text-align: left; }
/* 릴리스 게이트(곧 열려요): 공개 전 장 · 판 — 누를 수 없음 */
.level-btn.soon { background: #efe9df !important; color: #a39d95 !important; border-style: dashed !important; }
.level-btn.soon small { font-size: 8.5px; color: #8f887f; }
.chapter-note.soon { color: var(--coral); text-align: center; font-size: 13px; }
#level-tabs .soon, [role="tab"].soon { opacity: 0.62; }
#btn-next.soon { background: #e9e4da !important; color: #8f887f !important; box-shadow: none !important; }

#result-stars { justify-content: center; margin: 2px 0 2px; }
#result-stars .star { width: 46px; height: 46px; }
#result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 2px 0 6px; }
#result-stats div { background: #fff; border: 2px solid var(--grid); border-radius: 12px; padding: 6px 2px; }
#result-stats dt { font-size: 11px; color: var(--ink-soft); }
#result-stats dd { margin: 0; font: 900 20px/1.2 var(--font); }
#result-screen[data-result="win"] h2 { color: var(--coral); }

#help-body { text-align: left; display: flex; flex-direction: column; gap: 8px; }
.help-row { display: grid; grid-template-columns: 56px 1fr 60px; gap: 8px; align-items: center; background: #fff; border: 2px solid var(--grid); border-radius: 12px; padding: 6px; }
.help-row canvas { width: 56px; height: 56px; }
.help-row .grid5 { width: 60px; height: 60px; }
.help-row b { font: 900 15px/1.2 var(--font); display: block; }
.help-row span { font: 600 12px/1.35 var(--font); color: var(--ink-soft); }
.help-row.wide { grid-template-columns: 56px 1fr; }
.help-p { margin: 0; font: 600 13px/1.45 var(--font); color: var(--ink); }

#error-banner { position: absolute; left: 12px; right: 12px; top: 560px; z-index: 20; background: #fde2e1; color: #8a1f1b; border: 2px solid #8a1f1b; border-radius: 12px; padding: 8px 10px; font-size: 13px; }
#error-banner[hidden] { display: none; }

#debug-panel {
  position: absolute; left: 4px; top: 548px; z-index: 30; margin: 0;
  font: 9px/1.3 ui-monospace, Consolas, monospace; color: #fff; background: rgba(0, 0, 0, 0.6);
  padding: 4px 6px; border-radius: 8px; pointer-events: none; white-space: pre; max-width: 352px; overflow: hidden;
}
#debug-panel[hidden] { display: none; }
#debug-tools { position: absolute; right: 4px; top: 548px; z-index: 31; display: flex; flex-direction: column; gap: 3px; }
#debug-tools[hidden] { display: none; }
#debug-tools button { height: 22px; padding: 0 6px; font: 700 10px/1 var(--font); border: 1.5px solid var(--ink); border-radius: 7px; background: rgba(255, 255, 255, 0.9); }
#debug-tools button.on { background: var(--yellow); }

@media (prefers-reduced-motion: reduce) {
  .mission canvas, .mission .chip { transition: none; }
}
body.reduced-motion #moves-card.low #moves-count { animation: none; }
body.reduced-motion .mission canvas, body.reduced-motion .mission .chip { transition: none; }

/* 방해물 길게 누르기 설명 카드(이름표와 같은 자리) — 그림(정지) + 이름 + 설명 */
#name-bubble.info { display: grid; grid-template-columns: 40px 1fr; column-gap: 8px; align-items: center; text-align: left; max-width: 280px; width: 280px; }
#name-bubble.info #bubble-art { grid-row: span 2; width: 40px; height: 40px; }
#name-bubble.info #bubble-name { font-size: 14px; }

/* 피날레 이동 셈(D-041) — 숫자가 줄 때 톡 */
#moves-count { transition: transform 90ms ease-out; }
#moves-card.tick #moves-count { transform: scale(1.22); }
#moves-card.tick-flash #moves-count { color: var(--coral); }
body.reduced-motion #moves-count { transition: none; }
