:root {
    --bg: #f4efe6;
    --surface: rgba(255, 252, 246, 0.92);
    --surface-strong: #fffdf8;
    --text: #1f2937;
    --muted: #6b7280;
    --line: rgba(148, 163, 184, 0.22);
    --primary: #c2410c;
    --primary-dark: #7c2d12;
    --secondary: #0f766e;
    --shadow: 0 24px 60px rgba(120, 53, 15, 0.12);
    --radius-xl: 28px;
    --radius-lg: 20px;
    --radius-md: 14px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text);
    overflow-x: hidden;
    background:
        radial-gradient(circle at top left, rgba(251, 191, 36, 0.28), transparent 26%),
        radial-gradient(circle at top right, rgba(20, 184, 166, 0.18), transparent 22%),
        linear-gradient(160deg, #fff8ef 0%, #f7efe2 54%, #f3eadb 100%);
}

.page {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 36px 0 48px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 24px;
    margin-bottom: 24px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text);
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary) 0%, #ea580c 100%);
    color: #fff;
    font-weight: 800;
    box-shadow: 0 10px 24px rgba(194, 65, 12, 0.18);
}

.brand-text {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 0.01em;
}

.menu {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.menu-link {
    padding: 10px 16px;
    border-radius: 999px;
    text-decoration: none;
    color: var(--muted);
    font-weight: 700;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.menu-link:hover,
.menu-link.active {
    background: rgba(255, 237, 213, 0.92);
    color: var(--primary-dark);
    transform: translateY(-1px);
}

.hero {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 24px;
    align-items: stretch;
    margin-bottom: 24px;
}

.hero > *,
.layout > *,
.stack > * {
    min-width: 0;
}

.panel {
    background: var(--surface);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.65);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
}

.hero-card {
    padding: 34px;
    overflow: hidden;
    position: relative;
}

.hero-card::after {
    content: "";
    position: absolute;
    inset: auto -40px -40px auto;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(194, 65, 12, 0.14), transparent 70%);
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(255, 237, 213, 0.9);
    color: var(--primary-dark);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

h1 {
    margin: 18px 0 12px;
    font-size: clamp(32px, 4vw, 52px);
    line-height: 1.05;
}

.hero-copy {
    margin: 0;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.75;
    max-width: 620px;
}

.stats {
    margin-top: 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.stat-chip {
    padding: 12px 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.9);
    font-weight: 600;
}

.search-card {
    padding: 28px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.section-title {
    margin: 0 0 8px;
    font-size: 24px;
}

.section-subtitle {
    margin: 0 0 20px;
    color: var(--muted);
    line-height: 1.6;
}

.search-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 14px;
}

input, select, button {
    border: 0;
    outline: none;
    font: inherit;
}

input, select {
    width: 100%;
    padding: 15px 18px;
    border-radius: 16px;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

input:focus, select:focus {
    border-color: rgba(194, 65, 12, 0.45);
    box-shadow: 0 0 0 4px rgba(194, 65, 12, 0.1);
    transform: translateY(-1px);
}

button {
    padding: 15px 22px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--primary) 0%, #ea580c 100%);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    box-shadow: 0 16px 28px rgba(194, 65, 12, 0.2);
}

button:hover {
    transform: translateY(-2px);
}

button:disabled {
    opacity: 0.7;
    cursor: wait;
    transform: none;
}

.hint {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
}

.layout {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 24px;
    align-items: start;
}

.stack {
    display: grid;
    gap: 24px;
}

.content-stack {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
}

.card {
    padding: 26px;
}

.result-empty {
    padding: 18px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.68);
    color: var(--muted);
    text-align: center;
    border: 1px dashed rgba(148, 163, 184, 0.35);
}

.student-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.student-name {
    margin: 0;
    font-size: 26px;
}

.student-meta {
    margin: 8px 0 0;
    color: var(--muted);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(15, 118, 110, 0.1);
    color: var(--secondary);
    font-weight: 700;
}

.score-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.score-chip {
    min-width: 120px;
    padding: 14px 16px;
    border-radius: 18px;
    background: var(--surface-strong);
    border: 1px solid rgba(148, 163, 184, 0.16);
}

.score-chip strong,
.rank-card strong {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.score-chip span {
    font-size: 24px;
    font-weight: 800;
    color: var(--primary-dark);
}

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

.rank-card {
    padding: 18px;
    border-radius: 20px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 247, 237, 0.98));
    border: 1px solid rgba(251, 146, 60, 0.18);
}

.rank-score {
    font-size: 28px;
    font-weight: 800;
    color: var(--primary-dark);
    margin-bottom: 10px;
}

.rank-meta {
    color: var(--muted);
    line-height: 1.65;
    font-size: 14px;
}

.control-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 12px;
    margin-bottom: 18px;
}

.ranking-summary {
    margin-bottom: 14px;
    color: var(--primary-dark);
    font-weight: 700;
}

.table-wrap {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    border-radius: 22px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(255, 255, 255, 0.72);
}

table {
    width: 100%;
    min-width: 640px;
    border-collapse: collapse;
}

th, td {
    padding: 16px 14px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
    text-align: left;
    vertical-align: top;
}

th {
    background: rgba(255, 247, 237, 0.96);
    font-size: 13px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--primary-dark);
}

tbody tr:hover {
    background: rgba(255, 251, 235, 0.75);
}

tbody tr:last-child td {
    border-bottom: 0;
}

.rank-index {
    width: 72px;
    font-weight: 800;
    color: var(--primary-dark);
}

.student-cell {
    min-width: 150px;
}

.student-cell strong {
    display: block;
    font-size: 16px;
    margin-bottom: 6px;
}

.muted {
    color: var(--muted);
}

.subject-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 260px;
}

.subject-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.14);
    font-size: 14px;
}

.subject-pill b {
    color: var(--primary-dark);
}

.score-highlight {
    font-size: 20px;
    font-weight: 800;
    color: var(--secondary);
}

.status {
    color: var(--muted);
    font-size: 14px;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: center;
    margin-top: 16px;
}

.pagination-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

.page-button {
    min-width: 44px;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(255, 255, 255, 0.92);
    color: var(--text);
    box-shadow: none;
}

.page-button.active {
    background: linear-gradient(135deg, var(--primary) 0%, #ea580c 100%);
    color: #fff;
    border-color: transparent;
}

.page-button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.page-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    color: var(--muted);
    font-weight: 700;
}

.contact-hero {
    padding: 34px;
    margin-bottom: 24px;
}

.contact-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
}

.region-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
}

.region-card {
    padding: 26px;
}

.region-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.region-title {
    margin-top: 12px;
}

.region-count {
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(15, 118, 110, 0.1);
    color: var(--secondary);
    font-weight: 700;
    white-space: nowrap;
}

.region-province-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.region-province-item {
    display: inline-flex;
    align-items: center;
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(148, 163, 184, 0.18);
    color: var(--text);
    font-weight: 600;
}

.contact-card {
    display: block;
    padding: 28px;
    text-decoration: none;
    color: var(--text);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.contact-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 24px 48px rgba(120, 53, 15, 0.14);
    border-color: rgba(194, 65, 12, 0.2);
}

.contact-card strong {
    display: block;
    margin-bottom: 10px;
    font-size: 24px;
}

.contact-card p {
    margin: 0 0 18px;
    color: var(--muted);
    line-height: 1.7;
}

.contact-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(255, 237, 213, 0.92);
    color: var(--primary-dark);
    font-weight: 700;
}

.log-login,
.log-viewer {
    padding: 30px;
}

.log-form {
    display: flex;
    gap: 12px;
    margin-top: 18px;
}

.log-error {
    margin-top: 16px;
    padding: 14px 16px;
    border-radius: 14px;
    background: rgba(239, 68, 68, 0.1);
    color: #b91c1c;
    font-weight: 600;
}

.log-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.log-list {
    display: grid;
    gap: 12px;
}

.log-item {
    padding: 16px 18px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(148, 163, 184, 0.16);
    font-family: Consolas, "Courier New", monospace;
    line-height: 1.7;
    word-break: break-word;
}

@media (max-width: 980px) {
    .hero,
    .layout,
    .contact-grid,
    .region-grid {
        grid-template-columns: 1fr;
    }

    .table-wrap .subject-inline {
        width: 100%;
        min-width: 0;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .table-wrap .subject-pill {
        width: 100%;
        max-width: none;
        min-width: 0;
        justify-content: space-between;
    }
}

@media (max-width: 640px) {
    .page {
        width: min(100% - 20px, 100%);
        padding-top: 20px;
    }

    .hero-card,
    .search-card,
    .card,
    .contact-hero,
    .contact-card,
    .region-card,
    .log-login,
    .log-viewer {
        padding: 20px;
    }

    .search-bar {
        flex-direction: column;
    }

    .log-form,
    .log-header,
    .region-card-head {
        flex-direction: column;
    }

    .control-row {
        grid-template-columns: 1fr;
    }

    .student-header {
        align-items: stretch;
    }

    .topbar {
        padding: 16px 18px;
        flex-direction: column;
        align-items: flex-start;
    }

    .section-title {
        font-size: 22px;
    }

    .section-subtitle,
    .hero-copy,
    .hint {
        font-size: 14px;
    }

    .score-row {
        gap: 10px;
    }

    .score-chip {
        min-width: 0;
        width: calc(50% - 5px);
        max-width: calc(50% - 5px);
        flex: 0 0 calc(50% - 5px);
        padding: 12px 14px;
    }

    .score-chip span {
        font-size: 20px;
    }

    .rank-grid {
        grid-template-columns: 1fr;
    }

    .rank-card {
        padding: 16px;
    }

    .rank-score {
        font-size: 24px;
    }

    .student-cell,
    .subject-inline {
        min-width: 0;
    }

    .table-wrap .subject-pill {
        font-size: 13px;
    }

    .table-wrap {
        margin: 0 -4px;
        border-radius: 18px;
    }

    table {
        min-width: 560px;
    }

    th,
    td {
        padding: 12px 10px;
        font-size: 13px;
    }

    .rank-index {
        width: 58px;
    }
}
