/* ============================================================================
   Veloz Calculator — "Board & Page"

   The apps' own identity is a chalkboard: #097331→#3a8e5a green with white
   hand-drawn chalk notation. This site keeps that split literal — prose is read
   on paper, but every calculator and every worked solution happens on a board.

   Colours are sampled from the app icons. The gradient is clamped to a
   text-safe range (white stays >= 4.5:1 across the whole ramp); chalk accent
   colours are for marks only and clear 3:1 on the flat board.
   ========================================================================= */

/* ---------- tokens ---------- */

:root {
  /* board — sampled from the app icons */
  --board: #097331;
  --board-deep: #06541f;
  --board-grad: linear-gradient(152deg, #097331 0%, #1f7d47 100%);
  --board-edge: #3a8e5a; /* brand's light end — borders and marks only, never behind text */

  --chalk: #ffffff;
  --chalk-soft: rgba(255, 255, 255, 0.86);
  --chalk-faint: rgba(255, 255, 255, 0.5); /* rules and decoration only */
  --chalk-ghost: rgba(255, 255, 255, 0.14);

  /* paper */
  --page: #fbfbf8;
  --page-sunk: #f2f3ee;
  --page-raised: #ffffff;
  --ink: #12211a;
  --ink-soft: #5b6b62;
  --rule: #e2e5dd;
  --rule-strong: #cdd2c7;

  /* per-app accents; overridden on [data-app] */
  --chalk-accent: #ffe08a;
  --accent-ink: #7a5c00;

  /* type */
  --display: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --body: "Literata", ui-serif, Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* scale — 1.25 major third, clamped for fluid sizing */
  --t-xs: 0.75rem;
  --t-sm: 0.875rem;
  --t-base: 1.0625rem;
  --t-md: 1.1875rem;
  --t-lg: clamp(1.25rem, 0.6vw + 1.1rem, 1.5rem);
  --t-xl: clamp(1.5rem, 1.2vw + 1.2rem, 2rem);
  --t-2xl: clamp(1.9rem, 2.2vw + 1.3rem, 2.75rem);
  --t-3xl: clamp(2.05rem, 2.1vw + 1.35rem, 3.25rem);

  /* space */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;
  --s-8: 4rem;
  --s-9: 6rem;

  --radius: 10px;
  --radius-lg: 16px;
  --measure: 68ch;
  --gutter: clamp(1.15rem, 4vw, 2.5rem);
  --wrap: 74rem;

  --shadow-sm: 0 1px 2px rgba(18, 33, 26, 0.06), 0 1px 3px rgba(18, 33, 26, 0.05);
  --shadow-md: 0 4px 12px rgba(18, 33, 26, 0.07), 0 2px 4px rgba(18, 33, 26, 0.05);
  --shadow-board: 0 12px 32px rgba(6, 84, 31, 0.22), 0 2px 8px rgba(6, 84, 31, 0.14);

  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0e1512;
    --page-sunk: #131b17;
    --page-raised: #18211c;
    --ink: #e8efe9;
    --ink-soft: #9dafa4;
    --rule: #25302a;
    --rule-strong: #33413a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-board: 0 14px 36px rgba(0, 0, 0, 0.55);
  }
}

:root[data-theme="dark"] {
  --page: #0e1512;
  --page-sunk: #131b17;
  --page-raised: #18211c;
  --ink: #e8efe9;
  --ink-soft: #9dafa4;
  --rule: #25302a;
  --rule-strong: #33413a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-board: 0 14px 36px rgba(0, 0, 0, 0.55);
}

/* On paper the accent must carry ink-level contrast; in dark mode the chalk
   value is the legible one, so the two swap roles. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent-ink: var(--chalk-accent);
  }
}
:root[data-theme="dark"] {
  --accent-ink: var(--chalk-accent);
}

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

@font-face {
  font-family: "Space Grotesk";
  src: url("/assets/fonts/space-grotesk-latin.woff2") format("woff2");
  font-weight: 500 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Literata";
  src: url("/assets/fonts/literata-latin.woff2") format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}

/* ---------- reset ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* the nav is sticky, so anything scrolled to must clear it (WCAG 2.4.11) */
  scroll-padding-top: 5rem;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--body);
  font-size: var(--t-base);
  line-height: 1.65;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img,
svg,
picture {
  display: block;
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

h1,
h2,
h3,
h4 {
  font-family: var(--display);
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: -0.021em;
  margin: 0;
  text-wrap: balance;
}

p {
  margin: 0;
  text-wrap: pretty;
}

a {
  color: var(--accent-ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 3px solid var(--accent-ink);
  outline-offset: 2px;
  border-radius: 3px;
  scroll-margin-top: 5rem;
  scroll-margin-bottom: 2rem;
}

.board :focus-visible {
  outline-color: var(--chalk);
}

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

.wrap {
  width: min(100% - var(--gutter) * 2, var(--wrap));
  margin-inline: auto;
}

.wrap-narrow {
  width: min(100% - var(--gutter) * 2, 46rem);
  margin-inline: auto;
}

.band {
  padding-block: var(--s-8);
}

.band-sunk {
  background: var(--page-sunk);
}

.band + .band {
  border-top: 1px solid var(--rule);
}

.band-sunk + .band,
.band + .band-sunk {
  border-top: 0;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--board);
  color: var(--chalk);
  padding: var(--s-3) var(--s-4);
  z-index: 100;
  border-radius: 0 0 var(--radius) 0;
}

.skip:focus {
  left: 0;
}

/* ---------- eyebrow / section heading ---------- */

.eyebrow {
  font-family: var(--display);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 var(--s-3);
}

.board .eyebrow {
  color: var(--chalk-faint);
}

.band-title {
  font-size: var(--t-xl);
  margin-bottom: var(--s-3);
}

.band-lede {
  color: var(--ink-soft);
  max-width: 58ch;
  margin-bottom: var(--s-6);
}

/* ---------- nav ---------- */

.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--rule);
}

.nav-in {
  display: flex;
  align-items: center;
  gap: var(--s-5);
  min-height: 58px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-family: var(--display);
  font-weight: 700;
  font-size: var(--t-md);
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--board-grad);
  display: grid;
  place-items: center;
  color: var(--chalk);
  font-size: 15px;
  line-height: 1;
  flex: none;
}

.nav-links {
  margin-left: auto;
  display: flex;
  gap: var(--s-5);
  align-items: center;
  font-family: var(--display);
  font-size: var(--t-sm);
  font-weight: 500;
}

.nav-links a {
  color: var(--ink-soft);
  text-decoration: none;
  /* 24px minimum target size (WCAG 2.5.8) */
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding-inline: 0.15rem;
}

.nav-links a:hover,
.nav-links a[aria-current] {
  color: var(--ink);
}

@media (max-width: 46rem) {
  .nav-links {
    gap: var(--s-4);
  }
  .nav-hide-sm {
    display: none;
  }
}

/* ============================================================================
   THE BOARD — the signature surface. Calculators and worked solutions only.
   ========================================================================= */

.board {
  background: var(--board-grad);
  color: var(--chalk);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-board);
  padding: clamp(1.15rem, 3vw, 2rem);
  position: relative;
  isolation: isolate;
}

/* A single hairline of the brand's lighter green reads as the board's edge. */
.board::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid var(--board-edge);
  opacity: 0.5;
  pointer-events: none;
}

.board h2,
.board h3 {
  color: var(--chalk);
}

.board-title {
  font-family: var(--display);
  font-size: var(--t-sm);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--chalk-faint);
  margin: 0 0 var(--s-4);
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

.board-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--chalk-ghost);
}

/* ---------- calculator controls (on the board) ---------- */

.calc {
  display: grid;
  gap: var(--s-5);
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-4);
}

.field {
  display: grid;
  gap: var(--s-2);
  min-width: 0;
  flex: 1 1 6rem;
}

.field-label {
  font-family: var(--display);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--chalk-soft);
}

/* a variable name is not a heading: "A" and "a" are different things in an
   equation, so these keep their case and take the conventional italic */
.field-label.is-var {
  text-transform: none;
  font-style: italic;
  font-size: var(--t-md);
  letter-spacing: 0;
}

.input {
  width: 100%;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid var(--chalk-ghost);
  border-radius: var(--radius);
  color: var(--chalk);
  padding: 0.7rem 0.85rem;
  font-family: var(--display);
  font-size: var(--t-lg);
  font-variant-numeric: tabular-nums;
  transition: border-color 0.16s var(--ease), background 0.16s var(--ease);
  -moz-appearance: textfield;
  appearance: textfield;
}

.input::-webkit-outer-spin-button,
.input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.input::placeholder {
  color: rgba(255, 255, 255, 0.38);
}

.input:hover {
  border-color: rgba(255, 255, 255, 0.3);
}

.input:focus {
  border-color: var(--chalk);
  background: rgba(0, 0, 0, 0.32);
  outline: none;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.22);
}

.input[aria-invalid="true"] {
  border-color: #ffb3b3;
  box-shadow: 0 0 0 3px rgba(255, 179, 179, 0.25);
}

.input-mono {
  font-family: var(--mono);
  letter-spacing: 0.04em;
}

select.input {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--chalk-soft) 50%),
    linear-gradient(135deg, var(--chalk-soft) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2.25rem;
}

select.input option {
  background: var(--board-deep);
  color: var(--chalk);
}

/* ---------- fraction input: two boxes stacked over a rule ---------- */

.frac-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.6rem, 3vw, 1.4rem);
  flex-wrap: nowrap;
}

.frac-input {
  display: grid;
  gap: 0.4rem;
  flex: 1 1 0;
  min-width: 0;
  max-width: 9rem;
}

/* the bar is what makes it read as a fraction rather than two fields */
.frac-bar {
  height: 3px;
  border-radius: 3px;
  background: var(--chalk);
}

.frac-part {
  text-align: center;
  font-size: var(--t-xl);
  padding: 0.55rem 0.4rem;
}

.frac-op {
  font-family: var(--display);
  font-size: var(--t-2xl);
  font-weight: 500;
  color: var(--chalk);
  line-height: 1;
  flex: none;
}

/* segmented operation picker */
.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid var(--chalk-ghost);
  border-radius: var(--radius);
  flex-wrap: wrap;
}

.segmented button {
  flex: 1 1 auto;
  min-width: 3rem;
  background: none;
  border: 0;
  border-radius: 7px;
  color: var(--chalk-soft);
  font-family: var(--display);
  font-weight: 600;
  font-size: var(--t-md);
  padding: 0.5rem 0.6rem;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}

.segmented button:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--chalk);
}

.segmented button[aria-pressed="true"] {
  background: var(--chalk);
  color: var(--board);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  font-family: var(--display);
  font-weight: 600;
  font-size: var(--t-base);
  padding: 0.72rem 1.35rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s var(--ease), background 0.15s var(--ease),
    box-shadow 0.15s var(--ease);
}

.btn:active {
  transform: translateY(1px);
}

/* primary on the board */
.btn-chalk {
  background: var(--chalk);
  color: var(--board);
    margin-bottom: 1.45rem;
}

.btn-chalk:hover {
  background: #eef5f0;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.btn-ghost {
  background: transparent;
  border-color: var(--chalk-faint);
  color: var(--chalk);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* primary on paper */
.btn-ink {
  background: var(--board);
  color: #fff;
}

.btn-ink:hover {
  background: var(--board-deep);
  box-shadow: var(--shadow-md);
}

.btn-outline {
  background: transparent;
  border-color: var(--rule-strong);
  color: var(--ink);
}

.btn-outline:hover {
  border-color: var(--ink-soft);
  background: var(--page-raised);
}

/* ============================================================================
   MATH TYPESETTING — real notation, no MathJax, no images. Every glyph stays
   selectable text so search engines and screen readers get the actual content.
   ========================================================================= */

.m {
  font-family: var(--display);
  font-variant-numeric: tabular-nums lining-nums;
  white-space: nowrap;
  line-height: 1;
}

.m-lg {
  font-size: var(--t-xl);
}

/* fraction: stacked numerator over denominator with a real rule between */
.m-frac {
  display: inline-grid;
  grid-template-rows: 1fr auto 1fr;
  justify-items: center;
  vertical-align: middle;
  margin: 0 0.18em;
  text-align: center;
}

.m-frac > .m-num {
  padding: 0 0.28em 0.12em;
  grid-row: 1;
}

.m-frac > .m-den {
  padding: 0.12em 0.28em 0;
  grid-row: 3;
  border-top: 0.075em solid currentColor;
  min-width: 100%;
}

/* nested fractions step down so they stay legible */
.m-frac .m-frac {
  font-size: 0.86em;
}

/* radical: the glyph plus an overbar across the radicand */
.m-sqrt {
  display: inline-flex;
  align-items: stretch;
  vertical-align: middle;
  margin: 0 0.1em;
}

.m-sqrt::before {
  content: "√";
  font-size: 1.15em;
  line-height: 0.95;
  margin-right: -0.06em;
  transform: translateY(-0.02em);
}

.m-sqrt > .m-rad {
  border-top: 0.075em solid currentColor;
  padding: 0.16em 0.22em 0 0.1em;
}

/* matrix / determinant brackets drawn with borders, not glyphs */
.m-matrix {
  display: inline-grid;
  gap: 0.25em 0.85em;
  vertical-align: middle;
  padding: 0.3em 0.55em;
  position: relative;
  justify-items: end;
  font-variant-numeric: tabular-nums;
}

.m-matrix::before,
.m-matrix::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0.34em;
  border: 0.08em solid currentColor;
}

.m-matrix::before {
  left: 0;
  border-right: 0;
}

.m-matrix::after {
  right: 0;
  border-left: 0;
}

/* determinant bars: vertical rules instead of brackets */
.m-matrix.is-det::before,
.m-matrix.is-det::after {
  width: 0;
  border-width: 0 0 0 0.08em;
}

.m-matrix.is-det::after {
  border-width: 0 0.08em 0 0;
}

.m-sup {
  font-size: 0.7em;
  vertical-align: super;
  line-height: 0;
}

.m-sub {
  font-size: 0.7em;
  vertical-align: sub;
  line-height: 0;
}

.m-op {
  margin: 0 0.32em;
}

.m-hl {
  color: var(--chalk-accent);
}

/* ============================================================================
   THE WORKING — numbered derivation. The numbering is real: these are ordered
   steps, and the order is the information.
   ========================================================================= */

.working {
  margin: var(--s-5) 0 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
  border-top: 1px solid var(--chalk-ghost);
}

.working > li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 1.75rem 1fr;
  gap: var(--s-3);
  padding: var(--s-4) 0;
  border-bottom: 1px solid var(--chalk-ghost);
}

.working > li::before {
  content: counter(step);
  font-family: var(--display);
  font-size: var(--t-xs);
  font-weight: 600;
  color: var(--board);
  background: var(--chalk-faint);
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin-top: 0.15rem;
}

.working > li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

/* min-width:0 lets the 1fr track shrink so wide math scrolls instead of
   forcing the whole board wider */
.step-body {
  min-width: 0;
}

.step-label {
  font-family: var(--display);
  font-size: var(--t-sm);
  font-weight: 500;
  color: var(--chalk-soft);
  margin-bottom: var(--s-2);
}

.step-math {
  font-size: var(--t-lg);
  overflow-x: auto;
  padding-bottom: 0.2em;
}

/* the answer sits apart from the steps */
.answer {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--s-2) var(--s-4);
  padding: var(--s-4) var(--s-5);
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid var(--chalk-ghost);
  border-left: 3px solid var(--chalk-accent);
  border-radius: var(--radius);
}

.answer-label {
  font-family: var(--display);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--chalk-faint);
}

.answer-value {
  font-family: var(--display);
  font-size: var(--t-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.answer-note {
  font-size: var(--t-sm);
  color: var(--chalk-soft);
  flex-basis: 100%;
}

/* writing-on animation: steps appear in sequence, like working being written */
@media (prefers-reduced-motion: no-preference) {
  .working.is-fresh > li {
    animation: write-on 0.34s var(--ease) backwards;
  }
  .working.is-fresh > li:nth-child(1) { animation-delay: 0.02s; }
  .working.is-fresh > li:nth-child(2) { animation-delay: 0.08s; }
  .working.is-fresh > li:nth-child(3) { animation-delay: 0.14s; }
  .working.is-fresh > li:nth-child(4) { animation-delay: 0.2s; }
  .working.is-fresh > li:nth-child(5) { animation-delay: 0.26s; }
  .working.is-fresh > li:nth-child(6) { animation-delay: 0.32s; }
  .working.is-fresh > li:nth-child(n + 7) { animation-delay: 0.38s; }
}

@keyframes write-on {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.calc-error {
  padding: var(--s-3) var(--s-4);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.26);
  border-left: 3px solid #ffb3b3;
  color: var(--chalk);
  font-size: var(--t-sm);
}

.board-title-sub {
  margin-top: var(--s-5);
}

.board-hint {
  font-size: var(--t-sm);
  color: var(--chalk-soft);
  margin: 0;
}

.board-live {
  font-family: var(--display);
  font-size: var(--t-xs);
  color: var(--chalk-faint);
}

/* the unknown in a proportion — shows shape without pretending to be editable */
.input-readonly {
  background: transparent;
  border-style: dashed;
  color: var(--chalk-faint);
  display: flex;
  align-items: center;
}

/* secondary facts under the working */
.extras {
  margin: var(--s-4) 0 0;
  display: grid;
  gap: var(--s-3);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr));
}

.extras > div {
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius);
  padding: var(--s-3) var(--s-4);
}

.extras dt {
  font-family: var(--display);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--chalk-faint);
  margin-bottom: var(--s-2);
}

.extras dd {
  margin: 0;
  font-size: var(--t-md);
}

/* tabular steps (repeated division) */
.step-table {
  overflow-x: auto;
  margin-top: var(--s-2);
}

.step-table table {
  border-collapse: collapse;
  font-family: var(--display);
  font-variant-numeric: tabular-nums;
  font-size: var(--t-sm);
  min-width: 20rem;
}

.step-table th,
.step-table td {
  padding: 0.35rem 0.8rem 0.35rem 0;
  text-align: right;
  border-bottom: 1px solid var(--chalk-ghost);
}

.step-table th {
  color: var(--chalk-faint);
  font-weight: 600;
  font-size: var(--t-xs);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.step-table td:last-child {
  color: var(--chalk-accent);
  font-weight: 600;
}

/* ---------- Sarrus: the widened matrix with its diagonals drawn over it ---------- */

.sarrus-visual {
  position: relative;
  margin-top: var(--s-5);
  overflow-x: auto;
  padding: var(--s-2) 0;
}

.sarrus-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(2.6rem, 1fr));
  gap: 0.35rem;
  position: relative;
  min-width: 17rem;
  font-family: var(--display);
  font-variant-numeric: tabular-nums;
}

.sarrus-grid > span {
  display: grid;
  place-items: center;
  padding: 0.55rem 0.3rem;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--chalk-ghost);
  font-size: var(--t-md);
}

/* the two repeated columns read as an echo, not as new data */
.sarrus-grid > span.is-copy {
  background: transparent;
  border-style: dashed;
  color: var(--chalk-soft);
}

.sarrus-diagonals {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

/* Down and up diagonals are told apart by direction first and colour second —
   never by colour alone, and never by a dash pattern that the draw-on
   animation would have to overwrite. */
.diag {
  stroke-width: 2.5;
  fill: none;
  stroke-linecap: round;
}

.diag-down {
  stroke: var(--chalk-accent);
}

.diag-up {
  stroke: var(--chalk);
  opacity: 0.85;
}

/* pathLength="1" on each line makes this one keyframe work at any length */
@media (prefers-reduced-motion: no-preference) {
  .diag {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    animation: draw-diag 0.5s var(--ease) forwards;
  }
  .diag-up {
    animation-delay: 0.28s;
  }
}

@keyframes draw-diag {
  to {
    stroke-dashoffset: 0;
  }
}

.sarrus-key {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-4);
  margin-top: var(--s-4);
  font-family: var(--display);
  font-size: var(--t-xs);
  color: var(--chalk-soft);
}

.sarrus-key span {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
}

.sarrus-key i {
  width: 1.4rem;
  height: 0;
  border-top: 2px solid currentColor;
}

.sarrus-key .k-down {
  color: var(--chalk-accent);
}

.sarrus-key .k-up i {
  border-top-color: var(--chalk);
}

/* ---------- matrix input grid ---------- */

.matrix-input {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-3);
  max-width: 22rem;
}

/* ---------- base converter row ---------- */

.base-row {
  display: grid;
  gap: var(--s-3);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
  margin-top: var(--s-5);
}

.base-cell {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--chalk-ghost);
  border-radius: var(--radius);
  padding: var(--s-3) var(--s-4);
}

.base-cell.is-source {
  border-color: var(--chalk-accent);
}

.base-cell dt {
  font-family: var(--display);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--chalk-faint);
  margin-bottom: var(--s-2);
  display: flex;
  justify-content: space-between;
}

.base-cell dd {
  margin: 0;
  font-family: var(--mono);
  font-size: var(--t-md);
  word-break: break-all;
  line-height: 1.35;
}

/* ---------- area shape diagram ---------- */

.shape-figure {
  width: 100%;
  max-width: 9rem;
  aspect-ratio: 1;
  margin-inline: auto;
}

.shape-figure :is(polygon, rect, circle) {
  fill: color-mix(in srgb, var(--chalk-accent) 18%, transparent);
  stroke: var(--chalk-accent);
  stroke-width: 2;
  stroke-linejoin: round;
}

.shape-figure .dim {
  stroke: var(--chalk);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}

.shape-figure text {
  fill: var(--chalk);
  font-family: var(--display);
  font-size: 11px;
  text-anchor: middle;
}

.area-layout {
  display: grid;
  gap: var(--s-5);
  align-items: start;
}

@media (min-width: 34rem) {
  .area-layout {
    grid-template-columns: 9rem 1fr;
  }
}

/* ---------- All in One tab strip ---------- */

.tablist {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-bottom: var(--s-5);
}

.tablist button {
  font-family: var(--display);
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--chalk-soft);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--chalk-ghost);
  border-radius: 999px;
  /* clears the 24px minimum target size (WCAG 2.5.8) */
  padding: 0.5rem 0.95rem;
  min-height: 2.25rem;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}

.tablist button:hover {
  background: rgba(0, 0, 0, 0.34);
  color: var(--chalk);
}

.tablist button[aria-selected="true"] {
  background: var(--chalk);
  border-color: var(--chalk);
  color: var(--board);
}

/* Each panel names itself, which is what makes the no-JS stack navigable.
   Once the tab strip is driving things the tab already carries the name. */
.tabpanel + .tabpanel {
  margin-top: var(--s-7);
  padding-top: var(--s-6);
  border-top: 1px solid var(--chalk-ghost);
}

.tabpanel-title {
  font-family: var(--display);
  font-size: var(--t-md);
  color: var(--chalk);
  margin-bottom: var(--s-4);
}

.is-tabbed .tabpanel-title {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.is-tabbed .tabpanel + .tabpanel {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

/* ---------- app-only upsell, docked to the board ---------- */

.board-upsell {
  margin-top: var(--s-5);
  padding-top: var(--s-5);
  border-top: 1px solid var(--chalk-ghost);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-4);
  justify-content: space-between;
}

.board-upsell p {
  font-size: var(--t-sm);
  color: var(--chalk-soft);
  max-width: 34ch;
  margin: 0;
}

/* ---------- store badges ---------- */

.badges {
  display: flex;
  flex-wrap: wrap;
  /* >= 1/4 of the 44px button height, per Google's clear-space rule */
  gap: 0.85rem;
  align-items: center;
}

/* The two badges are sized so their visible BUTTONS match, not their image
   boxes — Google's PNG carries 41px of transparent clear space on every side,
   so an equal image height would render its button at 67% of Apple's. The
   width/height attributes come from badgeBox() in config.js; `height: auto`
   here just lets them scale down on narrow screens.

   Google's built-in padding doubles as the clear space its guidelines require.
   Apple's comes from the row gap, which is kept above 1/4 of the button
   height. Neither asset is cropped, recoloured or distorted. */
.badge-link {
  display: inline-flex;
  align-items: center;
  border-radius: 9px;
  line-height: 0;
  transition: transform 0.14s var(--ease), opacity 0.14s var(--ease);
}

.badge-link:hover {
  transform: translateY(-1px);
  opacity: 0.88;
}

.badge-link img {
  height: auto;
  max-width: 100%;
}

/* ---------- hero ---------- */

.hero {
  padding-block: var(--s-7) var(--s-8);
}

.hero-grid {
  display: grid;
  gap: var(--s-7);
  align-items: start;
}

@media (min-width: 62rem) {
  .hero-grid {
    grid-template-columns: minmax(0, 0.86fr) minmax(0, 1.14fr);
    gap: var(--s-8);
  }
  /* the board is tall; keeping the intro in view stops the left column
     turning into a column of nothing */
  .hero-intro {
    position: sticky;
    top: 5rem;
  }
}

.hero-icon {
  width: 68px;
  height: 68px;
  border-radius: 15px;
  box-shadow: var(--shadow-md);
  margin-bottom: var(--s-4);
}

.hero h1 {
  font-size: var(--t-3xl);
  margin-bottom: var(--s-4);
}

.hero-lede {
  font-size: var(--t-md);
  color: var(--ink-soft);
  max-width: 46ch;
  margin-bottom: var(--s-5);
}

.hero-price {
  font-family: var(--display);
  font-size: var(--t-sm);
  color: var(--ink-soft);
  margin-top: var(--s-3);
  max-width: 42ch;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-4);
  font-family: var(--display);
  font-size: var(--t-sm);
  color: var(--ink-soft);
  margin-top: var(--s-5);
}

.hero-meta > * {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
}

/* ---------- cards ---------- */

.grid {
  display: grid;
  gap: var(--s-5);
}

.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); }

.card {
  background: var(--page-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-sm);
}

.card h3 {
  font-size: var(--t-md);
  margin-bottom: var(--s-2);
}

.card p {
  font-size: var(--t-sm);
  color: var(--ink-soft);
  margin: 0;
}

/* link cards (app hub, guide index) */
.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.16s var(--ease), transform 0.16s var(--ease),
    box-shadow 0.16s var(--ease);
}

.card-link:hover {
  border-color: var(--accent-ink);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card-link .card-cta {
  font-family: var(--display);
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--accent-ink);
  margin-top: var(--s-3);
  display: inline-flex;
  gap: var(--s-2);
  align-items: center;
}

.card-link:hover .card-cta {
  gap: 0.65rem;
}

.card-icon {
  width: 46px;
  height: 46px;
  border-radius: 11px;
  margin-bottom: var(--s-4);
  box-shadow: var(--shadow-sm);
}

/* how it works — a genuine 3-step sequence, so it earns its numbering */
.steps {
  list-style: none;
  counter-reset: how;
  padding: 0;
  margin: 0;
  display: grid;
  gap: var(--s-5);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
}

.steps > li {
  counter-increment: how;
  padding-top: var(--s-4);
  border-top: 2px solid var(--accent-ink);
}

.steps > li::before {
  content: counter(how, decimal-leading-zero);
  display: block;
  font-family: var(--display);
  font-size: var(--t-sm);
  font-weight: 700;
  color: var(--accent-ink);
  margin-bottom: var(--s-2);
  font-variant-numeric: tabular-nums;
}

.steps h3 {
  font-size: var(--t-md);
  margin-bottom: var(--s-2);
}

.steps p {
  font-size: var(--t-sm);
  color: var(--ink-soft);
}

/* ---------- screenshots ---------- */

.shots {
  display: flex;
  gap: var(--s-5);
  overflow-x: auto;
  padding-bottom: var(--s-4);
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
}

.shots > figure {
  flex: 0 0 auto;
  width: min(62vw, 15rem);
  margin: 0;
  scroll-snap-align: center;
}

.shots img {
  width: 100%;
  height: auto;
  border-radius: 14px;
  border: 1px solid var(--rule);
  box-shadow: var(--shadow-md);
  background: var(--page-sunk);
}

.shots figcaption {
  font-size: var(--t-sm);
  color: var(--ink-soft);
  margin-top: var(--s-3);
  text-align: center;
}

/* ---------- prose (guide pages) ---------- */

.prose {
  max-width: var(--measure);
}

.prose > * + * {
  margin-top: var(--s-4);
}

.prose h2 {
  font-size: var(--t-xl);
  margin-top: var(--s-7);
}

.prose h3 {
  font-size: var(--t-lg);
  margin-top: var(--s-6);
}

.prose ul,
.prose ol {
  padding-left: 1.35rem;
  margin-top: var(--s-4);
}

.prose li + li {
  margin-top: var(--s-2);
}

.prose strong {
  font-weight: 600;
}

.prose code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--page-sunk);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 0.1em 0.36em;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-sm);
}

.table-scroll {
  overflow-x: auto;
  margin-top: var(--s-5);
}

.prose th,
.prose td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--rule);
}

.prose th {
  font-family: var(--display);
  font-size: var(--t-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.prose td {
  font-variant-numeric: tabular-nums;
}

/* the direct answer that opens every guide */
.answer-first {
  border-left: 3px solid var(--accent-ink);
  background: var(--page-sunk);
  padding: var(--s-5);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: var(--t-md);
}

.answer-first p {
  margin: 0;
}

.answer-first p + p {
  margin-top: var(--s-3);
}

/* ---------- guide layout ---------- */

.guide-head {
  padding-block: var(--s-5) var(--s-6);
  max-width: min(100% - var(--gutter) * 2, 52rem);
}

.guide-head h1 {
  font-size: var(--t-2xl);
}

.guide-body {
  display: grid;
  gap: var(--s-7);
  align-items: start;
  padding-bottom: var(--s-8);
}

@media (min-width: 64rem) {
  .guide-body {
    grid-template-columns: minmax(0, 1fr) minmax(0, 24rem);
  }
  /* the calculator follows the reader down the page */
  .guide-calc {
    position: sticky;
    top: 5rem;
  }
}

.guide-calc-note {
  font-size: var(--t-sm);
  color: var(--ink-soft);
  margin-top: var(--s-3);
  text-align: center;
}

/* the sidebar board is narrower, so its type steps down to match */
.guide-calc .step-math {
  font-size: var(--t-md);
}

.guide-calc .answer-value {
  font-size: var(--t-xl);
}

/* ---------- breadcrumbs ---------- */

.crumbs {
  font-family: var(--display);
  font-size: var(--t-sm);
  color: var(--ink-soft);
  padding-block: var(--s-4);
}

.crumbs ol {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin: 0;
  padding: 0;
}

.crumbs li:not(:last-child)::after {
  content: "/";
  margin-left: var(--s-2);
  color: var(--rule-strong);
}

.crumbs a {
  color: var(--ink-soft);
  text-decoration: none;
}

.crumbs a:hover {
  color: var(--ink);
  text-decoration: underline;
}

/* ---------- FAQ ---------- */

.faq {
  border-top: 1px solid var(--rule);
  max-width: var(--measure);
}

.faq > details {
  border-bottom: 1px solid var(--rule);
}

.faq summary {
  font-family: var(--display);
  font-weight: 600;
  font-size: var(--t-md);
  padding: var(--s-5) 2.5rem var(--s-5) 0;
  cursor: pointer;
  list-style: none;
  position: relative;
}

.faq summary::-webkit-details-marker {
  display: none;
}

.faq summary::after {
  content: "";
  position: absolute;
  right: 0.6rem;
  top: 50%;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--accent-ink);
  border-bottom: 2px solid var(--accent-ink);
  transform: translateY(-70%) rotate(45deg);
  transition: transform 0.18s var(--ease);
}

.faq details[open] summary::after {
  transform: translateY(-30%) rotate(-135deg);
}

.faq-body {
  padding-bottom: var(--s-5);
  color: var(--ink-soft);
}

.faq-body p {
  margin: 0;
}

.faq-more {
  display: inline-block;
  margin-top: var(--s-3);
  font-family: var(--display);
  font-size: var(--t-sm);
  font-weight: 600;
}

/* ---------- CTA ---------- */

.cta {
  background: var(--board-grad);
  color: var(--chalk);
  border-radius: var(--radius-lg);
  padding: clamp(1.6rem, 4vw, 3rem);
  display: grid;
  gap: var(--s-5);
  align-items: center;
  box-shadow: var(--shadow-board);
}

@media (min-width: 52rem) {
  .cta {
    grid-template-columns: 1fr auto;
    gap: var(--s-7);
  }
}

.cta h2 {
  font-size: var(--t-xl);
  color: var(--chalk);
  margin-bottom: var(--s-3);
}

.cta p {
  color: var(--chalk-soft);
  max-width: 48ch;
  margin: 0;
}

.cta-price {
  font-family: var(--display);
  font-size: var(--t-sm);
  color: var(--chalk-faint);
  margin-top: var(--s-3);
}

/* ---------- footer ---------- */

.footer {
  background: var(--board-deep);
  color: var(--chalk-soft);
  padding-block: var(--s-7) var(--s-6);
  margin-top: var(--s-8);
}

.footer a {
  color: var(--chalk-soft);
  text-decoration: none;
}

.footer a:hover {
  color: var(--chalk);
  text-decoration: underline;
}

.footer-grid {
  display: grid;
  gap: var(--s-6);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
  padding-bottom: var(--s-6);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.footer h2 {
  font-family: var(--display);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--chalk-faint);
  margin-bottom: var(--s-4);
}

.footer ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: var(--s-3);
  font-size: var(--t-sm);
  font-family: var(--display);
}

.footer-base {
  padding-top: var(--s-5);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-4);
  justify-content: space-between;
  font-size: var(--t-sm);
  color: var(--chalk-faint);
}

/* The Veloz wordmark sits with the copyright rather than in the nav — the site
   is the apps' home, and the company signs it at the bottom. */
.footer-copy {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

.footer-logo {
  height: 1.35em;
  width: auto;
  flex: none;
  color: var(--chalk);
  opacity: 0.85;
}

/* ---------- utilities ---------- */

.stack-4 { display: grid; gap: var(--s-4); }
.stack-5 { display: grid; gap: var(--s-5); }
.row { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }
.mt-5 { margin-top: var(--s-5); }
.mt-6 { margin-top: var(--s-6); }
.mt-7 { margin-top: var(--s-7); }

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

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-family: var(--display);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--page-sunk);
  border: 1px solid var(--rule);
  color: var(--ink-soft);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .nav, .footer, .cta, .board-upsell, .badges { display: none; }
  .board { box-shadow: none; background: #fff; color: #000; }
}
