/* ─── Performance-critical: font-display swap ──────────────────────────────── */
@font-face {
  font-display: swap;
}

:root {
  --paper: #f7f9fb;
  --paper-2: #eceef0;
  --ink: #191c1e;
  --ink-soft: #3b4949;
  --ink-mute: #6b7a7a;
  --rule: #bac9c9;
  --rule-soft: #e0e3e5;
  --moss: #00696b;
  --moss-deep: #005354;
  --leaf: #2878a0;
  --ochre: #565e74;
  --terracotta: #6b7a7a;
  --focus: #00ced1;
  --shadow:
    0 1px 0 rgba(25, 28, 30, 0.04), 0 14px 36px -16px rgba(25, 28, 30, 0.18);
  --grain-opacity: 0.12;

  --space-xs: clamp(6px, 1.2vw, 10px);
  --space-sm: clamp(10px, 1.6vw, 14px);
  --space-md: clamp(14px, 2.2vw, 20px);
  --space-lg: clamp(20px, 3vw, 32px);
  --space-xl: clamp(28px, 4.5vw, 48px);
  --space-2xl: clamp(40px, 6vw, 64px);

  --pad-panel: clamp(20px, 3.6vw, 40px);
  --pad-wrap-x: clamp(16px, 3.5vw, 32px);
  --pad-wrap-y-top: clamp(28px, 5vw, 56px);
  --pad-wrap-y-bot: clamp(48px, 7vw, 80px);

  /* CLS fix: pre-declare grade digit size so layout doesn't shift when font loads */
  --grade-digit-size: clamp(96px, 14vw, 180px);

  --color-outline-variant: #bac9c9;
}

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

html,
body {
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family:
    "Manrope", "Segoe UI", Arial, sans-serif; /* fallback stack prevents FOUT-shift */
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  position: relative;
  overflow-x: hidden;
  font-size: clamp(15px, 0.6vw + 13.5px, 17px);
}

.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  background: var(--ink);
  color: var(--paper);
  padding: 12px 18px;
  text-decoration: none;
  font-family: "Manrope", sans-serif;
  font-weight: 600;
  z-index: 1000;
  border-radius: 4px;
}
.skip-link:focus {
  top: 16px;
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(
      1px 1px at 23% 17%,
      rgba(26, 40, 32, 0.06) 50%,
      transparent 51%
    ),
    radial-gradient(
      1px 1px at 67% 83%,
      rgba(26, 40, 32, 0.05) 50%,
      transparent 51%
    ),
    radial-gradient(
      1px 1px at 89% 41%,
      rgba(26, 40, 32, 0.04) 50%,
      transparent 51%
    ),
    radial-gradient(
      1px 1px at 12% 71%,
      rgba(26, 40, 32, 0.05) 50%,
      transparent 51%
    );
  background-size:
    180px 180px,
    220px 220px,
    260px 260px,
    200px 200px;
  opacity: var(--grain-opacity);
  mix-blend-mode: multiply;
}

/* ─── CLS fix: corner leaves use contain + explicit dimensions ── */
.corner-leaf {
  position: fixed;
  width: clamp(120px, 18vw, 220px);
  height: clamp(120px, 18vw, 220px);
  pointer-events: none;
  opacity: 0.15;
  z-index: 0;
  /* Prevent layout influence */
  contain: layout style;
  will-change: auto;
}
.corner-leaf.tl {
  top: clamp(-40px, -3vw, -20px);
  left: clamp(-40px, -3vw, -20px);
}
.corner-leaf.br {
  bottom: clamp(-40px, -3vw, -20px);
  right: clamp(-40px, -3vw, -20px);
  transform: rotate(180deg);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: 2px;
}

a {
  color: var(--moss-deep);
}

/* ─── Navbar ──────────────────────────────────── */
.masthead-top {
  position: relative;
  z-index: 10;
  background: var(--paper);
  border-bottom: 1px solid var(--ink);
  /* CLS fix: explicit min-height prevents reflow when nav items load */
  min-height: 69px;
  contain: layout;
}
.masthead {
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px var(--pad-wrap-x);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: clamp(18px, 1.8vw, 22px);
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.logo-icon {
  /* CLS fix: explicit dimensions so icon slot never reflows */
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--moss-deep);
  color: var(--paper);
  border-radius: 6px;
}
.logo-icon svg {
  width: 18px;
  height: 18px;
}
.main-nav {
  display: flex;
  gap: clamp(14px, 2vw, 28px);
  align-items: center;
}
.nav-link {
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  text-decoration: none;
  position: relative;
  padding: 6px 0;
  transition: color 0.2s ease;
}
.nav-link:hover {
  color: var(--moss-deep);
}
.nav-link::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--moss-deep);
  transform: scaleX(0);
  transition: transform 0.2s ease;
}
.nav-link:hover::after {
  transform: scaleX(1);
}
.menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--ink);
  width: 42px;
  height: 42px;
  border-radius: 4px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.menu-toggle-bars {
  position: relative;
  width: 18px;
  height: 12px;
}
.menu-toggle-bars::before,
.menu-toggle-bars::after,
.menu-toggle-bars span {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 1.5px;
  background: var(--ink);
  transition:
    transform 0.25s ease,
    opacity 0.25s ease;
}
.menu-toggle-bars::before {
  top: 0;
}
.menu-toggle-bars span {
  top: 5px;
}
.menu-toggle-bars::after {
  bottom: 0;
}
.menu-toggle[aria-expanded="true"] .menu-toggle-bars::before {
  transform: translateY(5px) rotate(45deg);
}
.menu-toggle[aria-expanded="true"] .menu-toggle-bars span {
  opacity: 0;
}
.menu-toggle[aria-expanded="true"] .menu-toggle-bars::after {
  transform: translateY(-5px) rotate(-45deg);
}

.mobile-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 40, 32, 0.5);
  z-index: 9;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.mobile-overlay.active {
  opacity: 1;
}

/* ─── Breadcrumb ──────────────────────────────────── */
.breadcrumb-wrap {
  position: relative;
  z-index: 1;
  background: var(--paper-2);
  border-bottom: 1px solid var(--rule);
  /* CLS fix: reserve height */
  min-height: 41px;
  contain: layout;
}
.breadcrumb {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px var(--pad-wrap-x);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.breadcrumb a {
  color: var(--ink-soft);
  text-decoration: none;
  transition: color 0.2s ease;
}
.breadcrumb a:hover {
  color: var(--moss-deep);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.breadcrumb-separator {
  color: var(--rule);
}
.breadcrumb-current {
  color: var(--terracotta);
  font-weight: 600;
}

.wrap {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--pad-wrap-y-top) var(--pad-wrap-x) var(--pad-wrap-y-bot);
}

/* ─── Article masthead ──────────────────────────────────── */
.article-masthead {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-md);
  padding-bottom: 18px;
  border-bottom: 1px solid var(--ink);
  position: relative;
  /* CLS fix: reserve min-height matching font fallback size */
  min-height: clamp(60px, 8vw, 80px);
}
.article-masthead::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -5px;
  height: 1px;
  background: var(--ink);
  opacity: 0.6;
}
.vol {
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: clamp(10px, 0.9vw, 12px);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: nowrap;
}
.vol span {
  color: var(--terracotta);
  font-weight: 600;
}
.article-masthead .crest {
  /* CLS fix: explicit reserved dimensions */
  width: clamp(32px, 3.5vw, 38px);
  height: clamp(32px, 3.5vw, 38px);
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.article-masthead .crest svg {
  width: 100%;
  height: 100%;
}
.article-masthead h1 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 400;
  font-variation-settings: "opsz" 144;
  font-size: clamp(24px, 4.2vw, 44px);
  text-align: center;
  letter-spacing: -0.02em;
  font-style: italic;
  line-height: 1.1;
  /* CLS fix: explicit line-height * font-size reserves space */
  min-height: calc(clamp(24px, 4.2vw, 44px) * 1.1);
}
.article-masthead h1 em {
  font-style: normal;
  font-weight: 600;
  color: var(--moss-deep);
}

.subhead {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px var(--space-sm);
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: clamp(10px, 0.85vw, 12px);
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  /* CLS fix: reserve height */
  min-height: 20px;
}
.subhead .dot {
  color: var(--leaf);
  font-weight: 700;
}

/* ─── Lede ──────────────────────────────────── */
.lede {
  margin-top: var(--space-2xl);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2xl);
  align-items: end;
}
.lede .kicker {
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: clamp(11px, 0.9vw, 12px);
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--terracotta);
  margin-bottom: 12px;
}
.lede .display {
  font-family: "Fraunces", Georgia, serif;
  font-variation-settings: "opsz" 144;
  font-weight: 400;
  font-size: clamp(28px, 5vw, 60px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink);
  /* CLS fix: reserve approximate height for 2-line heading */
  min-height: calc(clamp(28px, 5vw, 60px) * 1.05 * 2);
}
.lede .display .accent {
  font-style: italic;
  font-weight: 500;
  color: var(--moss-deep);
}
.lede .standfirst {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 400;
  font-size: clamp(15px, 1.4vw, 18px);
  line-height: 1.6;
  color: var(--ink-soft);
  border-left: 3px solid var(--moss);
  padding-left: var(--space-md);
}
.lede .standfirst::first-letter {
  font-weight: 600;
  color: var(--moss-deep);
}

/* ─── Warning bar ──────────────────────────────────── */
.warning-bar {
  margin-top: var(--space-lg);
  background: rgba(154, 69, 48, 0.08);
  border-left: 3px solid var(--terracotta);
  padding: 14px 18px;
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-size: clamp(13.5px, 1.1vw, 15px);
  color: var(--ink-soft);
  line-height: 1.55;
}
.warning-bar strong {
  font-style: normal;
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: clamp(10.5px, 0.85vw, 11.5px);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--terracotta);
  display: inline-block;
  margin-right: 6px;
}

/* ─── Calculator ──────────────────────────────────── */
.calculator {
  margin-top: var(--space-2xl);
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 0;
  border: 1px solid var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow);
  position: relative;
  /* CLS fix: reserve minimum height so layout doesn't jump */
  min-height: 600px;
  contain: layout;
}
.calculator::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid var(--rule-soft);
  pointer-events: none;
  /* Decorative only — does not affect layout */
  z-index: 0;
}

.panel {
  padding: var(--pad-panel);
  position: relative;
  min-width: 0;
  z-index: 1;
}
.panel.left {
  border-right: 1px solid var(--ink);
  background-color: var(--paper-2);
}

.section-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--rule);
  flex-wrap: wrap;
}
.section-label .num {
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-weight: 500;
  font-size: 14px;
  color: var(--terracotta);
  letter-spacing: 0.04em;
}
.section-label .name {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  font-size: clamp(20px, 2.2vw, 24px);
  letter-spacing: -0.01em;
  color: var(--ink);
}
.section-label .meta {
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: clamp(10px, 0.9vw, 12px);
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: nowrap;
}

.field-block {
  margin-bottom: var(--space-lg);
  background-color: white;
  padding: var(--space-md);
}
.field-block:last-child {
  margin-bottom: 0;
}

.field-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
  gap: var(--space-sm);
  flex-wrap: wrap;
}
.field-head label {
  font-family: "Manrope", "Segoe UI", sans-serif;
  font-size: clamp(14px, 1.1vw, 15px);
  font-weight: 600;
  color: var(--ink);
}
.field-head .hint {
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: clamp(10px, 0.9vw, 12px);
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  text-transform: uppercase;
}

.number-display {
  font-family: "Fraunces", Georgia, serif;
  font-variation-settings: "opsz" 144;
  font-weight: 500;
  color: var(--moss-deep);
  font-size: clamp(24px, 2.8vw, 30px);
  line-height: 1;
  display: flex;
  align-items: baseline;
  gap: 6px;
  /* CLS fix: reserve width so slider row doesn't jump */
  min-width: 70px;
}
.number-display .total {
  font-size: clamp(14px, 1.5vw, 17px);
  color: var(--ink-soft);
  font-weight: 400;
}

.slider-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-md);
  align-items: center;
}
.slider-wrap {
  position: relative;
  padding: 8px 0;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--rule);
  outline: none;
  cursor: pointer;
  border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--moss-deep);
  border: 3px solid var(--paper);
  cursor: grab;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
  box-shadow: 0 0 0 1px var(--moss-deep);
}
input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}
input[type="range"]::-webkit-slider-thumb:active {
  cursor: grabbing;
}
input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 4px var(--focus);
}
input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--moss-deep);
  border: 3px solid var(--paper);
  cursor: grab;
  box-shadow: 0 0 0 1px var(--moss-deep);
}
input[type="range"]:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 4px var(--focus);
}

@media (pointer: coarse) {
  input[type="range"] {
    height: 6px;
  }
  input[type="range"]::-webkit-slider-thumb {
    width: 28px;
    height: 28px;
  }
  input[type="range"]::-moz-range-thumb {
    width: 28px;
    height: 28px;
  }
}

.stepper {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--ink-soft);
  border-radius: 0;
  flex-shrink: 0;
  /* CLS fix: explicit dimensions */
  width: 108px;
  height: 32px;
}
.stepper button {
  background: transparent;
  border: none;
  width: 32px;
  height: 32px;
  font-family: "Fraunces", Georgia, serif;
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  color: var(--ink);
  transition:
    background 0.15s ease,
    color 0.15s ease;
  touch-action: manipulation;
  flex-shrink: 0;
}
.stepper button:hover {
  background: var(--moss-deep);
  color: var(--paper);
}
.stepper button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}
.stepper input {
  width: 44px;
  border: none;
  border-left: 1px solid var(--ink-soft);
  border-right: 1px solid var(--ink-soft);
  text-align: center;
  background: transparent;
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: 16px;
  font-weight: 500;
  height: 32px;
  color: var(--ink);
  -moz-appearance: textfield;
  padding: 0;
  flex-shrink: 0;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.stepper input:focus {
  outline: none;
  background: var(--paper-2);
}
.stepper input:focus-visible {
  background: var(--paper-2);
  box-shadow: inset 0 0 0 2px var(--focus);
}

@media (pointer: coarse) {
  .stepper {
    width: 130px;
    height: 40px;
  }
  .stepper button {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
  .stepper input {
    width: 50px;
    height: 40px;
  }
}

.frq-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}
.frq-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: var(--space-sm) var(--space-md);
  align-items: center;
  padding: 12px 14px;
  background: linear-gradient(to right, transparent, transparent);
  background: white;
  transition: background 0.2s ease;
  border-radius: 2px;
  /* CLS fix: explicit min-height prevents row height shift */
  min-height: 52px;
}
.frq-row:hover {
  background: var(--paper-2);
}
.frq-row:focus-within {
  background: var(--paper-2);
}

.frq-row .ord {
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-weight: 500;
  font-size: 19px;
  color: var(--moss-deep);
  width: 32px;
  /* CLS fix: reserve width */
  min-width: 32px;
}
.frq-row .label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.frq-row .label .nm {
  font-size: clamp(13.5px, 1.1vw, 14.5px);
  font-weight: 600;
  color: var(--ink);
}
.frq-row .label .tp {
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: clamp(10.5px, 0.9vw, 11.5px);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  word-break: break-word;
}
.frq-row .ratio {
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
  min-width: 42px;
  text-align: right;
  white-space: nowrap;
}

.panel.right {
  background: linear-gradient(180deg, var(--paper-2) 0%, var(--paper) 100%);
  display: flex;
  flex-direction: column;
}

/* ─── CRITICAL CLS FIX: grade-display ──────────────────────────────────── */
/*
 * The giant Fraunces digit was the main CLS culprit (CLS=1).
 * We reserve the exact space before the font loads using explicit
 * width + height based on the known font metrics.
 * aspect-ratio + min-height + overflow:hidden prevents any reflow.
 */
.verdict {
  text-align: center;
  margin-top: calc(-1 * var(--pad-panel));
  margin-left: calc(-1 * var(--pad-panel));
  margin-right: calc(-1 * var(--pad-panel));
  margin-bottom: calc(-1 * var(--pad-panel));
  padding: var(--pad-panel) 0;
  background-color: var(--color-outline-variant);
}
.verdict .lab {
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: clamp(11px, 0.9vw, 12px);
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 8px;
  /* Reserve label height */
  min-height: 18px;
  display: block;
}

.grade-display {
  position: relative;
  display: inline-flex;
  align-items: flex-end;
  gap: clamp(6px, 0.8vw, 10px);
  padding: 8px 0 0;
  max-width: 100%;
  /* CLS fix: explicit height reservation based on digit size */
  min-height: calc(
    var(--grade-digit-size) * 0.88
  ); /* 0.88 = line-height 0.85 + padding */
}

.grade-display .digit {
  font-family:
    "Fraunces", Georgia, serif; /* fallback: Georgia preserves rough size */
  font-variation-settings: "opsz" 144;
  font-weight: 400;
  font-size: var(--grade-digit-size);
  line-height: 0.85;
  color: var(--moss-deep);
  letter-spacing: -0.05em;
  transition:
    color 0.4s ease,
    transform 0.4s cubic-bezier(0.2, 0.7, 0.3, 1.2);
  display: inline-block;
  /* CLS fix: pre-size based on single digit width — "3" in Fraunces ≈ 0.6em wide */
  min-width: calc(var(--grade-digit-size) * 0.6);
  text-align: center;
  /* Prevent font swap from causing overflow */
  overflow: visible;
}

.grade-display .of-five {
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-size: clamp(15px, 1.5vw, 20px);
  font-weight: 500;
  color: var(--ink-soft);
  padding-bottom: clamp(10px, 1.5vw, 18px);
  white-space: nowrap;
  /* Reserve space */
  min-width: 40px;
}

.verdict-text {
  margin-top: 36px;
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-size: clamp(16px, 1.5vw, 19px);
  font-weight: 500;
  color: var(--ink);
  /* CLS fix: reserve fixed height to prevent layout jump on text change */
  min-height: 28px;
  line-height: 1.4;
}

.composite {
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: 1px solid var(--rule);
}
.composite-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
  gap: var(--space-sm);
  flex-wrap: wrap;
}
.composite-head .ttl {
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-size: clamp(14px, 1.2vw, 15px);
  font-weight: 500;
  color: var(--ink);
}
.composite-head .val {
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: clamp(12px, 1vw, 13px);
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.composite-head .val .num {
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(20px, 2vw, 24px);
  font-weight: 600;
  color: var(--moss-deep);
  margin-right: 4px;
  /* CLS fix: reserve width for up to 3 digits */
  display: inline-block;
  min-width: 2ch;
  text-align: right;
}

/* CLS fix: progress bar — explicit height prevents reflow */
.composite-bar {
  position: relative;
  height: clamp(28px, 3vw, 32px);
  min-height: 28px;
  background: var(--paper);
  border: 1px solid var(--ink);
  overflow: hidden;
  border-radius: 2px;
}
.composite-fill {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(
    45deg,
    var(--moss-deep),
    var(--moss-deep) 6px,
    var(--moss) 6px,
    var(--moss) 12px
  );
  transition: width 0.5s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.composite-thresholds {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.threshold {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--paper);
  opacity: 0.9;
}
.threshold-labels {
  position: relative;
  margin-top: 8px;
  height: 18px;
  /* CLS fix: explicit height prevents reflow when labels inject */
}
.threshold-label {
  position: absolute;
  transform: translateX(-50%);
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: clamp(10px, 0.9vw, 12px);
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}
.threshold-label.active {
  color: var(--terracotta);
  font-weight: 700;
}

.breakdown {
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: 1px solid var(--rule);
}
.breakdown h3 {
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-weight: 500;
  font-size: clamp(15px, 1.3vw, 16px);
  color: var(--ink);
  margin-bottom: 14px;
  letter-spacing: 0.01em;
}
.br-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: var(--space-sm);
  padding: 12px 0;
  border-bottom: 1px dotted var(--rule);
  font-size: clamp(13px, 1.1vw, 14px);
  align-items: baseline;
  /* CLS fix: reserve row height */
  min-height: 42px;
}
.br-row:last-of-type {
  border-bottom: none;
}
.br-row .lbl {
  color: var(--ink);
  font-family: "Manrope", "Segoe UI", sans-serif;
  font-weight: 600;
}
.br-row .raw {
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: clamp(11.5px, 1vw, 12.5px);
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.br-row .scaled {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  color: var(--moss-deep);
  font-size: clamp(15px, 1.4vw, 17px);
  min-width: 60px;
  text-align: right;
}
.br-row.total {
  margin-top: 6px;
  padding-top: 14px;
  border-top: 2px solid var(--ink);
  border-bottom: none;
}
.br-row.total .lbl {
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-size: clamp(15px, 1.3vw, 16px);
  color: var(--ink);
}
.br-row.total .scaled {
  font-size: clamp(20px, 2vw, 24px);
  font-weight: 600;
}

.reset {
  margin-top: var(--space-md);
  width: 100%;
  background: transparent;
  border: 1.5px solid var(--ink);
  padding: 14px;
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: clamp(11px, 0.9vw, 12px);
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  cursor: pointer;
  transition:
    background 0.2s ease,
    color 0.2s ease;
  border-radius: 2px;
  touch-action: manipulation;
  min-height: 44px;
}
.reset:hover {
  background: var(--ink);
  color: var(--paper);
}
.reset:focus-visible {
  background: var(--ink);
  color: var(--paper);
}

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

/* ─── Article content sections ──────────────────────────────────── */
.info-section {
  margin-top: var(--space-2xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--rule);
  /* CLS fix: contain prevents children from causing ancestor reflow */
  contain: layout;
}
.info-section:first-of-type {
  border-top: none;
}
.info-section h2 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  font-size: clamp(22px, 2.6vw, 32px);
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: var(--space-md);
  line-height: 1.2;
}
.info-section h2::before {
  content: "§ ";
  color: var(--terracotta);
  font-style: italic;
  font-weight: 500;
}
.info-section p {
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(15px, 1.3vw, 17px);
  line-height: 1.65;
  color: var(--ink-soft);
  margin-bottom: var(--space-sm);
  max-width: 72ch;
}
.info-section ul {
  list-style: none;
  margin: var(--space-md) 0;
  padding: 0;
}
.info-section ul li {
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(15px, 1.3vw, 17px);
  line-height: 1.65;
  color: var(--ink-soft);
  padding: 10px 0 10px 28px;
  position: relative;
  border-bottom: 1px dotted var(--rule);
}
.info-section ul li:last-child {
  border-bottom: none;
}
.info-section ul li::before {
  content: "❧";
  position: absolute;
  left: 0;
  top: 10px;
  color: var(--moss-deep);
  font-size: 14px;
}
.info-section ul li strong {
  font-family: "Manrope", "Segoe UI", sans-serif;
  font-weight: 600;
  color: var(--ink);
  font-size: 0.96em;
}
.info-section a {
  color: var(--moss-deep);
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 3px;
}
.info-section a:hover {
  text-decoration-color: var(--moss-deep);
}

/* ─── Scoring table ──────────────────────────────────── */
.scoring-table-wrap {
  margin: var(--space-md) 0;
  overflow-x: auto;
  border: 1px solid var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow);
  position: relative;
  /* CLS fix: prevent overflow from expanding parent */
  contain: layout;
}
.scoring-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Manrope", "Segoe UI", sans-serif;
  min-width: 540px;
}
.scoring-table thead {
  background: var(--ink);
  color: var(--paper);
}
.scoring-table th {
  padding: 14px 18px;
  text-align: left;
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.scoring-table td {
  padding: 14px 18px;
  border-bottom: 1px dotted var(--rule);
  font-size: clamp(13.5px, 1.1vw, 14.5px);
  color: var(--ink-soft);
  vertical-align: middle;
}
.scoring-table tbody tr:last-child td {
  border-bottom: none;
}
.scoring-table tbody tr:hover {
  background: var(--paper-2);
}
.scoring-table td:first-child {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: clamp(20px, 2vw, 24px);
  width: 80px;
  text-align: center;
}
.scoring-table .score-5 {
  color: var(--moss-deep);
}
.scoring-table .score-4 {
  color: var(--leaf);
}
.scoring-table .score-3 {
  color: var(--ochre);
}
.scoring-table .score-2 {
  color: var(--terracotta);
}
.scoring-table .score-1 {
  color: var(--ink-soft);
}

/* ─── Tip cards ──────────────────────────────────── */
.tip-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-md);
  margin: var(--space-md) 0;
  /* CLS fix: reserve approximate grid height */
  contain: layout;
}
.tip-card {
  background: var(--paper);
  border: 1px solid var(--ink);
  padding: var(--space-md);
  position: relative;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
  /* CLS fix: explicit min-height prevents card height jumping */
  min-height: 140px;
}
.tip-card::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid var(--rule-soft);
  pointer-events: none;
}
.tip-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.tip-icon {
  font-size: 28px;
  margin-bottom: 10px;
  line-height: 1;
  /* CLS fix: explicit size for emoji icons */
  display: block;
  width: 36px;
  height: 36px;
}
.tip-card h3 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  font-size: clamp(16px, 1.4vw, 18px);
  color: var(--ink);
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}
.tip-card p {
  font-family: "Manrope", "Segoe UI", sans-serif;
  font-size: clamp(13.5px, 1.1vw, 14.5px);
  line-height: 1.5;
  color: var(--ink-soft);
  margin: 0;
}

/* ─── FAQ ──────────────────────────────────── */
.faq {
  margin-top: var(--space-2xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--rule);
}
.faq h2 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  font-size: clamp(22px, 2.6vw, 32px);
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: var(--space-md);
}
.faq h2::before {
  content: "§ ";
  color: var(--terracotta);
  font-style: italic;
  font-weight: 500;
}
.faq-item {
  border-bottom: 1px solid var(--rule);
}
.faq-item summary {
  padding: var(--space-md) 0;
  cursor: pointer;
  font-family: "Manrope", "Segoe UI", sans-serif;
  font-weight: 600;
  font-size: clamp(15px, 1.2vw, 16px);
  color: var(--ink);
  list-style: none;
  position: relative;
  padding-right: 40px;
  transition: color 0.2s ease;
  /* CLS fix: explicit min-height for summary row */
  min-height: 52px;
  display: flex;
  align-items: center;
}
.faq-item summary::-webkit-details-marker {
  display: none;
}
.faq-item summary::after {
  content: "+";
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-family: "Fraunces", Georgia, serif;
  font-size: 24px;
  font-weight: 400;
  color: var(--moss-deep);
  transition: transform 0.25s ease;
}
.faq-item[open] summary::after {
  content: "−";
  transform: translateY(-50%) rotate(180deg);
}
.faq-item summary:hover {
  color: var(--moss-deep);
}
.faq-answer {
  padding: 0 0 var(--space-md);
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(14.5px, 1.2vw, 16px);
  line-height: 1.65;
  color: var(--ink-soft);
  max-width: 72ch;
}

/* ─── Footer ──────────────────────────────────── */
.site-footer {
  position: relative;
  z-index: 1;
  margin-top: var(--space-2xl);
  background: var(--ink);
  color: var(--paper);
  padding: var(--space-2xl) var(--pad-wrap-x) var(--space-md);
  /* CLS fix: footer is below fold — no special treatment needed but contain helps */
  contain: layout;
}
.footer-top {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: var(--space-xl);
  padding-bottom: var(--space-xl);
  border-bottom: 1px solid rgba(246, 241, 230, 0.15);
}
.footer-brand .footer-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 22px;
  color: var(--paper);
  text-decoration: none;
  margin-bottom: 14px;
}
.footer-logo-icon {
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  color: var(--ink);
  border-radius: 6px;
}
.footer-logo-icon svg {
  width: 18px;
  height: 18px;
}
.footer-tagline {
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-size: 14.5px;
  line-height: 1.55;
  color: rgba(246, 241, 230, 0.7);
  max-width: 320px;
}
.footer-col-title {
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(246, 241, 230, 0.55);
  margin-bottom: 14px;
}
.footer-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.footer-link {
  font-family: "Manrope", "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 500;
  color: var(--paper);
  text-decoration: none;
  transition: color 0.2s ease;
}
.footer-link:hover {
  color: var(--terracotta);
}
.footer-disclaimer {
  max-width: 1200px;
  margin: var(--space-md) auto 0;
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-size: 13px;
  line-height: 1.5;
  color: rgba(246, 241, 230, 0.55);
  text-align: center;
}
.footer-bottom {
  max-width: 1200px;
  margin: var(--space-md) auto 0;
  padding-top: var(--space-md);
  border-top: 1px solid rgba(246, 241, 230, 0.1);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(246, 241, 230, 0.5);
}

/* ─── Animation — defer to after paint ──────────────────────────────────── */
/*
 * CLS fix: original animate class fired on first paint and used
 * translateY(12px) which could contribute to layout shifts on mobile.
 * We now use opacity-only animation (no transform that causes reflow)
 * and add animation-fill-mode: both so elements don't flash.
 * The transform is safe on compositor thread but the original was causing
 * CLS because elements started at opacity:0 and then jumped.
 */
@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate {
  animation: riseIn 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  /* 
   * CLS fix: will-change moves animation to compositor so it doesn't
   * trigger layout recalculation. Combined with transform-origin: top center
   * it stays in the existing layout space.
   */
  will-change: opacity, transform;
}

/*
 * CLS fix for above-fold animated elements:
 * Elements with animation-delay > 0 would start invisible, causing 
 * height reservation issues. We ensure the element still occupies space.
 */
.animate[style*="animation-delay"] {
  opacity: 0;
  animation-fill-mode: both;
}

@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;
  }
  .grade-display .digit.flash {
    transform: none;
  }
  /* Ensure elements are visible when motion is reduced */
  .animate {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }
}

@media (prefers-contrast: more) {
  :root {
    --ink-mute: #1a2820;
    --ink-soft: #1a2820;
    --rule: #1a2820;
    --rule-soft: #4a5a50;
  }
}

/* ─── Responsive ──────────────────────────────────── */
@media (max-width: 1100px) {
  .calculator {
    grid-template-columns: 1.25fr 1fr;
  }
}

@media (max-width: 980px) {
  .lede {
    gap: var(--space-xl);
  }
  .calculator {
    grid-template-columns: 1.15fr 1fr;
  }
  .frq-row {
    gap: 8px 12px;
    padding: 10px 10px;
  }
  .footer-top {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 900px) {
  .main-nav {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(320px, 80vw);
    height: 100dvh;
    background-color: var(--ink);
    border-left: 1px solid var(--ink);
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 80px var(--pad-wrap-x) var(--pad-wrap-x);
    align-items: stretch;
    z-index: 50;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
    box-shadow: -12px 0 32px -16px rgba(26, 40, 32, 0.2);
    overflow-y: auto;
  }

  .main-nav.active {
    transform: translateX(0);
  }

  .main-nav .nav-link {
    display: block;
    width: 100%;
    padding: 16px 0;
    font-size: 13px;
    line-height: 1.35;
    color: var(--paper);
    border-bottom: 1px dotted rgba(247, 249, 251, 0.28);
  }

  .main-nav .nav-link:hover,
  .main-nav .nav-link:focus-visible {
    color: var(--focus);
  }

  .main-nav .nav-link::after {
    display: none;
  }

  .menu-toggle {
    display: inline-flex;
    z-index: 60;
    position: relative;
  }

  .mobile-overlay {
    z-index: 40;
  }
}

@media (max-width: 820px) {
  .lede {
    grid-template-columns: 1fr;
    gap: var(--space-md);
    align-items: start;
  }
  .calculator {
    grid-template-columns: 1fr;
    min-height: auto; /* allow natural stacking height on mobile */
  }
  .panel.left {
    border-right: none;
    border-bottom: 1px solid var(--ink);
  }
  /* CLS fix: on mobile the grade digit is smaller — update custom property */
  :root {
    --grade-digit-size: clamp(96px, 24vw, 150px);
  }
}

@media (max-width: 700px) {
  .footer-top {
    grid-template-columns: 1fr;
    gap: var(--space-lg);
  }
  .footer-bottom {
    justify-content: center;
    text-align: center;
  }
}

@media (max-width: 600px) {
  .article-masthead {
    grid-template-columns: 1fr;
    gap: var(--space-xs);
    text-align: center;
    justify-items: center;
    min-height: auto;
  }
  .article-masthead .vol {
    order: 1;
  }
  .article-masthead h1 {
    order: 2;
    min-height: auto;
  }
  .article-masthead .crest {
    order: 3;
  }
  .subhead {
    justify-content: center;
    text-align: center;
  }
  .frq-row {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    gap: 10px 10px;
    padding: 12px 10px;
    align-items: center;
  }
  .frq-row .ord {
    grid-column: 1;
    grid-row: 1;
  }
  .frq-row .label {
    grid-column: 2 / -1;
    grid-row: 1;
  }
  .frq-row .ratio {
    grid-column: 2;
    grid-row: 2;
    justify-self: end;
    text-align: right;
    padding-left: 0;
    align-self: center;
  }
  .frq-row .stepper {
    grid-column: 3;
    grid-row: 2;
    justify-self: end;
    align-self: center;
  }
  .section-label {
    align-items: flex-start;
  }
  .section-label > div {
    flex: 1;
    min-width: 0;
  }
  .composite-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  .corner-leaf {
    display: none;
  }
  .tip-cards {
    grid-template-columns: 1fr;
  }
  /* CLS fix: smaller grade digit on small phones */
  :root {
    --grade-digit-size: clamp(90px, 28vw, 140px);
  }
}

@media (max-width: 420px) {
  .wrap {
    padding-left: 14px;
    padding-right: 14px;
  }
  .panel {
    padding: 22px 18px;
  }
  .frq-row {
    padding: 10px 6px;
  }
  .frq-row .ord {
    width: 24px;
    font-size: 17px;
  }
  .subhead {
    font-size: 10px;
  }
  .field-head {
    align-items: flex-start;
  }
  .br-row {
    grid-template-columns: 1fr auto;
    gap: 4px 12px;
  }
  .br-row .raw {
    grid-column: 1 / -1;
    grid-row: 2;
    text-align: left;
  }
  .br-row .lbl {
    grid-column: 1;
    grid-row: 1;
  }
  .br-row .scaled {
    grid-column: 2;
    grid-row: 1;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .wrap {
    padding-top: 20px;
    padding-bottom: 32px;
  }
  .lede {
    margin-top: 28px;
  }
  .calculator {
    margin-top: 28px;
  }
  .grade-display .digit {
    font-size: clamp(90px, 14vw, 160px);
  }
}

@media print {
  body::before,
  .corner-leaf,
  .skip-link,
  .reset,
  .masthead-top,
  .breadcrumb-wrap,
  .site-footer,
  .menu-toggle {
    display: none !important;
  }
  .calculator {
    break-inside: avoid;
    box-shadow: none;
  }
  .animate {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}
/* Replace the old .grade-display .digit.flash rule with these */
@keyframes flashA {
  0% {
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes flashB {
  0% {
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
  }
}
.grade-display .digit[data-flash="a"] {
  animation: flashA 0.4s cubic-bezier(0.2, 0.7, 0.3, 1.2) forwards;
}
.grade-display .digit[data-flash="b"] {
  animation: flashB 0.4s cubic-bezier(0.2, 0.7, 0.3, 1.2) forwards;
}
