:root {
  --bg1: #f6f1ea; --bg2: #e9e0d4;
  --ink: #3b3127; --ink2: #7a6c5d; --line: #e6dccd;
  --card: #fffdf9; --accent: #d9734e; --accent2: #2f6b4f; --gold: #f2b544; --red: #e0453a;
  --r: 18px; --shadow: 0 10px 30px rgba(59, 49, 39, .14);
  font-family: "Pretendard Variable", Pretendard, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; color: var(--ink); background: radial-gradient(120% 90% at 50% 30%, var(--bg1), var(--bg2)); }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

/* 위 정보 */
#hud { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; gap: 8px; align-items: center; pointer-events: none; z-index: 5; }
.pill { pointer-events: auto; background: rgba(255, 253, 249, .92); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: 14px; box-shadow: 0 4px 14px rgba(59, 49, 39, .08); backdrop-filter: blur(6px); white-space: nowrap; }
.theme-pill { overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1 1 auto; max-width: max-content; }
.coin-pill { margin-left: auto; border: 1px solid #f0d58f; background: #fff7e0; }
.owl-tip { position: fixed; left: 12px; right: 12px; top: calc(58px + env(safe-area-inset-top)); margin: 0 auto; max-width: 460px; z-index: 5; background: var(--card); border-radius: 16px; padding: 12px 14px 12px 54px; box-shadow: var(--shadow); font-size: 15px; line-height: 1.5; animation: pop .3s ease; }
.owl-tip::before { content: "🦉"; position: absolute; left: 12px; top: 10px; font-size: 30px; }

/* 아래 바로가기 */
#dock { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 6px; background: rgba(255, 253, 249, .94); border: 1px solid var(--line); border-radius: 22px; padding: 6px; box-shadow: var(--shadow); z-index: 5; }
#dock button { position: relative; border: 0; background: transparent; border-radius: 16px; padding: 7px 10px 5px; font-size: 22px; display: flex; flex-direction: column; align-items: center; min-width: 72px; }
#dock button span { white-space: nowrap; font-size: 11px; font-weight: 700; color: var(--ink2); margin-top: 2px; }
#dock button:active { background: #f2ebe0; }
.dot { position: absolute; top: 4px; right: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 2px #fff; }

/* 첫 화면 */
.screen { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(246, 241, 234, .55); backdrop-filter: blur(3px); }
.start-card { position: relative; width: 100%; max-width: 380px; background: var(--card); border-radius: 28px; padding: 30px 22px 22px; box-shadow: var(--shadow); text-align: center; animation: pop .35s ease; }
.logo { font-size: 54px; }
h1 { margin: 6px 0 2px; font-size: 30px; letter-spacing: -0.5px; }
h2 { margin: 6px 0 4px; font-size: 22px; }
h3 { margin: 0 0 12px; font-size: 18px; }
.sub { margin: 0 0 18px; color: var(--ink2); font-size: 15px; }
.btn { display: block; width: 100%; border: 0; border-radius: 16px; padding: 14px; font-weight: 800; font-size: 16px; margin-top: 10px; background: #f2ebe0; }
.btn.big { font-size: 18px; padding: 17px; }
.btn.small { font-size: 14px; padding: 10px; }
.btn.primary { background: var(--ink); color: #fff; }
.btn.green { background: var(--accent2); color: #fff; }
.btn.orange { background: var(--accent); color: #fff; }
.btn.kakao { background: #fee500; color: #191600; }
.btn.ghost { background: transparent; border: 1.5px dashed var(--line); color: var(--ink2); }
.btn:disabled { opacity: .45; }
.btn:active:not(:disabled) { transform: scale(.98); }
.back { position: absolute; left: 14px; top: 12px; border: 0; background: #f2ebe0; width: 38px; height: 38px; border-radius: 50%; font-size: 18px; }
.code-input { width: 100%; font-size: 30px; letter-spacing: 8px; text-align: center; text-transform: uppercase; border: 2px solid var(--line); border-radius: 16px; padding: 12px; font-weight: 800; outline: none; background: #fff; }
.code-input:focus { border-color: var(--ink); }
.kid-list { display: grid; gap: 10px; margin-top: 10px; }
.kid-list button { border: 2px solid var(--line); background: #fff; border-radius: 18px; padding: 16px; font-size: 20px; font-weight: 800; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 14px 0 18px; }
.pin-dots i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--ink); }
.pin-dots i.on { background: var(--ink); }
.pin-dots.shake { animation: shake .4s; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-pad button { border: 0; background: #f2ebe0; border-radius: 18px; padding: 16px 0; font-size: 24px; font-weight: 800; }
.pin-pad button:active { background: #e6dccd; }
.err { color: var(--red); min-height: 20px; font-size: 14px; margin: 10px 0 0; }

/* 아래에서 올라오는 창 */
#dim { position: fixed; inset: 0; background: rgba(40, 32, 24, .28); z-index: 9; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px; max-height: 86vh; overflow-y: auto; background: var(--card); border-radius: 26px 26px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); z-index: 10; box-shadow: 0 -10px 40px rgba(59, 49, 39, .18); animation: up .28s ease; overscroll-behavior: contain; }
.sheet.small { max-width: 360px; bottom: calc(90px + env(safe-area-inset-bottom)); border-radius: 26px; left: 12px; right: 12px; }
.sheet .close { position: absolute; right: 14px; top: 14px; border: 0; background: #f2ebe0; width: 36px; height: 36px; border-radius: 50%; font-size: 16px; }
.elev-btns { display: grid; gap: 8px; }
.elev-btns button { position: relative; display: flex; align-items: center; gap: 14px; border: 0; background: #f4efe7; border-radius: 16px; padding: 10px 14px; font-size: 24px; font-weight: 900; text-align: left; }
.elev-btns button small { font-size: 15px; font-weight: 700; color: var(--ink2); }
.elev-btns button:disabled { opacity: .45; }
.elev-btns button.cur { background: #ffe9b8; }
.elev-btns .dot { top: 50%; right: 16px; transform: translateY(-50%); }

/* 미션 보드 */
.board-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; padding-right: 40px; }
.board-head .tag { font-size: 12px; font-weight: 800; padding: 4px 9px; border-radius: 99px; color: #fff; }
.steps { display: grid; gap: 10px; }
.step { border: 1.5px solid var(--line); border-radius: 18px; padding: 14px; background: #fff; }
.step.done { background: #f3f8f2; border-color: #cfe3cc; }
.step.locked { opacity: .5; }
.step h4 { margin: 0 0 6px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.step h4 .n { width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; }
.step.done h4 .n { background: var(--accent2); }
.step p { margin: 4px 0; color: var(--ink2); font-size: 14px; line-height: 1.5; }
.field { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 12px; font: inherit; font-size: 16px; margin-top: 8px; outline: none; background: #fff; }
.field:focus { border-color: var(--ink); }
.photo-prev { width: 100%; max-height: 220px; object-fit: contain; border-radius: 12px; margin-top: 8px; background: #f4efe7; }
.qcard { margin: 10px 0; padding: 18px 16px; border-radius: 18px; background: linear-gradient(135deg, #fff4dc, #ffe2c4); font-size: 18px; font-weight: 800; line-height: 1.5; text-align: center; box-shadow: inset 0 0 0 2px #f6d59a; animation: flip .5s ease; }
.rec { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.rec .time { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 20px; min-width: 64px; }
.rec .live { width: 12px; height: 12px; border-radius: 50%; background: var(--red); animation: blink 1s infinite; }
audio { width: 100%; margin-top: 8px; }
.status-box { text-align: center; padding: 18px; border-radius: 18px; background: #f4efe7; margin-top: 10px; }
.status-box .big { font-size: 40px; }
.stars { font-size: 26px; letter-spacing: 2px; color: var(--gold); }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

/* ATM */
.atm-screen { background: linear-gradient(160deg, #2f5d8a, #1f3f63); color: #fff; border-radius: 20px; padding: 20px; text-align: center; margin-bottom: 14px; }
.atm-screen .bal { font-size: 40px; font-weight: 900; margin: 4px 0; }
.atm-screen .won { opacity: .85; }
.list { display: grid; gap: 6px; margin-top: 8px; }
.list .it { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; background: #f8f4ee; border-radius: 12px; font-size: 14px; }
.plus { color: var(--accent2); font-weight: 800; } .minus { color: var(--red); font-weight: 800; }
.sec-title { font-size: 14px; font-weight: 800; color: var(--ink2); margin: 16px 0 6px; }

/* 편지함·관리 */
.letter { border-radius: 18px; padding: 14px; background: #fff; border: 1.5px solid var(--line); margin-bottom: 10px; }
.letter.new { border-color: #f6c26b; background: #fffaf0; }
.letter .top { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink2); }
.letter .ttl { font-weight: 800; font-size: 16px; margin: 4px 0; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -2px 12px; padding: 2px 40px 4px 2px; }
.tabs button { flex: none; border: 0; background: #f2ebe0; border-radius: 99px; padding: 9px 14px; font-weight: 800; font-size: 14px; position: relative; }
.tabs button.on { background: var(--ink); color: #fff; }
.tabs .cnt { margin-left: 4px; background: var(--red); color: #fff; border-radius: 99px; padding: 0 6px; font-size: 12px; }
.review { border: 1.5px solid var(--line); border-radius: 18px; padding: 14px; margin-bottom: 12px; background: #fff; }
.review img { width: 100%; max-height: 260px; object-fit: contain; border-radius: 12px; background: #f4efe7; }
.star-pick { display: flex; gap: 4px; justify-content: center; margin: 8px 0; }
.star-pick button { border: 0; background: none; font-size: 34px; color: #e0d6c6; padding: 0 2px; }
.star-pick button.on { color: var(--gold); }
.stk-pick { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.stk-pick button { border: 2px solid transparent; background: #f4efe7; border-radius: 12px; font-size: 24px; padding: 4px 8px; }
.stk-pick button.on { border-color: var(--ink); background: #fff; }
.kv { display: grid; grid-template-columns: 1fr 110px; gap: 8px; align-items: center; font-size: 14px; }
.kv input { width: 100%; border: 1.5px solid var(--line); border-radius: 10px; padding: 8px; font: inherit; text-align: right; }
.note { font-size: 13px; color: var(--ink2); line-height: 1.5; background: #f8f4ee; border-radius: 12px; padding: 10px 12px; margin-top: 10px; }
.look-opts { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 12px; }
.look-opts button { border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 8px 12px; font-weight: 700; font-size: 14px; }
.look-opts button.on { border-color: var(--ink); background: #fff4dc; }
.look-opts .sw { width: 22px; height: 22px; border-radius: 50%; display: inline-block; vertical-align: middle; }

/* 효과 */
#fade { position: fixed; inset: 0; background: #f6f1ea; opacity: 0; pointer-events: none; z-index: 15; transition: opacity .35s; }
#fade.on { opacity: 1; }
#toast { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); background: rgba(59, 49, 39, .92); color: #fff; padding: 14px 20px; border-radius: 16px; font-weight: 700; z-index: 30; max-width: 86vw; text-align: center; line-height: 1.5; animation: pop .25s ease; }
.coin-rain { position: fixed; top: -40px; font-size: 30px; z-index: 25; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
#toast { animation-name: toastpop; } @keyframes toastpop { from { opacity: 0; transform: translate(-50%, -40%); } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes flip { from { transform: rotateY(90deg); } }
@keyframes blink { 50% { opacity: .2; } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@media (max-width: 380px) { #dock button { min-width: 58px; padding: 6px 6px 4px; } .pill { font-size: 13px; padding: 7px 11px; } }

/* 책장 고르기·독후감 */
.src-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.src-pick button { border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 9px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 13px; }
.src-pick button small { color: var(--ink2); font-size: 11px; }
.src-pick button.on { border-color: var(--ink); background: #fff4dc; }
.how { border: 1.5px dashed var(--line); border-radius: 14px; padding: 10px 12px; margin-top: 10px; background: #fffdf9; }
.how.ok { border-style: solid; border-color: #cfe3cc; background: #f6faf5; }
.how h5 { margin: 0 0 4px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.how .chk { font-size: 12px; color: var(--accent2); font-weight: 800; }
.essay { resize: vertical; line-height: 1.6; min-height: 120px; }
.essay-view { white-space: pre-wrap; line-height: 1.7; font-size: 15px; background: #fffaf0; border: 1.5px solid #f3e2bd; border-radius: 14px; padding: 12px 14px; margin-top: 10px; max-height: 260px; overflow-y: auto; }
