/* roughlogic.com - dark "encryptalotta" theme.
   Visual contract intentionally mirrors encryptalotta.com:
   - near-black/charcoal/graphite layered surfaces
   - white-on-dark text with two muted secondary tints
   - rounded cards with arrow-on-hover affordance
   - pill buttons, sticky topbar, gentle entry animations
   Spec.md section 8 (no emoji, no em-dash) and section 11 (live-render,
   48 px touch targets, single-h1 per view, aria-live output region) all
   continue to hold.
*/

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* The HTML `hidden` attribute should always hide an element, even when
   author CSS gives that element a more specific `display` rule (e.g.,
   the `.copy-all-btn` rule below sets `display: inline-flex`, which by
   specificity outranks the user-agent `[hidden] { display: none }`).
   This rule restores the expected behavior so `el.hidden = true` always
   visually hides the element. */
[hidden] { display: none !important; }

:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #2a2a2a;

  --fg: #ffffff;
  --fg-muted: #c8c8c8;       /* 8.5:1 on bg-secondary */
  --fg-dim: #9a9a9a;         /* 5.5:1 on bg-secondary */

  --border: #333333;
  --border-light: #404040;

  --accent-hover: #e0e0e0;
  --focus-ring: #4d90fe;
  --heart: #ff5d6c;

  /* Single brand accent (the only chromatic hue in the otherwise
     monochrome palette). Used for links, the shell "Run the calculator"
     CTA, input focus, and the copy-success pulse. Theme-specific so it
     clears WCAG AA as link text on each surface: #5aa9ff is 7.1:1 on
     bg-secondary in dark; the light override (#0a66c2) is 5.2:1 on
     bg-secondary in light. --bg aliases the primary surface so CTA text
     (color:var(--bg)) inverts cleanly against the accent fill in both
     themes (8.1:1 dark, 5.7:1 light). Previously both tokens were
     referenced by the prerendered shells but never defined, so shell
     links and the CTA fell back to plain body text. */
  --accent: #5aa9ff;
  --accent-strong: #7dbcff;
  --bg: var(--bg-primary);

  /* Validity / error tokens. The dark-mode pair (border + reason) keeps
     readable contrast on bg-secondary; the light-mode override below
     swaps to deeper red shades that meet WCAG AA on white (>= 4.5:1). */
  --error-border: #ff5d6c;
  --error-text: #ff8c95;

  --header-bg: rgba(10, 10, 10, 0.85);

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 48px;
  --space-7: 64px;

  --touch-min: 48px;
  --shell-max: 1100px;

  --font-stack: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, 'Cascadia Mono',
    'Roboto Mono', Consolas, 'Liberation Mono', monospace;
}

body {
  font-family: var(--font-stack);
  background: var(--bg-primary);
  color: var(--fg);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--border-light);
  text-underline-offset: 3px;
}

a:hover { text-decoration-color: var(--fg); }

a:focus, button:focus, select:focus, input:focus, textarea:focus,
[tabindex]:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

button {
  font-family: inherit;
}

main {
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: 0 var(--space-4) var(--space-5);
}

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: var(--space-2);
  background: var(--bg-secondary);
  color: var(--fg);
  padding: 10px 14px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  text-decoration: none;
  z-index: 100;
}

.skip-link:focus {
  left: var(--space-3);
}

/* Visually hidden (accessible) */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ============================================================
   Sticky topbar / site header (encryptalotta visual mirror)
   ============================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: rl-fade-down 0.5s ease-out;
}

.header-inner {
  max-width: var(--shell-max);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
  color: var(--fg);
  flex: 0 0 auto;
  border-radius: var(--radius);
  padding: 4px 6px;
  margin: -4px -6px;
  transition: opacity 0.18s ease;
}

.brand:hover { opacity: 0.85; }

.wordmark {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--fg);
}

.tagline {
  font-size: 0.92rem;
  color: var(--fg-muted);
}

.primary-nav {
  flex: 0 0 auto;
}

.primary-nav a {
  color: var(--fg-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 8px 12px;
  border-radius: var(--radius);
}

.primary-nav a:hover {
  color: var(--fg);
  background: var(--bg-secondary);
}

/* ============================================================
   Search input - shared visual rules (hero search box).
   ============================================================ */
.search-input {
  width: 100%;
  background: var(--bg-tertiary);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.search-input::placeholder { color: var(--fg-dim); }

.search-input:focus {
  border-color: var(--fg);
  background: var(--bg-secondary);
}

/* ============================================================
   Home view - centered elevator pitch + one search combobox.
   The home tile grid was retired; the catalog is reachable through the
   search dropdown, the per-tile shells, and the per-group shells.
   ============================================================ */
.home {
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(72px, 14vh, 180px) var(--space-4) var(--space-7);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.home-h1 {
  margin: 0 auto var(--space-4);
  max-width: 16ch;
  font-size: clamp(2.1rem, 5.5vw, 3rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--fg);
}

.home-lede {
  margin: 0 auto var(--space-6);
  max-width: 54ch;
  font-size: 1.08rem;
  line-height: 1.65;
  color: var(--fg-muted);
}

/* One search bar with a results dropdown (combobox). Centered in the hero
   and sized large so it reads as the primary entry point. */
.hero-search {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  text-align: left;
}

.hero-label {
  display: block;
  margin-bottom: 12px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--fg);
  text-align: center;
}

.hero-search .search-input {
  padding: 20px 26px;
  font-size: 1.25rem;
  border-radius: var(--radius-pill);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

/* The hero search is the front door: on focus, the border picks up the
   brand accent and a soft accent halo so it feels alive without breaking
   the monochrome restraint elsewhere. */
.hero-search .search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(90, 169, 255, 0.18);
}

/* Static "browse by trade" index under the hero. Links to the 24
   prerendered group hubs: a crawlable content + internal-link surface
   on the home document, kept visually quiet so the search bar stays
   the primary entry point. */
.home-trades {
  width: 100%;
  max-width: 720px;
  margin: var(--space-6) auto 0;
  text-align: center;
}

.home-trades-h2 {
  margin: 0 0 var(--space-3);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
}

.home-trades-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
}

.home-trades-list a {
  display: inline-block;
  padding: 8px 14px;
  font-size: 0.92rem;
  color: var(--fg-muted);
  text-decoration: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

.home-trades-list a:hover,
.home-trades-list a:focus-visible {
  color: var(--fg);
  border-color: var(--accent);
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  list-style: none;
  margin: 0;
  padding: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
  max-height: min(60vh, 460px);
  overflow-y: auto;
  z-index: 40;
  text-align: left;
}

.search-results[hidden] { display: none; }

.search-result {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--fg);
  user-select: none;
}

.search-result .sr-name { font-weight: 600; font-size: 0.98rem; }
.search-result .sr-group { font-size: 0.78rem; color: var(--fg-dim); }

.search-result:hover,
.search-result.is-active {
  background: var(--bg-tertiary);
}

.search-empty {
  padding: 16px 14px;
  color: var(--fg-muted);
  font-size: 0.92rem;
  text-align: center;
}

/* ============================================================
   Tool view (content panel)
   ============================================================ */
.view-region {
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: 0 var(--space-4);
  margin-top: var(--space-4);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-4);
  animation: rl-fade-up 0.4s ease-out;
}

.view-header-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch-min);
  padding: 0 14px;
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.back-link:hover {
  color: var(--fg);
  border-color: var(--border-light);
  background: var(--bg-tertiary);
}

.view-title {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.015em;
  margin: 0 0 var(--space-2);
  color: var(--fg);
}

.view-desc {
  font-size: 1.05rem;
  color: var(--fg-muted);
  margin: 0 0 var(--space-4);
}

.inline-notice {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-left: 3px solid var(--fg);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: var(--space-4);
  font-size: 0.92rem;
  color: var(--fg-muted);
}

/* v10 §B.1 limitation-banner: visually distinct from the citation
   footer and the result-area context band. Reuses .inline-notice as a
   base and thickens the left rule so the "what this is NOT" message
   reads at a glance. Color follows the High-Contrast palette through
   the existing inline-notice hook. */
.limitation-banner {
  border-left-width: 5px;
}
.limitation-banner .limitation-headline {
  display: block;
  font-size: 1rem;
  margin-bottom: 6px;
  color: var(--fg);
}
.limitation-banner .limitation-replacement,
.limitation-banner .limitation-governs,
.limitation-banner .limitation-link {
  margin: 6px 0 0;
}
.limitation-banner .limitation-link a {
  color: var(--fg);
  text-decoration: underline;
}

.citation {
  font-size: 0.85rem;
  color: var(--fg-dim);
  font-style: italic;
  margin-bottom: var(--space-3);
}

/* Source links read in the brand accent so a tradesperson can see at a
   glance that a citation's free-access pointer is tappable. Scoped to the
   citation / reference / sources surfaces; body prose links stay
   monochrome per the visual contract. citations.js fillCitationText emits
   .citation-link anchors around bare domains. */
.citation-link,
.citation a,
.v6-reference-block a,
.sources-region a,
.limitation-banner a {
  color: var(--accent);
  text-decoration-color: var(--accent);
  overflow-wrap: anywhere;
  word-break: break-word;
}
.citation-link:hover,
.citation a:hover,
.v6-reference-block a:hover,
.sources-region a:hover,
.limitation-banner a:hover {
  color: var(--accent-strong);
  text-decoration-color: var(--accent-strong);
}

.input-region, .output-region {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}

/* Hide an empty input-region. Group H reference utilities (color codes,
   knot reference, etc.) render their content into the output region and
   leave the input region empty; without this rule the empty bordered
   box reads as a layout glitch. */
.input-region:empty { display: none; }

.input-region .field {
  margin-bottom: var(--space-3);
}

.input-region .field:last-child { margin-bottom: 0; }

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--fg);
  font-size: 0.92rem;
}

input[type="number"],
input[type="text"],
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-primary);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.18s ease, background 0.18s ease;
}

input[type="number"]:focus,
input[type="text"]:focus,
select:focus,
textarea:focus {
  border-color: var(--fg);
  background: var(--bg-secondary);
}

input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--fg);
  vertical-align: middle;
  margin-right: 8px;
}

input::placeholder, textarea::placeholder { color: var(--fg-dim); }

input[aria-invalid="true"] {
  border-color: var(--error-border);
}

.validity-reason {
  display: block;
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--error-text);
}

.output-region {
  background: var(--bg-primary);
}

.output-region p {
  margin: 0 0 var(--space-2);
  font-size: 1rem;
  color: var(--fg);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.output-region strong {
  color: var(--fg-muted);
  font-weight: 600;
  min-width: 0;
}

.out-value {
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 0.98rem;
  /* A long unbreakable result token (a binary base-conversion string, a
     long hex pin, a multi-segment code) must wrap inside the flex output
     line rather than push the view-region wider than the viewport. The
     flex item needs min-width:0 for the break to take effect. */
  min-width: 0;
  overflow-wrap: anywhere;
}

.output-region.output-stale .out-value,
.output-region.output-stale span {
  text-decoration: line-through;
  color: var(--fg-dim);
}

.output-region dl {
  margin: 0;
}

.output-region dt {
  margin-top: var(--space-3);
  font-weight: 700;
  color: var(--fg);
}

.output-region dt:first-child { margin-top: 0; }

.output-region dd {
  margin: 4px 0 var(--space-2) 0;
  color: var(--fg-muted);
}

.output-region ul, .output-region ol {
  margin: 0 0 var(--space-2) var(--space-3);
  padding: 0;
  color: var(--fg-muted);
}

.output-region li {
  margin-bottom: 6px;
}

/* Per-output Copy and Copy-all. Min 48 px touch target per spec.md
   section 11.6 / spec-v2.md section 1. */
.copy-btn,
.copy-all-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-min);
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.copy-btn:hover,
.copy-all-btn:hover {
  color: var(--bg-primary);
  background: var(--fg);
  border-color: var(--fg);
}

.copy-all-btn {
  margin-top: var(--space-3);
}

/* Copy-success pulse. When a copy button reports success (clipboard.js
   flashCopied) it swaps its label to "Copied!" and adds .is-copied; the
   accent fill confirms the action visually for the ~1.3s before it
   restores. The accent uses --bg for text so it stays AA in both themes.
   The lift is transform-only and is neutralized by the global
   prefers-reduced-motion rule. */
.copy-btn.is-copied,
.copy-all-btn.is-copied,
.view-copy-reference.is-copied {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.sources-region {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

.data-source-stamp {
  font-size: 0.82rem;
  color: var(--fg-dim);
  font-family: var(--font-mono);
  margin: 0;
}

/* v6 §3 reference block. Mounts in the sources-region beneath the result,
   above the legacy data-source-stamp. Sized at the same scale as the answer
   per spec §8 (the reference is part of the answer). */
.v6-reference-block {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--border);
}
.v6-reference-heading {
  font-size: 1rem;
  margin: 0 0 var(--space-2) 0;
}
.v6-reference-subheading {
  font-size: 0.95rem;
  margin: var(--space-2) 0 var(--space-1) 0;
}
.v6-reference-list,
.v6-assumption-list {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px var(--space-2);
}
.v6-reference-list dt,
.v6-assumption-list dt {
  font-weight: 600;
  white-space: nowrap;
}
.v6-reference-list dd,
.v6-assumption-list dd {
  margin: 0;
}
.v6-assumption-note {
  margin: var(--space-1) 0 0 0;
  font-size: 0.9rem;
  color: var(--fg-dim);
}
.view-copy-reference {
  margin-top: var(--space-3);
  min-height: var(--touch-min);
}

/* ============================================================
   Footer (encryptalotta credit-pill mirror)
   ============================================================ */
.site-footer {
  margin: var(--space-6) auto var(--space-5);
  max-width: var(--shell-max);
  padding: 0 var(--space-4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  text-align: center;
}

.site-footer .disclaimer {
  font-size: 0.82rem;
  color: var(--fg-dim);
  max-width: 720px;
  line-height: 1.6;
  margin: 0;
}

.footer-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}

.footer-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--bg-secondary);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}

.footer-badge:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-light);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.footer-badge-icon {
  display: block;
}

.footer-badge-heart {
  color: var(--heart);
  font-size: 1rem;
  line-height: 1;
  transition: transform 0.18s ease;
}

.footer-badge:hover .footer-badge-heart {
  transform: scale(1.18);
}

/* Integrity banner */
.integrity-banner {
  background: var(--bg-secondary);
  border: 1px solid var(--error-border);
  border-left: 4px solid var(--error-border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: var(--space-3) auto;
  max-width: var(--shell-max);
  color: var(--fg);
  font-size: 0.92rem;
}

/* ============================================================
   Animations
   ============================================================ */
/* Entry animations: transform-only so element contents render at full
   contrast at every frame. An opacity ramp would briefly composite text
   at sub-full opacity over the body bg, producing apparent low-contrast
   that axe-core flags as a WCAG 2 AA violation. */
@keyframes rl-fade-up {
  from { transform: translateY(12px); }
  to { transform: translateY(0); }
}

@keyframes rl-fade-down {
  from { transform: translateY(-8px); }
  to { transform: translateY(0); }
}

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

/* ============================================================
   Changelog static viewer (scoped)
   ============================================================ */
#changelog-content h2 {
  margin-top: var(--space-4);
  margin-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space-1);
  font-size: 1.4rem;
  color: var(--fg);
}

#changelog-content h3 {
  margin-top: var(--space-3);
  margin-bottom: var(--space-2);
  font-size: 1.05rem;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#changelog-content h4 {
  margin-top: var(--space-2);
  margin-bottom: var(--space-1);
  font-size: 0.95rem;
  color: var(--fg-dim);
}

#changelog-content ul {
  margin: 0 0 var(--space-3) var(--space-3);
  padding: 0;
  color: var(--fg-muted);
}

#changelog-content li {
  margin-bottom: var(--space-2);
}

#changelog-content p {
  margin: 0 0 var(--space-2) 0;
  color: var(--fg-muted);
}

/* ============================================================
   Mobile breakpoint
   ============================================================ */
.noscript-notice {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 18px 20px;
  color: var(--fg-muted);
  font-size: 0.92rem;
  margin: var(--space-4) auto;
  max-width: 720px;
  text-align: center;
}

@media (max-width: 760px) {
  main { padding: 0 var(--space-3) var(--space-4); }
  .header-inner {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 10px;
  }
  .wordmark { font-size: 1.1rem; }
  .tagline { display: none; }
  /* Mobile header: brand (left) + theme toggle (right) on one row. */
  .brand { order: 1; }
  .theme-toggle { order: 2; margin-left: auto; }
  .home { padding: var(--space-6) var(--space-3) var(--space-5); }
  .view-region { padding: var(--space-4) var(--space-3); }
  .view-title { font-size: 1.7rem; }
  .site-footer { margin: var(--space-5) auto var(--space-4); }
  /* v12 Phase F.1: the reference block uses
     grid-template-columns: max-content 1fr on dt+dd. At a 375 px
     viewport the longest dt label ("Edition selector / disclosure")
     plus a long codes.iccsafe.org / nfpa.org / ecfr.gov URL in dd
     overflows the container because max-content does not shrink
     below intrinsic min-width. Collapse to a single-column stack
     on mobile and allow long URLs to break anywhere. Same treatment
     for the citation footer, the data-source stamp, and the
     limitation banner so every long-string surface wraps cleanly. */
  .v6-reference-list,
  .v6-assumption-list {
    grid-template-columns: 1fr;
    gap: 2px var(--space-2);
  }
  .v6-reference-list dt,
  .v6-assumption-list dt {
    white-space: normal;
    margin-top: var(--space-2);
  }
  .v6-reference-list dd,
  .v6-assumption-list dd,
  .v6-assumption-note,
  .citation,
  .data-source-stamp,
  .limitation-banner {
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}

/* ============================================================
   Print stylesheet
   ============================================================ */
@media print {
  .site-header, .primary-nav, .skip-link,
  .copy-btn, .copy-all-btn,
  .integrity-banner,
  .back-link, .site-footer .footer-badges {
    display: none !important;
  }
  body, .view-region, .input-region, .output-region {
    background: white !important;
    color: black !important;
    border-color: #999 !important;
  }
  .view-region, .input-region, .output-region {
    box-shadow: none !important;
  }
  a {
    color: black !important;
    text-decoration: underline !important;
  }
}

/* ============================================================
   Light theme override.
   Activated by `<html data-theme="light">` (set by theme.js before paint).
   The dark palette in :root remains the default so the site still
   renders correctly when the script has not yet run.
   ============================================================ */
:root[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-tertiary: #e8e8e8;

  --fg: #0a0a0a;
  --fg-muted: #404040;
  --fg-dim: #5e5e5e;

  --border: #d0d0d0;
  --border-light: #b8b8b8;

  --accent-hover: #2a2a2a;

  /* Light-theme accent: deeper blue that clears AA as link text on the
     light surfaces (5.2:1 on bg-secondary, 5.7:1 on white). */
  --accent: #0a66c2;
  --accent-strong: #084b8f;

  --header-bg: rgba(255, 255, 255, 0.85);

  /* Deeper reds that hit WCAG AA on white (5.4:1 and 6.6:1). */
  --error-border: #c0392b;
  --error-text: #a93226;
}

/* ============================================================
   Theme toggle button (sun/moon)
   ============================================================ */
.theme-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-min);
  height: var(--touch-min);
  padding: 0;
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.theme-toggle:hover {
  color: var(--fg);
  background: var(--bg-secondary);
  border-color: var(--fg-muted);
}

.theme-icon {
  display: none;
}

/* In dark mode show the sun (clicking switches to light). In light mode
   show the moon. The button toggles between dark and light. */
:root:not([data-theme="light"]) .theme-icon-sun { display: block; }
:root[data-theme="light"] .theme-icon-moon { display: block; }

/* ============================================================
   Crash-Safe Resume panel (v3 utility 187).
   ============================================================ */
.crash-panel {
  border-color: var(--error-border);
  color: var(--error-text);
}

/* ============================================================
   Preset chip row (v8 §C.1 wire-ampacity ambient presets).
   Chips render as a horizontal group below the input they prefill.
   Each chip honors the 48 px touch-min like every other interactive
   control.
   ============================================================ */
.preset-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
}
.preset-chip {
  min-height: var(--touch-min);
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--fg);
  font-size: 0.88rem;
  cursor: pointer;
}
.preset-chip:hover, .preset-chip:focus {
  background: var(--bg-primary);
  border-color: var(--border-light);
}

/* ============================================================
   v9 §F.2 lightning-countdown 30-minute resume timer.
   The hidden persistence input (id="lc-timer") is type="hidden" and
   layout-invisible via the UA stylesheet; the visible button + readout
   sit side-by-side in a flex row. The readout is monospace + tabular-
   nums so the count does not jiggle laterally as digits change.
   ============================================================ */
.lightning-timer-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.lightning-timer-btn,
.lightning-timer-reset {
  min-height: var(--touch-min);
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--fg);
  font-size: 0.95rem;
  cursor: pointer;
}
.lightning-timer-btn:hover, .lightning-timer-btn:focus,
.lightning-timer-reset:hover, .lightning-timer-reset:focus {
  background: var(--bg-primary);
  border-color: var(--border-light);
}
.lightning-timer-readout {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 1.1rem;
  min-width: 5.5ch;
  text-align: center;
  color: var(--fg);
}

/* ============================================================
   v5 Step 62 utility 269: CSV export button.
   ============================================================ */
.copy-csv-btn {
  min-height: var(--touch-min);
  margin: var(--space-2) 0;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--fg);
  font-size: 0.88rem;
  cursor: pointer;
}
.copy-csv-btn:hover, .copy-csv-btn:focus {
  background: var(--bg-primary);
  border-color: var(--border-light);
}

/* ============================================================
   v5 Step 62 utility 270: Print-optimized table view.
   Multi-row tables (amortization, mileage roll-up, PCR master mix)
   need rows that don't break across pages and a thead that repeats
   on every printed page. Wrapper class scopes the rules so non-tabular
   prints aren't affected.
   ============================================================ */
/* On screen, a wide multi-column table (loan amortization is 5 columns of
   currency; PCR master mix, mileage roll-up similar) has an intrinsic width
   that exceeds a 320 px phone viewport. Without a scroll container the table
   would push the whole .view-region wider than the screen and produce
   page-level horizontal scroll, which the spec-v12 §10 mobile sweep forbids.
   The wrapper owns the horizontal scroll so only the table scrolls and the
   page itself never does. The print block below restores full-width layout
   for paper. */
.tabular-tool {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media print {
  .tabular-tool table {
    page-break-inside: auto;
    border-collapse: collapse;
    width: 100%;
  }
  .tabular-tool tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }
  .tabular-tool thead {
    display: table-header-group;
  }
  .tabular-tool tfoot {
    display: table-footer-group;
  }
  .tabular-tool th, .tabular-tool td {
    border: 1px solid #000;
    padding: 4px 8px;
    font-size: 10pt;
  }
}

/* ============================================================
   v5 Step 62 utility 271: Inline glossary tooltip.
   Tooltip is hidden by default; the JS toggle in v5-platform.js
   shows / hides it via inline style. Positioned inline so it
   renders next to the field; mobile reads it inline as a clarifying
   line of text when shown.
   ============================================================ */
.glossary-tooltip {
  display: inline-block;
  margin: var(--space-1) 0 var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--fg);
  font-size: 0.8125rem;
  max-width: 60ch;
}


/* ============================================================
   spec-v13 Phase A + D: per-tile and per-group prerendered shells.
   The shells are static reference pages that share styles.css with
   the SPA. The selectors below scope shell-only structure (the
   breadcrumb, the lead paragraph under the h1, the "Run the
   calculator" button, the related-tiles list, the shell-page
   disclaimer footer copy). The shells carry no JavaScript, so the
   selectors do not need any state variants.
   ============================================================ */
.shell-page .shell-main {
  max-width: 72ch;
  margin: 0 auto;
  padding: var(--space-4) var(--space-3);
}
.shell-page .shell-breadcrumb ol {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-3);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: 0.875rem;
}
.shell-page .shell-breadcrumb li + li::before {
  content: "/ ";
  color: var(--fg-muted);
  margin-right: var(--space-2);
}
.shell-page .shell-breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}
.shell-page .shell-breadcrumb a:hover,
.shell-page .shell-breadcrumb a:focus {
  text-decoration: underline;
}
.shell-page .shell-h1 {
  font-size: 1.75rem;
  margin: 0 0 var(--space-2);
}
.shell-page .shell-lead {
  font-size: 1.0625rem;
  line-height: 1.5;
  margin: 0 0 var(--space-3);
}
.shell-page .shell-run {
  margin: var(--space-3) 0;
}
.shell-page .shell-run-link {
  display: inline-block;
  min-height: 48px;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  text-decoration: none;
  line-height: 2;
}
.shell-page .shell-run-link:hover,
.shell-page .shell-run-link:focus {
  filter: brightness(1.1);
  text-decoration: underline;
}
.shell-page .shell-section {
  margin: var(--space-4) 0;
}
.shell-page .shell-section h2 {
  font-size: 1.125rem;
  margin: 0 0 var(--space-2);
}
.shell-page .shell-related {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: var(--space-2);
}
.shell-page .shell-related a {
  color: var(--accent);
  text-decoration: none;
}
.shell-page .shell-related a:hover,
.shell-page .shell-related a:focus {
  text-decoration: underline;
}
.shell-page .shell-related-desc {
  color: var(--fg-muted);
  font-size: 0.9375rem;
}
.shell-page .shell-disclaimer {
  max-width: 72ch;
  margin: var(--space-3) auto 0;
  padding: var(--space-3);
  border-top: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 0.875rem;
}
