/* ---- Theme tokens ---- */
:root {
  --bg: #f5efe5;
  --bg-grad: radial-gradient(ellipse at top, #faf5ec 0%, #f5efe5 60%);
  --surface: #ebe3d3;
  --surface-2: #e2d9c6;
  --ink: #1c1917;
  --muted: #6b6157;
  --rule: #d9ceb9;
  --accent: #3a3330;
  --accent-hover: #000;
  --max: 1120px;
  --measure: 38rem;
  --radius: 2px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 8px 24px -8px rgba(28,25,23,0.15);
  --font-base: 18px;
  --measure-reader: 46rem;
}

/* Automatic dark mode when no override */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0d0b;
    --bg-grad: radial-gradient(ellipse at top, #171310 0%, #0f0d0b 60%);
    --surface: #1a1613;
    --surface-2: #231d18;
    --ink: #ebe3d3;
    --muted: #8c7f74;
    --rule: #2a2322;
    --accent: #c9a97a;
    --accent-hover: #e2c594;
  }
}
/* Explicit dark override */
:root[data-theme="dark"] {
  --bg: #0f0d0b;
  --bg-grad: radial-gradient(ellipse at top, #171310 0%, #0f0d0b 60%);
  --surface: #1a1613;
  --surface-2: #231d18;
  --ink: #ebe3d3;
  --muted: #8c7f74;
  --rule: #2a2322;
  --accent: #c9a97a;
  --accent-hover: #e2c594;
}

/* Section accent overrides */
body.horror {
  --bg: #0a0808;
  --bg-grad: radial-gradient(ellipse at top, #141010 0%, #0a0808 60%);
  --surface: #141010;
  --surface-2: #1e1818;
  --ink: #ebe3d3;
  --muted: #8c7f74;
  --rule: #2a2322;
  --accent: #a73030;
  --accent-hover: #d84848;
}
body.writing { --accent: #8b4a1f; --accent-hover: #6b3614; }
body.library { --accent: #1f4a4a; --accent-hover: #0f2d2d; }

/* Reader mode: bigger text, wider measure */
body.reader {
  --font-base: 20px;
  --measure: var(--measure-reader);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  font-size: var(--font-base);
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s, color 0.3s;
  overflow-x: hidden;
}

.container { max-width: var(--max); margin: 0 auto; padding: 0 1.75rem; position: relative; }

/* ---- Header ---- */
header.site {
  padding: 1.75rem 0 1.25rem;
  border-bottom: 1px solid var(--rule);
  position: relative;
  z-index: 10;
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.site-title {
  font-size: 1.5rem;
  font-weight: normal;
  margin: 0;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.site-title a {
  color: var(--ink);
  text-decoration: none;
}
.header-tools {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.tool-btn {
  background: none;
  border: 1px solid var(--rule);
  color: var(--muted);
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
}
.tool-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--surface);
}
.tool-btn svg { width: 16px; height: 16px; }
.tool-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

nav.primary ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1.75rem;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
}
nav.primary a {
  color: var(--muted);
  text-decoration: none;
  padding-bottom: 3px;
  border-bottom: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  position: relative;
}
nav.primary a:hover,
nav.primary a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---- Main ---- */
main {
  padding: 4rem 0 5rem;
  position: relative;
}
h1 {
  font-family: Georgia, serif;
  font-size: clamp(2.25rem, 5vw, 3.25rem);
  font-weight: normal;
  line-height: 1.1;
  margin: 0 0 1.5rem;
  letter-spacing: -0.015em;
}
h2 {
  font-size: 1.6rem;
  font-weight: normal;
  margin: 3rem 0 1rem;
  color: var(--accent);
  letter-spacing: 0.01em;
  position: relative;
  display: inline-block;
}
h2::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: -6px;
  width: 0;
  height: 2px;
  background: var(--accent);
  transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
h2.in-view::after { width: 2.5rem; }
h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 2rem 0 0.5rem;
  color: var(--ink);
}
p { margin: 0 0 1.1rem; max-width: var(--measure); }
a { color: var(--accent); transition: color 0.15s; }
a:hover { color: var(--accent-hover); }

.lead {
  font-size: 1.25rem;
  color: var(--muted);
  font-style: italic;
  max-width: var(--measure);
}

/* ---- Letter reveal ---- */
.reveal-letters { display: inline-block; }
.reveal-letters .letter {
  display: inline-block;
  opacity: 0;
  transform: translateY(0.5em);
  animation: letterRise 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  animation-delay: calc(var(--i, 0) * 25ms);
  will-change: transform, opacity;
}
.reveal-letters .space { width: 0.3em; display: inline-block; }
@keyframes letterRise {
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Scroll reveal ---- */
.reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.7s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: opacity, transform;
}
.reveal.in-view { opacity: 1; transform: translateY(0); }

/* ---- Hero split ---- */
.hero-split {
  display: grid;
  grid-template-columns: 0.9fr 1.3fr;
  gap: 3.5rem;
  align-items: center;
  padding: 1rem 0 2rem;
}
.hero-portrait-wrap { position: relative; }
.hero-portrait-wrap::before {
  content: '';
  position: absolute;
  inset: -10%;
  background: radial-gradient(circle at center, rgba(201,169,122,0.08) 0%, transparent 60%);
  z-index: 0;
  animation: breathe 8s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.1); opacity: 1; }
}
.hero-portrait {
  position: relative;
  aspect-ratio: 4/5;
  background: var(--surface);
  border: 1px solid var(--rule);
  overflow: hidden;
  z-index: 1;
  will-change: transform;
  box-shadow: var(--shadow-md);
}
.hero-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.hero-portrait:hover img { transform: scale(1.03); }
.hero-portrait .fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-style: italic;
  font-size: 0.9rem;
  text-align: center;
  padding: 1rem;
}

/* ---- Section cards ---- */
.section-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  margin: 4rem 0 0;
}
.section-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  padding: 1.75rem 1.5rem;
  text-decoration: none;
  color: var(--ink);
  display: block;
  position: relative;
  overflow: hidden;
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.2s, box-shadow 0.25s;
}
.section-card::before {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: var(--card-accent, var(--accent));
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.section-card:hover {
  transform: translateY(-3px);
  border-color: var(--card-accent, var(--accent));
  box-shadow: var(--shadow-md);
}
.section-card:hover::before { transform: scaleX(1); }
.section-card.horror-tint { --card-accent: #a73030; }
.section-card.writing-tint { --card-accent: #8b4a1f; }
.section-card.library-tint { --card-accent: #1f4a4a; }
.section-card .label {
  font-family: system-ui, sans-serif;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin: 0 0 0.5rem;
}
.section-card .title {
  font-size: 1.35rem;
  margin: 0 0 0.5rem;
  color: var(--ink);
  font-weight: normal;
}
.section-card .desc {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 0;
  max-width: none;
}

/* ---- Work list / placeholders ---- */
.work-list { list-style: none; padding: 0; margin: 1.5rem 0; }
.work-item { padding: 1.5rem 0; border-bottom: 1px solid var(--rule); }
.work-item:first-child { padding-top: 0; }
.work-item:last-child { border-bottom: none; }
.work-meta {
  font-family: system-ui, sans-serif;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--muted);
  margin: 0 0 0.35rem;
}
.work-title { font-size: 1.2rem; margin: 0 0 0.4rem; color: var(--ink); }

.placeholder-slot {
  padding: 2.25rem 1.5rem;
  background: var(--surface);
  border: 1px dashed var(--rule);
  color: var(--muted);
  font-style: italic;
  text-align: center;
  margin: 1rem 0;
  max-width: none;
  transition: border-color 0.2s;
}
.placeholder-slot:hover { border-color: var(--accent); }

/* Filter chips (ready for when works exist) */
.filter-chips {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 1rem 0 1.5rem;
  font-family: system-ui, sans-serif;
}
.chip {
  padding: 0.4rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 999px;
  transition: all 0.15s;
}
.chip:hover,
.chip[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent);
  background: transparent;
}

/* ---- Writing sub-sections ---- */
.sub-section + .sub-section {
  margin-top: 3.5rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--rule);
}

/* ---- Library affiliation badge ---- */
.affiliation {
  display: inline-block;
  padding: 0.4rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 1rem;
  border-radius: var(--radius);
}

/* ---- Collapsible sections ---- */
details.collapsible {
  margin: 1rem 0;
  border: 1px solid var(--rule);
  background: var(--surface);
  padding: 0;
  transition: border-color 0.2s;
}
details.collapsible[open] { border-color: var(--accent); }
details.collapsible > summary {
  cursor: pointer;
  padding: 1rem 1.25rem;
  font-family: system-ui, sans-serif;
  font-size: 0.95rem;
  color: var(--ink);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary::after {
  content: '+';
  font-size: 1.4rem;
  color: var(--muted);
  transition: transform 0.2s;
  line-height: 1;
}
details.collapsible[open] > summary::after { transform: rotate(45deg); }
details.collapsible > .content { padding: 0 1.25rem 1.25rem; }

/* ---- Horror atmospheric fog ---- */
.fog-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 1;
  opacity: 0.5;
  mix-blend-mode: screen;
}
body:not(.horror) .fog-overlay { display: none; }

/* ---- Footer ---- */
footer {
  border-top: 1px solid var(--rule);
  padding: 2rem 0 3rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-family: system-ui, sans-serif;
  position: relative;
  z-index: 10;
}
footer p { margin: 0.2rem 0; max-width: none; }
footer a { color: var(--muted); }

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .reveal { opacity: 1; transform: none; }
  .reveal-letters .letter { opacity: 1; transform: none; }
  .hero-portrait-wrap::before { animation: none; }
  .fog-overlay { display: none; }
}

/* ---- Mobile ---- */
@media (max-width: 760px) {
  .hero-split { grid-template-columns: 1fr; gap: 1.75rem; }
  .hero-portrait-wrap { max-width: 340px; margin: 0 auto; }
  .section-cards { grid-template-columns: 1fr; }
  nav.primary ul { gap: 1.25rem; }
  main { padding: 2rem 0 3rem; }
}

/* ---- Fixes: portrait layering + dark-mode section accents ---- */
.hero-portrait img { position: relative; z-index: 1; }
.hero-portrait .fallback { z-index: 0; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body.writing { --accent: #d08a55; --accent-hover: #e8a673; }
  :root:not([data-theme="light"]) body.library { --accent: #6fb3b3; --accent-hover: #8fcaca; }
}
:root[data-theme="dark"] body.writing { --accent: #d08a55; --accent-hover: #e8a673; }
:root[data-theme="dark"] body.library { --accent: #6fb3b3; --accent-hover: #8fcaca; }

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--accent); color: var(--bg); padding: 0.5rem 1rem; z-index: 100;
}
.skip-link:focus { left: 1rem; top: 1rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.section-card .title::after { background: var(--card-accent, var(--accent)); }

/* ---- v4: real content ---- */
.text-link { font-family: system-ui, sans-serif; font-size: 0.95rem; color: var(--accent); text-decoration: none; border-bottom: 1px solid currentColor; padding-bottom: 1px; }
.hero-link { margin-top: 0.5rem; }
.about p { max-width: 42rem; }

/* Books */
.book-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.25rem; margin: 1rem 0 0.5rem; }
.book-grid.single { grid-template-columns: minmax(0, 36rem); }
.book-card {
  background: var(--surface); border: 1px solid var(--rule); border-left: 3px solid var(--accent);
  padding: 1.5rem 1.5rem 1.25rem; transition: transform 0.25s cubic-bezier(0.2,0.8,0.2,1), box-shadow 0.25s;
}
.book-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.book-card .label, .degree-card .label {
  font-family: system-ui, sans-serif; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--muted); margin: 0 0 0.5rem;
}
.book-title { font-size: 1.3rem; font-weight: normal; margin: 0 0 0.35rem; letter-spacing: 0.01em; }
.book-sub { color: var(--muted); font-style: italic; margin: 0 0 0.75rem; }

/* Publication list */
.work-list .work-item { padding: 1.35rem 0; }
.work-list .work-item:first-child { padding-top: 0.5rem; }
.work-title { font-weight: normal; margin: 0 0 0.25rem; }
.work-venue { color: var(--muted); margin: 0 0 0.35rem; font-size: 0.97rem; }
.work-link { margin: 0.35rem 0 0; font-family: system-ui, sans-serif; font-size: 0.88rem; }
.work-link a { text-decoration: none; border-bottom: 1px solid transparent; transition: border-color 0.15s; }
.work-link a:hover { border-bottom-color: currentColor; }
.chip-count { opacity: 0.65; margin-left: 0.2rem; font-variant-numeric: tabular-nums; }

/* Forthcoming */
.forthcoming-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.25rem; margin-top: 1rem; }
.forthcoming-card { background: var(--surface); border: 1px solid var(--rule); padding: 1.5rem; }
.fc-kind { font-family: system-ui, sans-serif; font-size: 0.8rem; color: var(--muted); margin: 1rem 0 0.35rem; text-transform: uppercase; letter-spacing: 0.1em; }
.fc-list { margin: 0; padding-left: 1.1rem; }
.fc-list li { margin: 0.2rem 0; }
.fc-list li::marker { color: var(--accent); }

/* Library */
.degree-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 1rem; }
.degree-card { background: var(--surface); border: 1px solid var(--rule); border-top: 3px solid var(--accent); padding: 1.25rem 1.25rem 1.1rem; }
.degree-card h3 { font-weight: normal; margin: 0; font-size: 1.1rem; }
.degree-card.wide { max-width: 36rem; margin-top: 1rem; }

@media (max-width: 760px) {
  .book-grid, .forthcoming-grid, .degree-grid { grid-template-columns: 1fr; }
}
main { overflow-x: clip; }
h1.reveal-letters { display: block; }
footer a:hover { color: var(--accent); }
