/* ==========================================================================
   CF Dictionary — stylesheet
   A scholarly reference site. Serif body, generous whitespace,
   restrained accent, dark mode that feels like ink on warm paper.
   No framework. No flash. Function first.
   ========================================================================== */

/* ---------- Tokens ------------------------------------------------------- */
:root {
  /* type */
  --font-serif: "Iowan Old Style", "Source Serif 4", "Source Serif Pro",
    Charter, "Sitka Text", Cambria, Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
    "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;

  --fs-h1: clamp(2rem, 1.4rem + 2.4vw, 3.25rem);
  --fs-h2: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
  --fs-h3: 1.25rem;
  --fs-body: 1.0625rem;
  --fs-small: 0.875rem;
  --fs-eyebrow: 0.78rem;

  --lh-body: 1.65;
  --lh-tight: 1.25;

  --measure: 66ch;
  --container: 1180px;

  /* light palette — warm paper */
  --paper: #fbf8f1;
  --paper-2: #f3ede0;
  --ink: #1b1916;
  --ink-2: #4a443c;
  --ink-3: #80766a;
  --rule: #e2d8c4;
  --rule-2: #d4c8af;
  --accent: #9f4f2b;
  --accent-2: #6a3416;
  --accent-bg: #f1e5d8;
  --link: #6a3416;
  --link-visited: #4a1f0e;
  --hover: #c2683b;
  --code-bg: #efe7d3;
  --selection: #f3d8a8;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.04), 0 12px 24px -16px rgba(60, 40, 16, 0.18);
}

[data-theme="dark"] {
  /* dark palette — deep ink, warm cream text */
  --paper: #13110e;
  --paper-2: #1c1814;
  --ink: #ece4d3;
  --ink-2: #c8bfac;
  --ink-3: #8d8472;
  --rule: #2c2620;
  --rule-2: #3a3127;
  --accent: #d27a4c;
  --accent-2: #f0a978;
  --accent-bg: #2a1d14;
  --link: #e9a877;
  --link-visited: #c78559;
  --hover: #f0a978;
  --code-bg: #1f1a14;
  --selection: #4a3018;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.4), 0 12px 32px -16px rgba(0, 0, 0, 0.6);
}

/* respect OS theme on auto (default); explicit data-theme on html wins */
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    color-scheme: dark;
    --paper: #13110e;
    --paper-2: #1c1814;
    --ink: #ece4d3;
    --ink-2: #c8bfac;
    --ink-3: #8d8472;
    --rule: #2c2620;
    --rule-2: #3a3127;
    --accent: #d27a4c;
    --accent-2: #f0a978;
    --accent-bg: #2a1d14;
    --link: #e9a877;
    --link-visited: #c78559;
    --hover: #f0a978;
    --code-bg: #1f1a14;
    --selection: #4a3018;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.4), 0 12px 32px -16px rgba(0, 0, 0, 0.6);
  }
}

/* ---------- Base --------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-rendering: optimizeLegibility; }

body {
  margin: 0;
  font-family: var(--font-serif);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--ink);
  background: var(--paper);
  font-feature-settings: "kern", "liga", "onum";
  font-variant-numeric: oldstyle-nums;
  transition: background-color 120ms ease, color 120ms ease;
}

::selection { background: var(--selection); }

a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  text-decoration-color: var(--rule-2);
  transition: color 120ms ease, text-decoration-color 120ms ease;
}
a:hover { color: var(--hover); text-decoration-color: currentColor; }
a:visited { color: var(--link-visited); }

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  line-height: var(--lh-tight);
  color: var(--ink);
  margin: 0 0 0.5em;
  letter-spacing: -0.01em;
  font-weight: 600;
}
h1 { font-size: var(--fs-h1); letter-spacing: -0.02em; }
h2 { font-size: var(--fs-h2); margin-top: 1.6em; }
h3 { font-size: var(--fs-h3); margin-top: 1.4em; }
h4 { font-size: 1.05rem; margin-top: 1.2em; }

p { margin: 0 0 1em; }
small, .small { font-size: var(--fs-small); }

hr { border: 0; border-top: 1px solid var(--rule); margin: 2em 0; }

code, pre, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.92em;
}
code {
  background: var(--code-bg);
  padding: 0.08em 0.32em;
  border-radius: 3px;
  border: 1px solid var(--rule);
}
pre {
  background: var(--code-bg);
  padding: 1em;
  border-radius: 4px;
  border: 1px solid var(--rule);
  overflow-x: auto;
  margin: 1em 0;
}
pre code { background: none; padding: 0; border: 0; }

blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.2em 0;
  padding: 0.25em 1em;
  color: var(--ink-2);
  font-style: italic;
}

ul, ol { padding-left: 1.4em; }
li { margin: 0.2em 0; }

img, svg { max-width: 100%; height: auto; display: block; }

/* ---------- Layout ------------------------------------------------------ */
.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ---------- Header ------------------------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(140%) blur(6px);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.85rem;
  padding-bottom: 0.85rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
  color: var(--ink);
}
.brand:hover { color: var(--ink); }
.brand-mark {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  line-height: 1;
  width: 2rem; height: 2rem;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  font-style: italic;
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
}
.brand-title {
  display: block;
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  line-height: 1.05;
}
.brand-sub {
  display: block;
  font-family: var(--font-sans);
  font-size: 0.74rem;
  letter-spacing: 0.02em;
  color: var(--ink-3);
  text-transform: uppercase;
}
.site-nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-family: var(--font-sans);
  font-size: 0.92rem;
}
.site-nav a {
  color: var(--ink-2);
  text-decoration: none;
  padding: 0.25rem 0;
  border-bottom: 1px solid transparent;
}
.site-nav a:hover { color: var(--ink); border-bottom-color: var(--accent); }
.site-nav a[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}
.theme-toggle {
  background: transparent;
  border: 1px solid var(--rule-2);
  color: var(--ink-2);
  width: 2.1rem; height: 2.1rem;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-icon {
  width: 1rem; height: 1rem;
  display: inline-block;
  position: relative;
}
/* Default icon = sun (we're in light, want to go dark) */
html[data-theme="light"] .theme-icon,
html[data-theme="auto"] .theme-icon {
  background: currentColor;
  -webkit-mask: radial-gradient(circle, transparent 38%, currentColor 40%);
          mask: radial-gradient(circle, transparent 38%, currentColor 40%);
  border-radius: 50%;
}
html[data-theme="dark"] .theme-icon {
  background: currentColor;
  -webkit-mask: radial-gradient(circle at 50% 50%, currentColor 38%, transparent 40%);
          mask: radial-gradient(circle at 50% 50%, currentColor 38%, transparent 40%);
  border-radius: 50%;
  box-shadow: 0.6rem 0.6rem 0 -0.45rem currentColor, -0.6rem 0.6rem 0 -0.45rem currentColor, 0 -0.7rem 0 -0.4rem currentColor;
}

/* ---------- Hero --------------------------------------------------------- */
.hero {
  padding: 3.5rem 0 2.5rem;
  border-bottom: 1px solid var(--rule);
}
.hero h1 {
  margin: 0.25rem 0 1rem;
  font-size: clamp(2.5rem, 1.6rem + 3.5vw, 4.25rem);
  letter-spacing: -0.025em;
  font-weight: 600;
}
.eyebrow {
  font-family: var(--font-sans);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: var(--fs-eyebrow);
  color: var(--accent);
  margin: 0 0 0.5rem;
  font-weight: 500;
}
.lede {
  font-size: 1.2rem;
  line-height: 1.55;
  color: var(--ink-2);
  max-width: 50ch;
  margin: 0 0 1.5rem;
}
.hero-meta { margin-top: 1.5rem; }

.btn {
  display: inline-block;
  padding: 0.55rem 1rem;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  text-decoration: none;
  border-radius: 2px;
  transition: background-color 120ms ease, color 120ms ease;
}
.btn:hover { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.btn-ghost {
  background: transparent;
  color: var(--ink);
}
.btn-ghost:hover {
  background: var(--ink);
  color: var(--paper);
}

/* ---------- Foundations ------------------------------------------------- */
.foundations { padding: 2.5rem 0 1rem; }
.foundations h2 {
  margin-top: 0;
  font-size: 1.4rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.5rem;
  margin-bottom: 1.5rem;
}
.foundation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
}
.foundation {
  --accent: var(--accent);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--accent);
  background: var(--paper-2);
  padding: 1.25rem 1.25rem 1rem;
  border-radius: 2px;
}
.foundation h3 {
  font-size: 1.05rem;
  margin: 0 0 0.5rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.foundation .abbr {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
}
.foundation p { margin: 0.25rem 0; font-size: 0.96rem; color: var(--ink-2); }
.foundation .meta { font-size: 0.82rem; color: var(--ink-3); font-family: var(--font-sans); }
.foundation .more {
  display: inline-block;
  margin-top: 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--accent);
  border-bottom: 1px solid transparent;
}
.foundation .more:hover { border-bottom-color: var(--accent); }

/* ---------- Term sections (home) ---------------------------------------- */
.term-section {
  padding: 2.25rem 0 1rem;
  border-top: 1px solid var(--rule);
  margin-top: 1.5rem;
}
.term-section:first-of-type { border-top: 0; margin-top: 0; }
.term-section h2 {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-top: 0;
}
.term-section .count {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--ink-3);
  font-weight: 400;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.6rem 1.5rem;
}
.card {
  padding: 0.6rem 0;
  border-top: 1px dotted var(--rule);
}
.card:first-child { border-top: 0; }
.card h3 {
  font-size: 1rem;
  margin: 0 0 0.2rem;
  font-weight: 500;
}
.card h3 a {
  text-decoration: none;
  color: var(--ink);
  border-bottom: 1px solid transparent;
}
.card h3 a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.card p {
  margin: 0;
  font-size: 0.92rem;
  color: var(--ink-2);
  line-height: 1.5;
}

/* ---------- Term page layout ------------------------------------------- */
.layout-grid {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 3rem;
  max-width: var(--container);
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}
@media (max-width: 880px) {
  .layout-grid { grid-template-columns: 1fr; gap: 1.5rem; }
  .sidebar { position: static !important; }
}

.sidebar {
  position: sticky;
  top: 5rem;
  align-self: start;
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
  padding-right: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--rule-2) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--rule-2); border-radius: 3px; }
.sidebar-inner {
  font-family: var(--font-sans);
  font-size: 0.9rem;
}
#nav-filter {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--rule-2);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-family: var(--font-sans);
  border-radius: 2px;
  margin-bottom: 1rem;
}
#nav-filter:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.nav-section { margin-bottom: 1.25rem; }
.nav-section h3 {
  font-family: var(--font-sans);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 0.5rem;
  font-weight: 600;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.25rem;
}
.nav-section ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-section li {
  margin: 0;
  line-height: 1.35;
}
.nav-section li.is-current a {
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
}
.nav-section a {
  display: block;
  padding: 0.18rem 0 0.18rem 0.65rem;
  text-decoration: none;
  color: var(--ink-2);
  border-left: 2px solid transparent;
  margin-left: -2px;
  transition: color 80ms ease, border-color 80ms ease;
}
.nav-section a:hover {
  color: var(--accent);
  border-left-color: var(--accent-2);
}
.nav-section.hidden { display: none; }
.nav-section li.hidden { display: none; }

/* ---------- Term page -------------------------------------------------- */
.term {
  max-width: var(--measure);
}
.term-header {
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1.25rem;
  margin-bottom: 1.5rem;
}
.term-eyebrow {
  font-family: var(--font-sans);
  font-size: var(--fs-eyebrow);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-3);
  margin: 0 0 0.6rem;
}
.term-eyebrow a { color: var(--ink-3); text-decoration: none; border-bottom: 1px solid transparent; }
.term-eyebrow a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.term-header h1 {
  font-size: clamp(2rem, 1.3rem + 2.5vw, 3rem);
  margin: 0 0 0.5rem;
}
.term-summary {
  font-size: 1.1rem;
  line-height: 1.5;
  color: var(--ink-2);
  margin: 0.5rem 0 0;
  font-style: italic;
}
.aliases {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--ink-3);
  margin: 0.75rem 0 0;
}
.aliases::before { content: "Also: "; font-style: italic; color: var(--ink-3); }

.prose { font-size: 1.0625rem; line-height: var(--lh-body); }
.prose p { margin: 0 0 1em; }
.prose h2 {
  font-size: 1.5rem;
  margin-top: 1.8em;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.25em;
}
.prose h3 {
  font-size: 1.15rem;
  margin-top: 1.5em;
}
.prose ul, .prose ol { margin: 0 0 1em; }
.prose li { margin: 0.3em 0; }
.prose blockquote {
  font-style: italic;
  color: var(--ink-2);
}
.prose a { /* inherits */ }
.prose a.xref {
  text-decoration-style: dotted;
  text-decoration-color: var(--rule-2);
}
.prose a.xref:hover { text-decoration-style: solid; }
.prose code { font-size: 0.9em; }

/* See-also */
.see-also {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}
.see-also h2 {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-3);
  border-bottom: 0;
  margin: 0 0 0.6rem;
  padding: 0;
}
.see-also ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.6rem;
  font-family: var(--font-sans);
  font-size: 0.92rem;
}
.see-also li { margin: 0; }
.see-also a {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--rule-2);
  border-radius: 2px;
  text-decoration: none;
  color: var(--ink-2);
  background: var(--paper);
}
.see-also a:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}

.term-footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--rule);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--ink-3);
}
.term-footer a { color: var(--ink-3); }
.term-footer a:hover { color: var(--accent); }

/* ---------- Prose pages (about, sources) ------------------------------ */
.prose-page {
  max-width: var(--measure);
  padding: 2.5rem 1.25rem 4rem;
}
.prose-page h1 {
  font-size: clamp(2rem, 1.4rem + 2vw, 2.8rem);
  margin-bottom: 1rem;
}
.prose-page h2 {
  font-size: 1.4rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.3em;
  margin-top: 2em;
}

/* sources */
.source-item {
  border-left: 2px solid var(--rule-2);
  padding: 0.25rem 0 0.25rem 1rem;
  margin: 0 0 1.25rem;
}
.source-item h3 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
}
.source-item .role {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--ink-3);
  margin: 0 0 0.4rem;
}

/* ---------- Footer ----------------------------------------------------- */
.site-footer {
  margin-top: 4rem;
  border-top: 1px solid var(--rule);
  background: var(--paper-2);
  padding: 2rem 0;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--ink-3);
}
.site-footer a { color: var(--ink-2); }
.site-footer a:hover { color: var(--accent); }

/* ---------- Mobile tweaks ---------------------------------------------- */
@media (max-width: 640px) {
  .brand-sub { display: none; }
  .site-nav { gap: 0.85rem; font-size: 0.85rem; }
  .hero { padding: 2.5rem 0 1.5rem; }
  .foundations { padding: 1.5rem 0 0.5rem; }
  .layout-grid { padding: 1.25rem 1rem 3rem; }
}

/* ---------- Reduced motion --------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
  }
}

/* ---------- Print ------------------------------------------------------- */
@media print {
  .site-header, .site-footer, .sidebar, .theme-toggle { display: none; }
  .layout-grid { grid-template-columns: 1fr; }
  body { background: #fff; color: #000; }
  a { color: #000; text-decoration: underline; }
  a[href]::after { content: " (" attr(href) ")"; font-size: 0.8em; }
}
