/* ===================================================================
   Shared styles — atmospheric horror scrollytelling
   =================================================================== */

:root {
  --bg: #0a0707;
  --bg-2: #120c0c;
  --paper: #e8e2d6;
  --ink: #d8d2c4;
  --ink-dim: #8a847a;
  --ink-faint: #4a4540;
  --accent: #b91c1c;
  --accent-bright: #ef2b2b;
  --accent-deep: #5a0e0e;
  --rule: #1f1616;
  --vignette: rgba(0,0,0,0.85);

  --font-display: "Cormorant Garamond", "EB Garamond", Georgia, serif;
  --font-body: "EB Garamond", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Courier New", monospace;
  --font-sans: "Inter Tight", system-ui, sans-serif;
}

:root[data-mode="dim"] {
  --bg: #1a1414;
  --bg-2: #221919;
  --ink: #e8e2d6;
  --ink-dim: #a8a298;
  --ink-faint: #5a5550;
  --rule: #2f2222;
  --vignette: rgba(0,0,0,0.55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 19px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}

body {
  min-height: 100vh;
  position: relative;
}

/* Paper grain */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9000;
  opacity: var(--grain-opacity, 0.18);
  mix-blend-mode: overlay;
  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.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.6 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* Slow vignette pulse */
.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 8500;
  background: radial-gradient(ellipse at center, transparent 40%, var(--vignette) 100%);
  animation: vignette-pulse 9s ease-in-out infinite;
}
@keyframes vignette-pulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}

/* Ambient flicker */
.flicker {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 8000;
  background: rgba(255,240,230,0.02);
  animation: flicker 7s steps(2, end) infinite;
}
@keyframes flicker {
  0%, 92%, 100% { opacity: 0; }
  93% { opacity: 1; }
  94% { opacity: 0.2; }
  95% { opacity: 0.9; }
  96% { opacity: 0; }
}

[data-effects="off"] .grain,
[data-effects="off"] .vignette,
[data-effects="off"] .flicker { display: none; }

/* ===== Top bar ===== */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 40px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.wordmark {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 17px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 12px;
}
.wordmark::before {
  content: "";
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 12px var(--accent);
}

.menu-btn {
  background: transparent;
  border: none;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  align-items: flex-end;
}
.menu-btn:hover { color: var(--accent-bright); }
.menu-btn-lines {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}
.menu-btn-lines span {
  display: block;
  height: 1px;
  background: currentColor;
}
.menu-btn-lines span:nth-child(1) { width: 28px; }
.menu-btn-lines span:nth-child(2) { width: 20px; }
.menu-btn-lines span:nth-child(3) { width: 28px; }

/* ===== Main menu overlay ===== */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.menu-overlay.open { opacity: 1; pointer-events: auto; }
.menu-overlay::before {
  content: "";
  position: absolute; inset: 0;
  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.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.6 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  opacity: 0.15; mix-blend-mode: overlay; pointer-events: none;
}
.menu-close {
  position: absolute; top: 28px; right: 40px;
  background: transparent; border: none; color: var(--ink);
  font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.2em; text-transform: uppercase;
  cursor: pointer; padding: 10px; z-index: 10;
}
.menu-close:hover { color: var(--accent-bright); }

.menu-inner {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: 1fr 360px;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "head head"
    "list side";
  padding: 90px 64px 48px;
  gap: 0 64px;
  max-height: 100vh;
}

.menu-head {
  grid-area: head;
  display: flex;
  align-items: center;
  gap: 32px;
  padding-bottom: 24px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}
.menu-filter {
  flex: 1;
  min-width: 220px;
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink);
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  outline: none;
  transition: border-color 0.2s;
}
.menu-filter:focus { border-color: var(--accent); }
.menu-filter::placeholder { color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.15em; font-size: 11px; }

.menu-section-label {
  font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.25em; text-transform: uppercase;
  color: var(--accent);
  display: flex; align-items: center; gap: 12px;
  white-space: nowrap;
}
.menu-section-label::after {
  content: ""; width: 80px; height: 1px; background: var(--accent-deep);
}

.menu-list {
  grid-area: list;
  overflow-y: auto;
  padding-right: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-deep) transparent;
}
.menu-list::-webkit-scrollbar { width: 6px; }
.menu-list::-webkit-scrollbar-thumb { background: var(--accent-deep); }
.menu-list::-webkit-scrollbar-track { background: transparent; }

.menu-part { margin-bottom: 40px; }
.menu-part-head {
  position: sticky;
  top: 0;
  background: linear-gradient(to bottom, var(--bg) 70%, transparent);
  padding: 8px 0 14px;
  display: flex;
  align-items: baseline;
  gap: 16px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 8px;
  z-index: 2;
}
.menu-part-label {
  font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.3em; text-transform: uppercase;
  color: var(--accent);
}
.menu-part-sub {
  font-family: var(--font-display); font-style: italic;
  font-size: 18px; color: var(--ink-dim);
  letter-spacing: 0;
}

.menu-chapters {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 32px;
}
.menu-chapters li {
  border-bottom: 1px solid var(--rule);
  transition: opacity 0.2s;
}
.menu-chapters li.hidden { display: none; }
.menu-chapters a {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 20px;
  align-items: baseline;
  padding: 14px 0 14px 14px;
  text-decoration: none;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  font-style: italic;
  transition: color 0.25s, padding 0.25s, background 0.25s;
  position: relative;
  text-wrap: balance;
}
.menu-chapters a:hover {
  color: var(--accent-bright);
  padding-left: 22px;
  background: rgba(185, 28, 28, 0.04);
}
.menu-chapters a::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0;
  background: var(--accent);
  transition: width 0.25s;
}
.menu-chapters a:hover::before { width: 2px; }
.menu-chapters .num {
  font-family: var(--font-mono);
  font-style: normal;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--ink-faint);
  align-self: center;
}
.menu-chapters .title { line-height: 1.2; }

.menu-chapters .current a { color: var(--accent-bright); }
.menu-chapters .current .num { color: var(--accent-bright); }
.menu-chapters .current a::before {
  width: 2px;
  background: var(--accent-bright);
}
.menu-chapters .current::after {
  content: "READING";
  position: absolute;
  right: 0; top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.25em;
  color: var(--accent);
  padding: 4px 8px;
  border: 1px solid var(--accent-deep);
}
.menu-chapters .current { position: relative; }

.menu-side {
  grid-area: side;
  align-self: stretch;
  border-left: 1px solid var(--rule);
  padding-left: 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.menu-about {
  font-family: var(--font-display);
  font-size: 19px;
  font-style: italic;
  color: var(--ink-dim);
  line-height: 1.5;
}
.menu-progress {
  margin-top: auto;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
}
.menu-progress-bar {
  height: 2px;
  background: var(--rule);
  margin-bottom: 12px;
  position: relative;
}
.menu-progress-bar span {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
.menu-progress-meta {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.menu-progress-meta .accent { color: var(--accent-bright); }

.menu-empty {
  padding: 24px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: center;
  display: none;
}
.menu-list.is-empty .menu-empty { display: block; }
.menu-list.is-empty .menu-part { display: none; }

/* ===== Chapter pagination footer ===== */
.chapter-footer {
  position: relative;
  padding: 120px 40px 80px;
  border-top: 1px solid var(--rule);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  background: var(--bg);
}
.chapter-footer::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 4px var(--bg), 0 0 20px var(--accent);
}
.nav-card {
  text-decoration: none;
  color: var(--ink);
  display: block;
  padding: 28px;
  border: 1px solid var(--rule);
  transition: border-color 0.3s, background 0.3s, transform 0.4s;
  position: relative;
  overflow: hidden;
  min-height: 180px;
}
.nav-card:hover {
  border-color: var(--accent);
  background: rgba(185, 28, 28, 0.05);
}
.nav-card.disabled {
  opacity: 0.3;
  pointer-events: none;
}
.nav-card .label, .nav-card .num-big, .nav-card .title { display: block; }
.nav-card .label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-card.next { text-align: right; }
.nav-card .num-big {
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 0.2em;
  color: var(--accent);
  margin-bottom: 8px;
}
.nav-card .title {
  font-family: var(--font-display);
  font-size: 28px;
  font-style: italic;
  font-weight: 400;
  line-height: 1.2;
}
.nav-card .arrow {
  position: absolute;
  bottom: 24px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  transition: color 0.3s, transform 0.3s;
}
.nav-card.prev .arrow { left: 28px; }
.nav-card.next .arrow { right: 28px; }
.nav-card:hover .arrow { color: var(--accent-bright); }
.nav-card.prev:hover .arrow { transform: translateX(-6px); }
.nav-card.next:hover .arrow { transform: translateX(6px); }

/* ===== Brush dividers ===== */
.brush-divider {
  width: 100%;
  height: 24px;
  margin: 80px 0;
  opacity: 0.7;
}

/* ===== Reveal-on-scroll ===== */
.reveal {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 1.2s ease, transform 1.2s ease;
}
.reveal.in {
  opacity: 1;
  transform: translateY(0);
}
[data-effects="off"] .reveal {
  opacity: 1;
  transform: none;
}

/* ===== Glitch / chromatic aberration ===== */
.glitch {
  position: relative;
  display: inline-block;
  color: var(--ink);
}
.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  pointer-events: none;
  opacity: 0.7;
}
.glitch::before {
  color: var(--accent-bright);
  transform: translate(-1.5px, 0);
  mix-blend-mode: screen;
  animation: glitch-shift 4s infinite steps(2, end);
}
.glitch::after {
  color: #1ea7c4;
  transform: translate(1.5px, 0);
  mix-blend-mode: screen;
  animation: glitch-shift 4.3s infinite steps(2, end) reverse;
}
@keyframes glitch-shift {
  0%, 88%, 100% { transform: translate(0, 0); opacity: 0; }
  90% { transform: translate(-2px, 0.5px); opacity: 0.8; }
  92% { transform: translate(2px, -0.5px); opacity: 0.6; }
  94% { transform: translate(-1px, 0); opacity: 0.4; }
}
[data-effects="off"] .glitch::before,
[data-effects="off"] .glitch::after { display: none; }

/* ===== Scroll progress bar ===== */
.progress {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  background: var(--accent);
  z-index: 200;
  width: 0%;
  transition: width 0.1s linear;
  box-shadow: 0 0 8px var(--accent);
}

/* ===== Utility ===== */
.mono { font-family: var(--font-mono); letter-spacing: 0.15em; text-transform: uppercase; font-size: 11px; }
.dim { color: var(--ink-dim); }
.faint { color: var(--ink-faint); }

::selection {
  background: var(--accent);
  color: var(--paper);
}

/* ===== Responsive menu ===== */
@media (max-width: 1100px) {
  .menu-inner {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "head" "list" "side";
    padding: 80px 32px 24px;
    gap: 16px;
  }
  .menu-list { min-height: 50vh; padding-right: 8px; }
  .menu-side {
    border-left: none;
    border-top: 1px solid var(--rule);
    padding-left: 0;
    padding-top: 16px;
    gap: 12px;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .menu-side .menu-section-label { display: none; }
  .menu-about { display: none; }
  .menu-progress {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    flex: 1;
    min-width: 200px;
  }
  .menu-chapters { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .menu-close { top: 18px; right: 20px; }
  .menu-inner { padding: 70px 20px 24px; }
  .menu-list { min-height: 55vh; }
  .menu-chapters a { font-size: 19px; padding: 12px 0 12px 10px; }
  .menu-chapters .current::after { display: none; }
  .menu-head { gap: 16px; }
}
