/* ============================================================================
   CalculatorGraph Design System: Editorial Clarity, High Contrast, Fast & Accessible
   - Warm white / soft neutral backgrounds (#FAF9F5 / #FFFFFF)
   - High-contrast dark ink typography (#111827 / #374151)
   - Restrained deep teal primary (#0F766E / #115E59) & slate blue accents
   - Dark theme support via [data-theme="dark"]
   - Tabular numerals (font-variant-numeric: tabular-nums) across all results/tables
   - WCAG 2.2 AA focus rings, reduced motion, and responsive 360px -> 1440px+ grid
   ============================================================================ */

:root {
  --bg-page: #faf9f5;
  --bg-surface: #ffffff;
  --bg-subtle: #f3f1eb;
  --bg-muted: #e8e5dc;
  --bg-highlight: #f0fdfa;
  --bg-warning: #fffbeb;
  --bg-danger: #fef2f2;

  --text-primary: #111827;
  --text-secondary: #374151;
  --text-muted: #5b6472;
  --text-on-brand: #ffffff;

  --border-subtle: #e4e1d8;
  --border-strong: #cbc6b8;
  --border-brand: #0f766e;

  --brand-primary: #0f766e;
  --brand-primary-hover: #115e59;
  --brand-secondary: #0369a1;
  --brand-accent: #b45309;
  --brand-success: #15803d;
  --brand-danger: #b91c1c;

  /* Accessible Chart Palette */
  --chart-1: #0f766e; /* Deep Teal */
  --chart-2: #0284c7; /* Ocean Blue */
  --chart-3: #d97706; /* Warm Amber */
  --chart-4: #4f46e5; /* Indigo */
  --chart-5: #dc2626; /* Crimson */
  --chart-grid: #e5e7eb;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-xs: 0 1px 2px rgba(17, 24, 39, 0.04);
  --shadow-sm: 0 2px 6px rgba(17, 24, 39, 0.06);
  --shadow-md: 0 8px 24px rgba(17, 24, 39, 0.08);

  --font-sans: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-serif: 'Charter', 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua', Georgia, serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Menlo, Monaco, Consolas, monospace;

  --container-max: 1280px;
}

[data-theme="dark"] {
  --bg-page: #0c1117;
  --bg-surface: #151c25;
  --bg-subtle: #1c2532;
  --bg-muted: #263244;
  --bg-highlight: #0f292a;
  --bg-warning: #2b2111;
  --bg-danger: #2d1418;

  --text-primary: #f3f4f6;
  --text-secondary: #d1d5db;
  --text-muted: #9ca3af;
  --text-on-brand: #071312;

  --border-subtle: #263140;
  --border-strong: #3b4a5e;
  --border-brand: #2dd4bf;

  --brand-primary: #2dd4bf;
  --brand-primary-hover: #5eead4;
  --brand-secondary: #38bdf8;
  --brand-accent: #fbbf24;
  --brand-success: #4ade80;
  --brand-danger: #f87171;

  --chart-1: #2dd4bf;
  --chart-2: #38bdf8;
  --chart-3: #fbbf24;
  --chart-4: #818cf8;
  --chart-5: #f87171;
  --chart-grid: #263140;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.5);
}

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

html {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text-primary);
  background-color: var(--bg-page);
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-page);
  color: var(--text-primary);
  overflow-x: hidden;
}

/* Accessible Skip Link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 1rem;
  z-index: 9999;
  padding: 0.6rem 1rem;
  background: var(--brand-primary);
  color: var(--text-on-brand);
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.skip-link:focus {
  top: 0.75rem;
}

/* Visible Keyboard Focus (WCAG 2.2 AA) */
:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}

a {
  color: var(--brand-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}
a:hover {
  color: var(--brand-primary-hover);
}

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

.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 1.25rem;
}

@media (max-width: 480px) {
  .container {
    padding: 0 0.875rem;
  }
}

/* Header & Navigation */
.site-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 64px;
  flex-wrap: wrap;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 750;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}
.brand-link:hover {
  color: var(--text-primary);
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--brand-primary);
  color: var(--text-on-brand);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.95rem;
}
.brand-tagline-pill {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  border-left: 1px solid var(--border-subtle);
  padding-left: 0.625rem;
  display: none;
}
@media (min-width: 900px) {
  .brand-tagline-pill {
    display: inline;
  }
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.nav-link {
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  transition: background-color 0.15s ease;
}
.nav-link:hover, .nav-link[aria-current="page"] {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-search-wrap {
  position: relative;
  width: 240px;
}
@media (max-width: 640px) {
  .header-search-wrap {
    width: 100%;
    order: 3;
  }
}
.header-search-input {
  width: 100%;
  padding: 0.45rem 0.75rem 0.45rem 2rem;
  font-size: 0.875rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-page);
  color: var(--text-primary);
}
.header-search-icon {
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 0.85rem;
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  min-width: 310px;
  max-width: 92vw;
  max-height: 380px;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 200;
  padding: 0.375rem;
}
.search-dropdown[hidden] {
  display: none;
}
.search-result-item {
  display: block;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-primary);
}
.search-result-item:hover,
.search-result-item[aria-selected="true"] {
  background: var(--bg-highlight);
}
.search-result-title {
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.search-result-cat {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--brand-primary);
  background: var(--bg-subtle);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}
.search-result-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}
.search-empty-state {
  padding: 0.85rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.825rem;
  font-weight: 500;
}
.icon-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

/* Breadcrumbs */
.breadcrumbs {
  padding: 0.875rem 0 0.25rem;
  font-size: 0.825rem;
  color: var(--text-muted);
}
.breadcrumbs ol {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}
.breadcrumbs li + li::before {
  content: "/";
  margin-right: 0.4rem;
  color: var(--text-muted);
}
.breadcrumbs a {
  color: var(--text-secondary);
  text-decoration: none;
}
.breadcrumbs a:hover {
  text-decoration: underline;
}

/* Hero Section (Compact, Immediate Utility) */
.hero-section {
  padding: 2rem 0 1.75rem;
  border-bottom: 1px solid var(--border-subtle);
  background: linear-gradient(180deg, var(--bg-surface) 0%, var(--bg-page) 100%);
}
.hero-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.75rem;
  align-items: start;
}
@media (min-width: 960px) {
  .hero-grid {
    grid-template-columns: 1.15fr 0.85fr;
    gap: 2.5rem;
  }
}
.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--brand-primary);
  background: var(--bg-highlight);
  border: 1px solid var(--border-subtle);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  margin-bottom: 0.75rem;
}
.hero-title {
  font-size: clamp(1.75rem, 3.2vw, 2.5rem);
  line-height: 1.15;
  letter-spacing: -0.025em;
  margin: 0 0 0.75rem;
  font-weight: 800;
}
.hero-subtitle {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin: 0 0 1.25rem;
  max-width: 62ch;
}

.hero-search-box {
  position: relative;
  max-width: 580px;
}
.hero-search-input {
  width: 100%;
  padding: 0.85rem 1rem 0.85rem 2.65rem;
  font-size: 1rem;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
}
.hero-search-input:focus {
  border-color: var(--brand-primary);
  outline: none;
}
.hero-search-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.65rem;
  font-size: 0.8rem;
  align-items: center;
}
.chip-btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  cursor: pointer;
  text-decoration: none;
}
.chip-btn:hover {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

/* Interactive Mini Demo Card on Homepage */
.quick-calc-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.quick-calc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border-subtle);
}
.quick-calc-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin: 0;
}

/* Reusable Calculator Page Layout */
.calc-page-header {
  padding: 1rem 0 1.25rem;
}
.calc-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.calc-page-title {
  font-size: clamp(1.5rem, 2.6vw, 2.15rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 0.45rem;
}
.calc-page-lead {
  font-size: 1rem;
  color: var(--text-secondary);
  max-width: 75ch;
  margin: 0;
}
.calc-meta-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.65rem;
}
.meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.76rem;
  font-weight: 550;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

/* Desktop Two-Column Split: Left Inputs, Right Results + Visualization */
.calc-workspace-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  align-items: start;
  margin-bottom: 2.25rem;
}
.calc-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem 0.8rem;
}
.calc-form-grid .form-field-wide {
  grid-column: 1 / -1;
}
.calc-form-grid .form-field {
  min-width: 0;
  margin-bottom: 0;
}
.calc-form-grid .field-label {
  font-size: 0.82rem;
}
.calc-form-grid .field-help {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}
.calc-action-row {
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: var(--bg-surface);
}
@media (min-width: 920px) {
  .calc-workspace-grid {
    grid-template-columns: minmax(330px, 5fr) minmax(400px, 7fr);
    gap: 1.75rem;
  }
}

.panel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.35rem;
  box-shadow: var(--shadow-xs);
}
@media (max-width: 480px) {
  .panel-card {
    padding: 1rem;
  }
}

.panel-section-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

/* Form Controls */
.form-field {
  margin-bottom: 1.05rem;
}
.field-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.field-label {
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--text-primary);
}
.field-unit-tag {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.input-group {
  display: flex;
  align-items: stretch;
  gap: 0.4rem;
}
.text-input,
.select-input {
  width: 100%;
  padding: 0.58rem 0.75rem;
  font-size: 0.95rem;
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  background: var(--bg-page);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease;
}
.text-input:focus,
.select-input:focus {
  border-color: var(--brand-primary);
  background: var(--bg-surface);
}
.text-input[aria-invalid="true"] {
  border-color: var(--brand-danger);
  background: var(--bg-danger);
}

.range-slider {
  width: 100%;
  margin-top: 0.45rem;
  accent-color: var(--brand-primary);
  cursor: pointer;
}

.field-help {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}
.field-error {
  font-size: 0.78rem;
  color: var(--brand-danger);
  font-weight: 600;
  margin-top: 0.28rem;
}
.field-error[hidden] {
  display: none;
}

.calc-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
}

.btn-primary {
  flex: 1 1 auto;
  padding: 0.65rem 1.1rem;
  font-size: 0.925rem;
  font-weight: 650;
  color: var(--text-on-brand);
  background: var(--brand-primary);
  border: 1px solid var(--brand-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.btn-primary:hover {
  background: var(--brand-primary-hover);
}
.btn-secondary {
  padding: 0.65rem 0.95rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.btn-secondary:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

/* Primary Result Banner */
.primary-result-box {
  background: var(--bg-highlight);
  border: 1px solid var(--border-brand);
  border-radius: var(--radius-md);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1.15rem;
}
.primary-result-label {
  font-size: 0.8rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--brand-primary);
  margin-bottom: 0.2rem;
}
.primary-result-value {
  font-size: clamp(1.65rem, 3vw, 2.35rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}
.primary-result-sub {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.35rem;
}

/* Supporting Metric Grid */
.supporting-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.metric-tile {
  background: var(--bg-page);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
}
.metric-tile-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 550;
}
.metric-tile-value {
  font-size: 1.08rem;
  font-weight: 750;
  color: var(--text-primary);
  margin-top: 0.2rem;
  font-variant-numeric: tabular-nums;
}

/* Plain-language interpretation box */
.interpretation-box {
  background: var(--bg-subtle);
  border-left: 4px solid var(--brand-primary);
  padding: 0.85rem 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
}
.interpretation-box strong {
  color: var(--text-primary);
}

/* Chart Container with Reserved Dimensions (CLS <= 0.1) */
.chart-box {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  background: var(--bg-page);
  margin-bottom: 1.15rem;
  min-height: 250px;
}
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}
.chart-title {
  font-size: 0.88rem;
  font-weight: 700;
  margin: 0;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.76rem;
  color: var(--text-secondary);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.legend-swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  display: inline-block;
}
.chart-svg-wrap {
  width: 100%;
  overflow-x: auto;
}
.chart-svg-wrap svg {
  width: 100%;
  height: auto;
  display: block;
}
.chart-sr-summary {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border-subtle);
}

/* Scenario Comparison & Utility Toolbar */
.result-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
}
.export-dropdown {
  position: relative;
  display: inline-block;
}
.export-dropdown > summary {
  list-style: none;
}
.export-dropdown > summary::-webkit-details-marker {
  display: none;
}
.export-dropdown-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  min-width: 195px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 0.4rem;
  display: grid;
  gap: 0.35rem;
  z-index: 60;
}
.export-dropdown-menu .icon-btn {
  width: 100%;
  justify-content: flex-start;
}
.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;
}
.scenario-drawer {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg-page);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
}
.scenario-drawer[hidden] {
  display: none;
}

/* Data Tables */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  margin-top: 0.75rem;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.data-table th,
.data-table td {
  padding: 0.55rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid var(--border-subtle);
}
.data-table th:first-child,
.data-table td:first-child {
  text-align: left;
}
.data-table th {
  background: var(--bg-subtle);
  font-weight: 650;
  color: var(--text-secondary);
}
.data-table tr:last-child td {
  border-bottom: none;
}

/* Educational Content Sections Below Calculator */
.content-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  margin-bottom: 3rem;
}
@media (min-width: 960px) {
  .content-stack {
    grid-template-columns: 2fr 1fr;
    align-items: start;
  }
}

.editorial-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}
.editorial-card h2 {
  font-size: 1.25rem;
  margin: 0 0 0.75rem;
  letter-spacing: -0.015em;
}
.editorial-card h3 {
  font-size: 1.02rem;
  margin: 1.25rem 0 0.5rem;
}
.formula-block,
.formula-book-card {
  background: var(--bg-page);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--brand-primary);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.35rem;
  overflow-x: auto;
  margin: 0.85rem 0;
  text-align: center;
}

/* Textbook Mathematical Equations (Stacked Fractions, Radicals, Summations, Italic Variables) */
.math-display {
  display: inline-flex;
  flex-direction: column;
  gap: 0.9rem;
  align-items: center;
  justify-content: center;
  font-family: 'STIX Two Math', 'Cambria Math', 'Latin Modern Math', 'Times New Roman', Georgia, serif;
  font-size: 1.2rem;
  line-height: 1.4;
  color: var(--text-primary);
}
.math-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.28rem;
}
.math-var {
  font-style: italic;
  font-family: 'STIX Two Math', 'Cambria Math', 'Times New Roman', Georgia, serif;
  font-weight: 500;
  padding: 0 0.04rem;
}
.math-fn {
  font-style: normal;
  font-family: 'STIX Two Math', 'Cambria Math', 'Times New Roman', Georgia, serif;
  font-weight: 550;
}
.math-sup,
.math-sub {
  font-size: 0.72em;
  line-height: 0;
}
.math-frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 0.22rem;
}
.math-num {
  padding: 0 0.4rem 0.16rem;
  border-bottom: 1.6px solid currentColor;
  width: 100%;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.18rem;
  white-space: nowrap;
}
.math-den {
  padding: 0.18rem 0.4rem 0;
  width: 100%;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.18rem;
  white-space: nowrap;
}
.math-sqrt {
  display: inline-flex;
  align-items: stretch;
  vertical-align: middle;
  margin: 0 0.15rem;
}
.math-sqrt-stem {
  font-size: 1.32em;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  padding-right: 0.02rem;
}
.math-radicand {
  border-top: 1.5px solid currentColor;
  padding: 0.12rem 0.3rem 0.04rem 0.15rem;
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
}
.math-sum-op {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  line-height: 1;
  margin: 0 0.22rem;
}
.math-sum-top,
.math-sum-bot {
  font-size: 0.65em;
}
.math-sum-sym {
  font-size: 1.45em;
  line-height: 0.95;
}
.math-parens {
  display: inline-flex;
  align-items: center;
}
.math-delim {
  font-size: 1.25em;
  font-weight: 400;
  line-height: 1;
  padding: 0 0.05rem;
}
.math-parens-body {
  display: inline-flex;
  align-items: center;
  gap: 0.16rem;
}
.math-side-note {
  font-size: 0.82em;
  color: var(--text-muted);
  margin-left: 0.65rem;
  font-family: var(--font-sans);
}
.math-matrix {
  display: inline-flex;
  flex-direction: column;
  gap: 0.18rem;
  border-left: 2px solid currentColor;
  border-right: 2px solid currentColor;
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
  vertical-align: middle;
  margin: 0 0.2rem;
}
.math-matrix-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  text-align: center;
}
.math-inline-sym {
  display: inline-block;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 0.05rem 0.4rem;
  font-family: 'STIX Two Math', 'Cambria Math', 'Times New Roman', Georgia, serif;
  font-size: 0.98rem;
  color: var(--text-primary);
}

.faq-item {
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.85rem 0;
}
.faq-item:last-child {
  border-bottom: none;
}
.faq-q {
  font-weight: 700;
  font-size: 0.95rem;
  margin: 0 0 0.35rem;
}
.faq-a {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin: 0;
}

/* Category & Tool Cards */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.tool-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.1rem;
  text-decoration: none;
  color: var(--text-primary);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.tool-card:hover {
  border-color: var(--brand-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.tool-card-title {
  font-weight: 700;
  font-size: 1rem;
  margin: 0 0 0.35rem;
  color: var(--text-primary);
}
.tool-card-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: 0 0 0.75rem;
}
.tool-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--brand-primary);
  font-weight: 600;
}

/* Scientific Keypad */
.sci-keypad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
  margin-top: 0.75rem;
}
.sci-key {
  padding: 0.55rem 0.3rem;
  font-size: 0.85rem;
  font-family: var(--font-mono);
  font-weight: 600;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-page);
  color: var(--text-primary);
  cursor: pointer;
}
.sci-key:hover {
  background: var(--bg-subtle);
  border-color: var(--brand-primary);
}
.sci-key-accent {
  background: var(--brand-primary);
  color: var(--text-on-brand);
  border-color: var(--brand-primary);
}

/* Footer */
.site-footer {
  margin-top: auto;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  padding: 2.5rem 0 2rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.75rem;
}
.footer-col h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-primary);
  margin: 0 0 0.65rem;
}
.footer-col ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.footer-col li {
  margin-bottom: 0.4rem;
}
.footer-col a {
  color: var(--text-secondary);
  text-decoration: none;
}
.footer-col a:hover {
  color: var(--brand-primary);
  text-decoration: underline;
}

/* ============================================================================
   MULTI-VISUALIZATION SUITE (3 Interactive Graphs per Calculator)
   ============================================================================ */

.viz-suite-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.viz-switcher {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  background: var(--bg-subtle);
  padding: 0.22rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.viz-tab-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 650;
  padding: 0.28rem 0.55rem;
  border-radius: 4px;
  cursor: pointer;
}
.viz-tab-btn:hover {
  color: var(--text-primary);
}
.viz-tab-btn.active {
  background: var(--bg-surface);
  color: var(--brand-primary);
  box-shadow: var(--shadow-xs);
}

.viz-panels-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

.viz-panel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
}

.viz-panel-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border-subtle);
}

.viz-badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--brand-primary);
  background: var(--bg-highlight);
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
}

.viz-panels-grid[data-active-viz-mode="primary"] .viz-panel-card:not([data-viz-panel="primary"]),
.viz-panels-grid[data-active-viz-mode="donut"] .viz-panel-card:not([data-viz-panel="donut"]),
.viz-panels-grid[data-active-viz-mode="curve"] .viz-panel-card:not([data-viz-panel="curve"]) {
  display: none;
}

/* ============================================================================
   MOBILE SAME-PAGE RESPONSIVE ARCHITECTURE (<= 768px & <= 480px)
   Fixes all mobile UI bugs:
   1. Inputs, Primary Result, Supporting Metrics & all 3 Graphs stay on the SAME page!
   2. Live Result Banner stays synced at the top AND clicking Calculate scrolls smoothly to Results & Graphs below.
   3. Full-width readable labels & select dropdowns on mobile (never truncated or cut off).
   4. Viewport-safe search dropdown & export menu (never clips off left/right screen edges).
   ============================================================================ */

.mobile-live-result-bar,
.mobile-view-tabs {
  display: none;
}

.home-demo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.6rem;
}

@media (max-width: 768px) {
  .container {
    padding: 0 0.75rem;
  }

  /* 1. Ultra-compact non-sticky header + viewport-safe search dropdown */
  .site-header {
    position: relative;
  }
  .header-inner {
    min-height: 44px;
    padding-top: 0.35rem;
    padding-bottom: 0.3rem;
    gap: 0.4rem;
  }
  .brand-link {
    font-size: 1.05rem;
    gap: 0.4rem;
  }
  .brand-mark {
    width: 26px;
    height: 26px;
    font-size: 0.82rem;
    border-radius: 6px;
  }
  .header-actions {
    flex: 1;
    justify-content: flex-end;
    gap: 0.35rem;
  }
  .header-search-wrap {
    width: auto;
    flex: 1;
    max-width: 220px;
    order: 0;
    position: static;
  }
  .header-search-input {
    padding: 0.3rem 0.55rem 0.3rem 1.6rem;
    font-size: 0.82rem;
    height: 32px;
  }
  .header-search-icon {
    display: none;
  }
  .header-search-input {
    padding-left: 0.6rem;
  }
  .site-header .search-dropdown {
    position: fixed;
    top: 84px;
    left: 0.75rem;
    right: 0.75rem;
    width: auto;
    min-width: 0;
    max-width: none;
    z-index: 999;
  }
  #theme-toggle-btn {
    padding: 0.28rem 0.55rem;
    font-size: 0.76rem;
    height: 32px;
  }
  .header-nav {
    width: 100%;
    order: 3;
    flex-wrap: nowrap;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    gap: 0.3rem;
    padding-bottom: 0.15rem;
  }
  .header-nav::-webkit-scrollbar {
    display: none;
  }
  .nav-link {
    font-size: 0.76rem;
    padding: 0.2rem 0.52rem;
    background: var(--bg-subtle);
    flex-shrink: 0;
  }

  /* 2. Clean Breadcrumbs & Header */
  .breadcrumbs {
    padding: 0.3rem 0 0.1rem;
    font-size: 0.74rem;
    overflow-x: auto;
    white-space: nowrap;
  }
  .breadcrumbs ol {
    flex-wrap: nowrap;
  }
  .calc-page-header {
    padding: 0.25rem 0 0.45rem;
  }
  .calc-title-row {
    gap: 0.5rem;
    align-items: flex-start;
  }
  .calc-page-title {
    font-size: 1.22rem;
    line-height: 1.22;
    margin: 0;
  }
  .calc-page-lead {
    font-size: 0.8rem;
    line-height: 1.35;
    margin-top: 0.15rem;
  }
  #favorite-toggle-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    flex-shrink: 0;
  }

  /* 3. Single-Line SIP Mode Strip */
  .sip-suite-nav {
    padding: 0.45rem 0.65rem !important;
    margin-bottom: 0.55rem !important;
  }
  .sip-suite-pills {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    gap: 0.35rem !important;
  }
  .sip-suite-pills::-webkit-scrollbar {
    display: none;
  }
  .sip-suite-pills .chip-btn {
    flex-shrink: 0;
    padding: 0.22rem 0.55rem;
    font-size: 0.75rem;
  }

  /* 4. Same-Page Quick Jump Bar on Mobile (Never hides Results or Graphs!) */
  .mobile-view-tabs {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    background: var(--bg-subtle);
    padding: 0.28rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    margin-bottom: 0.55rem;
  }
  .mobile-view-tabs::-webkit-scrollbar {
    display: none;
  }
  .mobile-tab-btn {
    flex: 1 0 auto;
    border: none;
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 650;
    padding: 0.34rem 0.6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: center;
    box-shadow: var(--shadow-xs);
  }
  .mobile-tab-btn.active {
    background: var(--brand-primary);
    color: var(--text-on-brand);
  }

  /* 5. Above-the-Fold Mobile Live Result Banner (Always synced live on the same page) */
  .mobile-live-result-bar {
    display: block;
    background: var(--bg-highlight);
    border: 1px solid var(--border-brand);
    border-radius: var(--radius-md);
    padding: 0.65rem 0.8rem;
    margin-bottom: 0.65rem;
  }
  .mobile-live-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
  }
  .mobile-live-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--brand-primary);
  }
  .mobile-live-value {
    font-size: 1.4rem;
    font-weight: 800;
    line-height: 1.18;
    color: var(--text-primary);
  }
  .mobile-live-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
  }
  .mobile-supporting-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.35rem 0.45rem;
    margin-top: 0.45rem;
    padding-top: 0.42rem;
    border-top: 1px solid var(--border-subtle);
  }
  .mobile-sup-pill {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.3rem;
    font-size: 0.74rem;
    background: var(--bg-surface);
    padding: 0.25rem 0.45rem;
    border-radius: 4px;
    border: 1px solid var(--border-subtle);
  }
  .mobile-sup-label {
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mobile-sup-val {
    font-weight: 700;
    color: var(--text-primary);
    flex-shrink: 0;
  }

  /* 6. Clean, Readable Mobile Input Form (Full labels, no truncation, smooth sliders) */
  .calc-workspace-grid {
    gap: 0.85rem;
    margin-bottom: 1.1rem;
  }
  .panel-card {
    padding: 0.85rem;
    border-radius: var(--radius-md);
  }
  .panel-section-title {
    font-size: 0.88rem;
    margin: 0 0 0.55rem;
    padding-bottom: 0.35rem;
  }
  .calc-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem 0.6rem;
  }
  .calc-form-grid .form-field-wide {
    grid-column: 1 / -1;
  }
  .form-field {
    margin-bottom: 0;
    min-width: 0;
  }
  .field-label-row {
    margin-bottom: 0.2rem;
    gap: 0.35rem;
  }
  .field-label {
    font-size: 0.78rem;
    line-height: 1.25;
    white-space: normal;
  }
  .field-unit-tag {
    font-size: 0.72rem;
    flex-shrink: 0;
  }
  .text-input,
  .select-input {
    padding: 0.38rem 0.5rem;
    font-size: 0.94rem;
    height: 36px;
  }
  .range-slider {
    margin-top: 0.28rem;
    height: 6px;
  }
  .calc-form-grid .field-help {
    font-size: 0.68rem;
    line-height: 1.25;
    margin-top: 0.12rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .calc-action-row {
    position: sticky;
    bottom: 0;
    z-index: 5;
    background: var(--bg-surface);
    margin-inline: -0.85rem;
    padding: 0.55rem 0.85rem calc(0.55rem + env(safe-area-inset-bottom));
    margin-top: 0.7rem;
    gap: 0.5rem;
    border-top: 1px solid var(--border-subtle);
  }
  .btn-primary,
  .btn-secondary {
    padding: 0.55rem 0.9rem;
    font-size: 0.9rem;
  }

  /* 7. Results, Supporting Metrics & 3-Graph Suite ALWAYS visible on the SAME page on mobile */
  .primary-result-box {
    padding: 0.8rem 0.95rem;
    margin-bottom: 0.75rem;
  }
  .primary-result-value {
    font-size: 1.55rem;
  }
  .supporting-metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
    margin-bottom: 0.75rem;
  }
  .metric-tile {
    padding: 0.5rem 0.65rem;
  }
  .metric-tile-label {
    font-size: 0.72rem;
  }
  .metric-tile-value {
    font-size: 0.96rem;
  }
  .interpretation-box {
    padding: 0.65rem 0.8rem;
    font-size: 0.84rem;
    margin-bottom: 0.75rem;
  }
  .chart-box {
    padding: 0.65rem;
    min-height: 200px;
    margin-bottom: 0.75rem;
  }
  .viz-switcher {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
  }
  .viz-tab-btn {
    flex: 1 0 auto;
    white-space: nowrap;
  }
  .export-dropdown-menu {
    left: 0;
    right: auto;
  }

  /* Responsive textbook formula sizing on mobile */
  .formula-book-card {
    padding: 0.85rem 0.7rem;
  }
  .math-display {
    font-size: 0.98rem;
    gap: 0.65rem;
  }

  /* 8. Compact Homepage & Category Grids on Mobile */
  .hero-section {
    padding: 0.85rem 0;
  }
  .hero-grid {
    gap: 0.85rem;
  }
  .hero-title {
    font-size: 1.4rem;
    margin-bottom: 0.35rem;
  }
  .hero-subtitle {
    font-size: 0.85rem;
    margin-bottom: 0.65rem;
  }
  .hero-search-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    margin-top: 0.45rem;
  }
  .hero-search-chips::-webkit-scrollbar {
    display: none;
  }
  .home-demo-grid {
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }
  .cards-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
  }
  .tool-card {
    padding: 0.7rem;
  }
  .tool-card-title {
    font-size: 0.86rem;
    line-height: 1.25;
    margin-bottom: 0.2rem;
  }
  .tool-card-desc {
    font-size: 0.74rem;
    line-height: 1.3;
    margin-bottom: 0.4rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

/* Print-Friendly Stylesheet */
@media print {
  .site-header,
  .site-footer,
  .calc-action-row,
  .result-toolbar,
  .range-slider,
  .skip-link,
  .mobile-view-tabs,
  .mobile-live-result-bar,
  .viz-switcher {
    display: none !important;
  }
  body, .panel-card, .editorial-card {
    background: #ffffff !important;
    color: #000000 !important;
    box-shadow: none !important;
    border-color: #cccccc !important;
  }
  .calc-workspace-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
  }
}
