/* =========================================================
   TorchEBM Benchmarks — Stylesheet
   ========================================================= */

/* --- CSS Variables / Theming --- */
:root {
    --font-sans: -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
    --font-mono: SFMono-Regular, Consolas, Menlo, monospace;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 2px 8px rgba(0,0,0,0.15);
    --shadow-lg: 0 4px 24px rgba(0,0,0,0.25);
    --transition: 0.2s ease;
    --max-width: 1280px;
}

[data-theme="dark"] {
    --bg-primary: #111111;
    --bg-secondary: #161616;
    --bg-card: #1e1e1e;
    --bg-hover: #2a2a2a;
    --border: #2e2e2e;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #b0eb00;
    --accent-hover: #c8f530;
    --accent-subtle: rgba(176, 235, 0, 0.12);
    --green: #3fb950;
    --green-bg: rgba(63, 185, 80, 0.12);
    --yellow: #d29922;
    --yellow-bg: rgba(210, 153, 34, 0.12);
    --red: #f85149;
    --red-bg: rgba(248, 81, 73, 0.12);
    --purple: #bc8cff;
    --orange: #f0883e;
    --chart-bg: #161616;
    --chart-grid: #222222;
    --chart-text: #8b949e;
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f6f8fa;
    --bg-card: #ffffff;
    --bg-hover: #f3f4f6;
    --border: #d0d7de;
    --text-primary: #1a1a1a;
    --text-secondary: #3d4249;
    --text-muted: #636c76;
    --accent: #7cb305;
    --accent-hover: #5a8a00;
    --accent-subtle: rgba(124, 179, 5, 0.10);
    --green: #1a7f37;
    --green-bg: rgba(26, 127, 55, 0.08);
    --yellow: #9a6700;
    --yellow-bg: rgba(154, 103, 0, 0.08);
    --red: #cf222e;
    --red-bg: rgba(207, 34, 46, 0.08);
    --purple: #8250df;
    --orange: #bc4c00;
    --chart-bg: #ffffff;
    --chart-grid: #e1e4e8;
    --chart-text: #656d76;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font-sans);
    font-weight: 400;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

/* --- Site Header (two-row, matches TorchEBM official) --- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    color: #fff;
}

/* Top row: brand + actions */
.header-top {
    background: #0a0a0a;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.header-top-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 52px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.nav-logo-link {
    display: flex;
    align-items: center;
}

.nav-logo-img {
    display: block;
    width: 28px;
    height: 28px;
}

.nav-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: #fff;
    letter-spacing: -0.01em;
}

.nav-version {
    font-size: 0.75rem;
    font-weight: 500;
    color: rgba(255,255,255,0.45);
    background: rgba(255,255,255,0.08);
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    letter-spacing: 0.02em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.header-github {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #fff;
    font-size: 0.82rem;
    transition: opacity .25s;
    text-decoration: none;
}

.header-github:hover { opacity: 0.7; }

.header-github-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.header-github-name {
    font-weight: 500;
}

.header-github-meta {
    font-size: 0.65rem;
    color: rgba(255,255,255,0.55);
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.gh-stat {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
}

.gh-stat svg {
    opacity: 0.7;
}

.theme-toggle {
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.4rem;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .25s;
}

.theme-toggle:hover { opacity: 0.7; }

[data-theme="dark"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: none; }

/* Navbar star button */
.nav-star {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: .3em .9em;
    background: transparent;
    color: #b0eb00;
    border: .1rem solid #b0eb00;
    border-radius: 0.15rem;
    font-weight: 700;
    font-size: 0.78rem;
    line-height: 1.3;
    text-decoration: none;
    transition: color 125ms, background-color 125ms, border-color 125ms;
}

.nav-star:hover {
    background: #b0eb00;
    border-color: #b0eb00;
    color: #000;
}

/* Bottom row: navigation tabs */
.header-tabs {
    background: #0f0f0f;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    color: #fff;
}

.header-tabs-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0 1.5rem;
    overflow-x: auto;
    scrollbar-width: none;
}

.header-tabs-inner::-webkit-scrollbar { display: none; }

.tab-link svg {
    fill: currentcolor;
    height: 1.3em;
}

.tab-link {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0 0.6rem;
    height: 2.4rem;
    color: rgba(255,255,255,0.7);
    font-size: 0.9rem;
    font-weight: 400;
    text-decoration: none;
    border-bottom: 2px solid transparent;
    opacity: 0.7;
    transition: transform .4s cubic-bezier(.1,.7,.1,1), opacity .25s;
    white-space: nowrap;
}

.tab-link:hover {
    color: #fff;
    opacity: 1;
}

.tab-link.active {
    color: #fff;
    opacity: 1;
    border-bottom-color: var(--accent);
}

/* --- Container --- */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 1.5rem;
    flex: 1;
    width: 100%;
}

/* --- Hero --- */
.hero {
    padding: 2rem 0 1rem;
    text-align: center;
}

.hero h1 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

.hero-sub {
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 400;
}

/* --- Environment Card --- */
.env-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
}

.env-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    justify-content: center;
}

.env-item { text-align: center; }

.env-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.15rem;
}

.env-value {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-primary);
}

/* --- Summary Cards --- */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.summary-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: border-color var(--transition);
}

.summary-card:hover { border-color: var(--accent); }

.summary-card-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.summary-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text-primary);
}

.summary-card-detail {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: var(--font-mono);
}

.badge-green { background: var(--green-bg); color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-neutral { background: var(--bg-hover); color: var(--text-secondary); }

/* --- Chart Sections --- */
.chart-section {
    margin-bottom: 2.5rem;
}

.chart-section h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    min-height: 450px;
    overflow: hidden;
}

/* --- Module Tabs --- */
.module-tabs {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.tab {
    padding: .35rem .75rem;
    border: .1rem solid var(--border);
    border-radius: 0.25rem;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: color 125ms, background-color 125ms, border-color 125ms;
    text-transform: capitalize;
}

.tab:hover { color: var(--text-primary); border-color: var(--accent); }
.tab.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* --- Tables --- */
.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th {
    background: var(--bg-secondary);
    font-weight: 600;
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

th:hover { color: var(--text-primary); }

td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

tr:last-child td { border-bottom: none; }

tr:hover { background: var(--bg-hover); }

tr.row-improved { background: var(--green-bg); }
tr.row-regression { background: var(--red-bg); }

.sort-arrow { font-size: 0.65rem; margin-left: 0.25rem; opacity: 0.5; }
.sort-arrow.active { opacity: 1; }

/* --- Compare Page --- */
.compare-controls {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.select-group { flex: 1; min-width: 200px; }

.select-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: var(--font-mono);
    cursor: pointer;
}

.select:focus { outline: none; border-color: var(--accent); }

.compare-arrow {
    font-size: 1.5rem;
    color: var(--text-muted);
    padding-bottom: 0.25rem;
}

.btn-compare {
    padding: .625em 2em;
    background: var(--accent);
    color: #000;
    border: .1rem solid var(--accent);
    border-radius: 0.25rem;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: color 125ms, background-color 125ms, border-color 125ms;
}

.btn-compare:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #000;
}

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

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

/* --- About section (index.html) --- */
.about-section {
    margin-top: 3rem;
    padding: 2rem;
    border-radius: 0.75rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
}

.about-section h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text);
}

.about-content p {
    font-size: 0.9rem;
    line-height: 1.65;
    color: var(--muted);
    margin-bottom: 0.75rem;
}

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

.about-content a:hover {
    text-decoration: underline;
}

.about-author {
    color: var(--text) !important;
}

.about-links {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.about-links a {
    color: var(--muted);
    transition: color var(--transition);
}

.about-links a:hover {
    color: var(--accent);
}

/* --- Footer (always dark for logo readability) --- */
.footer {
    text-align: center;
    padding: 2.5rem 1.5rem;
    background: #0a0a0a;
    border-top: 1px solid rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.45);
    font-size: 0.8rem;
    margin-top: auto;
}

.footer a {
    color: #b0eb00;
}

.footer a:hover {
    color: #c8f530;
}

.footer-brand {
    margin-bottom: 1rem;
}

.footer-logo {
    height: 64px;
    width: auto;
    opacity: 0.85;
    transition: opacity var(--transition);
}

.footer-logo:hover {
    opacity: 1;
}

.footer-star {
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
}

.btn-star {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: .625em 2em;
    background: transparent;
    color: #b0eb00;
    border: .1rem solid #b0eb00;
    border-radius: 0.25rem;
    font-weight: 700;
    font-size: 0.9rem;
    line-height: 1.4;
    text-decoration: none;
    transition: color 125ms, background-color 125ms, border-color 125ms;
}

.btn-star:hover {
    background: #b0eb00;
    border-color: #b0eb00;
    color: #000;
}

.btn-star svg {
    flex-shrink: 0;
}

.footer-credit {
    margin-top: 0.4rem;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.6);
}

.footer-social {
    display: flex;
    justify-content: center;
    gap: 0.85rem;
    margin-top: 0.6rem;
}

.footer-social a {
    color: rgba(255,255,255,0.45);
    transition: color 150ms;
    display: inline-flex;
}

.footer-social a:hover {
    color: #b0eb00;
}

.footer-cite {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: rgba(255,255,255,0.4);
    font-style: italic;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .header-top-inner { padding: 0 1rem; }
    .header-tabs-inner { padding: 0 0.5rem; }
    .nav-title { font-size: 0.95rem; }
    .header-github-text { display: none; }
    .tab-link { padding: 0 0.4rem; height: 2rem; font-size: 0.8rem; }
    .hero h1 { font-size: 1.5rem; }
    .container { padding: 1rem; }
    .env-grid { gap: 1rem; }
    .compare-controls { flex-direction: column; }
    .compare-arrow { transform: rotate(90deg); text-align: center; }
    .section-header { flex-direction: column; align-items: flex-start; }
    .chart-container { min-height: 300px; padding: 0.5rem; }
}

@media (max-width: 480px) {
    .nav-version { display: none; }
    .summary-cards { grid-template-columns: 1fr 1fr; }
    .tab-link svg { display: none; }
}

/* --- Loading --- */
.loading {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    font-size: 1rem;
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.summary-card, .chart-section, .env-card {
    animation: fadeIn 0.3s ease forwards;
}

/* --- Scrollbar (dark theme) --- */
[data-theme="dark"] ::-webkit-scrollbar { width: 8px; height: 8px; }
[data-theme="dark"] ::-webkit-scrollbar-track { background: var(--bg-primary); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
