/* Better To Best Research Hub: shared stylesheet (S41).
   One header, footer, type scale and colour system for the front page, the papers index and the wiki.
   Light and dark follow the reader's system setting; the theme button in the header overrides it.
   Header and footer markup is generated by tools/apply_site_shell.py (never edit it by hand in a page). */

:root {
  color-scheme: light;
  --bg: #fbfaf7;
  --surface: #f4f2ec;
  --surface-raised: #ffffff;
  --text: #1c2330;
  --text-muted: #4d5666;
  --border: #dedad0;
  --border-strong: #c4bfb2;
  --primary: #243b66;
  --primary-dark: #172a4d;
  --on-primary: #ffffff;
  --accent: #2a4d8f;
  --accent-light: #eaeff8;
  --gold: #85641a;
  --success: #1f6b3f;
  --success-bg: #e9f5ee;
  --success-line: #a9d5bb;
  --warn: #8a4b0b;
  --warn-bg: #fbf1e0;
  --warn-line: #e3c48e;
  --info-line: #b9c9e6;
  --new: #6b21a8;
  --new-bg: #f6eefc;
  --new-line: #dcc3f0;
  --shadow: 0 1px 2px rgba(28,35,48,.06), 0 6px 24px rgba(28,35,48,.06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Courier New", monospace;
  --radius: 10px;
  --measure: 70ch;
  --header-h: 64px;
  /* category colours (white text sits on them in both themes) */
  --cco-color: #047857;
  --ptf-color: #6d28d9;
  --pth-color: #b91c1c;
  --szh-color: #c2410c;
  --cip-color: #0e7490;
  --eco-color: #1e40af;
  --gov-color: #be123c;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e131b;
    --surface: #151c27;
    --surface-raised: #1a2331;
    --text: #e8ebf1;
    --text-muted: #aab3c2;
    --border: #2a3545;
    --border-strong: #3b4a5f;
    --primary: #a9c1f0;
    --primary-dark: #c6d6f6;
    --on-primary: #0e131b;
    --accent: #8fb0ee;
    --accent-light: #1a2740;
    --gold: #d7b36a;
    --success: #6fcf97;
    --success-bg: #12281d;
    --success-line: #25513a;
    --warn: #f0b765;
    --warn-bg: #2a2012;
    --warn-line: #5d4519;
    --info-line: #2f4670;
    --new: #d8b4fe;
    --new-bg: #25183a;
    --new-line: #4a3375;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 24px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e131b;
  --surface: #151c27;
  --surface-raised: #1a2331;
  --text: #e8ebf1;
  --text-muted: #aab3c2;
  --border: #2a3545;
  --border-strong: #3b4a5f;
  --primary: #a9c1f0;
  --primary-dark: #c6d6f6;
  --on-primary: #0e131b;
  --accent: #8fb0ee;
  --accent-light: #1a2740;
  --gold: #d7b36a;
  --success: #6fcf97;
  --success-bg: #12281d;
  --success-line: #25513a;
  --warn: #f0b765;
  --warn-bg: #2a2012;
  --warn-line: #5d4519;
  --info-line: #2f4670;
  --new: #d8b4fe;
  --new-bg: #25183a;
  --new-line: #4a3375;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 24px rgba(0,0,0,.3);
}

/* ── Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 12px); }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; height: auto; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--primary-dark); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
::selection { background: var(--accent-light); }
h1, h2, h3, h4 { font-family: var(--serif); color: var(--text); line-height: 1.25; font-weight: 600; letter-spacing: -.005em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2.5rem 0; }
code, pre, kbd { font-family: var(--mono); font-size: .92em; }
pre { background: var(--surface); border: 1px solid var(--border); padding: .9rem 1rem; overflow: auto; border-radius: 8px; }
table { border-collapse: collapse; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 1.5rem; }
.container.narrow { max-width: 960px; }
.skip-link { position: absolute; left: -9999px; top: 0; z-index: 1000; background: var(--primary); color: var(--on-primary); padding: .6rem 1rem; border-radius: 0 0 8px 0; font-size: .95rem; text-decoration: none; }
.skip-link:focus { left: 0; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Site header ───────────────────────────────────── */
.site-header { position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--border); }
.header-inner { display: flex; align-items: center; gap: 1rem; min-height: var(--header-h); flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: .65rem; text-decoration: none; color: var(--text); font-family: var(--serif); font-size: 1.15rem; font-weight: 600; letter-spacing: -.005em; margin-right: auto; padding: .35rem 0; }
.brand:hover { color: var(--text); text-decoration: none; }
.brand img { width: 32px; height: 32px; display: block; }
.brand em { font-style: normal; color: var(--gold); }
.site-nav { display: flex; align-items: center; gap: .15rem; flex-wrap: wrap; }
.site-nav a { display: inline-block; padding: .45rem .8rem; border-radius: 999px; color: var(--text-muted); text-decoration: none; font-size: .95rem; font-weight: 500; }
.site-nav a:hover { color: var(--text); background: var(--surface); }
.site-nav a[aria-current="page"] { color: var(--primary); background: var(--accent-light); }
.header-tools { display: flex; align-items: center; gap: .5rem; }
.theme-toggle, .nav-toggle { font: inherit; font-size: .9rem; border: 1px solid var(--border-strong); background: var(--surface-raised); color: var(--text); border-radius: 999px; padding: .4rem .85rem; cursor: pointer; line-height: 1.2; }
.theme-toggle:hover, .nav-toggle:hover { border-color: var(--primary); }
.nav-toggle { display: none; }
.header-search { display: flex; align-items: stretch; }
.header-search input { font: inherit; font-size: .92rem; width: 15rem; padding: .42rem .9rem; border: 1px solid var(--border-strong); border-right: 0; border-radius: 999px 0 0 999px; background: var(--surface-raised); color: var(--text); }
.header-search input::placeholder { color: var(--text-muted); opacity: 1; }
.header-search button { font: inherit; font-size: .9rem; padding: .42rem 1rem; border: 1px solid var(--primary); background: var(--primary); color: var(--on-primary); border-radius: 0 999px 999px 0; cursor: pointer; font-weight: 600; }
.header-search button:hover { background: var(--primary-dark); }
@media (max-width: 860px) {
  .nav-toggle { display: inline-block; }
  .site-nav { display: none; width: 100%; order: 5; flex-direction: column; align-items: stretch; padding: .25rem 0 .75rem; }
  .site-nav.open { display: flex; }
  .site-nav a { padding: .65rem .9rem; border-radius: 8px; }
  .header-search { order: 6; width: 100%; padding-bottom: .75rem; }
  .header-search input { width: 100%; flex: 1; }
}

/* ── Page header (the title block under the site header) ── */
.page-header { background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%); border-bottom: 1px solid var(--border); padding: 3.25rem 0 2.5rem; text-align: center; }
.page-header h1 { font-size: clamp(1.9rem, 4.2vw, 2.8rem); margin: 0 0 .75rem; }
.page-header .subtitle, .page-header p { max-width: 46rem; margin: 0 auto; color: var(--text-muted); font-size: 1.1rem; }
.page-header .eyebrow, .eyebrow { display: block; font-family: var(--sans); font-size: .78rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); margin-bottom: .8rem; }
.header-stats { display: flex; justify-content: center; gap: 2.5rem; flex-wrap: wrap; margin-top: 2rem; }
.stat { text-align: center; }
.stat-n { display: block; font-family: var(--serif); font-size: 1.9rem; font-weight: 600; color: var(--primary); line-height: 1.1; }
.stat-l { display: block; font-size: .85rem; color: var(--text-muted); margin-top: .2rem; }
.about-strip { background: var(--accent-light); border-bottom: 1px solid var(--info-line); padding: .7rem 0; font-size: .9rem; color: var(--text-muted); text-align: center; }
.about-strip strong { color: var(--text); }

/* ── Main and prose ─────────────────────────────────── */
main { display: block; padding: 3rem 0 4rem; }
.prose { max-width: 860px; }
.prose > section, main.prose section { margin-bottom: 3rem; }
.prose h1 { font-size: clamp(1.9rem, 4vw, 2.6rem); margin: 0 0 1rem; }
.prose h2 { font-size: 1.65rem; margin: 2.4rem 0 .8rem; padding-bottom: .45rem; border-bottom: 1px solid var(--border); }
.prose h3 { font-size: 1.3rem; margin: 2rem 0 .6rem; }
.prose h4 { font-size: 1.08rem; margin: 1.5rem 0 .4rem; font-family: var(--sans); font-weight: 650; }
.prose p, .prose li { max-width: var(--measure); }
.prose ul, .prose ol { padding-left: 1.4rem; }
.prose li { margin-bottom: .35rem; }
.prose table { width: 100%; font-size: .95rem; margin: 1.25rem 0; }
.prose th, .prose td { overflow-wrap: anywhere; }
.prose th, .prose td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.prose th { font-weight: 650; color: var(--text); background: var(--surface); border-bottom: 1px solid var(--border-strong); }
.prose article { margin: 1.5rem 0; }

/* ── Buttons, badges, cards ─────────────────────────── */
.btn-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.btn { display: inline-block; font: inherit; font-size: .95rem; font-weight: 600; padding: .65rem 1.3rem; border-radius: 999px; background: var(--primary); color: var(--on-primary); border: 1px solid var(--primary); text-decoration: none; cursor: pointer; transition: background .15s ease, transform .15s ease; }
.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: var(--on-primary); text-decoration: none; transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary); color: var(--on-primary); }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: .15rem .6rem; border-radius: 999px; border: 1px solid transparent; }
.badge-live { background: var(--success-bg); color: var(--success); border-color: var(--success-line); }
.badge-beta { background: var(--accent-light); color: var(--primary); border-color: var(--info-line); }
.badge-new { background: var(--new-bg); color: var(--new); border-color: var(--new-line); }

.card-grid { display: grid; gap: 1.1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); margin-top: 1.4rem; }
.card { display: flex; flex-direction: column; background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.35rem 1.4rem; text-decoration: none; color: var(--text); transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease; }
a.card:hover { border-color: var(--primary); box-shadow: var(--shadow); transform: translateY(-2px); color: var(--text); text-decoration: none; }
.card h3 { font-size: 1.15rem; margin: 0 0 .4rem; }
.card p { margin: 0; color: var(--text-muted); font-size: .95rem; line-height: 1.55; }
.card .card-kicker { font-size: .72rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); margin-bottom: .5rem; }
.card .card-go { margin-top: auto; padding-top: .9rem; font-size: .9rem; font-weight: 600; color: var(--accent); }
.card .card-go::after { content: " \2192"; }

/* ── Front page ─────────────────────────────────────── */
.hero { text-align: center; padding: 4.5rem 0 3.5rem; background: radial-gradient(ellipse at 50% 0%, var(--accent-light) 0%, transparent 65%); border-bottom: 1px solid var(--border); }
.hero h1 { font-size: clamp(2.1rem, 5.2vw, 3.4rem); margin: 0 auto .9rem; max-width: 18ch; }
.hero .lede { font-size: 1.2rem; color: var(--text-muted); max-width: 42rem; margin: 0 auto 1.8rem; }
.hero .btn-row { justify-content: center; }
.home-section { padding: 3.25rem 0 2.3rem; border-bottom: 1px solid var(--border); }
.home-section .prose > section:last-child { margin-bottom: 0; }
.home-section:last-of-type { border-bottom: 0; }
.home-section > .container > h2 { font-size: clamp(1.5rem, 3vw, 2rem); margin: 0 0 .5rem; }
.home-section .section-intro { color: var(--text-muted); max-width: var(--measure); margin: 0 0 1.5rem; }
.findings-box { background: var(--surface-raised); border: 1px solid var(--border); border-left: 4px solid var(--gold); border-radius: var(--radius); padding: 1.4rem 1.6rem; box-shadow: var(--shadow); max-width: 62rem; }
.findings-box p { margin: 0 0 .8rem; max-width: var(--measure); }
.findings-box p:last-child { margin-bottom: 0; }
.help-list { display: grid; gap: .8rem; padding: 0; list-style: none; max-width: 52rem; }
.help-list li { background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1.2rem; margin: 0; }
.civic { margin-top: 2.5rem; padding: 1.5rem 1.75rem; background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--border-strong); border-radius: var(--radius); }
.civic h2 { margin: 0 0 .6rem; padding: 0; border: 0; font-family: var(--sans); font-size: .85rem; letter-spacing: .12em; text-transform: uppercase; color: var(--text-muted); }
.civic .note { font-size: .9rem; color: var(--text-muted); font-style: italic; }
.civic blockquote { margin: 0 0 1rem; font-family: var(--serif); font-size: 1.15rem; font-style: italic; }

/* mark and its construction note */
.btb-mark-wrap { display: flex; align-items: center; justify-content: center; gap: .75em; margin-bottom: .5rem; }
.btb-mark-button { background: none; border: 0; padding: 0; margin: 0; cursor: pointer; line-height: 0; border-radius: 50%; }
.btb-mark-button img { width: 56px; height: 56px; display: block; transition: transform .2s ease; }
.btb-mark-button:hover img { transform: scale(1.05); }
.btb-geometry-note { max-width: 560px; margin: 0 auto 1.5rem; padding: .9rem 1.1rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; font-size: .92em; color: var(--text-muted); text-align: left; display: none; }
.btb-geometry-note[data-open="true"] { display: block; }
.btb-geometry-note h2 { margin: 0 0 .4em; font-size: 1rem; color: var(--primary); border: 0; padding: 0; }
.btb-geometry-note p { margin: 0 0 .6em; }
.btb-geometry-note table { width: 100%; font-size: .88em; display: table; margin: 0; }
.btb-geometry-note td { padding: 2px 0; border: 0; }
.btb-geometry-note td:last-child { text-align: right; color: var(--text); }
.paper-type-badge { background: var(--primary); color: var(--on-primary); padding: 6px 14px; border-radius: 4px; font-size: 13px; font-weight: 600; display: inline-block; margin-bottom: 16px; text-transform: uppercase; letter-spacing: .5px; }

/* paper list (papers index) */
.paper-item { list-style: none; margin: 0 0 1.1rem; padding: 1.25rem 1.4rem; background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius); }
.prose ul:has(> .paper-item) { padding-left: 0; }
.paper-item h3 { margin: 0 0 .5rem; font-size: 1.12rem; }
.paper-item p { margin: .4rem 0; color: var(--text-muted); font-size: .96rem; }

/* ── Site footer ────────────────────────────────────── */
.site-footer { background: var(--surface); border-top: 1px solid var(--border); padding: 2.5rem 0 3rem; font-size: .92rem; color: var(--text-muted); }
.site-footer p { margin: 0 0 .5rem; max-width: 60rem; }
.footer-links { display: flex; flex-wrap: wrap; gap: .35rem 1.4rem; margin-top: 1.1rem; }
.footer-links a { color: var(--text); text-decoration: none; font-weight: 500; }
.footer-links a:hover { color: var(--accent); text-decoration: underline; }

/* ── Print ──────────────────────────────────────────── */
@media print {
  .site-header, .nav-toggle, .theme-toggle, .skip-link { display: none !important; }
  body { background: #fff; color: #000; }
  a { color: #000; text-decoration: underline; }
}

/* ── Small screens ──────────────────────────────────── */
@media (max-width: 640px) {
  body { font-size: 1rem; }
  .container { padding: 0 1.1rem; }
  .page-header { padding: 2.25rem 0 1.75rem; }
  .hero { padding: 3rem 0 2.5rem; }
  .header-stats { gap: 1.5rem; }
  main { padding: 2rem 0 3rem; }
  .brand { font-size: 1.02rem; }
  .brand em { display: none; }
}

/* ── Breadcrumb row (wiki and papers) ──────────────── */
.crumbs { border-bottom: 1px solid var(--border); background: var(--bg); font-size: .88rem; }
.breadcrumb { display: flex; flex-wrap: wrap; gap: .45rem; padding: .6rem 0; color: var(--text-muted); }
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb [aria-current="page"] { color: var(--text); font-weight: 600; }

/* ── Front page extras ─────────────────────────────── */
.home-section .prose { max-width: 1120px; }
.home-section .prose > section > h2 { margin-top: 0; }
.callout { margin: 2rem 0; padding: 1.25rem 1.5rem; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 8px; }
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.ontology-wrap { background: var(--surface); }
.home-top { display: none; position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 40; width: 2.75rem; height: 2.75rem; border-radius: 50%; border: 1px solid var(--border-strong); background: var(--surface-raised); color: var(--text); font-size: 1.1rem; cursor: pointer; box-shadow: var(--shadow); line-height: 1; }
.home-top.show { display: block; }
.corrections-note { max-width: 1120px; margin: 0 auto; padding: 1rem 1.5rem; font-size: .88rem; color: var(--text-muted); }
