/* ==========================================================================
   Inference Grades — Style Sheet
   Design direction: financial reference, not startup.
   The Economist, not Product Hunt.
   ========================================================================== */

/* ---------- Reset & Base ---------- */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'DM Sans', sans-serif;
  font-weight: 400;
  line-height: 1.6;
  color: #1A1A1A;
  background-color: #FAFAF7;
}

/* ---------- Color Tokens ---------- */

:root {
  --color-bg: #FAFAF7;
  --color-text: #1A1A1A;
  --color-text-secondary: #6B6B6B;
  --color-accent: #1B3A5C;
  --color-border: #E0DDD8;
  --color-border-strong: #C5C0B8;
  --color-row-alt: #F5F4F0;
  --color-grade-header-bg: #EEECEA;

  /* Grade-specific accent (subtle left border) */
  --color-grade-a: #1B3A5C;
  --color-grade-b: #2A7F6F;
  --color-grade-c: #8B7355;
}

/* ---------- Typography ---------- */

h1, h2, h3, h4 {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 600;
  line-height: 1.25;
  color: var(--color-text);
}

h1 { font-size: 2rem; margin-bottom: 0.5em; }
h2 { font-size: 1.5rem; margin-top: 2em; margin-bottom: 0.5em; }
h3 { font-size: 1.2rem; margin-top: 1.5em; margin-bottom: 0.4em; }
h4 { font-size: 1.05rem; margin-top: 1.2em; margin-bottom: 0.3em; }

p {
  margin-bottom: 1em;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code, .grade-name-inline {
  font-family: 'DM Mono', monospace;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.04);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

blockquote {
  border-left: 3px solid var(--color-border-strong);
  padding-left: 1.2em;
  margin: 1.5em 0;
  color: var(--color-text-secondary);
  font-style: italic;
}

hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 2em 0;
}

strong {
  font-weight: 600;
}

em {
  font-style: italic;
}

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

.site-header {
  border-bottom: 1px solid var(--color-border);
  padding: 1.2rem 0;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2rem;
}

.wordmark {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text);
  text-decoration: none;
  white-space: nowrap;
}

.wordmark:hover {
  text-decoration: none;
}

.site-nav {
  display: flex;
  gap: 1.5rem;
}

.site-nav a {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color 0.15s;
}

.site-nav a:hover,
.site-nav a.active {
  color: var(--color-text);
}

/* ---------- Index Page ---------- */

.index-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

.site-tagline {
  font-family: 'DM Sans', sans-serif;
  font-size: 1.15rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--color-text);
  max-width: 680px;
  margin-bottom: 1.5rem;
}

.edition-badge {
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  margin-bottom: 2rem;
}

.edition-verified {
  margin-left: 0.5em;
  padding-left: 0.5em;
  border-left: 1px solid var(--color-border);
}

/* ---------- Changelog ---------- */

.changelog {
  margin-bottom: 1.5rem;
  font-size: 0.82rem;
  color: var(--color-text-secondary);
}

.changelog-heading {
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.changelog-heading::-webkit-details-marker {
  display: none;
}

.changelog-heading::before {
  content: "\25b8 ";
  font-size: 0.7em;
}

.changelog[open] > .changelog-heading::before {
  content: "\25be ";
}

.changelog-list {
  list-style: none;
  margin-top: 0.4rem;
  padding-left: 0;
}

.changelog-list li {
  margin-bottom: 0.25rem;
  line-height: 1.5;
}

.changelog-date {
  font-weight: 500;
  margin-right: 0.4em;
}

.market-summary {
  max-width: 780px;
  border-left: 3px solid var(--color-accent);
  padding-left: 1.2rem;
  margin-bottom: 2.5rem;
}

.market-summary p {
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--color-text);
  margin-bottom: 0;
}

/* ---------- A/B Spread Callout ---------- */

.ab-spread-callout {
  max-width: 780px;
  margin-bottom: 2rem;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--color-text);
}

.ab-spread-callout p {
  margin-bottom: 0.2em;
}

.ab-spread-callout p:last-child {
  margin-bottom: 0;
  color: var(--color-text-secondary);
  font-size: 0.85rem;
}

/* ---------- Grade Table ---------- */

.table-container {
  overflow-x: auto;
  margin-bottom: 3rem;
  -webkit-overflow-scrolling: touch;
}

.grade-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  line-height: 1.4;
}

.grade-table thead {
  border-bottom: 2px solid var(--color-text);
}

.grade-table th {
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  padding: 0.6rem 0.75rem;
  text-align: left;
  white-space: nowrap;
  user-select: none;
}

.grade-table th .unit {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--color-text-secondary);
  opacity: 0.7;
}

.grade-table td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
  white-space: nowrap;
}

/* Grade group header rows */
.grade-header td {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.9rem 0.75rem 0.5rem;
  background: var(--color-grade-header-bg);
  border-bottom: 1px solid var(--color-border-strong);
  color: var(--color-text);
  letter-spacing: 0.01em;
}

/* Grade-specific left border on header */
.grade-ainstant td { border-left: 4px solid var(--color-grade-a); }
.grade-afast td { border-left: 4px solid var(--color-grade-a); }
.grade-abulk td { border-left: 4px solid var(--color-grade-a); }
.grade-binstant td { border-left: 4px solid var(--color-grade-b); }
.grade-bfast td { border-left: 4px solid var(--color-grade-b); }
.grade-bbulk td { border-left: 4px solid var(--color-grade-b); }
.grade-cinstant td { border-left: 4px solid var(--color-grade-c); }
.grade-cfast td { border-left: 4px solid var(--color-grade-c); }
.grade-cbulk td { border-left: 4px solid var(--color-grade-c); }

/* Alternating rows within each grade group (class-based, resets per group) */
.model-row.row-alt {
  background: var(--color-row-alt);
}

/* Model name column */
.model-name {
  font-weight: 500;
}

/* Tags (open weights, reasoning, incomplete data) */
.tag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.1em 0.4em;
  border-radius: 2px;
  vertical-align: middle;
  margin-left: 0.3em;
}

.tag-open {
  color: var(--color-grade-b);
  border: 1px solid var(--color-grade-b);
}

.tag-reasoning {
  color: var(--color-accent);
  border: 1px solid var(--color-accent);
}

.tag-incomplete {
  color: #9A6B30;
  border: 1px solid #9A6B30;
}

/* Numeric columns: right-align */
.col-score,
.col-speed,
.col-tt500,
.col-price {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.col-score[data-sort],
.col-speed[data-sort],
.col-tt500[data-sort],
.col-price[data-sort] {
  cursor: pointer;
}

.col-context {
  text-align: right;
}

.na {
  color: var(--color-text-secondary);
  opacity: 0.5;
}

/* Unit suffix shown only on mobile cards (e.g. "tok/s", "s") */
.unit-suffix {
  display: none;
}

.footnote {
  font-size: 0.75em;
  color: var(--color-text-secondary);
  cursor: help;
  margin-left: 0.2em;
}

/* Model note tooltip (shown on hover via JS, fallback: title attr) */
.model-row[data-note] {
  cursor: pointer;
}

.model-note-tooltip {
  position: absolute;
  background: var(--color-text);
  color: var(--color-bg);
  font-size: 0.8rem;
  line-height: 1.45;
  padding: 0.6rem 0.9rem;
  border-radius: 4px;
  max-width: 340px;
  white-space: normal;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* ---------- Grade Filters (JS-injected) ---------- */

.grade-filters {
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.filter-btn {
  font-family: 'DM Mono', monospace;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.3em 0.7em;
  border: 1px solid var(--color-border-strong);
  border-radius: 3px;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.12s;
}

.filter-btn.active {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

.filter-btn:hover:not(.active) {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.filter-sep {
  color: var(--color-border-strong);
  margin: 0 0.3rem;
  font-size: 0.85rem;
}

/* Sort direction indicators */
th[data-sort-dir="asc"]::after {
  content: " ▲";
  font-size: 0.6em;
  opacity: 0.6;
}

th[data-sort-dir="desc"]::after {
  content: " ▼";
  font-size: 0.6em;
  opacity: 0.6;
}

/* ---------- Grade Definitions ---------- */

.grade-definitions {
  max-width: 780px;
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--color-border);
}

.grade-definitions h2 {
  font-size: 1.3rem;
  margin-bottom: 1.5rem;
}

.grade-def {
  margin-bottom: 1.5rem;
}

.grade-def h3 {
  font-family: 'DM Mono', monospace;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--color-accent);
  margin-top: 0;
  margin-bottom: 0.3rem;
}

.grade-def p {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--color-text);
  margin-bottom: 0;
}

/* ---------- Reading Pages (Framework, Methodology) ---------- */

.reading-page {
  padding: 2.5rem 1.5rem 4rem;
}

.reading-inner {
  max-width: 680px;
  margin: 0 auto;
}

.back-link {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin-bottom: 2rem;
}

.back-link:last-child {
  margin-top: 3rem;
  margin-bottom: 0;
}

/* Essay content styling */
.essay-content h1 {
  font-size: 2.1rem;
  line-height: 1.2;
  margin-bottom: 0.3em;
}

.essay-content h1 + p > em:first-child {
  /* subtitle */
  display: block;
  font-size: 1.05rem;
  color: var(--color-text-secondary);
  font-style: italic;
  margin-bottom: 2em;
  line-height: 1.5;
}

.essay-content h2 {
  font-size: 1.4rem;
  margin-top: 2.5em;
}

.essay-content h3 {
  font-size: 1.15rem;
}

.essay-content p {
  font-size: 1rem;
  line-height: 1.7;
}

.essay-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 1.5em 0;
}

.essay-content th,
.essay-content td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  text-align: left;
}

.essay-content th {
  font-weight: 600;
  background: var(--color-grade-header-bg);
}

.essay-content ul,
.essay-content ol {
  margin: 1em 0;
  padding-left: 1.5em;
}

.essay-content li {
  margin-bottom: 0.4em;
  line-height: 1.65;
}

/* Author note */
.author-note {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

.author-note p {
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--color-text-secondary);
}

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

.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 2rem 0;
  margin-top: 2rem;
}

.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  line-height: 1.8;
}

.footer-inner a {
  color: var(--color-text-secondary);
}

.footer-inner a:hover {
  color: var(--color-text);
}

.footer-edition {
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 0.3rem;
}

.footer-links {
  margin-bottom: 0.3rem;
}

.footer-links a {
  margin-right: 1.2em;
}

.footer-sources {
  margin-bottom: 0.3rem;
}

.footer-contact {
  margin-bottom: 0;
}

/* ---------- Mobile ---------- */

@media (max-width: 768px) {

  /* -- Header -- */

  .header-inner {
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
  }

  .site-nav {
    gap: 0;
  }

  .site-nav a {
    padding: 0.5rem 0.75rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* -- Index page -- */

  .index-page {
    padding: 1.5rem 1rem 3rem;
  }

  .site-tagline {
    font-size: 1.05rem;
  }

  .market-summary {
    margin-bottom: 2rem;
  }

  .market-summary p {
    font-size: 0.88rem;
    line-height: 1.6;
  }

  /* -- Table → Card layout -- */

  .table-container {
    overflow-x: visible;
  }

  .grade-table {
    display: block;
  }

  .grade-table thead {
    display: none;
  }

  .grade-table tbody {
    display: block;
  }

  /* Grade group headers — full-width dividers */
  .grade-header {
    display: block;
  }

  .grade-header td {
    display: block;
    font-size: 0.95rem;
    padding: 0.75rem 0.75rem 0.45rem;
  }

  /* Model rows — card layout */
  .model-row {
    display: block;
    padding: 0.75rem;
    border-bottom: 1px solid var(--color-border);
  }

  .model-row.row-alt {
    background: var(--color-row-alt);
  }

  .model-row td {
    display: inline;
    padding: 0;
    border: none;
    white-space: normal;
    text-align: left;
    font-variant-numeric: tabular-nums;
  }

  /* Model name — block, acts as card title */
  .model-row .col-model {
    display: block;
    font-size: 0.95rem;
    margin-bottom: 0.15rem;
  }

  /* Provider — block, secondary text */
  .model-row .col-provider {
    display: block;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    margin-bottom: 0.5rem;
  }

  .model-row .col-provider::before {
    display: none;
  }

  /* Data fields — inline grid using CSS grid on the row */
  .model-row .col-score,
  .model-row .col-speed,
  .model-row .col-tt500,
  .model-row .col-price-in,
  .model-row .col-price-out,
  .model-row .col-context {
    display: inline-block;
    font-size: 0.8rem;
    margin-right: 1.2rem;
    margin-bottom: 0.2rem;
  }

  /* Labels via data-label */
  .model-row .col-score::before,
  .model-row .col-speed::before,
  .model-row .col-tt500::before,
  .model-row .col-price-in::before,
  .model-row .col-price-out::before,
  .model-row .col-context::before {
    content: attr(data-label) "\00a0";
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-secondary);
  }

  /* Show unit suffixes on mobile */
  .unit-suffix {
    display: inline;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
  }

  /* Tags — abbreviate */
  .tag {
    font-size: 0.6rem;
    padding: 0.05em 0.3em;
  }

  /* Grade filters — wrap nicely */
  .grade-filters {
    margin-bottom: 0.75rem;
  }

  .filter-btn {
    padding: 0.4em 0.8em;
    min-height: 36px;
  }

  /* -- Reading pages -- */

  .reading-page {
    padding: 1.5rem 1rem 3rem;
  }

  .essay-content h1 {
    font-size: 1.6rem;
  }

  .essay-content p {
    font-size: 0.95rem;
  }

  .essay-content table {
    font-size: 0.8rem;
  }

  .essay-content th,
  .essay-content td {
    padding: 0.35rem 0.5rem;
  }

  /* -- Footer -- */

  .footer-inner {
    line-height: 2;
  }

  .footer-links a {
    margin-right: 1em;
  }
}

@media (max-width: 480px) {
  .wordmark {
    font-size: 1.15rem;
  }

  .site-tagline {
    font-size: 0.95rem;
  }

  .model-row .col-model {
    font-size: 0.88rem;
  }

  .model-row .col-score,
  .model-row .col-speed,
  .model-row .col-tt500,
  .model-row .col-price-in,
  .model-row .col-price-out,
  .model-row .col-context {
    font-size: 0.75rem;
    margin-right: 0.9rem;
  }
}
