/*
 * academic.css — plain-HTML design system
 * Black & white. One size. Grid-centric. System fonts.
 *
 * A hard pivot from the brutalist-academic theme: no color, no type scale.
 * Hierarchy comes from weight, case, hairline rules, and spacing — not size.
 * Every element is 1rem; the only smaller things are true superscripts and
 * the superscript citation/footnote reference markers (positioned notation,
 * not part of the hierarchy). All prior selectors are preserved and restyled
 * so consuming tools keep working.
 */

/* ===== VARIABLES ===== */
:root {
  /* System fonts only — zero downloads */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --font-serif: Georgia, "Times New Roman", serif; /* only for the .serif opt-in */

  /* One size, everywhere */
  --size: 16px;
  --gap: 16px;

  /* Palette: black, white, and greys between. That's it. */
  --text: #000;
  --text-muted: #555;
  --text-faint: #888;
  --bg: #fff;
  --bg-muted: #f2f2f2;
  --bg-surface: #f7f7f7;
  --border: #000;        /* strong hairline — the grid */
  --border-light: #d0d0d0;
  --link: #000;
  --link-visited: #555;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: var(--size); }
body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
}
ul, ol { list-style: none; }
img { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; }

/* ===== TYPOGRAPHY ===== */
/* One size. Hierarchy from weight, case, and rules — never scale. */
h1, h2, h3, h4, h5, h6 {
  font-size: 1rem;
  font-family: var(--font-sans);
  font-weight: 700;
  line-height: 1.3;
}
h1 { text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 16px; padding-bottom: 8px; border-bottom: 2px solid var(--text); }
h2 { margin-top: 40px; margin-bottom: 12px; padding-top: 12px; border-top: 1px solid var(--text); }
h3 { margin-top: 28px; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 400; color: var(--text-muted); }
h4 { margin-top: 20px; margin-bottom: 8px; }
h5, h6 { margin-top: 16px; margin-bottom: 4px; font-weight: 400; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
p { margin-bottom: 1em; }

/* Links — black, underlined; invert on hover. No color anywhere. */
a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
a:visited { color: var(--link-visited); }
a:hover { background: var(--text); color: var(--bg); text-decoration: none; }

/* "Small" text is de-emphasized by colour, not size (one size everywhere). */
small, .small, .text-sm, .text-xs { font-size: 1rem; color: var(--text-muted); }
/* Superscripts/subscripts are positioned notation, so they keep their scale. */
sup, sub { font-size: 0.75em; line-height: 0; position: relative; vertical-align: baseline; }
sup { top: -0.5em; }
sub { bottom: -0.25em; }

/* ===== ELEMENTS ===== */
hr { border: none; border-top: 1px solid var(--text); margin: 20px 0; }
ul.list, ol.list { margin: 8px 0; padding-left: 1.5em; }
ul.list { list-style: disc; }
ol.list { list-style: decimal; }

table { border-collapse: collapse; width: 100%; margin: var(--gap) 0; }
th, td { border: 1px solid var(--text); padding: 6px 10px; text-align: left; }
th { background: var(--bg-muted); font-weight: 700; }
table.compact th, table.compact td { padding: 3px 6px; }
table.borderless th, table.borderless td { border: none; }

code { font-family: var(--font-mono); background: var(--bg-muted); padding: 2px 5px; }
pre { font-family: var(--font-mono); background: var(--bg-muted); padding: 12px; overflow-x: auto; margin: var(--gap) 0; border: 1px solid var(--text); }
pre code { background: none; padding: 0; }

input, select, textarea { font-family: var(--font-sans); border: 1px solid var(--text); padding: 5px 8px; background: var(--bg); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--text); outline-offset: 1px; border-color: var(--text); }

/* ===== COMPONENTS ===== */
.btn { font-family: var(--font-sans); background: var(--bg); border: 1px solid var(--text); padding: 5px 12px; cursor: pointer; text-decoration: none; color: var(--text); display: inline-block; }
.btn:hover { background: var(--text); color: var(--bg); }
.action { color: var(--link); text-decoration: underline; cursor: pointer; background: none; border: none; padding: 0; font: inherit; }

.tag { display: inline-block; font-family: var(--font-mono); background: var(--bg-muted); border: 1px solid var(--text); padding: 2px 6px; }
.badge { display: inline-block; padding: 1px 5px; border: 1px solid var(--text); }
.callout { padding: 12px 16px; background: var(--bg-muted); border-left: 3px solid var(--text); margin: 12px 0; }
.callout.alert { border-left-style: double; border-left-width: 5px; } /* was red — now a doubled rule */
.card { background: var(--bg); border: 1px solid var(--text); padding: 12px 16px; }
.empty { color: var(--text-muted); font-style: italic; padding: 20px; text-align: center; }

/* Status — encoded in weight/underline instead of colour */
.status-ok, .status-success { color: var(--text); }
.status-warning { color: var(--text); font-weight: 700; }
.status-error, .status-critical { color: var(--text); font-weight: 700; text-decoration: underline; }
.alert { color: var(--text); font-weight: 700; text-decoration: underline; }

/* ===== UTILITIES ===== */
/* Text */
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--font-mono); }
.sans { font-family: var(--font-sans); }
.serif { font-family: var(--font-serif); }
.uppercase { text-transform: uppercase; }
/* Data: monospace for numbers, metadata, stats — emphasis via weight, not size */
.data, .num, .stat, .meta { font-family: var(--font-mono); }
.data-lg { font-family: var(--font-mono); font-weight: 700; }
.data-xl { font-family: var(--font-mono); font-weight: 700; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Spacing (scale: 1=4px, 2=8px, 3=12px, 4=16px, 5=20px) */
.m-0 { margin: 0; } .m-2 { margin: 8px; } .m-4 { margin: 16px; }
.mt-0 { margin-top: 0; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-5 { margin-top: 20px; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-5 { margin-bottom: 20px; }
.ml-2 { margin-left: 8px; } .ml-3 { margin-left: 12px; } .ml-4 { margin-left: 16px; }
.mr-2 { margin-right: 8px; }
.p-0 { padding: 0; } .p-2 { padding: 8px; } .p-3 { padding: 12px; } .p-4 { padding: 16px; }
.px-2 { padding-left: 8px; padding-right: 8px; } .py-2 { padding-top: 8px; padding-bottom: 8px; }
.pt-4 { padding-top: 16px; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }

/* Layout — grid-first */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.items-center { align-items: center; }
.items-baseline { align-items: baseline; }
.justify-between { justify-content: space-between; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid-2 { display: grid; gap: var(--gap); grid-template-columns: repeat(2, 1fr); }
.grid-3 { display: grid; gap: var(--gap); grid-template-columns: repeat(3, 1fr); }
.grid-4 { display: grid; gap: var(--gap); grid-template-columns: repeat(4, 1fr); }
.w-full { width: 100%; }
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* Borders */
.border { border: 1px solid var(--border); }
.border-t { border-top: 1px solid var(--border); }
.border-b { border-bottom: 1px solid var(--border); }
.rounded { border-radius: 3px; }

/* Backgrounds */
.bg-muted { background: var(--bg-muted); }

/* Display */
.hidden { display: none; }
.inline { display: inline; }
.block { display: block; }

/* ===== DARK MODE ===== */
/* White-on-black greyscale — system preference (unless .light) or manual .dark */
@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --text: #fff; --text-muted: #aaa; --text-faint: #777;
    --bg: #000; --bg-muted: #141414; --bg-surface: #0d0d0d;
    --border: #fff; --border-light: #333;
    --link: #fff; --link-visited: #aaa;
  }
  :root:not(.light) img { opacity: 0.9; }
}
:root.dark {
  --text: #fff; --text-muted: #aaa; --text-faint: #777;
  --bg: #000; --bg-muted: #141414; --bg-surface: #0d0d0d;
  --border: #fff; --border-light: #333;
  --link: #fff; --link-visited: #aaa;
}
:root.dark img { opacity: 0.9; }

/* ===== PRINT ===== */
@media print {
  body { max-width: none; padding: 0; }
  a { color: #000; text-decoration: underline; }
  .btn { display: none; }
}

/* === CITATION SYSTEM (Gwern-inspired) === */
/* Reference markers stay superscript-small; everything else follows the palette. */

/* Primary source: external, verifiable ground truth */
.cite-primary { text-decoration: underline; text-underline-offset: 2px; }
.cite-primary::after {
  content: attr(data-src);
  font-family: var(--font-mono);
  font-size: 0.65em; vertical-align: super; margin-left: 1px;
  opacity: 0.6;
}
.cite-primary:hover::after { opacity: 1; }

/* Internal cross-ref: our own interpretation layer */
.cite-internal { text-decoration: underline dotted var(--text-faint); text-underline-offset: 2px; }
.cite-internal::after {
  content: attr(data-src);
  font-family: var(--font-mono);
  font-size: 0.65em; vertical-align: super; color: var(--text-faint); margin-left: 1px;
  opacity: 0.5;
}
.cite-internal:hover::after { opacity: 1; }

/* Entity cross-reference with source count */
.xref { text-decoration: underline dotted var(--text-faint); text-underline-offset: 2px; cursor: help; }
.xref[data-n]::after {
  content: attr(data-n);
  font-family: var(--font-mono);
  font-size: 0.6em; vertical-align: super; color: var(--text-faint); margin-left: 1px;
  opacity: 0.5;
}
.xref:hover { text-decoration-color: var(--text); }
.xref:hover::after { opacity: 1; color: var(--text-muted); }

/* Link type glyphs — Gwern-style typographic post-fix indicators */
.cite-primary[href$=".pdf"]::before { content: "pdf "; font-family: var(--font-mono);
  font-size: 0.6em; text-transform: uppercase; color: var(--text-muted); }

/* Ruby citation annotations */
ruby.cite rt { font-size: 0.7em; font-family: var(--font-mono); }
ruby.cite-primary rt { color: inherit; }
ruby.cite-internal rt { color: var(--text-faint); }

/* === SIDENOTES (wide screens) / FOOTNOTES (narrow) === */
/* Note bodies are full size; only the superscript reference marker is small. */
.sidenote-ref { font-size: 0.65em; vertical-align: super; font-family: var(--font-mono);
  cursor: pointer; color: var(--text-muted); text-decoration: none; }
.sidenote-ref:hover { color: var(--text); }

.sidenote { line-height: 1.4; color: var(--text-muted);
  border-left: 1px solid var(--border-light); padding-left: 8px; margin-bottom: 8px; }
.sidenote .sidenote-number { font-family: var(--font-mono);
  color: var(--text-faint); margin-right: 4px; }

@media (min-width: 1201px) {
  .sidenote { position: absolute; right: -280px; width: 250px;
    margin: 0; float: right; clear: right; }
  body.has-margin .sidenote { right: -260px; width: 230px; }
}

/* Footnote sections — Gwern style: compact, hierarchical */
.fn-sources, .fn-crossrefs { line-height: 1.5; }
.fn-sources { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 32px; }
.fn-crossrefs { border-top: 1px dotted var(--text-faint); padding-top: 8px; margin-top: 8px; }
.fn-sources dt, .fn-crossrefs dt { font-family: var(--font-mono);
  float: left; width: 32px; color: var(--text-muted); }
.fn-sources dd, .fn-crossrefs dd { margin-left: 36px; margin-bottom: 2px; }

/* === LINK POPUP PREVIEWS === */
/* Gwern-style hover popup for annotated links */
.link-popup { position: absolute; z-index: 200; background: var(--bg);
  border: 1px solid var(--border); padding: 10px 14px; max-width: 420px;
  line-height: 1.5;
  box-shadow: 0 4px 16px color-mix(in srgb, var(--text) 12%, transparent);
  pointer-events: none; opacity: 0; transition: opacity 0.15s; }
.link-popup.visible { opacity: 1; pointer-events: auto; }
.link-popup .popup-title { font-family: var(--font-sans); font-weight: 700;
  margin-bottom: 4px; }
.link-popup .popup-meta { font-family: var(--font-mono);
  color: var(--text-muted); margin-bottom: 4px; }
.link-popup .popup-excerpt { color: var(--text); }
.link-popup .popup-source-badge { display: inline-block; font-family: var(--font-mono);
  padding: 1px 4px; border: 1px solid var(--border);
  color: var(--text-muted); margin-right: 4px; }
.link-popup .popup-source-badge.primary { border-bottom: 2px solid var(--text); }
.link-popup .popup-source-badge.internal { border-bottom: 2px dotted var(--text-faint); }

/* Standardized margin sidebar */
.margin-aside { position: fixed; right: 0; top: 60px; width: 260px;
  max-height: calc(100vh - 80px); overflow-y: auto; padding: 12px;
  border-left: 1px solid var(--border-light); background: var(--bg); z-index: 50; }
.margin-aside h4 { font-style: italic; margin: 12px 0 4px;
  border-top: 1px solid var(--border-light); padding-top: 8px; }
.margin-aside h4:first-child { border-top: none; margin-top: 0; }
@media (max-width: 1200px) { .margin-aside { display: none; } }
@media (min-width: 1201px) { body.has-margin { padding-right: 280px; } }
