/* ============================================
   SNNU Grade Query - Unified Design System
   ============================================ */

/* === CSS Custom Properties === */
:root {
    --primary: #FF6B35;
    --primary-dark: #E85A2B;
    --primary-light: #FFF0EB;
    --secondary: #004E89;
    --secondary-light: #E8F0F8;
    --accent: #1A936F;
    --accent-light: #E6F5F0;

    --bg-start: #FDF2EE;
    --bg-end: #EBF2F8;

    --surface: rgba(255, 255, 255, 0.78);
    --surface-solid: #FFFFFF;
    --surface-hover: rgba(255, 255, 255, 0.92);

    --text: #1A1A2E;
    --text-secondary: #4A4A5A;
    --text-muted: #8B8FA3;

    --border: rgba(0, 0, 0, 0.06);
    --border-light: rgba(255, 255, 255, 0.6);

    --success: #10B981;
    --success-bg: #ECFDF5;
    --error: #EF4444;
    --error-bg: #FEF2F2;
    --warning: #F59E0B;
    --warning-bg: #FFFBEB;
    --info: #3B82F6;
    --info-bg: #EFF6FF;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 100px;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 24px 64px rgba(0, 0, 0, 0.12);

    --glass-blur: 24px;
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms ease;
    --transition-spring: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html {
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 100%);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* === Animated Background Orbs === */
.bg-aurora {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    will-change: transform;
}

.bg-orb-1 {
    width: 450px;
    height: 450px;
    background: rgba(255, 107, 53, 0.2);
    top: -12%;
    right: -8%;
    animation: orbFloat1 22s ease-in-out infinite;
}

.bg-orb-2 {
    width: 380px;
    height: 380px;
    background: rgba(0, 78, 137, 0.15);
    bottom: -10%;
    left: -6%;
    animation: orbFloat2 26s ease-in-out infinite;
}

.bg-orb-3 {
    width: 320px;
    height: 320px;
    background: rgba(26, 147, 111, 0.12);
    top: 45%;
    left: 50%;
    transform: translateX(-50%);
    animation: orbFloat3 20s ease-in-out infinite;
}

@keyframes orbFloat1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(-30px, 40px) scale(1.08); }
    50% { transform: translate(20px, -20px) scale(0.95); }
    75% { transform: translate(-15px, -30px) scale(1.03); }
}

@keyframes orbFloat2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(40px, -25px) scale(0.96); }
    50% { transform: translate(-20px, 35px) scale(1.06); }
    75% { transform: translate(25px, 15px) scale(0.98); }
}

@keyframes orbFloat3 {
    0%, 100% { transform: translateX(-50%) translate(0, 0) scale(1); }
    33% { transform: translateX(-50%) translate(25px, -35px) scale(1.04); }
    66% { transform: translateX(-50%) translate(-30px, 20px) scale(0.97); }
}

/* === Layout === */
.page-wrapper {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.page-wrapper--top {
    align-items: flex-start;
    padding-top: 40px;
    padding-bottom: 40px;
}

.container {
    width: 100%;
    max-width: 500px;
}

.container--wide {
    max-width: 920px;
}

/* === Glassmorphism Card === */
.card {
    background: var(--surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-light);
    padding: 40px 36px;
    box-shadow: var(--shadow-lg);
    transition: box-shadow var(--transition-base);
}

.card:hover {
    box-shadow: var(--shadow-xl);
}

.card--compact {
    padding: 28px 24px;
}

/* === Header Badge === */
.header-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--primary);
    color: white;
    padding: 8px 18px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 24px;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
    text-transform: uppercase;
}

.header-badge::before {
    content: '';
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
    animation: badgePulse 2s ease-in-out infinite;
}

@keyframes badgePulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.85); }
}

/* === Typography === */
.title {
    font-size: 28px;
    font-weight: 900;
    color: var(--text);
    line-height: 1.3;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 32px;
    line-height: 1.5;
}

.section-title {
    font-size: 18px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title::before {
    content: '';
    width: 4px;
    height: 22px;
    background: var(--primary);
    border-radius: 2px;
    flex-shrink: 0;
}

/* === Form Components === */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 8px;
    letter-spacing: 0.3px;
}

.input-wrapper {
    position: relative;
}

.form-input {
    width: 100%;
    padding: 14px 16px 14px 46px;
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    background: rgba(0, 0, 0, 0.03);
    transition: all var(--transition-base);
    outline: none;
}

.form-input:hover {
    background: rgba(0, 0, 0, 0.04);
}

.form-input:focus {
    border-color: var(--primary);
    background: var(--surface-solid);
    box-shadow: 0 0 0 4px rgba(255, 107, 53, 0.1);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    color: var(--text-muted);
    pointer-events: none;
    transition: color var(--transition-base);
    line-height: 1;
}

.form-input:focus ~ .input-icon {
    color: var(--primary);
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* === Button Components === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 16px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
    position: relative;
    overflow: hidden;
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 16px rgba(255, 107, 53, 0.3);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    box-shadow: 0 6px 20px rgba(255, 107, 53, 0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--secondary);
    color: white;
    box-shadow: 0 4px 16px rgba(0, 78, 137, 0.25);
}

.btn-secondary:hover:not(:disabled) {
    box-shadow: 0 6px 20px rgba(0, 78, 137, 0.35);
    transform: translateY(-1px);
}

.btn-accent {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 16px rgba(26, 147, 111, 0.25);
}

.btn-accent:hover:not(:disabled) {
    box-shadow: 0 6px 20px rgba(26, 147, 111, 0.35);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--error);
    color: white;
    box-shadow: 0 4px 16px rgba(239, 68, 68, 0.25);
}

.btn-danger:hover:not(:disabled) {
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.35);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    box-shadow: none;
    border: 2px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.03);
    color: var(--text);
    border-color: rgba(0, 0, 0, 0.12);
}

.btn-sm {
    padding: 10px 18px;
    font-size: 13px;
    border-radius: var(--radius-sm);
}

/* === Info Grid === */
.info-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.info-box {
    background: rgba(0, 0, 0, 0.03);
    padding: 16px 12px;
    border-radius: var(--radius-md);
    text-align: center;
    transition: background var(--transition-base);
}

.info-box:hover {
    background: rgba(0, 0, 0, 0.05);
}

.info-box-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.info-box-value {
    font-size: 15px;
    font-weight: 800;
    color: var(--text);
}

/* === Score Components === */
.scores-list {
    display: grid;
    gap: 8px;
}

.score-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--secondary);
    transition: all var(--transition-base);
}

.score-item:hover {
    background: rgba(0, 0, 0, 0.04);
    transform: translateX(4px);
}

.score-subject {
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
}

.score-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.score-value {
    font-size: 18px;
    font-weight: 800;
}

.average-box {
    margin-top: 16px;
    padding: 22px 24px;
    background: var(--text);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.average-label {
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;
    font-weight: 600;
}

.average-value {
    color: white;
    font-size: 28px;
    font-weight: 900;
}

/* === Divider === */
.divider {
    height: 0;
    border: none;
    border-top: 2px dashed rgba(0, 0, 0, 0.06);
    margin: 32px 0;
}

/* === Result Header === */
.result-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
}

.result-icon {
    width: 48px;
    height: 48px;
    background: var(--accent);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 4px 12px rgba(26, 147, 111, 0.2);
}

.result-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--text);
}

/* === Toast Notifications === */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: toastIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    max-width: 380px;
    min-width: 280px;
}

.toast--exit {
    animation: toastOut 0.3s ease forwards;
}

.toast-success {
    background: rgba(236, 253, 245, 0.95);
    color: #065F46;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.toast-error {
    background: rgba(254, 242, 242, 0.95);
    color: #991B1B;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.toast-warning {
    background: rgba(255, 251, 235, 0.95);
    color: #92400E;
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.toast-info {
    background: rgba(239, 246, 255, 0.95);
    color: #1E40AF;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(40px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(40px) scale(0.95);
    }
}

/* === Loading Spinner === */
.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(0, 0, 0, 0.08);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

.spinner--white {
    border-color: rgba(255, 255, 255, 0.25);
    border-top-color: white;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Entrance Animations === */
.fade-up {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.fade-up.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger children with CSS custom property */
.stagger > .fade-up {
    transition-delay: calc(var(--i, 0) * 60ms);
}

/* === Modal / Dialog === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--surface-solid);
    border-radius: var(--radius-xl);
    padding: 36px;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow-xl);
    transform: scale(0.92) translateY(12px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-title {
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 12px;
}

.modal-text {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 28px;
}

.modal-actions {
    display: flex;
    gap: 12px;
}

.modal-actions .btn {
    flex: 1;
}

/* === Progress Bar === */
.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin: 16px 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: var(--radius-full);
    transition: width 0.5s ease;
    min-width: 0;
}

/* === Status Badge === */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 700;
}

.status-pill--active {
    background: var(--success-bg);
    color: var(--success);
}

.status-pill--idle {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-muted);
}

/* === Footer === */
.footer {
    text-align: center;
    margin-top: 28px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
}

.footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.footer a:hover {
    text-decoration: underline;
}

/* === Back Link === */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 20px;
    transition: color var(--transition-fast);
}

.back-link:hover {
    color: var(--primary);
}

/* === Ranking Components === */
.rank-badge-large {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--text);
    color: white;
    padding: 16px 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.rank-number {
    font-size: 36px;
    font-weight: 900;
    line-height: 1;
}

.rank-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.6;
}

.ranking-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 40px;
}

.ranking-card {
    background: rgba(0, 0, 0, 0.02);
    border-radius: var(--radius-lg);
    padding: 24px;
    position: relative;
    overflow: hidden;
    transition: all var(--transition-base);
    border: 1px solid transparent;
}

.ranking-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    background: rgba(0, 0, 0, 0.03);
    border-color: var(--border);
}

.ranking-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
}

.subject-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.subject-name {
    font-size: 16px;
    font-weight: 800;
    color: var(--text);
}

.rank-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 800;
}

.rank-pill-1 { background: #FEF3C7; color: #92400E; }
.rank-pill-2 { background: #F3F4F6; color: #4B5563; }
.rank-pill-3 { background: #FED7AA; color: #9A3412; }
.rank-pill-other { background: var(--surface-solid); color: var(--text-muted); border: 1px solid rgba(0,0,0,0.06); }

.score-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.score-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.score-label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
}

/* === Total Section === */
.total-section {
    background: var(--text);
    border-radius: var(--radius-xl);
    padding: 32px;
    color: white;
}

.total-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.total-title { font-size: 20px; font-weight: 800; }

.total-rank {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.12);
    padding: 8px 16px;
    border-radius: var(--radius-full);
    font-weight: 800;
    font-size: 14px;
}

.total-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.total-item {
    text-align: center;
    padding: 18px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    transition: background var(--transition-base);
}

.total-item:hover {
    background: rgba(255, 255, 255, 0.13);
}

.total-item-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.5;
    margin-bottom: 6px;
}

.total-item-value {
    font-size: 24px;
    font-weight: 900;
}

/* === Edit Page Components === */
.polling-status {
    padding: 24px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: var(--radius-lg);
    margin-top: 24px;
}

.student-card {
    display: flex;
    gap: 16px;
    padding: 20px;
    background: var(--surface-solid);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    box-shadow: var(--shadow-xs);
}

.student-card-item {
    flex: 1;
    text-align: center;
}

.student-card-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.student-card-value {
    font-size: 17px;
    font-weight: 700;
}

.score-input-area {
    padding: 20px;
    background: var(--surface-solid);
    border-radius: var(--radius-md);
    border: 2px solid rgba(0, 0, 0, 0.04);
}

.score-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

.score-actions .btn {
    flex: 1;
}

/* === Responsive === */
@media (max-width: 768px) {
    .page-wrapper {
        padding: 16px;
    }

    .card {
        padding: 28px 22px;
    }

    .title {
        font-size: 24px;
    }

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

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

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

    .rank-number {
        font-size: 28px;
    }

    .rank-badge-large {
        padding: 12px 18px;
    }

    .toast-container {
        top: 12px;
        right: 12px;
        left: 12px;
    }

    .toast {
        max-width: 100%;
        min-width: 0;
    }

    .modal {
        padding: 28px;
    }

    .modal-actions {
        flex-direction: column-reverse;
    }

    .student-card {
        flex-direction: column;
        gap: 12px;
    }

    .score-actions {
        flex-direction: column;
    }

    .bg-orb-1 { width: 280px; height: 280px; }
    .bg-orb-2 { width: 240px; height: 240px; }
    .bg-orb-3 { width: 200px; height: 200px; }
}

@media (max-width: 480px) {
    .card {
        padding: 24px 18px;
        border-radius: var(--radius-lg);
    }

    .info-grid-3 {
        grid-template-columns: 1fr;
    }
}

/* Info grid with explicit column count */
.info-grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 768px) {
    .info-grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .info-grid-4 {
        grid-template-columns: 1fr;
    }
}
