/* ── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg:          #0a0008;
  --surface:     #130011;
  --surface2:    #1c0019;
  --border:      rgba(201,168,76,0.15);
  --gold:        #c9a84c;
  --gold-dim:    rgba(201,168,76,0.55);
  --cream:       #f0e8d5;
  --cream-dim:   rgba(240,232,213,0.72);
  --grey:        rgba(240,232,213,0.38);
  --purple:      #2d0033;
  --purple2:     #3d0044;
  --radius:      12px;
  --font-serif:  'Georgia', 'Times New Roman', serif;
  --font-sans:   system-ui, -apple-system, sans-serif;
  --max-reading: 680px;
}

[data-theme="light"] {
  --bg:        #faf7f2;
  --surface:   #ffffff;
  --surface2:  #f2ece0;
  --border:    rgba(138,95,24,0.18);
  --gold:      #8a5f18;
  --gold-dim:  rgba(138,95,24,0.5);
  --cream:     #1a1008;
  --cream-dim: rgba(26,16,8,0.7);
  --grey:      rgba(26,16,8,0.4);
  --purple:    #f0e8d5;
  --purple2:   #e8dfc8;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--cream);
  min-height: 100vh;
  line-height: 1.6;
}
a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }

/* ── Screen System ─────────────────────────────────────────────────────────── */
.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }

/* ── Password Gate ─────────────────────────────────────────────────────────── */
.gate-screen.active {
  display: flex;
}
.gate-screen {
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: radial-gradient(ellipse at 50% 30%, #1c001a 0%, var(--bg) 70%);
}

.gate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  max-width: 380px;
  width: 100%;
  text-align: center;
}

.gate-dragon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--gold-dim);
  margin-bottom: 1.25rem;
}

.gate-title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  color: var(--gold);
  margin-bottom: 0.3rem;
  font-weight: 400;
  font-style: italic;
}

.gate-sub {
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--grey);
  margin-bottom: 1.75rem;
}

.gate-error {
  display: none;
  color: #e07;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  padding: 0.6rem 0.9rem;
  background: rgba(238,0,119,0.08);
  border-radius: 6px;
}
.gate-error.visible { display: block; }

.gate-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.gate-form input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  color: var(--cream);
  font-size: 1rem;
  outline: none;
  text-align: center;
  letter-spacing: 0.08em;
  transition: border-color 0.2s;
}
.gate-form input:focus { border-color: var(--gold-dim); }
.gate-form input::placeholder { color: var(--grey); letter-spacing: 0.04em; }

.btn-gate {
  background: var(--gold);
  color: #0a0008;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.85rem;
  border-radius: 8px;
  letter-spacing: 0.04em;
  transition: opacity 0.2s;
}
.btn-gate:hover { opacity: 0.88; }

.gate-note {
  margin-top: 1.5rem;
  font-size: 0.8rem;
  color: var(--grey);
}

/* ── Book Nav ──────────────────────────────────────────────────────────────── */
.book-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  height: 54px;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 0.75rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.bn-menu {
  font-size: 1.25rem;
  color: var(--cream-dim);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.18s;
  flex-shrink: 0;
}
.bn-menu:hover { background: var(--surface2); }

.bn-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  flex: 1;
  overflow: hidden;
}

.bn-logo {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--gold-dim);
  flex-shrink: 0;
}

.bn-title span {
  font-family: var(--font-serif);
  font-size: 0.92rem;
  color: var(--gold);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bn-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.edit-badge {
  display: none;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  background: rgba(201,168,76,0.12);
  color: var(--gold);
  border: 1px solid var(--gold-dim);
  border-radius: 20px;
  padding: 0.2rem 0.65rem;
  letter-spacing: 0.04em;
}

.bn-theme {
  font-size: 1.1rem;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--cream-dim);
  transition: background 0.18s;
}
.bn-theme:hover { background: var(--surface2); }

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.book-sidebar {
  position: fixed;
  top: 0; left: -300px;
  width: 285px;
  height: 100vh;
  z-index: 200;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: left 0.28s cubic-bezier(0.4,0,0.2,1);
  overflow: hidden;
}
.book-sidebar.open { left: 0; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 190;
  background: rgba(0,0,0,0.55);
}
.sidebar-overlay.visible { display: block; }

.sidebar-header {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--grey);
  flex-shrink: 0;
}

.sidebar-close {
  color: var(--grey);
  font-size: 1rem;
  padding: 0.3rem;
  border-radius: 4px;
  transition: color 0.18s;
}
.sidebar-close:hover { color: var(--cream); }

.sidebar-toc {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0;
}

.toc-part {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-dim);
  padding: 1rem 1.1rem 0.35rem;
  font-weight: 600;
}

.toc-chapter {
  padding: 0.65rem 1.1rem;
  font-size: 0.88rem;
  color: var(--cream-dim);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all 0.18s;
  line-height: 1.4;
}
.toc-chapter:hover { background: var(--surface2); color: var(--cream); border-left-color: var(--gold-dim); }
.toc-chapter.done { color: var(--cream); }
.toc-chapter.done::after { content: ' ✓'; color: var(--gold-dim); font-size: 0.75rem; }

/* ── Reader Layout ─────────────────────────────────────────────────────────── */
#screen-reader {
  padding-top: 54px;
}

/* ── Book Cover ────────────────────────────────────────────────────────────── */
.book-cover {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: calc(100vh - 54px);
  padding: 3rem 1.5rem 4rem;
  background: radial-gradient(ellipse at 50% 20%, #1c001a 0%, var(--bg) 65%);
}

.cover-dragon-img {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--gold-dim);
  margin-bottom: 2rem;
}

.cover-title {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 400;
  font-style: italic;
  color: var(--gold);
  line-height: 1.2;
  margin-bottom: 0.75rem;
  max-width: 560px;
}

.cover-subtitle {
  font-size: 1rem;
  color: var(--cream-dim);
  margin-bottom: 0.5rem;
  max-width: 440px;
}

.cover-author {
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--grey);
  margin-bottom: 2.5rem;
}

.cover-tagline {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: var(--cream-dim);
  font-style: italic;
  max-width: 460px;
  line-height: 1.7;
  margin-bottom: 2.5rem;
  padding: 0 1rem;
}

.btn-start-reading {
  background: var(--gold);
  color: #0a0008;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.9rem 2rem;
  border-radius: 50px;
  letter-spacing: 0.04em;
  transition: opacity 0.2s, transform 0.2s;
  margin-bottom: 2.5rem;
}
.btn-start-reading:hover { opacity: 0.88; transform: translateY(-1px); }

.cover-url {
  font-size: 0.78rem;
  color: var(--grey);
}

/* ── Chapter View ──────────────────────────────────────────────────────────── */
.chapter-view {
  min-height: calc(100vh - 54px);
}

.chapter-inner {
  max-width: var(--max-reading);
  margin: 0 auto;
  padding: 3rem 1.5rem 5rem;
}

.chapter-part {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-dim);
  margin-bottom: 1rem;
  font-weight: 600;
}

.chapter-title {
  font-family: var(--font-serif);
  font-size: clamp(1.6rem, 5vw, 2.25rem);
  font-weight: 400;
  font-style: italic;
  color: var(--gold);
  line-height: 1.25;
  margin-bottom: 0.6rem;
}

.chapter-subtitle {
  font-size: 0.98rem;
  color: var(--cream-dim);
  margin-bottom: 0;
}

.chapter-divider {
  width: 3rem;
  height: 1px;
  background: var(--gold-dim);
  margin: 2rem 0;
}

.chapter-body {
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.chapter-para {
  font-size: 1.05rem;
  line-height: 1.85;
  color: var(--cream);
}

.chapter-bold {
  font-weight: 600;
  color: var(--gold);
}

.chapter-subheading {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-style: italic;
  font-weight: 400;
  color: var(--gold);
  margin-top: 0.5rem;
}

.chapter-quote {
  border-left: 3px solid var(--gold);
  padding: 1rem 1.25rem;
  margin: 0.75rem 0;
  font-family: var(--font-serif);
  font-size: 1.18rem;
  font-style: italic;
  color: var(--gold);
  line-height: 1.65;
  background: rgba(201,168,76,0.05);
  border-radius: 0 8px 8px 0;
}

/* ── Exercise Block ────────────────────────────────────────────────────────── */
.exercise-block {
  margin-top: 2.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.exercise-label {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.exercise-prompt {
  font-size: 1rem;
  color: var(--cream);
  line-height: 1.7;
  margin-bottom: 1rem;
  font-style: italic;
}

.exercise-textarea {
  width: 100%;
  min-height: 150px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  color: var(--cream);
  font-size: 0.95rem;
  line-height: 1.7;
  font-family: var(--font-sans);
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}
.exercise-textarea:focus { border-color: var(--gold-dim); }
.exercise-textarea::placeholder { color: var(--grey); }

.exercise-saved {
  font-size: 0.75rem;
  color: var(--gold-dim);
  margin-top: 0.5rem;
  height: 1rem;
  opacity: 0;
  transition: opacity 0.3s;
}
.exercise-saved.show { opacity: 1; }

/* ── Progress Bar ──────────────────────────────────────────────────────────── */
.reading-progress {
  --prog: 0%;
  height: 2px;
  background: linear-gradient(to right, var(--gold) var(--prog), var(--border) var(--prog));
  margin: 0;
}

/* ── Chapter Navigation ────────────────────────────────────────────────────── */
.chapter-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 2rem;
  max-width: var(--max-reading);
  margin: 0 auto;
  border-top: 1px solid var(--border);
}

.cpn-btn {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: 38%;
  background: none;
  padding: 0.75rem 0.5rem;
}
.cpn-btn:disabled { opacity: 0.3; pointer-events: none; }
.cpn-right { text-align: right; }

.cpn-dir {
  display: block;
  font-size: 0.75rem;
  color: var(--grey);
  letter-spacing: 0.06em;
}

.cpn-name {
  display: block;
  font-size: 0.88rem;
  color: var(--cream-dim);
  line-height: 1.35;
}

.cpn-counter {
  font-size: 0.78rem;
  color: var(--grey);
  letter-spacing: 0.08em;
}

/* ── Inline Editing ────────────────────────────────────────────────────────── */
.editable {
  cursor: text;
  border-radius: 4px;
  outline: none;
  min-width: 1ch;
  transition: background 0.15s, box-shadow 0.15s;
}
.editable:hover {
  background: rgba(201,168,76,0.06);
  box-shadow: 0 0 0 1px rgba(201,168,76,0.2);
}
.editable:focus {
  background: rgba(201,168,76,0.1);
  box-shadow: 0 0 0 1.5px rgba(201,168,76,0.45);
}

.edit-hint {
  font-size: 0.78rem;
  color: var(--gold-dim);
  background: rgba(201,168,76,0.06);
  border: 1px solid rgba(201,168,76,0.15);
  border-radius: 6px;
  padding: 0.5rem 0.85rem;
  margin-bottom: 1.5rem;
  letter-spacing: 0.02em;
}

.edit-reset {
  display: inline-block;
  margin-top: 2rem;
  font-size: 0.78rem;
  color: var(--grey);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.9rem;
  transition: color 0.18s, border-color 0.18s;
}
.edit-reset:hover { color: var(--cream); border-color: var(--gold-dim); }

/* ── Welcome Overlay ────────────────────────────────────────────────────────── */
.welcome-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0,0,0,0.75);
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  backdrop-filter: blur(6px);
}
.welcome-overlay.open { display: flex; }
.welcome-card {
  background: linear-gradient(160deg, #1a0a28 0%, #100020 100%);
  border: 1px solid rgba(201,168,76,0.3);
  border-radius: 18px;
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 420px;
  text-align: center;
  animation: slideUp 0.35s ease;
}
.welcome-logo img {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  margin-bottom: 1rem;
  opacity: 0.85;
}
.welcome-label {
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-dim, #c9a84c99);
  margin-bottom: 0.5rem;
}
.welcome-title {
  font-family: var(--font-serif, Georgia, serif);
  font-size: 1.35rem;
  color: var(--cream, #f5f0e8);
  margin: 0 0 0.6rem;
}
.welcome-sub {
  font-size: 0.88rem;
  color: var(--cream-dim, rgba(245,240,232,0.6));
  line-height: 1.6;
  margin: 0 0 1.4rem;
}
.welcome-form {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.welcome-input {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(201,168,76,0.3);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  font-size: 0.95rem;
  color: var(--cream, #f5f0e8);
  outline: none;
  transition: border-color 0.18s;
  width: 100%;
  box-sizing: border-box;
}
.welcome-input::placeholder { color: var(--cream-dim, rgba(245,240,232,0.45)); }
.welcome-input:focus { border-color: #c9a84c; }
.welcome-btn {
  background: #c9a84c;
  border: none;
  border-radius: 10px;
  padding: 0.85rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #0a0008;
  cursor: pointer;
  transition: opacity 0.18s;
}
.welcome-btn:hover { opacity: 0.85; }
.welcome-skip {
  background: none;
  border: none;
  color: var(--cream-dim, rgba(245,240,232,0.45));
  font-size: 0.78rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0.2rem;
}

/* ── Chapter Notes ─────────────────────────────────────────────────────────── */
.chapter-notes-section { margin: 2rem 0 0; padding-top: 1.5rem; border-top: 1px solid var(--gold-dim); }
.chapter-notes-label { font-size: 0.68rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold); margin-bottom: 0.65rem; }
.chapter-notes-textarea {
  width: 100%; min-height: 100px; padding: 0.85rem; box-sizing: border-box;
  background: rgba(30,16,48,0.4); border: 1px solid var(--gold-dim);
  border-radius: 10px; color: var(--cream); font-family: inherit;
  font-size: 0.9rem; line-height: 1.6; resize: vertical; transition: border-color 0.2s;
}
.chapter-notes-textarea:focus { outline: none; border-color: var(--gold); }
.chapter-notes-save { padding: 0.45rem 1.1rem; background: rgba(201,168,76,0.15); border: 1px solid var(--gold-dim); border-radius: 8px; color: var(--gold); font-size: 0.78rem; font-weight: 600; cursor: pointer; transition: all 0.18s; }
.chapter-notes-save:hover { background: rgba(201,168,76,0.3); }
.chapter-notes-saved { font-size: 0.72rem; color: var(--cream-dim); margin-left: 0.75rem; opacity: 0; transition: opacity 0.3s; }
.chapter-notes-saved.visible { opacity: 1; }

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold-dim); }

/* ── Mobile ────────────────────────────────────────────────────────────────── */
@media (max-width: 500px) {
  .chapter-inner { padding: 2rem 1.1rem 4rem; }
  .chapter-title { font-size: 1.55rem; }
  .chapter-para { font-size: 1rem; }
  .chapter-quote { font-size: 1.05rem; }
  .gate-card { padding: 2rem 1.25rem; }
}
