/* ============================================
   The Great Secret of Life — online reader
   ============================================ */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

:root {
  --bg: #f9f6ef;
  --bg-alt: #fdfaf3;
  --bg-soft: #f0eadd;
  --text: #0f1e3a;
  --text-soft: #4a5366;
  --text-mute: #8a8f9e;
  --accent: #b88a3f;
  --accent-dark: #8d6929;
  --border: #e8e2d3;
  --error: #b6451d;
  --serif: 'EB Garamond', 'Garamond', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

body.dark {
  --bg: #15171f;
  --bg-alt: #1c1f29;
  --bg-soft: #232733;
  --text: #ece6d6;
  --text-soft: #a8aebe;
  --text-mute: #6a7280;
  --accent: #d4a050;
  --accent-dark: #b88a3f;
  --border: #2a3040;
  --error: #d97a4a;
}

body {
  font-family: var(--serif);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background 0.3s ease, color 0.3s ease;
  min-height: 100vh;
}

a {
  color: var(--accent-dark);
}

/* ============================================
   GATE (license key entry)
   ============================================ */

.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: var(--bg);
}

.gate-card {
  max-width: 460px;
  width: 100%;
  text-align: center;
}

.gate-card .kicker {
  font-family: var(--sans);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--accent-dark);
  font-weight: 500;
  margin: 0 0 18px;
}

.gate-card h1 {
  font-size: clamp(32px, 5vw, 40px);
  font-weight: 500;
  margin: 0 0 14px;
  font-family: var(--serif);
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.gate-card .subtitle {
  color: var(--text-soft);
  margin: 0 0 32px;
  font-size: 17px;
  font-style: italic;
}

.gate-card form {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
  flex-direction: column;
}

.gate-card input {
  padding: 14px 16px;
  font-size: 14px;
  font-family: var(--sans);
  font-weight: 500;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  background: var(--bg-alt);
  color: var(--text);
  letter-spacing: 0.06em;
  text-align: center;
  width: 100%;
}
.gate-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.gate-card button {
  padding: 14px 24px;
  font-size: 13px;
  font-family: var(--sans);
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s ease;
}
.gate-card button:hover:not(:disabled) {
  background: var(--accent-dark);
}
.gate-card button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.gate-error {
  color: var(--error);
  font-size: 14px;
  font-style: italic;
  min-height: 1.5em;
  margin: 8px 0 16px;
}

.gate-help, .gate-back {
  font-size: 14px;
  color: var(--text-soft);
  margin: 8px 0;
  line-height: 1.5;
}

/* ============================================
   READER
   ============================================ */

.reader {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */
.reader-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.reader-title {
  font-size: 17px;
  font-weight: 500;
  font-family: var(--serif);
  margin: 0;
  color: var(--text);
  font-style: italic;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.15s ease;
}
.icon-btn:hover { background: var(--bg-soft); }

.reader-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pdf-download {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-dark);
  text-decoration: none;
  padding: 8px 14px;
  border: 1px solid var(--accent-dark);
  border-radius: 3px;
  transition: all 0.2s ease;
}
.pdf-download:hover {
  background: var(--accent-dark);
  color: var(--bg);
}

/* --- Body layout --- */
.reader-body {
  flex: 1;
  display: flex;
  position: relative;
}

.sidebar-overlay {
  display: none;
}

/* --- Sidebar --- */
.reader-sidebar {
  width: 280px;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  padding: 28px 20px;
  flex-shrink: 0;
  position: sticky;
  top: 57px;
  align-self: flex-start;
  max-height: calc(100vh - 57px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-label {
  font-family: var(--sans);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--text-mute);
  font-weight: 600;
  margin: 0 0 18px;
  padding-left: 12px;
}

.reader-sidebar ol {
  list-style: none;
  padding: 0;
  margin: 0 0 32px;
}
.reader-sidebar li {
  margin: 0;
}
.reader-sidebar a {
  display: block;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--text-soft);
  font-size: 15px;
  font-family: var(--serif);
  border-radius: 4px;
  line-height: 1.35;
  transition: background 0.15s ease, color 0.15s ease;
}
.reader-sidebar a:hover {
  background: var(--bg-soft);
  color: var(--text);
}
.reader-sidebar a.active {
  background: var(--text);
  color: var(--bg);
  font-weight: 500;
}
body.dark .reader-sidebar a.active {
  background: var(--accent);
  color: var(--bg);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.signout-btn {
  background: none;
  border: none;
  color: var(--text-mute);
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 8px 12px;
  width: 100%;
  text-align: left;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.signout-btn:hover {
  color: var(--text);
  background: var(--bg-soft);
}

/* --- Content --- */
.reader-content {
  flex: 1;
  padding: 72px 80px 64px;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  min-width: 0;
}

.reader-content h1 {
  font-family: var(--sans);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  color: var(--text-mute);
  text-align: center;
  font-weight: 600;
  margin: 0 0 10px;
}
.reader-content h2 {
  font-family: var(--serif);
  font-size: clamp(28px, 4vw, 38px);
  font-weight: 500;
  text-align: center;
  margin: 0 0 56px;
  letter-spacing: -0.01em;
  font-style: italic;
  line-height: 1.2;
}
.reader-content h3 {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  margin: 48px 0 14px;
  line-height: 1.3;
}
.reader-content p {
  font-size: 19px;
  line-height: 1.72;
  margin: 0 0 22px;
  text-align: left;
}
.reader-content > p:first-of-type {
  font-size: 21px;
}
.reader-content hr {
  border: none;
  text-align: center;
  margin: 36px 0;
}
.reader-content hr::after {
  content: '· · ·';
  letter-spacing: 0.7em;
  color: var(--text-mute);
  font-size: 14px;
}
.reader-content ul, .reader-content ol {
  font-size: 19px;
  line-height: 1.65;
  padding-left: 28px;
  margin: 14px 0 24px;
}
.reader-content li {
  margin: 10px 0;
}
.reader-content li p { margin: 8px 0; }
.reader-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 28px 0;
  padding: 4px 0 4px 24px;
  font-style: italic;
  color: var(--text-soft);
}
.reader-content blockquote p {
  font-size: 19px;
  margin: 0;
}
.reader-content strong {
  font-weight: 700;
  color: var(--text);
}
.reader-content em {
  font-style: italic;
}
.reader-content a {
  color: var(--accent-dark);
}

/* --- Chapter nav --- */
.chapter-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 80px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
  gap: 16px;
}
.nav-btn {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: none;
  border: 1.5px solid var(--text);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.nav-btn:hover:not(:disabled) {
  background: var(--text);
  color: var(--bg);
}
.nav-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}
.progress {
  font-family: var(--sans);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-mute);
  font-weight: 500;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 900px) {
  .reader-header {
    padding: 12px 16px;
  }
  .reader-title {
    font-size: 15px;
  }
  .reader-sidebar {
    position: fixed;
    top: 53px;
    left: 0;
    height: calc(100vh - 53px);
    width: 280px;
    max-width: 85vw;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.12);
  }
  .reader-sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    display: block;
    position: fixed;
    top: 53px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 30, 58, 0.4);
    z-index: 15;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }
  body.sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }
  .reader-content {
    padding: 40px 24px 56px;
  }
  .reader-content p {
    font-size: 18px;
  }
  .reader-content > p:first-of-type {
    font-size: 19px;
  }
  .reader-content h2 {
    font-size: 26px;
    margin-bottom: 40px;
  }
  .reader-content h3 {
    font-size: 20px;
    margin-top: 36px;
  }
  .nav-btn {
    padding: 10px 12px;
    font-size: 11px;
  }
}
@media (min-width: 901px) {
  .menu-toggle {
    display: none;
  }
}
