/* 집현전 한글 탐험 — 방탈출 게임 (비밀 서재 / 암호방) — .esc-* */

/* ================================================================ */
/* 1. 기호 그림                                                      */
/* ================================================================ */
.esc-g {
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  width: var(--gs, 32px); height: var(--gs, 32px);
  line-height: 1;
}
.esc-g svg { display: block; width: 100%; height: 100%; overflow: visible; }
.esc-g-text { font-size: calc(var(--gs, 32px) * .85); font-weight: 900; font-family: var(--font); }

/* ================================================================ */
/* 2. 비밀 서재                                                      */
/* ================================================================ */
.esc-lib {
  position: relative;
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 14px 16px;
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, .07) 0 2px, rgba(0, 0, 0, 0) 2px 23px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .03) 0 1px, rgba(0, 0, 0, 0) 1px 9px),
    linear-gradient(180deg, #6e4221 0%, #56321a 100%);
  border: 4px solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow-lg), inset 0 0 0 4px #8a5a2c;
}

/* 책장 한 줄 */
.esc-shelf {
  display: flex; align-items: flex-end; gap: 3px;
  height: 50px;
  margin-bottom: 10px;
  padding: 0 10px;
  overflow: hidden;
  background: linear-gradient(180deg, #2e1a0b 0%, #432713 100%);
  border: 3px solid var(--ink);
  border-bottom: 9px solid #b07236;
  border-radius: 10px 10px 6px 6px;
  box-shadow: inset 0 8px 12px rgba(0, 0, 0, .45);
}
.esc-book {
  position: relative;
  flex: 0 0 auto;
  background: var(--c, #8a5a2c);
  border: 2px solid rgba(0, 0, 0, .5);
  border-bottom: 0;
  border-radius: 3px 3px 0 0;
  box-shadow: inset 3px 0 0 rgba(255, 255, 255, .22), inset -3px 0 0 rgba(0, 0, 0, .22);
}
.esc-book::before, .esc-book::after {
  content: ""; position: absolute; left: 2px; right: 2px; height: 3px;
  background: rgba(255, 226, 140, .75);
}
.esc-book::before { top: 18%; }
.esc-book::after { top: 26%; }
.esc-shelf-deco { flex: 0 0 auto; font-size: 34px; line-height: 1; margin: 0 5px 1px; }
.esc-shelf-key { font-size: 28px; align-self: center; }
.esc-candle { display: inline-block; transform-origin: 50% 90%; animation: esc-flicker 2.2s ease-in-out infinite; filter: drop-shadow(0 0 8px rgba(255, 200, 80, .75)); }
@keyframes esc-flicker {
  0%, 100% { transform: scale(1) rotate(-1.5deg); }
  45% { transform: scale(1.05) rotate(1.5deg); }
  70% { transform: scale(.98) rotate(-.5deg); }
}

/* 자물쇠 줄 (runQuiz lockMode) — 나무 위 금속판 */
.esc-lib .locks {
  margin-bottom: 10px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, .28);
  border-radius: 16px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .35);
}
.esc-lib .lock.open { box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .2), 0 3px 0 var(--ink), 0 0 16px rgba(255, 210, 90, .85); }
.esc-lib .hint-box { margin-top: 12px; }

.esc-lib-head { gap: 10px; }
.esc-lib .q-card { gap: 16px; padding-top: 18px; }
.esc-lock-title {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 14px;
  background: #5b3a1e; color: #ffe9a8;
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: 16px; font-weight: 900;
  letter-spacing: .5px;
}
.esc-lib .q-prompt b { color: #9c3d00; background: linear-gradient(transparent 62%, #ffe08a 62%); }

/* 숫자 다이얼 입력 */
.esc-numwrap { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; }
.esc-dial-row { max-width: 440px; }
@media (min-width: 760px) {
  .esc-numwrap { flex-direction: row; justify-content: center; align-items: center; gap: 18px; }
  .esc-numwrap .esc-dial-row { flex: 1 1 320px; max-width: 380px; margin: 0; }
  .esc-numwrap .esc-keypad { flex: 1 1 330px; max-width: 360px; margin: 0; }
}
.answer-input.esc-dial {
  font-size: 40px; font-weight: 900;
  letter-spacing: .35em; text-indent: .35em;
  font-variant-numeric: tabular-nums;
  color: #ffd766;
  background: linear-gradient(180deg, #24160a 0%, #4a2c14 100%);
  border-color: var(--ink);
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, .55), 0 3px 0 var(--ink);
  caret-color: #ffd766;
}
.answer-input.esc-dial::placeholder { color: rgba(255, 231, 160, .6); letter-spacing: 0; text-indent: 0; font-size: 20px; }
.answer-input.esc-dial:focus { border-color: var(--gold); box-shadow: inset 0 4px 10px rgba(0, 0, 0, .55), 0 0 0 4px rgba(245, 184, 46, .45); }
.answer-input.esc-dial.wrong { border-color: var(--red); background: linear-gradient(180deg, #3a1210 0%, #5a1c18 100%); box-shadow: inset 0 4px 10px rgba(0, 0, 0, .55), 0 0 0 4px rgba(214, 69, 65, .45); }
.answer-input.esc-dial.ok { border-color: var(--green); color: #b2f2bb; box-shadow: inset 0 4px 10px rgba(0, 0, 0, .55), 0 0 0 4px rgba(47, 158, 68, .5); }

.esc-keypad {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) minmax(0, 1.25fr);
  gap: 8px;
  width: 100%; max-width: 440px;
  margin: 0 auto;
}
.btn.esc-key {
  min-height: 52px; min-width: 0;
  padding: 4px;
  font-size: 26px; font-weight: 900;
  font-variant-numeric: tabular-nums;
  background: #fffdf6;
  border-radius: 14px;
}
.btn.esc-key-back {
  grid-column: 6; grid-row: 1 / span 2;
  flex-direction: column; gap: 2px;
  font-size: 22px;
  background: var(--paper-2);
}
.esc-key-back-t { font-size: 15px; font-weight: 800; }

/* 서랍 열림 연출 */
.esc-drawer { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 10px 6px; text-align: center; }
.esc-drawer-stage { position: relative; width: 280px; height: 230px; }
.esc-drawer-cab {
  position: absolute; left: 10px; right: 10px; bottom: 6px; height: 120px;
  background: linear-gradient(180deg, #8a5a2c 0%, #6b4020 100%);
  border: 4px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 6px 0 var(--ink), inset 0 0 0 4px rgba(255, 220, 160, .15);
  z-index: 2;
}
.esc-drawer-front {
  position: absolute; left: 20px; right: 20px; top: 24px; height: 66px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #d7995a 0%, #b07236 100%);
  border: 4px solid var(--ink);
  border-radius: 10px;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, .3);
  transition: transform .6s var(--ease-pop);
}
.esc-drawer-handle { width: 64px; height: 16px; background: linear-gradient(180deg, #ffe27a, var(--gold-2)); border: 3px solid var(--ink); border-radius: 10px; }
.esc-drawer.open .esc-drawer-front { transform: translateY(22px) scale(1.14); }
.esc-scroll {
  position: absolute; left: 50%; bottom: 60px; z-index: 1;
  width: 110px; height: 110px; margin-left: -55px;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  background: transparent; border: 0; border-radius: 50%;
  font-size: 80px; line-height: 1;
  opacity: 0;
  transform: translateY(40px) scale(.3);
  transition: transform .75s var(--ease-pop) .3s, opacity .35s ease .3s;
  cursor: pointer;
}
.esc-scroll .emoji { filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .35)); }
.esc-drawer.open .esc-scroll { opacity: 1; transform: translateY(-40px) scale(1); z-index: 3; }
.esc-drawer-glow {
  position: absolute; left: 50%; top: 0; width: 200px; height: 200px; margin-left: -100px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 226, 122, .85) 0%, rgba(255, 200, 60, .35) 40%, rgba(255, 200, 60, 0) 70%);
  opacity: 0; transform: scale(.4);
  transition: opacity .6s ease .45s, transform .9s ease .45s;
  pointer-events: none;
}
.esc-drawer.open .esc-drawer-glow { opacity: 1; transform: scale(1); }
.esc-drawer-text { font-size: 30px; font-weight: 900; color: #ffe27a; text-shadow: 0 3px 0 var(--ink); }
.esc-drawer-sub { font-size: 19px; font-weight: 800; color: #fff3d6; }

/* ================================================================ */
/* 3. 암호방                                                         */
/* ================================================================ */
.esc-cipher { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.esc-lower { --gs: 44px; --tg: 38px; }
.esc-upper { --gs: 28px; --tg: 28px; }

/* 대응표 (두루마리) */
.esc-table {
  position: relative;
  margin: 10px 4px;
  padding: 12px 12px 14px;
  background:
    radial-gradient(ellipse at 20% 15%, rgba(255, 255, 255, .6), rgba(255, 255, 255, 0) 55%),
    linear-gradient(180deg, #fff5d9 0%, #f6e3b4 100%);
  border: 3px solid var(--ink);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
}
.esc-table::before, .esc-table::after {
  content: ""; position: absolute; left: -10px; right: -10px; height: 16px;
  background: linear-gradient(180deg, #c98a4b 0%, #8a5a2c 100%);
  border: 3px solid var(--ink);
  border-radius: 10px;
}
.esc-table::before { top: -12px; }
.esc-table::after { bottom: -12px; }
.esc-table-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 8px; }
.esc-table-title { font-size: 20px; font-weight: 900; }
.esc-table-toggle { flex: 0 0 auto; }
.esc-table-sub {
  display: inline-block;
  margin: 2px 0 6px;
  padding: 0 10px;
  font-size: 14px; font-weight: 900; color: #fff;
  background: var(--ink-2);
  border-radius: 999px;
}
.esc-sec + .esc-sec { margin-top: 8px; }
.esc-grid { display: grid; gap: 6px; }
.esc-lower .esc-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.esc-upper .esc-grid-cons { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.esc-upper .esc-grid-vows { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.esc-cell {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-width: 0;
  padding: 6px 2px 5px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 12px;
  transition: transform .15s ease, background-color .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.esc-cell .esc-g { --gs: var(--tg); }
.esc-cell-j {
  display: block; width: 100%;
  padding-top: 3px;
  border-top: 2px dashed var(--line);
  text-align: center;
  font-size: 24px; font-weight: 900; line-height: 1.1;
}
.esc-upper .esc-cell-j { font-size: 19px; }
.esc-cell.esc-hl {
  background: var(--gold-soft);
  border-color: var(--gold-2);
  box-shadow: 0 0 0 3px var(--gold), 0 0 16px rgba(245, 184, 46, .8);
  transform: scale(1.1);
  position: relative; z-index: 1;
}

/* 문제 카드 안 암호 */
.esc-q-head { gap: 12px; }
.esc-q-lead { font-size: 22px; font-weight: 900; }
.esc-q-tip { font-size: 15px; font-weight: 700; color: var(--ink-2); }
.esc-code {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start;
  gap: 12px 30px;
  width: 100%;
  padding: 14px 10px;
  background:
    repeating-linear-gradient(0deg, rgba(107, 74, 43, .06) 0 1px, rgba(0, 0, 0, 0) 1px 26px),
    #fdf3dc;
  border: 3px solid var(--ink-2);
  border-radius: 16px;
  box-shadow: inset 0 3px 0 rgba(59, 36, 18, .08);
}
.esc-word { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.esc-upper .esc-word { padding-bottom: 6px; border-bottom: 3px dotted var(--ink-2); }
.esc-syl {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 48px; min-height: 48px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .1s ease, background-color .15s ease, box-shadow .15s ease;
  touch-action: manipulation;
}
.esc-syl:hover:not(:disabled) { background: #fffbe8; transform: translateY(-1px); }
.esc-syl:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.esc-syl:disabled { cursor: default; opacity: 1; color: var(--ink); }
.esc-syl.esc-on { background: var(--gold-soft); border-color: var(--gold-2); box-shadow: 0 3px 0 var(--gold-2), 0 0 0 3px var(--gold); }
.esc-lower .esc-syl { padding: 10px 12px; border-radius: 18px; }
.esc-glyphs { display: inline-flex; align-items: center; gap: 3px; transition: opacity .25s ease; }
.esc-lower .esc-glyphs { gap: 5px; }
.esc-syl-txt {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--gs) * 1.05); font-weight: 900; line-height: 1;
  color: #1d5a2a;
  animation: jh-stamp .4s var(--ease-pop) both;
}
.esc-syl.revealed { background: var(--green-soft); border-color: var(--green); box-shadow: 0 3px 0 var(--green); }
.esc-syl.revealed .esc-glyphs { opacity: .14; }
.esc-lower .esc-syl-txt { font-size: 44px; }
.esc-upper .esc-syl-txt { font-size: 30px; }

/* ================================================================ */
/* 4. 반응형                                                          */
/* ================================================================ */
@media (min-width: 860px) {
  .esc-cipher { grid-template-columns: 290px minmax(0, 1fr); gap: 22px; }
  .esc-cipher.esc-upper { grid-template-columns: 330px minmax(0, 1fr); }
  .esc-table { position: sticky; top: calc(var(--hud-h) + 22px); }
  .esc-table-toggle { display: none; }
  .esc-table.collapsed .esc-table-body { display: block; }
}
@media (max-width: 859px) {
  .esc-table.collapsed .esc-table-body { display: none; }
  .esc-table.collapsed .esc-table-head { margin-bottom: 0; }
  /* 저학년: 자음(4칸×2줄) | 모음(2칸×2줄) 나란히 */
  .esc-lower .esc-table-body { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 10px; }
  .esc-lower .esc-sec + .esc-sec { margin-top: 0; }
  .esc-lower .esc-grid-vows { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .esc-upper .esc-grid-cons { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .esc-upper .esc-grid-vows { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .esc-lower { --tg: 32px; }
  .esc-upper { --tg: 24px; }
}
@media (max-width: 600px) {
  .esc-lib { padding: 10px 8px 12px; border-radius: 18px; }
  .esc-shelf { height: 46px; margin-bottom: 10px; }
  .esc-shelf-deco { font-size: 28px; }
  .esc-lock-title { font-size: 15px; }
  .answer-input.esc-dial { font-size: 32px; }
  .btn.esc-key { min-height: 50px; font-size: 22px; }
  .esc-drawer-stage { width: 250px; height: 210px; }
  .esc-drawer-text { font-size: 25px; }

  .esc-lower { --gs: 38px; --tg: 28px; }
  .esc-upper { --gs: 23px; --tg: 21px; }
  .esc-table { padding: 10px 8px 12px; }
  .esc-table-title { font-size: 18px; }
  .esc-cell { padding: 4px 1px 3px; border-radius: 9px; }
  .esc-cell-j { font-size: 20px; }
  .esc-upper .esc-cell-j { font-size: 15px; }
  .esc-grid { gap: 4px; }
  .esc-code { gap: 10px 18px; padding: 10px 6px; }
  .esc-syl { padding: 6px 6px; border-radius: 12px; }
  .esc-lower .esc-syl { padding: 8px 10px; }
  .esc-upper .esc-glyphs { gap: 2px; }
  .esc-upper .esc-word { gap: 4px; }
  .esc-upper .esc-syl-txt { font-size: 24px; }
  .esc-lower .esc-syl-txt { font-size: 38px; }
  .esc-q-lead { font-size: 19px; }
  .esc-q-tip { font-size: 14px; }
}
@media (max-width: 380px) {
  .esc-upper .esc-grid-cons { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .esc-upper .esc-cell-j { font-size: 14px; }
  .esc-upper { --gs: 22px; }
}

/* ================================================================ */
/* 5. 움직임 줄이기                                                   */
/* ================================================================ */
@media (prefers-reduced-motion: reduce) {
  .esc-candle { animation: none; }
  .esc-drawer-front, .esc-scroll, .esc-drawer-glow, .esc-cell, .esc-syl { transition: none; }
  .esc-cell.esc-hl { transform: none; }
  .esc-syl-txt { animation: none; }
}
