/* ============================================================
   STUDYHUB — GLOBAL STYLE
   StudyHub — zamonaviy ta'lim platformasi bo'lib, testlar, battle,
   turnirlar va reyting tizimi orqali o'quvchilarning bilimini
   qiziqarli usulda rivojlantirishga yordam beradi.
   Glassmorphism, Dark/Light mode, Responsive, Animatsiyalar
   ============================================================ */

:root {
    --bg-primary: #0f1123;
    --bg-secondary: #171a35;
    --text-primary: #f1f2f9;
    --text-secondary: #a6a9c8;
    --accent: #7c5cff;
    --accent-2: #ff5ca8;
    --success: #35d68f;
    --danger: #ff5c6c;
    --glass-bg: rgba(255, 255, 255, 0.06);
    --glass-border: rgba(255, 255, 255, 0.12);
}

body.theme-light {
    --bg-primary: #f4f5fb;
    --bg-secondary: #ffffff;
    --text-primary: #1c1e33;
    --text-secondary: #5c5f7d;
    --glass-bg: rgba(255, 255, 255, 0.55);
    --glass-border: rgba(28, 30, 51, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: radial-gradient(circle at top left, var(--bg-secondary), var(--bg-primary));
    background-size: 180% 180%;
    color: var(--text-primary);
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
    transition: background 0.4s ease, color 0.4s ease;
    animation: bgDrift 18s ease-in-out infinite alternate;
}

/* ---------------- FLOATING BACKGROUND BLOBS ---------------- */
.bg-blobs {
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: -1;
    pointer-events: none;
}
.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(70px);
    opacity: 0.35;
    animation: floatBlob 16s ease-in-out infinite;
}
.blob-1 {
    width: 420px; height: 420px;
    top: -100px; left: -80px;
    background: var(--accent);
    animation-duration: 20s;
}
.blob-2 {
    width: 360px; height: 360px;
    bottom: -120px; right: -60px;
    background: var(--accent-2);
    animation-duration: 24s;
    animation-delay: -6s;
}
.blob-3 {
    width: 280px; height: 280px;
    top: 40%; left: 60%;
    background: var(--success);
    animation-duration: 18s;
    animation-delay: -3s;
    opacity: 0.2;
}

.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 18px;
    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.25s ease, border-color 0.25s ease;
}

.gradient-text {
    background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--accent));
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: shimmer 4s linear infinite;
}

/* ============================================================
   ANIMATSIYALAR — KEYFRAMES VA UTILITY KLASSLAR
   ============================================================ */
@keyframes bgDrift {
    0%   { background-position: 0% 0%; }
    100% { background-position: 100% 100%; }
}
@keyframes floatBlob {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33%      { transform: translate(30px, -40px) scale(1.08); }
    66%      { transform: translate(-25px, 25px) scale(0.94); }
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInLeft {
    from { opacity: 0; transform: translateX(-24px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}
@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(124, 92, 255, 0.4); }
    50%      { box-shadow: 0 0 0 10px rgba(124, 92, 255, 0); }
}
@keyframes shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
@keyframes popIn {
    0%   { transform: scale(0.85); opacity: 0; }
    60%  { transform: scale(1.03); opacity: 1; }
    100% { transform: scale(1); }
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
@keyframes countPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.15); }
}
@keyframes ripple {
    from { transform: scale(0); opacity: 0.5; }
    to   { transform: scale(2.5); opacity: 0; }
}

.fade-in-up   { animation: fadeInUp 0.7s cubic-bezier(0.22, 1, 0.36, 1) both; }
.fade-in-down { animation: fadeInDown 0.6s cubic-bezier(0.22, 1, 0.36, 1) both; }
.fade-in-left { animation: fadeInLeft 0.6s cubic-bezier(0.22, 1, 0.36, 1) both; }
.question-pop { animation: fadeInScale 0.45s cubic-bezier(0.22, 1, 0.36, 1) both; }

.stagger-item {
    opacity: 0;
    animation: fadeInUp 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.stagger-item:nth-child(1) { animation-delay: 0.05s; }
.stagger-item:nth-child(2) { animation-delay: 0.15s; }
.stagger-item:nth-child(3) { animation-delay: 0.25s; }
.stagger-item:nth-child(4) { animation-delay: 0.35s; }
.stagger-item:nth-child(5) { animation-delay: 0.45s; }
.stagger-item:nth-child(6) { animation-delay: 0.55s; }
.stagger-item:nth-child(n+7) { animation-delay: 0.6s; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

/* ---------------- BUTTONS ---------------- */
.btn {
    position: relative;
    overflow: hidden;
    border: none;
    border-radius: 12px;
    padding: 12px 22px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.2s ease, opacity 0.15s ease, background 0.3s ease;
}
.btn::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 8px; height: 8px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
    pointer-events: none;
}
.btn:active::after {
    animation: ripple 0.5s ease-out;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(0.97); }
.btn-primary { background: linear-gradient(90deg, var(--accent), var(--accent-2)); background-size: 200% auto; color: white; }
.btn-primary:hover { background-position: right center; box-shadow: 0 8px 24px rgba(124, 92, 255, 0.35); }
.btn-ghost { background: var(--glass-bg); color: var(--text-primary); border: 1px solid var(--glass-border); }
.btn-ghost:hover { border-color: var(--accent); box-shadow: 0 6px 16px rgba(124, 92, 255, 0.15); }
.btn-block { width: 100%; }
.btn-lg { padding: 16px 32px; font-size: 17px; animation: pulseGlow 2.5s ease-in-out infinite; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ---------------- NAVBAR / LANDING ---------------- */
.navbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 40px; margin: 16px; position: sticky; top: 16px; z-index: 50;
}
.nav-logo { font-size: 22px; font-weight: 800; display: flex; align-items: center; gap: 8px; transition: transform 0.2s ease; }
.nav-logo:hover { transform: scale(1.04); }
.nav-actions { display: flex; gap: 12px; }

.hero { text-align: center; padding: 90px 20px 60px; }
.hero-content h1 { font-size: 48px; margin-bottom: 20px; }
.hero-content p { color: var(--text-secondary); max-width: 600px; margin: 0 auto 30px; font-size: 17px; }

.features {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px; padding: 20px 40px 80px; max-width: 1100px; margin: 0 auto;
}
.feature-card { padding: 28px; text-align: center; }
.feature-card:hover { transform: translateY(-6px); box-shadow: 0 16px 32px rgba(0, 0, 0, 0.18); border-color: var(--accent); }
.feature-icon { font-size: 36px; margin-bottom: 12px; display: inline-block; transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1); }
.feature-card:hover .feature-icon { transform: scale(1.2) rotate(-6deg); }
.feature-card h3 { margin-bottom: 8px; }
.feature-card p { color: var(--text-secondary); font-size: 14px; }

/* ---------------- MODALS ---------------- */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    align-items: center; justify-content: center; z-index: 100; padding: 20px;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.modal-overlay.active { display: flex; opacity: 1; }
.modal {
    padding: 32px; width: 100%; max-width: 400px; position: relative;
    animation: popIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.modal h2 { margin-bottom: 20px; }
.modal-close {
    position: absolute; top: 16px; right: 16px; background: none; border: none;
    color: var(--text-primary); font-size: 24px; cursor: pointer;
    transition: transform 0.2s ease, color 0.2s ease;
}
.modal-close:hover { transform: rotate(90deg); color: var(--danger); }
.modal form { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; gap: 12px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; }

input, select, textarea {
    background: var(--bg-secondary); border: 1px solid var(--glass-border);
    color: var(--text-primary); border-radius: 10px; padding: 12px 14px; font-size: 14px;
    width: 100%; font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.18);
    transform: translateY(-1px);
}

/* ---------------- GOOGLE LOGIN ---------------- */
.divider {
    display: flex; align-items: center; gap: 12px;
    margin: 18px 0; color: var(--text-secondary); font-size: 13px;
}
.divider::before, .divider::after {
    content: ''; flex: 1; height: 1px; background: var(--glass-border);
}
.google-btn-slot {
    display: flex; justify-content: center;
    animation: fadeInUp 0.5s ease both;
}

/* ---------------- APP LAYOUT ---------------- */
.app-layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px; margin: 16px; padding: 24px 16px; display: flex; flex-direction: column;
    gap: 6px; position: sticky; top: 16px; height: calc(100vh - 32px);
}
.side-nav { display: flex; flex-direction: column; gap: 6px; margin-top: 24px; }
.side-link {
    background: none; border: none; color: var(--text-secondary); text-align: left;
    padding: 12px 14px; border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 500;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease, padding-left 0.2s ease;
}
.side-link:hover { background: var(--glass-bg); color: var(--text-primary); padding-left: 20px; }
.side-link.active { background: var(--glass-bg); color: var(--text-primary); box-shadow: inset 3px 0 0 var(--accent); }
.side-link.logout { margin-top: auto; color: var(--danger); }

.main-content { flex: 1; padding: 16px 24px 40px; }

.top-bar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 24px; margin-bottom: 24px;
}
.user-badge { display: flex; align-items: center; gap: 12px; }
.avatar-sm { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; transition: transform 0.25s ease; }
.avatar-sm:hover { transform: scale(1.1) rotate(-4deg); }
.avatar-lg { width: 90px; height: 90px; border-radius: 50%; object-fit: cover; margin-bottom: 12px; border: 3px solid var(--accent); animation: fadeInScale 0.5s ease both; }
.user-stats-mini { display: flex; gap: 16px; font-size: 14px; color: var(--text-secondary); }
.user-stats-mini span { transition: transform 0.2s ease; display: inline-block; }
.user-stats-mini span:hover { transform: translateY(-2px) scale(1.05); }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeInUp 0.4s ease both; }
.subtitle { color: var(--text-secondary); margin-bottom: 20px; }

/* ---------------- SUBJECT GRID ---------------- */
.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.subject-card { padding: 24px; text-align: center; cursor: pointer; transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.25s ease; }
.subject-card:hover { transform: translateY(-6px) scale(1.03); border-color: var(--accent); box-shadow: 0 14px 28px rgba(124, 92, 255, 0.25); }
.subject-icon { font-size: 32px; margin-bottom: 8px; transition: transform 0.3s ease; }
.subject-card:hover .subject-icon { transform: scale(1.15) rotate(6deg); }
.subject-icon.big { font-size: 56px; }
.subject-name { font-weight: 600; font-size: 14px; }

/* ---------------- PROFILE ---------------- */
.profile-card { padding: 32px; text-align: center; max-width: 420px; }
.profile-stat-row { display: flex; justify-content: space-around; margin-top: 20px; }
.profile-stat-row div { display: flex; flex-direction: column; }
.profile-stat-row strong { font-size: 20px; }
.profile-stat-row span { color: var(--text-secondary); font-size: 12px; }

/* ---------------- TIER BADGES ---------------- */
.tier-badge { padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; transition: transform 0.2s ease; display: inline-block; }
.tier-badge:hover { transform: scale(1.08); }
.tier-bronze { background: #7a5230; color: #fff; }
.tier-silver { background: #8a8f9c; color: #fff; }
.tier-gold { background: #d4a828; color: #1c1e33; }
.tier-platinum { background: #6fd7c8; color: #1c1e33; }
.tier-diamond { background: #5cc4ff; color: #1c1e33; }
.tier-master { background: #a15cff; color: #fff; }
.tier-grandmaster { background: #ff5c6c; color: #fff; }
.tier-legend {
    background: linear-gradient(90deg, #ffd15c, #ff5ca8, #7c5cff, #ffd15c);
    background-size: 300% auto;
    color: #1c1e33;
    animation: shimmer 3s linear infinite;
}

.badge { padding: 3px 10px; border-radius: 20px; font-size: 11px; background: var(--glass-bg); border: 1px solid var(--glass-border); transition: transform 0.2s ease; }

/* ---------------- LISTS ---------------- */
.list-panel { padding: 12px; max-height: 480px; overflow-y: auto; }
.list-row {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 12px 14px; border-bottom: 1px solid var(--glass-border); font-size: 14px; flex-wrap: wrap;
    transition: background 0.2s ease, padding-left 0.2s ease;
    border-radius: 10px;
}
.list-row:hover { background: var(--glass-bg); padding-left: 18px; }
.list-row:last-child { border-bottom: none; }
.rank { font-weight: 700; color: var(--accent); }

.add-friend-row { display: flex; gap: 10px; margin-bottom: 16px; max-width: 420px; }

/* ---------------- SETTINGS ---------------- */
.settings-card { padding: 24px; margin-bottom: 16px; max-width: 420px; display: flex; flex-direction: column; gap: 12px; }
.settings-card:hover { box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12); }
.theme-toggle { display: flex; gap: 10px; }

/* ---------------- STATS ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 16px; max-width: 700px; }
.stat-box { padding: 24px; text-align: center; transition: transform 0.25s ease; }
.stat-box:hover { transform: translateY(-4px); }
.stat-box strong { font-size: 26px; display: block; }
.stat-box span { color: var(--text-secondary); font-size: 13px; }

/* ---------------- BATTLE ---------------- */
.battle-wrap { max-width: 700px; margin: 40px auto; padding: 0 16px; }
.battle-intro { padding: 50px 30px; text-align: center; }
.battle-intro .subject-icon.big { animation: floatBlob 6s ease-in-out infinite; display: inline-block; }
.battle-intro p { color: var(--text-secondary); margin: 16px 0 24px; }
.battle-intro .btn { margin: 6px; }

.battle-countdown { display: flex; align-items: center; justify-content: center; height: 60vh; }
.countdown-number { font-size: 120px; font-weight: 800; color: var(--accent); animation: countPulse 1s ease-in-out infinite; }

.battle-topbar { display: flex; justify-content: space-between; padding: 14px 20px; margin-bottom: 20px; font-weight: 600; }
.timer { color: var(--accent-2); transition: transform 0.2s ease, color 0.2s ease; display: inline-block; }

.question-card { padding: 30px; }
.question-meta { display: flex; gap: 8px; margin-bottom: 16px; }
.question-card h3 { font-size: 20px; margin-bottom: 24px; line-height: 1.5; }

.options-box { display: flex; flex-direction: column; gap: 12px; }
.option-btn {
    background: var(--bg-secondary); border: 1px solid var(--glass-border); color: var(--text-primary);
    padding: 14px 18px; border-radius: 12px; text-align: left; cursor: pointer; font-size: 15px;
    transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.option-btn:hover:not(:disabled) { border-color: var(--accent); transform: translateX(4px); box-shadow: 0 4px 14px rgba(124, 92, 255, 0.15); }
.option-btn:disabled { cursor: default; opacity: 0.7; }
.option-btn.correct-choice { background: rgba(53, 214, 143, 0.2); border-color: var(--success); animation: popIn 0.35s ease both; }
.option-btn.wrong-choice { background: rgba(255, 92, 108, 0.2); border-color: var(--danger); animation: popIn 0.35s ease both; }

.feedback-box { margin-top: 20px; padding: 14px 16px; border-radius: 12px; font-size: 14px; animation: fadeInUp 0.35s ease both; }
.feedback-box.correct { background: rgba(53, 214, 143, 0.15); color: var(--success); }
.feedback-box.incorrect { background: rgba(255, 92, 108, 0.15); color: var(--danger); }
.hidden { display: none !important; }

.battle-result { padding: 50px 30px; text-align: center; }
.result-score { font-size: 28px; font-weight: 700; margin: 20px 0; color: var(--accent); animation: fadeInScale 0.6s cubic-bezier(0.22, 1, 0.36, 1) both; }
.battle-result .btn { margin: 6px; }

/* ---------------- RESPONSIVE ---------------- */
@media (max-width: 768px) {
    .app-layout { flex-direction: column; }
    .sidebar { width: auto; position: relative; height: auto; flex-direction: row; overflow-x: auto; }
    .side-nav { flex-direction: row; margin-top: 0; }
    .side-link.logout { margin-top: 0; }
    .hero-content h1 { font-size: 32px; }
    .navbar { padding: 12px 16px; }
    .form-row { flex-direction: column; }
    .list-row { font-size: 13px; }
    .blob { filter: blur(45px); opacity: 0.22; }
    .blob-1, .blob-2 { width: 220px; height: 220px; }
    .blob-3 { width: 160px; height: 160px; }
}