/* F1 Database Explorer */
:root {
  --bg: #0b0d10;
  --bg-elevated: #12151a;
  --bg-card: #161a21;
  --bg-hover: #1c222c;
  --border: #252b36;
  --border-strong: #343c4a;
  --text: #e8ecf1;
  --text-muted: #8b95a8;
  --text-dim: #5c6678;
  --accent: #e10600;
  --accent-soft: rgba(225, 6, 0, 0.15);
  --accent-hover: #ff2a22;
  --link: #7eb6ff;
  --link-hover: #a8ceff;
  --gold: #f0c14b;
  --silver: #c0c6d0;
  --bronze: #cd7f32;
  --success: #3dd68c;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", "Cascadia Code", ui-monospace, monospace;
  --nav-h: 56px;
  --max: 1200px;
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(225, 6, 0, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(40, 60, 100, 0.15), transparent);
}

a {
  color: var(--link);
  text-decoration: none;
  transition: color 0.12s ease;
}
a:hover { color: var(--link-hover); text-decoration: underline; }

/* Nav */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  background: rgba(11, 13, 16, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  max-width: var(--max);
  margin: 0 auto;
  height: 100%;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  text-decoration: none;
  flex-shrink: 0;
}
.brand:hover { color: var(--text); text-decoration: none; }
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), #8b0000);
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.05em;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  flex: 1;
  overflow-x: auto;
}
.nav-links a {
  color: var(--text-muted);
  padding: 0.4rem 0.65rem;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.nav-links a:hover {
  color: var(--text);
  background: var(--bg-hover);
  text-decoration: none;
}
.nav-links a.active {
  color: #fff;
  background: var(--accent-soft);
}

.nav-search {
  display: flex;
  flex-shrink: 0;
}
.nav-search input {
  width: 160px;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.12s, width 0.2s;
}
.nav-search input:focus {
  border-color: var(--accent);
  width: 200px;
}
.nav-search input::placeholder { color: var(--text-dim); }

/* Layout */
.main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.75rem 1.25rem 4rem;
}

.page-header {
  margin-bottom: 1.75rem;
}
.page-header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}
.page-header .subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}
.page-header .meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin-top: 0.75rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.page-header .meta-row strong { color: var(--text); font-weight: 600; }

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-dim);
}
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs span.sep { color: var(--text-dim); }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 0.9rem;
  text-align: center;
}
.stat-card .value {
  display: block;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat-card .label {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 600;
}

/* Cards / panels */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.panel-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.panel-header .count {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.panel-body { padding: 0; }
.panel-body.padded { padding: 1.1rem; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* Tables */
.table-wrap { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
table.data th {
  text-align: left;
  padding: 0.55rem 0.85rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  font-weight: 650;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
}
table.data td {
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover td { background: var(--bg-hover); }
table.data .num { text-align: right; font-family: var(--mono); font-size: 0.84rem; }
table.data .pos {
  font-weight: 700;
  font-family: var(--mono);
  width: 2.5rem;
  text-align: center;
}
table.data tr.p1 .pos { color: var(--gold); }
table.data tr.p2 .pos { color: var(--silver); }
table.data tr.p3 .pos { color: var(--bronze); }
table.data .muted { color: var(--text-muted); }
table.data .retired { color: var(--text-dim); font-style: italic; }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  background: var(--bg-hover);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge.pole { background: rgba(240, 193, 75, 0.15); color: var(--gold); border-color: rgba(240, 193, 75, 0.3); }
.badge.fl { background: rgba(61, 214, 140, 0.12); color: var(--success); border-color: rgba(61, 214, 140, 0.3); }
.badge.champ { background: var(--accent-soft); color: #ff6b66; border-color: rgba(225, 6, 0, 0.35); }
.badge.video { background: rgba(126, 182, 255, 0.12); color: var(--link); border-color: rgba(126, 182, 255, 0.3); }

/* Pills / filters */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
  align-items: center;
}
.filters .label {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 0.25rem;
}
.pill {
  display: inline-block;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  text-decoration: none;
}
.pill:hover {
  color: var(--text);
  border-color: var(--border-strong);
  text-decoration: none;
  background: var(--bg-hover);
}
.pill.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

/* Nav between entities */
.entity-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.entity-nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.8rem;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  text-decoration: none;
  max-width: 48%;
}
.entity-nav a:hover {
  color: var(--text);
  border-color: var(--border-strong);
  text-decoration: none;
}
.entity-nav a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-nav .spacer { flex: 1; }

/* List cards (home) */
.list-cards {
  display: flex;
  flex-direction: column;
}
.list-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.75rem 1rem;
  align-items: center;
  padding: 0.75rem 1.1rem;
  border-bottom: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
}
.list-card:last-child { border-bottom: none; }
.list-card:hover {
  background: var(--bg-hover);
  text-decoration: none;
  color: inherit;
}
.list-card .round {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 2.2rem;
}
.list-card .title {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
}
.list-card .detail {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}
.list-card .side {
  text-align: right;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.list-card .side strong { color: var(--text); display: block; }

/* Tabs */
.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.65rem 1.1rem 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  overflow-x: auto;
}
.tabs a, .tabs button {
  appearance: none;
  border: none;
  background: none;
  color: var(--text-muted);
  padding: 0.55rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 550;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-family: inherit;
  white-space: nowrap;
}
.tabs a:hover, .tabs button:hover {
  color: var(--text);
  text-decoration: none;
}
.tabs a.active, .tabs button.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Search form */
.search-hero {
  max-width: 520px;
  margin: 0 auto 2rem;
}
.search-hero form {
  display: flex;
  gap: 0.5rem;
}
.search-hero input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}
.search-hero input:focus { border-color: var(--accent); }
.search-hero button {
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
  font-size: 0.95rem;
  cursor: pointer;
}
.search-hero button:hover { background: var(--accent-hover); }

/* Video links */
.video-list { list-style: none; margin: 0; padding: 0; }
.video-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.video-list li:last-child { border-bottom: none; }
.video-list .thumb {
  flex-shrink: 0;
  width: 120px;
  aspect-ratio: 16/9;
  border-radius: 6px;
  background: var(--bg-hover);
  object-fit: cover;
  border: 1px solid var(--border);
}
.video-list .info { flex: 1; min-width: 0; }
.video-list .info a.title {
  font-weight: 600;
  color: var(--text);
  display: block;
  margin-bottom: 0.2rem;
}
.video-list .info a.title:hover { color: var(--link); }
.video-list .meta { font-size: 0.8rem; color: var(--text-muted); }

/* Empty / 404 */
.empty {
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
}
.empty h2 { color: var(--text); margin: 0 0 0.5rem; }

/* Footer */
.site-footer {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.8rem;
  text-align: center;
}
.site-footer a { color: var(--text-muted); }

/* Utility */
.mono { font-family: var(--mono); font-size: 0.88em; }
.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.flag-note { font-size: 0.85rem; color: var(--text-muted); }

/* Letter index */
.letter-index {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 1rem;
}
.letter-index a {
  width: 1.7rem;
  height: 1.7rem;
  display: grid;
  place-items: center;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  text-decoration: none;
}
.letter-index a:hover, .letter-index a.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  text-decoration: none;
}

/* Highlight champion rows */
tr.champion td { background: rgba(225, 6, 0, 0.06); }
tr.champion:hover td { background: rgba(225, 6, 0, 0.1) !important; }

/* Ownership genealogy trees */
.lineage-toc-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem;
}
.lineage-toc-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: inherit;
  text-decoration: none;
  transition: border-color 0.12s, background 0.12s;
}
.lineage-toc-item:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
  text-decoration: none;
  color: inherit;
}
.lineage-toc-item.highlight,
.lineage-card.lineage-highlight {
  border-color: rgba(225, 6, 0, 0.45);
  box-shadow: 0 0 0 1px rgba(225, 6, 0, 0.15);
}
.lineage-toc-item strong { font-size: 0.92rem; color: var(--text); }
.lineage-sub {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 400;
}
.lineage-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.lineage-card { scroll-margin-top: calc(var(--nav-h) + 1rem); }

.tree-scroll {
  overflow-x: auto;
  padding: 1.25rem 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(225, 6, 0, 0.04), transparent 60%),
    var(--bg-card);
}
.ownership-tree {
  display: flex;
  align-items: stretch;
  gap: 0;
  min-width: min-content;
  padding-bottom: 0.25rem;
}
.ownership-tree.compact { padding: 0; }
.tree-node-wrap {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.tree-connector {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 3.2rem;
  color: var(--text-dim);
  position: relative;
}
.tree-connector::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0.2rem;
  right: 0.2rem;
  height: 2px;
  background: linear-gradient(90deg, var(--border-strong), var(--accent));
  opacity: 0.7;
  transform: translateY(-50%);
}
.tree-arrow {
  position: relative;
  z-index: 1;
  font-size: 0.85rem;
  color: var(--accent);
  background: var(--bg-card);
  padding: 0 0.15rem;
  line-height: 1;
}
.tree-year {
  position: relative;
  z-index: 1;
  margin-top: 1.1rem;
  font-size: 0.68rem;
  font-family: var(--mono);
  font-weight: 650;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 0 0.2rem;
}

.tree-node {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 8.5rem;
  max-width: 11rem;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: inherit;
  text-decoration: none;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
  position: relative;
}
.tree-node:hover {
  transform: translateY(-2px);
  border-color: var(--link);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  text-decoration: none;
  color: inherit;
}
.tree-node.current {
  border-color: var(--accent);
  background: linear-gradient(160deg, rgba(225, 6, 0, 0.18), var(--bg-elevated) 70%);
  box-shadow: 0 0 0 1px rgba(225, 6, 0, 0.25);
}
.tree-node.hl {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.tree-name {
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.2;
}
.tree-years {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}
.tree-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.45rem;
  margin-top: 0.2rem;
  font-size: 0.7rem;
  color: var(--text-dim);
}
.tree-now {
  position: absolute;
  top: -0.45rem;
  right: 0.5rem;
  font-size: 0.62rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
}
.lineage-detail { /* table under tree */ }

.ownership-tree.compact .tree-node {
  min-width: 7rem;
  max-width: 9rem;
  padding: 0.55rem 0.65rem;
}
.ownership-tree.compact .tree-connector { width: 2.4rem; }
.ownership-tree.compact .tree-name { font-size: 0.82rem; }

@media (max-width: 600px) {
  .tree-node { min-width: 7.5rem; }
  .tree-connector { width: 2.4rem; }
}
