/* 엄지 구멍 너머로 — 스타일 (외부 글꼴·CDN 없이 오프라인 동작) */
:root {
  --night-0: #050b24;
  --night-1: #0a1538;
  --night-2: #13245c;
  --star: #ffd23f;
  --star-soft: #fff1a8;
  --ink: #f4f7ff;
  --ink-dim: #aebbe0;
  --card: rgba(16, 30, 78, 0.94);
  --line: rgba(160, 190, 255, 0.24);
  --danger: #ef4c5a;
  --tb-h: 50px;
  --bag-h: 86px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  position: fixed; inset: 0; overflow: hidden; overscroll-behavior: none;
  background: radial-gradient(120% 90% at 70% 0%, #17306f 0%, var(--night-1) 45%, var(--night-0) 100%);
  color: var(--ink); font-family: var(--font);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%;
}
button, a.chip { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--star); outline-offset: 2px; }
[hidden] { display: none !important; }

#twinkles { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
#twinkles i { position: absolute; width: var(--sz); height: var(--sz); transform: translate(-50%, -50%); animation: twinkle 4s ease-in-out infinite; opacity: 0.2;
  background: radial-gradient(circle, #fff8d8 0 14%, transparent 15%), linear-gradient(90deg, transparent 44%, rgba(255, 244, 200, 0.95) 50%, transparent 56%), linear-gradient(0deg, transparent 44%, rgba(255, 244, 200, 0.95) 50%, transparent 56%);
  border-radius: 50%; filter: drop-shadow(0 0 3px rgba(255, 230, 150, 0.8)); }
@keyframes twinkle { 0%, 100% { opacity: 0.15; transform: translate(-50%, -50%) scale(0.6); } 50% { opacity: 0.95; transform: translate(-50%, -50%) scale(1.1); } }
@media (prefers-reduced-motion: reduce) { #twinkles i { animation: none; opacity: 0.5; } }

.screen { position: fixed; inset: 0; z-index: 1; }

/* ── 메뉴 ── */
#menu { overflow-y: auto; -webkit-overflow-scrolling: touch; scroll-behavior: auto; }
.menu-wrap { min-height: 100%; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: calc(18px + var(--safe-t)) calc(16px + var(--safe-r)) calc(18px + var(--safe-b)) calc(16px + var(--safe-l)); }
.menu-head { text-align: center; }
#title { margin: 0; display: flex; align-items: baseline; justify-content: center; gap: 8px; flex-wrap: wrap; }
.t-main { font-size: clamp(30px, 7vw, 46px); font-weight: 800; letter-spacing: -0.02em; color: var(--star-soft); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); }
.t-ver { font-size: 13px; font-weight: 600; color: var(--ink-dim); }
.sub { margin: 6px 0 0; color: var(--ink-dim); font-size: 15px; }
.menu-art { width: 100%; max-width: 620px; aspect-ratio: 1400 / 951; flex: 0 1 auto; }
.menu-art canvas { width: 100%; height: 100%; display: block; }
.menu-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; width: 100%; }
.big { min-width: 200px; min-height: 58px; padding: 10px 22px; border-radius: 16px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07);
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.big:hover { background: rgba(255, 255, 255, 0.12); }
.big.primary { background: var(--star); color: #1b1a10; border-color: transparent; }
.big.primary:hover { filter: brightness(1.06); }
.b-main { font-size: 18px; font-weight: 800; }
.b-sub { font-size: 13px; opacity: 0.8; }
.endings { margin: 0; color: var(--ink-dim); font-size: 14px; text-align: center; }
.menu-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: auto; }
.chip { min-height: 40px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); font-size: 14px; text-decoration: none; display: inline-flex; align-items: center; }
.chip:hover { background: rgba(255, 255, 255, 0.12); }

/* ── 게임 ── */
#game { display: grid; grid-template-rows: calc(var(--tb-h) + var(--safe-t)) 1fr calc(var(--bag-h) + var(--safe-b)); grid-template-columns: 1fr; background: #030716; }
.topbar { display: flex; align-items: center; gap: 6px; padding: var(--safe-t) calc(8px + var(--safe-r)) 0 calc(8px + var(--safe-l)); background: rgba(10, 21, 56, 0.96); border-bottom: 1px solid var(--line); min-width: 0; z-index: 3; }
.tb { height: 40px; min-width: 42px; padding: 0 10px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: 0 0 auto; font-size: 15px; }
.tb:hover { background: rgba(255, 255, 255, 0.12); }
.tb .ic { font-size: 18px; line-height: 1; }
.tb.hint { background: rgba(255, 210, 63, 0.16); border-color: rgba(255, 210, 63, 0.5); font-weight: 700; }
.tb[disabled] { opacity: 0.45; cursor: default; }
.place { flex: 1 1 auto; min-width: 0; margin: 0 4px; font-size: 17px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stars { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 15px; color: var(--star-soft); padding: 0 6px; }
.stars .ic { color: var(--star); }
@media (max-width: 460px) { .tb .lb { display: none; } .tb { padding: 0 8px; min-width: 40px; } .place { font-size: 15px; } .topbar { gap: 4px; } }

#stageWrap { position: relative; overflow: hidden; min-height: 0; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: default; }
#stage.hot { cursor: pointer; }

#bag { display: flex; align-items: center; gap: 8px; padding: 6px calc(10px + var(--safe-r)) calc(6px + var(--safe-b)) calc(10px + var(--safe-l)); background: rgba(10, 21, 56, 0.97); border-top: 1px solid var(--line);
  overflow-x: auto; overflow-y: hidden; scroll-behavior: auto; z-index: 3; }
.bag-empty { color: var(--ink-dim); font-size: 14px; padding-left: 4px; }
.slot { flex: 0 0 auto; width: 76px; height: 72px; border-radius: 14px; border: 2px solid var(--line); background: rgba(255, 255, 255, 0.07); padding: 2px 2px 3px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 0; touch-action: none; position: relative; }
.slot canvas { width: 50px; height: 50px; pointer-events: none; }
.slot span { font-size: 11.5px; line-height: 1.15; max-width: 72px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.slot.sel { border-color: var(--star); background: rgba(255, 210, 63, 0.18); box-shadow: 0 0 0 2px rgba(255, 210, 63, 0.35); }
.slot.target { border-color: #8fe3a0; background: rgba(143, 227, 160, 0.2); }
.slot.new { animation: slotNew 0.9s ease-out 2; }
@keyframes slotNew { 50% { background: rgba(255, 210, 63, 0.4); } }
#bag.locked .slot { opacity: 0.55; }

/* 가로로 짧은 화면(휴대폰 가로): 가방을 오른쪽 세로 줄로 */
#game.side { grid-template-rows: calc(42px + var(--safe-t)) 1fr; grid-template-columns: 1fr calc(92px + var(--safe-r)); }
#game.side .topbar { grid-column: 1 / 3; }
#game.side .tb { height: 34px; }
#game.side #bag { flex-direction: column; overflow-x: hidden; overflow-y: auto; padding: 6px calc(6px + var(--safe-r)) calc(6px + var(--safe-b)) 6px; border-top: 0; border-left: 1px solid var(--line); }
#game.side .slot { width: 78px; height: 66px; }
#game.side .slot canvas { width: 44px; height: 44px; }
#game.side .bag-empty { writing-mode: horizontal-tb; font-size: 12px; text-align: center; padding: 0; }

/* 말풍선 */
.bubble { position: absolute; z-index: 5; max-width: min(380px, calc(100% - 16px)); padding: 10px 14px 12px; border-radius: 16px; background: rgba(253, 251, 240, 0.97); color: #1b2142;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45); font-size: 17px; line-height: 1.45; pointer-events: auto; cursor: pointer; }
.bubble .who { display: block; font-size: 13px; font-weight: 800; color: var(--who, #6a5a10); margin-bottom: 2px; }
.bubble .who:empty { display: none; }
.bubble .txt { margin: 0; word-break: keep-all; overflow-wrap: anywhere; }
.bubble .more { position: absolute; right: 10px; bottom: 4px; font-size: 10px; font-style: normal; color: #7c86b0; animation: nudge 1.2s ease-in-out infinite; }
.bubble::after { content: ''; position: absolute; left: var(--tx, 50%); width: 16px; height: 16px; background: inherit; transform: translateX(-50%) rotate(45deg); }
.bubble.down::after { bottom: -7px; }
.bubble.up::after { top: -7px; }
.bubble.free::after { display: none; }
.bubble.narr { background: rgba(14, 27, 70, 0.96); color: var(--ink); border: 1px solid var(--line); }
.bubble.narr .more { color: var(--ink-dim); }
@keyframes nudge { 50% { transform: translateY(2px); } }
@media (prefers-reduced-motion: reduce) { .bubble .more { animation: none; } }

.selchip { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 4; display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 14px; border-radius: 999px;
  background: rgba(255, 210, 63, 0.95); color: #1b1a10; font-weight: 700; font-size: 14px; max-width: calc(100% - 20px); white-space: nowrap; }
.selchip span { overflow: hidden; text-overflow: ellipsis; }
.selchip button { width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, 0.15); font-weight: 900; flex: 0 0 auto; }
.toast { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 6; padding: 8px 16px; border-radius: 999px; background: rgba(14, 27, 70, 0.95); border: 1px solid var(--line);
  font-size: 15px; font-weight: 700; color: var(--star-soft); pointer-events: none; white-space: nowrap; max-width: calc(100% - 20px); overflow: hidden; text-overflow: ellipsis; }
.paintbar { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 4; display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 999px;
  background: rgba(14, 27, 70, 0.92); border: 1px solid var(--line); font-weight: 700; font-size: 14px; pointer-events: none; }
.paintbar i { display: block; width: 120px; height: 10px; border-radius: 5px; background: rgba(255, 255, 255, 0.15); overflow: hidden; }
.paintbar b { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffe36a, #ffc61a); }
.paintbar em { font-style: normal; min-width: 38px; text-align: right; color: var(--star-soft); }
.hovertip { position: absolute; z-index: 4; padding: 4px 10px; border-radius: 8px; background: rgba(14, 27, 70, 0.92); border: 1px solid var(--line); font-size: 14px; font-weight: 700; pointer-events: none; white-space: nowrap; }

/* ── 이야기(여는·닫는 장면) ── */
#story { background: #0c0a14; }
#storyCv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.caption { position: absolute; left: 50%; bottom: calc(22px + var(--safe-b)); transform: translateX(-50%); width: min(640px, calc(100% - 28px)); padding: 14px 18px 18px; border-radius: 16px;
  background: rgba(10, 16, 40, 0.88); border: 1px solid var(--line); font-size: 18px; line-height: 1.55; cursor: pointer; }
.caption p { margin: 0; word-break: keep-all; white-space: pre-line; }
.caption .more { position: absolute; right: 12px; bottom: 6px; font-size: 11px; font-style: normal; color: var(--ink-dim); animation: nudge 1.2s ease-in-out infinite; }
.skip { position: absolute; top: calc(12px + var(--safe-t)); right: calc(12px + var(--safe-r)); height: 40px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(10, 16, 40, 0.7); font-size: 14px; z-index: 2; }
.endcard { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(520px, calc(100% - 28px)); max-height: calc(100% - 28px); overflow-y: auto; padding: 22px 20px 20px; border-radius: 20px;
  background: rgba(10, 18, 48, 0.94); border: 1px solid var(--line); text-align: center; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); }
.endcard h2 { margin: 0 0 8px; font-size: 26px; color: var(--star-soft); }
.endcard p { margin: 0 0 16px; color: var(--ink-dim); font-size: 16px; line-height: 1.55; white-space: pre-line; word-break: keep-all; }
.end-actions { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }

/* ── 플로팅 창 ── */
.fwin { position: fixed; z-index: 50; display: flex; flex-direction: column; min-width: 220px; min-height: 160px; background: rgba(12, 24, 66, 0.97);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55); overflow: hidden; }
.fwin-bar { flex: 0 0 auto; display: flex; align-items: center; height: 40px; padding: 0 4px 0 12px; background: rgba(255, 255, 255, 0.07); cursor: move; touch-action: none; }
.fwin-title { flex: 1; font-size: 15px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fwin-close { width: 34px; height: 30px; border: 0; border-radius: 9px; background: var(--danger); color: #fff; font-size: 15px; font-weight: 900; line-height: 1; }
.fwin-close:hover { filter: brightness(1.15); }
.fwin-body { flex: 1 1 auto; min-height: 0; position: relative; }
.fwin-body.art canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.fwin-body.text { overflow-y: auto; padding: 10px 16px 14px; font-size: 15px; line-height: 1.6; -webkit-user-select: text; user-select: text; scroll-behavior: auto; }
.fwin-body.text ul { padding-left: 20px; margin: 8px 0; }
.fwin-body.text li { margin: 4px 0; }
.fwin-body .keys { color: var(--ink-dim); font-size: 13px; }
.fwin-resize { position: absolute; right: 0; bottom: 0; width: 26px; height: 26px; cursor: nwse-resize; touch-action: none;
  background: linear-gradient(135deg, transparent 50%, rgba(255, 255, 255, 0.28) 50%, rgba(255, 255, 255, 0.28) 58%, transparent 58%, transparent 68%, rgba(255, 255, 255, 0.28) 68%, rgba(255, 255, 255, 0.28) 76%, transparent 76%); }

/* ── 확인 상자 ── */
.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; background: rgba(2, 6, 20, 0.6); padding: 16px; }
.modal-card { width: min(420px, 100%); padding: 20px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); }
.modal-card p { margin: 0 0 16px; font-size: 17px; line-height: 1.55; white-space: pre-line; word-break: keep-all; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-actions .big { min-width: 110px; min-height: 48px; }

#fade { position: fixed; inset: 0; z-index: 60; background: #02040c; opacity: 0; pointer-events: none; transition: opacity 0.22s linear; }
#fade.on { opacity: 1; pointer-events: auto; }
#fx { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
#ghost { position: fixed; left: 0; top: 0; z-index: 70; width: 72px; height: 72px; pointer-events: none; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.5)); }
#ghost canvas { width: 100%; height: 100%; }

/* ── 언어 ── */
body.lang-en .ko { display: none; }
body:not(.lang-en) .en { display: none; }
/* 언어·소리 설정 창 */
.setbody h3 { margin: 10px 0 6px; font-size: 14px; color: var(--ink-dim); font-weight: 700; }
.seg { display: flex; gap: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; min-height: 44px; border: 0; border-right: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); font-size: 15px; font-weight: 700; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--star); color: #1b1a10; }
/* 확대 중 「원래 크기로」 */
.zoomreset { position: absolute; right: 10px; bottom: 10px; z-index: 4; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: rgba(14, 27, 70, 0.92); font-weight: 700; font-size: 14px; }
