/* ==========================================================================
   RimRatio — global CSS foundation (Design System v1)
   Mobile-first. No framework. Tokens → base → layout → components → utilities.
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  /* Color */
  --rr-primary: #1D4ED8;        /* Tire B, primary buttons, links */
  --rr-primary-strong: #1E40AF; /* hover / pressed */
  --rr-primary-tint: #EFF4FF;   /* answer box, selected chip */
  --rr-secondary: #475569;      /* Tire A, secondary UI, icons */
  --rr-bg: #F7F8FA;
  --rr-surface: #FFFFFF;
  --rr-text: #111827;
  --rr-text-muted: #4B5563;
  --rr-border: #E2E5EA;
  --rr-border-strong: #C7CCD4;
  --rr-border-control: #858E9C;  /* form control boundary: ≥ 3:1 on surface and bg (WCAG 1.4.11) */
  --rr-success: #15803D;
  --rr-success-tint: #ECFDF3;
  --rr-warning: #B45309;
  --rr-warning-tint: #FFF7E6;
  --rr-focus: #1D4ED8;          /* focus outline: 6.7:1 on surface, 6.3:1 on bg */

  --rr-tire-a: var(--rr-secondary);
  --rr-tire-b: var(--rr-primary);

  /* Typography (Inter is self-hosted later: /fonts/inter-var.woff2) */
  --rr-font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --rr-fs-display: 28px;
  --rr-fs-h1: 24px;
  --rr-fs-h2: 20px;
  --rr-fs-h3: 17px;
  --rr-fs-answer: 19px;
  --rr-fs-stat: 22px;
  --rr-fs-body: 16px;
  --rr-fs-small: 14px;
  --rr-fs-caption: 12px;

  /* Spacing (4px base) */
  --rr-space-1: 4px;
  --rr-space-2: 8px;
  --rr-space-3: 12px;
  --rr-space-4: 16px;
  --rr-space-5: 20px;
  --rr-space-6: 24px;
  --rr-space-8: 32px;
  --rr-space-10: 40px;
  --rr-space-12: 48px;
  --rr-space-16: 64px;

  --rr-section-gap: var(--rr-space-8);
  --rr-card-pad: var(--rr-space-4);
  --rr-gutter: var(--rr-space-4);

  /* Radius, shadow */
  --rr-radius-sm: 6px;
  --rr-radius-md: 8px;
  --rr-radius-lg: 12px;
  --rr-shadow-card: 0 1px 2px rgba(17, 24, 39, .06), 0 1px 3px rgba(17, 24, 39, .08);
  --rr-shadow-pop: 0 8px 24px rgba(17, 24, 39, .12);

  /* Motion */
  --rr-duration-fast: 120ms;
  --rr-duration-base: 200ms;

  /* Layout */
  --rr-container: 1200px;
  --rr-header-h: 56px;
}

@media (min-width: 640px) {
  :root {
    --rr-gutter: var(--rr-space-6);
  }
}

@media (min-width: 1024px) {
  :root {
    --rr-fs-display: 40px;
    --rr-fs-h1: 32px;
    --rr-fs-h2: 24px;
    --rr-fs-h3: 18px;
    --rr-fs-answer: 22px;
    --rr-fs-stat: 28px;
    --rr-section-gap: var(--rr-space-12);
    --rr-card-pad: var(--rr-space-6);
    --rr-gutter: var(--rr-space-8);
    --rr-header-h: 64px;
  }
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--rr-bg);
  color: var(--rr-text);
  font-family: var(--rr-font-sans);
  font-size: var(--rr-fs-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

h1, h2, h3, h4 { margin: 0; color: var(--rr-text); }
h1 { font-size: var(--rr-fs-h1); line-height: 1.2; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: var(--rr-fs-h2); line-height: 1.3; font-weight: 650; }
h3 { font-size: var(--rr-fs-h3); line-height: 1.4; font-weight: 600; }
p { margin: 0; }

a { color: var(--rr-primary); text-decoration: none; }
a:hover { color: var(--rr-primary-strong); text-decoration: underline; }

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

:focus-visible { outline: 3px solid var(--rr-focus); outline-offset: 2px; }
/* Forced colors (Windows High Contrast): use the system highlight color for the outline. */
@media (forced-colors: active) { :focus-visible { outline-color: Highlight; } }

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

/* ---------- 3. Layout ---------- */
.rr-container {
  width: 100%;
  max-width: calc(var(--rr-container) + 2 * var(--rr-gutter));
  margin-inline: auto;
  padding-inline: var(--rr-gutter);
}

.rr-main { flex: 1 0 auto; padding-block: var(--rr-space-6) var(--rr-section-gap); }

.rr-stack { display: flex; flex-direction: column; gap: var(--rr-section-gap); }
.rr-stack-sm { display: flex; flex-direction: column; gap: var(--rr-space-3); }

.rr-grid { display: grid; gap: var(--rr-space-3); grid-template-columns: repeat(var(--cols-sm, 1), minmax(0, 1fr)); }
@media (min-width: 640px) { .rr-grid { grid-template-columns: repeat(var(--cols-md, 2), minmax(0, 1fr)); } }
@media (min-width: 1024px) { .rr-grid { grid-template-columns: repeat(var(--cols-lg, 3), minmax(0, 1fr)); } }

/* Content + sticky ad sidebar (≥1024px): 760 + 40 + 300 */
.rr-with-sidebar { display: grid; gap: var(--rr-space-10); grid-template-columns: minmax(0, 1fr); }
.rr-with-sidebar > aside { display: none; }
@media (min-width: 1024px) {
  .rr-with-sidebar { grid-template-columns: minmax(0, 760px) 300px; }
  .rr-with-sidebar > aside { display: block; }
}

.rr-prose { max-width: 68ch; }
.rr-prose > * + * { margin-top: var(--rr-space-4); }

/* ---------- 4. Typography helpers ---------- */
.rr-display { font-size: var(--rr-fs-display); line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; }
.rr-lead { color: var(--rr-text-muted); max-width: 640px; }
.rr-caption { font-size: var(--rr-fs-caption); font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--rr-text-muted); }
.rr-small { font-size: var(--rr-fs-small); }
.rr-muted { color: var(--rr-text-muted); }
.rr-num { font-variant-numeric: tabular-nums; }

/* ---------- 5. Header ---------- */
.rr-skip {
  position: absolute; left: var(--rr-space-4); top: -100px; z-index: 100;
  background: var(--rr-surface); padding: var(--rr-space-2) var(--rr-space-4); border-radius: var(--rr-radius-md);
}
.rr-skip:focus { top: var(--rr-space-2); }

.rr-header { background: var(--rr-surface); border-bottom: 1px solid var(--rr-border); position: relative; z-index: 20; }
.rr-header__inner { height: var(--rr-header-h); display: flex; align-items: center; gap: var(--rr-space-10); }
.rr-logo { display: flex; align-items: center; gap: 10px; color: var(--rr-text); font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.rr-logo:hover { color: var(--rr-text); text-decoration: none; }
.rr-logo svg { width: 24px; height: 24px; }

.rr-nav { display: none; }
.rr-nav a { color: var(--rr-text); font-size: 15px; font-weight: 500; height: var(--rr-header-h); display: flex; align-items: center; }
.rr-nav a:hover { color: var(--rr-primary); text-decoration: none; }
.rr-nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--rr-primary); }

.rr-menu-btn {
  margin-left: auto; margin-right: -10px; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: 0; background: none; color: var(--rr-text); cursor: pointer;
}

.rr-mobile-nav { border-top: 1px solid var(--rr-border); background: var(--rr-surface); padding: var(--rr-space-2) var(--rr-gutter) var(--rr-space-6); }
.rr-mobile-nav[hidden] { display: none; }
.rr-mobile-nav a { display: flex; align-items: center; min-height: 52px; border-bottom: 1px solid var(--rr-border); color: var(--rr-text); font-weight: 600; font-size: 17px; }

@media (min-width: 1024px) {
  .rr-logo { font-size: 20px; }
  .rr-logo svg { width: 28px; height: 28px; }
  .rr-nav { display: flex; align-items: center; gap: 28px; flex: 1; }
  .rr-menu-btn, .rr-mobile-nav { display: none !important; }
}

/* ---------- 6. Footer ---------- */
.rr-footer { background: var(--rr-surface); border-top: 1px solid var(--rr-border); font-size: var(--rr-fs-small); }
.rr-footer__grid { display: grid; gap: var(--rr-space-8); grid-template-columns: repeat(2, minmax(0, 1fr)); padding-block: var(--rr-space-10) var(--rr-space-6); }
.rr-footer__col { display: flex; flex-direction: column; gap: 10px; }
.rr-footer__legal { border-top: 1px solid var(--rr-border); padding-block: var(--rr-space-5) var(--rr-space-8); color: var(--rr-text-muted); }
@media (min-width: 1024px) { .rr-footer__grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--rr-space-10); padding-top: var(--rr-space-12); } }

/* ---------- 7. Buttons ---------- */
.rr-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--rr-space-2);
  min-height: 44px; padding: 0 var(--rr-space-5);
  border: 1px solid transparent; border-radius: var(--rr-radius-md);
  font: 600 16px/1 var(--rr-font-sans); cursor: pointer;
  transition: background-color var(--rr-duration-fast), border-color var(--rr-duration-fast);
}
.rr-btn:hover { text-decoration: none; }
.rr-btn--primary { background: var(--rr-primary); color: #FFFFFF; min-height: 52px; }
.rr-btn--primary:hover { background: var(--rr-primary-strong); color: #FFFFFF; }
.rr-btn--secondary { background: var(--rr-surface); color: var(--rr-primary); border-color: var(--rr-border-strong); }
.rr-btn--secondary:hover { border-color: var(--rr-primary); }
.rr-btn--block { width: 100%; }
.rr-btn:disabled, .rr-btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
@media (min-width: 1024px) { .rr-btn--primary { min-height: 48px; } }

/* ---------- 8. Form inputs ---------- */
.rr-field { display: flex; flex-direction: column; gap: 6px; font-size: var(--rr-fs-small); font-weight: 500; color: var(--rr-text-muted); }
.rr-select-wrap { position: relative; }
.rr-select-wrap::after {
  content: ""; position: absolute; right: 12px; top: 50%; width: 7px; height: 7px; margin-top: -5px;
  border-right: 1.75px solid var(--rr-text-muted); border-bottom: 1.75px solid var(--rr-text-muted);
  transform: rotate(45deg); pointer-events: none;
}
.rr-select, .rr-input {
  width: 100%; height: 48px; padding: 0 12px;
  border: 1px solid var(--rr-border-control); border-radius: var(--rr-radius-sm);
  background: var(--rr-surface); color: var(--rr-text);
  font: 600 16px var(--rr-font-sans); /* 16px prevents iOS zoom */
  font-variant-numeric: tabular-nums;
}
.rr-select { appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer; }
.rr-select:focus, .rr-input:focus { border-color: var(--rr-primary); }
.rr-input--error { border-color: var(--rr-warning); }

/* ---------- 9. Cards & surfaces ---------- */
.rr-card { background: var(--rr-surface); border: 1px solid var(--rr-border); border-radius: var(--rr-radius-md); padding: var(--rr-card-pad); }
.rr-card--lg { border-radius: var(--rr-radius-lg); }
.rr-card--raised { border-radius: var(--rr-radius-lg); box-shadow: var(--rr-shadow-card); }
a.rr-card { color: var(--rr-text); display: block; }
a.rr-card:hover { border-color: var(--rr-border-strong); text-decoration: none; }

.rr-chip {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px;
  border: 1px solid var(--rr-border); border-radius: var(--rr-radius-sm); background: var(--rr-surface);
  font-size: var(--rr-fs-small); font-weight: 500; color: var(--rr-text); font-variant-numeric: tabular-nums;
}
.rr-chip:hover { border-color: var(--rr-border-strong); text-decoration: none; color: var(--rr-text); }
.rr-chip[aria-current="true"] { border-color: var(--rr-primary); background: var(--rr-primary-tint); color: var(--rr-primary); }
.rr-chip-list { display: flex; flex-wrap: wrap; gap: var(--rr-space-2); list-style: none; margin: 0; padding: 0; }
@media (min-width: 1024px) { .rr-chip { height: 32px; } }

.rr-badge { display: inline-block; padding: 2px 8px; border-radius: var(--rr-radius-sm); font-size: var(--rr-fs-small); font-weight: 600; font-variant-numeric: tabular-nums; }
.rr-badge--success { background: var(--rr-success-tint); color: var(--rr-success); }
.rr-badge--warning { background: var(--rr-warning-tint); color: var(--rr-warning); }

/* Tire identity dots: A = gray, B = blue */
.rr-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.rr-dot--a { background: var(--rr-tire-a); }
.rr-dot--b { background: var(--rr-tire-b); }

/* ---------- 10. Callouts ---------- */
.rr-callout { display: flex; gap: var(--rr-space-3); align-items: flex-start; padding: var(--rr-space-3) var(--rr-space-4); border-radius: var(--rr-radius-md); font-size: var(--rr-fs-small); font-weight: 600; }
.rr-callout svg { flex-shrink: 0; width: 18px; height: 18px; margin-top: 2px; }
.rr-callout--warning { background: var(--rr-warning-tint); color: var(--rr-warning); }
.rr-callout--success { background: var(--rr-success-tint); color: var(--rr-success); }
.rr-callout--info { background: var(--rr-primary-tint); color: var(--rr-primary-strong); }

/* ---------- 11. Calculator building blocks ---------- */
.rr-calc { display: flex; flex-direction: column; gap: var(--rr-space-4); }
.rr-tire-input { margin: 0; padding: 0; border: 0; min-width: 0; }
.rr-tire-input legend { display: flex; align-items: center; gap: var(--rr-space-2); padding: 0; margin-bottom: var(--rr-space-2); font-size: var(--rr-fs-small); font-weight: 600; color: var(--rr-text); }
.rr-tire-input__fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--rr-space-2); }
@media (min-width: 1024px) {
  .rr-calc__row { display: flex; flex-direction: row; align-items: flex-end; gap: var(--rr-space-6); }
  .rr-tire-input__fields { grid-template-columns: repeat(3, 104px); }
}

/* Answer box */
.rr-answer {
  background: var(--rr-primary-tint);
  border-left: 4px solid var(--rr-primary);
  border-radius: var(--rr-radius-lg);
  padding: var(--rr-space-4) var(--rr-space-5);
  display: flex; flex-direction: column; gap: var(--rr-space-1);
}
.rr-answer--warning { border-left-color: var(--rr-warning); }
.rr-answer--success { border-left-color: var(--rr-success); }
.rr-answer__text { font-size: var(--rr-fs-answer); line-height: 1.4; font-weight: 600; font-variant-numeric: tabular-nums; }
.rr-answer__sub { color: var(--rr-text-muted); font-variant-numeric: tabular-nums; }

/* Stat tiles */
.rr-stats { display: grid; gap: var(--rr-space-2); grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .rr-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .rr-stats { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--rr-space-3); } }
.rr-stat { background: var(--rr-surface); border: 1px solid var(--rr-border); border-radius: var(--rr-radius-md); padding: var(--rr-space-3); display: flex; flex-direction: column; gap: 2px; }
.rr-stat__label { font-size: 13px; font-weight: 500; color: var(--rr-text-muted); }
.rr-stat__value { font-size: var(--rr-fs-stat); line-height: 1.15; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rr-stat__sub { font-size: 12px; color: var(--rr-text-muted); font-variant-numeric: tabular-nums; }
.rr-stat__sub--warning { color: var(--rr-warning); font-weight: 600; }
@media (min-width: 1024px) { .rr-stat { padding: var(--rr-space-4); } .rr-stat__label, .rr-stat__sub { font-size: 14px; } }

/* Tables */
.rr-table-wrap { background: var(--rr-surface); border: 1px solid var(--rr-border); border-radius: var(--rr-radius-lg); overflow: hidden; }
.rr-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rr-table th, .rr-table td { padding: 10px 12px; border-bottom: 1px solid var(--rr-border); text-align: right; font-size: 15px; vertical-align: top; }
.rr-table th:first-child, .rr-table td:first-child { text-align: left; }
.rr-table thead th { background: var(--rr-bg); font-size: 13px; font-weight: 600; }
.rr-table tbody th { font-weight: 500; color: var(--rr-text-muted); }
.rr-table tr:last-child > * { border-bottom: 0; }
@media (min-width: 1024px) { .rr-table th, .rr-table td { padding: 0 16px; height: 44px; vertical-align: middle; } }
@media (max-width: 639px) {
  .rr-table th, .rr-table td { padding: 8px 4px; font-size: 13px; }
  .rr-table th:first-child, .rr-table td:first-child { padding-left: 8px; }
  .rr-table th:last-child, .rr-table td:last-child { padding-right: 8px; }
  .rr-table__sub { font-size: 11px; }
}
.rr-table__caption { caption-side: top; text-align: left; padding: 10px 12px; font-size: 13px; color: var(--rr-text-muted); background: var(--rr-surface); border-bottom: 1px solid var(--rr-border); }
.rr-table__sub { display: block; font-size: 12px; font-weight: 400; color: var(--rr-text-muted); }
.rr-table__diff { font-weight: 600; }
.rr-table__diff--warning { color: var(--rr-warning); font-weight: 700; }
.rr-dot--sm { width: 8px; height: 8px; margin-right: 6px; vertical-align: 1px; }
@media (min-width: 1024px) { .rr-table__caption { padding: 12px 16px; } }

/* Comparison details (Phase 2) */
.rr-stats--3 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
@media (min-width: 640px) { .rr-stats--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.rr-insights { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--rr-space-2); }
.rr-insights li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--rr-space-1) var(--rr-space-3); padding: var(--rr-space-3) var(--rr-space-4); background: var(--rr-surface); border: 1px solid var(--rr-border); border-radius: var(--rr-radius-md); font-variant-numeric: tabular-nums; }
.rr-insights__label { font-weight: 600; }
.rr-insights__value { color: var(--rr-text-muted); }
@media (min-width: 640px) { .rr-insights { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* Comparison visual */
.rr-visual { display: grid; gap: var(--rr-space-4); }
@media (min-width: 640px) { .rr-visual { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--rr-space-8); } }
.rr-visual figure { margin: 0; }
.rr-visual figcaption { font-size: var(--rr-fs-small); font-weight: 600; color: var(--rr-text-muted); margin-top: var(--rr-space-2); }
.rr-visual svg { width: 100%; height: auto; }
.rr-viz__legend { list-style: none; margin: 0 0 var(--rr-space-4); padding: 0; display: flex; flex-wrap: wrap; gap: var(--rr-space-2) var(--rr-space-6); font-size: var(--rr-fs-small); }
.rr-viz__legend li { display: flex; align-items: center; gap: var(--rr-space-2); }
.rr-viz__legend svg { flex-shrink: 0; }
.rr-viz text { font-family: var(--rr-font-sans); font-size: 13px; fill: var(--rr-text); font-variant-numeric: tabular-nums; }
.rr-viz__ground { stroke: var(--rr-border-strong); stroke-width: 1.5; }
.rr-viz__a { fill: none; stroke: var(--rr-tire-a); stroke-width: 2; stroke-dasharray: 6 4; }
.rr-viz__b { fill: var(--rr-primary-tint); stroke: var(--rr-tire-b); stroke-width: 2.5; }
.rr-viz__rim-a { fill: none; stroke: var(--rr-tire-a); stroke-width: 1.25; stroke-dasharray: 4 3; }
.rr-viz__rim-b { fill: var(--rr-surface); stroke: var(--rr-border-strong); stroke-width: 1.25; }
.rr-viz__band { fill: var(--rr-border); fill-opacity: 0.7; }
.rr-viz__guide-a { stroke: var(--rr-tire-a); stroke-width: 1; stroke-dasharray: 3 3; }
.rr-viz__guide-b { stroke: var(--rr-tire-b); stroke-width: 1; stroke-dasharray: 3 3; }
.rr-viz__bracket { stroke: var(--rr-text); stroke-width: 1.5; }
.rr-viz__dot { fill: var(--rr-text-muted); }
.rr-viz .rr-viz__label { fill: var(--rr-text-muted); }
.rr-viz .rr-viz__letter { font-weight: 700; fill: var(--rr-text); }
.rr-viz .rr-viz__value { font-weight: 700; }

/* ---------- 12. Ad slots (reserved space → no CLS) ---------- */
.rr-ad { display: flex; flex-direction: column; gap: 6px; }
.rr-ad__label { font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--rr-text-muted); }
.rr-ad__box { min-height: var(--rr-ad-min-h, 250px); }
.rr-ad__box--placeholder {
  border: 1px dashed var(--rr-border-strong); border-radius: var(--rr-radius-md); background: var(--rr-surface);
  display: flex; align-items: center; justify-content: center; color: var(--rr-text-muted);
  font-size: var(--rr-fs-small); font-weight: 600; text-align: center;
}
.rr-ad--sticky { position: sticky; top: var(--rr-space-6); }

/* ---------- 13. Utilities ---------- */
.rr-visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.rr-mt-2 { margin-top: var(--rr-space-2); }
.rr-mt-4 { margin-top: var(--rr-space-4); }
.rr-flex-between { display: flex; align-items: center; justify-content: space-between; gap: var(--rr-space-3); flex-wrap: wrap; }
