/* ===========================================
   Visual Novel - Stylesheet
   =========================================== */

:root {
  --bg-color: #0a0a0f;
  --text-color: #f0f0f0;
  --accent: #d4af37;
  --accent-dim: #8a7330;
  --dialogue-bg: rgba(0, 0, 0, 0.75);
  --dialogue-border: rgba(212, 175, 55, 0.4);
  --modal-bg: rgba(15, 15, 25, 0.95);
  --button-bg: rgba(40, 40, 55, 0.9);
  --button-hover: rgba(70, 70, 90, 0.9);
  --font-main: 'Noto Sans KR', 'Malgun Gothic', 'Yu Gothic', 'Meiryo', sans-serif;
  --font-title: 'Noto Serif KR', 'Batang', 'Yu Mincho', serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--text-color);
  font-family: var(--font-main);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;   /* 모바일: 이미지 길게 눌러 저장 메뉴 차단 */
  -webkit-tap-highlight-color: transparent;  /* 탭마다 회색 박스 깜빡임 제거 */
  overscroll-behavior: none;     /* 당겨서 새로고침/스크롤 체이닝 차단 */
}

/* 이미지 드래그(끌어서 저장) 차단 */
img {
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  user-drag: none;
  -webkit-touch-callout: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;   /* 모바일 주소창 표시/숨김에도 다이얼로그가 잘리지 않게 */
  overflow: hidden;
}

/* ============ 게임사 로고 스플래시 (최초 진입) ============ */
#logo-splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 44%, #ffffff 0%, #f4f1ec 100%);
  opacity: 1;
  transition: opacity 1.1s ease;
  cursor: pointer;
}
#logo-splash.hide { opacity: 0; pointer-events: none; }
#logo-splash .logo-img {
  width: clamp(260px, 48vmin, 600px);
  height: auto;
  opacity: 0;
  transform: scale(0.94);
  filter: drop-shadow(0 10px 28px rgba(40, 30, 15, 0.14));
  transition: opacity 1.8s ease, transform 2.4s cubic-bezier(0.2, 0.7, 0.2, 1);
}
#logo-splash.logo-in .logo-img { opacity: 1; transform: scale(1); }

/* 화면 전환 커튼 — 시나리오 시작 시 검게 페이드 → 게임 진입 */
#screen-fade {
  position: fixed;
  inset: 0;
  z-index: 95;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.7s ease;
}
#screen-fade.active { opacity: 1; }

/* ============ 화면 공통 ============ */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
}

.screen.visible {
  display: block;
}

/* ============ 타이틀 화면 (문 열림 시네마틱) ============ */
:root { --glow: #ffd9a0; }

#screen-title {
  background: #0c0a07;
}
#screen-title.visible { display: grid; place-items: center; }

#title-stage {
  position: absolute;
  left: 0; top: 0;
  width: 1633px;
  height: 963px;
  transform-origin: 0 0;   /* JS fitTitle()가 translate로 가운데 정렬 — grid 센터링은 오버스케일 박스를 못 맞춤 */
  box-shadow: 0 40px 110px -30px rgba(0,0,0,.8);
  overflow: hidden;
}
#title-scene {
  position: absolute; inset: 0;
  transform-origin: 54% 50%;
  transition: transform 2.2s cubic-bezier(.5,.02,.3,1), filter 1.7s ease;
}

#title-stage .t-bg { position: absolute; left: 0; top: 0; width: 1633px; height: 963px; z-index: 1; }
#title-stage .t-lightback {
  position: absolute; left: 720px; top: 20px; width: 812px; height: 970px; z-index: 0; pointer-events: none;
  filter: blur(12px);
  transition: filter 1.4s ease, transform 1.8s ease;
  background: radial-gradient(58% 56% at 32% 38%, #fff9ee 0%, #ffe7c2 52%, #f0cd94 100%);
}
#title-stage .t-door {
  position: absolute; left: 766px; top: 0; width: 800px; z-index: 2; transform-origin: 100% 46%;
  transition: transform 1.7s cubic-bezier(.45,.05,.2,1), filter 1.7s ease;
  will-change: transform; backface-visibility: hidden;
}
#title-stage .t-beam {
  position: absolute; left: 752px; top: 20px; width: 240px; height: 1000px; z-index: 0;
  transform-origin: left center; transform: rotate(8deg) scaleX(0); opacity: 0; pointer-events: none;
  filter: blur(28px); mix-blend-mode: screen;
  background: linear-gradient(90deg, rgba(255,249,238,.98) 0%, rgba(255,244,224,.55) 42%, transparent 100%);
  transition: transform 1.4s cubic-bezier(.5,.05,.25,1), opacity 1.1s ease;
}
#title-stage .t-bloom {
  position: absolute; left: 716px; top: -10px; width: 300px; height: 986px; z-index: 6; pointer-events: none;
  opacity: 0; mix-blend-mode: screen; filter: blur(5px);
  transform: rotate(8deg); transform-origin: 50% 12%;
  transition: opacity 1.3s ease;
  background: repeating-linear-gradient(90deg,
    rgba(255,250,238,0) 0px, rgba(255,250,238,0) 8px,
    rgba(255,250,238,.55) 14px, rgba(255,250,238,0) 24px,
    rgba(255,246,228,0) 33px, rgba(255,246,228,.32) 39px, rgba(255,246,228,0) 50px,
    rgba(255,250,238,0) 58px, rgba(255,250,238,.50) 65px, rgba(255,250,238,0) 76px);
  -webkit-mask: radial-gradient(56% 84% at 50% 13%, #000 0%, rgba(0,0,0,.5) 48%, transparent 82%);
          mask: radial-gradient(56% 84% at 50% 13%, #000 0%, rgba(0,0,0,.5) 48%, transparent 82%);
}
#title-stage .t-ambient {
  position: absolute; left: 0; top: 0; width: 1633px; height: 963px; z-index: 4; pointer-events: none;
  box-shadow: inset 0 0 220px 50px rgba(30,16,4,.4);
}

#title-stage .t-btn {
  position: absolute; z-index: 5; cursor: pointer;
  filter: drop-shadow(0 6px 12px rgba(30,18,6,.28));
  transition: transform .26s cubic-bezier(.2,.8,.3,1.1), filter .26s;
  will-change: transform, filter;
}
#title-stage .t-btn:hover {
  transform: translate(4px,-3px) scale(1.025);
  filter: drop-shadow(0 12px 20px rgba(30,18,6,.4)) brightness(1.06) drop-shadow(0 0 10px var(--glow));
}
#title-stage .t-btn:active { transform: translate(2px,-1px) scale(1.005); }
#title-stage .t-btn.sel { filter: drop-shadow(0 12px 22px rgba(30,18,6,.45)) brightness(1.12) drop-shadow(0 0 16px var(--glow)); }
#title-stage .t-b1 { left: 206px; top: 300px; }
#title-stage .t-b2 { left: 206px; top: 400px; }
#title-stage .t-b3 { left: 206px; top: 500px; }

#title-stage .t-whiteout {
  position: absolute; inset: 0; z-index: 8; background: #fffdf7; opacity: 0; pointer-events: none;
  transition: opacity 1s ease;
}
#title-stage .t-vtag {
  position: absolute; right: 24px; bottom: 16px; z-index: 7; font-family: var(--font-title);
  font-size: 17px; color: rgba(255,246,230,.55); letter-spacing: 3px; text-shadow: 0 1px 4px rgba(0,0,0,.6);
}

#title-stage.entering #title-scene { transform: scale(1.16); filter: brightness(1.08) saturate(1.03); }
#title-stage.entering .t-door { transform: perspective(2200px) rotateY(-14deg); filter: brightness(.84); }
#title-stage.entering .t-btn { pointer-events: none; }

/* --- 시나리오 선택 --- */
#scenario-select {
  position: absolute; inset: 0; z-index: 35;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; pointer-events: none;
  color: #3a2c1d;
  background: radial-gradient(130% 112% at 50% -8%, #ece0c9 0%, #d7c2a0 55%, #bda47e 100%);
  transition: opacity .7s ease, visibility .7s;
}
#scenario-select.open { opacity: 1; visibility: visible; pointer-events: auto; }
.scsel-head { text-align: center; margin-bottom: 42px; display: flex; flex-direction: column; align-items: center; }
.scsel-kicker { font-size: 12px; font-weight: 700; letter-spacing: 6px; color: #bd6a3c; margin-bottom: 18px; display: flex; align-items: center; gap: 12px; }
.scsel-kicker::before, .scsel-kicker::after { content: ""; width: 6px; height: 6px; border: 1px solid #bd6a3c; transform: rotate(45deg); opacity: .8; }
.scsel-titlerow { display: flex; align-items: center; gap: 28px; }
.scsel-titlerow::before, .scsel-titlerow::after { content: ""; width: 70px; height: 1px; background: linear-gradient(90deg, transparent, rgba(120,90,50,.55)); }
.scsel-titlerow::after { transform: scaleX(-1); }
.scsel-title { font-family: var(--font-title); font-size: 42px; font-weight: 700; letter-spacing: 4px; color: #3a2c1d; }
.scsel-sub { font-size: 12px; font-weight: 500; letter-spacing: 7px; color: rgba(120,90,55,.5); margin-top: 16px; }
.sc-cards { display: flex; gap: 46px; }
.sc-card {
  width: 460px; background: rgba(252,249,243,.72); border: 1px solid rgba(255,255,255,.7); border-radius: 16px;
  overflow: hidden; cursor: pointer; box-shadow: 0 24px 50px -22px rgba(40,24,8,.42);
  transition: transform .32s cubic-bezier(.2,.8,.3,1.1), box-shadow .32s, opacity .32s, filter .32s, border-color .2s;
}
.sc-card:hover { transform: translateY(-8px); box-shadow: 0 34px 66px -22px rgba(40,24,8,.52); }
.sc-thumb { width: 100%; height: 252px; background-size: cover; background-position: center; }
.sc-body { padding: 24px 30px 30px; }
.sc-num { font-size: 13px; font-weight: 600; letter-spacing: 3px; color: #bd6a3c; }
.sc-name { font-family: var(--font-title); font-size: 28px; font-weight: 700; letter-spacing: 1px; margin: 9px 0 13px; color: #3a2c1d; }
.sc-desc { font-size: 15px; line-height: 1.65; color: #5e4a34; }
#scenario-select.has-sel .sc-card:not(.sel) { opacity: .42; filter: saturate(.65); transform: none; box-shadow: 0 16px 34px -22px rgba(40,24,8,.4); }
.sc-card.sel { border-color: #c2843e; transform: translateY(-8px); box-shadow: 0 0 0 3px rgba(194,132,62,.55), 0 30px 62px -20px rgba(40,24,8,.5); }
.scsel-foot { display: flex; align-items: center; gap: 22px; margin-top: 42px; }
.sc-back { font-family: var(--font-main); font-size: 16px; letter-spacing: 2px; color: #7a6244; background: transparent; border: none; cursor: pointer; padding: 12px 18px; border-radius: 8px; transition: .2s; }
.sc-back:hover { background: rgba(120,90,50,.1); color: #3a2c1d; }
.sc-start {
  font-family: var(--font-main); font-size: 17px; font-weight: 700; letter-spacing: 3px; color: #fff;
  background: #c2843e; border: none; border-radius: 10px; padding: 14px 38px; cursor: pointer;
  box-shadow: 0 12px 24px -10px rgba(150,90,30,.6); transition: .22s;
}
.sc-start:hover:not(:disabled) { background: #b3742f; transform: translateY(-2px); box-shadow: 0 16px 30px -10px rgba(150,90,30,.7); }
.sc-start:disabled { background: rgba(120,90,55,.25); color: rgba(255,255,255,.7); cursor: default; box-shadow: none; }

/* ============ 게임 화면 ============ */
#screen-game {
  background: #000;
}

.layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* --- 배경 --- */
.layer-bg {
  background: #000;
}

.bg-image {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 0.8s ease;
}

.bg-image.active {
  opacity: 1;
}

/* placeholder 스타일 (에셋 없을 때) */
.bg-image.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.4);
  font-size: 1.5rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

/* --- 캐릭터 --- */
.layer-char {
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  padding-bottom: 30%;
}

.char-slot {
  position: absolute;
  bottom: 0;
  height: 100%;
  width: 44%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.5s ease, transform 0.5s ease, filter 0.4s ease;
  transform: translateY(20px);
  pointer-events: none;
}

.char-slot[data-pos="left"]   { left: -2%; }
.char-slot[data-pos="center"] { left: 28%; }
.char-slot[data-pos="right"]  { right: -2%; }

.char-slot.visible {
  opacity: 1;
  transform: translateY(0);
}

.char-slot.dim {
  filter: brightness(0.5) saturate(0.7);
}

/* --- 등장 애니메이션 (화면 밖에서 들어옴) --- */
.char-slot.enter-left {
  animation: char-enter-left 0.7s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
.char-slot.enter-right {
  animation: char-enter-right 0.7s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
@keyframes char-enter-left {
  0%   { opacity: 0; transform: translateX(-80%) translateY(0); }
  100% { opacity: 1; transform: translateX(0) translateY(0); }
}
@keyframes char-enter-right {
  0%   { opacity: 0; transform: translateX(80%) translateY(0); }
  100% { opacity: 1; transform: translateX(0) translateY(0); }
}

/* --- 퇴장 애니메이션 --- */
.char-slot.exit-left {
  animation: char-exit-left 0.5s ease-in both;
}
.char-slot.exit-right {
  animation: char-exit-right 0.5s ease-in both;
}
@keyframes char-exit-left {
  0%   { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(-80%); }
}
@keyframes char-exit-right {
  0%   { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(80%); }
}

/* --- 통통 튀기 (강조) — 위아래로만 튐, 스케일 변형 없음 --- */
.char-slot.bounce {
  animation: char-bounce 0.85s cubic-bezier(0.28, 0.84, 0.42, 1);
}
@keyframes char-bounce {
  0%   { transform: translateY(0); }
  25%  { transform: translateY(-40px); }
  45%  { transform: translateY(0); }
  60%  { transform: translateY(-18px); }
  78%  { transform: translateY(0); }
  88%  { transform: translateY(-7px); }
  100% { transform: translateY(0); }
}

/* --- 앉기 (의자에 앉는 모션 — 아래로 한 번 내려갔다 살짝 튐) --- */
.char-slot.sit {
  animation: char-sit 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes char-sit {
  0%   { transform: translateY(0); }
  55%  { transform: translateY(28px); }
  78%  { transform: translateY(12px); }
  100% { transform: translateY(0); }
}

/* --- 등장 느림 옵션 (slow) --- */
.char-slot.enter-left.enter-slow,
.char-slot.enter-right.enter-slow {
  animation-duration: 1.4s !important;
  animation-timing-function: cubic-bezier(0.18, 0.55, 0.3, 1) !important;
}

.char-slot img {
  height: 90%;          /* 버스트 스탠딩을 세로 기준으로 크게 */
  width: auto;
  max-width: 100%;
  max-height: 90%;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.35));
}

/* 입모양 토글용 — base는 항상 보이고, talk는 위에 absolute로 깔아 opacity만 바꿈 */
.char-slot .char-img-talk {
  position: absolute !important;
  left: 50% !important;
  bottom: 0 !important;
  transform: translateX(-50%) !important;
  opacity: 0 !important;
  transition: opacity 0.05s linear !important;
  pointer-events: none !important;
}
.char-slot .char-img-talk.mouth-open {
  opacity: 1 !important;
}

.char-slot .char-placeholder {
  width: 80%;
  height: 80%;
  background: rgba(80, 60, 100, 0.6);
  border: 2px dashed rgba(255,255,255,0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.7);
  font-size: 1.2rem;
  text-align: center;
  padding: 1rem;
}

.char-slot .char-placeholder small {
  font-size: 0.85rem;
  opacity: 0.6;
  margin-top: 0.5rem;
}

/* --- CG --- */
.layer-cg {
  display: flex;
  align-items: center;
  justify-content: center;
}
/* TV 꺼짐 효과 동안 CG 뒤 배경이 비치지 않게 layer 자체를 검게 */
.layer-cg.tvoff-bg {
  background: #000;
}

#cg-image {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: #000;             /* 배경 가리기용 검은 백드롭 */
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.4);
  font-size: 1.3rem;
  letter-spacing: 0.2em;
  overflow: hidden;
}

#cg-image.visible {
  opacity: 1;
}

/* 옆으로 슬라이드+페이드 등장의 '시작' 상태 — JS가 다음 프레임에 이 클래스를 제거하면
   제자리(translateX 0)+불투명으로 전환된다. (.visible 보다 뒤에 와서 opacity를 덮어씀) */
#cg-image.cg-slide-start {
  opacity: 0;
  transform: translateX(8%);
}

#cg-image.placeholder {
  background: rgba(20, 20, 40, 0.85);
  border: 1px solid rgba(255,255,255,0.1);
}

/* --- CG 글리치 (지지직 + 살짝 흔들림) --- */
#cg-image.glitch {
  animation: cg-shake 0.18s linear infinite;
}
#cg-image.glitch::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.05) 0px,
      rgba(255, 255, 255, 0.05) 1px,
      transparent 1px,
      transparent 3px
    );
  mix-blend-mode: overlay;
  animation: cg-scan 1.4s linear infinite;
}
#cg-image.glitch::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: rgba(120, 200, 255, 0.04);
  mix-blend-mode: screen;
  animation: cg-flicker 0.27s steps(2) infinite;
}
@keyframes cg-shake {
  0%   { transform: translate(0, 0); filter: none; }
  20%  { transform: translate(-2px, 1px); filter: contrast(1.15) brightness(1.05); }
  40%  { transform: translate(2px, -1px); filter: hue-rotate(-3deg); }
  60%  { transform: translate(-1px, -1px); filter: contrast(1.1); }
  80%  { transform: translate(1px, 1px); filter: brightness(1.08); }
  100% { transform: translate(0, 0); filter: none; }
}
@keyframes cg-scan {
  0%   { transform: translateY(0); opacity: 0.6; }
  50%  { opacity: 1; }
  100% { transform: translateY(8px); opacity: 0.6; }
}
@keyframes cg-flicker {
  0%, 100% { opacity: 0; }
  50%      { opacity: 1; }
}

/* --- TV 꺼짐 (CRT 줄어들며 사라짐) --- */
#cg-image.tvoff {
  animation: tv-off 0.65s cubic-bezier(0.55, 0, 0.4, 1) forwards;
  transform-origin: 50% 50%;
}
@keyframes tv-off {
  0%   { transform: scale(1, 1);          filter: brightness(1);   opacity: 1; }
  20%  { transform: scale(1.02, 0.06);     filter: brightness(2.5); opacity: 1; }
  55%  { transform: scale(0.06, 0.012);    filter: brightness(3);   opacity: 1; }
  100% { transform: scale(0.0, 0.0);       filter: brightness(0);   opacity: 0; }
}

/* --- 스토리 진입 안내창 (@confirm) --- */
#story-confirm {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.82);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
#story-confirm.show {
  opacity: 1;
  pointer-events: auto;
}
.story-confirm-box {
  max-width: 560px;
  width: 84%;
  padding: 2.6rem 2.2rem 2.2rem;
  border-radius: 16px;
  background: linear-gradient(150deg, rgba(38, 32, 44, 0.97), rgba(20, 17, 25, 0.98));
  border: 1px solid rgba(240, 182, 207, 0.28);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.62);
  text-align: center;
  transform: translateY(14px) scale(0.98);
  transition: transform 0.4s cubic-bezier(0.22, 0.61, 0.36, 1);
}
#story-confirm.show .story-confirm-box {
  transform: translateY(0) scale(1);
}
#story-confirm-msg {
  margin: 0 0 1.9rem;
  color: #ece6ee;
  font-size: 1.18rem;
  line-height: 1.75;
  word-break: keep-all;
}
.story-confirm-btns {
  display: flex;
  gap: 1rem;
  justify-content: center;
}
.sc-confirm-btn {
  min-width: 128px;
  padding: 0.72rem 1.5rem;
  border-radius: 10px;
  font-size: 1.04rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.18);
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease;
}
.sc-confirm-btn.yes { background: linear-gradient(135deg, #b56b86, #8a4d63); color: #fff; }
.sc-confirm-btn.no  { background: rgba(255, 255, 255, 0.06); color: #cfc8d2; }
.sc-confirm-btn:hover { transform: translateY(-2px); }
.sc-confirm-btn.yes:hover { border-color: #f0b6cf; }
.sc-confirm-btn.no:hover  { border-color: rgba(255, 255, 255, 0.4); }

/* --- FX --- */
#overlay-fade {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

#overlay-fade.active {
  opacity: 1;
}

/* --- 시계방향 회전 전환 (클럭 와이프) — --spin-a는 JS가 매 프레임 갱신 --- */
#overlay-spin {
  position: absolute;
  inset: 0;
  z-index: 58;
  pointer-events: none;
  opacity: 0;
  --spin-a: 0deg;
}
#overlay-spin.active { opacity: 1; }
/* 덮기: 검은 부채꼴이 12시→시계방향으로 차오름 (--spin-a 0→360) */
#overlay-spin.cover  { background: conic-gradient(from -90deg, #000 0deg, #000 var(--spin-a), transparent var(--spin-a)); }
/* 열기: 투명 부채꼴이 시계방향으로 열림 (검은 화면 → 장면) */
#overlay-spin.reveal { background: conic-gradient(from -90deg, transparent 0deg, transparent var(--spin-a), #000 var(--spin-a)); }

/* --- 중앙 타이프라이터 (검은 화면 위 한 글자씩) --- */
#center-type {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-title);
  font-size: 2.6rem;
  letter-spacing: 0.3em;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 0 24px rgba(255, 255, 255, 0.18);
  opacity: 0;
  transition: opacity 0.7s ease;
  z-index: 50;
  text-align: center;
  pointer-events: none;
  white-space: nowrap;
  font-weight: 300;
}
#center-type.visible { opacity: 1; }

/* --- 풀스크린 텍스트 카드 ("몇 개월 뒤" 등) --- */
#text-card {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1.04);
  font-family: var(--font-title);
  font-size: 2.2rem;
  letter-spacing: 0.45em;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 0 26px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 1s ease, transform 1.4s ease;
  z-index: 55;
  text-align: center;
  pointer-events: none;
  white-space: normal;
  max-width: 78%;
  line-height: 1.6;
  font-weight: 300;
}
#text-card.visible { opacity: 1; transform: translate(-50%, -50%) scale(1); }

@media (max-width: 960px), (max-height: 480px) {
  #text-card { font-size: 1.5rem; letter-spacing: 0.3em; }
}

/* --- 크레딧 스크롤 --- */
#credits-roll {
  position: absolute;
  inset: 0;
  background: #000;
  display: none;
  overflow: hidden;
  z-index: 200;
  pointer-events: auto;
  cursor: pointer;
}
#credits-roll.visible { display: block; }

#credits-content {
  position: absolute;
  top: 100%;
  left: 50%;
  width: 80%;
  max-width: 720px;
  color: rgba(255, 255, 255, 0.88);
  text-align: center;
  font-size: 1rem;
  line-height: 1.7;
  padding: 2rem 0;
  transform: translate(-50%, 0);
}
#credits-roll.visible #credits-content {
  animation: credits-scroll 42s linear forwards;
}

@keyframes credits-scroll {
  0%   { transform: translate(-50%, 0); }
  100% { transform: translate(-50%, calc(-100% - 60vh)); }
}

.credits-section { margin: 3rem 0; }
.credits-section h2 {
  font-family: var(--font-title);
  color: var(--accent);
  font-size: 2.2rem;
  letter-spacing: 0.3em;
  font-weight: 300;
  margin-bottom: 0.5rem;
}
.credits-section h3 {
  color: var(--accent);
  font-size: 1.05rem;
  letter-spacing: 0.3em;
  margin-bottom: 1.2rem;
  font-weight: 400;
}
.credits-sub {
  font-size: 0.85rem;
  letter-spacing: 0.4em;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 1rem;
}
.credits-name {
  font-size: 1.15rem;
  letter-spacing: 0.2em;
  color: rgba(255, 255, 255, 0.95);
}
.credit-item {
  margin: 1.4rem 0;
  padding: 0 0.5rem;
}
.credit-item .credit-name {
  font-size: 0.92rem;
  color: rgba(255, 255, 255, 0.92);
  word-break: break-word;
}
.credit-item .credit-meta {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.55);
  margin-top: 0.25rem;
}
.credit-item .credit-url {
  font-size: 0.72rem;
  color: rgba(212, 175, 55, 0.55);
  font-family: 'Consolas', monospace;
  margin-top: 0.15rem;
}
.credits-end {
  margin-top: 6rem;
  font-style: italic;
  color: rgba(255, 255, 255, 0.6);
  letter-spacing: 0.2em;
}

/* --- 클릭 영역 --- */
#click-area {
  position: absolute;
  inset: 0;
  bottom: 264px;
  cursor: pointer;
  z-index: 5;
}

/* --- 씬 타이틀 --- */
#scene-title {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-title);
  font-size: 2.5rem;
  letter-spacing: 0.4em;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(0,0,0,0.8);
  opacity: 0;
  transition: opacity 1s ease;
  pointer-events: none;
}

#scene-title.visible {
  opacity: 1;
}

/* --- 다이얼로그 박스 --- */
#ui-dialogue {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 264px;
  background: linear-gradient(to top,
    rgba(0,0,0,0.95) 0%,
    rgba(0,0,0,0.9) 90%,
    rgba(0,0,0,0) 100%);
  padding: 2.2rem 0 1.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;        /* 텍스트 블록을 화면 가운데로 정렬 (가독성) */
  pointer-events: auto;
}

.name-plate {
  height: 36px;
  margin-bottom: 0.6rem;
  width: min(90%, 1000px);    /* 대사 블록과 동일 폭으로 좌측 정렬 기준 맞춤 */
}

#speaker-name {
  display: inline-block;
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--accent);
  padding: 0.25rem 1.1rem;
  border-left: 3px solid var(--accent);
  letter-spacing: 0.1em;
  min-height: 1.5rem;
}

#speaker-name:empty {
  display: none;
}

.dialogue-content {
  flex: 1;
  position: relative;
  width: min(90%, 1000px);    /* 화면 가운데 블록 + 줄 길이 제한 */
  font-size: calc(1.4rem * var(--dlg-scale, 1));
  line-height: 1.75;
  color: var(--text-color);
}

#dialogue-text {
  white-space: pre-wrap;
}

#dialogue-text.narration {
  color: rgba(255, 255, 255, 0.85);
  font-style: italic;
  text-align: left;     /* 좌측 정렬: 첫 글자 고정 + 뒤로 출력 (타이핑 중 안 흔들림) */
  padding-top: 0.5rem;
}

#dialogue-arrow {
  position: absolute;
  bottom: 0;
  right: 0;
  font-size: 0.9rem;
  color: var(--accent);
  opacity: 0;
  animation: arrow-blink 1.2s infinite;
}

#dialogue-arrow.visible {
  opacity: 1;
}

@keyframes arrow-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* --- 빠른 메뉴 --- */
#ui-quick {
  position: absolute;
  top: 0.8rem;
  right: 1rem;
  display: flex;
  gap: 0.3rem;
  pointer-events: auto;
  z-index: 20;             /* click-area(z:5)보다 위에 와야 클릭됨 */
}

#ui-quick button {
  background: var(--button-bg);
  color: var(--text-color);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 0.4rem 0.7rem;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  font-family: var(--font-main);
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}

#ui-quick button:hover {
  background: var(--button-hover);
  color: var(--accent);
}

#ui-quick button:active {
  transform: scale(0.92);
  background: rgba(212, 175, 55, 0.4);
  color: #fff;
  border-color: var(--accent);
}

#ui-quick button.active {
  background: rgba(212, 175, 55, 0.3);
  color: var(--accent);
  border-color: var(--accent);
}

/* ============ 모달 ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: auto;
}

.modal.visible {
  display: flex;
}

.modal-box {
  background: var(--modal-bg);
  border: 1px solid rgba(212, 175, 55, 0.3);
  width: 80%;
  max-width: 800px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  border-radius: 4px;
}

.modal-large {
  max-width: 1000px;
}

.modal-small {
  max-width: 400px;
}

.modal-box header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.modal-box header h2 {
  font-family: var(--font-title);
  font-weight: 400;
  letter-spacing: 0.2em;
  color: var(--accent);
  font-size: 1.3rem;
}

.modal-close {
  background: transparent;
  color: var(--text-color);
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--accent);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

/* --- 설정 모달 --- */
.config-row {
  display: grid;
  grid-template-columns: 130px 1fr 60px;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.config-row label {
  color: rgba(255,255,255,0.8);
  letter-spacing: 0.1em;
  font-size: 0.95rem;
}

.config-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.config-row select,
.config-row button {
  background: var(--button-bg);
  color: var(--text-color);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 0.4rem 0.8rem;
  font-family: var(--font-main);
  cursor: pointer;
  border-radius: 2px;
}

.cfg-value {
  text-align: right;
  color: var(--accent);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

/* --- 세이브/로드 --- */
.save-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.save-slot {
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 1rem;
  cursor: pointer;
  display: flex;
  gap: 1rem;
  min-height: 100px;
  transition: all 0.15s ease;
}

.save-slot:hover {
  border-color: var(--accent);
  background: rgba(20,20,30,0.6);
}

.save-slot .slot-thumb {
  width: 120px;
  height: 70px;
  background: rgba(0,0,0,0.6);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.3);
  font-size: 0.7rem;
}

.save-slot .slot-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.save-slot .slot-title {
  color: var(--accent);
  font-size: 0.95rem;
  letter-spacing: 0.1em;
}

.save-slot .slot-preview {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.6);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.save-slot .slot-date {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.4);
}

.save-slot.empty {
  color: rgba(255,255,255,0.3);
  font-style: italic;
  align-items: center;
  justify-content: center;
}

/* --- 로그(백로그) --- */
#log-entries {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 60vh;
  overflow-y: auto;
}

.log-entry {
  padding: 0.6rem 0.8rem;
  border-left: 2px solid transparent;
  background: rgba(0,0,0,0.3);
}

.log-entry.dialogue {
  border-left-color: var(--accent);
}

.log-entry.narration {
  border-left-color: rgba(255,255,255,0.3);
  font-style: italic;
}

.log-entry .log-name {
  color: var(--accent);
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.log-entry .log-text {
  font-size: 1.1rem;
  line-height: 1.7;
  color: var(--text-color);
}

/* --- 확인 다이얼로그 --- */
#confirm-message {
  margin-bottom: 1.5rem;
  text-align: center;
  line-height: 1.6;
}

.confirm-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.confirm-buttons button {
  background: var(--button-bg);
  color: var(--text-color);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 0.6rem 2rem;
  font-family: var(--font-main);
  cursor: pointer;
  letter-spacing: 0.2em;
  border-radius: 2px;
}

.confirm-buttons button:hover {
  background: var(--button-hover);
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================================
   시스템 UI — 크림/파치먼트 테마 (설정 · 불러오기 · 세이브)
   원본 타이틀(혐관 여동생 - 타이틀.html)의 .set-panel 디자인 이식
   ============================================================ */
.modal {
  background: rgba(20,12,4,.52);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

/* --- 공통 크림 패널 --- */
.set-panel {
  width: 760px;
  max-width: 90%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 36px 46px 28px;
  font-family: 'Gothic A1', var(--font-main);
  color: #3a2c1d;
  background: rgba(244,240,232,.95);
  -webkit-backdrop-filter: blur(16px) saturate(1.05);
  backdrop-filter: blur(16px) saturate(1.05);
  border: 1px solid rgba(255,255,255,.65);
  border-radius: 16px;
  box-shadow: 0 34px 80px -24px rgba(20,10,0,.62), inset 0 1px 0 rgba(255,255,255,.75);
}
.set-panel-wide { width: 980px; }
.set-head {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(120,90,50,.22);
}
.set-title { font-family: 'Gothic A1', 'Noto Sans KR', sans-serif; font-size: 30px; font-weight: 800; letter-spacing: 3px; color: #3a2c1d; }
.set-sub { font-size: 12px; font-weight: 500; letter-spacing: 5px; color: rgba(120,90,55,.55); }
.set-x {
  position: absolute; right: -10px; top: -8px; width: 42px; height: 42px;
  border: none; border-radius: 50%; background: transparent;
  font-size: 19px; color: #8a6f4c; cursor: pointer; transition: .2s; line-height: 1;
}
.set-x:hover { background: rgba(120,90,50,.12); color: #3a2c1d; }
.set-body { padding: 24px 0 6px; display: flex; flex-direction: column; gap: 22px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 30px; }
.set-label { font-size: 19px; font-weight: 600; letter-spacing: .5px; white-space: nowrap; color: #3a2c1d; }
.set-label small { font-size: 11px; letter-spacing: 3px; color: rgba(120,90,55,.5); margin-left: 9px; font-weight: 500; }
.set-ctrl { display: flex; align-items: center; gap: 18px; width: 380px; justify-content: flex-end; }
.set-val { min-width: 56px; text-align: right; font-size: 17px; color: #6e5638; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.set-foot { display: flex; justify-content: flex-end; gap: 14px; padding-top: 22px; border-top: 1px solid rgba(120,90,50,.16); margin-top: 8px; }
.set-btn {
  font-family: var(--font-main); font-weight: 600; font-size: 16px; color: #3a2c1d; letter-spacing: 3px;
  background: rgba(255,255,255,.55); border: 1px solid rgba(120,90,50,.3); border-radius: 9px;
  padding: 12px 30px; cursor: pointer; transition: .2s;
}
.set-btn:hover { background: #fff; transform: translateY(-1px); box-shadow: 0 8px 16px -8px rgba(40,24,8,.4); }

/* --- 크림 슬라이더 --- */
.sl {
  -webkit-appearance: none; appearance: none; flex: 1; height: 6px; border-radius: 5px;
  outline: none; cursor: pointer; --ac: #c2843e;
  background: linear-gradient(to right, var(--ac) 0 var(--p,70%), rgba(120,90,50,.18) var(--p,70%) 100%);
}
.sl::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: #fffdf8; border: 2px solid var(--ac); box-shadow: 0 2px 6px rgba(40,24,8,.3); cursor: grab;
}
.sl::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: #fffdf8; border: 2px solid var(--ac); box-shadow: 0 2px 6px rgba(40,24,8,.3); cursor: grab;
}

/* --- 불러오기 화면 (문이 열리면 등장, 시나리오 선택과 동일 연출) --- */
#title-load {
  position: absolute; inset: 0; z-index: 36;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; pointer-events: none;
  /* 블러 처리된 타이틀(문) 배경이 뒤에 비치도록 */
  background: rgba(18,11,4,.42);
  -webkit-backdrop-filter: blur(16px) saturate(1.05) brightness(.9);
  backdrop-filter: blur(16px) saturate(1.05) brightness(.9);
  transition: opacity .7s ease, visibility .7s;
}
#title-load.open { opacity: 1; visibility: visible; pointer-events: auto; }
#title-load .save-grid { max-height: 56vh; overflow-y: auto; padding-right: 4px; }

/* 불러오기 화면 — 원본 설정창 폰트(Gothic A1) 굵게 */
#title-load .set-title { letter-spacing: 4px; }
#title-load .save-slot { font-family: 'Gothic A1', var(--font-main); font-weight: 700; }
#title-load .slot-title { font-weight: 800; }
#title-load .slot-preview { font-weight: 600; }
#title-load .set-btn { font-weight: 700; }

/* --- 인게임 세이브/로드 모달도 크림으로 통일 --- */
#modal-save .modal-box, #modal-load .modal-box {
  background: rgba(244,240,232,.95);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,.65); color: #3a2c1d; border-radius: 16px;
}
#modal-save .modal-box header, #modal-load .modal-box header { border-bottom: 1px solid rgba(120,90,50,.22); }
#modal-save .modal-box header h2, #modal-load .modal-box header h2 { color: #3a2c1d; }
#modal-save .modal-close, #modal-load .modal-close { color: #8a6f4c; }
#modal-save .modal-close:hover, #modal-load .modal-close:hover { color: #3a2c1d; }

/* --- 크림 세이브 슬롯 (불러오기 화면 + 인게임 모달 공통) --- */
#title-load .save-slot, #modal-save .save-slot, #modal-load .save-slot {
  background: rgba(255,255,255,.55); border: 1px solid rgba(120,90,50,.25); color: #3a2c1d; border-radius: 10px;
}
#title-load .save-slot:hover, #modal-save .save-slot:hover, #modal-load .save-slot:hover {
  border-color: #c2843e; background: #fff; box-shadow: 0 10px 22px -12px rgba(40,24,8,.4);
}
#title-load .save-slot .slot-thumb, #modal-save .save-slot .slot-thumb, #modal-load .save-slot .slot-thumb {
  background: rgba(120,90,50,.12); color: #8a6f4c; border: 1px solid rgba(120,90,50,.2);
}
#title-load .slot-title, #modal-save .slot-title, #modal-load .slot-title { color: #9a5a26; }
#title-load .slot-preview, #modal-save .slot-preview, #modal-load .slot-preview { color: #5e4a34; }
#title-load .slot-date, #modal-save .slot-date, #modal-load .slot-date { color: rgba(90,70,50,.6); }
#title-load .save-slot.empty, #modal-save .save-slot.empty, #modal-load .save-slot.empty { color: rgba(90,70,50,.5); }

/* --- 확인 다이얼로그도 크림 --- */
#modal-confirm .modal-box { background: rgba(244,240,232,.96); color: #3a2c1d; border: 1px solid rgba(255,255,255,.65); border-radius: 14px; }
#modal-confirm .modal-box header { border-bottom: 1px solid rgba(120,90,50,.2); }
#modal-confirm h2 { color: #3a2c1d; }
#modal-confirm .confirm-buttons button { background: rgba(255,255,255,.55); border: 1px solid rgba(120,90,50,.3); color: #3a2c1d; }
#modal-confirm .confirm-buttons button:hover { background: #fff; border-color: #c2843e; color: #3a2c1d; }

/* 모바일: 크림 패널 여백/슬롯 조정 */
@media (max-width: 960px) {
  /* 가로폰: 가로로 짧으므로 행을 가로 배치 그대로 두되 전체를 컴팩트하게 → 스크롤 없이 다 보이게 */
  .set-panel { padding: 18px 22px 14px; max-height: 94vh; }
  .set-panel-wide { width: 760px; }
  .set-title { font-size: 21px; letter-spacing: 2px; }
  .set-sub { font-size: 10px; letter-spacing: 3px; }
  .set-head { padding-bottom: 12px; }
  .set-body { gap: 13px; padding: 14px 0 4px; }
  .set-row { gap: 16px; }
  .set-label { font-size: 14px; }
  .set-label small { font-size: 9px; letter-spacing: 2px; margin-left: 6px; }
  .set-ctrl { width: 56%; gap: 12px; }
  .set-val { font-size: 13px; min-width: 38px; }
  .set-foot { padding-top: 12px; }
  .set-btn { font-size: 13px; padding: 9px 20px; letter-spacing: 2px; }
}

/* ============ 유틸 ============ */
.hidden { display: none !important; }

/* ============================================================
   회전 안내 (모바일 세로 모드)
   ============================================================ */
#rotate-hint {
  display: none;
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 9999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-family: var(--font-main);
  text-align: center;
  letter-spacing: 0.2em;
  font-size: 1.1rem;
  line-height: 1.6;
  padding: 2rem;
}
#rotate-hint .rotate-icon {
  font-size: 4rem;
  animation: rotate-spin 2.4s ease-in-out infinite;
  margin-bottom: 1.5rem;
  display: inline-block;
}
@keyframes rotate-spin {
  0%, 50%, 100% { transform: rotate(0deg); }
  20%           { transform: rotate(90deg); }
  70%           { transform: rotate(90deg); }
}

/* ============================================================
   모바일 — 작은 화면 (터치, 폰트 축소, 패딩 조정)
   ============================================================ */
@media (max-width: 960px) {
  /* 타이틀: 시나리오 선택 (이제 스테이지 밖 = 뷰포트 기준 → 일반 반응형 적용) */
  #scenario-select { padding: 14px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .scsel-head { margin-bottom: 16px; }
  .scsel-title { font-size: 26px; letter-spacing: 2px; }
  .scsel-kicker { margin-bottom: 8px; }
  .scsel-titlerow { gap: 16px; }
  .scsel-titlerow::before, .scsel-titlerow::after { width: 36px; }
  .scsel-sub { margin-top: 8px; font-size: 10px; letter-spacing: 4px; }
  .sc-cards { gap: 16px; width: 100%; justify-content: center; }
  .sc-card { width: min(44vw, 320px); }
  .sc-thumb { height: 22vh; max-height: 150px; }
  .sc-body { padding: 12px 16px 16px; }
  .sc-num { font-size: 11px; }
  .sc-name { font-size: 19px; margin: 6px 0 8px; }
  .sc-desc { font-size: 12.5px; line-height: 1.5; }
  .scsel-foot { margin-top: 18px; gap: 14px; }
  .sc-back { font-size: 14px; padding: 12px 16px; min-height: 44px; }
  .sc-start { font-size: 15px; padding: 12px 24px; min-height: 44px; }

  /* 타이틀: 불러오기 패널 (스테이지 밖 → 실제 뷰포트 크기로) */
  #title-load .set-panel-wide { width: 92vw; max-width: 560px; }
  #title-load .set-x { min-width: 44px; min-height: 44px; }

  /* 다이얼로그 박스 */
  #ui-dialogue {
    height: 36vh;
    min-height: 160px;
    max-height: 230px;
    padding: 1rem 1.3rem 1rem;
  }
  .dialogue-content {
    font-size: calc(1.2rem * var(--dlg-scale, 1));
    line-height: 1.65;
  }
  #speaker-name {
    font-size: 1.25rem;
    padding: 0.18rem 0.8rem;
  }
  .name-plate {
    height: 32px;
    margin-bottom: 0.4rem;
  }

  /* 빠른 메뉴 — 터치 영역 확대 */
  #ui-quick {
    top: 0.5rem;
    right: 0.5rem;
    gap: 0.25rem;
  }
  #ui-quick button {
    padding: 0.6rem 0.7rem;
    font-size: 0.7rem;
    min-height: 38px;
    min-width: 44px;
  }

  /* 씬 타이틀 */
  #scene-title {
    font-size: 1.7rem;
    letter-spacing: 0.3em;
  }

  /* 캐릭터 슬롯 — 다이얼로그 박스 위로 약간 올림 */
  .layer-char {
    padding-bottom: 36vh;
  }
  .char-slot {
    height: 80%;
  }

  /* 모달 */
  .modal-box {
    width: 95%;
    max-height: 90vh;
  }
  .modal-box header {
    padding: 0.75rem 1rem;
  }
  .modal-box header h2 {
    font-size: 1.05rem;
    letter-spacing: 0.15em;
  }
  .modal-close {
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
  }
  .modal-body {
    padding: 1rem;
  }

  /* 설정 행 */
  .config-row {
    grid-template-columns: 100px 1fr 50px;
    gap: 0.6rem;
    padding: 0.6rem 0;
  }
  .config-row label {
    font-size: 0.85rem;
    letter-spacing: 0.05em;
  }
  .config-row select,
  .config-row button {
    padding: 0.6rem 0.8rem;
    font-size: 0.85rem;
    min-height: 40px;
  }
  .config-row input[type="range"] {
    height: 32px;
  }

  /* 세이브 슬롯 — 1열 */
  .save-grid {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }
  .save-slot {
    padding: 0.7rem;
    min-height: 80px;
  }
  .save-slot .slot-thumb {
    width: 90px;
    height: 55px;
  }

  /* 확인 다이얼로그 */
  .confirm-buttons button {
    padding: 0.8rem 1.5rem;
    font-size: 0.95rem;
    min-height: 48px;
    flex: 1;
  }

  /* 클릭 영역 — 다이얼로그 박스 위쪽까지만 */
  #click-area {
    bottom: 36vh;
  }

  /* 중앙 타이프라이터 (우 리 는 살 ...) */
  #center-type {
    font-size: 1.6rem;
    letter-spacing: 0.2em;
    white-space: normal;
    width: 90%;
    line-height: 1.6;
  }

  /* 크레딧 */
  #credits-content {
    width: 90%;
    font-size: 0.92rem;
    line-height: 1.6;
  }
  .credits-section h3 {
    font-size: 0.95rem;
  }
  .credit-item .credit-name {
    font-size: 0.85rem;
  }
  .credit-item .credit-meta {
    font-size: 0.72rem;
  }
  .credit-item .credit-url {
    font-size: 0.66rem;
  }

  /* 백로그 */
  .log-entry {
    padding: 0.5rem 0.6rem;
  }
  .log-entry .log-name {
    font-size: 0.78rem;
  }
  .log-entry .log-text {
    font-size: 0.88rem;
  }
}

/* ============================================================
   초소형 화면 (스마트폰 가로 - 짧은 높이)
   ============================================================ */
@media (max-width: 960px) and (max-height: 540px) {
  #ui-dialogue {
    height: 40vh;
    min-height: 120px;
    max-height: none;
    padding: 0.6rem 1rem 0.5rem;
  }
  .dialogue-content {
    font-size: calc(1.05rem * var(--dlg-scale, 1));   /* 글자크기 설정 유지 (이전엔 무시됐음) */
    line-height: 1.5;
    overflow-y: auto;                  /* 긴 대사는 잘리지 말고 스크롤 */
    -webkit-overflow-scrolling: touch;
  }
  #speaker-name {
    font-size: 1.05rem;
  }
  .name-plate {
    height: 26px;
    margin-bottom: 0.2rem;
  }
  /* 빠른 메뉴: 7개 버튼이 줄바꿈되며 ≥44px 탭 영역 유지 */
  #ui-quick {
    flex-wrap: wrap;
    max-width: 64vw;
    justify-content: flex-end;
  }
  #ui-quick button {
    min-height: 44px;
    min-width: 44px;
  }
  .layer-char {
    padding-bottom: 40vh;
  }
  #click-area {
    bottom: 40vh;
  }
  #scene-title {
    font-size: 1.4rem;
  }
}

/* ============================================================
   세로 모드 (모바일 portrait) — 회전 안내 표시
   ============================================================ */
@media (max-width: 900px) and (orientation: portrait) {
  #rotate-hint {
    display: flex;
  }
  /* 세로일 땐 게임 일시 가림 */
  #app {
    visibility: hidden;
  }
}

/* 터치 디바이스: hover 효과 비활성, :active 강조 */
@media (hover: none) {
  .title-menu button:hover,
  #ui-quick button:hover,
  .modal-close:hover,
  .save-slot:hover,
  .confirm-buttons button:hover {
    background: var(--button-bg);
    color: var(--text-color);
    border-color: rgba(255,255,255,0.1);
  }
  .title-menu button:active {
    background: rgba(212, 175, 55, 0.25);
    border-color: var(--accent);
    color: var(--accent);
    transform: scale(0.97);
  }
  .save-slot:active {
    border-color: var(--accent);
    background: rgba(20,20,30,0.6);
  }
  .confirm-buttons button:active {
    background: rgba(212, 175, 55, 0.3);
    color: var(--accent);
    border-color: var(--accent);
    transform: scale(0.96);
  }
}

/* ============================================================
   터치 디바이스 (포인터 coarse) — 줌 방지 / 세이프에어리어 / 탭 영역
   ============================================================ */
@media (pointer: coarse) {
  /* 더블탭 줌·300ms 탭 지연 제거 (백로그 스와이프엔 영향 없음) */
  #click-area, #ui-dialogue, #ui-quick button,
  #title-stage .t-btn, .sc-card, .sc-start, .sc-back, .set-btn, .set-x,
  .save-slot, .sc-confirm-btn, .modal-close,
  .config-row button, .config-row select {
    touch-action: manipulation;
  }
  /* 노치/홈 인디케이터 회피 (index.html viewport-fit=cover) */
  #ui-quick {
    top: calc(0.5rem + env(safe-area-inset-top));
    right: calc(0.5rem + env(safe-area-inset-right));
  }
  #ui-dialogue {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }
  #dialogue-arrow { right: calc(0.1rem + env(safe-area-inset-right)); }
  /* 설정 슬라이더 썸 — 잡기 쉽되 과하지 않게 */
  .sl { height: 7px; }
  .sl::-webkit-slider-thumb { width: 22px; height: 22px; }
  .sl::-moz-range-thumb { width: 22px; height: 22px; }
  /* 스토리 안내창 버튼 ≥48px */
  .sc-confirm-btn { min-height: 48px; }
  /* 스크롤 패널: iOS 관성 스크롤 + 배경 스크롤 체이닝 차단 */
  .set-panel, .modal-body, #log-entries, #title-load .save-grid {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
}

/* 터치(hover 불가): 실제 사용 셀렉터의 hover 잔상 제거 + :active 탭 피드백 */
@media (hover: none) {
  #title-stage .t-btn:hover { transform: none; filter: drop-shadow(0 6px 12px rgba(30,18,6,.28)); }
  .sc-card:hover { transform: none; box-shadow: 0 24px 50px -22px rgba(40,24,8,.42); }
  .sc-start:hover:not(:disabled) { transform: none; box-shadow: 0 12px 24px -10px rgba(150,90,30,.6); }
  .sc-back:hover { background: transparent; color: #7a6244; }
  .sc-confirm-btn:hover { transform: none; }

  #title-stage .t-btn:active { transform: scale(0.97); }
  .sc-card:active { transform: scale(0.985); }
  .sc-start:active:not(:disabled) { transform: scale(0.97); }
  .sc-confirm-btn:active { transform: scale(0.96); filter: brightness(1.1); }
}

/* 스토리 안내창(@confirm): 짧은 가로 화면에서 버튼이 화면 밖으로 밀리지 않게 */
@media (max-height: 540px) {
  .story-confirm-box { padding: 1.2rem 1.3rem; max-height: 92vh; overflow-y: auto; }
  #story-confirm-msg { font-size: 1rem; margin-bottom: 1rem; line-height: 1.5; }
  .story-confirm-btns { flex-wrap: wrap; }
  .sc-confirm-btn { min-width: 96px; padding: 0.6rem 1rem; font-size: 0.95rem; }
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.05);
}
::-webkit-scrollbar-thumb {
  background: rgba(212, 175, 55, 0.3);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(212, 175, 55, 0.5);
}
