/* style.css — all styling */

/* ---------- Theme tokens ---------- */
:root {
  --bg-deep: #0c0e1a;
  --bg-soft: #141527;
  --parchment: #ece0c6;
  --parchment-dim: #c9bda1;
  --ink: #f3ead4;
  --ink-dim: #b8ae95;
  --ink-faint: #847a64;
  --gold: #d4a84b;
  --gold-bright: #f0cf7a;
  --gold-deep: #8a6a3a;
  --bronze: #a07a3e;
  --blood: #8a2a2a;
  --blood-deep: #5a1818;
  --dawn: #6a8ab0;
  --veil: #1a1d33;
  --rule: rgba(212, 168, 75, 0.22);
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --hebrew: 'Times New Roman', 'Ezra SIL', Georgia, serif;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg-deep: #f4ecda;
  --bg-soft: #ece0c6;
  --parchment: #fdf7e8;
  --parchment-dim: #d9cca8;
  --ink: #2a2418;
  --ink-dim: #5a4f38;
  --ink-faint: #8a7d60;
  --gold: #8a6a2a;
  --gold-bright: #b8902e;
  --gold-deep: #5a4220;
  --bronze: #6a4e22;
  --blood: #7a2a2a;
  --blood-deep: #5a1818;
  --dawn: #4a6a8a;
  --veil: #d9cca8;
  --rule: rgba(90, 66, 32, 0.25);
  --shadow: 0 24px 60px rgba(60, 40, 10, 0.18);
  color-scheme: light;
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg-deep);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  touch-action: manipulation;
  overflow-x: hidden;
}

#scroll-root {
  position: relative;
  width: 100%;
  min-height: 100%;
}

/* ---------- Texture overlay ---------- */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(212, 168, 75, 0.08), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(106, 138, 176, 0.07), transparent 50%);
  mix-blend-mode: screen;
}
html[data-theme="light"] body::before { mix-blend-mode: multiply; opacity: 0.6; }

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  opacity: 0.35;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.1  0 0 0 0 0.08  0 0 0 0 0.05  0 0 0 0.5 0'/></filter><rect width='200' height='200' filter='url(%23n)' opacity='0.4'/></svg>");
  mix-blend-mode: overlay;
}

#scroll-root > * { position: relative; z-index: 3; }

/* ---------- HERO ---------- */
.hero {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8vh 6vw 6vh;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.hero-glow {
  position: absolute;
  width: 120vw;
  height: 120vw;
  max-width: 900px;
  max-height: 900px;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(212, 168, 75, 0.14), transparent 60%);
  filter: blur(20px);
  pointer-events: none;
}
.hero-grain {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 30% 40%, rgba(106, 138, 176, 0.1), transparent 40%),
    radial-gradient(circle at 70% 70%, rgba(138, 42, 42, 0.08), transparent 45%);
  pointer-events: none;
}
.hero-content { position: relative; z-index: 2; max-width: 720px; }

.eyebrow {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 1.6rem;
  font-weight: 500;
}
.title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(2.6rem, 9vw, 5.2rem);
  line-height: 1.02;
  margin: 0 0 1rem;
  color: var(--ink);
  letter-spacing: 0.01em;
  text-shadow: 0 2px 30px rgba(0,0,0,0.5), 0 0 1px rgba(212,168,75,0.3);
}
html[data-theme="light"] .title { text-shadow: 0 2px 12px rgba(90,66,32,0.15); }
.subtitle {
  font-style: italic;
  font-size: clamp(1rem, 3.6vw, 1.3rem);
  color: var(--ink-dim);
  margin: 0 0 3rem;
  letter-spacing: 0.04em;
}

/* ---------- Gate ---------- */
.gate-stage {
  position: relative;
  width: min(280px, 70vw);
  cursor: pointer;
  user-select: none;
  margin: 0 auto;
  outline: none;
}
.gate-svg { width: 100%; height: auto; display: block; filter: drop-shadow(0 12px 30px rgba(0,0,0,0.5)); }
.gate-door {
  transform-origin: 120px 60px;
  transform-box: fill-box;
  transition: transform 1.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.gate-door-left { transform-origin: left center; transform-box: view-box; }
.gate-door-right { transform-origin: right center; transform-box: view-box; }
.gate-door-left.open { transform: rotateY(70deg); transform-origin: 40px 170px; }
.gate-door-right.open { transform: rotateY(-70deg); transform-origin: 200px 170px; }
.gate-light { opacity: 0; transition: opacity 1.6s ease 0.4s; }
.gate-light.shown { opacity: 1; }

.gate-hint {
  font-family: var(--sans);
  font-size: 0.74rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 1.4rem 0 0;
  transition: opacity 0.4s;
}

.scroll-cue {
  position: absolute;
  bottom: 2.4rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
}
.scroll-cue span {
  display: block;
  width: 1px;
  height: 36px;
  background: linear-gradient(to bottom, transparent, var(--gold));
  animation: cuePulse 2.4s ease-in-out infinite;
}
@keyframes cuePulse {
  0%, 100% { opacity: 0.2; transform: scaleY(0.6); transform-origin: top; }
  50% { opacity: 1; transform: scaleY(1); }
}

/* ---------- Chapters ---------- */
.chapter {
  max-width: 720px;
  margin: 0 auto;
  padding: 12vh 6vw;
  opacity: 0;
  transform: translateY(40px);
  transition: opacity 1.1s ease, transform 1.1s cubic-bezier(0.16, 1, 0.3, 1);
}
.chapter.in { opacity: 1; transform: none; }

.chapter-num {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  letter-spacing: 0.5em;
  color: var(--gold);
  text-transform: uppercase;
  margin: 0 0 1.4rem;
  opacity: 0.85;
}
.chapter-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(1.9rem, 6vw, 3rem);
  line-height: 1.1;
  margin: 0 0 2.6rem;
  color: var(--ink);
  letter-spacing: 0.005em;
}
.chapter-body p {
  margin: 0 0 1.4rem;
  color: var(--ink);
}
.chapter-body .lede {
  font-size: 1.18rem;
  font-style: italic;
  color: var(--gold-bright);
  margin-bottom: 1.8rem;
}
html[data-theme="light"] .chapter-body .lede { color: var(--gold-deep); }
.chapter-body em { color: var(--gold-bright); font-style: italic; }
html[data-theme="light"] .chapter-body em { color: var(--bronze); }
.chapter-body strong { color: var(--ink); font-weight: 700; letter-spacing: 0.01em; }
.hebrew {
  font-family: var(--hebrew);
  direction: rtl;
  font-size: 1.05em;
  color: var(--gold);
}

/* ---------- Scripture block ---------- */
.scripture {
  position: relative;
  margin: 2.4rem 0;
  padding: 1.8rem 1.6rem 1.4rem;
  border-left: 2px solid var(--gold);
  background: linear-gradient(90deg, rgba(212, 168, 75, 0.06), transparent 60%);
  font-style: italic;
}
.scripture p {
  margin: 0 0 1rem;
  font-size: 1.08rem;
  color: var(--ink);
}
.scripture.big p { font-size: 1.24rem; line-height: 1.6; }
.ref {
  display: inline-block;
  font-family: var(--sans);
  font-style: normal;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  background: rgba(212, 168, 75, 0.12);
  border: 1px solid var(--rule);
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, color 0.2s;
}
.ref:hover, .ref:focus-visible {
  background: var(--gold);
  color: var(--bg-deep);
  transform: translateY(-1px);
  outline: none;
}

/* ---------- Aside (hidden insight) ---------- */
.aside {
  position: relative;
  margin: 2rem 0;
  padding: 1.2rem 1.4rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: rgba(20, 21, 39, 0.5);
  transition: background 0.4s, border-color 0.4s;
}
html[data-theme="light"] .aside { background: rgba(253, 247, 232, 0.6); }
.aside-mark {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
  cursor: pointer;
  margin-bottom: 0.6rem;
  user-select: none;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  transition: all 0.2s;
}
.aside-mark:hover { background: var(--gold); color: var(--bg-deep); }
.aside p {
  margin: 0;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.6s ease, opacity 0.5s ease, margin 0.4s;
  color: var(--ink-dim);
  font-size: 0.98rem;
  line-height: 1.65;
}
.aside.open {
  border-color: var(--gold);
  background: rgba(212, 168, 75, 0.08);
}
.aside.open p {
  max-height: 400px;
  opacity: 1;
  margin-top: 0.4rem;
}

/* ---------- Key chapter ---------- */
.key-chapter { text-align: center; }
.key-stage {
  margin: 3rem auto 2rem;
  max-width: 320px;
  position: relative;
}
.key-prompt {
  font-family: var(--sans);
  font-size: 0.76rem;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 1.2rem;
  transition: opacity 0.4s;
}
.key-device {
  width: 220px;
  height: 220px;
  margin: 0 auto;
  cursor: pointer;
  outline: none;
  user-select: none;
}
.key-svg { width: 100%; height: 100%; }
.key-aura { transition: opacity 1.2s ease; }
.key-group {
  transform-origin: 100px 100px;
  transform-box: view-box;
  transition: transform 1.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.key-group.turned { transform: rotate(180deg); }
.key-device:hover .key-group { filter: drop-shadow(0 0 12px rgba(212, 168, 75, 0.5)); }

.key-result {
  margin-top: 1.4rem;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.8s ease 0.2s, transform 0.8s ease 0.2s;
}
.key-result.shown { opacity: 1; transform: none; }
.key-line {
  font-style: italic;
  font-size: 1.1rem;
  color: var(--gold-bright);
  margin: 0 0 0.5rem;
}
html[data-theme="light"] .key-line { color: var(--gold-deep); }
.key-cite {
  font-family: var(--sans);
  font-size: 0.76rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0;
}

/* ---------- Closing ---------- */
.closing .benediction {
  font-size: 1.24rem;
  font-style: italic;
  line-height: 1.6;
  color: var(--gold-bright);
  margin-top: 2.4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--rule);
}
html[data-theme="light"] .closing .benediction { color: var(--bronze); }

/* ---------- Illustrations ---------- */
.gen-illustration {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 2px;
  opacity: 0;
  transition: opacity 1.4s ease 0.3s;
}
.gen-illustration[src] { opacity: 1; }
.illustration-frame {
  margin: 2.6rem auto;
  padding: 10px;
  background: rgba(20, 21, 39, 0.6);
  border: 1px solid var(--rule);
  box-shadow: var(--shadow);
  border-radius: 2px;
  max-width: 560px;
  position: relative;
}
html[data-theme="light"] .illustration-frame { background: rgba(253, 247, 232, 0.8); }
.illustration-frame::before, .illustration-frame::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 1px solid var(--gold);
  opacity: 0.5;
}
.illustration-frame::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.illustration-frame::after { bottom: -1px; right: -1px; border-left: none; border-top: none; }
.illustration-frame .gen-illustration { border-radius: 1px; }

/* ---------- Scripture Index ---------- */
.index {
  max-width: 860px;
  margin: 4vh auto 0;
  padding: 10vh 6vw 6vh;
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 1.1s ease, transform 1.1s ease;
  border-top: 1px solid var(--rule);
}
.index.in { opacity: 1; transform: none; }
.index-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(1.5rem, 4.5vw, 2.2rem);
  text-align: center;
  margin: 0 0 0.8rem;
  color: var(--ink);
}
.index-note {
  text-align: center;
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 3rem;
}
.index-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: 0.8rem;
}
.index-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.3rem;
  padding: 1rem 1.1rem;
  background: rgba(20, 21, 39, 0.5);
  border: 1px solid var(--rule);
  border-radius: 4px;
  cursor: pointer;
  text-align: left;
  font-family: var(--sans);
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  color: var(--ink);
}
html[data-theme="light"] .index-card { background: rgba(253, 247, 232, 0.7); }
.index-card:hover, .index-card:focus-visible {
  background: rgba(212, 168, 75, 0.14);
  border-color: var(--gold);
  transform: translateY(-2px);
  outline: none;
}
.index-card.read { border-color: var(--gold); }
.index-card.read::after {
  content: "read";
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
  margin-top: 0.3rem;
}
.index-ref {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--gold-bright);
  font-family: var(--serif);
}
html[data-theme="light"] .index-ref { color: var(--bronze); }
.index-cite {
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  padding: 5vh 6vw 8vh;
  border-top: 1px solid var(--rule);
  max-width: 720px;
  margin: 0 auto;
}
.footer-line {
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 0.4rem;
}
.footer-line.dim { color: var(--ink-faint); font-size: 0.7rem; }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 720px) { .drawer { align-items: center; } }
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 8, 16, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.drawer.open .drawer-backdrop { opacity: 1; }
.drawer-panel {
  position: relative;
  background: var(--bg-soft);
  border: 1px solid var(--gold);
  border-radius: 6px 6px 0 0;
  padding: 2.4rem 1.8rem 2.2rem;
  max-width: 600px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  transform: translateY(40px);
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s ease;
  box-shadow: var(--shadow);
}
@media (min-width: 720px) {
  .drawer-panel { border-radius: 6px; transform: translateY(20px) scale(0.98); }
  .drawer.open .drawer-panel { transform: none; }
}
.drawer.open .drawer-panel { transform: none; opacity: 1; }
.drawer-close {
  position: absolute;
  top: 0.8rem;
  right: 0.9rem;
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--gold);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  transition: background 0.2s, color 0.2s;
}
.drawer-close:hover { background: var(--gold); color: var(--bg-deep); }
.drawer-ref {
  font-family: var(--sans);
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 0.5rem;
}
.drawer-citation {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--ink);
  margin: 0 0 1.4rem;
}
.drawer-text {
  font-style: italic;
  font-size: 1.08rem;
  line-height: 1.7;
  color: var(--ink);
  margin: 0 0 1.6rem;
}
.drawer-note {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--ink-dim);
  border-top: 1px solid var(--rule);
  padding-top: 1.2rem;
  margin: 0;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  body { font-size: 17px; }
  .chapter { padding: 10vh 7vw; }
  .scripture { padding: 1.4rem 1.1rem 1.1rem; }
  .key-device { width: 180px; height: 180px; }
}

/* ---------- Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .chapter { opacity: 1; transform: none; }
}
