/* ==========================================================================
   욕망의 칼 (가제) — 기본 스타일 (모바일 퍼스트)
   뼈대 세팅 단계: 리셋 + 리더 기본값(폰트/줄간격/색상 변수)만 최소 정의
   ========================================================================== */

/* --- 색상/타이포 변수 (고정 다크 테마 — 검은 배경 + 흰 글자) --- */
:root {
  --color-bg: #000000;
  --color-surface: #1a1a1a;
  --color-text: #ffffff;
  --color-text-muted: #b3b3b3;
  --color-accent: #e05a5a; /* 칼/욕망 — 절제된 레드 */
  --color-border: #333333;

  --font-body: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Noto Sans KR", "Malgun Gothic", sans-serif;

  --reader-font-size: 1.0625rem; /* 17px — 본문 가독성 기준 */
  --reader-line-height: 1.8;      /* 웹소설 리더 표준 줄간격 */
  --reader-max-width: 42rem;      /* 한 줄 길이 제한 */
}

/* --- 리셋 (최소) --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

img,
picture,
video {
  max-width: 100%;
  display: block;
}

/* --- 기본 레이아웃 --- */
body {
  font-family: var(--font-body);
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.site-header,
.site-main,
.site-footer {
  width: 100%;
  max-width: var(--reader-max-width);
  margin-inline: auto;
  padding-inline: 1.25rem;
}

/* --- 헤더 --- */
.site-header {
  padding-top: 2.5rem;
  padding-bottom: 1.5rem;
  text-align: center;
  border-bottom: 1px solid var(--color-border);
}

.site-title {
  font-size: 1.75rem;
  letter-spacing: 0.02em;
  color: var(--color-accent);
}

.site-subtitle {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* --- 본문 --- */
.site-main {
  flex: 1;
  padding-top: 2.5rem;
  padding-bottom: 2.5rem;
}

/* --- 푸터 --- */
.site-footer {
  padding-top: 1.5rem;
  padding-bottom: 2rem;
  text-align: center;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
}

/* ==========================================================================
   리더 영역 (헤더 아래) — 누리 스펙
   ========================================================================== */

.site-main {
  /* 우하단 플로팅 버튼과 겹치지 않도록 하단 여유 */
  padding-bottom: 6rem;
}

.reader__head {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

.reader__epno {
  font-size: 0.8125rem;
  letter-spacing: 0.08em;
  color: var(--color-accent);
}

.reader__eptitle {
  margin-top: 0.35rem;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--color-text);
}

/* --- 블록 공통 --- */
.blk {
  margin-bottom: 1.15rem;
}

/* 씬 헤딩: 작게·회색·자간 넓게·위아래 여백 크게 */
.blk--scene {
  margin-top: 2.75rem;
  margin-bottom: 1.75rem;
  font-size: 0.8125rem;
  letter-spacing: 0.14em;
  line-height: 1.6;
  color: var(--color-text-muted);
  text-transform: none;
}
.blk--scene:first-child {
  margin-top: 0;
}

/* 지문: 본문체, 줄간격 1.7 */
.blk--action {
  line-height: 1.7;
  color: var(--color-text);
}
.blk--action em {
  font-style: italic;
  color: var(--color-text-muted);
}

/* 대사 블록 */
.blk--dialogue {
  margin-top: 1.35rem;
  margin-bottom: 1.35rem;
}

/* 캐릭터명: 볼드, 왼쪽 정렬 */
.dlg__name {
  font-weight: 700;
  text-align: left;
  color: var(--color-text);
}

/* 지시어: 캐릭터명 아래 이탤릭·회색·작게, 괄호 유지 */
.dlg__paren {
  margin-top: 0.1rem;
  font-style: italic;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

/* 대사: 지문 대비 좌우 약 1em 들여쓰기 */
.dlg__line {
  margin-top: 0.35rem;
  padding-inline: 1em;
  line-height: 1.7;
}

/* 읽음 판정용 sentinel */
.reader__sentinel {
  height: 1px;
  width: 100%;
}

/* ==========================================================================
   다음 화 플로팅 버튼 (우하단 고정)
   ========================================================================== */
.next-fab {
  position: fixed;
  right: 1.1rem;
  bottom: 1.4rem;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.7rem 1.1rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease,
    border-color 0.18s ease, transform 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}
.next-fab:active {
  transform: scale(0.96);
}

/* 잠금: 회색 비활성 + 자물쇠 */
.next-fab.is-locked {
  background-color: var(--color-surface);
  color: var(--color-text-muted);
  border-color: var(--color-border);
}

/* 해제: 강조색 활성 */
.next-fab.is-unlocked {
  background-color: var(--color-accent);
  color: #ffffff;
  border-color: var(--color-accent);
  box-shadow: 0 6px 18px rgba(224, 90, 90, 0.35);
}

.next-fab__icon {
  font-size: 0.95rem;
  line-height: 1;
}

/* ==========================================================================
   접근 게이트 (가벼운 접근 제한)
   ========================================================================== */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background-color: var(--color-bg);
  transition: opacity 0.28s ease;
}
.gate.is-hidden {
  opacity: 0;
  pointer-events: none;
}
/* 게이트 활성 동안 뒤 스크롤 잠금 */
body.is-gated {
  overflow: hidden;
}

.gate__box {
  width: 100%;
  max-width: 20rem;
  display: flex;
  flex-direction: column;
  text-align: center;
}
.gate__title {
  font-size: 1.75rem;
  letter-spacing: 0.02em;
  color: var(--color-accent);
}
.gate__desc {
  margin-top: 0.6rem;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}
.gate__input {
  width: 100%;
  padding: 0.75rem 0.9rem;
  font-family: inherit;
  font-size: 1rem;
  color: var(--color-text);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.6rem;
  outline: none;
  transition: border-color 0.18s ease;
}
.gate__input:focus {
  border-color: var(--color-accent);
}
.gate__btn {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: #ffffff;
  background-color: var(--color-accent);
  border: 1px solid var(--color-accent);
  border-radius: 0.6rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease;
}
.gate__btn:active {
  transform: scale(0.97);
}
.gate__error {
  min-height: 1.2em;
  margin-top: 0.9rem;
  font-size: 0.85rem;
  color: var(--color-accent);
}

/* ==========================================================================
   토스트
   ========================================================================== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 5.5rem;
  transform: translateX(-50%) translateY(0.5rem);
  z-index: 40;
  max-width: calc(100% - 2.5rem);
  padding: 0.65rem 1.1rem;
  background-color: rgba(40, 40, 40, 0.96);
  color: #ffffff;
  border: 1px solid var(--color-border);
  border-radius: 0.6rem;
  font-size: 0.9rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- 태블릿 이상 --- */
@media (min-width: 640px) {
  :root {
    --reader-font-size: 1.125rem; /* 18px */
  }

  .site-title {
    font-size: 2rem;
  }

  .reader__eptitle {
    font-size: 1.6rem;
  }
}

/* ==========================================================================
   상단 내비게이션 (3탭: 기획서 / 트리트먼트 / 시나리오) — 신규
   전역 sticky, 다크 배경, 현재 뷰 탭을 accent 로 강조
   ========================================================================== */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  width: 100%;
  background-color: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}
.site-nav__inner {
  width: 100%;
  max-width: var(--reader-max-width);
  margin-inline: auto;
  display: flex;
}
.site-nav__tab {
  flex: 1;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.25rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--color-text-muted);
  position: relative;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.18s ease;
}
.site-nav__tab::after {
  content: "";
  position: absolute;
  left: 20%;
  right: 20%;
  bottom: -1px;
  height: 2px;
  background-color: transparent;
  transition: background-color 0.18s ease;
}
/* 현재 뷰 활성 강조 */
body[data-view="reader"] .site-nav__tab[data-tab="reader"],
body[data-view="deck"] .site-nav__tab[data-tab="deck"],
body[data-view="treatment"] .site-nav__tab[data-tab="treatment"] {
  color: var(--color-accent);
}
body[data-view="reader"] .site-nav__tab[data-tab="reader"]::after,
body[data-view="deck"] .site-nav__tab[data-tab="deck"]::after,
body[data-view="treatment"] .site-nav__tab[data-tab="treatment"]::after {
  background-color: var(--color-accent);
}

/* ==========================================================================
   뷰 토글 (라우터가 body[data-view] 설정)
   ========================================================================== */
#view-reader,
#view-treatment {
  display: none;
}
.deck {
  display: none;
}
body[data-view="reader"] #view-reader {
  display: block;
}
body[data-view="treatment"] #view-treatment {
  display: block;
}
body[data-view="deck"] .deck {
  display: flex;
}
/* 기획서(deck)는 풀스크린 캐러셀 — 헤더/본문/푸터 숨기고 화면을 채운다 */
body[data-view="deck"] .site-header,
body[data-view="deck"] .site-main,
body[data-view="deck"] .site-footer {
  display: none;
}
body[data-view="deck"] {
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}
/* 다음 화 FAB·토스트는 시나리오 리더에서만 */
body:not([data-view="reader"]) .next-fab,
body:not([data-view="reader"]) .toast {
  display: none;
}
/* ==========================================================================
   기획서 뷰어 (좌우 페이지 넘김) — 신규 넘김 패턴
   ========================================================================== */
.deck {
  flex: 1;
  min-height: 0;
  flex-direction: column;
}
.deck__viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.deck__track {
  display: flex;
  height: 100%;
  will-change: transform;
}
.deck__viewport.is-fading {
  transition: opacity 0.12s ease;
  opacity: 0.35;
}
.deck-page {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
/* 좌우 화살표 (세로 중앙 고정) */
.deck__arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--color-text);
  background-color: rgba(26, 26, 26, 0.72);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.18s ease, background-color 0.18s ease;
}
.deck__arrow--prev { left: 0.5rem; }
.deck__arrow--next { right: 0.5rem; }
.deck__arrow.is-disabled {
  opacity: 0;
  pointer-events: none;
}

/* 하단 인디케이터 (도트 + n/21) */
.deck__nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  padding: 0.7rem 1rem calc(0.7rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--color-border);
}
.deck__dots {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.deck-dot {
  width: 8px;
  height: 8px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background-color: var(--color-border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.18s ease, width 0.18s ease;
}
.deck-dot.is-active {
  width: 20px;
  background-color: var(--color-accent);
}
.deck__count {
  font-size: 0.8125rem;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  min-width: 3.2em;
  text-align: right;
}

/* PDF 기획서 슬라이드(12-06): 기본 = 화면을 꽉 채움(창 비율이 16:9와 다르면 위아래나 좌우 끝이 잘림).
   [원본 비율] 버튼(.deck.is-fit)이나 세로 화면 = 16:9 통째로(남는 곳 검정). 상단 탭·하단 점은 슬라이드 위에 겹침 */
.deck-slide {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
  container-type: size;
}
.deck-slide__frame {
  position: relative;
  flex: none;
  width: max(100cqw, 100cqh * 16 / 9);
  aspect-ratio: 16 / 9;
}
.deck.is-fit .deck-slide__frame {
  width: min(100cqw, 100cqh * 16 / 9);
}
@media (orientation: portrait) {
  .deck-slide__frame { width: min(100cqw, 100cqh * 16 / 9); }
  .deck__fit { display: none; }
}
/* 슬라이드가 창 전체를 쓰고, 탭·점은 그 위에 반투명으로 */
body[data-view="deck"] .site-nav {
  position: fixed;
  left: 0;
  right: 0;
  background: linear-gradient(rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
  border-bottom: none;
}
body[data-view="deck"] .deck {
  position: fixed;
  inset: 0;
}
body[data-view="deck"] .deck__nav {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  border-top: none;
  background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.55));
}
.deck__fit {
  margin-left: 0.5rem;
  padding: 0.2rem 0.6rem;
  font: inherit;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  cursor: pointer;
}
.deck__fit:hover { color: var(--color-text); }
.deck-slide__img {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}
/* PDF 안 링크 자리(투명) */
.deck-slide__link {
  position: absolute;
  border-radius: 2px;
}
.deck-slide__link:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ==========================================================================
   트리트먼트 뷰 (임시 · 단순 세로 스크롤 마크다운) — 신규
   ※ 누리 정식 기획 없이 만든 임시 구현. 정식 뷰어 기획은 추후 누리에게 받는다.
   ========================================================================== */
.treatment {
  padding-top: 1rem;
}
.treatment__note {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  margin-bottom: 2rem;
  line-height: 1.6;
}
.md h1,
.md h2,
.md h3,
.md h4 {
  line-height: 1.35;
  margin-top: 2rem;
  margin-bottom: 0.9rem;
  color: var(--color-text);
}
.md h1 { font-size: 1.5rem; color: var(--color-accent); }
.md h2 { font-size: 1.25rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.4rem; }
.md h3 { font-size: 1.08rem; color: var(--color-accent); }
.md h4 { font-size: 0.98rem; }
.md h1:first-child,
.md h2:first-child { margin-top: 0; }
.md p {
  font-size: 0.9375rem;
  line-height: 1.8;
  margin-bottom: 1rem;
  color: var(--color-text);
}
.md em { color: var(--color-text-muted); font-style: italic; }
.md strong { color: var(--color-text); font-weight: 700; }
.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.3rem;
  padding: 0.05rem 0.35rem;
}
.md ul,
.md ol {
  margin: 0 0 1rem 1.2rem;
  padding: 0;
}
.md li {
  font-size: 0.9375rem;
  line-height: 1.75;
  margin-bottom: 0.4rem;
}
.md blockquote {
  margin: 0 0 1.2rem;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--color-accent);
  background-color: var(--color-surface);
  border-radius: 0 0.5rem 0.5rem 0;
  color: var(--color-text-muted);
}
.md blockquote p { margin-bottom: 0.5rem; color: var(--color-text-muted); }
.md blockquote p:last-child { margin-bottom: 0; }
.md hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 2rem 0;
}
.md__tablewrap {
  overflow-x: auto;
  margin-bottom: 1.4rem;
  -webkit-overflow-scrolling: touch;
}
.md table {
  border-collapse: collapse;
  width: 100%;
  min-width: 32rem;
  font-size: 0.85rem;
}
.md th,
.md td {
  border: 1px solid var(--color-border);
  padding: 0.5rem 0.7rem;
  text-align: left;
  line-height: 1.5;
  vertical-align: top;
}
.md th {
  background-color: var(--color-surface);
  color: var(--color-accent);
  font-weight: 700;
  white-space: nowrap;
}

/* --- 태블릿 이상: 넘김 뷰 여백 확대 --- */
@media (min-width: 640px) {
  .deck__arrow--prev { left: 1.25rem; }
  .deck__arrow--next { right: 1.25rem; }
}
