/*
 * Forge base theme.
 *
 * Topic-agnostic: colour, type scale, layout primitives and the shared
 * components every topic site uses. A topic may append its own stylesheet,
 * but should not need to override anything here.
 *
 * Accessibility notes that are load-bearing, not decoration:
 *  - every colour pair below clears WCAG AA (4.5:1 body, 3:1 large/UI)
 *  - focus is always visible and never removed, only restyled
 *  - nothing is conveyed by colour alone
 *  - motion respects prefers-reduced-motion
 */

/* ---------- fonts ---------- */

/*
 * Inter, self-hosted as a single variable file. Self-hosting is what lets the
 * CSP stay at font-src 'self'; a hosted font would need the policy widened to
 * a third party for the sake of one request.
 *
 * The weight axis is the point: the UI asks for 550 and 650, which a static
 * font cannot produce and silently rounds to 400 or 600. With the variable
 * axis declared those weights render as specified.
 *
 * swap, not block: the fallback shows immediately and is replaced when the
 * font lands. A reference table nobody can read for 300ms is a worse failure
 * than one brief reflow.
 */
@font-face {
  font-family: "Inter var";
  /*
   * format("woff2"), not the older "woff2-variations" token — that syntax was
   * an experimental proposal that never standardised, and a browser that does
   * not recognise the token discards the whole src and silently falls back.
   * The variable axis is read from the file itself, so plain woff2 is both
   * correct and universally supported.
   */
  src: url("/fonts/inter-var-latin.f052ee44.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  /*
   * Derived from the file's actual cmap, not copied boilerplate. Two
   * consequences are deliberate: the combining marks (U+0300-0329) are in
   * range so decomposed Spanish accents render in Inter rather than dropping
   * to a fallback mid-word, and braille (U+2800-28FF) is OUT of range because
   * this file contains none — so cells fall straight through to the explicit
   * braille stack below instead of waiting on a download that cannot help.
   */
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
                 U+02DC, U+0300-0329, U+2000-206F, U+2074, U+20AC, U+2122,
                 U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/*
 * Braille cells, self-hosted. 256 glyphs subset from Noto Sans Symbols 2 —
 * under 2 KB, because the shapes are simple and nothing else is kept.
 *
 * This exists so cell rendering does not depend on what the visitor's OS
 * happens to ship. The fallback stack below still names the platform symbol
 * fonts, but on a braille reference the cells are the content, and content
 * should not change shape between a Mac and a Windows machine.
 *
 * Loaded only for U+2800-28FF, so a visitor who never sees a braille
 * character never downloads it.
 */
@font-face {
  font-family: "Braille Cells";
  src: url("/fonts/braille-symbols.548dec9d.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+2800-28FF;
}

/* ---------- tokens ---------- */
:root {
  color-scheme: light dark;

  --bg:            #ffffff;
  --bg-sunken:     #f4f6fa;
  --bg-raised:     #ffffff;
  --border:        #d9dee8;
  --border-strong: #b3bccd;

  --text:          #12161f;
  --text-muted:    #545d70;
  --text-faint:    #6b7385;

  --accent:        #1d4ed8;
  --accent-hover:  #1740b0;
  --accent-soft:   #eaf0ff;
  --accent-text:   #ffffff;

  --dot-raised:    #12161f;
  --dot-empty:     #cdd4e1;

  --ok:            #0f7b46;
  --warn:          #8a5300;
  --ok-soft:       #e6f5ee;
  --warn-soft:     #fdf3e0;

  --radius:        10px;
  --radius-lg:     16px;
  --shadow:        0 1px 2px rgb(16 22 31 / .06), 0 4px 16px rgb(16 22 31 / .06);

  --wrap:          72rem;
  --wrap-narrow:   44rem;

  --ease:          cubic-bezier(.23, 1, .32, 1);

  /*
   * "Braille Cells" sits in the body stack rather than only on a wrapper
   * class. Braille characters turn up in running prose, table cells and hint
   * text — 41 of the built pages contain them, and not all are inside a known
   * element — so the coverage has to be global to be reliable. Its
   * unicode-range means it only ever applies to U+2800-28FF, so naming it
   * second costs nothing for Latin text.
   *
   * The platform symbol fonts stay at the tail as a safety net for the case
   * where the woff2 fails to load.
   */
  --font: "Inter var", "Braille Cells", ui-sans-serif, system-ui, -apple-system,
          "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
          "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols2", "DejaVu Sans";
  --mono: ui-monospace, "Braille Cells", SFMono-Regular, "SF Mono", Menlo,
          Consolas, monospace,
          "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols2", "DejaVu Sans";

  /*
   * Braille cells get their own stack. No text font ships the U+2800-28FF
   * block, so without naming the symbol fonts explicitly each platform picks
   * a different fallback and the same cell renders at a different size and
   * dot spacing per visitor. On a braille reference that is the one
   * inconsistency that undermines the whole page, so the order below is
   * platform-specific and deliberate: Windows, macOS, Android/ChromeOS, Linux.
   */
  --braille: "Braille Cells", "Segoe UI Symbol", "Apple Symbols",
             "Noto Sans Symbols2", "Noto Sans Symbols", "DejaVu Sans",
             "FreeSerif", sans-serif;

  /* Arabic pages: Inter has no Arabic coverage, so name the faces that do. */
  --font-ar: "Noto Naskh Arabic", "Segoe UI", "Geeza Pro", "Traditional Arabic",
             "Noto Sans Arabic", Tahoma, sans-serif;
}

/* RTL locales swap the body stack; everything else inherits unchanged. */
:root:lang(ar), [dir="rtl"] { --font: var(--font-ar); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0e1117;
    --bg-sunken:     #141922;
    --bg-raised:     #171d27;
    --border:        #2a3241;
    --border-strong: #3d485b;

    --text:          #eef1f6;
    --text-muted:    #a8b2c4;
    --text-faint:    #8d97a9;

    --accent:        #7ea2ff;
    --accent-hover:  #9db8ff;
    --accent-soft:   #1a2338;
    --accent-text:   #0e1117;

    --dot-raised:    #eef1f6;
    --dot-empty:     #333c4d;

    --ok:            #4ade9b;
    --warn:          #f0b95c;
    --ok-soft:       #10261c;
    --warn-soft:     #2a2113;

    --shadow:        0 1px 2px rgb(0 0 0 / .4), 0 4px 16px rgb(0 0 0 / .3);
  }
}

:root[data-theme="dark"] {
  --bg:            #0e1117;
  --bg-sunken:     #141922;
  --bg-raised:     #171d27;
  --border:        #2a3241;
  --border-strong: #3d485b;
  --text:          #eef1f6;
  --text-muted:    #a8b2c4;
  --text-faint:    #8d97a9;
  --accent:        #7ea2ff;
  --accent-hover:  #9db8ff;
  --accent-soft:   #1a2338;
  --accent-text:   #0e1117;
  --dot-raised:    #eef1f6;
  --dot-empty:     #333c4d;
  --ok:            #4ade9b;
  --warn:          #f0b95c;
  --ok-soft:       #10261c;
  --warn-soft:     #2a2113;
  --shadow:        0 1px 2px rgb(0 0 0 / .4), 0 4px 16px rgb(0 0 0 / .3);
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  /*
   * Inter's default figures are proportional, which makes dot numbers and
   * table columns fail to line up vertically. Tabular figures fix the columns;
   * contextual alternates off avoids Inter's ligature substitutions in code
   * and dot sequences, where "1-3-4-6" should stay six literal characters.
   */
  font-variant-numeric: tabular-nums;
  font-feature-settings: "calt" 0;
  text-rendering: optimizeLegibility;
}

/*
 * The optical-size compensation Inter needs: at display sizes the default
 * tracking is too loose, at small sizes too tight. Headings tighten, small
 * UI text opens up slightly.
 */
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; font-weight: 700; letter-spacing: -.021em; }
h1 { font-size: clamp(1.9rem, 1.3rem + 2.4vw, 2.9rem); letter-spacing: -.032em; }
h2 { font-size: clamp(1.4rem, 1.1rem + 1.2vw, 1.95rem); margin-top: 2.2em; letter-spacing: -.024em; }
h3 { font-size: 1.2rem; margin-top: 1.8em; letter-spacing: -.014em; }
p, ul, ol { margin: 0 0 1.1em; }
ul, ol { padding-inline-start: 1.3em; }
li + li { margin-top: .35em; }

a { color: var(--accent); text-decoration-thickness: .08em; text-underline-offset: .18em; }
a:hover { color: var(--accent-hover); }

code {
  font-family: var(--mono); font-size: .9em;
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: 5px; padding: .1em .35em;
}

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

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- layout ---------- */
.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: clamp(1rem, 4vw, 2rem); }
.narrow { max-width: var(--wrap-narrow); margin-inline: auto; }
section { margin-block: 3rem; }

.skip {
  position: absolute; inset-inline-start: -9999px; top: .5rem;
  background: var(--accent); color: var(--accent-text);
  padding: .7rem 1.1rem; border-radius: var(--radius); z-index: 100; font-weight: 600;
}
.skip:focus { inset-inline-start: .5rem; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; gap: 1rem; min-height: 3.75rem; }

.brand { display: inline-flex; align-items: center; gap: .6rem; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.brand-mark { display: inline-flex; }
.brand-mark svg { display: block; }

.site-nav { margin-inline-start: auto; }
.site-nav ul { display: flex; gap: .3rem; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
.site-nav li { margin: 0; }
.site-nav a {
  display: block; padding: .45rem .7rem; border-radius: var(--radius);
  color: var(--text-muted); text-decoration: none; font-weight: 550; font-size: .95rem;
  transition: background .2s var(--ease), color .2s var(--ease);
}
.site-nav a:hover { background: var(--bg-sunken); color: var(--text); }
.site-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

.theme-toggle, .nav-toggle {
  display: inline-grid; place-items: center; width: 2.4rem; height: 2.4rem;
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-muted); cursor: pointer;
  transition: background .2s var(--ease), color .2s var(--ease);
}
.theme-toggle:hover, .nav-toggle:hover { background: var(--bg-sunken); color: var(--text); }
.theme-icon::before { content: "◐"; font-size: 1.1rem; line-height: 1; }
.nav-toggle { display: none; }
.nav-toggle-bar, .nav-toggle-bar::before, .nav-toggle-bar::after {
  display: block; width: 1.1rem; height: 2px; background: currentColor; border-radius: 2px;
}
.nav-toggle-bar { position: relative; }
.nav-toggle-bar::before, .nav-toggle-bar::after { content: ""; position: absolute; inset-inline: 0; }
.nav-toggle-bar::before { top: -6px; }
.nav-toggle-bar::after { top: 6px; }

@media (max-width: 56rem) {
  .nav-toggle { display: inline-grid; margin-inline-start: auto; order: 3; }
  .theme-toggle { order: 2; margin-inline-start: 0; }
  .site-nav {
    order: 4; flex-basis: 100%; margin-inline-start: 0;
    display: grid; grid-template-rows: 0fr;
    transition: grid-template-rows .2s var(--ease);
  }
  .site-nav > ul { overflow: hidden; flex-direction: column; gap: 0; }
  .site-nav[data-open="true"] { grid-template-rows: 1fr; }
  .site-nav[data-open="true"] > ul { padding-bottom: .75rem; }
  .site-nav a { padding: .6rem .5rem; }
}

/* ---------- hero ---------- */
.hero { padding-block: clamp(2.5rem, 6vw, 4.5rem) 1rem; }
.hero p.lede { font-size: 1.2rem; color: var(--text-muted); max-width: 46rem; }
.eyebrow {
  display: inline-block; font-size: .8rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent); margin-bottom: .6rem;
}

/* ---------- braille cell rendering ---------- */
/*
 * A cell is a 2x3 grid of dots. Raised dots use a filled circle, empty dots a
 * faint outline — shape and fill both differ, so the distinction survives
 * greyscale, colour-blindness and high-contrast mode.
 */
.cell {
  display: inline-grid;
  grid-template-columns: repeat(2, var(--dot-size, .62rem));
  grid-auto-rows: var(--dot-size, .62rem);
  gap: var(--dot-gap, .26rem);
  padding: var(--cell-pad, .4rem);
  vertical-align: middle;
}
.cell .dot { border-radius: 50%; width: 100%; height: 100%; }
.cell .dot.on { background: var(--dot-raised); }
.cell .dot.off { border: 1.5px solid var(--dot-empty); }
.cell.lg { --dot-size: 1.05rem; --dot-gap: .42rem; --cell-pad: .5rem; }
.cell.sm { --dot-size: .44rem; --dot-gap: .18rem; --cell-pad: .2rem; }

.braille-text {
  font-size: 1.9rem; line-height: 1.5; letter-spacing: .06em;
  word-break: break-word; font-family: var(--braille);
}

/* ---------- cards & grids ---------- */
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(13.5rem, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); }

.card {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem;
  transition: border-color .2s var(--ease), transform .2s var(--ease);
}
a.card { display: block; text-decoration: none; color: inherit; }
a.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card h3 { margin-top: 0; }
.card p { color: var(--text-muted); margin-bottom: 0; font-size: .95rem; }

.letter-card { text-align: center; padding: 1rem .5rem; }
.letter-card .glyph { font-size: 1.75rem; font-weight: 700; display: block; }
.letter-card .dots { font-size: .78rem; color: var(--text-faint); font-family: var(--mono); }

/* ---------- tables ---------- */
/*
 * Reference tables are the substance of this site, so they get real treatment:
 * a sticky header that survives long scrolls, generous row padding, and a
 * header that reads as a label rather than a heavier data row.
 */
.table-scroll {
  overflow-x: auto; margin-bottom: 1.4em;
  border: 1px solid var(--border); border-radius: var(--radius);
}
.table-scroll > table { margin: 0; }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
caption { text-align: start; color: var(--text-muted); padding-bottom: .6rem; font-size: .9rem; }
th, td { text-align: start; padding: .7rem .85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .06em;
  font-weight: 600; color: var(--text-muted);
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border-strong);
  position: sticky; top: 0; z-index: 1;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .15s var(--ease); }
tbody tr:hover { background: var(--bg-sunken); }

/* ---------- forms & buttons ---------- */
label { display: block; font-weight: 600; margin-bottom: .4rem; font-size: .95rem; }
.hint { color: var(--text-muted); font-size: .88rem; font-weight: 400; }

textarea, input[type="text"], select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--bg-raised); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: .7rem .85rem;
}
textarea { min-height: 7.5rem; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; gap: .45rem; font: inherit; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
  border: 1px solid transparent; border-radius: var(--radius);
  padding: .6rem 1.1rem; cursor: pointer; text-decoration: none;
  transition: background .2s var(--ease);
}
.btn:hover { background: var(--accent-hover); color: var(--accent-text); }
.btn.secondary { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--bg-sunken); color: var(--text); }
.btn-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }

fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
legend { font-weight: 600; margin-bottom: .4rem; padding: 0; font-size: .95rem; }
.radio-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.radio-row label {
  display: inline-flex; align-items: center; gap: .4rem; margin: 0; font-weight: 500;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: .45rem .8rem; cursor: pointer;
}
.radio-row input { accent-color: var(--accent); }
.radio-row label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ---------- panels ---------- */
.panel {
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem;
}
.note {
  border-inline-start: 4px solid var(--accent); background: var(--accent-soft);
  border-radius: var(--radius); padding: .9rem 1.1rem; margin-bottom: 1.2em;
}
.note.caution { border-inline-start-color: var(--warn); background: var(--warn-soft); }
.note :last-child { margin-bottom: 0; }
.note strong { display: block; margin-bottom: .2rem; }

.output {
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; min-height: 4rem;
}

.pill {
  display: inline-block; font-size: .78rem; font-weight: 650; padding: .18rem .55rem;
  border-radius: 999px; background: var(--bg-sunken); border: 1px solid var(--border); color: var(--text-muted);
}
.pill.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- breadcrumbs & prev/next ---------- */
.crumbs { font-size: .88rem; color: var(--text-muted); padding-top: 1.2rem; }
.crumbs ol { display: flex; flex-wrap: wrap; gap: .4rem; list-style: none; padding: 0; margin: 0; }
.crumbs li + li::before { content: "/"; margin-inline-end: .4rem; color: var(--text-faint); }

.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2.5rem; }
.pager a { font-weight: 600; text-decoration: none; }

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--border); background: var(--bg-sunken);
  margin-top: 4rem; padding-block: 2.5rem 2rem; font-size: .93rem;
}
.footer-grid { display: grid; gap: 1.75rem; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); }
.footer-grid h2 { font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin: 0 0 .6rem; }
.footer-grid ul { list-style: none; margin: 0; padding: 0; }
.footer-grid li { margin: 0 0 .35rem; }
.footer-grid a { color: var(--text-muted); text-decoration: none; }
.footer-grid a:hover { color: var(--accent); text-decoration: underline; }
.footer-base {
  margin-top: 2rem; padding-top: 1.25rem; border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; align-items: center;
  color: var(--text-faint); font-size: .88rem;
}
.footer-base a { color: var(--text-faint); }

/* ---------- print ---------- */
@media print {
  .site-header, .site-footer, .skip, .btn, .nav-toggle, .theme-toggle, .no-print { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .cell .dot.on { background: #000; }
  .cell .dot.off { border-color: #999; }
  a { text-decoration: none; color: #000; }
  .card, .panel, .output { border-color: #999; break-inside: avoid; }
  table { break-inside: auto; }
  tr { break-inside: avoid; }
  h2 { break-after: avoid; }
}


/* Braille topic: dot rendering tuned so a cell reads at body-text size. */
.letter-card .cell { margin-block: .35rem; }
.braille-text { font-size: 2.1rem; }
.output .cell { margin-inline-end: .15rem; }
@media (max-width: 34rem) { .braille-text { font-size: 1.6rem; } }
