/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink:       #1a1409;
  --paper:     #f5f0e8;
  --gold:      #a07830;
  --gold-lt:   #c9a050;
  --rust:      #7a3a1a;
  --muted:     #6b5e4a;
  --card-bg:   #faf6ee;
  --card-brd:  #d4c4a0;
  --rule:      #c8b888;
  --hover-bg:  #f0e8d0;
  --link:      #5a3010;
  --max-w:     1200px;
  --serif:     'Garamond', 'EB Garamond', 'Palatino Linotype', Georgia, serif;
  --sans:      'Optima', 'Gill Sans', Candara, system-ui, sans-serif;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--serif);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.65;
}

/* ── Header ───────────────────────────────────────────────── */
header {
  background: var(--ink);
  color: var(--paper);
  padding: 2.5rem 1.5rem 2rem;
  text-align: center;
  border-bottom: 4px solid var(--gold);
}

header .subtitle {
  font-family: var(--sans);
  font-size: .85rem;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--gold-lt);
  margin-bottom: .6rem;
}

header h1 {
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  font-weight: 400;
  letter-spacing: .03em;
  line-height: 1.2;
}

header h1 em {
  font-style: italic;
  color: var(--gold-lt);
}

header .meta {
  margin-top: .8rem;
  font-size: .88rem;
  color: #b0a080;
}

/* ── Nav bar ──────────────────────────────────────────────── */
nav.breadcrumb {
  background: #2a2010;
  padding: .5rem 1.5rem;
  font-family: var(--sans);
  font-size: .82rem;
  color: #a09070;
}

nav.breadcrumb a { color: var(--gold-lt); text-decoration: none; }
nav.breadcrumb a:hover { text-decoration: underline; }

/* ── Main layout ──────────────────────────────────────────── */
main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ── Search / filter bar ──────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  align-items: center;
}

.filter-bar input[type="search"] {
  flex: 1;
  min-width: 200px;
  padding: .55rem .9rem;
  border: 1px solid var(--card-brd);
  border-radius: 4px;
  background: var(--card-bg);
  font-family: var(--serif);
  font-size: .95rem;
  color: var(--ink);
}

.filter-bar input[type="search"]:focus {
  outline: 2px solid var(--gold);
  border-color: var(--gold);
}

.filter-bar .count {
  font-family: var(--sans);
  font-size: .82rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ── Card grid ────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.4rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-brd);
  border-radius: 6px;
  padding: 1.4rem 1.5rem 1.2rem;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, background .15s;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  position: relative;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,.12);
  background: var(--hover-bg);
}

.card-num {
  font-family: var(--sans);
  font-size: .72rem;
  letter-spacing: .1em;
  color: var(--gold);
  text-transform: uppercase;
}

.card-heading {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--rust);
}

.card-pages {
  font-family: var(--sans);
  font-size: .75rem;
  color: var(--muted);
}

.card-summary {
  font-size: .9rem;
  line-height: 1.6;
  color: #3a2e1a;
  flex: 1;
}

.card-arrow {
  font-family: var(--sans);
  font-size: .78rem;
  color: var(--gold);
  margin-top: .3rem;
  align-self: flex-end;
}

/* Loading skeleton */
.card.loading .card-heading,
.card.loading .card-summary {
  background: linear-gradient(90deg, #e8dcc8 25%, #f0e8d8 50%, #e8dcc8 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 3px;
  color: transparent;
}

.card.loading .card-heading { height: 1.2em; width: 70%; }
.card.loading .card-summary { height: 4em; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Essay page ───────────────────────────────────────────── */
.essay-wrap {
  max-width: 780px;
  margin: 0 auto;
}

.essay-header {
  border-bottom: 2px solid var(--rule);
  padding-bottom: 1.2rem;
  margin-bottom: 2rem;
}

.essay-chunk-id {
  font-family: var(--sans);
  font-size: .78rem;
  letter-spacing: .12em;
  color: var(--gold);
  text-transform: uppercase;
  margin-bottom: .4rem;
}

.essay-title {
  font-size: clamp(1.3rem, 3vw, 1.9rem);
  font-weight: 400;
  color: var(--rust);
  line-height: 1.25;
  margin-bottom: .5rem;
}

.essay-pages {
  font-family: var(--sans);
  font-size: .8rem;
  color: var(--muted);
}

.essay-card-summary {
  background: #ede4ce;
  border-left: 3px solid var(--gold);
  padding: 1rem 1.3rem;
  font-style: italic;
  font-size: .95rem;
  margin-bottom: 2rem;
  border-radius: 0 4px 4px 0;
}

.essay-body {
  font-size: 1rem;
  line-height: 1.7;
}

.essay-body h2 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--rust);
  margin: 1.7rem 0 .45rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: .25rem;
}

.essay-body h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  margin: 1.25rem 0 .3rem;
}

.essay-body p { margin-bottom: .85rem; }

.essay-body hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 1.5rem 0;
}

.essay-body blockquote {
  padding: 0;
  margin: .9rem 0 .9rem 2rem;
  font-style: italic;
  font-size: .93rem;
  color: #3a2a10;
}

.essay-body blockquote cite {
  display: inline;
  font-style: normal;
  font-family: var(--sans);
  font-size: .75rem;
  color: var(--muted);
  margin-left: .5em;
}

.essay-body cite {
  font-style: normal;
  font-family: var(--sans);
  font-size: .75rem;
  color: var(--muted);
}

/* ── Chunk navigation ─────────────────────────────────────── */
.chunk-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  gap: 1rem;
}

.chunk-nav a {
  font-family: var(--sans);
  font-size: .85rem;
  color: var(--link);
  text-decoration: none;
  padding: .5rem .9rem;
  border: 1px solid var(--card-brd);
  border-radius: 4px;
  background: var(--card-bg);
  transition: background .15s;
}

.chunk-nav a:hover { background: var(--hover-bg); }

/* ── Footer ───────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 1.5rem;
  font-family: var(--sans);
  font-size: .78rem;
  color: var(--muted);
  border-top: 1px solid var(--rule);
  margin-top: 2rem;
}

footer a { color: var(--gold); text-decoration: none; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 600px) {
  .card-grid { grid-template-columns: 1fr; }
  header { padding: 1.5rem 1rem 1.2rem; }
  main { padding: 1.2rem 1rem 3rem; }
}

/* ── Reading progress bar ─────────────────────────────────── */
.progress-bar {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0;
  background: var(--gold);
  z-index: 100;
}

/* ── Back to top ──────────────────────────────────────────── */
.back-to-top {
  position: fixed;
  bottom: 1.5rem; right: 1.5rem;
  width: 42px; height: 42px;
  border: 1px solid var(--card-brd);
  border-radius: 50%;
  background: var(--card-bg);
  color: var(--gold);
  font-size: 1.1rem;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  z-index: 90;
}

.back-to-top.visible { opacity: 1; pointer-events: auto; }
.back-to-top:hover { background: var(--hover-bg); }

/* ── Spinner for essay load ───────────────────────────────── */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--rule);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 4rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  text-align: center;
  padding: 3rem;
  color: var(--rust);
  font-style: italic;
}
