:root {
  --bg: #0b1033;
  --bg2: #151c52;
  --ink: #f4f1ff;
  --ink-soft: #c3c6ee;
  --gold: #ffd35a;
  --gold-deep: #f0a81c;
  --panel: rgba(22, 29, 84, 0.82);
  --line: rgba(255, 220, 130, 0.35);
  --purple: #8d63ff;
  --focus: #7ff3ff;
  --topbar-h: 60px;
  --radius: 20px;
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", "Noto Sans KR", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: radial-gradient(ellipse at 50% -10%, #3a2a8a 0%, var(--bg2) 38%, var(--bg) 75%) fixed, var(--bg);
  font-size: 18px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font-family: inherit; }
img { max-width: 100%; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; margin: -1px; padding: 0; border: 0;
}

:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; border-radius: 12px; }
h2:focus, h1:focus { outline: none; }

/* 반짝이는 별 배경 */
.sky {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff 60%, transparent),
    radial-gradient(1px 1px at 28% 72%, #fff 60%, transparent),
    radial-gradient(2px 2px at 44% 32%, #ffe9a8 60%, transparent),
    radial-gradient(1px 1px at 63% 12%, #fff 60%, transparent),
    radial-gradient(1.5px 1.5px at 78% 58%, #cfe6ff 60%, transparent),
    radial-gradient(1px 1px at 88% 26%, #fff 60%, transparent),
    radial-gradient(2px 2px at 92% 84%, #ffe9a8 60%, transparent),
    radial-gradient(1px 1px at 6% 88%, #fff 60%, transparent),
    radial-gradient(1.5px 1.5px at 52% 90%, #fff 60%, transparent),
    radial-gradient(1px 1px at 36% 50%, #cfe6ff 60%, transparent);
  animation: twinkle 5s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .55; } to { opacity: 1; } }

/* 상단 바 */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  background: linear-gradient(to bottom, rgba(8, 11, 38, .92), rgba(8, 11, 38, .6));
  backdrop-filter: blur(6px);
}
.status { display: flex; gap: 6px; flex-wrap: nowrap; min-width: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  padding: 6px 12px; border-radius: 999px; font-size: 16px;
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .18);
}
.pill b { color: var(--gold); font-variant-numeric: tabular-nums; }
.sound-btns { display: flex; gap: 6px; margin-left: auto; }
.chip {
  min-height: 44px; padding: 6px 14px; border-radius: 999px; font-size: 15px; font-weight: 700;
  color: var(--ink); background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .25);
  cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="false"] { opacity: .65; }
.chip:disabled { opacity: .45; cursor: not-allowed; }

main {
  position: relative; z-index: 1;
  min-height: 100vh; min-height: 100dvh;
  padding: calc(var(--topbar-h) + 12px) max(16px, env(safe-area-inset-right)) 20px max(16px, env(safe-area-inset-left));
}
.screen { animation: screen-in .35s ease both; }
.screen[hidden] { display: none !important; }
@keyframes screen-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 10px 22px; border-radius: 16px; border: 0;
  font-size: 19px; font-weight: 800; color: #1c1440; cursor: pointer;
  transition: transform .12s ease, filter .12s ease, opacity .2s;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; filter: grayscale(.4); }
.btn.big { min-height: 62px; font-size: 22px; padding: 12px 30px; }
.btn.small { min-height: 44px; font-size: 16px; padding: 8px 16px; }
.btn.gold {
  background: linear-gradient(180deg, #ffe58a, var(--gold) 45%, var(--gold-deep));
  box-shadow: 0 6px 0 #b8740a, 0 10px 24px rgba(255, 196, 60, .35);
}
.btn.gold:active:not(:disabled) { box-shadow: 0 2px 0 #b8740a; transform: translateY(4px); }
.btn.purple {
  color: #fff; background: linear-gradient(180deg, #a986ff, var(--purple));
  box-shadow: 0 5px 0 #5a35c2;
}
.btn.ghost {
  color: var(--ink); background: rgba(255, 255, 255, .1); border: 2px solid rgba(255, 255, 255, .3);
}
.panel {
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35), inset 0 0 40px rgba(140, 120, 255, .12);
}

/* 표지 */
.screen-cover { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.cover-frame {
  width: min(100%, 1100px, calc((100dvh - var(--topbar-h) - 320px) * 1.777));
  border-radius: 24px; overflow: hidden; border: 3px solid var(--line);
  box-shadow: 0 0 60px rgba(255, 210, 90, .25);
}
.cover-img { display: block; width: 100%; height: auto; }
.cover-sub { margin: 0; font-size: clamp(16px, 2.2vw, 21px); color: var(--ink-soft); }
.cover-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.mode-pick { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.mode {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 200px; padding: 12px 26px; border-radius: 18px; border: 0; cursor: pointer;
  font-family: inherit; touch-action: manipulation;
  transition: transform .12s ease;
}
.mode:active { transform: translateY(4px); }
.mode-name { font-size: 24px; font-weight: 900; letter-spacing: 1px; }
.mode-hint { font-size: 17px; font-weight: 700; }
.mode.easy {
  color: #0f3b24; background: linear-gradient(180deg, #a6f5c6, #3ddc84);
  box-shadow: 0 6px 0 #1f8f52, 0 10px 24px rgba(61, 220, 132, .35);
}
.mode.hard {
  color: #fff; background: linear-gradient(180deg, #ff9aa8, #ff5a6e);
  box-shadow: 0 6px 0 #b8293b, 0 10px 24px rgba(255, 90, 110, .35);
}
.mode:active.easy { box-shadow: 0 2px 0 #1f8f52; }
.mode:active.hard { box-shadow: 0 2px 0 #b8293b; }

/* 규칙 */
.screen-rules { display: flex; justify-content: center; }
.rules-panel { max-width: 780px; width: 100%; padding: 28px clamp(18px, 4vw, 40px); text-align: center; }
.rules-panel h2 { margin: 0 0 16px; font-size: clamp(26px, 4vw, 36px); color: var(--gold); }
.rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; text-align: left; }
.rules li {
  display: flex; gap: 12px; align-items: center;
  padding: 12px 16px; border-radius: 14px; background: rgba(255, 255, 255, .07);
  font-size: clamp(17px, 2.2vw, 21px);
}
.rules li b { color: var(--gold); }
.rules .ico { font-size: 26px; flex: none; }
.rules-note { color: var(--ink-soft); margin: 18px 0; }

/* 문제 화면 */
.puzzle {
  display: grid; gap: 16px;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 1fr);
  height: calc(100dvh - var(--topbar-h) - 32px);
  min-height: 560px;
}
.puzzle-left { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.puzzle-title { margin: 0; font-size: clamp(22px, 3vw, 30px); color: var(--gold); display: flex; align-items: center; gap: 10px; }
.puzzle-title .dot { width: 18px; height: 18px; border-radius: 50%; background: var(--room, var(--gold)); box-shadow: 0 0 12px var(--room, var(--gold)); flex: none; }
.puzzle-img-wrap {
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: clamp(10px, 2vw, 22px); border-radius: var(--radius);
  background: #fff; border: 4px solid var(--room, var(--gold));
  box-shadow: 0 0 36px color-mix(in srgb, var(--room, #ffd35a) 45%, transparent);
}
.puzzle-img-wrap img { width: 100%; height: 100%; object-fit: contain; display: block; }
.hintbox {
  padding: 12px 16px; border-radius: 16px; font-size: 18px;
  background: rgba(141, 99, 255, .22); border: 2px solid rgba(169, 134, 255, .6);
  max-height: 32%; overflow: auto;
}
.hintbox ol { margin: 0; padding-left: 0; list-style: none; display: grid; gap: 6px; }
.hintbox li b { color: #d8c8ff; margin-right: 6px; }
.hintbox .tip { margin: 0; }

.puzzle-right {
  display: flex; flex-direction: column; gap: 12px; justify-content: center;
  padding: 18px; border-radius: var(--radius);
  background: var(--panel); border: 2px solid var(--line);
  min-height: 0; overflow: auto;
}
.digits { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.digit {
  aspect-ratio: 4 / 5; max-height: 92px;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(38px, 5vw, 58px); font-weight: 900; font-variant-numeric: tabular-nums;
  border-radius: 16px; background: rgba(5, 8, 30, .7); border: 3px solid rgba(255, 255, 255, .25);
  color: #fff; transition: border-color .15s, box-shadow .15s;
}
.digit.filled { border-color: var(--gold); box-shadow: 0 0 16px rgba(255, 211, 90, .45); }
.digit.next { border-color: rgba(127, 243, 255, .8); }
.digits.wrong .digit { border-color: #ff9fb0; box-shadow: 0 0 16px rgba(255, 120, 150, .5); }
.feedback { min-height: 3em; margin: 0; text-align: center; font-size: 18px; font-weight: 700; color: #ffe3a3; }
.feedback.bad { color: #ffc4d0; }
.feedback.wait { color: #b9f3ff; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button {
  min-height: 58px; border-radius: 14px; border: 0; cursor: pointer;
  font-size: 28px; font-weight: 800; color: #1b1650;
  background: linear-gradient(180deg, #ffffff, #dcdcff);
  box-shadow: 0 4px 0 #8e8bd0;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.keypad button:active { transform: translateY(3px); box-shadow: 0 1px 0 #8e8bd0; }
.keypad .k-sub { font-size: 16px; line-height: 1.1; background: linear-gradient(180deg, #e8e2ff, #bfb4f2); }
.keypad button:disabled { opacity: .4; }
.puzzle-actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; }
.puzzle-actions .btn { font-size: 17px; padding: 10px 12px; }
.puzzle.practice .hint-only { display: none; }

/* 흔들림 (오답) */
.shake { animation: shake .42s cubic-bezier(.36, .07, .19, .97); }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

/* 정답 카드 */
.reveal { max-width: 1200px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.reveal h2 { margin: 0; font-size: clamp(28px, 4.4vw, 44px); color: var(--gold); text-shadow: 0 0 22px rgba(255, 211, 90, .6); }
.reveal-sub { margin: 0; font-size: 20px; color: var(--ink-soft); }
.reveal-body { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; width: 100%; align-items: start; }
.reveal-card {
  border-radius: var(--radius); overflow: hidden; border: 3px solid var(--room, var(--gold));
  box-shadow: 0 0 40px color-mix(in srgb, var(--room, #ffd35a) 50%, transparent);
  background: #0e1440;
}
.reveal-card img { display: block; width: 100%; height: auto; }
.reveal-explain { padding: 20px 22px; text-align: left; }
.reveal-answer { margin: 0 0 6px; font-size: 18px; color: var(--ink-soft); }
.reveal-answer b { display: inline-block; margin-left: 6px; font-size: 40px; letter-spacing: 6px; color: var(--gold); font-variant-numeric: tabular-nums; }
.reveal-explain h3 { margin: 4px 0 10px; font-size: 22px; }
.reveal-explain ol { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; font-size: 18px; }
.reveal-talk { margin: 14px 0 0; padding: 10px 14px; border-radius: 12px; background: rgba(255, 211, 90, .12); font-size: 17px; }

/* 7번 방 풀이판 */
.sudoku-card { padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.sudoku-card p { margin: 0; font-weight: 800; color: var(--gold); font-size: 20px; }
.sudoku {
  display: grid; grid-template-columns: repeat(9, 1fr); width: min(100%, 440px);
  background: #fff; border: 3px solid #1b1f44; border-radius: 8px; overflow: hidden;
}
.sudoku span {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center; position: relative;
  font-size: clamp(16px, 2.4vw, 24px); font-weight: 700; color: #1b1f44; border: 1px solid #d5d8ea;
}
.sudoku span.hole { background: #ffd35a; color: #3a1d00; font-weight: 900; box-shadow: inset 0 0 0 2px #e79a00; }
.sudoku span.hole i {
  position: absolute; top: 1px; left: 3px; font-style: normal; font-size: 11px; font-weight: 800; color: #8a4b00;
}

/* 지도 */
.map-head { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.map-head h2 { margin: 0; font-size: clamp(26px, 4vw, 38px); color: var(--gold); }
.map-stats { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.stat {
  display: flex; flex-direction: column; align-items: center; min-width: 130px;
  padding: 8px 18px; border-radius: 16px; background: var(--panel); border: 2px solid var(--line);
}
.stat > span { font-size: 15px; color: var(--ink-soft); }
.stat b { font-size: 28px; color: #fff; font-variant-numeric: tabular-nums; }
.stat.big b { font-size: 38px; color: var(--gold); }
.star-track { display: flex; gap: 8px; font-size: 28px; }
.star-track span { color: rgba(255, 255, 255, .18); transition: color .4s, text-shadow .4s; }
.star-track span.on { color: var(--c); text-shadow: 0 0 12px var(--c); }
.map-guide { text-align: center; margin: 12px 0; color: var(--ink-soft); }
.doors {
  display: grid; gap: clamp(8px, 1.4vw, 16px);
  grid-template-columns: repeat(7, minmax(0, 1fr));
  max-width: 1200px; margin: 0 auto;
}
.door {
  --c: #ffd35a;
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px;
  min-height: clamp(170px, 30vh, 260px); padding: 12px 6px 14px;
  border: 3px solid color-mix(in srgb, var(--c) 80%, #fff); border-bottom-width: 6px;
  border-radius: 999px 999px 18px 18px;
  background:
    radial-gradient(ellipse at 50% 35%, color-mix(in srgb, var(--c) 55%, transparent), transparent 70%),
    linear-gradient(180deg, color-mix(in srgb, var(--c) 45%, #141a4f), #10143e);
  box-shadow: 0 0 22px color-mix(in srgb, var(--c) 40%, transparent), inset 0 0 26px rgba(0, 0, 0, .35);
  color: #fff; cursor: pointer; overflow: hidden;
  transition: transform .15s ease, box-shadow .2s ease;
  touch-action: manipulation;
}
.door:hover { transform: translateY(-4px); }
.door:active { transform: scale(.97); }
.door .d-num { font-size: clamp(30px, 4vw, 46px); font-weight: 900; text-shadow: 0 2px 10px rgba(0, 0, 0, .5); line-height: 1; }
.door .d-name { font-size: clamp(13px, 1.6vw, 17px); font-weight: 700; }
.door .d-state {
  font-size: clamp(12px, 1.4vw, 15px); font-weight: 800; padding: 3px 10px; border-radius: 999px;
  background: rgba(0, 0, 0, .35);
}
.door .d-icon { font-size: clamp(34px, 5vw, 54px); line-height: 1; margin-bottom: auto; margin-top: 10%; filter: drop-shadow(0 0 8px rgba(0, 0, 0, .5)); }
.door.open {
  background:
    radial-gradient(ellipse at 50% 38%, #fffbe0 0%, color-mix(in srgb, var(--c) 80%, #fff) 30%, transparent 72%),
    linear-gradient(180deg, color-mix(in srgb, var(--c) 60%, #1b1f5a), #10143e);
  box-shadow: 0 0 36px var(--c), inset 0 0 24px rgba(255, 255, 255, .25);
}
.door.open .d-state { background: #fff; color: #2a1f66; }
.door.open .d-icon { animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) scale(1.06); } }

/* 최종 성공 */
.final { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; max-width: 900px; margin: 0 auto; }
.final-stage { position: relative; width: min(70vw, 300px); aspect-ratio: 1; }
.final-glow {
  position: absolute; inset: -20%;
  background: radial-gradient(circle, rgba(255, 240, 180, .95) 0%, rgba(255, 211, 90, .5) 25%, transparent 60%);
  opacity: 0; animation: glow-in 1s 1.6s ease forwards, glow-pulse 2.6s 2.6s ease-in-out infinite;
}
.final-bigstar {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: min(52vw, 230px); line-height: 1; color: #fff3b5;
  text-shadow: 0 0 30px #ffd35a, 0 0 60px #ffb300;
  transform: scale(0); animation: star-pop .8s 1.5s cubic-bezier(.2, 1.6, .4, 1) forwards;
}
.mini-star {
  position: absolute; left: 50%; top: 50%; font-size: 44px; color: var(--c); text-shadow: 0 0 14px var(--c);
  transform: translate(-50%, -50%) translate(var(--x), var(--y));
  animation: gather 1.5s ease-in forwards;
}
@keyframes gather {
  0% { transform: translate(-50%, -50%) translate(var(--x), var(--y)) scale(1); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(-50%, -50%) translate(0, 0) scale(.3) rotate(360deg); opacity: 0; }
}
@keyframes star-pop { to { transform: scale(1); } }
@keyframes glow-in { to { opacity: 1; } }
@keyframes glow-pulse { 50% { opacity: .65; } }
.final-title {
  margin: 0; font-size: clamp(46px, 9vw, 86px); font-weight: 900; color: var(--gold);
  text-shadow: 0 0 24px rgba(255, 211, 90, .8), 0 4px 0 #b8740a;
  opacity: 0; animation: title-in .7s 2s ease forwards;
}
@keyframes title-in { from { opacity: 0; transform: scale(.7); } to { opacity: 1; transform: none; } }
.final-sub { margin: 0; font-size: 21px; color: var(--ink-soft); }
.final-doors { display: flex; gap: 8px; }
.final-doors span {
  width: 36px; height: 50px; border-radius: 18px 18px 6px 6px;
  background: radial-gradient(ellipse at 50% 40%, #fff, var(--c) 60%);
  box-shadow: 0 0 14px var(--c);
}
.final-record {
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 40px; border-radius: 22px; background: var(--panel); border: 3px solid var(--gold);
}
.final-record span { font-size: 18px; color: var(--ink-soft); }
.final-record b { font-size: clamp(44px, 8vw, 72px); color: #fff; line-height: 1.15; font-variant-numeric: tabular-nums; }
.final-record small { font-size: 16px; color: var(--ink-soft); }
.final-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.cert-box {
  display: flex; flex-direction: column; gap: 8px; width: min(100%, 560px);
  padding: 14px 16px; border-radius: 18px; background: rgba(141, 99, 255, .18); border: 2px solid rgba(169, 134, 255, .55);
}
.cert-box label { font-weight: 800; font-size: 18px; }
.cert-row { display: flex; gap: 8px; }
.cert-row input {
  flex: 1; min-width: 0; min-height: 52px; padding: 0 16px; border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, .35); background: rgba(5, 8, 30, .6); color: #fff;
  font: 700 20px var(--font);
}
.cert-row input::placeholder { color: rgba(255, 255, 255, .45); font-weight: 500; }
.cert-row .btn { font-size: 17px; white-space: nowrap; }
@media (max-width: 480px) { .cert-row { flex-direction: column; } }

/* 문 열림 연출 */
.fx {
  position: fixed; inset: 0; z-index: 50; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 50%, #2a1a70, #05061a);
  --room: #ffd35a;
}
.fx[hidden] { display: none; }
.fx-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.fx-rays {
  position: absolute; width: 180vmax; height: 180vmax; border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(255, 220, 120, .55) 0deg 6deg, transparent 6deg 20deg);
  mask-image: radial-gradient(circle, #000 0%, transparent 55%);
  -webkit-mask-image: radial-gradient(circle, #000 0%, transparent 55%);
  opacity: 0; transform: scale(.3);
}
.fx-circle {
  position: absolute; width: min(86vmin, 640px); height: min(86vmin, 640px);
  fill: none; stroke: var(--gold); stroke-width: 1.4; opacity: 0; transform: scale(.2) rotate(-90deg);
  filter: drop-shadow(0 0 6px #ffcc4d);
}
.fx-circle .dash { stroke-dasharray: 3 5; stroke-width: 3; stroke: color-mix(in srgb, var(--room) 70%, #fff); }
.fx-circle .inner { stroke: color-mix(in srgb, var(--room) 60%, #fff); }
.fx-door {
  position: relative; width: min(42vmin, 300px); aspect-ratio: 3 / 4.4;
  border-radius: 999px 999px 14px 14px; border: 6px solid #ffe28a;
  box-shadow: 0 0 30px rgba(255, 210, 90, .6); overflow: hidden; perspective: 900px;
  background: #1a1a4a;
}
.fx-light {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 45%, #fff 0%, #fff4c2 25%, color-mix(in srgb, var(--room) 70%, #fff) 55%, var(--room) 100%);
}
.leaf {
  position: absolute; top: 0; bottom: 0; width: 50%;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 255, 255, .25), transparent 60%),
    linear-gradient(180deg, color-mix(in srgb, var(--room) 65%, #1b1f5a), color-mix(in srgb, var(--room) 30%, #0c0f33));
  border: 2px solid rgba(255, 230, 150, .6);
}
.leaf.l { left: 0; transform-origin: left center; border-radius: 999px 0 0 0; }
.leaf.r { right: 0; transform-origin: right center; border-radius: 0 999px 0 0; }
.keyhole {
  position: absolute; left: 50%; top: 55%; width: 26px; height: 40px; transform: translate(-50%, -50%);
  background: radial-gradient(circle at 50% 30%, #fff 0 9px, transparent 10px), linear-gradient(#fff, #fff) 50% 100% / 10px 60% no-repeat;
  filter: drop-shadow(0 0 10px #fff) drop-shadow(0 0 20px var(--gold));
  opacity: .5;
}
.fx-text {
  position: absolute; bottom: 10vh; margin: 0; width: 100%; text-align: center;
  font-size: clamp(34px, 7vw, 64px); font-weight: 900; color: #fff6c9;
  text-shadow: 0 0 20px var(--gold), 0 3px 0 #b8740a; opacity: 0;
}
.fx.play .keyhole { animation: key-flash .8s ease forwards; }
.fx.play .fx-circle { animation: circle-in 1s .1s cubic-bezier(.2, 1.2, .4, 1) forwards, spin 9s 1.1s linear infinite; }
.fx.play .leaf.l { animation: open-l .9s .85s cubic-bezier(.5, 0, .2, 1) forwards; }
.fx.play .leaf.r { animation: open-r .9s .85s cubic-bezier(.5, 0, .2, 1) forwards; }
.fx.play .fx-door { animation: door-glow 1.6s .85s ease forwards; }
.fx.play .fx-rays { animation: rays-in .6s .9s ease-out forwards, spin 14s .9s linear infinite; }
.fx.play .fx-text { animation: text-pop .6s 1.1s cubic-bezier(.2, 1.5, .4, 1) forwards; }
@keyframes key-flash { 0% { opacity: .5; } 50% { opacity: 1; transform: translate(-50%, -50%) scale(1.5); } 100% { opacity: 0; transform: translate(-50%, -50%) scale(2.2); } }
@keyframes circle-in { to { opacity: .95; transform: scale(1) rotate(0deg); } }
@keyframes spin { from { rotate: 0deg; } to { rotate: 360deg; } }
@keyframes open-l { to { transform: rotateY(-105deg); } }
@keyframes open-r { to { transform: rotateY(105deg); } }
@keyframes door-glow { to { box-shadow: 0 0 60px #fff3b5, 0 0 140px var(--room); } }
@keyframes rays-in { to { opacity: 1; transform: scale(1); } }
@keyframes text-pop { from { opacity: 0; transform: scale(.5); } to { opacity: 1; transform: none; } }

/* 모션 줄이기: 간단한 빛 변화만 */
.fx.calm .fx-rays, .fx.calm .fx-circle, .fx.calm .keyhole, .fx.calm .leaf { display: none; }
.fx.calm .fx-door { animation: calm-glow 1.2s ease forwards; }
.fx.calm .fx-text { opacity: 1; }
@keyframes calm-glow { from { box-shadow: 0 0 0 transparent; } to { box-shadow: 0 0 60px #fff3b5; } }

/* 확인 창 */
.modal {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(4, 6, 24, .7); backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.modal-box {
  width: min(100%, 460px); padding: 26px 24px 22px; text-align: center;
  border-radius: 22px; background: #1b2266; border: 3px solid var(--gold);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
  animation: screen-in .25s ease both;
}
.modal-box h2 { margin: 0 0 8px; font-size: 24px; color: var(--gold); }
.modal-box p { margin: 0 0 20px; font-size: 19px; white-space: pre-line; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 70; transform: translate(-50%, 30px);
  padding: 12px 22px; border-radius: 999px; background: #fff; color: #1b1650; font-weight: 800;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35); opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 관리자 모드 */
.admin-link {
  margin-top: 6px; padding: 8px 14px; min-height: 44px; border: 0; border-radius: 12px; cursor: pointer;
  background: transparent; color: var(--ink-soft); font: 600 15px var(--font); text-decoration: underline; text-underline-offset: 3px;
}
.screen-admin-login { display: flex; justify-content: center; padding-top: 6vh; }
.admin-login { width: min(100%, 440px); padding: 28px 24px; text-align: center; display: flex; flex-direction: column; gap: 10px; }
.admin-login h2 { margin: 0; color: var(--gold); font-size: 28px; }
.admin-login p { margin: 0; color: var(--ink-soft); }
.admin-login input {
  min-height: 56px; padding: 0 16px; border-radius: 14px; text-align: center;
  border: 2px solid rgba(255, 255, 255, .35); background: rgba(5, 8, 30, .6); color: #fff; font: 700 22px var(--font);
}
.admin-error { min-height: 1.5em; color: #ffc4d0 !important; font-weight: 700; }
.admin-login-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.admin-head { text-align: center; max-width: 1100px; margin: 0 auto 18px; }
.admin-head h2 { margin: 0; color: var(--gold); font-size: clamp(26px, 4vw, 36px); }
.admin-head p { margin: 6px 0 12px; color: var(--ink-soft); }
.admin-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.admin-list { display: grid; gap: 16px; max-width: 1100px; margin: 0 auto; }
.admin-item {
  border-radius: 18px; background: var(--panel); border: 2px solid var(--line);
  border-left: 10px solid var(--room); overflow: hidden;
}
.admin-item-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 18px; background: rgba(255, 255, 255, .06);
}
.admin-item-head h3 { margin: 0; font-size: 22px; }
.admin-answer { margin: 0; font-size: 18px; color: var(--ink-soft); }
.admin-answer b { margin-left: 6px; font-size: 32px; letter-spacing: 4px; color: var(--gold); font-variant-numeric: tabular-nums; }
.admin-item-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 16px; padding: 16px 18px; }
.admin-problem { margin: 0; background: #fff; border-radius: 12px; padding: 10px; display: flex; align-items: center; justify-content: center; }
.admin-problem img { max-height: 300px; width: 100%; object-fit: contain; }
.admin-text h4 { margin: 0 0 6px; font-size: 18px; color: var(--gold); }
.admin-text h4 + ol { margin-top: 0; }
.admin-text ol { margin: 0 0 14px; padding-left: 1.3em; display: grid; gap: 4px; font-size: 17px; }
.admin-hints li::marker { font-weight: 800; }
.admin-note { color: var(--ink-soft); margin: 0; }
@media (max-width: 760px) { .admin-item-body { grid-template-columns: 1fr; } }

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff !important; color: #111; font-size: 12pt; }
  .sky, .topbar, .admin-actions, .toast, .fx, .modal { display: none !important; }
  main { padding: 0 !important; min-height: 0; }
  .screen { animation: none !important; }
  .admin-head h2, .admin-text h4, .admin-answer b { color: #111 !important; text-shadow: none; }
  .admin-head p, .admin-answer, .admin-note { color: #444 !important; }
  .admin-item { background: #fff !important; border: 1px solid #999; border-left: 8px solid var(--room); break-inside: avoid; page-break-inside: avoid; box-shadow: none; }
  .admin-item-head { background: #f3f3f7 !important; }
  .admin-problem { border: 1px solid #ddd; }
  .admin-problem img { max-height: 220px; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* 반응형 */
@media (max-width: 900px) {
  .doors { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 760px; }
  .door { min-height: clamp(160px, 24vh, 220px); }
}
@media (max-width: 900px), (orientation: portrait) {
  .puzzle { grid-template-columns: 1fr; height: auto; min-height: 0; }
  .puzzle-img-wrap { height: clamp(220px, 42vh, 520px); flex: none; }
  .hintbox { max-height: none; }
  .reveal-body { grid-template-columns: 1fr; }
  .digit { max-height: 84px; }
}
@media (max-width: 640px) {
  :root { --topbar-h: 104px; }
  .topbar { flex-wrap: wrap; height: auto; min-height: var(--topbar-h); padding-top: 6px; padding-bottom: 6px; align-content: center; }
  .status { width: 100%; justify-content: center; order: 2; }
  .sound-btns { width: 100%; justify-content: center; margin: 0; }
  .pill { font-size: 14px; padding: 4px 10px; }
  .chip { min-height: 40px; font-size: 14px; }
  .doors { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .door { min-height: 150px; }
  .stat { min-width: 96px; padding: 6px 12px; }
  .stat.big b { font-size: 30px; }
  .puzzle-actions { grid-template-columns: 1fr; }
  .keypad button { min-height: 54px; }
  .cover-frame { width: 100%; }
}
@media (max-width: 640px) and (orientation: portrait) {
  body:not(.in-game) { --topbar-h: 60px; }
  body:not(.in-game) .status { display: none; }
  body:not(.in-game) .sound-btns { width: auto; margin-left: auto; }
}
/* 세로가 짧은 가로 화면(휴대전화 가로) */
@media (orientation: landscape) and (max-height: 560px) {
  .puzzle { height: auto; min-height: 0; }
  .puzzle-img-wrap { height: 70vh; flex: none; }
  .keypad button { min-height: 46px; font-size: 22px; }
  .digit { max-height: 64px; font-size: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .sky { animation: none; }
  .mini-star { display: none; }
  .final-bigstar { transform: none; }
  .final-glow, .final-title { opacity: 1; }
}

/* ───────── 2편: 잠든 달의 성 ───────── */
:root { --gold: #ffe08a; --gold-deep: #e6a93c; --line: rgba(220, 230, 255, .32); }
body { background: radial-gradient(ellipse at 50% -10%, #2d3a8c 0%, #151c52 38%, #0a0f30 75%) fixed, #0a0f30; }

.story1-link {
  display: inline-flex; align-items: center; gap: 6px; min-height: 48px; padding: 10px 20px; border-radius: 999px;
  color: #fff; font-weight: 800; font-size: 17px; text-decoration: none;
  background: linear-gradient(90deg, rgba(255, 90, 110, .35), rgba(255, 211, 90, .35), rgba(61, 220, 132, .35), rgba(76, 125, 255, .35));
  border: 2px solid rgba(255, 255, 255, .45);
}
.story1-link:hover { filter: brightness(1.15); }

/* 지도: 차오르는 달 */
.star-track { align-items: center; gap: 14px; }
.moon-meter {
  --p: 0%;
  width: 54px; height: 54px; border-radius: 50%; flex: none;
  background: linear-gradient(90deg, #fff6c9 0 var(--p), #2b3266 var(--p) 100%);
  box-shadow: 0 0 calc(6px + var(--p) * .3) rgba(255, 240, 180, .8), inset -4px -4px 10px rgba(0, 0, 0, .25);
  border: 2px solid rgba(255, 246, 201, .6);
}
.star-track .moon-meter-label { font-size: 18px; font-weight: 800; color: #fff6c9; }

/* 정답 카드 */
.moon-card { position: relative; background: #fff; }
.moon-card img { display: block; width: 100%; height: auto; }
.moon-card-badge {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; padding: 8px 26px 10px; border-radius: 18px;
  background: rgba(12, 16, 52, .9); border: 3px solid var(--gold); box-shadow: 0 0 30px rgba(255, 224, 138, .6);
}
.moon-card-badge span { font-size: 15px; font-weight: 700; color: #dfe4ff; }
.moon-card-badge b { font-size: 44px; letter-spacing: 8px; color: var(--gold); font-variant-numeric: tabular-nums; line-height: 1.1; }

/* 탈출 성공: 보름달이 떠오르며 눈을 뜸 */
.final-moon {
  position: absolute; inset: 8%; border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #fffdf0 0%, #fff3b8 45%, #f3d77a 100%);
  box-shadow: 0 0 60px #ffe9a0, 0 0 120px rgba(255, 220, 130, .6), inset -14px -18px 30px rgba(200, 160, 60, .35);
  transform: scale(0); animation: star-pop .9s 1.5s cubic-bezier(.2, 1.5, .4, 1) forwards;
}
.final-moon .eye {
  position: absolute; top: 42%; width: 14%; height: 5%; border-radius: 50%; background: #6b4a1a;
  animation: moon-wake .6s 2.5s ease forwards;
}
.final-moon .eye.l { left: 28%; } .final-moon .eye.r { right: 28%; }
.final-moon .mouth {
  position: absolute; left: 38%; width: 24%; top: 60%; height: 12%;
  border-bottom: 6px solid #6b4a1a; border-radius: 0 0 50% 50%;
  opacity: 0; animation: glow-in .5s 2.8s ease forwards;
}
@keyframes moon-wake { to { height: 14%; top: 38%; } }
@media (prefers-reduced-motion: reduce) {
  .final-moon { transform: none; }
  .final-moon .eye { height: 14%; top: 38%; }
  .final-moon .mouth { opacity: 1; }
}
@media print { .story1-link { display: none !important; } }