/* ============ TOKENS ============ */
:root {
  /* surfaces */
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f6fa;
  --ink: #1a1a1a;
  --ink-2: #3a3a3a;
  --muted: #6a6a6a;
  --line: #e2e6ed;
  --line-strong: #c4cad4;

  /* brand palette — the defaults happen to be the SBF suit colors but
     accent variants below make the site trivially rebrandable */
  --sbf-red: #c8102e;
  --sbf-blue: #1a4d8f;
  --sbf-blue-dark: #0f3b75;
  --sbf-gold: #e8a01e;
  --sbf-bronze: #8a7540;

  --accent: var(--sbf-blue);
  --accent-hover: var(--sbf-blue-dark);
  --accent-tint: #e8f0fa;
  --accent-contrast: #ffffff;

  --felt: var(--accent);
  --felt-2: var(--accent-hover);
  --hearts: var(--sbf-red);
  --gold: var(--sbf-gold);
  --focus: #ffb000;

  --fs-base: 19px;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.15rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 2rem;
  --fs-3xl: 2.75rem;
  --fs-4xl: 4rem;
  --fs-5xl: 6rem;

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "SF Mono", Consolas, monospace;

  --row-pad: 14px;
  --radius: 4px;
  --radius-lg: 8px;

  --container: 1240px;
  --container-wide: 1400px;
}

html[data-text-size="s"] { --fs-base: 17px; }
html[data-text-size="m"] { --fs-base: 19px; }
html[data-text-size="l"] { --fs-base: 22px; }
html[data-text-size="xl"] { --fs-base: 26px; }

html[data-accent="blue"] {
  --accent: var(--sbf-blue);
  --accent-hover: var(--sbf-blue-dark);
  --accent-tint: #e8f0fa;
  --accent-contrast: #ffffff;
  --felt: var(--accent); --felt-2: var(--accent-hover);
}
html[data-accent="red"] {
  --accent: var(--sbf-red);
  --accent-hover: #a50d25;
  --accent-tint: #fbe8ec;
  --accent-contrast: #ffffff;
  --felt: var(--accent); --felt-2: var(--accent-hover);
}
html[data-accent="green"] {
  --accent: #1a6b3e;
  --accent-hover: #0f5530;
  --accent-tint: #e6f2ec;
  --accent-contrast: #ffffff;
  --felt: var(--accent); --felt-2: var(--accent-hover);
}

html[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c232c;
  --ink: #e8ecf2;
  --ink-2: #b8bfc9;
  --muted: #8a919c;
  --line: #2a313b;
  --line-strong: #3a424d;
  --accent-tint: rgba(26, 77, 143, 0.15);
}
html[data-theme="dark"][data-accent="blue"] { --accent: #5c9bdc; --accent-hover: #7ab0e5; --accent-contrast: #0d1117; --felt: var(--accent); --felt-2: var(--accent-hover); --accent-tint: rgba(92,155,220,0.15); }
html[data-theme="dark"][data-accent="red"]  { --accent: #ee6579; --accent-hover: #f08091; --accent-contrast: #0d1117; --felt: var(--accent); --felt-2: var(--accent-hover); --accent-tint: rgba(238,101,121,0.15); }
html[data-theme="dark"][data-accent="green"]{ --accent: #5fc088; --accent-hover: #7ed1a0; --accent-contrast: #0d1117; --felt: var(--accent); --felt-2: var(--accent-hover); --accent-tint: rgba(95,192,136,0.15); }

html[data-contrast="high"] {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0f0f0;
  --ink: #000000;
  --ink-2: #000000;
  --muted: #2a2a2a;
  --line: #000000;
  --line-strong: #000000;
  --accent: #000000;
  --accent-hover: #000000;
  --accent-contrast: #ffffff;
  --felt: #000000;
  --felt-2: #000000;
  --hearts: #a00000;
}
html[data-theme="dark"][data-contrast="high"] {
  --bg: #000000;
  --surface: #000000;
  --surface-2: #0a0a0a;
  --ink: #ffffff;
  --ink-2: #ffffff;
  --muted: #e0e0e0;
  --line: #ffffff;
  --line-strong: #ffffff;
  --accent: #ffff66;
  --accent-hover: #ffffff;
  --felt: #ffff66;
  --hearts: #ff8080;
}

html[data-density="compact"] { --row-pad: 8px; }

/* ============ BASE ============ */
* { box-sizing: border-box; }
html { font-size: var(--fs-base); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "kern", "liga";
}

*:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}
a:hover { color: var(--accent-hover); }

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
  text-wrap: balance;
}

.container { max-width: var(--container); margin: 0 auto; padding: 0 28px; }
.container-wide { max-width: var(--container-wide); margin: 0 auto; padding: 0 28px; }

/* ============ SKIP LINK ============ */
.skip-link {
  position: absolute;
  top: -100px; left: 8px;
  background: var(--ink); color: var(--bg);
  padding: 12px 20px;
  z-index: 1000;
  font-weight: 600;
  border-radius: var(--radius);
}
.skip-link:focus { top: 8px; }

/* ============ UTILITY BAR ============ */
.util-bar {
  background: var(--ink);
  color: var(--bg);
  border-bottom: 1px solid var(--line);
}
html[data-theme="dark"] .util-bar { background: var(--surface-2); color: var(--ink); border-bottom-color: var(--line); }

.util-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 28px; gap: 20px;
  max-width: var(--container-wide); margin: 0 auto;
  font-size: 0.85rem;
}
.util-left { display: flex; align-items: center; gap: 18px; color: rgba(255,255,255,0.85); }
html[data-theme="dark"] .util-left { color: var(--muted); }
.util-right { display: flex; align-items: center; gap: 6px; }
.util-btn {
  background: transparent; color: inherit;
  border: 1px solid rgba(255,255,255,0.25);
  padding: 6px 12px; font: inherit; font-size: 0.85rem;
  cursor: pointer; border-radius: var(--radius);
  min-height: 34px;
  display: inline-flex; align-items: center; gap: 6px;
}
html[data-theme="dark"] .util-btn { border-color: var(--line-strong); }
.util-btn:hover { background: rgba(255,255,255,0.1); }
html[data-theme="dark"] .util-btn:hover { background: var(--surface); }
.util-btn[aria-pressed="true"] { background: rgba(255,255,255,0.18); }
.text-size-group { display: inline-flex; border: 1px solid rgba(255,255,255,0.25); border-radius: var(--radius); overflow: hidden; }
html[data-theme="dark"] .text-size-group { border-color: var(--line-strong); }
.text-size-group button {
  background: transparent; color: inherit; border: none;
  padding: 6px 10px; font: inherit; font-family: var(--serif);
  cursor: pointer; min-height: 34px; min-width: 36px;
}
.text-size-group button[aria-pressed="true"] { background: rgba(255,255,255,0.2); font-weight: 700; }
html[data-theme="dark"] .text-size-group button[aria-pressed="true"] { background: var(--surface); }
.text-size-group button:not(:last-child) { border-right: 1px solid rgba(255,255,255,0.2); }
html[data-theme="dark"] .text-size-group button:not(:last-child) { border-right-color: var(--line-strong); }
.ts-s { font-size: 0.75rem; }
.ts-m { font-size: 0.9rem; }
.ts-l { font-size: 1.05rem; }
.ts-xl { font-size: 1.2rem; }

/* ============ PRIMARY NAV ============ */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.nav-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; gap: 24px;
  max-width: var(--container-wide); margin: 0 auto;
}
.brand {
  display: flex; align-items: center; gap: 14px;
  text-decoration: none; color: var(--ink);
}
.brand-mark {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  flex-shrink: 0;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: var(--radius);
  font-family: var(--serif);
  font-size: 1.6rem;
  line-height: 1;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-title { font-family: var(--serif); font-weight: 600; font-size: 1.25rem; letter-spacing: -0.01em; }
.brand-sub { font-size: 0.8rem; color: var(--muted); letter-spacing: 0.02em; text-transform: uppercase; margin-top: 3px; font-weight: 500; }

/* Data-driven menu tree (desktop + drawer share markup, CSS switches layout) */
.nav-mount { display: flex; align-items: center; gap: 4px; flex: 1; justify-content: flex-end; }
.nav-tree { display: flex; gap: 2px; align-items: center; list-style: none; margin: 0; padding: 0; }
.nav-tree a, .nav-tree .nav-dead {
  text-decoration: none;
  color: var(--ink);
  padding: 12px 14px;
  font-weight: 500;
  font-size: 0.98rem;
  border-radius: var(--radius);
  min-height: 44px;
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.nav-tree a:hover { background: var(--surface-2); color: var(--ink); }
.nav-tree a.active { color: var(--felt); font-weight: 600; }
.nav-tree .nav-dead { color: var(--muted); cursor: default; opacity: 0.65; }
.nav-tree .external-icon { width: 10px; height: 10px; opacity: 0.6; }

/* 2nd-level as hover/focus-within popover on desktop */
.nav-tree > li { position: relative; }
.nav-tree > li > .nav-subtree {
  position: absolute;
  top: 100%; left: 0;
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  padding: 8px;
  list-style: none; margin: 4px 0 0;
  display: none;
  z-index: 50;
}
.nav-tree > li:hover > .nav-subtree,
.nav-tree > li:focus-within > .nav-subtree { display: block; }
.nav-tree .nav-subtree a,
.nav-tree .nav-subtree .nav-dead {
  display: block; padding: 10px 14px; border-radius: var(--radius);
  font-size: 0.95rem;
}
.nav-tree .nav-subtree a:hover { background: var(--surface-2); }
.nav-tree .nav-subtree .nav-subtree {
  margin: 4px 0 4px 12px;
  padding-left: 12px;
  border-left: 2px solid var(--line);
  list-style: none;
}
.nav-parent-label { font-weight: 500; }
.nav-parent-label::after { content: "▾"; margin-left: 6px; opacity: 0.5; font-size: 0.8em; }

.menu-toggle {
  display: none;
  background: transparent; border: 1px solid var(--line-strong);
  color: var(--ink); padding: 10px 14px; font: inherit; font-weight: 600;
  border-radius: var(--radius); cursor: pointer; min-height: 44px;
}

.nav-drawer { display: none; }
.nav-drawer-mount .nav-tree { flex-direction: column; align-items: stretch; gap: 0; }
.nav-drawer-mount .nav-tree > li > .nav-subtree {
  position: static; display: block;
  border: none; box-shadow: none; padding: 0 0 8px 20px; margin: 0;
  background: transparent;
}
.nav-drawer-mount .nav-tree a, .nav-drawer-mount .nav-tree .nav-dead {
  display: block; width: 100%;
  border-bottom: 1px solid var(--line);
  padding: 14px 28px; font-size: 1.05rem;
}

@media (max-width: 960px) {
  .nav-mount { display: none; }
  .menu-toggle { display: inline-flex; align-items: center; gap: 8px; }
  .nav-drawer {
    display: none;
    border-top: 1px solid var(--line);
    padding: 8px 0 16px;
    background: var(--surface);
  }
  .nav-drawer.open { display: block; }
}

/* ============ HERO (generic page header) ============ */
.page-hero {
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 64px 0 72px;
  position: relative;
  overflow: hidden;
  border-bottom: 6px solid var(--gold);
}
html[data-theme="dark"] .page-hero { background: var(--surface-2); color: var(--ink); border-bottom-color: var(--gold); }
.page-hero::before {
  content: "";
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,0.08) 0%, transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(0,0,0,0.18) 0%, transparent 50%);
  pointer-events: none;
}
.page-hero-inner { position: relative; z-index: 1; max-width: var(--container); margin: 0 auto; padding: 0 28px; }
.page-hero h1 {
  font-family: var(--serif);
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1.05;
  font-weight: 600;
  color: inherit;
  letter-spacing: -0.02em;
  max-width: 22ch;
}
.page-hero .eyebrow {
  font-family: var(--sans);
  font-size: 0.88rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 24px;
  display: inline-block;
}
.page-hero .preamble {
  font-family: var(--serif);
  font-size: 1.35rem;
  line-height: 1.5;
  max-width: 62ch;
  margin-top: 28px;
  color: inherit;
  opacity: 0.92;
}
.page-hero .preamble p { margin: 0 0 0.8em; }
.page-hero .page-hero-banner {
  margin-top: 40px;
  max-width: 100%;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255,255,255,0.15);
  display: block;
}

/* ============ PAGE BODY / PROSE ============ */
.page-body {
  padding: 64px 0 96px;
}
.prose {
  max-width: 72ch;
  margin: 0 auto;
  font-family: var(--serif);
  font-size: 1.12rem;
  line-height: 1.65;
  color: var(--ink);
}
.prose p { margin: 0 0 1.15em; text-wrap: pretty; }
.prose h2 {
  font-family: var(--serif);
  font-size: 1.9rem;
  line-height: 1.15;
  margin: 2em 0 0.5em;
}
.prose h3 {
  font-family: var(--serif);
  font-size: 1.45rem;
  line-height: 1.2;
  margin: 1.6em 0 0.4em;
}
.prose h4 {
  font-family: var(--sans);
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  margin: 1.4em 0 0.4em;
  color: var(--ink-2);
}
.prose a { color: var(--accent); }
.prose a:hover { color: var(--accent-hover); }
.prose a.dead-link,
.prose .dead-link {
  color: var(--muted);
  text-decoration: line-through;
  cursor: not-allowed;
}
.prose ul, .prose ol { margin: 0 0 1.2em; padding-left: 1.6em; }
.prose li { margin: 0.25em 0; }
.prose blockquote {
  margin: 1.4em 0;
  padding: 0.2em 1.2em;
  border-left: 4px solid var(--felt);
  color: var(--ink-2);
  font-style: italic;
}
.prose code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 0.1em 0.4em;
  border-radius: 3px;
}
.prose pre {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  overflow-x: auto;
  margin: 1.3em 0;
}
.prose img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius);
  margin: 1.4em auto;
}
.prose img[data-unresolved] {
  outline: 2px dashed var(--hearts);
  outline-offset: 2px;
}
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.4em 0;
  font-family: var(--sans);
  font-size: 0.98rem;
}
.prose th, .prose td {
  padding: var(--row-pad) 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.prose th {
  font-family: var(--sans);
  font-weight: 600;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-bottom: 2px solid var(--line-strong);
}
.prose hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 2em 0;
}
.prose .item-list ul { list-style: none; padding: 0; }
.prose .sbf-mini-menu {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 0 0 1.4em;
}
.prose .sbf-mini-menu li { margin: 0; }
.prose .sbf-mini-menu a {
  display: inline-flex; align-items: center;
  padding: 8px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 100px;
  font-family: var(--sans);
  font-size: 0.92rem;
  font-weight: 500;
  text-decoration: none;
  color: var(--ink);
}
.prose .sbf-mini-menu a:hover { background: var(--accent-tint); border-color: var(--felt); color: var(--felt); }

/* ============ ATTACHMENTS ============ */
.attachments {
  max-width: 72ch;
  margin: 64px auto 0;
  padding-top: 32px;
  border-top: 1px solid var(--line);
}
.attachments h2 {
  font-family: var(--sans);
  font-size: 0.85rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 18px;
}
.attachments-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  list-style: none; margin: 0; padding: 0;
}
.attachment {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}
.attachment a {
  display: block;
  font-family: var(--sans);
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--ink);
  text-decoration: none;
  word-break: break-word;
}
.attachment a:hover { color: var(--accent); }
.attachment .meta {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

/* ============ FOOTER ============ */
footer#footer-mount {
  background: var(--ink);
  color: var(--accent-contrast);
  padding: 60px 0 40px;
}
html[data-theme="dark"] footer#footer-mount { background: var(--surface-2); color: var(--ink); }
.footer-inner {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 28px;
  display: flex; flex-direction: column; gap: 20px;
}
.footer-inner h2 {
  color: inherit;
  font-family: var(--serif);
  font-size: 1.4rem;
}
.footer-inner p, .footer-inner a { color: rgba(255,255,255,0.78); line-height: 1.6; font-size: 0.95rem; }
html[data-theme="dark"] .footer-inner p, html[data-theme="dark"] .footer-inner a { color: var(--muted); }
.footer-inner a:hover { color: var(--gold); }
.footer-bottom {
  margin-top: 24px; padding-top: 20px;
  border-top: 1px solid rgba(255,255,255,0.15);
  font-size: 0.85rem;
  color: rgba(255,255,255,0.55);
}
html[data-theme="dark"] .footer-bottom { border-top-color: var(--line); color: var(--muted); }

/* ============ LOAD / EMPTY STATES ============ */
.site-loading, .site-empty {
  max-width: 72ch;
  margin: 120px auto;
  padding: 0 28px;
  font-family: var(--serif);
  font-size: 1.2rem;
  color: var(--muted);
  text-align: center;
}
.site-empty strong { display: block; color: var(--ink); font-size: 1.4rem; margin-bottom: 8px; }

/* ============ SMALL SCREENS ============ */
@media (max-width: 640px) {
  .util-inner { padding: 8px 16px; gap: 10px; flex-wrap: wrap; }
  .util-left { display: none; }
  .nav-inner { padding: 14px 18px; }
  .brand-mark { width: 44px; height: 44px; font-size: 1.2rem; }
  .brand-sub { font-size: 0.72rem; }
  .container, .container-wide { padding: 0 18px; }
  .page-hero { padding: 40px 0 48px; }
  .page-body { padding: 40px 0 64px; }
  .prose { font-size: 1.05rem; }
}

/* ============ PRINT ============ */
@media print {
  .util-bar, .nav, footer#footer-mount, #tweaks-root { display: none !important; }
  body { background: white; color: black; }
  .page-hero { background: white; color: black; padding: 24px 0; border-bottom: 2px solid #000; }
  .page-body { padding: 20px 0; }
  a { color: black; text-decoration: underline; }
  .prose img { page-break-inside: avoid; }
}
