:root {
    --color-background: #101014;
    --color-surface: #191920;
    --color-accent: #d4ff00;
    --color-accent-rgb: 212, 255, 0;
    --color-text-primary: #f1f1f1;
    --color-text-secondary: #a2a2b6;
    --color-border: rgba(132, 132, 154, 0.18);
    --csp-gold: #ffd700;
    --csp-silver: #e8e8ec;
    --csp-bronze: #cd7f32;
    --csp-purple-rgb: 168, 85, 247;
}

* { box-sizing: border-box; }
html, body {
    width: 100%; height: 100%; margin: 0;
    background: #08080c; color: var(--color-text-primary);
    font-family: "Exo 2", Arial, sans-serif;
}
body { overflow: hidden; }
select { font: inherit; }

.simhub-shell {
    width: 100vw; height: 100vh; min-width: 320px;
    display: grid; grid-template-rows: auto minmax(0, 1fr);
    gap: 8px; padding: 8px;
    background: radial-gradient(90% 70% at 100% 0%, rgba(var(--color-accent-rgb), .08), transparent 62%), #08080c;
}

.simhub-filter {
    position: relative; z-index: 5;
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 420px);
    align-items: center; gap: 14px; min-height: 58px; padding: 8px 12px;
    border: 1px solid var(--color-border); border-left: 4px solid var(--color-accent);
    border-radius: 10px; background: rgba(25,25,32,.95);
}
.simhub-filter__copy { display: flex; flex-direction: column; min-width: 0; }
.simhub-filter__eyebrow, .simhub-filter__field > span {
    color: var(--color-text-secondary); font-size: 9px; font-weight: 800;
    letter-spacing: .14em; text-transform: uppercase;
}
.simhub-filter__copy strong { margin-top: 2px; font-size: 17px; line-height: 1.1; }
.simhub-filter__field {
    display: grid; grid-template-columns: auto minmax(0, 1fr);
    align-items: center; gap: 10px;
}
.simhub-filter select {
    width: 100%; min-width: 0; min-height: 38px;
    padding: 7px 34px 7px 10px; color: #fff;
    border: 1px solid rgba(132,132,154,.36); border-radius: 8px;
    outline: none; background: #111117;
}
.simhub-filter select:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(var(--color-accent-rgb), .12);
}
.simhub-filter select:disabled { opacity: .58; }

.csp-board {
    position: relative; display: flex; flex-direction: column; min-height: 0;
    overflow: hidden; padding: 14px 16px 10px;
    border: 1px solid rgba(var(--color-accent-rgb), .2);
    border-left: 4px solid var(--color-accent); border-radius: 10px;
    background:
        radial-gradient(120% 90% at 100% 0%, rgba(var(--color-accent-rgb), .12), transparent 58%),
        linear-gradient(168deg, rgba(26,26,34,.98), rgba(8,8,12,.98));
    box-shadow: 0 28px 72px rgba(0,0,0,.54);
}
.csp-fx, .csp-banner {
    position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 0;
}
.csp-banner {
    background-size: cover; background-position: center;
    opacity: .11; filter: saturate(1.1) blur(2px);
}
.csp-fx-glow {
    position: absolute; top: -42%; right: -16%; width: 70%; height: 70%;
    background: radial-gradient(circle, rgba(var(--color-accent-rgb), .16), transparent 70%);
}
.csp-fx-stripe {
    position: absolute; top: 0; left: -100%; width: 100%; height: 3px;
    background: linear-gradient(90deg, transparent, var(--color-accent), #fff, var(--color-accent), transparent);
    opacity: .82; animation: shimmer 3.4s linear infinite;
}
.csp-fx-grid {
    position: absolute; inset: 0; opacity: .03;
    background-image:
        linear-gradient(rgba(255,255,255,.55) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.55) 1px, transparent 1px);
    background-size: 20px 20px;
}
@keyframes shimmer { to { transform: translateX(200%); } }

.csp-content, .simhub-state { position: relative; z-index: 2; }
.csp-content { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.simhub-state {
    flex: 1; min-height: 180px; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 10px;
    text-align: center; color: var(--color-text-secondary);
}
.simhub-state--error strong { color: var(--color-text-primary); font-size: 18px; }
.simhub-spinner {
    width: 28px; height: 28px; border: 3px solid rgba(255,255,255,.14);
    border-top-color: var(--color-accent); border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.csp-chrome {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 12px; margin-bottom: 8px; padding-bottom: 8px;
    border-bottom: 1px solid rgba(var(--color-accent-rgb), .16);
}
.csp-chrome__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.csp-chrome__logo {
    width: 44px; height: 44px; flex: 0 0 auto; object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,.45));
}
.csp-chrome__titles { min-width: 0; }
.csp-chrome__badges { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 3px; }
.csp-badge, .csp-category, .csp-discard-badge {
    display: inline-flex; align-items: center; min-height: 20px;
    padding: 3px 8px; font-size: 8px; font-weight: 900;
    letter-spacing: .12em; text-transform: uppercase;
}
.csp-badge { color: var(--color-background); background: var(--color-accent); }
.csp-category {
    color: var(--color-accent); border: 1px solid rgba(var(--color-accent-rgb), .35);
    border-radius: 999px; background: rgba(var(--color-accent-rgb), .08);
}
.csp-discard-badge {
    color: var(--color-text-primary); border: 1px solid rgba(255,193,7,.45);
    border-radius: 999px; background: rgba(255,193,7,.16);
}
.csp-chrome__title {
    max-width: 520px; margin: 0; overflow: hidden;
    color: var(--color-text-primary); font-size: clamp(18px, 2.3vw, 26px);
    font-weight: 900; line-height: 1.05; text-overflow: ellipsis; white-space: nowrap;
}
.csp-chrome__org {
    margin: 2px 0 0; overflow: hidden; color: var(--color-text-secondary);
    font-size: 10px; text-overflow: ellipsis; white-space: nowrap;
}
.csp-chrome__meta { display: flex; gap: 6px; flex: 0 0 auto; }
.csp-meta-pill {
    display: flex; flex-direction: column; align-items: center;
    min-width: 56px; padding: 6px 8px;
    border: 1px solid rgba(132,132,154,.18); border-radius: 8px;
    background: rgba(0,0,0,.35);
}
.csp-meta-pill--done {
    border-color: rgba(var(--color-accent-rgb), .28);
    background: rgba(var(--color-accent-rgb), .07);
}
.csp-meta-pill__value { color: var(--color-accent); font-size: 18px; font-weight: 900; line-height: 1; }
.csp-meta-pill__label {
    margin-top: 2px; color: var(--color-text-secondary);
    font-size: 7px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
}

.csp-podium {
    display: grid; grid-template-columns: 1.05fr .95fr .9fr;
    gap: 6px; margin-bottom: 7px;
}
.csp-podium-card {
    position: relative; display: flex; align-items: center; gap: 7px;
    min-width: 0; padding: 6px 8px; overflow: hidden;
    border: 1px solid rgba(132,132,154,.16); border-radius: 8px;
    background: rgba(0,0,0,.38);
}
.csp-podium-card::before {
    content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
    background: var(--csp-medal, var(--color-accent));
}
.csp-podium-card--p1 { --csp-medal: var(--csp-gold); }
.csp-podium-card--p2 { --csp-medal: var(--csp-silver); }
.csp-podium-card--p3 { --csp-medal: var(--csp-bronze); }
.csp-podium-pos { min-width: 22px; color: var(--csp-medal); font-size: 14px; font-weight: 900; }
.csp-podium-name {
    flex: 1; min-width: 0; overflow: hidden;
    font-size: 11px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap;
}
.csp-podium-pts { color: var(--color-accent); font-size: 14px; font-weight: 900; }

.csp-progress { margin-bottom: 6px; }
.csp-progress__track {
    height: 4px; overflow: hidden; border-radius: 999px;
    background: rgba(255,255,255,.06);
}
.csp-progress__fill {
    height: 100%; width: 0; border-radius: inherit;
    background: linear-gradient(90deg, var(--color-accent), #fff 50%, var(--color-accent));
    box-shadow: 0 0 10px rgba(var(--color-accent-rgb), .5);
    transition: width .5s ease;
}
.csp-progress__label { margin: 3px 0 0; color: var(--color-text-secondary); font-size: 9px; font-weight: 600; }

.csp-matrix-wrap {
    flex: 1; min-height: 0; overflow: auto;
    border: 1px solid rgba(132,132,154,.14); border-radius: 8px;
    background: rgba(0,0,0,.28);
    scrollbar-width: thin;
}
.csp-matrix { width: max(100%, 620px); border-collapse: separate; border-spacing: 0; font-size: 11px; }
.csp-matrix thead th {
    position: sticky; top: 0; z-index: 3; padding: 5px 6px;
    color: var(--color-text-primary); border-bottom: 1px solid rgba(var(--color-accent-rgb), .18);
    background: rgba(0,0,0,.88); font-size: 9px; font-weight: 800;
    letter-spacing: .08em; text-transform: uppercase; white-space: nowrap;
}
.csp-col-sticky { position: sticky; left: 0; z-index: 4; background: rgba(0,0,0,.92) !important; }
.csp-col-pos { width: 36px; text-align: center; }
.csp-col-driver { left: 36px; min-width: 150px; max-width: 190px; text-align: left; }
.csp-stage-head { min-width: 44px; max-width: 56px; text-align: center; }
.csp-stage-head__code { display: block; color: var(--color-text-primary); font-size: 10px; font-weight: 900; }
.csp-stage-head--done .csp-stage-head__code { color: var(--color-accent); }
.csp-stage-head--pending { opacity: .45; }
.csp-matrix tbody td {
    padding: 4px 6px; border-bottom: 1px solid rgba(132,132,154,.08);
    font-variant-numeric: tabular-nums; white-space: nowrap;
}
.csp-matrix tbody tr:nth-child(even) td { background: rgba(255,255,255,.02); }
.csp-matrix tbody tr:hover td { background: rgba(var(--color-accent-rgb), .06); }
.csp-driver-name {
    display: block; overflow: hidden; color: var(--color-text-primary);
    font-size: 12px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap;
}
.csp-cell, .csp-total, .csp-discard, .csp-final,
.csp-col-total, .csp-col-discard, .csp-col-final { text-align: center; }
.csp-cell { color: var(--color-text-primary); font-size: 10px; font-weight: 800; }
.csp-cell--empty { color: rgba(241,241,241,.42); }
.csp-cell--heat { background: rgba(var(--color-accent-rgb), calc(.04 + var(--csp-heat, 0) * .22)); }
.csp-cell--win {
    color: #e9d5ff; background: rgba(var(--csp-purple-rgb), .22) !important;
    box-shadow: inset 0 0 0 1px rgba(var(--csp-purple-rgb), .45);
}
.csp-cell--discard {
    color: #c8c8d4; text-decoration: line-through; text-decoration-thickness: 2px;
    background: rgba(255,193,7,.12) !important;
}
.csp-row--p1 .csp-col-pos { color: var(--csp-gold); font-weight: 900; }
.csp-row--p2 .csp-col-pos { color: var(--csp-silver); font-weight: 900; }
.csp-row--p3 .csp-col-pos { color: var(--csp-bronze); font-weight: 900; }
.csp-total { color: var(--color-text-secondary); font-size: 11px; font-weight: 900; }
.csp-discard { min-width: 48px; color: #ffc107; font-size: 11px; font-weight: 800; }
.csp-final {
    min-width: 48px; color: var(--color-accent); font-size: 12px; font-weight: 900;
    background: rgba(var(--color-accent-rgb), .08);
}
.csp-foot { flex: 0 0 auto; margin-top: 4px; }
.csp-foot__updated { margin: 0; color: var(--color-text-secondary); font-size: 8px; text-align: right; }
[hidden] { display: none !important; }

@media (max-width: 700px) {
    .simhub-filter { grid-template-columns: 1fr; gap: 5px; padding: 6px 8px; }
    .simhub-filter__copy { display: none; }
    .simhub-filter__field { grid-template-columns: 62px minmax(0, 1fr); }
    .csp-board { padding: 8px; }
    .csp-chrome__logo { width: 34px; height: 34px; }
    .csp-chrome__title { font-size: 16px; }
    .csp-podium { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .csp-podium-card { padding: 4px 6px; }
    .csp-podium-name { font-size: 9px; }
    .csp-podium-pts { font-size: 11px; }
}

@media (max-height: 520px) {
    .simhub-shell { gap: 5px; padding: 5px; }
    .simhub-filter { min-height: 44px; padding-top: 4px; padding-bottom: 4px; }
    .csp-board { padding: 7px 9px 5px; }
    .csp-chrome { margin-bottom: 5px; padding-bottom: 5px; }
    .csp-chrome__logo { width: 32px; height: 32px; }
    .csp-chrome__title { font-size: 15px; }
    .csp-meta-pill { min-width: 48px; padding: 4px 6px; }
    .csp-meta-pill__value { font-size: 14px; }
    .csp-podium { margin-bottom: 4px; }
    .csp-podium-card { padding-top: 3px; padding-bottom: 3px; }
    .csp-progress { margin-bottom: 3px; }
    .csp-progress__label { display: none; }
    .csp-matrix tbody td { padding-top: 3px; padding-bottom: 3px; }
}
