/* TYPE GUARD — 먹과 한지, 등불의 색. 휴대폰 세로가 먼저다. */
:root {
  --ink: #0b1024; --ink-2: #141a36; --ink-3: #1f2750; --paper: #f1e7cf; --paper-2: #e3d5b4;
  --lamp: #ffc66b; --lamp-2: #ff9a3d; --vermilion: #c2361f; --text: #f3ecdc; --muted: #b9b2c9; --line: rgba(255,255,255,.14);
  --font: system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", "Segoe UI", sans-serif;
  --safe-r: env(safe-area-inset-right); --safe-l: env(safe-area-inset-left); --safe-b: env(safe-area-inset-bottom);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--text); font-family: var(--font); -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; }
[hidden] { display: none !important; }
kbd { font: 600 .82em var(--font); padding: .1em .45em; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: rgba(255,255,255,.06); white-space: nowrap; }

.primary, .secondary, .ghost, .mode { border: 0; border-radius: 12px; min-height: 48px; padding: 12px 18px; font-weight: 700; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.primary { background: linear-gradient(180deg, #ffd27a, #f19a3a); color: #2a1406; box-shadow: 0 6px 24px rgba(255,160,60,.35), inset 0 -2px 0 rgba(0,0,0,.18); font-size: 1.08rem; }
.primary:active { transform: translateY(1px); }
.secondary { background: rgba(255,255,255,.1); border: 1px solid var(--line); }
.ghost { background: transparent; color: var(--muted); min-height: 44px; padding: 10px 12px; font-weight: 600; }
.icon { width: 44px; height: 44px; min-width: 44px; border-radius: 12px; border: 1px solid var(--line); background: rgba(10,14,32,.55); font-size: 1.05rem; display: inline-grid; place-items: center; padding: 0; }

/* ---------------- 첫 화면 ---------------- */
#entry { position: relative; min-height: 100dvh; display: flex; flex-direction: column; padding: max(10px, env(safe-area-inset-top)) max(16px, var(--safe-r)) max(14px, var(--safe-b)) max(16px, var(--safe-l)); overflow: hidden; }
body:has(#gamenow-exit-launcher) #entry { padding-right: max(104px, var(--safe-r)); }
body.gamenow-mobile-mode #entry, body.gamenow-mobile-mode:has(#gamenow-exit-launcher) #entry { padding-right: max(56px, var(--safe-r)); }
.poster { position: absolute; inset: 0; z-index: 0; pointer-events: none; background: radial-gradient(120% 70% at 75% 8%, #2a3a78 0%, transparent 55%), linear-gradient(180deg, #070b1f 0%, #121a44 48%, #3a2a55 78%, #6a3a4e 100%); }
.poster .moon { position: absolute; right: 14%; top: 7%; width: 64px; height: 64px; border-radius: 50%; background: #eef1ff; box-shadow: 0 0 60px 20px rgba(200,215,255,.25); }
.poster .moon::after { content: ''; position: absolute; inset: -4px -4px auto auto; width: 58px; height: 58px; border-radius: 50%; background: #121a44; transform: translate(14px, -6px); }
.poster .cloud { position: absolute; width: 160px; height: 60px; border-radius: 40px; background: radial-gradient(60% 80% at 40% 35%, #303a66, #141a36 70%); filter: blur(.4px); opacity: .9; animation: drift 18s ease-in-out infinite alternate; }
.poster .cloud::before, .poster .cloud::after { content: ''; position: absolute; border-radius: 50%; background: inherit; }
.poster .cloud::before { width: 80px; height: 70px; left: 26px; top: -30px; }
.poster .cloud::after { width: 60px; height: 52px; left: 84px; top: -18px; }
.poster .c1 { left: 6%; top: 22%; } .poster .c2 { right: 6%; top: 40%; transform: scale(.8); animation-duration: 22s; } .poster .c3 { left: 32%; top: 58%; transform: scale(.6); animation-duration: 26s; opacity: .7; }
@keyframes drift { to { translate: 24px 10px; } }
@media (prefers-reduced-motion: reduce) { .poster .cloud { animation: none; } }
.poster .village { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 22vh; fill: #07091a; }
.poster .lamps circle { fill: var(--lamp); filter: drop-shadow(0 0 6px var(--lamp)); }
.topbar, .hero, .modes, .foot { position: relative; z-index: 1; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { color: var(--text); font-weight: 800; letter-spacing: .02em; text-decoration: none; padding: 10px 2px; min-height: 44px; display: inline-flex; align-items: center; }
.top-actions { display: flex; gap: 8px; }
.hero { margin: auto 0 0; padding-top: 6vh; max-width: 560px; display: flex; flex-direction: column; gap: 12px; }
.kicker { margin: 0; color: var(--lamp); font-weight: 700; letter-spacing: .16em; font-size: .78rem; }
h1 { margin: 0; font-size: clamp(2.3rem, 11vw, 4rem); line-height: .95; font-weight: 900; letter-spacing: -.01em; text-shadow: 0 4px 30px rgba(255,180,90,.25); }
h1 span { display: block; font-size: .42em; margin-top: .35em; color: var(--paper); letter-spacing: .08em; font-weight: 800; }
.lede { margin: 0; color: #d9d2e6; line-height: 1.55; font-size: .98rem; max-width: 34em; }
.lang-pick { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lang-pick > span { color: var(--muted); font-size: .85rem; margin-right: 2px; }
.lang-pick button { min-height: 48px; min-width: 112px; border-radius: 12px; border: 1px solid var(--line); background: rgba(10,14,32,.6); padding: 6px 14px; display: flex; flex-direction: column; align-items: flex-start; }
.lang-pick button b { font-size: 1rem; } .lang-pick button small { color: var(--muted); font-size: .72rem; }
.lang-pick button[aria-checked="true"] { border-color: var(--lamp); background: rgba(255,198,107,.14); box-shadow: inset 0 0 0 1px var(--lamp); }
#play { align-self: flex-start; min-width: 220px; min-height: 56px; }
.note { margin: 0; color: var(--muted); font-size: .85rem; }
.modes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 18px 0 8px; max-width: 560px; }
.mode { flex-direction: column; align-items: flex-start; justify-content: center; background: rgba(12,16,38,.78); border: 1px solid var(--line); min-height: 64px; text-align: left; padding: 10px 14px; }
.mode b { font-size: 1rem; } .mode small { color: var(--muted); font-weight: 500; font-size: .78rem; line-height: 1.3; }
.foot { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
@media (min-width: 900px) { #entry { padding-left: 7vw; } .hero { padding-top: 10vh; } .modes { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 820px; } }
@media (max-height: 640px) { .hero { padding-top: 2vh; gap: 8px; } .lede { font-size: .9rem; } h1 { font-size: 2.2rem; } .modes { margin-top: 10px; } }

/* ---------------- 게임 화면 ---------------- */
#game { position: fixed; left: 0; right: 0; top: var(--vv-top, 0px); height: var(--vv-h, 100dvh); display: flex; flex-direction: column; background: var(--ink); touch-action: manipulation; }
#hud { flex: none; height: 52px; display: flex; align-items: center; gap: 8px; padding: 4px max(8px, var(--safe-r)) 4px max(8px, var(--safe-l)); background: linear-gradient(180deg, rgba(5,8,22,.95), rgba(5,8,22,.6)); z-index: 2; }
body.gamenow-mobile-mode #hud { padding-right: max(56px, var(--safe-r)); }
#hud .where { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.1; }
#hud .where small { color: var(--muted); font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hud-score { font-weight: 800; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
#hud .meters { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; font-size: .82rem; color: var(--muted); }
#hud .combo { color: #2a1406; background: var(--lamp); border-radius: 999px; padding: 2px 8px; font-weight: 800; }
#hud .combo.pop { animation: pop .28s ease-out; }
@keyframes pop { from { transform: scale(1.35); } to { transform: scale(1); } }
#field { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#view, #bg { position: absolute; inset: 0; display: block; touch-action: none; }
.overlay { position: absolute; inset: 0; pointer-events: none; opacity: 0; will-change: opacity; }
#ov-slow { background: rgba(80,120,220,.16); }
#ov-danger { background: radial-gradient(ellipse at 50% 55%, rgba(180,30,30,0) 45%, rgba(180,30,30,.45) 100%); }
#ov-flash { background: rgba(255,240,210,.6); }
#banner { position: absolute; left: 50%; top: 18%; translate: -50% 0; pointer-events: none; text-align: center; font-weight: 900; font-size: clamp(1.3rem, 6vw, 2.2rem); color: var(--paper); text-shadow: 0 2px 18px rgba(0,0,0,.7); opacity: 0; transition: opacity .3s; white-space: nowrap; }
#banner.show { opacity: 1; }
#banner small { display: block; font-size: .5em; color: var(--lamp); letter-spacing: .14em; margin-top: 4px; }
#typebar { flex: none; display: flex; gap: 8px; align-items: center; padding: 8px max(10px, var(--safe-r)) max(8px, var(--safe-b)) max(10px, var(--safe-l)); background: #070a1a; border-top: 1px solid var(--line); margin: 0; }
body.gamenow-mobile-mode #typebar { padding-right: max(56px, var(--safe-r)); }
#type { flex: 1; min-width: 0; height: 48px; border-radius: 12px; border: 2px solid #3a4378; background: var(--paper); color: #1e1b24; font: 700 1.2rem var(--font); padding: 0 14px; outline: none; }
#type:focus { border-color: var(--lamp); box-shadow: 0 0 0 3px rgba(255,198,107,.25); }
#type.ok { animation: okflash .25s; } #type.bad { animation: shake .3s; border-color: #e0573f; }
@keyframes okflash { from { box-shadow: 0 0 0 6px rgba(255,210,120,.6); } }
@keyframes shake { 20% { translate: -6px 0; } 40% { translate: 5px 0; } 60% { translate: -3px 0; } 80% { translate: 2px 0; } }
@media (prefers-reduced-motion: reduce) { #type.bad { animation: none; } #hud .combo.pop { animation: none; } }
.fire { width: 56px; height: 48px; min-width: 48px; border-radius: 12px; border: 0; background: linear-gradient(180deg, #ffd27a, #f19a3a); color: #2a1406; font-weight: 900; font-size: 1.3rem; }
.kbd { display: none; font-size: 1.3rem; }
#game.touch .kbd { display: inline-grid; }
#game.kbd-game .kbd { background: rgba(255,198,107,.2); border-color: var(--lamp); }
#game:not(.touch) .fire { display: none; }
#game.pad .fire { display: inline-flex; align-items: center; justify-content: center; }
#game.kbd-game .fire, #game.pad .fire { display: none; }
@media (max-height: 640px) { #vkeys { gap: 4px; padding-top: 4px; } .vk-row { gap: 4px; } #typebar { padding-top: 5px; padding-bottom: max(5px, var(--safe-b)); } #type { height: 44px; } #hud { height: 48px; } }

/* 화면 자판 */
#vkeys { flex: none; padding: 6px max(4px, var(--safe-r)) max(6px, var(--safe-b)) max(4px, var(--safe-l)); background: #060918; display: flex; flex-direction: column; gap: 6px; user-select: none; -webkit-user-select: none; touch-action: none; }
.vk-row { display: flex; gap: 5px; justify-content: center; }
.vk { flex: 1 1 0; max-width: 64px; min-width: 0; height: 46px; border-radius: 8px; border: 1px solid rgba(255,255,255,.12); background: #1a2147; color: var(--text); font: 700 1.05rem var(--font); padding: 0; touch-action: none; }
.vk.vk-wide { flex: 1.5 1 0; max-width: 96px; font-size: 1rem; }
.vk.vk-mod { background: #262e5c; }
.vk.vk-enter { flex: 1; max-width: 420px; background: linear-gradient(180deg, #ffd27a, #f19a3a); color: #2a1406; border: 0; }
.vk.down { background: #3c478a; transform: translateY(1px); }
.vk.on { background: #5a4a24; border-color: var(--lamp); }
.vk.cursor { outline: 3px solid #ffe14d; outline-offset: -2px; }
.vk.glow { background: #ffcf70; color: #2a1406; box-shadow: 0 0 14px rgba(255,200,100,.8); }
.vk.ok { animation: okflash .25s; } .vk.bad { animation: badflash .3s; }
@keyframes badflash { from { background: #b8432f; } }
#game.practice .vk.f0, #game.practice .vk.f7 { border-bottom: 3px solid #b56bd6; }
#game.practice .vk.f1, #game.practice .vk.f6 { border-bottom: 3px solid #5fa6e8; }
#game.practice .vk.f2, #game.practice .vk.f5 { border-bottom: 3px solid #5fd08a; }
#game.practice .vk.f3, #game.practice .vk.f4 { border-bottom: 3px solid #f0b54a; }
#game.practice [data-code="KeyF"]::after, #game.practice [data-code="KeyJ"]::after { content: ''; display: block; width: 12px; height: 2px; margin: 2px auto 0; background: currentColor; opacity: .7; }
@media (min-width: 700px) { .vk { height: 50px; } }

/* 자리 연습 */
#practice { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 12px; pointer-events: none; }
.pr-line { display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: nowrap; max-width: 100%; overflow: hidden; }
.pr-line .k { min-width: 40px; height: 52px; padding: 0 8px; border-radius: 10px; display: grid; place-items: center; background: rgba(241,231,207,.16); color: var(--paper); font: 800 1.4rem var(--font); }
.pr-line .k.now { background: var(--paper); color: #1e1b24; transform: scale(1.18); box-shadow: 0 0 22px rgba(255,210,120,.55); }
.pr-line .k.bad { background: #b8432f; color: #fff; }
.pr-line .k.word { min-width: auto; padding: 0 14px; }
.pr-line .k.word em { font-style: normal; color: var(--vermilion); }
.pr-stats { display: flex; gap: 14px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: .9rem; }
.pr-hint { margin: 0; color: var(--paper); text-align: center; max-width: 30em; font-size: .9rem; text-shadow: 0 1px 8px #000; }
#game.practice .vk-row:last-child { display: none; } #game.practice [data-code="back"] { visibility: hidden; }
#game.practice #typebar { position: absolute; opacity: 0; pointer-events: none; height: 1px; overflow: hidden; }

/* 첫 조작 안내 — 판 아래쪽(성벽 위)에 낮게 띄운다. 낱말이 내려오는 하늘을 가리지 않게 */
#coach { position: fixed; left: max(8px, var(--safe-l)); right: max(8px, var(--safe-r)); top: var(--coach-top, 70%); z-index: 5; margin: 0 auto; max-width: 640px; background: rgba(8,11,28,.88); border: 1px solid rgba(255,198,107,.45); border-radius: 12px; padding: 7px 10px; font-size: .8rem; opacity: 0; translate: 0 calc(-100% + 6px); transition: opacity .3s, translate .3s; pointer-events: none; display: flex; gap: 8px; align-items: center; }
body.gamenow-mobile-mode #coach { right: max(56px, var(--safe-r)); }
#coach.show { opacity: 1; translate: 0 -100%; }
#coach b { color: var(--lamp); flex: none; font-size: .78rem; }
#coach ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 10px; }
#coach li { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
#coach li.done { opacity: .4; }
#coach li.done kbd { text-decoration: line-through; }
#coach li.done::after { content: '✓'; color: #7fe39a; }
#coach small { color: var(--muted); font-size: .72rem; }

/* 창 */
dialog#sheet { width: min(520px, calc(100vw - 24px)); max-height: calc(var(--vv-h, 100dvh) - 24px); overflow: auto; border: 1px solid rgba(255,198,107,.3); border-radius: 18px; padding: 22px 18px 18px; background: linear-gradient(180deg, #151b3f, #0b1024); color: var(--text); box-shadow: 0 20px 80px rgba(0,0,0,.6); }
dialog#sheet::backdrop { background: rgba(3,5,14,.7); backdrop-filter: blur(3px); }
#sheet .close { position: absolute; right: 10px; top: 10px; }
#sheet h2 { margin: 0 44px 8px 0; font-size: 1.35rem; }
#sheet p { line-height: 1.55; color: #d9d2e6; }
#sheet .small { font-size: .85rem; color: var(--muted); }
#sheet .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
#sheet .actions .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
.stats div { background: rgba(255,255,255,.06); border-radius: 12px; padding: 10px 6px; text-align: center; }
.stats strong { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stats span { font-size: .72rem; color: var(--muted); }
.stars { font-size: 2rem; letter-spacing: .15em; text-align: center; color: #4a4560; margin: 4px 0; }
.stars .on { color: var(--lamp); text-shadow: 0 0 14px rgba(255,200,100,.7); }
.stars .on.new { animation: pop .5s ease-out both; }
.badge { display: inline-block; background: var(--vermilion); color: #fff; font-weight: 800; border-radius: 999px; padding: 2px 10px; font-size: .8rem; margin-left: 6px; vertical-align: middle; }
.reason { background: rgba(255,198,107,.1); border-left: 3px solid var(--lamp); padding: 8px 10px; border-radius: 6px; font-size: .9rem; }
.stage-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin: 6px 0 14px; }
.stage-grid button { min-height: 48px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.06); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px; font-weight: 800; }
.stage-grid button small { font-size: .62rem; color: var(--lamp); letter-spacing: .05em; font-weight: 600; }
.stage-grid button:disabled { opacity: .35; cursor: default; }
.stage-grid button.boss { border-color: rgba(194,54,31,.7); }
.region-title { margin: 10px 0 2px; font-size: .85rem; color: var(--muted); letter-spacing: .08em; }
.lesson-list { display: grid; gap: 8px; }
.lesson-list button { justify-content: space-between; }
.lesson-list small { color: var(--muted); font-weight: 500; }
dl.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; margin: 10px 0; font-size: .9rem; }
dl.keys dt { color: var(--lamp); font-weight: 700; } dl.keys dd { margin: 0; color: #d9d2e6; }
ul.specials { padding-left: 18px; line-height: 1.6; font-size: .9rem; color: #d9d2e6; }
#toast { position: fixed; left: 50%; top: calc(var(--vv-top, 0px) + 64px); translate: -50% 0; z-index: 6; background: rgba(8,11,28,.94); border: 1px solid var(--line); border-radius: 999px; padding: 10px 16px; font-size: .88rem; max-width: calc(100vw - 32px); text-align: center; opacity: 0; transition: opacity .25s; pointer-events: none; }
#toast.show { opacity: 1; }
#gamepad-status { position: fixed; left: 50%; bottom: 12px; translate: -50% 0; z-index: 4; background: rgba(8,11,28,.9); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: .8rem; color: var(--muted); }
body[data-playing] #gamepad-status { display: none; }

body[data-playing] #gamenow-share-launcher { display: none !important; }
.volumes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.volumes label { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; color: var(--muted); }
.volumes input[type=range] { width: 100%; height: 44px; accent-color: var(--lamp); }
