:root {
  --paper: #f4f1ea;
  --panel: #ffffff;
  --ink: #1e2a32;
  --ink-soft: #5b6770;
  --line: #d9d4c8;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #e3ece8;
  --warm: #c98a2b;
  --good: #2e7d5b;
  --bad: #b4482f;
  --radius: 1.2cqh;
  --font: "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  --font-en: Georgia, "Times New Roman", serif;
  /* 화면 높이에 맞춰 커지는 글자 크기(크롬북·전자칠판 공통) */
  --fs-s: 2.1cqh;
  --fs-m: 2.6cqh;
  --fs-l: 3.4cqh;
  --fs-xl: 4.8cqh;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; touch-action: manipulation; -webkit-text-size-adjust: 100%; }
body { background: #12181d; color: var(--ink); font-family: var(--font); line-height: 1.45; }
h1, h2, p, figure { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }
.hidden { display: none !important; }
kbd { font: inherit; font-size: 0.72em; padding: 0.1em 0.5em; margin-left: 0.6em; border: 1px solid currentColor; border-radius: 0.4em; opacity: 0.65; }

/* 창 모양과 상관없이 16:9 틀 안에 전부 그린다. 틀 안의 크기 단위는 cqw·cqh */
#frame { position: fixed; left: 50%; top: 50%; width: min(100vw, 177.78vh); height: min(100vh, 56.25vw); transform: translate(-50%, -50%); container-type: size; overflow: hidden; background: var(--paper); }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#ui { position: absolute; inset: 0; font-size: var(--fs-m); }
#modal-root { font-size: var(--fs-m); }
#ui[data-screen="home"], #ui[data-screen="shelf"] { background: var(--paper); }
#ui[data-screen="play"] { pointer-events: none; }
#ui[data-screen="play"] .screen > * { pointer-events: auto; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* 공통 부품 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5em; padding: 0.6em 1.2em; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); font-weight: 600; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:focus-visible, .icon-btn:focus-visible, .profile-main:focus-visible, .gate-option:focus-visible { outline: 3px solid var(--warm); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { padding: 0.35em 0.8em; font-size: var(--fs-s); }
.btn.big { padding: 0.75em 1.8em; font-size: var(--fs-l); }
.icon-btn { display: inline-grid; place-items: center; width: 2.2em; height: 2.2em; border: 1px solid var(--line); border-radius: 50%; background: var(--panel); }
.row { display: flex; gap: 0.8em; align-items: center; }
.row.end { justify-content: flex-end; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 2cqw; padding: 3cqh 4cqw 0; }
.field { display: flex; flex-direction: column; gap: 0.4em; }
.field > span, .opt-group > span { font-size: var(--fs-s); font-weight: 700; color: var(--ink-soft); }
.field input[type="text"] { padding: 0.55em 0.8em; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.field input:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
.field-note { font-size: var(--fs-s); color: var(--ink-soft); margin-top: -0.6em; }
.seg, .tabs { display: flex; gap: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.seg button, .tabs button { flex: 1; padding: 0.55em 1em; border: 0; border-right: 1px solid var(--line); background: transparent; font-weight: 600; white-space: nowrap; }
.seg button:last-child, .tabs button:last-child { border-right: 0; }
.seg button.on, .tabs button.on { background: var(--accent); color: var(--accent-ink); }

/* 창 */
.modal-backdrop { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(20, 28, 34, 0.55); z-index: 50; }
.modal { width: 62cqw; max-height: 90cqh; overflow: auto; padding: 4cqh 3cqw; border-radius: calc(var(--radius) * 1.5); background: var(--panel); }
.confirm { display: flex; flex-direction: column; gap: 3cqh; font-size: var(--fs-l); }
.settings-lock { display: flex; flex-direction: column; gap: 2cqh; }
.settings-lock input { width: 8em; padding: 0.5em 0.8em; border: 1px solid var(--line); border-radius: var(--radius); font-size: var(--fs-l); }
.lock-msg, .set-msg { min-height: 1.4em; color: var(--bad); font-size: var(--fs-s); }
.settings { display: flex; flex-direction: column; gap: 1.6cqh; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 3cqw; padding: 1.4cqh 0; border-top: 1px solid var(--line); }
.set-row p { font-size: var(--fs-s); color: var(--ink-soft); }
.set-ctl { display: flex; align-items: center; gap: 0.8em; flex-shrink: 0; }
.set-ctl input[type="range"] { width: 22cqh; accent-color: var(--accent); }
.set-ctl output { min-width: 3em; font-weight: 700; text-align: right; }
.set-profiles { display: flex; flex-wrap: wrap; gap: 0.6em; justify-content: flex-end; }
.set-profiles span { display: inline-flex; align-items: center; gap: 0.5em; font-size: var(--fs-s); }
.switch { position: relative; flex-shrink: 0; width: 3.2em; height: 1.7em; }
.switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 1em; background: var(--line); transition: background 0.15s; pointer-events: none; }
.switch i::after { content: ""; position: absolute; top: 0.2em; left: 0.2em; width: 1.3em; height: 1.3em; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(1.5em); }
.switch input:focus-visible + i { outline: 3px solid var(--warm); }

/* 첫 화면 */
.brand h1 { font-family: var(--font-en); font-size: var(--fs-xl); letter-spacing: -0.01em; }
.brand p { color: var(--ink-soft); }
.home-ask { padding: 5cqh 4cqw 2.5cqh; font-size: var(--fs-l); }
.browser-notice { display: flex; flex-direction: column; gap: 0.4cqh; margin: 2cqh 4cqw 0; padding: 1.5cqh 2cqw; border: 1px solid #d4bb7a; border-left: 0.7cqh solid #b2852e; border-radius: var(--radius); background: #fbf2d7; font-size: var(--fs-s); }
.browser-notice strong { color: #775312; font-size: var(--fs-m); }
.browser-notice.unsupported { background: #fce6df; border-color: #bc6d54; }
.browser-notice.unsupported strong { color: #8e3f29; }
.home:has(.browser-notice) .home-ask { padding-top: 2.5cqh; }
.shelf-browser-note { margin: 1.2cqh 4cqw 0; color: #775312; font-size: var(--fs-s); }
.gate-browser-note { padding: 0.3em 0.8em; border-radius: var(--radius); background: #fbf2d7; color: #775312; font-size: var(--fs-s); font-weight: 600; }
.profile-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1.6cqw; padding: 0 4cqw; }
.profile-card { position: relative; }
.profile-main { display: flex; flex-direction: column; align-items: center; gap: 0.3em; width: 100%; padding: 2.5cqh 1cqw 3cqh; border: 1px solid var(--line); border-radius: calc(var(--radius) * 1.5); background: var(--panel); }
.profile-main:hover { border-color: var(--accent); }
.profile-main img, .add-icon { width: 100%; max-width: 22cqh; aspect-ratio: 1; object-fit: contain; border-radius: var(--radius); background: #ece7dc; }
.add-icon { display: grid; place-items: center; font-size: 6cqh; color: var(--ink-soft); background: transparent; border: 2px dashed var(--line); }
.profile-main strong { font-size: var(--fs-l); margin-top: 0.4em; }
.profile-main span:not(.add-icon) { font-size: var(--fs-s); color: var(--ink-soft); }
.profile-edit { position: absolute; top: 1cqh; right: 1cqh; }
.note { margin-top: auto; padding: 3cqh 4cqw; font-size: var(--fs-s); color: var(--ink-soft); }

/* 캐릭터 만들기 */
.editor { flex-direction: row; }
.editor-view { flex: 1; position: relative; cursor: grab; touch-action: none; }
.editor-hint { position: absolute; left: 0; right: 0; bottom: 3cqh; text-align: center; font-size: var(--fs-s); color: var(--ink-soft); }
.editor-panel { width: 46cqw; display: flex; flex-direction: column; gap: 1.8cqh; padding: 3.5cqh 3cqw; background: var(--panel); border-left: 1px solid var(--line); }
.editor-panel h2 { font-size: var(--fs-l); }
.tab-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 1.8cqh; }
.opt-group { display: flex; flex-direction: column; gap: 0.6cqh; }
.opt-items { display: flex; flex-wrap: wrap; gap: 1cqh; }
.swatch { width: 5.4cqh; height: 5.4cqh; border-radius: 50%; border: 2px solid rgba(0, 0, 0, 0.12); background: var(--c); }
.swatch.on { outline: 3px solid var(--accent); outline-offset: 3px; }
.chip { padding: 0.45em 1em; border: 1px solid var(--line); border-radius: 2em; background: var(--panel); font-size: var(--fs-s); font-weight: 600; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.others { display: flex; align-items: center; gap: 1cqw; font-size: var(--fs-s); color: var(--ink-soft); }
.others figure { display: flex; flex-direction: column; align-items: center; }
.others img { width: 7cqh; height: 7cqh; object-fit: contain; border-radius: var(--radius); background: #ece7dc; }
.editor-msg { min-height: 1.5em; color: var(--bad); font-size: var(--fs-s); font-weight: 600; }

/* 책장 */
.who { display: flex; align-items: center; gap: 0.7em; margin-right: auto; }
.who img { width: 6cqh; height: 6cqh; object-fit: contain; border-radius: 50%; background: #ece7dc; }
.who span { font-size: var(--fs-s); color: var(--ink-soft); }
.shelf .tabs { width: 40cqw; }
.shelf-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 3cqh; padding: 3.5cqh 4cqw 4cqh; }
.storybook-library { flex: 1; min-height: 0; display: grid; grid-template-columns: 1.05fr 1fr; gap: 3cqw; }
.bookcase { min-width: 0; display: flex; flex-direction: column; padding: 2cqh 2cqw 3cqh; border: 1px solid #d7c5a6; border-radius: 2cqh; background: radial-gradient(ellipse at 50% 10%, #fff9e9 0, transparent 65%), repeating-linear-gradient(0deg, #e9ddc833 0 1px, transparent 1px 4px), #eee3d1; box-shadow: inset 0 0 5cqh #c4aa7433; }
.bookcase-heading { text-align: center; margin-bottom: 1.5cqh; }
.bookcase-heading > span { color: #a97c31; font-size: 2.6cqh; }
.bookcase-heading h1 { font-size: 2.8cqh; font-weight: 700; letter-spacing: -0.03em; }
.bookcase-heading p { font-size: 1.9cqh; margin-top: 0.5cqh; color: #76664f; }
.books { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 2cqh 1.4cqw; align-content: space-evenly; padding: 1cqh 0.7cqw 0; perspective: 1100px; }
.book { --book-depth: 1.6cqh; position: relative; display: block; width: 100%; height: 24cqh; min-width: 0; padding: 0; border: 0; background: transparent; color: #fff8de; isolation: isolate; perspective: 850px; text-align: center; outline-offset: 0.6cqh; }
.book::after { content: ''; position: absolute; left: -6%; right: -8%; bottom: -1.4cqh; height: 0.9cqh; border-radius: 50%; background: #72533744; filter: blur(0.7cqh); z-index: -1; }
.book-shell { position: absolute; inset: 0; display: block; transform-style: preserve-3d; transform: rotateX(4deg) rotateY(-21deg) rotateZ(-1deg); transition: transform 0.65s cubic-bezier(.22,.7,.25,1); }
.book-cover, .book-back { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 2px 6px 6px 2px; background: linear-gradient(95deg, #0005, transparent 12%, #ffffff13 70%, #0002), repeating-linear-gradient(15deg, transparent 0 2px, #fff1 2px 3px), var(--c); border: 1px solid #e7c58288; box-shadow: inset 3px 0 3px #0004, inset 0 0 0 4px #1113; backface-visibility: hidden; }
.book-cover { transform: translateZ(var(--book-depth)); padding: 1.1cqh 0.6cqw 0.8cqh; gap: 0.4cqh; }
.book-cover::after, .book-back::after { content: ''; position: absolute; inset: 0.65cqh 0.45cqw; border: 1px solid #efd28a99; border-radius: 1px 3px 3px 1px; pointer-events: none; }
.book-back { transform: rotateY(180deg) translateZ(var(--book-depth)); gap: 1.6cqh; padding: 1.6cqh 0.8cqw; }
.book-back-motif { display: grid; place-items: center; width: 8cqh; height: 8cqh; border: 1px solid #e0c17a; border-radius: 50%; color: #f5d690; font-family: var(--font-en); font-size: 6cqh; text-shadow: 0 2px 2px #0004; }
.book-back-title { font-size: 1.9cqh; font-weight: 600; }
.book-back-label { font-family: var(--font-en); font-size: 1.25cqh; color: #f5d690; letter-spacing: 0.06em; }
.book-pages { position: absolute; top: 0.5cqh; bottom: 0.5cqh; right: 0; width: calc(var(--book-depth) * 2); transform: rotateY(90deg) translateX(var(--book-depth)); transform-origin: right center; background: repeating-linear-gradient(90deg, #f6e9ce 0 2px, #c6bba2 2px 3px, #fffbef 3px 5px); border: 1px solid #bbaa87; border-radius: 2px; }
.book-spine { position: absolute; top: 0; bottom: 0; left: 0; display: flex; align-items: center; justify-content: center; width: calc(var(--book-depth) * 2); transform: rotateY(-90deg) translateX(calc(var(--book-depth) * -1)); transform-origin: left center; background: linear-gradient(90deg, #0005, transparent 50%, #fff2), var(--c); border: 1px solid #e4c17888; color: #f9e0a0; border-radius: 4px; }
.book-spine::before, .book-spine::after { content: ''; position: absolute; inset: 10% 0 auto; height: 0.55cqh; border-top: 1px solid #e9c67f; border-bottom: 1px solid #e9c67f; }
.book-spine::after { inset: auto 0 10%; }
.book-spine > span { writing-mode: vertical-rl; font-size: 1.5cqh; font-weight: 700; letter-spacing: 0.14em; max-height: 70%; overflow: hidden; }
.book-foil { display: block; color: #f1d58f; font-size: 2.4cqh; height: 2.6cqh; line-height: 1; text-shadow: 0 1px 1px #0006; }
.book-cover-art { display: block; width: 92%; height: 10.5cqh; flex-shrink: 0; overflow: hidden; border: 1px solid #e8ca8299; border-radius: 40% 40% 6px 6px / 20% 20% 6px 6px; background: #f4ecd6; box-shadow: 0 1px 5px #0005; }
.book-cover-art img { width: 100%; height: 100%; display: block; object-fit: cover; }
.book-title { font-family: var(--font-en); font-size: 1.85cqh; line-height: 1.16; font-weight: 700; margin-top: 0.5cqh; text-shadow: 0 1px 1px #0006; }
.book-ko { font-size: 1.5cqh; line-height: 1.3; color: #ffebba; }
.book-cover-flourish { font-size: 1.4cqh; line-height: 1; color: #f1d58f; }
.book-aura { position: absolute; inset: -12% -16%; pointer-events: none; opacity: 0; background: radial-gradient(ellipse, #ffd78375 0, #e9b65e33 38%, transparent 70%); transition: opacity 0.6s; z-index: -1; }
.book-aura::before, .book-aura::after { content: '✦'; position: absolute; top: 8%; right: 12%; color: #bb8f38; font-size: 2cqh; }
.book-aura::after { content: '✧'; top: auto; right: auto; left: 6%; bottom: 14%; font-size: 2.6cqh; }
.book:hover .book-shell { transform: translateY(-0.6cqh) rotateX(2deg) rotateY(-12deg) rotateZ(0deg); }
.book.on { z-index: 2; animation: book-pick 0.72s cubic-bezier(.2,.75,.25,1) both; }
.book.on .book-shell { animation: book-orbit 24s 0.7s linear infinite; transform: translateY(-0.8cqh) rotateX(3deg) rotateY(-17deg); }
.book.on .book-aura { opacity: 1; animation: book-glow 6s ease-in-out infinite; }
.book.on:focus-visible .book-shell { animation-play-state: paused; }
.book:focus-visible { outline: 2px solid #b18436; border-radius: 6px; }
@keyframes book-pick { 0% { transform: translateY(0) scale(1); } 50% { transform: translateY(-0.8cqh) scale(1.075); } 100% { transform: translateY(-0.35cqh) scale(1.035); } }
@keyframes book-orbit { 0% { transform: translateY(-0.8cqh) rotateX(3deg) rotateY(-17deg) rotateZ(-1deg); } 25% { transform: translateY(-1.3cqh) rotateX(2deg) rotateY(73deg) rotateZ(1deg); } 50% { transform: translateY(-0.8cqh) rotateX(3deg) rotateY(163deg) rotateZ(-1deg); } 75% { transform: translateY(-1.3cqh) rotateX(2deg) rotateY(253deg) rotateZ(1deg); } 100% { transform: translateY(-0.8cqh) rotateX(3deg) rotateY(343deg) rotateZ(-1deg); } }
@keyframes book-glow { 50% { opacity: 0.5; } }
.album-select { display: flex; align-items: center; gap: 0.8em; font-size: var(--fs-s); }
.album-select select { padding: 0.4em 0.8em; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); max-width: 100%; }
.book.soon { opacity: 0.42; }
.book-soon { position: absolute; top: 1.4cqh; right: 1cqw; font-size: var(--fs-s); }
.book-detail { min-height: 0; min-width: 0; display: flex; flex-direction: column; gap: 1.5cqh; padding: 1.4cqh 1.6cqw 2cqh; border: 1px solid #d8cdb8; border-radius: 2cqh; background: #fffaf0; box-shadow: 0 0.8cqh 3cqh #8e724314; }
.book-preview { position: relative; width: 100%; height: 27cqh; min-height: 0; flex-shrink: 0; overflow: hidden; border: 1px solid #dccba9; border-radius: 1.3cqh; background: #e9e4d2; }
.book-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-preview figcaption { position: absolute; bottom: 0; left: 0; right: 0; padding: 0.8cqh 1cqw; font-size: 1.7cqh; letter-spacing: 0.04em; color: #fff4dc; background: linear-gradient(transparent, #1d2d2bc4); }
.book-preview figcaption > span { margin-right: 0.4em; color: #edca78; }
.book-detail h2 { font-family: var(--font-en); font-size: 3.35cqh; line-height: 1.16; }
.detail-ko { color: #877043; margin-top: 0.3cqh; font-size: 2.1cqh; }
.detail-blurb { margin-top: 1cqh; max-width: 34em; font-size: 2.1cqh; line-height: 1.5; }
.detail-side { display: flex; flex-direction: column; gap: 1.2cqh; min-width: 0; margin-top: auto; }
.detail-side .seg button { font-size: 1.9cqh; padding: 0.5em; }
.detail-side .row { gap: 0.7cqw; }
.detail-side .btn { font-size: 1.8cqh; padding: 0.6em 0.8em; }
.detail-side .btn.big { font-size: 2.4cqh; padding: 0.55em 1em; }
.detail-copy .detail-progress { margin-top: 0.7cqh; font-size: 1.8cqh; min-height: 1.4em; }
.empty { margin: auto; color: var(--ink-soft); }
.notes { flex: 1; min-height: 0; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: calc(var(--radius) * 1.5); background: var(--panel); overflow: hidden; }
.notes-head, .notes-row { display: grid; grid-template-columns: 1fr 6em 6em 9em 3.5em; align-items: center; gap: 1cqw; padding: 1.2cqh 2cqw; }
.notes-head { font-size: var(--fs-s); font-weight: 700; color: var(--ink-soft); border-bottom: 1px solid var(--line); }
.notes-list { flex: 1; overflow-y: auto; }
.notes-row { border-bottom: 1px solid var(--line); }
.notes-row.fail .notes-text { color: var(--bad); }
.notes-text { font-family: var(--font-en); font-size: var(--fs-l); }

/* 플레이 */
.hud { display: flex; align-items: center; gap: 1.5cqw; padding: 2cqh 2cqw; pointer-events: none !important; }
.hud > * { pointer-events: auto; }
.hud-exit { position: relative; z-index: 10; }
.hud > * { box-shadow: 0 0.3cqh 1.2cqh rgba(0, 0, 0, 0.18); }
.hud-chapter, .hud-goal, .hud-mini { padding: 0.5em 1em; border-radius: var(--radius); background: rgba(255, 255, 255, 0.94); font-size: var(--fs-s); font-weight: 600; }
.hud-chapter { font-family: var(--font-en); }
.hud-chapter:empty { display: none; }
.hud-goal { margin-left: auto; }
.hud-mini { margin-left: auto; display: flex; align-items: center; gap: 1em; font-size: var(--fs-m); }
.mini-bar { width: 26cqw; height: 1.4cqh; border-radius: 1cqh; background: var(--line); overflow: hidden; }
.mini-bar i { display: block; height: 100%; background: var(--warm); }

#stage.orbit-ready { cursor: grab; }
#stage.orbit-dragging { cursor: grabbing; }
.camera-tools { position: absolute; top: 12cqh; right: 2cqw; display: flex; flex-direction: column; align-items: flex-end; gap: 0.5cqh; }
.camera-buttons { display: flex; gap: 0.5cqw; }
.camera-buttons .btn { background: rgba(255, 255, 255, 0.94); min-width: 2.4em; }
.camera-hint { padding: 0.25em 0.6em; border-radius: var(--radius); background: rgba(30, 42, 50, 0.78); color: #fff; font-size: var(--fs-s); pointer-events: none; }

.markers { position: absolute; inset: 0; pointer-events: none !important; }
.marker { position: absolute; transform: translate(-50%, -100%); display: flex; align-items: center; gap: 0.5em; padding: 0.3em 0.8em; border: 0; border-radius: 2em; background: rgba(30, 42, 50, 0.78); color: #fff; font-family: var(--font-en); font-size: var(--fs-s); pointer-events: auto; }
.marker-key { display: none; padding: 0 0.5em; border-radius: 0.4em; background: var(--warm); color: #1e2a32; font-family: var(--font); font-weight: 700; }
.marker.near { background: var(--accent); font-size: var(--fs-m); z-index: 2; }
.marker.near .marker-key { display: inline; }

.dialogue { position: absolute; left: 6cqw; right: 6cqw; bottom: 4cqh; min-height: 22cqh; padding: 3.2cqh 3cqw 3cqh; border-radius: calc(var(--radius) * 1.5); background: rgba(255, 255, 255, 0.96); box-shadow: 0 0.6cqh 3cqh rgba(0, 0, 0, 0.28); cursor: pointer; }
.dialogue-name { position: absolute; top: 0; left: 3cqw; transform: translateY(-55%); padding: 0.25em 1em; border-radius: var(--radius); background: var(--accent); color: var(--accent-ink); font-family: var(--font-en); font-weight: 700; }
.dialogue-en { font-family: var(--font-en); font-size: var(--fs-xl); line-height: 1.25; padding-right: 8cqw; }
.dialogue.narration .dialogue-en { font-style: italic; }
.dialogue-ko { margin-top: 1cqh; color: var(--ink-soft); }
.dialogue-listen { position: absolute; top: 2.6cqh; right: 2cqw; font-size: var(--fs-l); }
.dialogue-next { position: absolute; right: 2cqw; bottom: 1.8cqh; padding: 0.1em 0.7em; border: 1px solid var(--line); border-radius: 0.5em; font-size: var(--fs-s); color: var(--ink-soft); }

.gate { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(20, 28, 34, 0.45); }
.gate-box { width: 84cqw; display: flex; flex-direction: column; align-items: center; gap: 2cqh; padding: 4cqh 3cqw; border-radius: calc(var(--radius) * 2); background: var(--panel); box-shadow: 0 1cqh 5cqh rgba(0, 0, 0, 0.35); }
.gate-prompt { font-size: var(--fs-l); font-weight: 700; }
.gate-options { display: flex; gap: 1.5cqw; width: 100%; }
.gate-option { flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.6cqh; min-height: 17cqh; padding: 2.5cqh 1.5cqw; border: 2px solid var(--line); border-radius: calc(var(--radius) * 1.5); background: var(--paper); }
.gate-option:hover { border-color: var(--accent); }
.gate-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.gate-options.single .gate-option { cursor: default; }
.opt-num { position: absolute; top: 1.2cqh; left: 1cqw; display: grid; place-items: center; width: 1.8em; height: 1.8em; border-radius: 50%; background: var(--ink); color: #fff; font-size: var(--fs-s); font-weight: 700; }
.opt-en { font-family: var(--font-en); font-size: var(--fs-xl); line-height: 1.2; text-align: center; }
.opt-ko { color: var(--ink-soft); }
.gate-words { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5em; align-items: center; }
.word { padding: 0.2em 0.7em; border: 2px solid var(--line); border-radius: 0.6em; background: var(--panel); font-family: var(--font-en); font-size: var(--fs-l); }
.word.ok { border-color: var(--good); background: #e4f1ea; color: var(--good); font-weight: 700; }
.word.miss { border-style: dashed; border-color: var(--bad); color: #b9a59e; }
.gate-heard { min-height: 1.5em; font-family: var(--font-en); color: var(--ink-soft); }
.gate-msg { min-height: 1.5em; font-weight: 600; text-align: center; }
.gate-msg.good { color: var(--good); font-size: var(--fs-l); }
.gate-msg.bad { color: var(--bad); }
.gate-actions { display: flex; gap: 1cqw; }
.gate-actions .btn { font-size: var(--fs-m); }
.gate-actions .mic { min-width: 34cqh; font-size: var(--fs-l); }
.mic.on { background: var(--bad); border-color: var(--bad); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 1.4cqh rgba(180, 72, 47, 0.18); } }
.gate-debug { width: 100%; }
.gate-debug input { width: 100%; padding: 0.5em 0.8em; border: 1px dashed var(--line); border-radius: var(--radius); font-size: var(--fs-s); }

.card-layer { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(20, 28, 34, 0.5); }
.card { display: flex; flex-direction: column; align-items: center; gap: 1.2cqh; min-width: 40cqw; max-width: 70cqw; padding: 5cqh 4cqw; border-radius: calc(var(--radius) * 2); background: var(--panel); text-align: center; box-shadow: 0 1cqh 5cqh rgba(0, 0, 0, 0.35); }
.card-kicker { font-family: var(--font-en); font-size: var(--fs-m); letter-spacing: 0.14em; text-transform: uppercase; color: var(--warm); }
.card-title { font-family: var(--font-en); font-size: calc(var(--fs-xl) * 1.3); line-height: 1.15; }
.card-sub { font-size: var(--fs-l); color: var(--ink-soft); }
.card-line { font-size: var(--fs-m); }
.card-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 1.5cqw; margin-top: 2cqh; }
.card .btn { font-size: var(--fs-l); }

.fade { position: absolute; inset: 0; background: #0d141a; opacity: 0; transition: opacity 0.25s; pointer-events: none !important; }
.fade.on { opacity: 1; }

/* 단어 옆 그림 */
.gword { white-space: nowrap; }
.gpic { display: inline-block; height: 1.9em; margin: -0.45em 0 -0.45em 0.1em; vertical-align: -0.5em; font-style: normal; line-height: 1; }
.opt-en .gpic { height: 2.4em; margin: -0.5em 0 -0.5em 0.15em; vertical-align: -0.7em; }
span.gpic { font-size: 1.05em; height: auto; vertical-align: -0.08em; }
img.gpic { width: auto; }

/* 말하기: 듣는 중 표시 */
.gate-result { display: flex; flex-direction: column; align-items: center; gap: 1cqh; min-height: 17cqh; justify-content: center; }
.gate-live { display: flex; align-items: center; justify-content: center; gap: 3cqw; width: 100%; min-height: 17cqh; padding: 1.5cqh 3cqw; border-radius: calc(var(--radius) * 1.5); background: #fbe9e4; animation: live-in 0.28s cubic-bezier(0.2, 1.6, 0.4, 1); }
.gate-live[data-state="speech"] { background: #e4f1ea; }
.gate-live[data-state="thinking"] { background: var(--accent-soft); }
@keyframes live-in { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.live-mic { position: relative; display: grid; place-items: center; width: 11cqh; height: 11cqh; flex-shrink: 0; border-radius: 50%; background: var(--bad); color: #fff; font-size: 6cqh; }
.gate-live[data-state="speech"] .live-mic { background: var(--good); }
.gate-live[data-state="thinking"] .live-mic { background: var(--accent); }
.live-mic i { position: absolute; inset: 0; border-radius: 50%; border: 0.5cqh solid currentColor; color: var(--bad); opacity: 0; animation: ring 1.4s ease-out infinite; }
.live-mic i:nth-child(2) { animation-delay: 0.7s; }
.gate-live[data-state="speech"] .live-mic i { color: var(--good); animation-duration: 0.8s; }
.gate-live[data-state="thinking"] .live-mic i { animation: none; }
@keyframes ring { from { transform: scale(1); opacity: 0.7; } to { transform: scale(1.9); opacity: 0; } }
.live-text { display: flex; flex-direction: column; min-width: 0; }
.live-title { font-size: var(--fs-xl); line-height: 1.2; }
.live-heard { min-height: 1.4em; font-family: var(--font-en); font-size: var(--fs-l); color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 44cqw; }
.live-bars { display: flex; align-items: center; gap: 0.7cqw; height: 9cqh; flex-shrink: 0; }
.live-bars i { width: 1cqw; height: 22%; border-radius: 1cqw; background: var(--bad); animation: bar 1.1s ease-in-out infinite; }
.live-bars i:nth-child(2n) { animation-delay: 0.18s; }
.live-bars i:nth-child(3n) { animation-delay: 0.36s; }
.live-bars i:nth-child(4) { animation-delay: 0.54s; }
.gate-live[data-state="speech"] .live-bars i { background: var(--good); animation-duration: 0.45s; animation-name: bar-loud; }
.gate-live[data-state="starting"] .live-bars i, .gate-live[data-state="thinking"] .live-bars i { animation: none; opacity: 0.35; }
@keyframes bar { 50% { height: 45%; } }
@keyframes bar-loud { 50% { height: 100%; } }
/* 듣는 동안에는 고른 문장만 또렷하게 남긴다 */
.gate.listening .gate-option:not(.selected) { opacity: 0.25; }
.gate.listening .gate-option.selected { border-color: var(--bad); box-shadow: 0 0 0 0.6cqh rgba(180, 72, 47, 0.16); }
.gate.listening .btn:not(.mic) { opacity: 0.35; }
.gate-box.pop { animation: pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1); }
.gate-box.shake { animation: shake 0.4s ease-in-out; }
@keyframes pop { 30% { transform: scale(1.04); } }
@keyframes shake { 20%, 60% { transform: translateX(-1.2cqw); } 40%, 80% { transform: translateX(1.2cqw); } }

/* 미니게임용 화면 요소 */
.mini-layer { position: absolute; inset: 0; pointer-events: none !important; }
.mini-layer > * { pointer-events: auto; }
.mini-layer.busy .mini-dot { pointer-events: none; }
.mini-panel { position: absolute; left: 50%; bottom: 5cqh; transform: translateX(-50%); display: flex; align-items: center; gap: 2cqw; padding: 1.6cqh 2cqw; border-radius: calc(var(--radius) * 1.5); background: rgba(255, 255, 255, 0.96); box-shadow: 0 0.6cqh 3cqh rgba(0, 0, 0, 0.28); font-size: var(--fs-l); }
.workshop-panel { position: absolute; left: 50%; bottom: 4cqh; transform: translateX(-50%); width: 76cqw; padding: 2cqh 3cqw; border-radius: calc(var(--radius) * 1.5); background: rgba(255,255,255,0.96); box-shadow: 0 0.6cqh 3cqh rgba(0,0,0,0.2); }
.workshop-head { display: flex; align-items: center; justify-content: space-between; }
.workshop-count { color: var(--ink-soft); font-size: var(--fs-s); }
.workshop-prompt { font-family: var(--font-en); font-size: var(--fs-l); margin-bottom: 1.5cqh; }
.workshop-choices { display: flex; gap: 1cqw; flex-wrap: wrap; }
.workshop-choices .btn { flex: 1; min-height: 6cqh; }
.workshop-choices kbd { margin-left: 0; }
.workshop-message { min-height: 1.5em; margin-top: 0.6cqh; color: var(--accent); font-size: var(--fs-s); }
.mini-word { min-width: 9em; font-family: var(--font-en); font-size: var(--fs-xl); text-align: center; }
.mini-dot { position: absolute; width: 7cqh; height: 7cqh; transform: translate(-50%, -50%); border-radius: 50%; border: 0.6cqh solid #fff; background: rgba(201, 138, 43, 0.55); box-shadow: 0 0.3cqh 1.2cqh rgba(0, 0, 0, 0.35); }
.mini-dot:hover { background: rgba(201, 138, 43, 0.9); }
.mini-dot.wrong { background: var(--bad); animation: shake 0.4s ease-in-out; }
.mini-dot.done { background: var(--good); opacity: 0.6; }
.hud-goal.alert { background: var(--bad); color: #fff; font-family: var(--font-en); font-size: var(--fs-l); }

/* 엔딩 앨범 */
.detail-progress { margin-top: 1.5cqh; font-weight: 700; color: var(--accent); }
.collector { display: flex; align-items: center; gap: 2cqw; padding: 1.6cqh 2cqw; border: 1px solid var(--line); border-radius: calc(var(--radius) * 1.5); background: var(--panel); }
.collector-text { display: flex; flex-direction: column; }
.collector-text strong { font-family: var(--font-en); font-size: var(--fs-l); }
.collector-text span { font-size: var(--fs-s); color: var(--ink-soft); }
.collector-bar { flex: 1; min-width: 12cqw; height: 1.4cqh; border-radius: 1cqh; background: var(--line); overflow: hidden; }
.collector-bar i { display: block; height: 100%; background: var(--warm); }
.medal { position: relative; flex-shrink: 0; width: 7cqh; height: 7cqh; border-radius: 50%; border: 0.5cqh solid rgba(0, 0, 0, 0.12); background: var(--line); }
.medal::after { content: ""; position: absolute; inset: 22%; border-radius: 50%; border: 0.35cqh solid rgba(255, 255, 255, 0.65); }
.medal.bronze { background: #b0764a; }
.medal.silver { background: #a9b1b7; }
.medal.gold { background: #d9a441; }
.endings { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 1fr; gap: 1.4cqw; }
.ending { position: relative; display: flex; flex-direction: column; justify-content: center; gap: 0.4cqh; padding: 1.5cqh 1.5cqw 1.5cqh 5cqw; border: 1px dashed var(--line); border-radius: calc(var(--radius) * 1.5); color: var(--ink-soft); font-size: var(--fs-s); }
.ending strong { font-size: var(--fs-m); }
.ending.on { border-style: solid; border-color: var(--accent); background: var(--panel); color: var(--ink); }
.ending.on strong { font-family: var(--font-en); font-size: var(--fs-l); }
.ending-no { position: absolute; left: 1.4cqw; top: 50%; transform: translateY(-50%); display: grid; place-items: center; width: 2.4cqw; height: 2.4cqw; border-radius: 50%; background: var(--line); color: var(--ink); font-weight: 700; }
.ending.on .ending-no { background: var(--accent); color: #fff; }

.marker.edge { opacity: 0.9; box-shadow: 0 0 0 0.4cqh var(--warm); }
#ui, #modal-root { -webkit-tap-highlight-color: transparent; user-select: none; }
input { user-select: text; }

/* 손가락으로 쓰는 기기에서는 키보드 안내를 숨긴다 */
@media (hover: none) and (pointer: coarse) {
  kbd, .marker-key, .dialogue-next { display: none !important; }
}

/* ───────── 세로 화면(폰을 세워 든 경우): 16:9 틀 대신 화면 전체를 쓴다 ───────── */
@media (orientation: portrait) {
  :root {
    --fs-s: min(3.5cqw, 2.3cqh);
    --fs-m: min(4.2cqw, 2.8cqh);
    --fs-l: min(5.2cqw, 3.5cqh);
    --fs-xl: min(6.6cqw, 4.6cqh);
  }
  #frame { width: 100vw; height: 100vh; height: 100dvh; }
  .top { flex-wrap: wrap; padding: 2cqh 5cqw 0; gap: 1.2cqh 3cqw; }
  .modal { width: 92cqw; padding: 3cqh 5cqw; }
  .set-row { flex-direction: column; align-items: stretch; gap: 1cqh; }
  .set-ctl { flex-wrap: wrap; }
  .set-ctl input[type="range"] { width: 60cqw; }
  .set-profiles { justify-content: flex-start; }
  .seg button, .tabs button { padding: 0.6em 0.3em; white-space: normal; }

  /* 첫 화면 */
  .home { overflow-y: auto; }
  .home-ask { padding: 3cqh 5cqw 2cqh; }
  .profile-grid { grid-template-columns: repeat(2, 1fr); gap: 3cqw; padding: 0 5cqw; }
  .profile-main { padding: 2cqh 3cqw 2.4cqh; }
  .profile-main img, .add-icon { max-width: 30cqw; }
  .add-icon { font-size: 10cqw; }
  .profile-edit { top: 2cqw; right: 2cqw; }
  .note { padding: 3cqh 5cqw; }

  /* 캐릭터 만들기: 위에 미리 보기, 아래에 고르는 칸 */
  .editor { flex-direction: column; }
  .editor-view { flex: 0 0 30cqh; }
  .editor-hint { bottom: 1cqh; }
  .editor-panel { width: 100%; flex: 1; min-height: 0; overflow-y: auto; border-left: 0; border-top: 1px solid var(--line); padding: 2cqh 5cqw 3cqh; gap: 1.4cqh; }
  .editor-panel > * { flex-shrink: 0; }
  .tab-body { flex: none; }
  .swatch { width: min(11cqw, 6cqh); height: min(11cqw, 6cqh); }
  .others { gap: 3cqw; }
  .others img { width: 12cqw; height: 12cqw; }

  /* 책장 */
  .who { margin-right: 0; }
  .who img { width: 5cqh; height: 5cqh; }
  .shelf .tabs { width: 100%; order: 3; }
  .shelf-body { padding: 2cqh 5cqw 3cqh; gap: 2cqh; overflow-y: auto; }
  .storybook-library { flex: none; display: flex; flex-direction: column; gap: 2.5cqh; }
  .bookcase { padding: 1.5cqh 3.5cqw 2.8cqh; border-radius: 2cqh; }
  .bookcase-heading { margin-bottom: 1cqh; }
  .bookcase-heading h1 { font-size: 4.6cqw; }
  .bookcase-heading p { font-size: 3.1cqw; }
  .bookcase-heading > span { font-size: 4.6cqw; }
  .books { flex: none; grid-template-columns: repeat(3, 1fr); gap: 2.6cqh 3.5cqw; padding: 1cqh 0; }
  .book { height: 20cqh; padding: 0; --book-depth: 2.2cqw; }
  .book-cover { padding: 1cqh 1.7cqw 0.7cqh; gap: 0.4cqh; }
  .book-cover::after, .book-back::after { inset: 0.55cqh 1.1cqw; }
  .book-cover-art { height: 8.5cqh; width: 94%; }
  .book-foil { font-size: 4.5cqw; height: 2cqh; }
  .book-title { font-size: 3cqw; line-height: 1.12; }
  .book-ko { display: block; font-size: 2.5cqw; }
  .book-cover-flourish { font-size: 2.5cqw; }
  .book-back-motif { width: 13cqw; height: 13cqw; font-size: 10cqw; }
  .book-back-title { font-size: 3cqw; }
  .book-back-label { font-size: 2cqw; }
  .book-spine > span { font-size: 2.5cqw; }
  .book-soon { top: 0.8cqh; right: 2cqw; }
  .book-detail { flex: none; flex-direction: column; gap: 1.6cqh; padding: 1.5cqh 3.5cqw 2cqh; }
  .book-preview { height: 23cqh; }
  .book-preview figcaption { padding: 1cqh 3cqw; font-size: 3.1cqw; }
  .book-detail h2 { font-size: 5.8cqw; }
  .detail-ko { font-size: 3.6cqw; }
  .detail-blurb { font-size: 3.6cqw; }
  .detail-copy .detail-progress { font-size: 3.3cqw; }
  .detail-side { min-width: 0; }
  .detail-side .seg button { font-size: 3.5cqw; }
  .detail-side .row { flex-wrap: wrap; }
  .detail-side .btn { flex: 1; font-size: 3.5cqw; }
  .detail-side .btn.big { font-size: 4.5cqw; }
  .endings { flex: none; grid-template-columns: 1fr; }
  .collector { flex-wrap: wrap; gap: 3cqw; padding: 1.6cqh 4cqw; }
  .collector-text { flex: 1; min-width: 0; }
  .collector-bar { flex: none; width: 100%; }
  .ending { padding: 1.4cqh 4cqw 1.4cqh 15cqw; }
  .ending-no { left: 4cqw; width: 7cqw; height: 7cqw; }
  .notes { flex: none; }
  .notes-head, .notes-row { grid-template-columns: 1fr 2.4em 2.4em 3.2em 2.4em; gap: 2cqw; padding: 1cqh 3cqw; }
  .notes-text { font-size: var(--fs-m); }

  /* 플레이 */
  .hud { flex-wrap: wrap; padding: 1.5cqh 3cqw; gap: 1cqh 2cqw; }
  .hud-goal { margin-left: 0; width: 100%; order: 5; }
  .hud-mini { margin-left: 0; width: 100%; order: 6; }
  .camera-tools { top: 15cqh; right: 3cqw; }
  .camera-hint { display: none; }
  .mini-bar { flex: 1; width: auto; }
  .dialogue { left: 3cqw; right: 3cqw; bottom: 2.5cqh; min-height: 20cqh; padding: 3.4cqh 5cqw 3cqh; }
  .dialogue-name { left: 5cqw; }
  .dialogue-en { padding-right: 13cqw; }
  .dialogue-listen { top: 2cqh; right: 3cqw; }
  .dialogue-next { right: 3cqw; }
  .gate-box { width: 94cqw; max-height: 96cqh; overflow-y: auto; padding: 3cqh 4cqw; gap: 1.6cqh; }
  .gate-options { flex-direction: column; gap: 1.2cqh; }
  .gate-option { min-height: 9cqh; padding: 1.6cqh 4cqw 1.6cqh 13cqw; }
  .gate-options.single .gate-option { padding-left: 4cqw; }
  .opt-num { top: 50%; left: 3.5cqw; transform: translateY(-50%); }
  .gate-result, .gate-live { min-height: 13cqh; }
  .gate-live { flex-direction: column; gap: 1cqh; padding: 1.5cqh 3cqw; text-align: center; }
  .live-bars { display: none; }
  .live-mic { width: 8cqh; height: 8cqh; font-size: 4.5cqh; }
  .live-title { font-size: var(--fs-l); }
  .live-heard { max-width: 82cqw; }
  .gate-actions { flex-wrap: wrap; justify-content: center; gap: 2cqw; width: 100%; }
  .gate-actions .mic { order: -1; width: 100%; min-width: 0; padding: 0.9em; }
  .gate-actions .btn:not(.mic) { flex: 1; }
  .card { width: 88cqw; min-width: 0; max-width: none; padding: 4cqh 6cqw; }
  .card-title { font-size: calc(var(--fs-xl) * 1.15); }
  .mini-panel { width: 92cqw; bottom: 3cqh; justify-content: space-between; }
  .workshop-panel { width: 94cqw; bottom: 2cqh; padding: 2cqh 4cqw; }
  .workshop-choices .btn { min-width: 25%; font-size: var(--fs-s); }
  .mini-word { min-width: 0; flex: 1; }
  .mini-dot { width: 13cqw; height: 13cqw; border-width: 1cqw; }
}

@media (prefers-reduced-motion: reduce) {
  .book, .book-shell, .book-aura { animation: none !important; transition: none !important; }
  .book.on .book-shell { transform: translateY(-0.6cqh) rotateX(3deg) rotateY(-17deg); }
}
