/* ---- theme ---------------------------------------------------------------- */
:root {
  --bg: #0d1117;
  --bg-soft: #121821;
  --bg-card: #161e29;
  --bg-card-hover: #1b2533;
  --line: #232e3d;
  --txt: #dbe4ee;
  --txt-dim: #8595a8;
  --accent: #ff5a1f;
  --accent-soft: rgba(255, 90, 31, .14);
  --good: #3fcf6f;
  --bad: #ff5a5a;
  --warn: #ffc53f;
  --info: #58a6ff;
  --radius: 10px;
  --shadow: 0 4px 16px rgba(0, 0, 0, .35);
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--txt);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 700; letter-spacing: .01em; }
button, select, input {
  font: inherit;
  color: var(--txt);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
}
button { cursor: pointer; }
button:hover { background: var(--bg-card-hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
[hidden] { display: none !important; }

/* ---- topbar ---------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 22px;
  padding: 10px 20px;
  background: rgba(13, 17, 23, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 6px; font-weight: 900; font-size: 20px; color: var(--txt); }
.brand:hover { text-decoration: none; }
.brand-td { color: var(--accent); letter-spacing: .04em; }
.brand-sep { color: var(--txt-dim); }
.brand-w43 { font-weight: 600; color: var(--txt-dim); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 7px 14px; border-radius: 8px; color: var(--txt-dim); font-weight: 600;
  position: relative;
}
.nav a:hover { color: var(--txt); background: var(--bg-card); text-decoration: none; }
.nav a.active { color: var(--accent); background: var(--accent-soft); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.conn { font-size: 12px; }
.conn-on { color: var(--good); }
.conn-off { color: var(--bad); }
.conn-warn { color: var(--warn); }
.live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--bad); margin-left: 4px; vertical-align: middle;
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 50% { opacity: .35; } }
.auth-chip { color: var(--txt-dim); font-size: 13px; }
.auth-chip b { color: var(--txt); }

/* ---- layout ---------------------------------------------------------------- */
main { max-width: 1280px; margin: 0 auto; padding: 22px 20px 80px; }
.boot { color: var(--txt-dim); padding: 60px 0; text-align: center; }
.page-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 24px; }
.page-head .sub { color: var(--txt-dim); }
.muted { color: var(--txt-dim); }
.spacer { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---- chips & badges --------------------------------------------------------- */
.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  background: var(--bg-card); border: 1px solid var(--line);
  font-size: 12px; color: var(--txt-dim); white-space: nowrap;
}
.chip.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.chip.good { color: var(--good); }
.chip.bad { color: var(--bad); }
.chip.warn { color: var(--warn); }
.rq {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 38px; padding: 2px 7px; border-radius: 8px;
  font-weight: 800; font-size: 13px; color: #0d1117;
}
.rq-t1 { background: #9aa7b5; }      /* low */
.rq-t2 { background: #58d68d; }
.rq-t3 { background: #58a6ff; }
.rq-t4 { background: #b07cf7; }
.rq-t5 { background: #ffc53f; }      /* high */

/* ---- card grid --------------------------------------------------------------- */
.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.car-tile {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: transform .12s, border-color .12s;
  display: flex; flex-direction: column;
}
.car-tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.car-tile .thumb {
  aspect-ratio: 16/9; background: var(--bg-soft); display: flex; align-items: center; justify-content: center;
}
.car-tile .thumb img { width: 100%; height: 100%; object-fit: cover; }
.car-tile .thumb .noimg { color: var(--line); font-size: 34px; font-weight: 900; }
.car-tile .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.car-tile .name { font-weight: 600; font-size: 14px; line-height: 1.25; }
.car-tile .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tile-flags { display: flex; gap: 5px; margin-top: 2px; flex-wrap: wrap; }
.upg { font-family: Consolas, monospace; font-size: 12px; color: var(--txt-dim); }
.upg b { color: var(--accent); }

/* ---- panels ------------------------------------------------------------------ */
.panel {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px;
}
.panel h3 { margin: 0 0 10px; }

/* diff banner */
.diff-banner { border-left: 4px solid var(--accent); }
.diff-banner .counts { display: flex; gap: 16px; flex-wrap: wrap; font-weight: 600; }
.diff-banner .counts .add { color: var(--good); }
.diff-banner .counts .del { color: var(--bad); }
.diff-banner .counts .upg-c { color: var(--warn); }
details.diff-details summary { cursor: pointer; color: var(--txt-dim); margin-top: 8px; }
.diff-list { margin: 10px 0 0; display: flex; flex-direction: column; gap: 6px; }
.diff-row { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 8px; background: var(--bg-soft); }
.diff-row img { width: 56px; height: 32px; object-fit: cover; border-radius: 4px; }
.diff-row .arrow { color: var(--txt-dim); }

/* ---- tabs (campaign) ----------------------------------------------------------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tab {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg-card); cursor: pointer; font-weight: 600; color: var(--txt-dim);
  font-size: 14px;
}
.tab:hover { color: var(--txt); border-color: var(--txt-dim); }
.tab.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tab .flag { margin-right: 6px; }

.boss-banner { display: flex; align-items: center; gap: 18px; }
.boss-banner .boss-info h2 { margin: 0 0 4px; }

.match { margin-bottom: 14px; }
.match-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.match-head h3 { margin: 0; font-size: 16px; }
.slots { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); }
.slot {
  position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  background: var(--bg-card); cursor: pointer;
  display: flex; flex-direction: column;
  transition: border-color .12s, transform .12s;
}
.slot:hover { border-color: var(--accent); transform: translateY(-2px); }
/* Track preview as a proper banner (images are 128–256px; cover crops cleanly). */
.slot .track-banner {
  position: relative; aspect-ratio: 2 / 1; background-size: cover; background-position: center;
  background-color: var(--bg-soft);
}
.slot .track-banner::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(13,17,23,.96) 4%, rgba(13,17,23,.25) 55%, rgba(13,17,23,0) 100%);
}
.slot .track-banner.noimg { display: grid; place-items: center; color: var(--line); font-weight: 900; font-size: 22px; }
.slot .ch-name {
  position: absolute; left: 10px; right: 10px; bottom: 7px; z-index: 1;
  font-weight: 700; font-size: 14px; line-height: 1.15; text-shadow: 0 1px 5px #000;
}
.slot .slot-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.slot .slot-foot {
  display: flex; align-items: center; gap: 8px; padding-top: 6px;
  border-top: 1px solid var(--line); font-size: 12px;
}
.slot .opp { display: flex; align-items: center; gap: 7px; min-width: 0; }
.slot .opp img { width: 42px; height: 24px; object-fit: cover; border-radius: 4px; flex: 0 0 42px; }
.slot .opp .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--txt-dim); }
.slot .opp .nm b { color: var(--txt); font-weight: 600; }
.slot .beat { margin-left: auto; text-align: right; white-space: nowrap; }
.slot .beat .sc { font-weight: 800; color: var(--accent); }
.slot .beat .tn { color: var(--txt-dim); font-size: 11px; }

/* ---- leaderboard drawer ---------------------------------------------------------- */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 90;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(680px, 96vw); z-index: 95;
  background: var(--bg-soft); border-left: 1px solid var(--line);
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  animation: slidein .15s ease-out;
}
@keyframes slidein { from { transform: translateX(40px); opacity: .4; } }
.drawer-head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.drawer-head h3 { margin: 0; flex: 1; }
.drawer-body { padding: 14px 18px; overflow-y: auto; flex: 1; }
.drawer-close { font-size: 18px; }

/* ---- tables ----------------------------------------------------------------------- */
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th {
  text-align: left; color: var(--txt-dim); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .05em;
  padding: 8px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg-soft);
}
table.t td { padding: 7px 10px; border-bottom: 1px solid rgba(35, 46, 61, .5); }
table.t tr:hover td { background: var(--bg-card); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.t .car-cell { display: flex; align-items: center; gap: 10px; }
.t .car-cell img { width: 64px; height: 36px; object-fit: cover; border-radius: 5px; }
.t .car-cell .nm { font-weight: 600; }
.best { color: var(--good); font-weight: 700; }
.dnf { color: var(--bad); }

/* ---- live feed ----------------------------------------------------------------------- */
.event {
  border-left: 3px solid var(--info); margin-bottom: 12px;
}
.event .ev-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.event .ev-time { color: var(--txt-dim); font-size: 12px; }
.event .cards-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.mini-card {
  display: flex; align-items: center; gap: 8px; background: var(--bg-soft);
  padding: 4px 10px 4px 4px; border-radius: 8px; border: 1px solid var(--line);
  font-size: 13px;
}
.mini-card img { width: 48px; height: 27px; object-fit: cover; border-radius: 4px; }
.event details { margin-top: 8px; }
.event pre {
  background: #0a0e14; padding: 10px; border-radius: 8px; overflow: auto;
  font-size: 12px; max-height: 320px;
}

/* ---- upload zone ----------------------------------------------------------------------- */
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 44px 20px; text-align: center; color: var(--txt-dim);
  transition: border-color .15s, background .15s; cursor: pointer;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone b { color: var(--txt); }

/* ---- toasts ----------------------------------------------------------------------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  background: var(--bg-card); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  padding: 12px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px;
  animation: slidein .15s ease-out;
}
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }

/* ---- car detail ----------------------------------------------------------------------- */
.car-hero { display: flex; gap: 22px; flex-wrap: wrap; align-items: flex-start; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; flex: 1; min-width: 300px; align-content: start; }
.stat {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; display: flex; align-items: center; gap: 11px; min-width: 0;
}
.stat .k { color: var(--txt-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.stat .v { font-size: 16px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* stat icons */
.ic { width: 36px; height: 36px; flex: 0 0 36px; color: var(--txt-dim); }
.ic .ln { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ic .dim { opacity: .45; }
.ic .fl { fill: var(--accent); stroke: none; }
.ic .num { fill: var(--txt); font-weight: 800; font-family: inherit; }

.chip.mono { font-family: Consolas, monospace; }
.tag-chip { cursor: pointer; }
.tag-chip:hover { border-color: var(--accent); color: var(--accent); }

/* tune colour swatch (recognise a tune at a glance) */
.tune-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--tc, #9aa7b5); margin-right: 5px; vertical-align: middle;
}
.tab[data-tune].active { border-color: var(--tc, var(--accent)); }

/* ---- surface chips ----------------------------------------------------------- */
.surf-list { display: inline-flex; flex-wrap: wrap; gap: 5px; align-items: center; vertical-align: middle; }
.ch-name-cell { margin-right: 8px; }
td .surf-list { margin-top: 0; }
.surf-chip {
  --sc: #8595a8;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px 1px 5px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  color: var(--sc);
  background: color-mix(in srgb, var(--sc) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--sc) 40%, transparent);
}
.surf-chip.dry {
  /* Dry asphalt is the baseline — keep it quiet so hazards stand out. */
  color: var(--txt-dim);
  background: transparent;
  border-color: var(--line);
}
.surf-ic { width: 14px; height: 14px; flex: 0 0 14px; }
.surf-ic .s { fill: none; stroke: var(--sc); stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
.surf-ic .f { fill: var(--sc); stroke: none; }
.surf-chip.dry .surf-ic .s { stroke: var(--txt-dim); }
.surf-chip.dry .surf-ic .f { fill: var(--txt-dim); }
.swatch-chip { display: inline-flex; align-items: center; gap: 7px; font-family: Consolas, monospace; }
.swatch { width: 14px; height: 14px; border-radius: 4px; border: 1px solid #0008; display: inline-block; }
.tier-chip[data-tier="7"] { color: #efae2f; border-color: #efae2f55; }
.tier-chip[data-tier="6"] { color: #a071e8; border-color: #7437d855; }
.tier-chip[data-tier="5"] { color: #f0524d; border-color: #f02a2455; }
.tier-chip[data-tier="4"] { color: #f0d328; border-color: #f0d32855; }
.tier-chip[data-tier="3"] { color: #5cb4e0; border-color: #3aa0d455; }
.tier-chip[data-tier="2"] { color: #58c97c; border-color: #39b85b55; }
.tier-chip[data-tier="1"] { color: #a7b2bf; border-color: #8c8c8c55; }

/* ---- game-style card (overlay on the card art; positions ported from the
        TopDrives.Extractor.Web reference implementation) ------------------------ */
.gamecard {
  --top: 12%;            /* height of the art's name plate */
  --right: 23.5%;        /* width of the art's stat column */
  --gap: .8%;
  position: relative;
  /* Card art is natively 415×256 — never upscale past it (keeps the overlay crisp). */
  width: min(415px, 100%);
  aspect-ratio: 415 / 256;
  border-radius: 10px;
  overflow: hidden;
  background: #222;
  box-shadow: 0 10px 24px #0008;
  container-type: inline-size;
  image-rendering: -webkit-optimize-contrast;
}
.gamecard > .art { width: 100%; height: 100%; object-fit: cover; display: block; }
.gamecard > .noart { display: grid; place-items: center; color: var(--line); font-size: 60px; font-weight: 900; }
.gamecard .ovl { position: absolute; inset: 0; pointer-events: none; color: #f5f5f5; text-shadow: 0 1px 2px #000; }
.gamecard .ovl > div { position: absolute; }

.gc-name {
  top: 0; left: 11.5%; width: 61%; height: var(--top);
  display: flex; align-items: center;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-size: clamp(.8rem, 4cqw, 1.45rem); font-weight: 800; line-height: .92;
  text-transform: uppercase;
}
.gc-year, .gc-country {
  top: 0; height: var(--top);
  display: grid; place-items: center;
  background: #161616d8; font-weight: 800; font-size: clamp(.7rem, 3.1cqw, 1.1rem);
}
.gc-year { right: 6.8%; width: 13.8%; border-radius: 0 0 0 5px; }
.gc-country { right: 0; width: 6.8%; border-radius: 0 5px 0 0; }
.gc-tyres {
  right: calc(var(--right) + 1.2%); bottom: 2.4%; width: 47%;
  text-align: right; font-size: clamp(.65rem, 2.7cqw, 1rem); color: #eeeeeedb;
}
.gc-mfr { left: 0; top: -3%; width: 17%; height: 17%; overflow: hidden; }
.gc-mfr img { width: 100%; height: 100%; object-fit: contain; object-position: left top; display: block; filter: drop-shadow(0 1px 1px #000); }
.gc-mfr span { display: block; font-size: clamp(.5rem, 2cqw, .8rem); font-weight: 800; text-transform: uppercase; line-height: .9; padding: 6% 0 0 4%; }

.gc-rq { left: 0; bottom: 0; width: 11%; height: 29%; color: #fff; text-shadow: none; }
.gc-rq svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.gc-rq svg path { stroke: none; fill: #8c8c8c; }
.gamecard[data-tier="2"] .gc-rq svg path { fill: #39b85b; }
.gamecard[data-tier="3"] .gc-rq svg path { fill: #3aa0d4; }
.gamecard[data-tier="4"] .gc-rq svg path { fill: #f0d328; }
.gamecard[data-tier="5"] .gc-rq svg path { fill: #f02a24; }
.gamecard[data-tier="6"] .gc-rq svg path { fill: #7437d8; }
.gamecard[data-tier="7"] .gc-rq svg path { fill: #efae2f; }
.gc-rq span { position: absolute; left: 7%; top: 5%; font-size: clamp(.45rem, 1.7cqw, .68rem); font-weight: 900; text-shadow: 0 2px 1px #0008; }
.gc-rq b { position: absolute; left: 0; right: 0; top: 20%; text-align: center; font-size: clamp(.85rem, 3.8cqw, 1.4rem); font-weight: 800; line-height: .82; text-shadow: 0 3px 1px #0008; }
.gc-rq strong { position: absolute; left: 9%; right: 10%; bottom: 6%; text-align: center; font-size: clamp(1.7rem, 8.6cqw, 3rem); font-weight: 900; line-height: .78; text-shadow: 0 3px 1px #0008; }

.gc-stats {
  top: calc(var(--top) + var(--gap)); right: 0; bottom: 0; width: var(--right);
  display: grid; grid-template-rows: repeat(4, 1fr); gap: var(--gap);
  padding: 0 1px 1px 0;
}
.gc-stats div { display: grid; align-content: center; justify-items: end; padding-right: 7%; }
.gc-stats b { font-size: clamp(1rem, 5.3cqw, 1.55rem); font-weight: 900; line-height: 1; }
.gc-stats span { color: #ffffffc4; font-size: clamp(.55rem, 2.25cqw, .82rem); font-weight: 500; line-height: 1.1; text-transform: uppercase; }

/* ---- setup page (link + step styling mirrors the td-vpn.w43.nl onboarding) ----------- */
.setup { max-width: 880px; }
.setup .panel { max-width: 880px; }
.setup h3 { margin: 0 0 10px; }
.setup .note { color: var(--txt-dim); font-size: 14px; }
code.inline { background: var(--bg-soft); padding: 2px 7px; border-radius: 5px; font-size: 13px; }

/* accent-underline links, like the td-vpn site */
.setup a {
  color: var(--txt); font-weight: 600; text-decoration: underline;
  text-decoration-color: rgba(255, 90, 31, .55); text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}
.setup a:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* numbered circle steps */
.setup ol.steps { margin: 0; padding-left: 0; list-style: none; counter-reset: step; }
.setup ol.steps > li {
  counter-increment: step; position: relative;
  padding: 0 0 16px 44px; line-height: 1.6;
}
.setup ol.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: 0;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 14px;
}
.setup ol.steps > li:last-child { padding-bottom: 0; }
.setup ol.steps b { color: var(--txt); }

/* iOS breadcrumb path + the "you must do this" callout */
.setup .path { color: var(--txt); font-weight: 600; }
.setup .path span { color: var(--txt-dim); font-weight: 400; padding: 0 2px; }
.setup .must {
  display: inline-block; margin-top: 5px; padding: 3px 10px; border-radius: 6px;
  background: rgba(255, 197, 63, .12); color: var(--warn); font-size: 13px; font-weight: 600;
}

@media (max-width: 720px) {
  .nav a { padding: 7px 9px; font-size: 13px; }
  main { padding: 14px 12px 60px; }
}
