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

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

body {
    font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    color: #2c2418;
    background: #faf6f1;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a {
    color: #2c2418;
    text-decoration: underline;
    text-underline-offset: 2px;
}

a:hover {
    color: #d97757;
}

/* ─── Header ──────────────────────────────────────────────── */
.site-header {
    border-bottom: 1px solid #d4c8b8;
    padding: 1rem 2rem;
    background: #faf6f1;
}

.site-header nav {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-home {
    font-size: 0.875rem;
    text-decoration: none;
    color: #8c7e72;
}

.nav-home:hover {
    color: #2c2418;
}

.nav-title {
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #8c7e72;
}

/* ─── Hero ────────────────────────────────────────────────── */
.hero {
    text-align: center;
    padding: 5rem 2rem 4rem;
    border-bottom: 1px solid #d4c8b8;
}

.hero h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
    color: #2c2418;
}

.hero-subtitle {
    font-size: 1.125rem;
    color: #8c7e72;
    margin-bottom: 3rem;
}

.hero-stats {
    display: flex;
    justify-content: center;
    gap: 4rem;
    margin-bottom: 2rem;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-number {
    font-size: 2.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1;
    margin-bottom: 0.25rem;
    color: #2c2418;
}

.stat-number.accent {
    color: #d97757;
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #8c7e72;
}

/* ─── Filter Toggle ───────────────────────────────────────── */
.filter-toggle {
    display: flex;
    justify-content: center;
    gap: 0;
    margin-bottom: 1.5rem;
    border: 1px solid #d4c8b8;
    border-radius: 4px;
    overflow: hidden;
    display: inline-flex;
}

.filter-btn {
    padding: 0.5rem 1.25rem;
    font-size: 0.8125rem;
    font-family: inherit;
    font-weight: 500;
    background: #faf6f1;
    color: #8c7e72;
    border: none;
    border-right: 1px solid #d4c8b8;
    cursor: pointer;
    transition: all 0.15s;
}

.filter-btn:last-child {
    border-right: none;
}

.filter-btn:hover {
    background: #f0ebe4;
    color: #3a2e22;
}

.filter-btn.active {
    background: #2c2418;
    color: #faf6f1;
}

.filter-hint {
    color: #b0a594;
}

.hero-note {
    font-size: 0.8125rem;
    color: #b0a594;
}

.hero-note a {
    color: #8c7e72;
}

/* ─── Sections ────────────────────────────────────────────── */
.section {
    border-bottom: 1px solid #d4c8b8;
    padding: 4rem 2rem;
}

.section-content {
    max-width: 700px;
    margin: 0 auto;
}

.section-number {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.15em;
    color: #d4c8b8;
    margin-bottom: 0.75rem;
}

.section h2 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: 0.375rem;
    color: #2c2418;
}

.section-question {
    font-size: 1rem;
    color: #8c7e72;
    margin-bottom: 2rem;
}

/* ─── Charts ──────────────────────────────────────────────── */
.chart-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin: 0 auto 1.5rem;
}

.chart-container-wide {
    max-width: 700px;
}

.chart-container-tall {
    max-width: 650px;
}

canvas {
    width: 100% !important;
}

/* ─── Insights ────────────────────────────────────────────── */
.insight {
    font-size: 0.9375rem;
    color: #3a2e22;
    line-height: 1.7;
    padding: 1rem 0;
    border-top: 1px solid #e8e0d6;
    margin-top: 0.5rem;
}

/* ─── Champions Table ─────────────────────────────────────── */
.champions-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

.champions-table th {
    text-align: left;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #8c7e72;
    padding: 0.5rem 0.75rem;
    border-bottom: 2px solid #d4c8b8;
}

.champions-table th:last-child,
.champions-table td:last-child {
    text-align: right;
}

.champions-table td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid #e8e0d6;
    color: #2c2418;
}

.champions-table tr:hover {
    background: #f5f0e8;
}

.champions-table .rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
}

.rank-1 { background: #d97757; color: #fff; }
.rank-2 { background: #d4874a; color: #fff; }
.rank-3 { background: #b8652a; color: #fff; }
.rank-default { background: #e8e0d6; color: #3a2e22; }

.champions-table .pass-rate-bar {
    display: inline-block;
    height: 6px;
    border-radius: 3px;
    background: #6b7f5e;
    margin-right: 0.5rem;
    vertical-align: middle;
}

.champions-table .school-name {
    font-weight: 500;
}

.champions-table .school-code {
    color: #8c7e72;
    font-size: 0.75rem;
    margin-left: 0.25rem;
}

/* ─── Subject Category Groups ─────────────────────────────── */
.subject-groups {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.subject-group {
    border: 1px solid #e8e0d6;
    border-radius: 6px;
    overflow: hidden;
}

.subject-group-header {
    padding: 0.75rem 1rem;
    background: #f0ebe4;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #3a2e22;
    border-bottom: 1px solid #e8e0d6;
}

.subject-bar-row {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid #f0ebe4;
    font-size: 0.8125rem;
    gap: 0.75rem;
}

.subject-bar-row:last-child {
    border-bottom: none;
}

.subject-bar-name {
    width: 140px;
    flex-shrink: 0;
    color: #3a2e22;
    font-weight: 500;
}

.subject-bar-track {
    flex: 1;
    height: 20px;
    background: #e8e0d6;
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.subject-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.6s ease;
}

.subject-bar-value {
    width: 50px;
    text-align: right;
    font-weight: 600;
    flex-shrink: 0;
    font-size: 0.8125rem;
}

.subject-bar-enrollment {
    width: 70px;
    text-align: right;
    color: #8c7e72;
    font-size: 0.75rem;
    flex-shrink: 0;
}

/* ─── Anomalies ───────────────────────────────────────────── */
.anomaly-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.anomaly-card {
    border: 1px solid #e8e0d6;
    border-radius: 6px;
    padding: 1.25rem 1.5rem;
    background: #fff;
}

.anomaly-card .anomaly-icon {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
}

.anomaly-card h4 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: #2c2418;
    margin-bottom: 0.5rem;
}

.anomaly-card p {
    font-size: 0.8125rem;
    color: #3a2e22;
    line-height: 1.6;
}

.anomaly-card .anomaly-stat {
    font-size: 1.5rem;
    font-weight: 700;
    color: #d97757;
    display: block;
    margin: 0.5rem 0;
}

/* ─── School Search ───────────────────────────────────────── */
.search-wrapper {
    position: relative;
    max-width: 500px;
    margin: 0 auto 2rem;
}

#school-input {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    font-family: inherit;
    border: 2px solid #d4c8b8;
    border-radius: 4px;
    outline: none;
    transition: border-color 0.15s;
    background: #fff;
    color: #2c2418;
}

#school-input:focus {
    border-color: #d97757;
    background: #fff;
}

#school-input::placeholder {
    color: #b0a594;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #d4c8b8;
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 240px;
    overflow-y: auto;
    display: none;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(44, 36, 24, 0.08);
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: 0.625rem 1rem;
    cursor: pointer;
    font-size: 0.875rem;
    border-bottom: 1px solid #f0ebe4;
    color: #2c2418;
}

.search-result-item:hover {
    background: #f5f0e8;
}

.search-result-item .result-code {
    color: #8c7e72;
    font-size: 0.75rem;
    margin-right: 0.5rem;
}

/* ─── School Card ─────────────────────────────────────────── */
.school-card {
    max-width: 500px;
    margin: 0 auto;
    padding: 1.5rem;
    border: 1px solid #d4c8b8;
    border-radius: 6px;
    background: #fff;
}

.school-card.hidden {
    display: none;
}

.school-card h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e8e0d6;
    color: #2c2418;
}

.card-stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 1.25rem;
}

.card-stat {
    text-align: center;
}

.card-stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: #2c2418;
}

.card-stat-label {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #8c7e72;
}

.card-chart-container {
    margin-bottom: 1rem;
}

.card-comparison {
    font-size: 0.8125rem;
    color: #3a2e22;
    text-align: center;
}

/* ─── Footer ──────────────────────────────────────────────── */
footer {
    padding: 3rem 2rem;
    background: #f0ebe4;
    border-top: 1px solid #d4c8b8;
}

.footer-content {
    max-width: 700px;
    margin: 0 auto;
    text-align: center;
}

.footer-content p {
    font-size: 0.8125rem;
    color: #8c7e72;
    margin-bottom: 0.5rem;
}

.footer-content a {
    color: #3a2e22;
}

.footer-disclaimer {
    margin-top: 1rem;
    font-size: 0.75rem !important;
    color: #b0a594 !important;
}

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 640px) {
    .hero {
        padding: 3rem 1.5rem 2.5rem;
    }

    .hero h1 {
        font-size: 1.75rem;
    }

    .hero-stats {
        gap: 2rem;
    }

    .stat-number {
        font-size: 2rem;
    }

    .section {
        padding: 3rem 1.25rem;
    }

    .section h2 {
        font-size: 1.375rem;
    }

    .card-stats {
        flex-direction: column;
        gap: 0.75rem;
    }

    .subject-bar-name {
        width: 100px;
    }

    .subject-bar-enrollment {
        display: none;
    }

    .champions-table {
        font-size: 0.75rem;
    }
}
