:root {
  --ink: #221c3d; --night: #0d0f2b; --indigo: #232457; --moon: #fff3c4; --lantern: #ffb45a;
  --red: #e65a5a; --yellow: #f7c948; --green: #59b37a; --blue: #4a7fd6; --pink: #ef8fb4;
  --paper: #fff8ea; --sx: 0px; --sw: 390px; --u: 390px; --cam: 0;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--moon);
  font-family: 'Gowun Dodum', 'Apple SD Gothic Neo', 'Noto Sans KR', system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
button:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
.hidden { display: none !important; }
#sky { position: fixed; inset: 0; z-index: 0; }

#stage { position: fixed; top: 0; bottom: 0; left: var(--sx); width: var(--sw); z-index: 1; }
#creatures { position: absolute; inset: 0; pointer-events: none; }

/* ---------- creatures ---------- */
.creature { position: absolute; transform: translate(-50%, -88%) translateX(calc(var(--cam) * var(--d, .5) * 1px));
  transition: opacity .6s ease, filter .6s ease; opacity: 0; --lvl: 0; }
.creature.show { opacity: 1; }
.creature::before { content: ''; position: absolute; left: 12%; right: 12%; bottom: -3%; height: 12%; border-radius: 50%;
  background: radial-gradient(ellipse at 50% 40%, rgba(12,10,32,.75), rgba(12,10,32,0) 70%); }
.creature.floaty::before { display: none; }
.creature .body { transform-origin: 50% 90%; animation: breathe 3.4s ease-in-out infinite; }
.creature svg { width: 100%; height: auto; display: block; overflow: visible; filter: drop-shadow(0 4px 0 rgba(10,8,30,.35)); }
.creature .eo, .creature .mo { display: none; }
.creature.awake .eo { display: inline; } .creature.awake .ec { display: none; }
.creature.sing .mo { display: inline; } .creature.sing .mc { display: none; }
.creature:not(.awake) { filter: saturate(.55) brightness(.78); }
.creature.awake .body { animation: perk .5s cubic-bezier(.3,1.8,.5,1) both, breathe 2.2s .5s ease-in-out infinite; }
.creature.sing .body { animation: none; transform: scale(calc(1 + var(--lvl) * .22), calc(1 + var(--lvl) * .32)) rotate(calc(var(--lvl) * 6deg)); transition: transform .05s linear; }
.creature .zzz { position: absolute; right: -6%; top: -4%; font-family: Jua, sans-serif; color: #cfd2ff; font-size: calc(var(--sw) * .04);
  animation: zz 2.6s ease-in-out infinite; pointer-events: none; }
.creature.awake .zzz { display: none; }
.creature.peek { opacity: .55; }
.creature.peek .body { animation: peek 1.2s ease-in-out infinite; }
.creature.rise { animation: rise .9s cubic-bezier(.3,1.5,.5,1) both; }
.creature .glow { transition: opacity .3s; opacity: .15; }
.creature.awake .glow { opacity: 1; animation: glow 1.4s ease-in-out infinite; }
.creature.ear .body { animation: ear 1.2s ease-in-out infinite; }
.creature.dance .body { animation: dance .625s ease-in-out infinite alternate; }
.creature.kid .hands { opacity: 0; transition: opacity .2s; }
.creature.kid.sing .hands, .creature.kid.calling .hands { opacity: 1; }
@keyframes breathe { 50% { transform: scale(1.03, .97); } }
@keyframes perk { 0% { transform: scale(.85, 1.2) translateY(6%); } 100% { transform: none; } }
@keyframes zz { 0% { opacity: 0; transform: translate(0, 10px) scale(.7); } 40% { opacity: 1; } 100% { opacity: 0; transform: translate(10px, -16px) scale(1.1); } }
@keyframes peek { 50% { transform: translateY(-6%) rotate(-4deg); } }
@keyframes rise { 0% { opacity: 0; transform: translate(-50%, -40%) scale(.4); } 100% { opacity: 1; } }
@keyframes glow { 50% { opacity: .55; } }
@keyframes ear { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg) translateY(-3%); } }
@keyframes dance { from { transform: translateY(0) rotate(-6deg); } to { transform: translateY(-10%) rotate(6deg) scale(1.05); } }

/* ---------- word card ---------- */
#wordcard { position: absolute; left: 50%; top: calc(var(--safe-t) + 6.5%); transform: translateX(-50%); z-index: 3;
  background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 22px 26px 20px 28px;
  padding: 10px 22px 12px; display: flex; align-items: center; gap: 12px; box-shadow: 0 6px 0 rgba(10,8,30,.45);
  max-width: 92%; animation: cardin .6s cubic-bezier(.3,1.6,.5,1) both; }
#wordcard::after { content: ''; position: absolute; left: 22%; bottom: -16px; width: 22px; height: 22px; background: var(--paper);
  border-right: 3px solid var(--ink); border-bottom: 3px solid var(--ink); transform: rotate(35deg) skew(10deg); border-radius: 0 0 6px 0; }
#wordcard .pic { font-size: calc(var(--u) * .1); line-height: 1; }
#wordcard .ko { font-family: Jua, sans-serif; font-size: calc(var(--u) * .12); line-height: 1.05; white-space: nowrap; letter-spacing: .02em; }
#wordcard.long .ko { font-size: calc(var(--u) * .085); white-space: normal; }
#wordcard .ko span { display: inline-block; animation: ripple .9s ease-in-out both; }
#wordcard .ko span.sp { width: .3em; }
#wordcard.again .ko span { animation: ripple .9s ease-in-out both; }
@keyframes ripple { 0% { transform: translateY(0) scale(1); color: var(--ink); } 30% { transform: translateY(-28%) scale(1.25); color: var(--red); } 60% { transform: translateY(6%) scale(.95); } 100% { transform: none; } }
@keyframes cardin { 0% { opacity: 0; transform: translateX(-50%) scale(.5) rotate(-6deg); } 100% { opacity: 1; transform: translateX(-50%); } }

#bubble { position: absolute; z-index: 4; width: calc(var(--sw) * .13); height: calc(var(--sw) * .13); border-radius: 50%;
  background: var(--paper); color: var(--ink); border: 3px solid var(--ink); font-family: Jua, sans-serif; font-size: calc(var(--sw) * .09);
  display: grid; place-items: center; animation: bob 1s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(6deg); } }
#hint { position: absolute; left: 50%; top: 45%; transform: translateX(-50%); z-index: 3; background: rgba(20,24,60,.75); border: 2px dashed #9af0dc;
  color: #c8fff2; border-radius: 18px; padding: 6px 14px; font-family: Jua, sans-serif; font-size: calc(var(--sw) * .05); display: flex; gap: 8px; align-items: center;
  animation: fadebob 3.5s ease-in-out both; }
#hint .hint-bug { width: 24px; height: 24px; border-radius: 50%; background: radial-gradient(#fff59a, #f7e64a 40%, rgba(247,230,74,0) 70%); animation: glow 1s infinite; }
@keyframes fadebob { 0% { opacity: 0; } 15%, 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- lanterns progress ---------- */
#lanterns { position: absolute; top: calc(var(--safe-t) + 14px); left: 50%; transform: translateX(-50%); display: flex; gap: 8px; z-index: 2; }
#lanterns i { width: 14px; height: 18px; border-radius: 7px 7px 8px 8px; background: #3b3a70; border: 2px solid #15132e; position: relative; transition: all .4s; }
#lanterns i::before { content: ''; position: absolute; left: 50%; top: -7px; width: 2px; height: 6px; background: #15132e; }
#lanterns i.lit { background: var(--lantern); box-shadow: 0 0 14px 4px rgba(255,180,90,.55); }
#lanterns i.now { animation: bob 1.2s infinite; }
#classbadge { position: absolute; top: calc(var(--safe-t) + 46px); left: 50%; transform: translateX(-50%); font-size: 18px; opacity: .8; z-index: 2; }

/* ---------- duet / capsule ---------- */
#duet, #capsule { position: absolute; left: 50%; top: 60%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; z-index: 3;
  background: rgba(13,15,43,.55); padding: 8px 14px; border-radius: 26px; border: 2px solid rgba(255,243,196,.35); }
#duet .who, #capsule .who { width: calc(var(--sw) * .16); height: calc(var(--sw) * .16); border-radius: 50%; background: var(--paper); border: 3px solid var(--ink);
  display: grid; place-items: center; overflow: hidden; transition: transform .2s, box-shadow .2s; opacity: .6; }
#duet .who svg, #capsule .who svg { width: 92%; }
#duet .who.on, #capsule .who.on { transform: scale(1.18); box-shadow: 0 0 0 5px var(--yellow); opacity: 1; }
#duet .arrow, #capsule .arrow { font-size: 22px; color: var(--moon); }
#capsule .who { position: relative; }
#capsule .who span { position: absolute; bottom: 2px; font-family: Jua, sans-serif; color: var(--ink); font-size: 13px; background: var(--yellow); border-radius: 8px; padding: 0 5px; }
#capsule .then svg { width: 62%; margin-top: 10%; }

/* ---------- hold button ---------- */
#hold { position: absolute; left: 50%; bottom: calc(var(--safe-b) + 3.5%); width: calc(var(--u) * .31); height: calc(var(--u) * .31);
  transform: translateX(-50%); z-index: 5; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #ff8a8a, var(--red) 60%, #b8394a);
  border: 4px solid var(--ink); box-shadow: 0 8px 0 #7a2238, 0 0 0 8px rgba(255,243,196,.12); touch-action: none; transition: transform .1s, box-shadow .1s; }
#hold svg { width: 100%; height: 100%; }
#hold .mic rect { fill: var(--moon); stroke: var(--ink); stroke-width: 3; }
#hold .mic path { fill: none; stroke: var(--moon); stroke-width: 5; stroke-linecap: round; }
#hold .hold-ring { fill: none; stroke: rgba(255,243,196,.0); stroke-width: 4; }
#hold.ready { animation: pulse 1.6s ease-in-out infinite; }
#hold.down { transform: translateX(-50%) translateY(6px) scale(.96); box-shadow: 0 2px 0 #7a2238, 0 0 0 calc(10px + var(--lvl, 0) * 60px) rgba(255,225,150,.25); animation: none; }
#hold.down .hold-ring { stroke: var(--moon); stroke-dasharray: 6 8; animation: spin 2s linear infinite; transform-origin: 50% 50%; }
#hold.wait { filter: grayscale(.7) brightness(.7); }
@keyframes pulse { 50% { box-shadow: 0 8px 0 #7a2238, 0 0 0 18px rgba(255,243,196,.18); transform: translateX(-50%) scale(1.04); } }
@keyframes spin { to { transform: rotate(360deg); } }
#ghost { position: absolute; left: 56%; bottom: calc(var(--safe-b) + 1%); width: calc(var(--sw) * .17); z-index: 6; pointer-events: none;
  animation: ghost 2.4s ease-in-out infinite; filter: drop-shadow(0 4px 6px rgba(0,0,0,.5)); }
@keyframes ghost { 0% { transform: translate(40%, 30%); opacity: 0; } 20% { opacity: .95; transform: translate(0, 0); } 30%, 75% { transform: translate(-8%, 8%) scale(.92); opacity: .95; } 90%, 100% { transform: translate(30%, 30%); opacity: 0; } }

/* ---------- choices ---------- */
#choices { position: absolute; left: 0; right: 0; bottom: calc(var(--safe-b) + 4%); display: flex; justify-content: center; align-items: center; gap: 14px; z-index: 5; }
.round { width: calc(var(--sw) * .2); height: calc(var(--sw) * .2); border-radius: 50%; background: var(--paper); color: var(--ink); border: 4px solid var(--ink);
  box-shadow: 0 6px 0 rgba(10,8,30,.6); display: grid; place-items: center; animation: popin .45s cubic-bezier(.3,1.7,.5,1) both; font-size: calc(var(--sw) * .08); }
.round svg { width: 62%; height: 62%; }
.round.small { width: calc(var(--sw) * .15); height: calc(var(--sw) * .15); }
.round.big { width: calc(var(--sw) * .26); height: calc(var(--sw) * .26); background: var(--yellow); }
.round:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(10,8,30,.6); }
@keyframes popin { from { transform: scale(.3); opacity: 0; } }

/* ---------- corner buttons ---------- */
.corner-btn { position: absolute; top: calc(var(--safe-t) + 8px); width: 52px; height: 52px; z-index: 6; }
.corner-btn svg { width: 100%; height: 100%; }
#albumbtn { left: 8px; }
#albumcount { position: absolute; right: -4px; bottom: -2px; background: var(--red); color: #fff; border-radius: 10px; font-family: Jua, sans-serif; font-size: 12px; padding: 1px 6px; border: 2px solid var(--ink); }
#albumcount:empty { display: none; }
#mutebtn { right: 64px; }
#mutebtn .off { display: none; } #mutebtn.muted .off { display: inline; } #mutebtn.muted .on { display: none; }
#cornerbtn { position: fixed; top: calc(var(--safe-t) + 10px); left: calc(var(--sx) + var(--sw) - 56px); width: 48px; height: 48px; z-index: 22; opacity: .75; touch-action: none; }
#cornerbtn svg { width: 100%; height: 100%; }
#cornerbtn .fill { fill: rgba(255,255,255,.08); stroke: var(--moon); stroke-width: 2.5; stroke-dasharray: 126; stroke-dashoffset: 126; transform: rotate(-90deg); transform-origin: 50% 50%; }
#cornerbtn.holding .fill { stroke-dashoffset: 0; transition: stroke-dashoffset 1.6s linear; }
#cornerbtn span { position: absolute; left: 0; right: 0; bottom: -14px; font-size: 11px; text-align: center; color: var(--moon); }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.paper { background: rgba(10,10,35,.88); }
.sheet { max-width: 560px; margin: calc(var(--safe-t) + 20px) auto 40px; padding: 22px 20px 26px; background: var(--paper); color: var(--ink);
  border: 3px solid var(--ink); border-radius: 24px; box-shadow: 0 8px 0 rgba(0,0,0,.35); -webkit-user-select: text; user-select: text; width: calc(100% - 24px); }
.sheet.wide { max-width: 720px; }
.sheet h1 { font-family: Jua, sans-serif; font-weight: 400; font-size: 28px; margin: 0 0 8px; line-height: 1.2; }
.sheet h1 small, .sheet h2 small { font-size: .6em; opacity: .7; margin-left: 6px; }
.sheet h2 { font-family: Jua, sans-serif; font-weight: 400; font-size: 20px; margin: 18px 0 6px; }
.sheet p, .sheet li { font-size: 15.5px; line-height: 1.5; }
.sheet ul { padding-left: 20px; margin: 6px 0; }
.sheet .lead { font-size: 16.5px; }
.sheet .fine { font-size: 13px; opacity: .78; }
.sheet .two { display: grid; grid-template-columns: 1fr; gap: 4px 18px; }
@media (min-width: 640px) { .sheet .two { grid-template-columns: 1fr 1fr; } }
.primary { display: block; width: 100%; margin-top: 16px; padding: 16px; font-family: Jua, sans-serif; font-size: 20px; color: var(--ink);
  background: var(--yellow); border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 5px 0 var(--ink); }
.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.sheet button:not(.primary):not(.close):not(.mini) { padding: 9px 14px; border: 2px solid var(--ink); border-radius: 12px; background: #fff; font-size: 14px; margin: 4px 6px 4px 0; }
.sheet .danger { background: #ffe1e1 !important; color: #8a1f2b; margin-top: 10px !important; }
.sheet .danger.confirm { background: #e65a5a !important; color: #fff; }
.howto { background: #fff; border: 2px dashed var(--ink); border-radius: 14px; padding: 6px 14px; }
.howto h3 { font-size: 15px; margin: 10px 0 2px; }
.howto ol { margin: 4px 0 8px; padding-left: 20px; }
.close { position: absolute; right: 12px; top: 10px; width: 44px; height: 44px; border-radius: 50%; background: var(--paper); color: var(--ink); border: 3px solid var(--ink); font-size: 20px; }
.corner-head { position: relative; padding-right: 50px; }
.corner-head .close { top: -4px; right: 0; }
.list { display: flex; flex-direction: column; gap: 6px; }
.list .item { display: flex; align-items: center; gap: 8px; background: #fff; border: 2px solid #e4dccb; border-radius: 12px; padding: 6px 8px; }
.list .item .w { font-family: Jua, sans-serif; font-size: 17px; flex: 1; min-width: 0; }
.list .item .d { font-size: 12px; opacity: .65; }
.list .item .badge { font-size: 11px; background: var(--yellow); border-radius: 8px; padding: 1px 6px; }
.list .item button.mini { min-width: 40px; height: 36px; border: 2px solid var(--ink); border-radius: 10px; background: #fff; font-size: 15px; padding: 0 8px; }
.list .empty { font-size: 14px; opacity: .6; padding: 6px; }
.row { display: flex; flex-wrap: wrap; align-items: center; }
textarea, input[readonly] { width: 100%; font: inherit; font-size: 16px; padding: 8px; border: 2px solid var(--ink); border-radius: 10px; margin: 6px 0; -webkit-user-select: text; user-select: text; }
.mono { font-family: ui-monospace, Menlo, monospace; white-space: pre-wrap; }

/* title */
#title { display: grid; place-items: center; background: radial-gradient(ellipse at 50% 40%, rgba(35,36,87,.75), rgba(13,15,43,.92)); }
.title-wrap { text-align: center; padding-bottom: 8vh; }
.logo { font-family: Jua, sans-serif; font-weight: 400; font-size: min(17vw, 76px); margin: 0 0 4vh; color: var(--moon); text-shadow: 0 5px 0 var(--ink), 0 0 30px rgba(255,243,196,.35); }
.logo span { display: inline-block; animation: logowave 2.8s ease-in-out infinite; }
@keyframes logowave { 0%, 40%, 100% { transform: none; } 15% { transform: translateY(-14%) scale(1.12); } 28% { transform: translateY(4%); } }
.logo span:nth-child(2) { animation-delay: .15s; } .logo span:nth-child(3) { animation-delay: .3s; }
.logo span:nth-child(4) { animation-delay: .6s; } .logo span:nth-child(5) { animation-delay: .75s; } .logo span:nth-child(6) { animation-delay: .9s; }
#todaycaller { width: 34vw; max-width: 150px; margin: 0 auto 3vh; animation: dance 1.2s ease-in-out infinite alternate; }
#todaycaller svg { width: 100%; filter: drop-shadow(0 5px 0 rgba(0,0,0,.4)); }
.play { width: 110px; height: 110px; border-radius: 50%; background: var(--yellow); color: var(--ink); border: 4px solid var(--ink); box-shadow: 0 8px 0 var(--ink); animation: pulse2 1.6s ease-in-out infinite; }
.play svg { width: 56%; margin-left: 8%; }
@keyframes pulse2 { 50% { transform: scale(1.07); } }

/* album */
#album { background: rgba(13,15,43,.94); padding: calc(var(--safe-t) + 12px) 12px 30px; }
.album-head { position: relative; max-width: 620px; margin: 0 auto; }
.album-head h2 { font-family: Jua, sans-serif; font-weight: 400; font-size: 28px; margin: 6px 0 14px; text-align: center; }
.album-head .close { top: 0; right: 0; }
#albumgrid { max-width: 620px; margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 560px) { #albumgrid { grid-template-columns: repeat(4, 1fr); } }
.acard { background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; padding: 8px 6px 6px; color: var(--ink); text-align: center; position: relative; box-shadow: 0 4px 0 rgba(0,0,0,.4); }
.acard svg { width: 82%; height: auto; }
.acard .nm { font-family: Jua, sans-serif; font-size: 15px; }
.acard.locked { background: #2b2c5c; border-color: #15132e; }
.acard.locked svg { filter: brightness(0) opacity(.55); }
.acard.locked .nm { color: #9fa3e0; font-size: 22px; letter-spacing: 2px; }
.acard .eo { display: inline; } .acard .ec { display: none; } .acard .mo { display: none; }
.acard.bounce { animation: dance .3s 2 alternate; }

/* new friend */
#newfriend { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; pointer-events: none; background: rgba(13,15,43,.4); }
#newfriend .card { background: var(--paper); color: var(--ink); border: 4px solid var(--ink); border-radius: 26px; padding: 16px 26px; text-align: center;
  animation: friend 1.8s cubic-bezier(.3,1.6,.5,1) both; box-shadow: 0 0 0 10px rgba(247,201,72,.35), 0 10px 0 rgba(0,0,0,.4); }
#newfriend .art { width: 150px; margin: 0 auto; }
#newfriend .art .eo { display: inline; } #newfriend .art .ec { display: none; } #newfriend .art .mo { display: none; }
#newfriend .label { font-family: Jua, sans-serif; font-size: 18px; color: var(--red); }
#newfriend .name { font-family: Jua, sans-serif; font-size: 30px; }
@keyframes friend { 0% { transform: scale(.2) rotate(-15deg); opacity: 0; } 18% { transform: scale(1.05); opacity: 1; } 85% { transform: scale(1); opacity: 1; } 100% { transform: scale(.9) translateY(-40px); opacity: 0; } }

/* song */
#song { background: radial-gradient(ellipse at 50% 45%, #2a2b62, #0d0f2b 75%); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(var(--safe-t) + 10px) 10px calc(var(--safe-b) + 20px); }
.song-title { font-family: Jua, sans-serif; font-weight: 400; font-size: 32px; margin: 0 0 10px; }
#songstage { position: relative; width: min(92vw, 420px); height: min(48vh, 360px); }
#songstage .creature { opacity: 1; }
#songstage .note { position: absolute; font-size: 26px; animation: note 1.6s ease-out forwards; pointer-events: none; }
@keyframes note { from { transform: translateY(0) rotate(0); opacity: 1; } to { transform: translateY(-120px) rotate(30deg); opacity: 0; } }
#songbar { width: min(80vw, 360px); height: 10px; background: rgba(255,255,255,.12); border-radius: 6px; overflow: hidden; margin: 14px 0; }
#songbar div { height: 100%; width: 0; background: var(--yellow); }
.song-actions { display: flex; gap: 18px; align-items: center; }
.song-busy #songplay, .song-busy #songnext { opacity: .35; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

body.no-corner #cornerbtn { display: none; }
