@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,600;0,9..144,700;1,9..144,500&family=Inter:wght@400;500;600&display=swap');

:root {
  --ink: #1b1f2a;
  --ink-soft: #2a2f3d;
  --parchment: #ede4d3;
  --parchment-dim: #e0d5bd;
  --rust: #a63d40;
  --gold: #c9a227;
  --sage: #6b8f71;
  --text-on-ink: #ede4d3;
  --text-on-parchment: #211c14;
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Inter', system-ui, sans-serif;
  --rule: rgba(237, 228, 211, 0.18);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--text-on-ink);
  font-family: var(--sans);
  line-height: 1.6;
}

a { color: inherit; }

.wrap {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 28px;
}

/* ---- Header / nav ---- */
header.site {
  border-bottom: 1px solid var(--rule);
  padding: 22px 0;
}

header.site .wrap {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.brand {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: 0.01em;
  text-decoration: none;
  color: var(--text-on-ink);
}

.brand em { color: var(--rust); font-style: normal; }

nav.pages { display: flex; gap: 26px; }

nav.pages a {
  text-decoration: none;
  font-size: 0.95rem;
  color: var(--text-on-ink);
  border-bottom: 1px solid transparent;
  padding-bottom: 3px;
  transition: border-color 0.15s ease, color 0.15s ease;
}

nav.pages a:hover,
nav.pages a[aria-current="page"] {
  border-color: var(--gold);
  color: var(--gold);
}

/* ---- Hero ---- */
.hero {
  padding: 64px 0 48px;
  border-bottom: 1px solid var(--rule);
}

.hero .kicker {
  font-family: var(--serif);
  font-style: italic;
  color: var(--sage);
  font-size: 1.05rem;
  margin: 0 0 10px;
}

.hero h1 {
  font-family: var(--serif);
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  line-height: 1.08;
  margin: 0 0 20px;
  max-width: 14ch;
}

.hero p.lede {
  max-width: 58ch;
  font-size: 1.08rem;
  color: rgba(237, 228, 211, 0.85);
}

/* ---- Section shell ---- */
main .section {
  padding: 56px 0;
  border-bottom: 1px solid var(--rule);
}

main .section:last-of-type { border-bottom: none; }

.section h2 {
  font-family: var(--serif);
  font-size: 1.9rem;
  margin: 0 0 8px;
}

.section .section-note {
  color: rgba(237, 228, 211, 0.65);
  max-width: 60ch;
  margin: 0 0 32px;
}

/* ---- Codex entry panels (replaces generic cards) ---- */
.entry {
  background: var(--parchment);
  color: var(--text-on-parchment);
  border: 1px solid #cbbd9d;
  padding: 24px 26px;
  margin-bottom: 18px;
}

.entry:last-child { margin-bottom: 0; }

.entry .entry-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  padding: 0;
}

.entry h3 {
  font-family: var(--serif);
  font-size: 1.3rem;
  margin: 0;
}

.entry .tag {
  font-size: 0.78rem;
  color: var(--rust);
  white-space: nowrap;
  border: 1px solid var(--rust);
  padding: 2px 9px;
}

.entry .entry-body {
  margin-top: 14px;
  max-width: 62ch;
  display: none;
}

.entry.open .entry-body { display: block; }

.entry .entry-body p { margin: 0 0 10px; }
.entry .entry-body p:last-child { margin-bottom: 0; }

.entry .stat-line {
  font-family: var(--sans);
  font-size: 0.9rem;
  color: #52472f;
  margin-top: 10px;
}

.entry .chevron {
  font-family: var(--serif);
  font-size: 1.1rem;
  color: var(--rust);
  transition: transform 0.2s ease;
}

.entry.open .chevron { transform: rotate(90deg); }

/* ---- Filters (bestiary) ---- */
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.filters button {
  font-family: var(--sans);
  font-size: 0.85rem;
  background: none;
  border: 1px solid var(--rule);
  color: var(--text-on-ink);
  padding: 7px 14px;
  cursor: pointer;
}

.filters button:hover { border-color: var(--gold); }

.filters button.active {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--ink);
}

/* ---- Dice roller ---- */
.roller {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 28px;
}

.roller select,
.roller button.roll {
  font-family: var(--sans);
  font-size: 0.95rem;
  padding: 10px 16px;
  border: 1px solid var(--rule);
  background: var(--ink-soft);
  color: var(--text-on-ink);
}

.roller button.roll {
  background: var(--rust);
  border-color: var(--rust);
  color: var(--parchment);
  cursor: pointer;
  font-weight: 600;
}

.roller button.roll:hover { background: #8f3436; }

.result-stage {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 30px 0;
}

.die-face {
  width: 96px;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 2.4rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--parchment);
  border: 1px solid var(--gold);
  transform: rotate(-3deg);
  transition: transform 0.15s ease;
}

.die-face.rolling { animation: shake 0.4s ease; }

@keyframes shake {
  0% { transform: rotate(-3deg) scale(1); }
  30% { transform: rotate(6deg) scale(1.05); }
  60% { transform: rotate(-8deg) scale(0.97); }
  100% { transform: rotate(-3deg) scale(1); }
}

.result-meta {
  font-size: 0.95rem;
  color: rgba(237, 228, 211, 0.75);
}

.result-meta .roll-total {
  font-family: var(--serif);
  font-size: 1.1rem;
  color: var(--gold);
}

.history {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history li {
  font-size: 0.82rem;
  border: 1px solid var(--rule);
  padding: 5px 10px;
  color: rgba(237, 228, 211, 0.8);
}

.history .empty { border: none; padding: 0; color: rgba(237, 228, 211, 0.4); }

/* ---- Footer ---- */
footer.site {
  padding: 32px 0 48px;
  color: rgba(237, 228, 211, 0.5);
  font-size: 0.85rem;
}

/* ---- Focus states ---- */
a:focus-visible,
button:focus-visible,
select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .die-face.rolling { animation: none; }
}

@media (max-width: 600px) {
  nav.pages { gap: 16px; }
  .result-stage { flex-direction: column; align-items: flex-start; }
}
