/* ==========================================================================
   TechThings.work — core stylesheet
   Dark by default, light theme via [data-theme="light"] on <html>.
   ========================================================================== */

:root {
  --bg:        #070b16;
  --bg-soft:   #0b1022;
  --surface:   #101a31;
  --surface-2: #16223e;
  --line:      #22314f;
  --line-soft: #1a2640;
  --text:      #e9eefc;
  --text-dim:  #a8b6d4;
  --muted:     #8494b5;
  --accent:    #3b8bff;
  --accent-2:  #17b6ff;
  --accent-ink:#ffffff;
  --good:      #2fd08a;
  --warn:      #ffb445;
  --bad:       #ff6b6b;
  --shadow:    0 24px 60px -30px rgb(0 0 0 / .85);
  --radius:    16px;
  --logo-filter: invert(1) hue-rotate(180deg);
  --grid-line: rgb(255 255 255 / .035);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg:        #f3f6fd;
  --bg-soft:   #eaf0fb;
  --surface:   #ffffff;
  --surface-2: #f5f8ff;
  --line:      #dbe4f5;
  --line-soft: #e7edf9;
  --text:      #0b1233;
  --text-dim:  #41527a;
  --muted:     #64749a;
  --accent:    #0a5cf5;
  --accent-2:  #0098e0;
  --accent-ink:#ffffff;
  --good:      #0f9b63;
  --warn:      #b3690a;
  --bad:       #d23b3b;
  --shadow:    0 20px 50px -32px rgb(11 18 51 / .45);
  --logo-filter: none;
  --grid-line: rgb(11 18 51 / .04);
  color-scheme: light;
}

*, *::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; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(900px 480px at 82% -12%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
    radial-gradient(700px 420px at -10% 4%, color-mix(in srgb, var(--accent-2) 12%, transparent), transparent 70%);
  background-repeat: no-repeat;
  background-attachment: fixed;
}

h1, h2, h3, h4 { line-height: 1.2; letter-spacing: -.02em; margin: 0 0 .5em; font-weight: 700; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
code, .mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace; font-size: .88em; }
code {
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  padding: .1em .38em;
  border-radius: 6px;
  color: var(--text);
}

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

.wrap { width: min(1240px, 100% - 3rem); margin-inline: auto; }
@media (max-width: 640px) { .wrap { width: min(1240px, 100% - 2rem); } }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--accent-ink);
  padding: .6rem 1rem; border-radius: 0 0 10px 0;
}
.skip-link:focus { left: 0; }

/* ---------- Header ---------------------------------------------------- */

.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.site-header__inner {
  display: flex; align-items: center; gap: 1.25rem;
  min-height: 96px;
}
.brand { display: inline-flex; align-items: center; margin-right: auto; }
.brand img { height: 70px; width: auto; filter: var(--logo-filter); }
.brand:hover { text-decoration: none; }

.nav { display: flex; align-items: center; gap: .35rem; }
.nav a {
  color: var(--text-dim); font-size: .92rem; font-weight: 500;
  padding: .45rem .7rem; border-radius: 9px;
}
.nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }

.theme-toggle {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; padding: 0;
  border-radius: 10px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text-dim);
}
.theme-toggle:hover { color: var(--text); border-color: var(--accent); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: none; }

/* ---------- Footer ---------------------------------------------------- */

.site-footer {
  margin-top: 5rem;
  border-top: 1px solid var(--line-soft);
  padding: 2rem 0 3rem;
  color: var(--muted);
  font-size: .88rem;
}
.site-footer__inner { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between; }

/* ---------- Shared bits ----------------------------------------------- */

.pill {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  padding: .25rem .6rem; border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text-dim);
}
.pill--live { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); background: color-mix(in srgb, var(--good) 12%, transparent); }

.btn {
  display: inline-flex; align-items: center; gap: .55rem;
  font: inherit; font-weight: 600; font-size: .95rem;
  padding: .7rem 1.15rem; border-radius: 11px; cursor: pointer;
  border: 1px solid transparent; text-decoration: none;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 85%, white); }
.btn--ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn--ghost:hover { border-color: var(--accent); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }

/* ---------- Home: hero ------------------------------------------------ */

.hero { padding: clamp(3rem, 8vw, 6rem) 0 clamp(2rem, 5vw, 3.5rem); }

.hero h1 {
  font-size: clamp(2.3rem, 5.6vw, 3.8rem);
  margin-block: 0 .9rem;
}
.hero h1 .grad, .reference-hero h1 .grad {
  background: linear-gradient(100deg, var(--accent-2), var(--accent) 60%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero__lede { font-size: clamp(1.05rem, 1.7vw, 1.28rem); color: var(--text-dim); }
.hero__actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1.6rem; }

/* ---------- Home: topic cards ----------------------------------------- */

.section { padding: clamp(2rem, 5vw, 3.5rem) 0; }
.section__head { margin-bottom: 2rem; }
.section__head h2 { font-size: clamp(1.5rem, 3vw, 2rem); }
.section__head p { color: var(--text-dim); margin: 0; }

.cards { display: grid; gap: 1.1rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.card {
  position: relative; display: flex; flex-direction: column; gap: .55rem;
  padding: 1.5rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  color: inherit; text-decoration: none; overflow: hidden;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.card::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(420px 180px at 100% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%);
  opacity: 0; transition: opacity .2s ease;
}
a.card:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); box-shadow: var(--shadow); text-decoration: none; }
a.card:hover::after { opacity: 1; }
.card__top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .35rem; }
.card__icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line-soft); color: var(--accent-2); }
.card__icon svg { width: 21px; height: 21px; }
.card h3 { margin: 0; font-size: 1.16rem; }
.card p { margin: 0; color: var(--text-dim); font-size: .94rem; }
.card__meta { margin-top: auto; padding-top: .9rem; font-size: .82rem; color: var(--muted); display: flex; gap: .8rem; }
.card--soon { opacity: .62; }
.card--soon .card__icon { color: var(--muted); }

/* ---------- Technical references ------------------------------------- */

.reference-hero { padding: clamp(2.8rem, 7vw, 5.5rem) 0 2.2rem; }
.reference-hero__kicker {
  margin: 0 0 .7rem; color: var(--accent-2); font: 700 .76rem/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .14em; text-transform: uppercase;
}
.reference-hero h1 { font-size: clamp(2.35rem, 5.7vw, 4.2rem); }
.reference-hero__lede { max-width: 72ch; color: var(--text-dim); font-size: clamp(1.05rem, 1.8vw, 1.25rem); }
.reference-hero__actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1.4rem; }

.ref-grid {
  display: grid; grid-template-columns: minmax(215px, 270px) minmax(0, 780px);
  gap: clamp(1.5rem, 4vw, 3.5rem); align-items: start; justify-content: center;
  padding: 1.2rem 0 2rem;
}
.ref-toc {
  position: sticky; top: 116px; padding: 1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 15px;
}
.ref-toc__title {
  margin: 0 0 .65rem; color: var(--muted); font-size: .72rem; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
}
.ref-toc ol { list-style: none; padding: 0; margin: 0; }
.ref-toc li + li { border-top: 1px solid var(--line-soft); }
.ref-toc a { display: block; padding: .52rem .4rem; color: var(--text-dim); font-size: .88rem; line-height: 1.35; }
.ref-toc a:hover { color: var(--text); text-decoration: none; }
.ref-toc__back { display: inline-flex; margin-top: .8rem; font-size: .82rem; }

.ref-article {
  min-width: 0; padding: clamp(1.35rem, 3.5vw, 2.5rem);
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
}
.ref-article > section { scroll-margin-top: 118px; }
.ref-article > section + section { margin-top: 3rem; padding-top: 2.7rem; border-top: 1px solid var(--line-soft); }
.ref-article h2 { font-size: clamp(1.45rem, 3vw, 2rem); margin-bottom: .75rem; }
.ref-article h3 { margin: 1.7rem 0 .55rem; font-size: 1.08rem; }
.ref-article p, .ref-article li { color: var(--text-dim); }
.ref-article strong { color: var(--text); }
.ref-article ul, .ref-article ol { padding-left: 1.25rem; }
.ref-article li { margin-bottom: .48rem; }
.ref-article li::marker { color: var(--accent); font-weight: 700; }
.ref-article .figure { margin-inline: 0; }
.ref-article :not(pre) > code { overflow-wrap: anywhere; }

.plain-steps { list-style: none; padding: 0 !important; margin: 1.4rem 0; counter-reset: plain-step; }
.plain-steps li {
  counter-increment: plain-step; display: grid; grid-template-columns: 36px 1fr; gap: .8rem;
  padding: .8rem 0; margin: 0; border-bottom: 1px solid var(--line-soft);
}
.plain-steps li::before {
  content: counter(plain-step); width: 30px; height: 30px; display: grid; place-items: center;
  color: var(--accent-ink); background: var(--accent); border-radius: 50%; font: 700 .78rem/1 ui-monospace, monospace;
}
.plain-steps li:last-child { border-bottom: 0; }

.concept-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .8rem; margin: 1.3rem 0; }
.concept {
  padding: 1rem; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 13px;
}
.concept h3, .concept h4 { margin: 0 0 .35rem; font-size: 1rem; }
.concept p { margin: 0; font-size: .9rem; }
.concept__tag { display: block; margin-bottom: .4rem; color: var(--accent-2); font: 700 .72rem/1.3 ui-monospace, monospace; letter-spacing: .07em; text-transform: uppercase; }

.bit-demo {
  overflow-x: auto; margin: 1.25rem 0; padding: 1rem;
  background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: 13px;
  color: var(--text); font: 600 .88rem/1.9 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre;
}
.equation {
  margin: 1.25rem 0; padding: .9rem 1rem; text-align: center;
  color: var(--text); background: var(--surface-2); border-radius: 12px;
  font: 650 clamp(.95rem, 2vw, 1.1rem)/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.related-refs { margin-top: 2.8rem; padding-top: 1.4rem; border-top: 1px solid var(--line-soft); }
.related-refs p { margin: 0 0 .6rem; color: var(--muted); font-size: .78rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.related-refs__links { display: flex; flex-wrap: wrap; gap: .5rem; }
.related-refs a { padding: .38rem .7rem; color: var(--text-dim); background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 999px; font-size: .82rem; }
.related-refs a:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }

@media (max-width: 820px) {
  .ref-grid { grid-template-columns: 1fr; }
  .ref-toc { position: static; }
  .ref-toc ol { columns: 2; column-gap: 1.5rem; }
  .ref-toc li { break-inside: avoid; }
}
@media (max-width: 520px) {
  .ref-toc ol { columns: 1; }
  .ref-article { padding: 1.15rem; border-radius: 16px; }
}

/* ---------- Lesson layout --------------------------------------------- */

.lesson-head { padding: clamp(2.2rem, 5vw, 3.4rem) 0 1.6rem; }
.lesson-head h1 { font-size: clamp(2rem, 4.6vw, 3rem); margin-block: 0 .7rem; }
.lesson-head p { color: var(--text-dim); font-size: 1.08rem; }
.lesson-head__facts { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.1rem; }

.lesson-grid {
  display: grid;
  grid-template-columns: minmax(270px, 340px) minmax(0, 1fr);
  gap: clamp(1.5rem, 3vw, 2.75rem);
  align-items: start;
  padding-bottom: 2rem;
}
@media (max-width: 980px) { .lesson-grid { grid-template-columns: 1fr; } }

/* Left rail ------------------------------------------------------------ */

.rail { position: sticky; top: 116px; }
@media (max-width: 980px) { .rail { position: static; } }

.rail__title {
  font-size: .74rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; margin: 0 0 .9rem .15rem;
}
.rail__list { list-style: none; margin: 0; padding: 0; position: relative; }
.rail__list::before {
  content: ""; position: absolute; left: 19px; top: 14px; bottom: 14px;
  width: 2px; background: var(--line); border-radius: 2px;
}
.rail__progress {
  position: absolute; left: 19px; top: 14px; width: 2px; height: 0;
  background: linear-gradient(var(--accent-2), var(--accent));
  border-radius: 2px; transition: height .35s cubic-bezier(.4,0,.2,1);
}
.rail__item { position: relative; }

.rail__btn {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: 38px 1fr; gap: .8rem; align-items: start;
  width: 100%; text-align: left; font: inherit; color: inherit;
  background: none; border: 1px solid transparent; border-radius: 13px;
  padding: .7rem .8rem .7rem .15rem; cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.rail__btn:hover { background: var(--surface); border-color: var(--line-soft); }
.rail__num {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: .82rem; font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg); color: var(--muted);
  border: 2px solid var(--line);
  transition: all .2s ease;
}
.rail__label { font-weight: 600; font-size: .98rem; display: block; padding-top: .3rem; }
.rail__sub { display: block; font-size: .83rem; color: var(--muted); line-height: 1.45; margin-top: .15rem; }

.rail__btn[aria-selected="true"] { background: var(--surface); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.rail__btn[aria-selected="true"] .rail__num {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 18%, transparent);
}
.rail__btn[aria-selected="true"] .rail__label { color: var(--text); }
.rail__btn[data-visited="true"]:not([aria-selected="true"]) .rail__num { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent-2) 55%, var(--line)); }

.rail__hint {
  margin-top: 1.1rem; padding: .7rem .85rem; border-radius: 11px;
  background: var(--surface); border: 1px dashed var(--line);
  color: var(--muted); font-size: .8rem;
}
.rail__hint kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .75rem;
  background: var(--surface-2); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; padding: .05rem .32rem; color: var(--text-dim);
}

/* Right-hand detail panels --------------------------------------------- */

.stage { min-height: 60vh; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: clamp(1.3rem, 3vw, 2.2rem);
  box-shadow: var(--shadow);
}
.panel[hidden] { display: none; }
.panel.is-entering { animation: panel-in .38s cubic-bezier(.22,.8,.3,1); }
@keyframes panel-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

.panel__head { border-bottom: 1px solid var(--line-soft); padding-bottom: 1.1rem; margin-bottom: 1.4rem; }
.panel__step { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .78rem; color: var(--accent-2); letter-spacing: .1em; }
.panel__head h2 { font-size: clamp(1.45rem, 3vw, 2rem); margin: .35rem 0 .5rem; }
.panel__lede { color: var(--text-dim); font-size: 1.03rem; margin: 0; max-width: 68ch; }

.panel h3 { font-size: 1.05rem; margin: 2rem 0 .6rem; }
.panel h3:first-of-type { margin-top: 0; }
.panel p, .panel li { color: var(--text-dim); }
.panel strong { color: var(--text); font-weight: 650; }
.panel ul { padding-left: 1.15rem; margin: 0 0 1em; }
.panel li { margin-bottom: .45rem; }
.panel li::marker { color: var(--accent); }

.figure {
  margin: 1.6rem 0;
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  padding: 1.1rem 1.1rem .8rem;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 22px 22px;
}
.figure svg { width: 100%; height: auto; display: block; overflow: visible; }
.figure figcaption { margin-top: .85rem; font-size: .84rem; color: var(--muted); border-top: 1px solid var(--line-soft); padding-top: .65rem; }

.callout {
  display: grid; grid-template-columns: auto 1fr; gap: .9rem;
  padding: 1rem 1.1rem; border-radius: 13px; margin: 1.5rem 0;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
}
.callout__icon { color: var(--accent-2); font-size: 1.05rem; line-height: 1.5; }
.callout p { margin: 0; color: var(--text); font-size: .96rem; }
.callout strong { display: block; margin-bottom: .15rem; }

.facts { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin: 1.4rem 0; }
.fact { background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 12px; padding: .85rem .95rem; }
.fact__k { font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 600; }
.fact__v { font-size: 1.22rem; font-weight: 700; color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: -.02em; }
.fact__n { font-size: .82rem; color: var(--muted); }

.table-wrap { overflow-x: auto; margin: 1.4rem 0; }
table.tt { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 460px; }
table.tt th, table.tt td { text-align: left; padding: .65rem .8rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.tt th { color: var(--text); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
table.tt td { color: var(--text-dim); }
table.tt tbody tr:last-child td { border-bottom: 0; }

.jargon { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1.2rem 0 0; }
.jargon dt { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .78rem; font-weight: 700; color: var(--accent-2); }
.jargon dd { margin: 0 0 0 .45rem; font-size: .86rem; color: var(--muted); }
.jargon__row { display: flex; align-items: baseline; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 999px; padding: .3rem .8rem; }

.panel__nav { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2.2rem; padding-top: 1.3rem; border-top: 1px solid var(--line-soft); }
.panel__nav .btn { font-size: .88rem; padding: .55rem .9rem; }
.panel__nav .btn span.dir { color: var(--muted); font-size: .76rem; display: block; }

/* Diagram primitives (shared by all inline SVGs) ------------------------ */

.d-fill      { fill: var(--surface); }
.d-fill-2    { fill: var(--surface-2); }
.d-stroke    { stroke: var(--line); fill: none; stroke-width: 1.5; }
.d-accent    { stroke: var(--accent); fill: none; stroke-width: 2; }
.d-accent-2  { stroke: var(--accent-2); fill: none; stroke-width: 2; }
.d-accent-f  { fill: var(--accent); }
.d-accent-2f { fill: var(--accent-2); }
.d-good      { stroke: var(--good); fill: none; stroke-width: 2; }
.d-good-f    { fill: var(--good); }
.d-warn      { stroke: var(--warn); fill: none; stroke-width: 2; }
.d-warn-f    { fill: var(--warn); }
.d-bad       { stroke: var(--bad); fill: none; stroke-width: 2; }
.d-bad-f     { fill: var(--bad); }
.d-dash      { stroke-dasharray: 5 5; }
.d-t         { fill: var(--text); font-size: 13px; font-family: inherit; }
.d-t-dim     { fill: var(--text-dim); font-size: 12px; font-family: inherit; }
.d-t-mut     { fill: var(--muted); font-size: 11px; font-family: inherit; }
.d-mono      { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; fill: var(--muted); }
.d-title     { fill: var(--text); font-size: 13px; font-weight: 700; font-family: inherit; }
.d-mid       { text-anchor: middle; }
.d-end       { text-anchor: end; }

@keyframes d-pulse  { 0% { r: 8; opacity: .55; } 100% { r: 46; opacity: 0; } }
@keyframes d-dashrun{ to { stroke-dashoffset: -40; } }
@keyframes d-blink  { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
@keyframes d-travel { 0% { offset-distance: 0%; opacity: 0; } 8% { opacity: 1; } 92% { opacity: 1; } 100% { offset-distance: 100%; opacity: 0; } }

.d-wave { animation: d-pulse 2.6s ease-out infinite; transform-box: fill-box; }
.d-flow { stroke-dasharray: 8 6; animation: d-dashrun 1.4s linear infinite; }
.d-blink { animation: d-blink 1.8s ease-in-out infinite; }

/* The arrow-key hint is meaningless on a touch device. */
@media (max-width: 980px) {
  .rail__hint { display: none; }
  .rail__list { margin-bottom: 1.75rem; }
}

/* ---------- Glossary --------------------------------------------------- */

.gloss-tools {
  position: sticky; top: 96px; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
  padding: .9rem 0;
  margin-bottom: 2rem;
}
.gloss-tools__row { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; }

.gloss-search { position: relative; flex: 1 1 260px; min-width: 0; }
.gloss-search svg {
  position: absolute; left: .8rem; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; color: var(--muted); pointer-events: none;
}
.gloss-search input {
  width: 100%; font: inherit; font-size: .95rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 11px; padding: .62rem .9rem .62rem 2.4rem;
}
.gloss-search input::placeholder { color: var(--muted); }
.gloss-search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

.gloss-filters { display: flex; flex-wrap: wrap; gap: .4rem; }
.gloss-filters button {
  font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer;
  color: var(--text-dim); background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: .38rem .78rem;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.gloss-filters button:hover { color: var(--text); border-color: var(--accent); }
.gloss-filters button[aria-pressed="true"] {
  color: var(--accent-ink); background: var(--accent); border-color: var(--accent);
}

.gloss-count { font-size: .84rem; color: var(--muted); margin: .7rem 0 0; }

.az-nav {
  display: flex; flex-wrap: wrap; gap: .2rem;
  margin: 0 0 2.5rem; padding-bottom: 1.2rem;
  border-bottom: 1px solid var(--line-soft);
}
.az-nav a {
  display: grid; place-items: center;
  min-width: 30px; height: 30px; padding: 0 .3rem;
  border-radius: 8px; font-size: .84rem; font-weight: 600;
  color: var(--text-dim); font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.az-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

.az { margin-bottom: 2.6rem; scroll-margin-top: 170px; }
.az__letter {
  font-size: .78rem; letter-spacing: .16em; text-transform: uppercase;
  color: var(--accent-2); font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin: 0 0 .9rem; padding-bottom: .5rem;
  border-bottom: 1px solid var(--line-soft);
}
.az__terms { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.term {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 1.05rem 1.15rem;
  scroll-margin-top: 180px;
  transition: border-color .18s ease;
}
.term:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.term:target { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.term__name {
  margin: 0; font-size: 1rem; font-weight: 700; color: var(--accent-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: -.01em;
}
.term__exp { margin: .2rem 0 0; font-size: .87rem; font-weight: 600; color: var(--text); }
.term__def { margin: .55rem 0 0; font-size: .91rem; color: var(--text-dim); }
.term__src { margin: .75rem 0 0; font-size: .78rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.term__src span { text-transform: uppercase; letter-spacing: .09em; font-weight: 600; font-size: .68rem; }
.term__src a {
  color: var(--text-dim); background: var(--surface-2);
  border: 1px solid var(--line-soft); border-radius: 999px; padding: .12rem .55rem;
}
.term__src a:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }

.term[hidden], .az[hidden] { display: none; }

.gloss-empty {
  text-align: center; padding: 3rem 1rem; color: var(--muted);
  border: 1px dashed var(--line); border-radius: 14px;
}
.gloss-empty[hidden] { display: none; }

@media (max-width: 640px) {
  .gloss-tools { top: 0; }
  .az { scroll-margin-top: 120px; }
  .term { scroll-margin-top: 130px; }
}

/* The header carries a logo, two nav links and the toggle; below this width
   they no longer fit side by side at full size. */
@media (max-width: 560px) {
  .site-header__inner { gap: .6rem; min-height: 76px; }
  .brand img { height: 46px; }
  .nav { gap: .1rem; }
  .nav a { font-size: .84rem; padding: .4rem .5rem; white-space: nowrap; }
  .nav a:nth-last-child(3) { display: none; }
}
@media (max-width: 400px) {
  .brand img { height: 38px; }
  .nav a { font-size: .77rem; padding: .34rem .38rem; }
  .theme-toggle { width: 34px; height: 34px; }
}
