/* Codex Project base stylesheet. Requires codex-tokens.css first.
   Modes: pages default to light (sustained reading). Add class="cx-context-dark" to <html>
   on marketing pages, which default to dark. A device set to dark always gets dark, and an
   explicit data-theme="light" or "dark" on <html> (from a user toggle) wins over both. */

/* Fonts: self-hosted, SIL Open Font Licence 1.1 (see /fonts) */
@font-face { font-family: 'Atkinson Hyperlegible Next'; src: url('../fonts/AtkinsonHyperlegibleNext-Variable.woff2') format('woff2'); font-weight: 200 800; font-style: normal; font-display: swap; }
@font-face { font-family: 'Atkinson Hyperlegible Next'; src: url('../fonts/AtkinsonHyperlegibleNext-Italic-Variable.woff2') format('woff2'); font-weight: 200 800; font-style: italic; font-display: swap; }
@font-face { font-family: 'Atkinson Hyperlegible Mono'; src: url('../fonts/AtkinsonHyperlegibleMono-Variable.woff2') format('woff2'); font-weight: 200 800; font-style: normal; font-display: swap; }
@font-face { font-family: 'Instrument Sans'; src: url('../fonts/InstrumentSans-Variable.woff2') format('woff2'); font-weight: 400 700; font-stretch: 75% 100%; font-style: normal; font-display: swap; }

/* Semantic colours: light (default) */
:root {
  --bg: var(--cx-paper); --fg: var(--cx-ink); --fg-muted: var(--cx-text-muted-on-paper);
  --rule: var(--cx-rule-on-paper); --surface: #EAE6DB; --focus: var(--cx-ink);
  --button-bg: var(--cx-ink); --button-fg: var(--cx-paper);
  --body-weight: 400; --body-lh: var(--cx-lh-body);
  color-scheme: light;
}
/* Dark: marketing context, device preference, or explicit choice */
html.cx-context-dark:not([data-theme="light"]), html[data-theme="dark"] {
  --bg: var(--cx-ink); --fg: var(--cx-paper); --fg-muted: var(--cx-text-muted-on-ink);
  --rule: #33363F; --surface: #1E2027; --focus: var(--cx-highlighter);
  --button-bg: var(--cx-highlighter); --button-fg: var(--cx-ink);
  --body-weight: 400; --body-lh: 1.7; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: var(--cx-ink); --fg: var(--cx-paper); --fg-muted: var(--cx-text-muted-on-ink);
    --rule: #33363F; --surface: #1E2027; --focus: var(--cx-highlighter);
    --button-bg: var(--cx-highlighter); --button-fg: var(--cx-ink);
    --body-lh: 1.7; color-scheme: dark;
  }
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(env(safe-area-inset-top, 0px) + 16px); }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--cx-font-text); font-size: var(--cx-size-body); line-height: var(--body-lh);
  font-weight: var(--body-weight); font-variant-numeric: tabular-nums;
  text-align: left; hyphens: manual; overflow-wrap: break-word;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
img, svg, video { max-width: 100%; height: auto; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 2px; }
.cx-skip { position: absolute; left: -9999px; top: 0; }
.cx-skip:focus { left: var(--cx-space-4); top: var(--cx-space-4); z-index: 100; background: var(--cx-highlighter); color: var(--cx-ink); padding: var(--cx-space-2) var(--cx-space-4); }
.cx-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Type scale. Instrument Sans only at 32 px and above. */
h1, h2, .cx-display-xl, .cx-display-l, .cx-display-m { font-family: var(--cx-font-display); font-weight: 500; letter-spacing: -0.015em; margin: 0 0 var(--cx-space-5); }
.cx-display-xl { font-size: clamp(40px, 7vw, var(--cx-size-display-xl)); line-height: var(--cx-lh-display-xl); }
h1, .cx-display-l { font-size: clamp(36px, 5vw, var(--cx-size-display-l)); line-height: var(--cx-lh-display-l); }
h2, .cx-display-m { font-size: var(--cx-size-display-m); line-height: var(--cx-lh-display-m); margin-top: var(--cx-space-8); }
h3 { font-family: var(--cx-font-text); font-size: var(--cx-size-heading); line-height: var(--cx-lh-heading); font-weight: 700; margin: var(--cx-space-7) 0 var(--cx-space-3); }
h4 { font-size: var(--cx-size-body); font-weight: 700; margin: var(--cx-space-6) 0 var(--cx-space-2); }
p, ul, ol, dl, blockquote, figure, table { margin: 0 0 var(--cx-space-5); }
.cx-lead { font-size: var(--cx-size-lead); line-height: var(--cx-lh-lead); }
small, .cx-small { font-size: var(--cx-size-small); line-height: var(--cx-lh-small); }
.cx-muted { color: var(--fg-muted); }
.cx-label { font-size: var(--cx-size-label); line-height: var(--cx-lh-label); }
em, i, cite { font-style: italic; } /* titles, the Codex product noun and brief emphasis only */
.cx-num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* The highlighter: one per view, key idea only. Same in both modes. */
mark, .cx-highlight { background: var(--cx-highlighter); color: var(--cx-ink); padding: 0 0.08em; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.cx-wipe { background-image: linear-gradient(var(--cx-highlighter), var(--cx-highlighter)); background-repeat: no-repeat; background-color: transparent; background-size: 100% 100%; animation: cx-wipe var(--cx-wipe) ease-out both; }
@keyframes cx-wipe { from { background-size: 0 100%; color: inherit; } to { background-size: 100% 100%; color: var(--cx-ink); } }

/* Layout */
.cx-container { width: 100%; max-width: var(--cx-container); margin-inline: auto; padding-inline: var(--cx-gutter); }
.cx-prose { max-width: var(--cx-measure); }
.cx-section { padding-block: var(--cx-space-8); }
.cx-grid { display: grid; gap: var(--cx-space-6); grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }

/* Site header, navigation and running head */
.cx-header { border-bottom: 1px solid var(--rule); }
.cx-header-inner { display: flex; align-items: center; justify-content: space-between; gap: var(--cx-space-5); min-height: 80px; flex-wrap: wrap; padding-block: var(--cx-space-3); }
.cx-logo { display: inline-flex; line-height: 0; }
.cx-logo img { height: 40px; width: auto; } /* one-line lockup; mark height stays above the 28 px minimum */
.cx-nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--cx-space-2) var(--cx-space-6); }
.cx-nav a { display: inline-flex; align-items: center; min-height: var(--cx-touch); text-decoration: none; }
.cx-nav a:hover, .cx-nav a[aria-current="page"] { text-decoration: underline; }
.cx-running-head { border-bottom: 1px solid var(--rule); font-size: var(--cx-size-small); color: var(--fg-muted); padding-block: var(--cx-space-3); } /* course lesson pages only */

/* Buttons: yellow on dark grounds; Ink on Paper, because yellow fails on Paper */
.cx-button { display: inline-flex; align-items: center; justify-content: center; min-height: var(--cx-touch); padding: 0 var(--cx-space-5); border-radius: var(--cx-radius); border: 1.5px solid transparent; font: 700 var(--cx-size-body)/1 var(--cx-font-text); text-decoration: none; background: var(--button-bg); color: var(--button-fg); cursor: pointer; }
.cx-button-secondary { background: transparent; color: var(--fg); border-color: var(--fg-muted); font-weight: 500; }

/* Ink panels: every screen chart and diagram sits on Ink, in both modes */
.cx-panel-ink { background: var(--cx-ink); color: var(--cx-paper); border-radius: var(--cx-radius); padding: var(--cx-space-6); }
.cx-panel-ink :focus-visible { outline-color: var(--cx-highlighter); }
.cx-source { font-family: var(--cx-font-mono); font-size: var(--cx-size-label); line-height: var(--cx-lh-label); color: var(--cx-text-muted-on-ink); margin: var(--cx-space-4) 0 0; }
figcaption { font-size: var(--cx-size-small); line-height: var(--cx-lh-small); color: var(--fg-muted); margin-top: var(--cx-space-3); }

/* References: linked superscripts, labelled for screen readers ("Reference 3") */
sup.cx-ref a { text-decoration: none; padding: 0 0.1em; }
.cx-references { font-size: var(--cx-size-small); line-height: var(--cx-lh-small); }

/* Tables */
.cx-table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; vertical-align: top; padding: var(--cx-space-3) var(--cx-space-4) var(--cx-space-3) 0; border-bottom: 1px solid var(--rule); }
thead th { font-size: var(--cx-size-small); font-weight: 500; color: var(--fg-muted); border-bottom: 2px solid var(--fg); }

/* Footer */
.cx-footer { border-top: 1px solid var(--rule); padding-block: var(--cx-space-7); font-size: var(--cx-size-small); color: var(--fg-muted); }

/* Motion: gentle, and off when the user asks */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* Logo swaps with the mode: Ink one-colour on Paper, full colour on Ink */
.cx-logo .on-dark { display: none; }
html.cx-context-dark:not([data-theme="light"]) .cx-logo .on-dark, html[data-theme="dark"] .cx-logo .on-dark { display: block; }
html.cx-context-dark:not([data-theme="light"]) .cx-logo .on-light, html[data-theme="dark"] .cx-logo .on-light { display: none; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .cx-logo .on-dark { display: block; }
  html:not([data-theme="light"]) .cx-logo .on-light { display: none; }
}
