:root {
    --bg: #f7ead6;
    --bg-deep: #ecd6b5;
    --ink: #2b1d14;
    --muted: #7d6550;
    --red: #d9472b;
    --red-deep: #a8301b;
    --yellow: #ffd83d;
    --paper: #fffaf1;
    --line: #e2c9a6;
    --good: #2f8f4e;
    --bad: #b3261e;
    --shadow: 0 6px 0 rgba(43, 29, 20, .18);
    --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; height: 100%; }

body {
    background:
        repeating-linear-gradient(90deg, rgba(0,0,0,.025) 0 2px, transparent 2px 22px),
        var(--bg);
    color: var(--ink);
    font-family: "Gowun Dodum", -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
    font-size: 16px;
    overscroll-behavior: none;
}

.app {
    max-width: 480px;
    min-height: 100dvh;
    margin: 0 auto;
    padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
    position: relative;
    overflow: hidden;
}

.screen { display: none; flex-direction: column; gap: 14px; min-height: calc(100dvh - 28px); }
.screen.is-active { display: flex; animation: pop-in .35s ease; }

@keyframes pop-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- 인트로 ---------- */
.sign {
    background: var(--ink);
    color: var(--yellow);
    border-radius: var(--radius);
    padding: 16px 16px 14px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 3px solid #000;
}
.sign-sub { margin: 0; color: #fff; font-size: 14px; letter-spacing: .02em; }
.sign-title {
    margin: 4px 0 2px;
    font-family: "Black Han Sans", sans-serif;
    font-weight: 400;
    font-size: clamp(52px, 17vw, 76px);
    line-height: .95;
    text-shadow: 3px 3px 0 var(--red);
}
.sign-tag { margin: 6px 0 0; font-family: "Black Han Sans", sans-serif; color: #fff; font-size: 18px; }

.owner-stage { position: relative; display: flex; flex-direction: column; align-items: center; }
.owner { width: 170px; height: 170px; }
.owner svg { width: 100%; height: 100%; display: block; overflow: visible; }
.owner.is-talking .mouth-open { display: inline; }
.owner.is-talking .mouth-closed { display: none; }
.mouth-open { display: none; }
.owner.is-talking svg { animation: bob .28s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(-2px) rotate(-1deg); } }

.bubble {
    position: relative;
    background: var(--paper);
    border: 3px solid var(--ink);
    border-radius: 16px;
    padding: 10px 14px;
    font-size: 18px;
    line-height: 1.35;
    font-weight: 700;
    box-shadow: var(--shadow);
    min-height: 52px;
    word-break: keep-all;
}
.bubble-intro { margin-top: 6px; text-align: center; }
.bubble-intro::before {
    content: ""; position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
    border: 10px solid transparent; border-bottom-color: var(--ink); border-top: 0;
}

.visitors { margin: 0; text-align: center; color: var(--muted); font-size: 14px; }
.visitors span { color: var(--red); font-weight: 700; font-variant-numeric: tabular-nums; }

.sound-toggle { text-align: center; font-size: 14px; color: var(--muted); }
.sound-toggle input { accent-color: var(--red); width: 16px; height: 16px; vertical-align: -3px; }

.howto { background: var(--paper); border: 2px dashed var(--line); border-radius: 14px; padding: 10px 14px; font-size: 15px; }
.howto summary { font-weight: 700; cursor: pointer; }
.howto ol { margin: 8px 0 0; padding-left: 20px; line-height: 1.6; }

.disclaimer { margin-top: auto; font-size: 12px; color: var(--muted); line-height: 1.5; text-align: center; }

/* ---------- 버튼 ---------- */
.btn {
    font: inherit;
    font-family: "Black Han Sans", sans-serif;
    font-size: 21px;
    border: 3px solid var(--ink);
    border-radius: 16px;
    padding: 14px 16px;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform .08s ease, box-shadow .08s ease;
    touch-action: manipulation;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(43,29,20,.18); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--red); color: #fff; }
.btn-ghost { background: var(--paper); color: var(--ink); }
.btn-start { font-size: 26px; padding: 16px; }

/* ---------- 게임 HUD ---------- */
.hud { display: flex; flex-direction: column; gap: 8px; }
.timer {
    position: relative; height: 26px; border-radius: 13px; background: var(--paper);
    border: 3px solid var(--ink); overflow: hidden;
}
.timer i { position: absolute; inset: 0; background: linear-gradient(90deg, var(--red), #f08a3c); transform-origin: left; transition: transform 1s linear; }
.timer span { position: relative; display: block; text-align: center; font-family: "Black Han Sans", sans-serif; font-size: 16px; line-height: 20px; color: var(--ink); mix-blend-mode: multiply; }
.timer.is-hurry { animation: shake .4s ease-in-out infinite; }
@keyframes shake { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }

.basket { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.slot {
    aspect-ratio: 1; border-radius: 10px; border: 2px dashed var(--line); background: rgba(255,255,255,.45);
    overflow: hidden; position: relative;
}
.slot.is-filled { border: 2px solid var(--ink); background: var(--paper); animation: drop .3s ease; }
.slot svg { width: 100%; height: 100%; display: block; }
@keyframes drop { from { transform: translateY(-14px) scale(1.2); } to { transform: none; } }

.owner-row { display: flex; align-items: flex-end; gap: 6px; }
.owner-small { width: 92px; height: 92px; flex: none; }
.bubble-game { flex: 1; font-size: 17px; }
.bubble-game::before {
    content: ""; position: absolute; left: -12px; bottom: 16px;
    border: 9px solid transparent; border-right-color: var(--ink); border-left: 0;
}

/* ---------- 매대 ---------- */
.stall {
    position: relative;
    background: linear-gradient(#c58b4f, #a86d36);
    border: 3px solid var(--ink);
    border-radius: var(--radius);
    padding: 34px 10px 12px;
    box-shadow: var(--shadow);
}
.layer-tag {
    position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
    background: var(--yellow); border: 2px solid var(--ink); border-radius: 999px;
    padding: 1px 12px; font-family: "Black Han Sans", sans-serif; font-size: 14px; white-space: nowrap;
}
.pile { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; min-height: 200px; }
.pile.is-digging { animation: dig .5s ease; }
@keyframes dig { 40% { transform: translateY(14px) scale(.96); opacity: .3; } }

.scarf {
    appearance: none; border: 2px solid var(--ink); background: var(--paper); border-radius: 12px;
    padding: 4px 4px 3px; cursor: pointer; display: flex; flex-direction: column; align-items: stretch;
    font: inherit; color: var(--ink); touch-action: manipulation;
    transition: transform .12s ease;
}
.scarf:active { transform: scale(.94); }
.scarf svg { width: 100%; aspect-ratio: 1; display: block; border-radius: 8px; }
.scarf .hint { font-size: 11px; line-height: 1.25; margin-top: 3px; text-align: center; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scarf.is-gone { animation: gone .35s ease forwards; pointer-events: none; }
.scarf.is-snatched { animation: snatched .5s ease forwards; pointer-events: none; }
@keyframes gone { to { transform: translateY(-60px) scale(.3); opacity: 0; } }
@keyframes snatched { 30% { transform: rotate(-12deg) scale(1.05); } to { transform: translateX(-140px) rotate(-30deg); opacity: 0; } }

.toast {
    position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%) scale(.6);
    font-family: "Black Han Sans", sans-serif; font-size: 34px; color: #fff; padding: 4px 16px;
    border-radius: 12px; border: 3px solid var(--ink); opacity: 0; pointer-events: none; white-space: nowrap;
}
.toast.is-show { animation: toast .9s ease; }
.toast.good { background: var(--good); }
.toast.bad { background: var(--bad); }
@keyframes toast { 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); } 70% { opacity: 1; transform: translate(-50%, -50%) scale(1); } to { opacity: 0; transform: translate(-50%, -70%) scale(1); } }

.ajumma { position: absolute; top: -26px; width: 58px; height: 58px; z-index: 2; transition: transform .25s ease; }
.ajumma-left { left: -8px; transform: translateX(-30px) rotate(-12deg); }
.ajumma-right { right: -8px; transform: translateX(30px) rotate(12deg); }
.ajumma.is-active { transform: none; }
.ajumma-face svg { width: 100%; height: 100%; }
.ajumma-bubble {
    position: absolute; top: 4px; white-space: nowrap; background: #fff; border: 2px solid var(--ink);
    border-radius: 10px; padding: 2px 8px; font-size: 13px; font-weight: 700; opacity: 0; transition: opacity .2s;
}
.ajumma-left .ajumma-bubble { left: 60px; }
.ajumma-right .ajumma-bubble { right: 60px; }
.ajumma.is-active .ajumma-bubble { opacity: 1; }

.actions { display: grid; grid-template-columns: 1fr 1.2fr; gap: 10px; margin-top: auto; }
.actions .btn { white-space: nowrap; font-size: 19px; padding: 14px 8px; }
.actions-result { grid-template-columns: 1fr; }

/* ---------- 결과 ---------- */
.result-card {
    background: var(--paper); border: 3px solid var(--ink); border-radius: var(--radius);
    padding: 18px 16px; text-align: center; box-shadow: var(--shadow);
}
.result-label { margin: 0; color: var(--muted); font-size: 14px; }
.result-emoji { font-size: 64px; line-height: 1.1; margin-top: 4px; }
.result-title { margin: 4px 0; font-family: "Black Han Sans", sans-serif; font-weight: 400; font-size: 34px; color: var(--red); word-break: keep-all; }
.result-meta { margin: 0 0 12px; font-size: 16px; }
.result-meta b { font-variant-numeric: tabular-nums; }
.result-scarves { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.result-scarf { border: 2px solid var(--ink); border-radius: 10px; overflow: hidden; background: #fff; }
.result-scarf svg { width: 100%; aspect-ratio: 1; display: block; }
.result-scarf span { display: block; font-size: 12px; font-weight: 700; padding: 2px 0; }
.result-scarf.bad span { background: #f6d3cf; color: var(--bad); }
.result-scarf.good span { background: #d3efd9; color: var(--good); }
.result-scarf.filled span { background: #eee; color: #666; }
.service { margin-top: 12px; background: var(--yellow); border: 2px solid var(--ink); border-radius: 12px; padding: 8px; font-weight: 700; animation: pop-in .4s ease; }
.result-receipt { margin: 12px 0 0; font-size: 14px; color: var(--muted); border-top: 2px dashed var(--line); padding-top: 10px; }
.result-revenue { margin: 6px 0 0; font-size: 14px; color: var(--muted); }
.result-revenue b { color: var(--red); font-variant-numeric: tabular-nums; }
.result-revenue small { font-size: 12px; }

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

/* ---------- 실사풍 가게 앞 장면 ---------- */
.scene {
    position: relative;
    border: 3px solid var(--ink);
    border-radius: var(--radius);
    overflow: hidden;
    background: #1d1712;
    box-shadow: var(--shadow);
    flex: none;
}
.scene-intro { height: 300px; }
.scene-game { height: 196px; }
.scene-bg, .scene-crowd { position: absolute; left: 0; right: 0; }
.scene-bg { top: 0; height: 100%; }
.scene-bg svg { width: 100%; height: 100%; display: block; }
.scene-bg::after {
    content: ""; position: absolute; inset: 0;
    background: radial-gradient(ellipse at 50% 70%, rgba(0,0,0,0) 30%, rgba(0,0,0,.55) 100%);
}
.hang { transform-origin: top center; animation: sway 3.2s ease-in-out infinite alternate; animation-delay: var(--d); }
@keyframes sway { from { transform: rotate(-.6deg); } to { transform: rotate(.6deg); } }
.scene-owner { position: absolute; left: 50%; transform: translateX(-50%); bottom: 34px; z-index: 1; filter: drop-shadow(0 6px 10px rgba(0,0,0,.5)); }
.scene-intro .scene-owner { width: 200px; height: 200px; bottom: 18px; }
.scene-game .scene-owner { width: 136px; height: 136px; bottom: -14px; left: 22%; }
.scene-crowd { bottom: -2px; height: 34%; z-index: 2; pointer-events: none; }
.scene-game .scene-crowd { height: 17%; }
.scene-crowd svg { width: 100%; height: 100%; display: block; }
.bubble-down { text-align: center; margin-top: -4px; }
.bubble-down::before {
    content: ""; position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
    border: 10px solid transparent; border-bottom-color: var(--ink); border-top: 0;
}
.bubble-scene {
    position: absolute; z-index: 3; right: 10px; top: 52px; width: 54%;
    font-size: 16px; padding: 8px 12px; min-height: 0;
}
.bubble-scene::before {
    content: ""; position: absolute; left: -12px; top: 18px;
    border: 9px solid transparent; border-right-color: var(--ink); border-left: 0;
}
.sign-compact { padding: 10px 14px; }
.sign-compact .sign-title { font-size: clamp(40px, 13vw, 58px); }
.sign-compact .sign-tag { font-size: 16px; margin-top: 2px; }
