/* =========================================================================
   Sage — coding harness leaderboard
   Hand-rolled CSS. No framework. EPI-USE navy + amber accent.
   ========================================================================= */

:root {
  /* Brand */
  --navy-900: #0a1f3d;
  --navy-800: #102b54;
  --navy-700: #1a3a6c;
  --navy-600: #2a5298;
  --amber-500: #d4a418;
  --amber-400: #e6b934;
  --amber-300: #f0cc5e;

  /* Neutrals (warm) */
  --paper:    #faf7f1;
  --paper-2:  #f3eee2;
  --ink-900:  #0d0d0d;
  --ink-700:  #2b2b2b;
  --ink-500:  #5a5a5a;
  --ink-300:  #9a9a9a;
  --rule:     #e7e1d3;
  --rule-2:   #d6cdb8;

  /* Semantic */
  --bg:       var(--paper);
  --surface:  #ffffff;
  --text:     var(--ink-900);
  --muted:    var(--ink-500);
  --accent:   var(--amber-500);
  --accent-ink: var(--navy-900);
  --primary:  var(--navy-900);

  /* Type */
  --serif: "Fraunces", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --sans:  "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono:  ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;

  /* Layout */
  --maxw: 1180px;
  --gutter: clamp(20px, 4vw, 56px);
  --radius: 4px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 2px rgba(10, 31, 61, .06), 0 1px 1px rgba(10, 31, 61, .04);
  --shadow-md: 0 8px 24px rgba(10, 31, 61, .08), 0 2px 6px rgba(10, 31, 61, .05);
  --shadow-lg: 0 24px 60px rgba(10, 31, 61, .14), 0 6px 16px rgba(10, 31, 61, .08);
}

[data-theme="dark"] {
  --bg:       #0c1626;
  --surface:  #142238;
  --text:     #f1ece1;
  --muted:    #a9b0bf;
  --paper-2:  #1a2944;
  --rule:     #243652;
  --rule-2:   #2f4a70;
  --primary:  #ffffff;
  --accent-ink: #0c1626;
}

/* -------------------------------------------------------------------------
   Reset + base
   ------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; display: block; }
a { color: var(--primary); text-decoration: none; border-bottom: 1px solid currentColor; transition: color .15s ease; }
a:hover { color: var(--amber-500); }
button { font: inherit; cursor: pointer; }

/* Typography */
h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0;
}
h1 { font-size: clamp(2.4rem, 5vw, 4.2rem); line-height: 1.05; letter-spacing: -0.025em; }
h2 { font-size: clamp(1.8rem, 3vw, 2.6rem); line-height: 1.15; }
h3 { font-size: 1.4rem; line-height: 1.25; }
h4 { font-size: 1.05rem; font-weight: 600; }
.eyebrow {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

/* -------------------------------------------------------------------------
   Layout primitives
   ------------------------------------------------------------------------- */

.wrap { max-width: var(--maxw); margin: 0 auto; padding-left: var(--gutter); padding-right: var(--gutter); }

/* Faint editorial grid backdrop */
.grid-bg {
  position: fixed; inset: 0; z-index: -1;
  background-image:
    linear-gradient(to right, rgba(10,31,61,.035) 1px, transparent 1px);
  background-size: 80px 100%;
  pointer-events: none;
}
[data-theme="dark"] .grid-bg {
  background-image: linear-gradient(to right, rgba(255,255,255,.04) 1px, transparent 1px);
}

/* Scroll progress rail */
.progress-rail {
  position: fixed; top: 0; left: 0; height: 2px;
  background: var(--amber-500);
  width: 0%; z-index: 100;
  transition: width 0.05s linear;
}

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

.topnav {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--rule);
}
.topnav-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px;
}
.brand {
  display: flex; align-items: baseline; gap: 12px;
  border: 0; color: var(--text);
}
.brand-mark {
  font-family: var(--serif);
  font-size: 1.4rem; font-weight: 600; letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted);
}
.nav-links { display: flex; gap: 24px; align-items: center; }
.nav-links a { font-size: 0.9rem; border: 0; color: var(--muted); }
.nav-links a:hover { color: var(--text); }
.theme-toggle {
  background: transparent; border: 1px solid var(--rule); color: var(--muted);
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .2s ease;
}
.theme-toggle:hover { border-color: var(--text); color: var(--text); }

@media (max-width: 640px) {
  .nav-links a:not(.theme-toggle-wrap) { display: none; }
}

/* -------------------------------------------------------------------------
   Hero
   ------------------------------------------------------------------------- */

.hero { padding: clamp(60px, 10vh, 120px) 0 clamp(40px, 6vh, 72px); }
.hero-meta {
  display: flex; gap: 16px; align-items: center;
  margin-bottom: 28px;
}
.hero-meta .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--amber-500); }
.hero h1 { max-width: 16ch; margin-bottom: 28px; }
.hero h1 em {
  font-style: italic;
  color: var(--navy-700);
  position: relative;
}
[data-theme="dark"] .hero h1 em { color: var(--amber-400); }
.hero-lede {
  font-size: clamp(1.05rem, 1.4vw, 1.2rem);
  max-width: 62ch; color: var(--ink-700);
  margin-bottom: 32px;
}
[data-theme="dark"] .hero-lede { color: #c9c9c9; }
.hero-byline { font-size: 0.85rem; color: var(--muted); }
.hero-byline a { color: var(--muted); }

/* -------------------------------------------------------------------------
   Section header
   ------------------------------------------------------------------------- */

.section { padding: clamp(48px, 8vh, 96px) 0; }
.section-head { margin-bottom: clamp(32px, 5vh, 56px); max-width: 70ch; }
.section-head .eyebrow { display: block; margin-bottom: 12px; }
.section-head p { color: var(--muted); margin: 12px 0 0; max-width: 60ch; }

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

.cards { display: flex; flex-direction: column; gap: 28px; }

.card {
  position: relative;
  display: grid;
  grid-template-columns: 140px 1fr auto;
  gap: clamp(20px, 4vw, 48px);
  align-items: start;
  padding: clamp(28px, 4vw, 44px);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: transform .25s cubic-bezier(.2,.8,.2,1), box-shadow .25s ease, border-color .25s ease;
  text-decoration: none;
  color: inherit;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--rule-2);
}
.card:hover .card-cta { color: var(--amber-500); gap: 14px; }

.card-rank {
  font-family: var(--serif);
  font-size: clamp(4rem, 8vw, 6.4rem);
  line-height: 1;
  font-weight: 500;
  color: var(--navy-900);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  position: relative;
}
[data-theme="dark"] .card-rank { color: var(--amber-400); }
.card-rank::after {
  content: "";
  display: block;
  width: 40px; height: 2px;
  background: var(--amber-500);
  margin-top: 12px;
}

.card-body { min-width: 0; }
.card-name {
  display: flex; align-items: baseline; gap: 14px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.card-name h3 { font-size: clamp(1.5rem, 2vw, 1.85rem); }
.card-vendor { font-size: 0.82rem; color: var(--muted); letter-spacing: 0.04em; }
.card-verdict {
  font-family: var(--serif);
  font-size: 1.15rem; line-height: 1.45;
  color: var(--ink-700);
  margin: 8px 0 18px;
  max-width: 60ch;
}
[data-theme="dark"] .card-verdict { color: #d8d3c5; }

.card-bullets {
  list-style: none; padding: 0; margin: 0 0 16px;
  display: grid; gap: 8px;
  font-size: 0.92rem;
}
.card-bullets li {
  position: relative; padding-left: 22px;
  color: var(--ink-700);
}
[data-theme="dark"] .card-bullets li { color: #cfcabe; }
.card-bullets li::before {
  content: ""; position: absolute; left: 0; top: 0.55em;
  width: 12px; height: 1px; background: var(--amber-500);
}

.card-watch {
  font-size: 0.85rem;
  color: var(--muted);
  border-left: 2px solid var(--amber-500);
  padding: 4px 0 4px 14px;
  margin: 0;
}

.card-aside {
  display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between;
  height: 100%; gap: 24px;
  text-align: right;
}
.card-price {
  font-family: var(--serif);
  font-size: 1.4rem;
  white-space: nowrap;
}
.card-price small {
  display: block;
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-top: 4px;
  font-weight: 400;
}
.card-cta {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 0.88rem; font-weight: 500;
  color: var(--primary);
  border: 0;
  transition: gap .2s ease, color .2s ease;
}
.card-cta::after { content: "→"; font-size: 1.1em; }

@media (max-width: 820px) {
  .card { grid-template-columns: 80px 1fr; }
  .card-aside {
    grid-column: 1 / -1; flex-direction: row; align-items: center; text-align: left;
    padding-top: 18px; border-top: 1px solid var(--rule); width: 100%;
    justify-content: space-between;
  }
  .card-rank { font-size: 3.2rem; }
}

/* -------------------------------------------------------------------------
   Compare table
   ------------------------------------------------------------------------- */

.compare-controls {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 24px;
}
.chip {
  font-size: 0.82rem;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--rule-2);
  background: transparent;
  color: var(--ink-700);
  transition: all .15s ease;
}
[data-theme="dark"] .chip { color: #cfcabe; }
.chip:hover { border-color: var(--text); }
.chip.active {
  background: var(--navy-900);
  color: var(--paper);
  border-color: var(--navy-900);
}
[data-theme="dark"] .chip.active {
  background: var(--amber-500); color: var(--navy-900); border-color: var(--amber-500);
}

.table-scroll { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--rule); background: var(--surface); }
.compare {
  width: 100%; border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 800px;
}
.compare thead th {
  text-align: left;
  padding: 16px 14px;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--rule);
  background: var(--paper-2);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color .15s ease;
}
.compare thead th:hover { color: var(--text); }
.compare thead th.sorted { color: var(--text); }
.compare thead th.sorted::after { content: " ↓"; color: var(--amber-500); }
.compare thead th.sorted.asc::after { content: " ↑"; }

.compare tbody td {
  padding: 14px;
  border-bottom: 1px solid var(--rule);
  vertical-align: middle;
}
.compare tbody tr:last-child td { border-bottom: 0; }
.compare tbody tr { transition: background .15s ease; }
.compare tbody tr:hover { background: var(--paper-2); }

.compare .col-name { font-weight: 600; white-space: nowrap; }
.compare .col-name a { border: 0; color: inherit; }
.compare .col-name a:hover { color: var(--amber-500); }
.compare .col-name .rk {
  display: inline-block;
  font-family: var(--serif);
  font-size: 0.8rem;
  color: var(--muted);
  margin-right: 8px;
  font-variant-numeric: tabular-nums;
}
.compare .yes { color: var(--navy-700); font-weight: 600; }
[data-theme="dark"] .compare .yes { color: var(--amber-400); }
.compare .no { color: var(--ink-300); }

/* -------------------------------------------------------------------------
   Pricing matrix
   ------------------------------------------------------------------------- */

.pricing-controls {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  margin-bottom: 28px;
  font-size: 0.88rem;
}
.toggle {
  display: inline-flex; gap: 0;
  border: 1px solid var(--rule-2); border-radius: 999px; overflow: hidden;
  padding: 3px;
}
.toggle button {
  border: 0; background: transparent;
  padding: 6px 14px; font-size: 0.82rem;
  border-radius: 999px;
  color: var(--muted);
}
.toggle button.active { background: var(--navy-900); color: var(--paper); }
[data-theme="dark"] .toggle button.active { background: var(--amber-500); color: var(--navy-900); }

.pricing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
}
.price-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 24px;
}
.price-card h4 {
  margin: 0 0 4px;
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 500;
}
.price-card .vendor { font-size: 0.78rem; color: var(--muted); margin-bottom: 18px; }
.price-card ul {
  list-style: none; padding: 0; margin: 0;
  display: grid; gap: 10px;
}
.price-card li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--rule);
  font-size: 0.88rem;
}
.price-card li:last-child { border-bottom: 0; padding-bottom: 0; }
.price-card .tier { font-weight: 600; }
.price-card .tier small {
  display: block; font-weight: 400; color: var(--muted);
  margin-top: 2px; font-size: 0.78rem;
}
.price-card .amount {
  font-family: var(--serif);
  font-size: 1rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------------------------
   Methodology
   ------------------------------------------------------------------------- */

.method {
  background: var(--paper-2);
  border-radius: var(--radius-lg);
  padding: clamp(32px, 5vw, 56px);
  border: 1px solid var(--rule);
}
.method h2 { margin-bottom: 20px; }
.method-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 24px;
  margin-top: 28px;
}
.method-grid h4 { margin-bottom: 6px; font-size: 0.95rem; }
.method-grid p { margin: 0; font-size: 0.88rem; color: var(--muted); }

/* -------------------------------------------------------------------------
   Footer
   ------------------------------------------------------------------------- */

.footer {
  margin-top: clamp(48px, 8vh, 96px);
  border-top: 1px solid var(--rule);
  padding: 32px 0;
  font-size: 0.82rem;
  color: var(--muted);
}
.footer-inner { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.footer a { color: var(--muted); }

/* -------------------------------------------------------------------------
   Detail page (harness.html)
   ------------------------------------------------------------------------- */

.detail-back {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.85rem; color: var(--muted); border: 0;
  margin-bottom: 24px;
}
.detail-back:hover { color: var(--text); }

.detail-hero {
  padding: clamp(40px, 6vh, 72px) 0;
  border-bottom: 1px solid var(--rule);
}
.detail-rank-line {
  display: flex; align-items: baseline; gap: 16px;
  font-family: var(--serif); color: var(--muted);
  margin-bottom: 8px;
}
.detail-rank-line .num {
  font-size: 2rem; color: var(--navy-900);
  font-variant-numeric: tabular-nums;
}
[data-theme="dark"] .detail-rank-line .num { color: var(--amber-400); }
.detail-hero h1 { margin: 8px 0 16px; font-size: clamp(2.2rem, 5vw, 3.6rem); }
.detail-verdict {
  font-family: var(--serif);
  font-size: clamp(1.2rem, 1.8vw, 1.5rem);
  line-height: 1.4;
  color: var(--ink-700);
  max-width: 60ch;
  margin: 0 0 24px;
}
[data-theme="dark"] .detail-verdict { color: #d8d3c5; }

.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: clamp(32px, 5vw, 64px);
  padding: clamp(40px, 6vh, 64px) 0;
}
@media (max-width: 820px) { .detail-grid { grid-template-columns: 1fr; } }

.detail-section { margin-bottom: 40px; }
.detail-section h3 {
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 16px;
  font-family: var(--sans);
  font-weight: 600;
}
.detail-section p { font-size: 1.02rem; line-height: 1.7; }
.detail-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.detail-list li {
  position: relative; padding-left: 22px;
  line-height: 1.55;
}
.detail-list li::before {
  content: ""; position: absolute; left: 0; top: 0.6em;
  width: 12px; height: 1px; background: var(--amber-500);
}
.detail-list.warn li::before { background: #b45f3e; }

.detail-aside {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 28px;
  height: fit-content;
  position: sticky; top: 80px;
}
.detail-aside h4 { font-family: var(--sans); font-size: 0.74rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); margin-bottom: 12px; }
.attr-list { list-style: none; padding: 0; margin: 0 0 24px; display: grid; gap: 10px; font-size: 0.9rem; }
.attr-list li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--rule); }
.attr-list li:last-child { border-bottom: 0; }
.attr-list span:first-child { color: var(--muted); }
.attr-list span:last-child { font-weight: 600; text-align: right; }

.score-row { display: grid; grid-template-columns: 90px 1fr 28px; gap: 12px; align-items: center; padding: 6px 0; font-size: 0.85rem; }
.score-row .label { color: var(--muted); text-transform: capitalize; }
.score-row .bar { height: 6px; background: var(--rule); border-radius: 999px; overflow: hidden; }
.score-row .bar > i { display: block; height: 100%; background: var(--amber-500); border-radius: 999px; }
.score-row .num { font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }

.detail-pricing-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.detail-pricing-table td { padding: 10px 0; border-bottom: 1px dashed var(--rule); vertical-align: top; }
.detail-pricing-table td:last-child { text-align: right; white-space: nowrap; font-family: var(--serif); padding-left: 14px; }
.detail-pricing-table small { display: block; color: var(--muted); margin-top: 2px; font-size: 0.8rem; }

.detail-links { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 18px; }
.detail-links a {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.85rem; padding: 8px 14px;
  border: 1px solid var(--rule-2); border-radius: 999px;
  color: var(--text);
}
.detail-links a:hover { border-color: var(--text); color: var(--amber-500); }

/* Print-friendly */
@media print {
  .topnav, .progress-rail, .grid-bg, .compare-controls, .pricing-controls, .footer, .theme-toggle { display: none; }
  .card { break-inside: avoid; box-shadow: none; }
}
