:root {
  --bg: #07061a;
  --bg2: #120f33;
  --ink: #f4f1ff;
  --dim: #8f88b8;
  --line: rgba(255, 255, 255, 0.09);
  --pink: #ff2e88;
  --mint: #2affc6;
  --gold: #ffd23f;
  --violet: #8b5cff;
  --ice: #7fd8ff;
  --red: #ff4d4d;
  --orange: #ff8a3d;
  --display: "Black Han Sans", "Pretendard Variable", sans-serif;
  --arcade: "Bungee", "Black Han Sans", sans-serif;
  --body: "Pretendard Variable", -apple-system, "Apple SD Gothic Neo", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--body); overflow: hidden; }
body { -webkit-user-select: none; user-select: none; touch-action: manipulation; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

/* ---------- background ---------- */
#aurora { position: fixed; inset: 0; overflow: hidden; z-index: 0; }
#aurora i { position: absolute; width: 70vmax; height: 70vmax; border-radius: 50%; filter: blur(90px); opacity: 0.35; animation: drift 22s ease-in-out infinite alternate; }
#aurora i:nth-child(1) { background: #3b1fa8; left: -20vmax; top: -25vmax; }
#aurora i:nth-child(2) { background: #a3135f; right: -30vmax; top: 20vh; animation-duration: 28s; opacity: 0.25; }
#aurora i:nth-child(3) { background: #0a6b6a; left: 10vw; bottom: -40vmax; animation-duration: 34s; opacity: 0.3; }
@keyframes drift { to { transform: translate(8vmax, 6vmax) scale(1.15); } }
#snow { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 60; pointer-events: none; }
#flash { position: fixed; inset: 0; z-index: 61; pointer-events: none; opacity: 0; }

#app { position: relative; z-index: 2; height: 100dvh; max-width: 480px; margin: 0 auto; overflow: hidden; }
@media (min-width: 560px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); box-shadow: 0 0 120px rgba(139, 92, 255, 0.18); background: rgba(7, 6, 26, 0.35); }
}

.screen { position: absolute; inset: 0; display: none; flex-direction: column; overflow: hidden; }
.screen.active { display: flex; animation: screenIn 0.35s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes screenIn { from { opacity: 0; transform: scale(0.96); } }
.scroll { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; flex: 1; padding-bottom: calc(24px + var(--safe-bottom)); }
.scroll::-webkit-scrollbar { display: none; }

/* ---------- home ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: calc(14px + var(--safe-top)) 18px 6px; }
.brand { font-family: var(--arcade); font-size: 15px; letter-spacing: 1px; line-height: 1; }
.brand b { color: var(--pink); text-shadow: 0 0 12px var(--pink); }
.brand small { display: block; font-family: var(--mono); font-size: 10px; color: var(--dim); letter-spacing: 3px; margin-top: 4px; }
.iconbtn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); font-size: 18px; transition: transform .15s; }
.iconbtn:active { transform: scale(0.9); }
.topbar .right { display: flex; gap: 8px; }

.hero { text-align: center; padding: 4px 18px 0; }
.hero .date { font-family: var(--arcade); font-size: 12px; letter-spacing: 4px; color: var(--mint); text-shadow: 0 0 10px var(--mint); }
.hero h1 { font-family: var(--display); font-weight: 400; font-size: 34px; line-height: 1.05; margin: 6px 0 4px; letter-spacing: -0.5px; }
.hero h1 em { font-style: normal; background: linear-gradient(90deg, var(--gold), var(--pink), var(--violet)); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 0 18px rgba(255, 46, 136, 0.45)); }
.hero p { color: var(--dim); font-size: 13px; margin: 0; }

.tree-wrap { position: relative; margin: 6px auto 0; width: 100%; max-width: 380px; aspect-ratio: 1 / 1.02; }
.tree-wrap svg { width: 100%; height: 100%; overflow: visible; }
.tree-progress { text-align: center; font-family: var(--mono); font-size: 11px; color: var(--dim); letter-spacing: 2px; margin-top: -6px; }
.tree-progress b { color: var(--gold); font-size: 14px; }
.orn { cursor: pointer; transition: transform .2s; transform-box: fill-box; transform-origin: center; }
.orn:active { transform: scale(0.85); }
.orn circle.base { fill: #1a1640; stroke: rgba(255,255,255,0.18); stroke-width: 1.2; }
.orn.lit circle.base { fill: var(--c); stroke: #fff; filter: url(#glow); }
.orn.today circle.base { stroke: var(--gold); stroke-width: 2.2; animation: pulse 1.2s ease-in-out infinite; }
.orn text { font-family: var(--arcade); font-size: 9px; fill: rgba(255,255,255,0.35); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.orn.lit text { fill: #0b0820; }
@keyframes pulse { 50% { stroke-width: 4; stroke-opacity: .5; } }
.garland { fill: none; stroke: rgba(127, 216, 255, 0.22); stroke-width: 1.4; stroke-dasharray: 3 5; animation: march 6s linear infinite; }
.garland.lit { stroke: rgba(255, 210, 63, 0.75); filter: url(#glow); }
@keyframes march { to { stroke-dashoffset: -80; } }
.star { cursor: pointer; transform-box: fill-box; transform-origin: center; }
.star path { fill: #2a2550; stroke: rgba(255,255,255,.25); stroke-width: 1.5; }
.star.lit path { fill: var(--gold); stroke: #fff; filter: url(#glow); animation: spin 8s linear infinite; transform-box: fill-box; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }

.today-card { margin: 10px 16px 0; padding: 16px; border-radius: 22px; background: linear-gradient(135deg, rgba(255, 46, 136, 0.18), rgba(139, 92, 255, 0.18)); border: 1px solid rgba(255, 255, 255, 0.14); display: flex; align-items: center; gap: 14px; position: relative; overflow: hidden; cursor: pointer; }
.today-card::after { content: ""; position: absolute; inset: -50%; background: linear-gradient(115deg, transparent 40%, rgba(255,255,255,0.13) 50%, transparent 60%); animation: sheen 3.2s ease-in-out infinite; }
@keyframes sheen { from { transform: translateX(-60%); } to { transform: translateX(60%); } }
.today-card .num { font-family: var(--arcade); font-size: 34px; line-height: 1; color: var(--gold); text-shadow: 0 0 16px rgba(255, 210, 63, .7); min-width: 58px; text-align: center; }
.today-card .t1 { font-family: var(--mono); font-size: 10px; color: var(--mint); letter-spacing: 2px; }
.today-card .t2 { font-family: var(--display); font-size: 21px; margin: 2px 0; }
.today-card .t3 { font-size: 12px; color: #cfc8f2; }
.today-card .go { margin-left: auto; width: 46px; height: 46px; flex: none; border-radius: 50%; background: var(--gold); color: #1a1030; display: grid; place-items: center; font-size: 18px; box-shadow: 0 0 22px rgba(255, 210, 63, 0.6); }

.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 18px 10px; font-family: var(--arcade); font-size: 12px; letter-spacing: 2px; color: var(--dim); }
.doors { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; padding: 0 14px; perspective: 800px; }
.door { position: relative; aspect-ratio: 0.82; border-radius: 14px; background: linear-gradient(160deg, #1d1848, #120e30); border: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; transition: transform .18s; }
.door:active { transform: scale(0.92); }
.door .n { font-family: var(--arcade); font-size: 20px; line-height: 1; }
.door .ic { font-size: 13px; margin-top: 4px; opacity: .9; height: 16px; }
.door .st { font-size: 9px; letter-spacing: -1px; color: var(--gold); margin-top: 3px; height: 12px; }
.door.locked { opacity: .5; }
.door.locked .n { color: #6f68a0; }
.door.locked .ic { filter: grayscale(1); opacity: .5; }
.door.open { border-color: color-mix(in srgb, var(--c) 60%, transparent); box-shadow: inset 0 0 18px color-mix(in srgb, var(--c) 25%, transparent); }
.door.open .n { color: var(--c); text-shadow: 0 0 10px var(--c); }
.door.cleared { background: linear-gradient(160deg, color-mix(in srgb, var(--c) 35%, #1d1848), #120e30); }
.door.today::before { content: "TODAY"; position: absolute; top: 4px; font-family: var(--arcade); font-size: 7px; letter-spacing: 1px; color: #1a1030; background: var(--gold); padding: 1px 4px; border-radius: 4px; }
.door.new::after { content: ""; position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--pink); box-shadow: 0 0 8px var(--pink); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }
.door.opening { animation: doorOpen .55s cubic-bezier(.5, 0, .3, 1.4) forwards; z-index: 5; }
@keyframes doorOpen { 40% { transform: rotateY(-70deg) scale(1.1); } 100% { transform: rotateY(0) scale(1.4); opacity: 0; } }

.week-legend { display: flex; gap: 6px; justify-content: center; margin: 12px 0 0; flex-wrap: wrap; }
.week-legend span { font-size: 11px; color: var(--dim); padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line); }
.footer-note { text-align: center; color: #5d5788; font-size: 11px; margin: 22px 20px 6px; line-height: 1.6; }

/* ---------- intro ---------- */
.intro-inner { flex: 1; display: flex; flex-direction: column; padding: calc(14px + var(--safe-top)) 22px calc(22px + var(--safe-bottom)); position: relative; }
.intro-top { display: flex; justify-content: space-between; align-items: center; }
.intro-day { font-family: var(--arcade); font-size: 13px; letter-spacing: 3px; color: var(--c); text-shadow: 0 0 10px var(--c); }
.intro-center { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.intro-icon { font-size: 64px; width: 112px; height: 112px; border-radius: 32px; display: grid; place-items: center; background: radial-gradient(circle, color-mix(in srgb, var(--c) 40%, transparent), transparent 70%); border: 1px solid color-mix(in srgb, var(--c) 50%, transparent); margin-bottom: 18px; animation: float 3s ease-in-out infinite; font-family: var(--arcade); color: var(--c); }
@keyframes float { 50% { transform: translateY(-8px) rotate(-3deg); } }
.intro-code { font-family: var(--arcade); font-size: clamp(30px, 10vw, 44px); line-height: .95; color: var(--c); text-shadow: 0 0 24px var(--c), 3px 3px 0 rgba(255, 46, 136, 0.5); animation: slam .6s cubic-bezier(.2, 1.6, .4, 1); word-break: keep-all; }
@keyframes slam { from { transform: scale(2.4); opacity: 0; filter: blur(8px); } }
.intro-title { font-family: var(--display); font-size: 26px; margin: 12px 0 8px; }
.intro-tag { font-size: 16px; line-height: 1.5; color: #d9d3ff; margin: 0 0 22px; word-break: keep-all; }
.howto { padding: 14px 16px; border-radius: 16px; background: rgba(255, 255, 255, 0.05); border: 1px dashed rgba(255, 255, 255, 0.18); font-size: 14px; line-height: 1.5; word-break: keep-all; }
.howto b { font-family: var(--arcade); font-size: 10px; letter-spacing: 2px; color: var(--gold); display: block; margin-bottom: 4px; }
.best { margin-top: 12px; font-family: var(--mono); font-size: 12px; color: var(--dim); }
.best b { color: var(--gold); }
.btn-big { width: 100%; padding: 19px; border-radius: 20px; font-family: var(--arcade); font-size: 20px; letter-spacing: 2px; color: #170d2c; background: linear-gradient(90deg, var(--gold), #ffb03f); box-shadow: 0 8px 0 #b3761c, 0 0 40px rgba(255, 210, 63, 0.45); transition: transform .08s, box-shadow .08s; }
.btn-big:active { transform: translateY(6px); box-shadow: 0 2px 0 #b3761c, 0 0 30px rgba(255, 210, 63, 0.4); }
.btn-ghost { width: 100%; padding: 15px; border-radius: 18px; font-weight: 700; font-size: 15px; background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); }
.btn-row { display: flex; gap: 10px; }

/* ---------- play ---------- */
#hud { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-top)) 12px 8px; z-index: 5; }
#hud .hx { width: 36px; height: 36px; border-radius: 11px; background: rgba(255,255,255,.07); display: grid; place-items: center; font-size: 15px; flex: none; }
#hud .hs { flex: 1; min-width: 0; display: flex; gap: 6px; align-items: center; justify-content: flex-end; }
.chip { font-family: var(--arcade); font-size: 13px; padding: 7px 11px; border-radius: 11px; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.chip small { font-family: var(--mono); font-size: 9px; color: var(--dim); letter-spacing: 1px; }
.chip.score { color: var(--gold); min-width: 86px; justify-content: space-between; }
.chip.combo { color: var(--pink); }
.chip.combo.hot { animation: hot .3s; }
@keyframes hot { 50% { transform: scale(1.25); } }
.chip.time.low { color: var(--red); animation: blink .5s steps(2) infinite; }
.chip.label { font-family: var(--body); font-weight: 700; font-size: 12px; min-width: 0; flex-shrink: 1; overflow: hidden; text-overflow: ellipsis; display: block; }
@media (max-width: 400px) { .chip { font-size: 11.5px; padding: 6px 8px; gap: 4px; } .chip.score { min-width: 0; } .chip.score small { display: none; } #hud { gap: 6px; } }
#hud .tbar { position: absolute; left: 0; right: 0; top: calc(56px + var(--safe-top)); height: 3px; background: rgba(255,255,255,.06); }
#hud .tbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--mint), var(--gold)); transition: width .1s linear; }
#stage-wrap { flex: 1; position: relative; padding-bottom: var(--safe-bottom); }
#stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
#stage.shake { animation: shake .35s; }
@keyframes shake { 10%, 90% { transform: translate(-2px, 1px); } 20%, 80% { transform: translate(4px, -2px); } 30%, 50%, 70% { transform: translate(calc(var(--sh) * -1), 2px); } 40%, 60% { transform: translate(var(--sh), -2px); } }
.floattext { position: absolute; pointer-events: none; font-family: var(--arcade); font-size: 20px; white-space: nowrap; transform: translate(-50%, -50%); animation: floatUp .9s ease-out forwards; z-index: 50; text-shadow: 0 0 12px currentColor, 2px 2px 0 rgba(0,0,0,.6); }
@keyframes floatUp { 0% { transform: translate(-50%, -50%) scale(.4); opacity: 0; } 15% { transform: translate(-50%, -60%) scale(1.25); opacity: 1; } 100% { transform: translate(-50%, -160%) scale(1); opacity: 0; } }

/* countdown + overlay */
#overlay { position: absolute; inset: 0; z-index: 40; display: none; place-items: center; background: rgba(7, 6, 26, 0.55); backdrop-filter: blur(4px); }
#overlay.show { display: grid; }
.count { font-family: var(--arcade); font-size: 120px; color: var(--gold); text-shadow: 0 0 40px var(--gold); animation: countPop .8s ease-out forwards; }
.count.go { color: var(--mint); text-shadow: 0 0 40px var(--mint); font-size: 96px; }
@keyframes countPop { 0% { transform: scale(2.5); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 80% { opacity: 1; } 100% { transform: scale(.7); opacity: 0; } }
.modal { width: calc(100% - 48px); max-width: 360px; padding: 22px; border-radius: 24px; background: #15113a; border: 1px solid rgba(255,255,255,.14); text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.6); animation: slam .35s cubic-bezier(.2, 1.4, .4, 1); }
.modal h3 { font-family: var(--display); font-weight: 400; font-size: 22px; margin: 0 0 8px; }
.modal p { color: #cfc8f2; font-size: 14px; line-height: 1.5; margin: 0 0 16px; }
.modal .btn-row { flex-direction: column; }
.modal input { width: 100%; font: inherit; font-size: 18px; text-align: center; padding: 14px; border-radius: 14px; border: 1px solid rgba(255,255,255,.2); background: rgba(0,0,0,.3); color: var(--ink); margin-bottom: 12px; outline: none; }
.modal input:focus { border-color: var(--gold); }

#toast { position: absolute; left: 50%; top: calc(16px + var(--safe-top)); transform: translate(-50%, calc(-100% - 40px)); visibility: hidden; z-index: 70; padding: 12px 18px; border-radius: 16px; background: #1f1950; border: 1px solid rgba(255,255,255,.2); font-weight: 700; font-size: 14px; transition: transform .35s cubic-bezier(.2, 1.4, .4, 1); white-space: nowrap; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
#toast.show { transform: translate(-50%, 0); visibility: visible; }

/* ---------- result ---------- */
.res-head { text-align: center; padding: calc(26px + var(--safe-top)) 20px 6px; }
.res-verdict { font-family: var(--arcade); font-size: 44px; line-height: 1; animation: slam .6s cubic-bezier(.2, 1.6, .4, 1); }
.res-verdict.win { color: var(--gold); text-shadow: 0 0 30px var(--gold), 3px 3px 0 var(--pink); }
.res-verdict.lose { color: var(--ice); text-shadow: 0 0 24px var(--ice); }
.stars { display: flex; justify-content: center; gap: 10px; margin: 16px 0 6px; }
.stars span { font-size: 46px; filter: grayscale(1) brightness(.4); transform: scale(.6); transition: all .35s cubic-bezier(.2, 1.8, .4, 1); }
.stars span.on { filter: drop-shadow(0 0 14px rgba(255, 210, 63, .9)); transform: scale(1); }
.res-score { font-family: var(--arcade); font-size: 38px; color: #fff; }
.res-score small { display: block; font-family: var(--mono); font-size: 11px; color: var(--dim); letter-spacing: 3px; }
.newbest { display: inline-block; margin-top: 6px; font-family: var(--arcade); font-size: 11px; letter-spacing: 2px; padding: 4px 10px; border-radius: 8px; background: var(--pink); color: #fff; animation: hot .6s 3; }
.res-stat { color: var(--dim); font-size: 13px; margin-top: 8px; }
.unlock-card { margin: 16px 16px 0; padding: 14px 16px; border-radius: 18px; display: flex; align-items: center; gap: 12px; background: linear-gradient(90deg, color-mix(in srgb, var(--c) 30%, transparent), rgba(255,255,255,.03)); border: 1px solid color-mix(in srgb, var(--c) 55%, transparent); animation: slideUp .5s .6s both cubic-bezier(.2, 1.3, .4, 1); }
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } }
.unlock-card .oi { width: 46px; height: 46px; border-radius: 50%; background: var(--c); color: #120c2a; display: grid; place-items: center; font-size: 20px; box-shadow: 0 0 20px var(--c); flex: none; font-family: var(--arcade); }
.unlock-card .ot { font-size: 11px; color: var(--dim); font-family: var(--mono); letter-spacing: 1px; }
.unlock-card .on { font-weight: 800; font-size: 16px; }
.res-card { margin: 14px 16px 0; padding: 16px; border-radius: 18px; background: rgba(255, 255, 255, 0.045); border: 1px solid var(--line); animation: slideUp .5s .8s both; }
.res-card h4 { margin: 0 0 10px; font-family: var(--display); font-weight: 400; font-size: 15px; letter-spacing: 0.3px; color: var(--mint); display: flex; justify-content: space-between; align-items: center; }
.res-card ol { margin: 0; padding-left: 20px; font-size: 14px; line-height: 1.6; color: #e6e1ff; word-break: keep-all; }
.res-card ol li + li { margin-top: 6px; }
.code { font-family: var(--mono); font-size: 11.5px; line-height: 1.65; background: #0b0920; border-radius: 12px; padding: 14px; overflow-x: auto; white-space: pre; color: #dcd6ff; border: 1px solid rgba(255,255,255,.06); -webkit-user-select: text; user-select: text; }
.code .c { color: #6f7aa8; font-style: italic; }
.code .s { color: var(--mint); }
.code .k { color: var(--pink); }
.code .n { color: var(--gold); }
.copy { font-family: var(--body); font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 8px; background: rgba(255,255,255,.08); color: var(--ink); letter-spacing: 0; }
.res-actions { padding: 18px 16px 0; display: flex; flex-direction: column; gap: 10px; }

/* ---------- book ---------- */
.book-head { padding: calc(14px + var(--safe-top)) 18px 4px; display: flex; align-items: center; gap: 12px; }
.book-head h2 { font-family: var(--display); font-weight: 400; font-size: 24px; margin: 0; flex: 1; }
.book-intro { color: var(--dim); font-size: 13px; padding: 0 18px; line-height: 1.5; }
.book-item { margin: 12px 16px 0; }
.book-item .bh { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.book-item .bh i { font-style: normal; font-family: var(--arcade); color: var(--c); font-size: 12px; }
.book-item.locked .code { filter: blur(4px); opacity: .35; max-height: 80px; overflow: hidden; }

/* shared helpers for games */
.g-center { position: absolute; inset: 0; display: grid; place-items: center; }
.g-btn { padding: 14px 18px; border-radius: 16px; font-weight: 800; font-size: 16px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16); transition: transform .08s; }
.g-btn:active { transform: scale(.94); }
.g-pill { display: inline-block; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; background: rgba(255,255,255,.08); border: 1px solid var(--line); }
