/* ISEKAI_MAID — 비주얼 노벨 최소 엔진 스타일 */

:root {
  --stage-w: 1280px;
  --stage-h: 720px; /* 16:9 */
  --ink: #f4ecdf;
  --ink-dim: #cbbfa8;
  --box-bg: rgba(28, 22, 30, 0.82);
  --box-edge: rgba(214, 190, 148, 0.55);
  --accent: #d8b56a; /* 금빛 (성/메이드 톤) */
  --choice-bg: rgba(38, 30, 42, 0.86);
  --choice-hover: rgba(70, 54, 78, 0.95);
  --name-bg: rgba(120, 78, 60, 0.92);
  --font: "Noto Serif KR", "Nanum Myeongjo", Georgia, serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background: #050406;
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
}

/* 화면 중앙에 16:9 무대를 레터박스로 배치 */
#game {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
}
#stage {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  background: #000;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  user-select: none;
}

/* --- 레이어 --- */
.layer {
  position: absolute;
  inset: 0;
}

#bg-layer img,
#cg-layer img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.45s ease;
}
#cg-layer {
  opacity: 0;
  transition: opacity 0.45s ease;
  pointer-events: none;
}
#cg-layer.show {
  opacity: 1;
}

#char-layer {
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#char-layer img {
  height: 92%;
  max-width: 60%;
  object-fit: contain;
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.5));
  transition:
    opacity 0.3s ease,
    transform 0.3s ease;
  transform: translateY(2%);
}
#char-layer.hidden img {
  opacity: 0;
}

/* --- 대사창 --- */
#textbox {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 3.5%;
  min-height: 22%;
  background: var(--box-bg);
  border: 1px solid var(--box-edge);
  border-radius: 14px;
  padding: 26px 34px 30px;
  backdrop-filter: blur(3px);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.2s ease;
}
#textbox.show {
  opacity: 1;
}

#speaker {
  display: inline-block;
  position: absolute;
  top: -18px;
  left: 26px;
  background: var(--name-bg);
  color: #fff;
  font-weight: 700;
  padding: 6px 18px;
  border-radius: 8px;
  font-size: clamp(14px, 1.6vw, 20px);
  letter-spacing: 0.5px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
}
#speaker:empty {
  display: none;
}

#text {
  font-size: clamp(15px, 1.9vw, 24px);
  line-height: 1.7;
  white-space: pre-wrap;
  min-height: 2em;
}
#textbox.narration #text {
  font-style: italic;
  color: var(--ink-dim);
}

#indicator {
  position: absolute;
  right: 22px;
  bottom: 12px;
  color: var(--accent);
  font-size: 18px;
  animation: bob 1s ease-in-out infinite;
  opacity: 0;
}
#indicator.show {
  opacity: 1;
}
@keyframes bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(4px);
  }
}

/* --- 선택지 --- */
#choices {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 0 12%;
  background: rgba(0, 0, 0, 0.35);
}
#choices.show {
  display: flex;
}
#choice-prompt {
  color: var(--ink);
  font-size: clamp(15px, 1.8vw, 22px);
  margin-bottom: 8px;
  text-align: center;
  text-shadow: 0 2px 8px #000;
}
.choice-btn {
  width: 100%;
  max-width: 720px;
  background: var(--choice-bg);
  color: var(--ink);
  border: 1px solid var(--box-edge);
  border-radius: 12px;
  padding: 16px 24px;
  font-family: var(--font);
  font-size: clamp(14px, 1.7vw, 21px);
  cursor: pointer;
  transition:
    background 0.15s ease,
    transform 0.1s ease,
    border-color 0.15s ease;
}
.choice-btn:hover {
  background: var(--choice-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
}

/* --- 타이틀/챕터 카드 --- */
#titlecard {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
}
#titlecard.show {
  display: flex;
}
#titlecard .card {
  text-align: center;
  font-size: clamp(22px, 3.4vw, 46px);
  line-height: 1.5;
  white-space: pre-wrap;
  color: #fff;
  letter-spacing: 2px;
  text-shadow: 0 3px 16px rgba(0, 0, 0, 0.7);
  animation: fadeUp 0.6s ease;
}
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* --- 디버그 패널 (v 키로 토글) --- */
#debug {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.7);
  color: #9fe6a0;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  display: none;
  max-width: 40%;
  pointer-events: none;
}
#debug.show {
  display: block;
}
#debug b {
  color: var(--accent);
}

/* --- 테스트용 라인 정보 (우상단, i 키로 토글) --- */
#lineinfo {
  position: absolute;
  top: 10px;
  right: 10px;
  display: none;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  background: rgba(0, 0, 0, 0.66);
  border: 1px solid rgba(216, 181, 106, 0.35);
  border-radius: 8px;
  padding: 7px 11px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  line-height: 1.35;
  cursor: pointer;
  max-width: 60%;
  z-index: 20;
}
#lineinfo.on {
  display: flex;
}
#lineinfo .li-scene {
  color: var(--ink-dim);
  font-size: 11px;
}
#lineinfo .li-id {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  word-break: break-all;
  text-align: right;
}
#lineinfo .li-no {
  color: #8fd0ff;
  font-size: 11px;
}
#lineinfo:hover {
  border-color: var(--accent);
}

/* --- 메뉴 버튼 --- */
#menu-btn {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 25;
  width: 40px;
  height: 40px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--box-edge);
  border-radius: 8px;
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease;
}
#menu-btn:hover {
  background: rgba(70, 54, 78, 0.9);
  border-color: var(--accent);
}

/* --- 타이틀 화면 --- */
#titlescreen {
  position: absolute;
  inset: 0;
  display: none;
  z-index: 30;
  overflow: hidden;
}
#titlescreen.show {
  display: block;
}
#titlescreen .ts-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#titlescreen .ts-left {
  position: absolute;
  top: 5%;
  left: 4%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 22px;
  width: min(300px, 40%);
}
#titlescreen .ts-logo {
  width: 100%;
  max-height: 34vh;
  object-fit: contain;
  object-position: left top;
  filter: drop-shadow(0 6px 20px rgba(0, 0, 0, 0.55));
}
#titlescreen .ts-title {
  font-size: clamp(26px, 4vw, 48px);
  color: #fff;
  letter-spacing: 3px;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.7);
}
#titlescreen .ts-menu {
  display: flex;
  flex-direction: column;
  gap: 9px;
  width: 100%;
}
#titlescreen .ts-menu button {
  background: rgba(24, 18, 26, 0.7);
  border: 1px solid var(--box-edge);
  color: var(--ink);
  font-family: var(--font);
  font-size: clamp(13px, 1.4vw, 18px);
  padding: 11px 16px;
  border-radius: 10px;
  cursor: pointer;
  backdrop-filter: blur(2px);
  transition:
    background 0.15s ease,
    transform 0.1s ease,
    border-color 0.15s ease;
}
#titlescreen .ts-menu button:hover:not(:disabled) {
  background: var(--choice-hover);
  border-color: var(--accent);
  transform: translateX(4px);
}
#titlescreen .ts-menu button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* --- 모달 (메뉴/세이브/로드/설정) --- */
#modal {
  position: absolute;
  inset: 0;
  display: none;
  z-index: 35;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
}
#modal.show {
  display: flex;
}
#modal-box {
  background: rgba(26, 20, 28, 0.97);
  border: 1px solid var(--box-edge);
  border-radius: 16px;
  padding: 26px 30px;
  width: min(560px, 88%);
  max-height: 84%;
  overflow-y: auto;
  box-shadow: 0 12px 50px rgba(0, 0, 0, 0.6);
}
#modal-box h2 {
  color: var(--accent);
  font-size: clamp(18px, 2.2vw, 26px);
  margin-bottom: 18px;
  text-align: center;
}
#modal-box button {
  font-family: var(--font);
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--box-edge);
  background: var(--choice-bg);
  color: var(--ink);
  padding: 11px 18px;
  font-size: clamp(13px, 1.5vw, 18px);
  transition:
    background 0.15s ease,
    border-color 0.15s ease;
}
#modal-box button:hover:not(:disabled) {
  background: var(--choice-hover);
  border-color: var(--accent);
}
#modal-box button:disabled {
  opacity: 0.4;
  cursor: default;
}
.menu-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.modal-close {
  display: block;
  margin: 16px auto 0;
}

/* 세이브 슬롯 */
.slots {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.slot {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  align-items: center;
  gap: 14px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(214, 190, 148, 0.25);
  border-radius: 10px;
  padding: 12px 14px;
}
.slot-head {
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
}
.slot-info {
  font-size: 13px;
  color: var(--ink-dim);
  line-height: 1.4;
  overflow: hidden;
}
.slot-info .slot-scene {
  color: #8fd0ff;
  font-family: ui-monospace, monospace;
  font-size: 11px;
}
.slot-info .slot-prev {
  color: var(--ink);
}
.slot-info small {
  opacity: 0.6;
}

/* 설정 */
.cfg-row {
  margin-bottom: 18px;
}
.cfg-row label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 15px;
}
.cfg-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.cfg-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 8px;
}

/* 넓은 모달 (갤러리/CG뷰) */
#modal-box.wide {
  width: min(1000px, 94%);
  max-height: 90%;
}

/* 백로그 */
.backlog {
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 6px 10px 6px 2px;
}
.bl-row {
  line-height: 1.55;
}
.bl-name {
  display: block;
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 2px;
}
.bl-text {
  color: var(--ink);
  font-size: 15px;
}
.bl-text.narr {
  color: var(--ink-dim);
  font-style: italic;
}
.bl-row + .bl-row {
  border-top: 1px solid rgba(214, 190, 148, 0.15);
  padding-top: 10px;
}
.bl-empty {
  color: var(--ink-dim);
  text-align: center;
  padding: 30px;
}

/* CG 갤러리 */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  max-height: 68vh;
  overflow-y: auto;
  padding: 4px;
}
.cg-cell {
  aspect-ratio: 16 / 9;
  border: 1px solid var(--box-edge);
  border-radius: 8px;
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cg-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s ease;
}
.cg-cell:hover img {
  transform: scale(1.05);
}
.cg-cell.locked {
  cursor: default;
  background: rgba(0, 0, 0, 0.4);
  color: var(--ink-dim);
  font-size: 26px;
  border-style: dashed;
}

/* CG 확대 뷰 */
.cg-view {
  display: flex;
  align-items: center;
  justify-content: center;
}
.cg-view img {
  max-width: 100%;
  max-height: 74vh;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}

/* 조작법(도움말) */
.help-list,
.help-dev {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
}
.help-row {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 14px;
  align-items: baseline;
  font-size: 15px;
}
.help-row .k {
  color: var(--accent);
  font-weight: 700;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  text-align: right;
}
.help-dev {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(214, 190, 148, 0.2);
  opacity: 0.7;
}
.help-dev-title {
  color: var(--ink-dim);
  font-size: 12px;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

/* 첫 실행 힌트 */
.first-hint {
  position: absolute;
  left: 50%;
  bottom: 30%;
  transform: translate(-50%, 10px);
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid var(--box-edge);
  color: var(--ink);
  font-size: clamp(13px, 1.6vw, 18px);
  padding: 12px 22px;
  border-radius: 24px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition:
    opacity 0.5s ease,
    transform 0.5s ease;
  z-index: 24;
}
.first-hint.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* --- 로딩/에러 --- */
#overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #050406;
  color: var(--ink-dim);
  font-size: 18px;
  text-align: center;
  padding: 40px;
  line-height: 1.6;
}
#overlay.hidden {
  display: none;
}
