/* ===== Variables ===== */
:root {
  --bg: #09090f;
  --surface: #111118;
  --surface-2: #181826;
  --border: rgba(180, 210, 255, 0.08);
  --text: #e0e0ee;
  --text-dim: #9090b0;
  --text-muted: #606080;
  --accent: #b8d8ff;
  --accent-glow: rgba(184, 216, 255, 0.18);
  --accent-strong: rgba(184, 216, 255, 0.35);
  --serif: 'Noto Serif KR', Georgia, serif;
  --sans: 'Noto Sans KR', -apple-system, sans-serif;
  --mono: 'SF Mono', 'Consolas', 'Courier New', monospace;
  --radius: 12px;
  --tr: 0.26s cubic-bezier(0.4, 0, 0.2, 1);
  --font-size: 17px;
}

.light {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #eeecea;
  --border: rgba(0, 0, 0, 0.07);
  --text: #1a1a2a;
  --text-dim: #555570;
  --text-muted: #999999;
  --accent: #2255aa;
  --accent-glow: rgba(34, 85, 170, 0.1);
  --accent-strong: rgba(34, 85, 170, 0.2);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); font-family: var(--sans); color: var(--text); overscroll-behavior: none; }
button { cursor: pointer; border: none; background: none; color: inherit; font-family: inherit; }
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }

/* ===== App shell ===== */
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}

/* ===== Screen system ===== */
.screen {
  min-height: 100vh;
  background: var(--bg);
  animation: screenIn var(--tr) ease both;
}
@keyframes screenIn {
  from { opacity: 0; transform: translateX(32px); }
  to   { opacity: 1; transform: translateX(0); }
}
.screen.back-anim {
  animation: screenBack var(--tr) ease both;
}
@keyframes screenBack {
  from { opacity: 0; transform: translateX(-32px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ===== Cover screen ===== */
.cover-screen {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.cover-bg {
  position: absolute;
  inset: 0;
  background: #090912;
  overflow: hidden;
}
.cover-bg img {
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0.75;
}
.cover-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(9,9,18,0) 30%,
    rgba(9,9,18,0.6) 60%,
    rgba(9,9,18,0.96) 85%,
    rgba(9,9,18,1) 100%
  );
}
/* Portal glow fallback when image missing */
.cover-bg-fallback {
  width: 100%; height: 100%;
  background: radial-gradient(ellipse at 50% 40%, #1a2040 0%, #090912 70%);
  display: flex; align-items: center; justify-content: center;
}
.cover-bg-fallback::before {
  content: '';
  width: 2px; height: 45%;
  background: linear-gradient(to bottom, transparent, var(--accent), transparent);
  box-shadow: 0 0 40px 20px var(--accent-glow);
}

.cover-content {
  position: relative;
  z-index: 1;
  padding: 0 28px 48px;
}

.cover-title {
  font-family: var(--serif);
  font-size: 38px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #fff;
  margin-bottom: 6px;
  text-shadow: 0 2px 20px rgba(0,0,0,0.6);
}
.cover-subtitle {
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.12em;
  margin-bottom: 36px;
}

.btn-read {
  width: 100%;
  padding: 17px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #09090f;
  font-size: 17px;
  font-weight: 500;
  font-family: var(--sans);
  letter-spacing: 0.04em;
  margin-bottom: 12px;
  transition: opacity var(--tr), transform var(--tr);
}
.btn-read:active { opacity: 0.8; transform: scale(0.98); }

.cover-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.btn-nav {
  padding: 13px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.05);
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  transition: background var(--tr), color var(--tr);
  backdrop-filter: blur(8px);
}
.btn-nav:active { background: var(--accent-glow); color: var(--accent); }

/* ===== Common header ===== */
.page-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.btn-back {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  font-size: 18px;
  color: var(--text-dim);
  flex-shrink: 0;
  transition: background var(--tr);
}
.btn-back:active { background: var(--surface-2); }
.header-title {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  text-align: center;
}
.header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.btn-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-dim);
  transition: background var(--tr), color var(--tr);
}
.btn-icon:active { background: var(--surface-2); color: var(--text); }
.btn-icon.active { color: var(--accent); }

/* ===== Reading screen ===== */
.chapter-tabs {
  display: flex;
  overflow-x: auto;
  padding: 0 16px;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chapter-tabs::-webkit-scrollbar { display: none; }
.chapter-tab {
  flex-shrink: 0;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: color var(--tr), border-color var(--tr);
  white-space: nowrap;
}
.chapter-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.reading-body {
  padding: 0 0 80px;
}

/* Content blocks */
.chapter-content {
  padding: 0 24px;
}
.chapter-content p {
  font-family: var(--serif);
  font-size: var(--font-size);
  line-height: 2;
  color: var(--text);
  margin-bottom: 0.5em;
  word-break: keep-all;
}
.chapter-content p + p { margin-top: 0.3em; }
.chapter-content code {
  font-family: var(--mono);
  font-size: 0.88em;
  color: var(--accent);
  background: var(--accent-glow);
  padding: 1px 5px;
  border-radius: 4px;
}

.scene-header {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 28px 24px 16px;
}

.scene-break {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 24px;
  color: var(--text-muted);
}
.scene-break::before,
.scene-break::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.scene-break span {
  font-size: 10px;
  letter-spacing: 0.2em;
}

.illustration {
  width: 100%;
  margin: 4px 0 24px;
  position: relative;
  background: var(--surface);
}
.illustration img {
  width: 100%;
  max-height: 70vh;
  object-fit: cover;
  display: block;
}
.illustration-fallback {
  width: 100%;
  aspect-ratio: 9/13;
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 12px;
}
.illustration-fallback::before {
  content: '';
  width: 1px; height: 60px;
  background: linear-gradient(to bottom, transparent, var(--accent), transparent);
  box-shadow: 0 0 12px 6px var(--accent-glow);
}

.timer {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 400;
  color: var(--accent);
  text-align: center;
  padding: 16px 24px;
  letter-spacing: 0.08em;
}

.ad-slot {
  margin: 28px 24px;
  text-align: center;
  overflow: hidden;
}
.ad-slot::before {
  content: 'AD';
  display: block;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  opacity: 0.7;
  margin-bottom: 8px;
}
.ad-slot-dev {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 18px 12px;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--surface-2);
}
.ad-slot-dev::before { content: ''; margin: 0; }

.code-block {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-dim);
  background: var(--surface);
  border-left: 2px solid var(--accent);
  padding: 14px 16px;
  margin: 16px 24px;
  white-space: pre;
  overflow-x: auto;
  border-radius: 0 8px 8px 0;
}

.inner-monologue {
  font-family: var(--serif);
  font-size: var(--font-size);
  line-height: 2;
  color: var(--text-dim);
  font-style: italic;
  padding: 0 24px;
  margin-bottom: 0.4em;
}

/* Chapter nav footer */
.chapter-footer {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.btn-chapter {
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background var(--tr), color var(--tr);
}
.btn-chapter:active { background: var(--surface-2); color: var(--text); }
.btn-chapter:disabled { opacity: 0.3; pointer-events: none; }
.btn-chapter.next { color: var(--accent); border-color: var(--accent-strong); }

/* ===== Characters screen ===== */
.char-list {
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.char-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.char-card.center-char {
  border-color: var(--accent-strong);
  background: linear-gradient(135deg, var(--surface) 0%, rgba(184,216,255,0.05) 100%);
}
.char-card.center-char::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(to right, transparent, var(--accent), transparent);
}
.char-name {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 2px;
}
.char-role {
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.char-age {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.char-desc {
  font-size: 14px;
  line-height: 1.75;
  color: var(--text-dim);
  word-break: keep-all;
}

/* ===== Synopsis screen ===== */
.synopsis-body {
  padding: 32px 24px 60px;
}
.synopsis-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.18em;
  margin-bottom: 24px;
}
.synopsis-body p {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 2.1;
  color: var(--text);
  margin-bottom: 1.2em;
  word-break: keep-all;
}

/* ===== Author screen ===== */
.author-body {
  padding: 40px 24px 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.author-avatar {
  width: 80px; height: 80px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  color: var(--text-muted);
}
.author-name {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  text-align: center;
}
.author-bio {
  font-size: 15px;
  line-height: 1.9;
  color: var(--text-dim);
  text-align: center;
  word-break: keep-all;
}

/* ===== Loading ===== */
.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}
.loading-text {
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

/* ===== 퇴고 메모 (관리자 전용) ===== */
.is-admin .annotatable { cursor: pointer; }
.is-admin .annotatable:active { background: rgba(120, 170, 255, 0.10); }

/* 메모가 달린 단락: 좌측 강조선 + ✎ 배지 */
.has-memo {
  position: relative;
  background: rgba(120, 170, 255, 0.08);
  box-shadow: inset 3px 0 0 var(--accent, #6aa0ff);
  border-radius: 2px;
}
.has-memo::after {
  content: '✎';
  position: absolute;
  top: 2px; right: 6px;
  font-size: 12px;
  color: var(--accent, #6aa0ff);
  opacity: 0.85;
}
.has-memo.memo-resolved {
  background: rgba(130, 200, 140, 0.08);
  box-shadow: inset 3px 0 0 #5fbf72;
}
.has-memo.memo-resolved::after { content: '✓'; color: #5fbf72; }

/* 책갈피 (메모와 다른 색 — 호박/골드) */
.has-bookmark {
  position: relative;
  background: rgba(240, 190, 90, 0.12);
  box-shadow: inset 3px 0 0 #f0be5a;
  border-radius: 2px;
}
.has-bookmark::before {
  content: '🔖';
  position: absolute;
  top: 2px; left: -2px;
  font-size: 12px;
}
/* 메모+책갈피 동시: 오른쪽 ✎(메모), 왼쪽 🔖(책갈피) 둘 다 보이도록 */
.has-bookmark.has-memo { box-shadow: inset 3px 0 0 #f0be5a; }

/* 이동 시 잠깐 강조 */
.bookmark-flash {
  animation: bookmarkFlash 1.6s ease-out;
}
@keyframes bookmarkFlash {
  0%, 30% { background: rgba(240, 190, 90, 0.34); }
  100%    { background: rgba(240, 190, 90, 0.12); }
}

/* 헤더 책갈피 버튼: 설정돼 있으면 골드 강조 */
.btn-icon.has-bm { color: #f0be5a; }

/* 모달 */
.memo-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: flex-start; justify-content: center;
  z-index: 1000;
  padding: 0;
}
.memo-box {
  width: 100%;
  max-width: 560px;
  background: var(--surface, #16161d);
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
  padding: calc(20px + env(safe-area-inset-top)) 18px 18px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.memo-quote {
  font-family: var(--serif);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-dim, #b8b8c0);
  border-left: 2px solid var(--accent, #6aa0ff);
  padding: 4px 0 4px 10px;
  margin-bottom: 12px;
  max-height: 4.8em;
  overflow: hidden;
}
.memo-textarea {
  width: 100%;
  min-height: 96px;
  box-sizing: border-box;
  background: var(--surface-2, #1f1f29);
  color: var(--text, #e8e8ee);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 10px;
  padding: 12px;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  resize: vertical;
}
.memo-textarea:focus { outline: none; border-color: var(--accent, #6aa0ff); }
.memo-actions {
  display: flex; gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.memo-btn {
  flex: 1;
  min-width: 64px;
  padding: 12px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: transparent;
  color: var(--text, #e8e8ee);
  font-family: var(--sans);
  font-size: 14px;
  cursor: pointer;
}
.memo-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0d0d14;          /* 밝은 하늘색 accent 위 → 어두운 글씨 (다크 테마) */
  font-weight: 700;
}
.memo-btn.danger { color: #ff7676; border-color: rgba(255, 118, 118, 0.4); }
.memo-btn.bookmark { color: #f0be5a; border-color: rgba(240, 190, 90, 0.45); }

body.light .memo-box { background: #fff; }
body.light .memo-textarea { background: #f4f4f7; color: #1a1a1f; }
body.light .memo-btn.primary { color: #fff; }   /* 진한 파랑 accent 위 → 흰 글씨 (라이트 테마) */

/* ===== Font size helpers ===== */
.fs-sm { --font-size: 15px; }
.fs-md { --font-size: 17px; }
.fs-lg { --font-size: 20px; }

/* ===== PC (넓은 화면) — 읽기 컬럼 확대 + 삽화 크기 제한 =====
   모바일(< 840px)은 이 블록 밖이라 기존 480px 레이아웃 그대로 유지. */
@media (min-width: 840px) {
  #app { max-width: 760px; }
  .chapter-footer { max-width: 760px; }

  /* 텍스트: 좌우 여백 넓혀 읽기 편한 폭 유지 */
  .chapter-content { padding: 0 40px; }
  .inner-monologue { padding: 0 40px; }
  .scene-header { padding: 28px 40px 16px; }
  .timer { padding: 16px 40px; }
  .code-block { margin: 16px 40px; }

  /* 삽화: 컬럼이 넓어져도 과하게 커지지 않게 폭 제한 + 가운데 + 프레임 */
  .illustration {
    max-width: 560px;
    margin: 8px auto 28px;
    border-radius: 10px;
    overflow: hidden;
  }
  .illustration img { max-height: 62vh; }
  .illustration-fallback { max-width: 560px; margin: 0 auto; }
}
