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

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

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

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

h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; font-weight: 700; letter-spacing: -.015em; }
h1 { font-size: clamp(1.9rem, 1.3rem + 2.4vw, 2.9rem); }
h2 { font-size: clamp(1.4rem, 1.1rem + 1.2vw, 1.95rem); margin-top: 2.2em; }
h3 { font-size: 1.2rem; margin-top: 1.8em; }
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(--mono);
}

/* ---------- 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 ---------- */
.table-scroll { overflow-x: auto; margin-bottom: 1.2em; }
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: .6rem .7rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); border-bottom: 2px solid var(--border-strong); }
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; } }
