/*
 * 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.
 */
/*
 * Arabic was never served a font.
 *
 * The stack named "Noto Naskh Arabic" and nothing shipped it, so every Arabic
 * page fell through to whatever the visitor's system had: Geeza Pro on a Mac,
 * Segoe UI or Traditional Arabic on Windows. Those are not comparable to the
 * Latin side of this site, and on a reference work the Arabic reader was
 * getting visibly worse typography than the English one.
 *
 * Noto Naskh, because this site is read rather than skimmed and prints
 * vocalised Arabic on nearly every page — the harakat pages, the shadda rules,
 * the whole /ar/ research section. A Naskh face is built to place those marks.
 * The Arabic-Indic digits settled the shortlist: dot numbers are printed as
 * ١-٢-٣ on every letter page and every table row, and a face whose ٢ and ٣ are
 * hard to tell apart is disqualifying here whatever its prose looks like.
 *
 * Subset to the Arabic blocks and the joiners, with every layout feature kept
 * — the GSUB tables are what join the letters, so dropping them would render
 * Arabic as disconnected shapes. The unicode-range means only a page with
 * Arabic on it ever downloads the file.
 */
@font-face {
  font-family: "Noto Naskh Arabic";
  src: url("/fonts/noto-naskh-arabic.8f9bfc1a.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200E, U+2010-2011, U+FD3E-FD3F;
}

/*
 * Devanagari, self-hosted for the same reason Arabic is.
 *
 * The Hindi section draws a Devanagari letter beside almost every cell it
 * shows — that glyph IS the reference, the thing a reader is checking the dots
 * against — and without a shipped face every one of them was drawn by whatever
 * the visitor happened to have. On a machine with no Devanagari font that is
 * not a different shape, it is a row of empty boxes, and the chart says
 * nothing at all.
 *
 * Noto Sans Devanagari, subset by Google Fonts to the Devanagari blocks. The
 * layout features matter here as much as they do for Arabic: Devanagari joins
 * its consonants into conjuncts and hangs matras above, below and on both
 * sides of a letter, all of it done by GSUB and GPOS. A face without them
 * renders क्ष as three separate letters with a visible halant — which is
 * exactly the spelling this section spends a page explaining is NOT what the
 * braille does.
 *
 * The unicode-range means only a page with Devanagari on it downloads the
 * file, so the English, Spanish, Portuguese and Arabic sections are unchanged.
 */
@font-face {
  font-family: "Noto Sans Devanagari";
  src: url("/fonts/noto-sans-devanagari.3b3cae4d.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0900-097F, U+1CD0-1CF9, U+200C-200D, U+20A8, U+20B9, U+20F0, U+25CC, U+A830-A839, U+A8E0-A8FF;
}

@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;
}

/*
 * Three characters Inter's Latin subset does not carry.
 *
 * ← and → appear 823 times: a prev/next pair at the foot of nearly every
 * phrase and letter page, and a standalone 1.3rem → on the translator pages.
 * ␣ marks a space in 20 places. None of them are in the shipped Inter subset,
 * and none are in its declared unicode-range either, so every one of them was
 * being drawn by whatever font the visitor happened to have — measured here as
 * DejaVu Sans, whose arrows are longer, narrower and lighter than Inter's next
 * to the text they sit in.
 *
 * The face is 1.2 KB and is built from the same Inter this site already ships:
 * the three glyphs subset out of Inter-Regular through ExtraBold in
 * scripts/lib/fonts, then interpolated back into one variable font with
 * varLib, so an arrow inside a 600-weight link is drawn at 600 rather than
 * pulled from a single static weight. At wght 400 it renders pixel-identical
 * to Inter-Regular's own arrows.
 *
 * Its own family name rather than a second "Inter var" face: matching by
 * unicode-range within one family across two different font-weight ranges is
 * the sort of thing that is correct on paper and varies between engines. Named
 * explicitly in the stacks below, it cannot be ambiguous.
 */
@font-face {
  font-family: "Inter Arrows";
  src: url("/fonts/inter-arrows.814fc567.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+2190, U+2192, U+2423;
}

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

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

  --text:          #12161f;
  --text-muted:    #545d70;
  /*
   * Measured, not chosen by eye. #6b7385 gave 4.40:1 against --bg-sunken —
   * the footer's own background — which is a WCAG AA failure on every page of
   * a site about reading. This value clears 4.5:1 against every surface token
   * in the palette, with the closest pair at 4.68:1, and stays visibly
   * lighter than --text-muted.
   */
  --text-faint:    #636b7d;

  --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.
   *
   * "Inter Arrows" sits beside it for the same reason and on the same terms:
   * three code points, scoped by unicode-range, invisible to everything else.
   *
   * The platform symbol fonts stay at the tail as a safety net for the case
   * where the woff2 fails to load.
   */
  --font: "Inter var", "Inter Arrows", "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, "Inter Arrows", "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. */
  /*
   * "Braille Cells" belongs here for the same reason it is in --font: a braille
   * character written inline in prose — and the Arabic research pages write
   * them constantly — otherwise falls through to whatever the system has for
   * U+2800. The Latin stack always had it; the Arabic one did not, so the two
   * halves of the site drew the same cell differently. unicode-range keeps the
   * face scoped to braille and nothing else.
   *
   * "Inter Arrows" likewise: the prev/next pair at the foot of a page is there
   * in Arabic too, and Noto Naskh does not carry ← or →.
   *
   * And "Inter var", which was the bigger omission. An Arabic page is not
   * entirely Arabic — the brand in the header, "liblouis", "ar-ar-g1.utb",
   * "CC BY", the link to the English site: 14 Latin runs on /ar/ alone. The
   * Naskh subset covers U+0600 upwards and nothing below it, not even the
   * space, so every one of those was drawn by a system font — measured as
   * Liberation Sans. The two faces cannot collide: each is scoped by
   * unicode-range to a script the other does not carry, so Arabic still gets
   * Naskh and Latin now gets the face the rest of the site uses. Naskh stays
   * first because Arabic is what the page is mostly made of.
   */
  --font-ar: "Noto Naskh Arabic", "Inter var", "Inter Arrows", "Braille Cells",
             "Segoe UI", "Geeza Pro", "Traditional Arabic", "Noto Sans Arabic",
             Tahoma, sans-serif;
  /*
   * Devanagari first, then the same Latin faces the rest of the site uses.
   *
   * Hindi pages are not purely Devanagari — dot numbers, the braille cells and
   * the occasional Latin term all appear — and each face is bound by
   * unicode-range to a script the others do not carry, so every character
   * lands on the file that was chosen for it.
   */
  --font-hi: "Noto Sans Devanagari", "Inter var", "Inter Arrows", "Braille Cells",
             "Nirmala UI", "Kohinoor Devanagari", "Noto Sans", sans-serif;
}

/* RTL locales swap the body stack; everything else inherits unchanged. */
/*
 * Both the custom property and font-family, because inheritance carries the
 * RESOLVED value.
 *
 * Setting --font alone works on the page root, where the body rule reads it.
 * It does nothing for an Arabic word inside an English sentence: body already
 * resolved font-family to the Latin stack, and a descendant inherits that
 * resolved value, not the var() reference. So "the letter ف" on the English
 * dots pages, and every Arabic glyph in the FAQ and the defects write-up, was
 * rendering in whatever the system supplies rather than in the face the rest
 * of the site uses.
 */
/*
 * :lang(), not :root:lang().
 *
 * The root form styles the page and nothing inside it that is marked
 * differently. Arabic got away with it because inLang() also sets dir="rtl"
 * and the attribute selector caught the spans; Hindi is left to right, so
 * there was no second selector to catch them, and "the consonant क" on the
 * English dots pages resolved to Inter — a face with no Devanagari in it at
 * all. The glyph-coverage check did not see it either: that reads the
 * @font-face declarations, and the face WAS declared. It just was not in the
 * stack the element resolved to.
 *
 * :lang() matches any element whose language is that language, root or span,
 * so both cases are covered by the rule that describes the intent.
 */
:lang(ar), [dir="rtl"] { --font: var(--font-ar); font-family: var(--font-ar); }
:lang(hi) { --font: var(--font-hi); font-family: var(--font-hi); }

@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;
  /*
   * An inline <code> holding a file path or an endpoint is one long token
   * with no space in it, so at a phone width it hangs off the side and takes
   * the whole page with it — 4px of horizontal scroll on /api/ and 5px on the
   * defects page. Small numbers, but a WCAG reflow failure either way, and
   * scrolling a page sideways to read a filename is worse than a broken word.
   * Code BLOCKS override this: they scroll inside themselves instead.
   */
  overflow-wrap: anywhere;
}

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;
  /* A <button> does not inherit the page font; without this these two render
   * in the UA default, which on this machine measured as Arial. */
  font: inherit;
  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); }
/*
 * The theme icon is drawn, not typed.
 *
 * It used to be the character ◐ (U+25D0), which no face this site ships
 * carries — it is not in Inter at all. So the one mark in the header was
 * supplied by whatever the visitor had installed: measured here as Liberation
 * Sans, rendering 10.6px wide inside a 17.6px box. A circle is a border and a
 * gradient, costs no bytes, takes its colour from the button and is the same
 * on every machine.
 */
.theme-icon {
  display: block;
  width: 1.05rem; height: 1.05rem;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  /* Half filled, so the control reads as "light or dark" at a glance. */
  background: linear-gradient(to right, currentColor 50%, transparent 50%);
}
.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; }
.hero p.hero-note {
  margin-top: .9rem; max-width: 46rem; font-size: .95rem; color: var(--text-muted);
}
.hero p.hero-note strong { color: var(--text); font-weight: 600; }
.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.
 */
/*
 * direction is load-bearing, not decoration. A cell is a two-column grid
 * holding dots 1-2-3 then 4-5-6, and a grid lays its columns along the inline
 * axis — so inside dir="rtl" the columns swap and every cell renders mirrored,
 * with dot 1 sitting where a reader expects dot 4. Braille is written left to
 * right whatever the surrounding script does, so a cell pins its own direction
 * instead of inheriting the page's.
 */
.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;
  direction: ltr;
}
/* A run of cells is a word, and a word's cells run left to right too. */
.cell-run { direction: ltr; unicode-bidi: isolate; display: inline-block; }
/*
 * The word space, where a run of cells has to show one.
 *
 * A blank cell is a real cell on a sign — it occupies a cell width and the
 * inter-cell spacing applies across it — so the gap is one cell wide rather
 * than a word space in the surrounding font. Drawn as empty rather than as a
 * .cell with no dots on purpose: an all-off cell reads as a cell that means
 * something, and this one means the absence of one.
 */
.cell-space { display: inline-block; width: 1.6em; }
.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; }

/*
 * direction is pinned for the same reason the .cell rule pins it: braille runs
 * left to right in every code, including the ones written for a right-to-left
 * script. Braille pattern characters are bidi class L, so a run of them is
 * already internally left-to-right — but isolating it keeps its placement from
 * shifting when it sits next to Arabic text.
 */
.braille-text {
  font-size: 1.9rem; line-height: 1.5; letter-spacing: .06em;
  word-break: break-word; font-family: var(--braille);
  direction: ltr; unicode-bidi: isolate;
}

/* ---------- 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; }
/*
 * The dot numbers get their own line.
 *
 * They used to run inline, immediately after the cell with no gap at all —
 * measured at 0px in both media, and on the printed sheet, where the cell's
 * own padding shrinks to 1.6px, "1-2-4-5" ran straight into the dots it was
 * describing. It also threw the card off centre: the card centres one line, so
 * the cell sat left of its own letter by half the label's width, and the
 * longer the label the further it drifted. "Y" (1-3-4-5-6) was visibly out of
 * line with the Y above it. On a chart whose whole job is that a letter and
 * its cell read as one thing, that is worth a line of its own.
 */
.letter-card .dots {
  display: block;
  font-size: .78rem; color: var(--text-faint); font-family: var(--mono);
}

/* ---------- code blocks ---------- */
/*
 * One rule, because there were three copies of it as inline styles and a
 * fourth caller that invented this class name and never defined it — so the
 * defects page shipped shell commands that pushed the whole page 338px wide
 * at a phone width. overflow-x is the load-bearing part: a command line is
 * one long unbreakable token, and the alternative to scrolling it is
 * scrolling the page.
 */
.code-block {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
  margin-bottom: 1.4em;
}
.code-block code { white-space: pre; }

/* ---------- 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 {
  /*
   * Paper has one palette, whatever the screen was set to.
   *
   * The print rules forced a white background and black text, but everything
   * painted from a token kept the token's current value — so printing from
   * dark mode gave table headers at rgb(20,25,34): a solid black band with
   * pale grey text on it, unreadable and expensive in toner. Redefining the
   * tokens here fixes every such surface at once, and it is a real print
   * palette rather than a copy of the light theme: greyscale, because the page
   * promises to print cleanly in black and white.
   */
  /*
   * !important, because a media query carries no specificity of its own and
   * :root[data-theme="dark"] outranks a bare :root wherever it appears in the
   * file. Without it this block styled the light theme and left the dark one
   * printing black bands — which was the entire bug.
   */
  :root {
    --bg: #fff !important; --bg-sunken: #f2f2f2 !important; --bg-raised: #fff !important;
    --border: #999 !important; --border-strong: #666 !important;
    --text: #000 !important; --text-muted: #333 !important; --text-faint: #555 !important;
    --accent: #000 !important; --accent-hover: #000 !important;
    --accent-soft: #f2f2f2 !important; --accent-text: #fff !important;
    --dot-raised: #000 !important; --dot-empty: #bbb !important;
    --ok: #000 !important; --warn: #000 !important;
    --ok-soft: #f2f2f2 !important; --warn-soft: #f2f2f2 !important;
    --shadow: none !important;
  }

  .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; }

  /*
   * The chart pages promise a single sheet, and printed five.
   *
   * On screen the chart is a comfortable 4-column grid of cards with room to
   * read; on paper that is four pages of white space around 74 cells. This
   * block only applies to the pages that make the promise, and only when
   * printing, so nothing about the screen layout changes: the cards collapse
   * to a dense grid, the cells shrink to the size they are on a real reference
   * card, and the prose that exists to orient a reader on screen comes out.
   *
   * The sheet count is measured on every build. If this stops fitting, the
   * gate says so rather than the page quietly lying.
   */
  .print-sheet .hero { padding-block: 0 .3rem; }
  .print-sheet .hero p.lede,
  .print-sheet .crumbs,
  .print-sheet .prose,
  .print-sheet section > p,
  .print-sheet .note { display: none; }
  .print-sheet main > section { margin-block: .35rem; padding-block: 0; }
  .print-sheet h1 { font-size: 14pt; margin: 0 0 .2rem; }
  .print-sheet h2 { font-size: 10pt; margin: .4rem 0 .2rem; }
  .print-sheet .grid { gap: .12rem; }
  .print-sheet .grid.cols-4 { grid-template-columns: repeat(9, 1fr); }
  .print-sheet .card {
    padding: .12rem; border: none; border-radius: 0; background: none;
    text-align: center;
  }
  .print-sheet .letter-card .glyph { font-size: 8pt; }
  /*
   * A dot sequence must not break across lines. In the dense print grid "1-2-4-5"
   * wrapped after the last hyphen and left a lone "5" floating under the card,
   * which reads as a typo and, worse, as a different cell.
   */
  .print-sheet .letter-card .dots { font-size: 6pt; white-space: nowrap; line-height: 1.1; }
  /*
   * The cell's margin was tuned for the screen and never for paper.
   *
   * .35rem above and below is right in a roomy card and is 11px of every card
   * row on a sheet that has 979px to spend. Across the ten card rows of the
   * Portuguese chart — it has thirteen accented letters on top of the
   * alphabet — that margin alone was most of a second sheet. Giving the dot
   * numbers their own line cost about a third of what this gives back.
   */
  .print-sheet .letter-card .cell { margin-block: .08rem; }
  .print-sheet .cell { --dot-size: .3rem; --dot-gap: .1rem; --cell-pad: .1rem; }
  .print-sheet table { font-size: 7pt; }
  .print-sheet th, .print-sheet td { padding: .1rem .2rem; }
  .print-sheet caption { display: none; }
  .print-sheet .table-scroll { border: none; margin-bottom: .2rem; }


  /*
   * Two columns, which is what a reference card has always been.
   *
   * Measured under these rules, the four sections come to about 1085px of a
   * 979px sheet — the punctuation table alone is half of it, and no amount of
   * further shrinking gets 32 rows into the gap without making the dots too
   * small to read. Flowing the sections into two columns puts the alphabet and
   * numbers beside the indicators and punctuation and leaves room to spare.
   */
  .print-sheet main { columns: 2; column-gap: 1.2rem; }
  .print-sheet main > section,
  .print-sheet main > .hero { break-inside: avoid; }
  .print-sheet h1 { column-span: all; }
  /*
   * Four across, not five. The widest label on these cards is a full dot
   * sequence with its letter — "g · 1-2-4-5" — and at five columns it is wider
   * than the card, so it dropped onto its own line under the row and stopped
   * belonging to any cell. The card has to be at least as wide as the longest
   * thing it has to say.
   */
  .print-sheet .grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
  .print-sheet .wrap { padding-inline: 0; max-width: none; }

  /*
   * A grid of links to other pages is navigation. On screen it is how a reader
   * carries on; on paper it is a list of underlined phrases that go nowhere,
   * and on the Arabic chart it was 208px of a sheet that had none to spare.
   */
  .print-sheet .grid.cols-3:has(> a.card) { display: none; }
  .print-sheet .grid.cols-3:has(> a.card) + *,
  .print-sheet section:has(> .grid.cols-3 > a.card) { display: none; }

  /*
   * Arabic gets a third column, because it has more code to print: 28 letters
   * plus 8 more forms plus 8 harakat, where the Latin charts have 26 letters.
   * Measured, two columns leaves it about 200px over a sheet. The alternative
   * was shrinking the dots below roughly a millimetre on paper, which would
   * make the diagrams smaller than the braille they describe.
   */
  /* lang is on <html>, the class on <body>: descendant, not compound. */
  [lang="ar"] .print-sheet main { columns: 3; column-gap: .8rem; }
  [lang="ar"] .print-sheet .cell { --dot-size: .26rem; --dot-gap: .09rem; }

  /*
   * Hindi gets a third column too, and for a stronger version of the same
   * reason: 114 rows against Arabic's 78.
   *
   * Devanagari has consonants, vowels, matras, nukta forms and two conjuncts
   * where the Latin codes have letters, and every one of them needs a row. At
   * two columns it printed on a second sheet, which the page says it does not.
   *
   * The dots are shrunk to the Arabic size and no further. That is the floor
   * this file has already established: below roughly a millimetre on paper the
   * diagram of a cell is smaller than the braille it is describing, which is
   * the point at which shrinking stops being a layout decision.
   */
  [lang="hi"] .print-sheet main { columns: 4; column-gap: .7rem; }
  [lang="hi"] .print-sheet .cell { --dot-size: .26rem; --dot-gap: .09rem; }
  /*
   * And a little less air between the sections, because at four columns there
   * are fourteen of them. Measured, the margin alone was the last 16px of a
   * sheet that had 979 — the dots are already at the floor this file sets, so
   * the space had to come from somewhere that is not the diagrams.
   */
  [lang="hi"] .print-sheet main > section { margin-block: .2rem; }
  [lang="hi"] .print-sheet h2 { margin: .25rem 0 .15rem; }
}


/*
 * Page images: a figure, not a hero. The files are 1200 by 630 because that
 * is what a social preview needs, but drawn at full width on the page they
 * would tower over the section they illustrate. The width and height
 * attributes stay on the element so the space is still reserved before the
 * file arrives.
 */
.page-image {
  max-width: 34rem;
  width: 100%;
  height: auto;
  border-radius: 12px;
}

/* A family chart carries dot numbers under every cell, so it needs the room
   a single-cell diagram does not. */
.page-image-wide { max-width: 46rem; }

/*
 * Research write-ups.
 *
 * The method box is a definition list rather than a paragraph so that each
 * measurement states the same four things in the same order, and a reader
 * comparing two of the write-ups can find the one they care about without
 * reading either.
 */
.method { margin: .8rem 0 0; }
.method dt {
  margin-top: .8rem;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.method dt:first-child { margin-top: 0; }
.method dd { margin: .25rem 0 0; }

/*
 * Real braille characters inside the comparison tables. The bundled cell font,
 * not a symbol fallback: the point of printing the cells is that a refreshable
 * display shows them, and a platform substitute would draw them at a width
 * that stops the two spellings lining up.
 */
.braille-inline {
  font-family: var(--braille);
  font-size: 1.35rem;
  line-height: 1;
  white-space: nowrap;
}
.braille-count { font-size: .78rem; color: var(--text-faint); }

/* 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; } }

/* The dot picker on /dots/: a real cell you can press, not six checkboxes. */
.dots-picker {
  display: inline-grid;
  grid-template-columns: repeat(2, 3.25rem);
  gap: .6rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface, transparent);
}
.dot-toggle {
  width: 3.25rem; height: 3.25rem;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font: inherit; font-size: .95rem;
  cursor: pointer;
  transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}
.dot-toggle:hover { border-color: var(--text-muted); }
.dot-toggle[aria-pressed="true"] {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}
.dots-layout { display: flex; gap: 2.5rem; flex-wrap: wrap; align-items: flex-start; }
.dots-result { flex: 1 1 18rem; min-width: 0; }
.dots-result .cell { --dot-size: 1.05rem; --dot-gap: .42rem; --cell-pad: .5rem; }
.dots-result ul { line-height: 1.7; }

/* The contraction finder: the word broken into the pieces it was written as. */
.cf-segments {
  display: flex; flex-wrap: wrap; gap: .5rem;
  margin: 0 0 1.25rem;
}
.cf-seg {
  display: flex; flex-direction: column; align-items: center; gap: .3rem;
  padding: .5rem .6rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  min-width: 3rem;
}
.cf-seg-on { border-color: var(--accent); background: var(--bg-sunken); }
.cf-seg-text { font-weight: 700; font-size: 1.05rem; }
.cf-seg-kind { font-size: .72rem; color: var(--text-muted); text-transform: lowercase; }
#cf-output h4 { margin: 1.25rem 0 .4rem; font-size: .95rem; }
#cf-output ul { margin: 0; padding-left: 1.15rem; line-height: 1.7; }

/* The estimator's page preview: real braille characters, one line per row. */
.braille-page {
  overflow-x: auto;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
.braille-page-line {
  /*
   * The bundled cell font, not a monospace stack. Braille cells are the
   * content of this preview, and the platform symbol fonts draw them at
   * different widths — which would misalign the one thing the preview exists
   * to show, that each line stops short of the margin.
   */
  font-family: var(--braille);
  font-size: 1.15rem;
  line-height: 1.5;
  letter-spacing: .02em;
  white-space: pre;
  min-height: 1.5em;
}
