/* Roblox LLM Leaderboard, Torpedo Software brand.
   Tokens mirror torpedosoftware.llc (src/styles/tokens.css). Dark theme is default. */

:root,
[data-theme="dark"] {
  --color-canvas: #0f1012;
  --color-surface: #17191c;
  --color-surface-raised: #1d1f23;
  --color-surface-sunken: #0a0b0d;
  --color-border-subtle: #24272b;
  --color-border: #313439;
  --color-border-strong: #474b53;
  --color-text-primary: #f2eee6;
  --color-text-secondary: #b6b7ba;
  --color-text-tertiary: #82858a;
  --color-primary: #4837c8;
  --color-primary-hover: #5140d5;
  --color-primary-contrast: #ffffff;
  --color-primary-soft: rgba(72, 55, 200, 0.16);
  --color-primary-bright: #7d6ee8; /* readable purple for text/points on dark */
  --color-accent: #e0a050;
  --color-accent-soft: #382915;
  --color-success: #4fb079;
  --color-warning: #e0a050;
  --color-danger: #e86058;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 1px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 2px 4px rgba(0, 0, 0, 0.32), 0 4px 8px rgba(0, 0, 0, 0.3);
  /* Purple-on-black reads fainter than purple-on-white, so dark theme gets a
     stronger sonar grid to keep the field equally legible on both. */
  --sonar-ring-opacity: 0.15;
  --sonar-spoke-opacity: 0.1;
  --sonar-crosshair-opacity: 0.15;
  --sonar-beam-opacity: 0.3;
  --score-tint: 72, 55, 200;
  --score-tint-max: 0.3;
}

[data-theme="light"] {
  --color-canvas: #faf8f5;
  --color-surface: #ffffff;
  --color-surface-raised: #ffffff;
  --color-surface-sunken: #f3efe9;
  --color-border-subtle: #eae4da;
  --color-border: #d8d1c4;
  --color-border-strong: #b8ae9c;
  --color-text-primary: #0f1621;
  --color-text-secondary: #4a5568;
  --color-text-tertiary: #5a6577;
  --color-primary: #3224a5;
  --color-primary-hover: #3728ae;
  --color-primary-contrast: #ffffff;
  --color-primary-soft: #ece9fa;
  --color-primary-bright: #3224a5;
  --color-accent: #c68a3a;
  --color-accent-soft: #f7ebd5;
  --color-success: #2f7d4f;
  --color-warning: #b3701a;
  --color-danger: #b3322c;
  --shadow-1: 0 1px 2px rgba(23, 18, 9, 0.04), 0 1px 1px rgba(23, 18, 9, 0.06);
  --shadow-2: 0 2px 4px rgba(23, 18, 9, 0.05), 0 4px 8px rgba(23, 18, 9, 0.04);
  --sonar-ring-opacity: 0.06;
  --sonar-spoke-opacity: 0.05;
  --sonar-crosshair-opacity: 0.08;
  --sonar-beam-opacity: 0.2;
  --score-tint: 50, 36, 165;
  --score-tint-max: 0.26;
}

:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: "Big Shoulders Display", "Inter", sans-serif;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
  --motion-fast: 160ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  font-feature-settings: "tnum", "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 24px;
  background-color: var(--color-canvas);
  transition: background-color var(--motion-fast) var(--ease-out), color var(--motion-fast) var(--ease-out);
}

a { color: var(--color-primary-bright); text-decoration: none; transition: color var(--motion-fast) var(--ease-out); }
a:hover { color: var(--color-primary-hover); text-decoration: underline; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 24px; }

h1, h2, h3 { font-family: var(--font-display); text-transform: uppercase; }

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-canvas), 0 0 0 4px var(--color-primary);
  border-radius: var(--radius-sm);
}

/* Overline label: brand utility for eyebrows, table headers, captions */
.overline, thead th, .detail-grid h4 {
  font-family: var(--font-sans);
  font-size: 11px;
  line-height: 16px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ---------- Nav ---------- */

.site-nav {
  height: 56px;
  border-bottom: 1px solid var(--color-border-subtle);
  background: var(--color-canvas);
}
.nav-inner { display: flex; align-items: center; justify-content: space-between; height: 100%; }
.nav-brand { display: inline-flex; align-items: center; height: 100%; padding: 10px 0; }
.nav-brand img { display: block; }
.wordmark { height: 100%; width: auto; }
[data-theme="dark"] .wordmark-light { display: none; }
[data-theme="light"] .wordmark-dark { display: none; }
.nav-links { display: flex; align-items: center; gap: 24px; }
.nav-links a { color: var(--color-text-secondary); font-size: 13px; font-weight: 500; }
.nav-links a:hover { color: var(--color-text-primary); text-decoration: none; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-size: 16px;
  color: var(--color-text-tertiary);
  border-radius: var(--radius-sm);
  transition: color var(--motion-fast) var(--ease-out), background-color var(--motion-fast) var(--ease-out),
    transform var(--motion-fast) var(--ease-out);
}
.theme-toggle:hover { color: var(--color-text-primary); background: var(--color-surface-sunken); }
.theme-toggle:active { transform: scale(0.98); }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="light"] .theme-icon-dark { display: none; }

/* ---------- Header / hero with sonar ---------- */

.site-header { position: relative; overflow: hidden; padding: 64px 0 72px; }

/* Sonar field (ported from the brand site's SonarBackground.tsx; see the
   comment in index.html for the performance rationale). The field sets
   `color` once and every layer paints with currentColor, so the whole sonar
   is theme-reactive; faintness comes from per-layer opacity tokens. */
.sonar-root {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.sonar-field {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(90vw, 520px);
  aspect-ratio: 1;
  color: var(--color-primary);
}
@media (min-width: 768px) {
  .sonar-field { width: min(140vh, 1200px); }
}
.sonar-grid {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* Promote to a cached GPU layer so the rotating beam (a sibling) never
     dirties the grid's picture-cache slice. */
  transform: translateZ(0);
  will-change: transform;
}
.sonar-grid circle, .sonar-grid line { stroke-width: 1; }
.sonar-ring { opacity: var(--sonar-ring-opacity); }
.sonar-spoke { opacity: var(--sonar-spoke-opacity); }
.sonar-crosshair { opacity: var(--sonar-crosshair-opacity); }

@keyframes sonar-sweep {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.sonar-beam {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-full);
  opacity: var(--sonar-beam-opacity);
  background-size: 100% 100%;
  animation: sonar-sweep 8s linear infinite;
  will-change: transform;
}

/* A ping bloom: pops in, peaks, fades, then stays dormant for the rest of the
   cycle. `backwards` fill holds the invisible 0% state through the delay so a
   delayed ping never shows un-animated on first paint. */
@keyframes sonar-ping {
  0% { opacity: 0; transform: scale(0.4); }
  4% { opacity: 1; transform: scale(1); }
  14% { opacity: 0; transform: scale(1.1); }
  100% { opacity: 0; transform: scale(1.1); }
}
.sonar-ping-pos { position: absolute; }
.sonar-ping {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-full);
  opacity: 0.4;
  background: radial-gradient(circle, currentColor 0%, currentColor 35%, transparent 70%);
  animation: sonar-ping 8s linear infinite backwards;
  will-change: transform, opacity;
}

.site-header .wrap { position: relative; }

.eyebrow {
  font-size: 11px;
  line-height: 16px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-primary-bright);
  margin: 0 0 12px;
}

.site-header h1 {
  font-size: clamp(40px, 6vw, 64px);
  line-height: 1.06;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0 0 16px;
}
.site-header h1 .accent { color: var(--color-primary-bright); }

.lede { max-width: 620px; color: var(--color-text-secondary); font-size: 17px; line-height: 26px; margin: 0; }

/* ---------- Controls ---------- */

.controls {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 14px 16px;
  margin-bottom: 20px;
  background: color-mix(in srgb, var(--color-canvas) 90%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
}

.search {
  width: 100%;
  max-width: 360px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--color-text-primary);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: border-color var(--motion-fast) var(--ease-out);
}
.search:hover { border-color: var(--color-border-strong); }
.search::placeholder { color: var(--color-text-tertiary); }

.chip-group { display: inline-flex; gap: 4px; }

.chip {
  height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--color-text-primary);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  transition: color var(--motion-fast) var(--ease-out), background-color var(--motion-fast) var(--ease-out),
    border-color var(--motion-fast) var(--ease-out), transform var(--motion-fast) var(--ease-out);
}
.chip:hover { border-color: var(--color-border-strong); }
.chip:active { transform: scale(0.98); }
.chip.is-active {
  color: var(--color-primary-contrast);
  background: var(--color-primary);
  border-color: var(--color-primary);
}

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

.board { margin-bottom: 64px; }

.board-tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-bottom: -1px; }

.board-tab {
  padding: 9px 18px;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--color-text-tertiary);
  border: 1px solid transparent;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  transition: color var(--motion-fast) var(--ease-out);
}
.board-tab:hover { color: var(--color-text-primary); }
.board-tab.is-active {
  color: var(--color-text-primary);
  background: var(--color-surface);
  border-color: var(--color-border-subtle);
  border-bottom-color: var(--color-surface);
}

.difficulty-select { display: inline-flex; gap: 4px; margin-left: 12px; }
.difficulty-select[hidden] { display: none; }

.table-scroll {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: 0 var(--radius-md) var(--radius-md) var(--radius-md);
  box-shadow: var(--shadow-1);
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }

thead th {
  position: sticky;
  top: 0;
  padding: 10px 14px;
  color: var(--color-text-tertiary);
  text-align: right;
  white-space: nowrap;
  background: var(--color-surface-raised);
  border-bottom: 1px solid var(--color-border-subtle);
  cursor: pointer;
  user-select: none;
  transition: color var(--motion-fast) var(--ease-out);
}
thead th.col-model { text-align: left; }
thead th:hover { color: var(--color-text-primary); }
thead th.sorted { color: var(--color-primary-bright); }
thead th .arrow { display: inline-block; width: 1em; }

tbody td {
  padding: 10px 14px;
  text-align: right;
  white-space: nowrap;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--color-border-subtle);
}
tbody tr:last-child > td { border-bottom: none; }

tbody tr.model-row { cursor: pointer; transition: background var(--motion-fast) var(--ease-out); }
tbody tr.model-row:hover { background: var(--color-primary-soft); }
tbody tr.model-row.expanded { background: var(--color-primary-soft); }

td.col-rank { color: var(--color-text-tertiary); width: 44px; }
td.col-rank .medal {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
}
tr[data-rank="1"] .medal { color: var(--color-accent); }
tr[data-rank="2"] .medal { color: var(--color-text-secondary); }
tr[data-rank="3"] .medal { color: var(--color-text-tertiary); }

td.col-model { text-align: left; }
td.col-model .model-name { font-weight: 600; color: var(--color-text-primary); }
td.col-model .model-name:hover { color: var(--color-primary-bright); text-decoration: none; }
td.col-model .provider { display: block; font-size: 12px; color: var(--color-text-tertiary); }
td.col-model .provider .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: var(--radius-full);
}

/* Score cells: brand-purple tint whose opacity tracks the value (--pct is 0-1). */
td.cell-score {
  font-weight: 500;
  background-color: rgba(var(--score-tint), calc(var(--pct, 0) * var(--score-tint-max)));
}

td.cell-dim { color: var(--color-text-secondary); }

/* Expanded detail row */
tr.detail-row > td {
  padding: 16px 20px 20px;
  text-align: left;
  background: var(--color-surface-sunken);
}
.detail-grid { display: flex; flex-wrap: wrap; gap: 28px 48px; }
.detail-grid h4 { margin: 0 0 8px; color: var(--color-text-tertiary); font-family: var(--font-sans); }
.detail-grid table { font-size: 13px; width: auto; }
.detail-grid td, .detail-grid th {
  padding: 3px 12px 3px 0;
  border: none;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.detail-grid th { color: var(--color-text-tertiary); font-weight: 500; font-size: 12px; }
.detail-grid td:first-child, .detail-grid th:first-child { text-align: left; color: var(--color-text-secondary); }
.detail-grid .kv { margin: 0; font-size: 14px; }
.detail-grid .kv span { color: var(--color-text-tertiary); }

.board-note { color: var(--color-text-tertiary); font-size: 13px; line-height: 20px; margin: 10px 2px; }

.empty-note { padding: 28px; text-align: center; color: var(--color-text-tertiary); font-size: 13px; }

/* ---------- Charts ---------- */

.charts h2, .about h2 {
  font-size: 28px;
  font-weight: 500;
  letter-spacing: 0.01em;
  margin: 0 0 6px;
}
.section-lede { color: var(--color-text-secondary); margin: 0 0 20px; max-width: 640px; }

.chart-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }

.chart-card {
  margin: 0;
  min-width: 0;
  padding: 20px 20px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
  transition: box-shadow var(--motion-fast) var(--ease-out);
}
.chart-card:hover { box-shadow: var(--shadow-2); }
.chart-card figcaption { margin-bottom: 12px; }
.chart-card figcaption strong {
  display: block;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.chart-card figcaption span { display: block; color: var(--color-text-tertiary); font-size: 13px; line-height: 20px; margin-top: 2px; }
.chart-card .metric-toggle { margin-top: 8px; }

.chart-box { position: relative; height: 340px; max-width: 100%; }
.chart-box canvas { max-width: 100%; }
.chart-box.tall { height: 460px; }

/* ---------- About & footer ---------- */

.about { margin: 64px 0; }
.about-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.about-grid > div {
  padding: 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
}
.about-grid h3 { margin: 0 0 8px; font-size: 16px; font-weight: 600; letter-spacing: 0.02em; }
.about-grid p { margin: 0; color: var(--color-text-secondary); font-size: 13px; line-height: 20px; }
.about-grid code {
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--color-primary-bright);
  background: var(--color-primary-soft);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
}

.site-footer {
  padding: 28px 0 40px;
  border-top: 1px solid var(--color-border-subtle);
  color: var(--color-text-tertiary);
  font-size: 13px;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; }
  .about-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .site-header { padding: 40px 0 48px; }
  .wrap { padding: 0 16px; }
  .controls { position: static; }
  .chart-box { height: 300px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition-duration: 50ms !important; animation-duration: 50ms !important; animation-iteration-count: 1 !important; }
  /* The sweep and pings hide under reduced motion, leaving the static grid. */
  .sonar-beam, .sonar-ping { display: none; }
}
