:root {
  --bg: #120d0a;
  --surface: #241711;
  --surface-2: #332018;
  --surface-3: #3e2a1f;
  --text: #f5ead7;
  --muted: #cdbb9f;
  --line: rgba(230, 184, 113, 0.2);
  --accent: #c9843f;
  --accent-2: #e0b66e;
  --accent-deep: #7d321f;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: radial-gradient(circle at 16% 0%, rgba(125, 50, 31, 0.26), transparent 32%), radial-gradient(circle at 90% 10%, rgba(201, 132, 63, 0.13), transparent 30%), linear-gradient(180deg, #1a100c 0%, var(--bg) 42%, #0d0907 100%);
  color: var(--text);
  font-family: Inter, Segoe UI, Arial, sans-serif;
  line-height: 1.5;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: linear-gradient(rgba(230, 184, 113, 0.035) 1px, transparent 1px), linear-gradient(90deg, rgba(230, 184, 113, 0.025) 1px, transparent 1px);
  background-size: 56px 56px, 56px 56px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.68), transparent 74%);
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
h1, h2, h3, p { margin-top: 0; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 72px;
  padding: 14px clamp(18px, 4vw, 56px);
  background: rgba(18, 13, 10, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 34px;
  border: 1px solid rgba(224, 182, 110, 0.72);
  border-radius: 8px;
  background: linear-gradient(145deg, #3b2117, #1b100c);
  color: var(--accent-2);
  font-size: 0.8rem;
  font-weight: 900;
}

.main-nav { display: flex; align-items: center; gap: 6px; }
.main-nav a {
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}
.main-nav a:hover, .main-nav a.active { background: rgba(224, 182, 110, 0.1); color: var(--text); }

.hero {
  position: relative;
  min-height: calc(100vh - 72px);
  display: grid;
  align-items: end;
  padding: clamp(70px, 12vh, 130px) clamp(18px, 5vw, 72px) clamp(58px, 9vh, 92px);
  overflow: hidden;
}
.hero-media {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(18, 13, 10, 0.94), rgba(39, 24, 17, 0.68) 46%, rgba(66, 36, 22, 0.18)), linear-gradient(0deg, rgba(13, 9, 7, 0.95), rgba(18, 13, 10, 0.12) 48%), url('assets/hero-tabletop.svg?v=3') center / cover no-repeat;
  filter: sepia(0.18) saturate(1.16) contrast(1.08);
  transform: scale(1.01);
}
.hero-media::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 74% 56%, rgba(224, 128, 52, 0.24), transparent 32%), radial-gradient(circle at 54% 34%, rgba(230, 184, 113, 0.13), transparent 34%), linear-gradient(90deg, transparent, rgba(18, 13, 10, 0.16));
  pointer-events: none;
}
.hero-content { position: relative; width: min(760px, 100%); }
.eyebrow { margin: 0 0 10px; color: var(--accent); font-size: 0.78rem; font-weight: 800; letter-spacing: 0; text-transform: uppercase; }
h1 { margin-bottom: 18px; font-size: clamp(2.4rem, 7vw, 5.8rem); line-height: 0.96; letter-spacing: 0; }
h2 { margin-bottom: 14px; font-size: clamp(1.9rem, 4vw, 3.4rem); line-height: 1.05; letter-spacing: 0; }
h3 { margin-bottom: 8px; font-size: 1.2rem; }
.hero-copy, .page-intro p, .feature-card p, .catalog-card p, .timeline p, .term-block p, .reader-body p, .term-list dd { color: var(--muted); }
.hero-copy { width: min(650px, 100%); margin-bottom: 28px; font-size: clamp(1rem, 2vw, 1.2rem); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 800;
}
.button.primary { background: linear-gradient(180deg, #e0b66e, var(--accent)); color: #18140d; box-shadow: 0 10px 28px rgba(201, 132, 63, 0.22); }
.button.secondary { border-color: var(--line); background: rgba(230, 184, 113, 0.08); }

.stats-band { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stats-band div { padding: 24px clamp(18px, 4vw, 56px); background: #1a100c; }
.stats-band strong { display: block; color: var(--accent-2); font-size: clamp(1.55rem, 3vw, 2.6rem); }
.stats-band span, .site-footer, .intro-panel span { color: var(--muted); }

.section, .page-intro { padding: clamp(54px, 8vw, 92px) clamp(18px, 5vw, 72px); }
.section-heading { width: min(760px, 100%); margin-bottom: 28px; }
.feature-grid, .catalog-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.rule-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

.feature-card, .catalog-card, .rule-card, .term-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(230, 184, 113, 0.055), transparent 42%), var(--surface);
  box-shadow: var(--shadow);
}
.feature-card, .catalog-card, .rule-card { min-height: 230px; padding: 22px; }
.rule-card { display: block; min-height: 260px; transition: transform 160ms ease, border-color 160ms ease, background 160ms ease; }
.rule-card:hover, .feature-card.is-linked:hover, .catalog-card:hover { transform: translateY(-2px); border-color: rgba(224, 182, 110, 0.58); background: var(--surface-2); }
.feature-card.is-active { border-color: rgba(224, 182, 110, 0.6); background: linear-gradient(135deg, rgba(125, 50, 31, 0.32), transparent 46%), var(--surface-2); }
.feature-icon { display: inline-grid; place-items: center; width: 42px; height: 42px; margin-bottom: 22px; border-radius: 50%; background: rgba(201, 132, 63, 0.16); color: var(--accent-2); font-weight: 900; }

.split-section { display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1fr); gap: clamp(24px, 6vw, 80px); border-top: 1px solid var(--line); }
.timeline { display: grid; gap: 14px; margin: 0; padding: 0; list-style: none; }
.timeline li { padding: 18px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 8px 8px 0; }
.timeline span { display: block; margin-bottom: 4px; color: var(--accent); font-weight: 900; }
.timeline p { margin-bottom: 0; }

.page-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  align-items: end;
  gap: 28px;
  background: radial-gradient(circle at 86% 8%, rgba(224, 182, 110, 0.15), transparent 28%), linear-gradient(135deg, rgba(125, 50, 31, 0.32), transparent 42%), #1a100c;
  border-bottom: 1px solid var(--line);
}
.page-intro h1 { font-size: clamp(2.6rem, 7vw, 5.4rem); }
.rule-intro { align-items: center; }
.intro-panel { padding: 20px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.intro-panel strong { display: block; color: var(--accent); font-size: 3rem; line-height: 1; }

.filters { display: grid; grid-template-columns: minmax(220px, 520px); gap: 14px; padding: 24px clamp(18px, 5vw, 72px); border-bottom: 1px solid var(--line); background: #120d0a; }
.filters label { display: grid; gap: 8px; color: var(--muted); font-size: 0.88rem; font-weight: 700; }
input { width: 100%; min-height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); }

.catalog-section { padding: 42px clamp(18px, 5vw, 72px) 0; }
.catalog-section + .catalog-section { margin-top: 22px; border-top: 1px solid var(--line); }
.catalog-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.catalog-heading h2 { margin-bottom: 0; }
.catalog-heading > span { display: grid; place-items: center; min-width: 54px; height: 42px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--accent-2); font-weight: 900; }
.catalog-workspace { display: block; min-height: calc(100vh - 72px); padding-bottom: clamp(52px, 8vw, 88px); }
.catalog-workspace.is-open { display: grid; grid-template-columns: minmax(0, 1fr) minmax(170px, 230px); align-items: start; gap: 18px; }
.catalog-card { position: relative; display: grid; width: 100%; min-height: 190px; overflow: hidden; color: inherit; cursor: pointer; text-align: left; transition: transform 160ms ease, border-color 160ms ease, background 160ms ease; }
.catalog-card::before { content: ''; position: absolute; inset: 0 0 auto; height: 4px; background: linear-gradient(90deg, var(--accent-deep), var(--accent-2), var(--accent)); }
.catalog-card span { align-self: end; margin-bottom: 10px; color: var(--text); font-size: 1.45rem; font-weight: 900; }
.catalog-card p { margin-bottom: 0; }
.title-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.title-card { min-height: 150px; }
.title-card span { align-self: center; margin-bottom: 0; }

.catalog-reader {
  min-height: calc(100vh - 176px);
  padding: clamp(26px, 5vw, 58px);
  border: 1px solid rgba(224, 182, 110, 0.32);
  border-radius: 8px;
  background: radial-gradient(circle at 88% 0%, rgba(224, 182, 110, 0.12), transparent 28%), linear-gradient(135deg, rgba(125, 50, 31, 0.2), transparent 34%), var(--surface);
  box-shadow: var(--shadow);
}
.reader-close { min-height: 40px; margin-bottom: 42px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; background: rgba(230, 184, 113, 0.08); color: var(--text); cursor: pointer; font-weight: 800; }
.catalog-reader h2 { margin-bottom: 18px; font-size: clamp(3rem, 9vw, 7rem); line-height: 0.88; }
.reader-summary { max-width: 860px; margin-bottom: clamp(28px, 5vw, 54px); color: var(--text); font-size: clamp(1.15rem, 2vw, 1.55rem); }
.reader-body { display: grid; grid-template-columns: 1.25fr 0.75fr; gap: 18px; }
.reader-body.single-reader { grid-template-columns: 1fr; }
.reader-body section { padding: 20px; border: 1px solid var(--line); border-radius: 8px; background: rgba(230, 184, 113, 0.045); }
.reader-body section:first-child { grid-row: span 2; }
.reader-body.single-reader section:first-child { grid-row: auto; }
.reader-body h3 { color: var(--accent); }
.reader-body p { margin-bottom: 0; }

.catalog-rail, .rule-sidebar { position: sticky; top: 96px; display: grid; align-content: start; gap: 8px; max-height: calc(100vh - 120px); overflow: auto; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #1a100c; }
.rail-title { margin: 0 0 6px; color: var(--accent); font-size: 0.8rem; font-weight: 900; text-transform: uppercase; }
.rail-item, .rule-sidebar a { min-height: 42px; padding: 10px 12px; border: 1px solid transparent; border-radius: 8px; background: rgba(230, 184, 113, 0.055); color: var(--muted); cursor: pointer; font-weight: 800; text-align: left; }
.rail-item:hover, .rule-sidebar a:hover, .rule-sidebar a.active { border-color: rgba(224, 182, 110, 0.5); background: rgba(201, 132, 63, 0.16); color: var(--text); }

.empty-state { margin: 0 clamp(18px, 5vw, 72px) 72px; padding: 24px; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); text-align: center; }
.rule-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 22px; padding: 34px clamp(18px, 5vw, 72px) clamp(64px, 8vw, 96px); }
.rule-sidebar { overflow: visible; }
.rule-content { display: grid; gap: 16px; }
.term-block { padding: clamp(22px, 4vw, 34px); }
.term-block h2 { font-size: clamp(1.5rem, 3vw, 2.2rem); }
.term-block p { margin-bottom: 0; }
.term-list { display: grid; gap: 12px; margin: 0; }
.term-list div { padding: 14px 16px; border: 1px solid var(--line); border-radius: 8px; background: rgba(230, 184, 113, 0.045); }
.term-list dt { margin-bottom: 4px; color: var(--text); font-weight: 900; }
code { color: var(--accent-2); font-family: Cascadia Mono, Consolas, monospace; }

.site-footer { display: flex; justify-content: space-between; gap: 18px; padding: 28px clamp(18px, 5vw, 72px); border-top: 1px solid var(--line); background: #0d0907; color: var(--muted); font-size: 0.9rem; }

@media (max-width: 980px) {
  .feature-grid, .catalog-grid, .rule-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-section, .page-intro, .catalog-workspace.is-open, .rule-layout, .reader-body { grid-template-columns: 1fr; }
  .intro-panel { width: min(260px, 100%); }
  .catalog-rail { position: static; grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: none; }
  .rule-sidebar { position: static; grid-template-columns: repeat(3, minmax(0, 1fr)); max-height: none; }
  .rail-title { grid-column: 1 / -1; }
}

@media (max-width: 680px) {
  .site-header, .site-footer { align-items: flex-start; flex-direction: column; }
  .main-nav { width: 100%; overflow-x: auto; }
  .hero { min-height: 760px; }
  .stats-band, .feature-grid, .catalog-grid, .title-grid, .catalog-rail, .rule-grid, .rule-sidebar, .filters { grid-template-columns: 1fr; }
  .feature-card, .catalog-card, .rule-card { min-height: auto; }
}
