/* ============================================================
   Schopenhauer · Vierfache Wurzel — Stylesheet
   F.R.Granaria AC · schopenhauer.granaria · 2026
   ============================================================ */

/* ── DARK THEME (default) ─────────────────────────────── */
:root, [data-theme="dark"] {
  --gold:        #C9A84C;
  --gold-light:  #E8C870;
  --gold-dim:    #8B6B2A;
  --bg:          #0D0D18;
  --bg-2:        #13131F;
  --bg-3:        #1A1A2E;
  --bg-4:        #242438;
  --mid:         #2E2E4A;
  --text:        #E8E4D8;
  --text-dim:    #9E9A8E;
  --text-faint:  #5A5660;
  --border:      rgba(201,168,76,0.18);
  --border-mid:  rgba(201,168,76,0.35);
  --shadow:      0 4px 32px rgba(0,0,0,0.5);
  --shadow-gold: 0 0 40px rgba(201,168,76,0.12);
  --grain-op:    0.03;
  --font-serif:  'Playfair Display', Georgia, serif;
  --font-body:   'Crimson Text', Georgia, serif;
  --font-mono:   'Space Mono', monospace;
  --radius:      8px;
}

/* ── LIGHT THEME ──────────────────────────────────────── */
[data-theme="light"] {
  --gold:        #9B6E1A;
  --gold-light:  #7A5214;
  --gold-dim:    #C9940A;
  --bg:          #FAF8F5;
  --bg-2:        #F2EEE8;
  --bg-3:        #EAE4DC;
  --bg-4:        #E0D8CE;
  --mid:         #CCC4B6;
  --text:        #1A1A2E;
  --text-dim:    #4A4438;
  --text-faint:  #9A9086;
  --border:      rgba(155,110,26,0.22);
  --border-mid:  rgba(155,110,26,0.45);
  --shadow:      0 4px 24px rgba(0,0,0,0.12);
  --shadow-gold: 0 0 30px rgba(155,110,26,0.1);
  --grain-op:    0.015;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 19px;
  line-height: 1.82;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.3s, color 0.3s;
}

/* ── GRAIN ────────────────────────────────────────────── */
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 999;
  opacity: var(--grain-op);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
}

/* ── PROGRESS BAR ─────────────────────────────────────── */
#readProgress {
  position: fixed; top: 0; left: 0; height: 2px;
  background: linear-gradient(to right, var(--gold-dim), var(--gold));
  z-index: 300; width: 0%; transition: width 0.1s; pointer-events: none;
}

/* ── NAV ──────────────────────────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 200;
  display: flex; align-items: center; gap: 1rem;
  padding: 0.75rem 2rem;
  background: rgba(13,13,24,0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  transition: background 0.3s;
}
[data-theme="light"] .nav { background: rgba(250,248,245,0.94); }

.nav-brand { display: flex; align-items: baseline; gap: 0.6rem; text-decoration: none; flex-shrink: 0; }
.nav-logo  { font-family: var(--font-serif); font-size: 1.5rem; color: var(--gold); font-weight: 700; line-height: 1; }
.nav-title { font-family: var(--font-serif); font-size: 1rem; color: var(--text); font-weight: 600; letter-spacing: 0.02em; }
.nav-sub   { font-family: var(--font-mono); font-size: 0.58rem; color: var(--text-faint); letter-spacing: 0.08em; }

.nav-links { display: flex; align-items: center; gap: 0.2rem; margin-left: auto; }
.nav-link {
  padding: 0.35rem 0.75rem; border-radius: 6px;
  color: var(--text-dim); text-decoration: none;
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.04em;
  transition: all 0.2s; border: 1px solid transparent; white-space: nowrap;
}
.nav-link:hover { color: var(--gold); border-color: var(--border); }
.nav-link.active { color: var(--gold); background: rgba(201,168,76,0.08); border-color: var(--border); }

.theme-toggle {
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 6px; color: var(--gold);
  padding: 0.3rem 0.55rem; cursor: pointer; font-size: 0.9rem; transition: all 0.2s;
}
.theme-toggle:hover { border-color: var(--border-mid); }
.nav-toggle { display: none; background: none; border: 1px solid var(--border); color: var(--text-dim); padding: 0.3rem 0.65rem; border-radius: 6px; cursor: pointer; font-size: 1rem; }

.mobile-menu { display: none; flex-direction: column; background: var(--bg-2); border-bottom: 1px solid var(--border); padding: 1rem 2rem; }
.mobile-menu a { padding: 0.55rem 0; color: var(--text-dim); text-decoration: none; font-family: var(--font-mono); font-size: 0.82rem; border-bottom: 1px solid var(--border); }
.mobile-menu.open { display: flex; }
@media (max-width: 900px) { .nav-links { display: none; } .nav-toggle { display: block; } }
@media (max-width: 600px) { .nav { padding: 0.7rem 1rem; } .nav-sub { display: none; } }

/* ── HERO ─────────────────────────────────────────────── */
.hero {
  padding: 5rem 2rem 4rem;
  text-align: center;
  background: radial-gradient(ellipse at 50% 0%, rgba(201,168,76,0.08) 0%, transparent 70%);
  border-bottom: 1px solid var(--border);
  position: relative;
}
.hero::after {
  content: '';
  position: absolute; bottom: -1px; left: 0; right: 0; height: 1px;
  background: linear-gradient(to right, transparent, var(--gold), transparent);
}
.hero-label {
  font-family: var(--font-mono); font-size: 0.68rem;
  letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--gold-dim); margin-bottom: 1.5rem;
}
.hero h1 {
  font-family: var(--font-serif); font-weight: 700;
  font-size: clamp(1.8rem, 4.5vw, 3rem);
  color: var(--text); line-height: 1.25; margin-bottom: 0.6rem;
  text-shadow: var(--shadow-gold);
}
.hero h2 {
  font-family: var(--font-serif); font-weight: 400; font-style: italic;
  font-size: 1.15rem; color: var(--text-dim); margin-bottom: 2rem;
}
.hero-meta {
  font-family: var(--font-mono); font-size: 0.68rem;
  color: var(--text-faint); letter-spacing: 0.04em;
}
.hero-meta span { color: var(--gold-dim); margin: 0 0.4rem; }

/* ── TOC BAR ──────────────────────────────────────────── */
.toc-bar {
  background: var(--bg-2); border-bottom: 1px solid var(--border);
  padding: 0.6rem 2rem; overflow-x: auto; white-space: nowrap;
  display: flex; gap: 0.2rem;
}
.toc-bar a {
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.04em;
  color: var(--text-faint); text-decoration: none;
  padding: 0.25rem 0.7rem; border-radius: 4px; border: 1px solid transparent;
  transition: all 0.2s;
}
.toc-bar a:hover { color: var(--gold); border-color: var(--border); }

/* ── LAYOUT ───────────────────────────────────────────── */
.main { min-height: calc(100vh - 120px); }
.content { max-width: 780px; margin: 0 auto; padding: 3rem 2rem 6rem; }

/* ── CHAPTER ──────────────────────────────────────────── */
.chapter { margin-top: 4.5rem; }

.chapter-label {
  font-family: var(--font-mono); font-size: 0.62rem;
  letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--gold-dim); margin-bottom: 0.8rem;
  display: flex; align-items: center; gap: 0.8rem;
}
.chapter-label::after {
  content: ''; flex: 1; height: 1px;
  background: linear-gradient(to right, var(--gold-dim), transparent);
  opacity: 0.4;
}

.chapter h2 {
  font-family: var(--font-serif); font-size: 1.7rem; font-weight: 600;
  color: var(--text); margin-bottom: 2rem; line-height: 1.3;
}

/* ── PARAGRAPHS ───────────────────────────────────────── */
.para { margin-top: 2.5rem; }

.para-head {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.06em;
  color: var(--text-faint); margin-bottom: 0.6rem;
  display: flex; align-items: center; gap: 0.6rem;
}
.para-head strong { color: var(--gold); font-weight: 700; }
.para-head::after {
  content: ''; flex: 1; height: 1px; background: var(--border); opacity: 0.5;
}

.para p { margin-bottom: 1.1rem; text-align: justify; color: var(--text); }
.para p:last-child { margin-bottom: 0; }

/* ── THEOREM BOX ──────────────────────────────────────── */
.theorem {
  margin: 2rem 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1.5rem 1.8rem;
  box-shadow: var(--shadow);
}
.theorem-title {
  font-family: var(--font-mono); font-size: 0.65rem; letter-spacing: 0.15em;
  text-transform: uppercase; color: var(--gold); margin-bottom: 1rem;
}
.theorem-body { font-family: var(--font-body); color: var(--text); line-height: 1.9; }
.theorem-body strong { color: var(--gold-light); }
.theorem-body em { color: var(--text-dim); font-style: italic; }
.theorem code {
  font-family: var(--font-mono); font-size: 0.85em;
  color: var(--gold); background: rgba(201,168,76,0.08);
  padding: 0.1em 0.4em; border-radius: 3px;
}

/* ── BLOCKQUOTE ───────────────────────────────────────── */
blockquote {
  margin: 1.8rem 0;
  padding: 1rem 1.6rem;
  background: var(--bg-3);
  border-left: 2px solid var(--gold-dim);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-dim);
  font-style: italic;
}
blockquote em { color: var(--text-faint); }

/* ── STUB ─────────────────────────────────────────────── */
.stub {
  margin: 2rem 0; padding: 1.4rem 1.6rem;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono); font-size: 0.75rem;
  color: var(--text-faint); line-height: 1.7;
}
.stub a { color: var(--gold); text-decoration: none; }
.stub a:hover { color: var(--gold-light); }

/* ── PARTITION GRID ───────────────────────────────────── */
.partition { margin: 2rem 0; display: grid; gap: 1px; background: var(--border); border-radius: var(--radius); overflow: hidden; }
.partition-row {
  display: grid; grid-template-columns: 2rem 1fr 1fr;
  gap: 0; background: var(--bg-2);
  transition: background 0.2s;
}
.partition-row:hover { background: var(--bg-3); }
.partition-cell {
  padding: 0.9rem 1.2rem;
  border-right: 1px solid var(--border);
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-dim);
}
.partition-cell:last-child { border-right: none; }
.partition-cell.idx { color: var(--gold); font-weight: 700; text-align: center; }
.partition-cell.name { color: var(--text); font-weight: 600; }
.partition-header .partition-cell { color: var(--gold-dim); letter-spacing: 0.1em; text-transform: uppercase; font-size: 0.62rem; background: var(--bg-3); }

/* ── LATIN ────────────────────────────────────────────── */
em.lat { color: var(--text-dim); font-style: italic; }

/* ── OL/UL ────────────────────────────────────────────── */
.para ol, .para ul { padding-left: 1.5rem; margin: 1rem 0 1rem; color: var(--text); }
.para li { margin-bottom: 0.6rem; }
.para li strong { color: var(--gold-light); }
.para li em.lat { font-size: 0.9em; }

/* ── FOOTER ───────────────────────────────────────────── */
footer {
  border-top: 1px solid var(--border);
  padding: 1rem 2rem; background: var(--bg-2);
}
.footer-inner {
  display: flex; flex-wrap: wrap; gap: 0.4rem 0.8rem; align-items: center;
  font-family: var(--font-mono); font-size: 0.66rem;
  color: var(--text-faint); letter-spacing: 0.04em;
  max-width: 780px; margin: 0 auto;
}
.footer-inner span.brand { color: var(--gold-dim); }
.footer-sep { color: var(--gold-dim); opacity: 0.5; }
.footer-inner a { color: var(--text-faint); text-decoration: none; transition: color 0.2s; }
.footer-inner a:hover { color: var(--gold); }

@media (max-width: 600px) {
  .content { padding: 2rem 1.2rem 4rem; }
  .hero { padding: 3rem 1.2rem 2.5rem; }
  .hero h1 { font-size: 1.7rem; }
  .toc-bar { padding: 0.5rem 1rem; }
}
