/* =========================================
   QuizzUp Premium Design System
   ========================================= */

/* Imports are handled via HTML link for simplicity and performance */

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

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-body);
    overflow-x: hidden;
    min-height: 100vh;
    line-height: 1.5;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    color: var(--text-primary);
    line-height: 1.2;
}

a {
    text-decoration: none;
    color: inherit;
    transition: var(--transition-smooth);
}

button {
    font-family: inherit;
    border: none;
    outline: none;
    cursor: pointer;
}

/* --- Utility Classes --- */
.hidden { display: none !important; }
.fade-in { animation: fadeInSlideUp 0.6s ease forwards; }
.text-center { text-align: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }

/* --- App Shell Layout --- */
.app-shell {
    display: flex;
    min-height: 100vh;
    position: relative;
    background: radial-gradient(circle at top left, #1e1b4b 0%, var(--bg-main) 40%);
}

/* Sidebar (Desktop) */
.sidebar {
    width: var(--sidebar-width);
    background: rgba(2, 6, 23, 0.8);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: transform var(--duration-normal) var(--ease-out);
}

.sidebar-header {
    margin-bottom: 3rem;
    padding-left: 0.5rem;
}

.logo-small {
    font-size: 1.8rem;
    font-weight: 800;
    font-family: var(--font-heading);
    letter-spacing: -1px;
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

.logo-accent {
    color: var(--primary);
    background: linear-gradient(135deg, var(--primary), var(--tertiary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.8rem 1rem;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    background: transparent;
    transition: all var(--duration-fast);
    font-weight: 500;
    font-size: 0.95rem;
}

.nav-item:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.15), transparent);
    color: var(--primary);
    border-left: 3px solid var(--primary);
}

.nav-item .icon {
    font-size: 1.2rem;
    opacity: 0.8;
}

.nav-item.active .icon {
    opacity: 1;
}

.sidebar-footer {
    margin-top: auto;
    border-top: 1px solid var(--border-subtle);
    padding-top: 1.5rem;
}

.danger-hover:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

/* Main Content Wrapper */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Top Bar */
.top-bar {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    background: rgba(2, 6, 23, 0.4);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 90;
    border-bottom: 1px solid var(--border-subtle);
}

.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: var(--font-heading);
    color: var(--text-primary);
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.wallet-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.8rem;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 100px;
    font-family: var(--font-mono);
    color: var(--success);
    font-weight: 600;
    font-size: 0.9rem;
}

.mini-profile {
    cursor: pointer;
}

.avatar-small {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: var(--text-secondary);
    font-weight: 600;
}

.avatar-small img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Content Area */
.content-area {
    padding: 2rem;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    animation: fadeInSlideUp 0.5s ease-out;
}

/* Mobile Nav */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-subtle);
    padding: 0.8rem 1.5rem;
    z-index: 1000;
    justify-content: space-between;
}

.mobile-nav-item {
    padding: 0.8rem;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    background: transparent;
    font-size: 1.4rem;
}

.mobile-nav-item.active {
    color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}

/* --- Components --- */

/* Cards */
.glass-card {
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow-sm);
}

/* Buttons */
.primary-btn {
    padding: 0.8rem 1.5rem;
    background: var(--primary);
    color: white;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.95rem;
    transition: all var(--duration-fast);
    box-shadow: 0 4px 15px var(--primary-glow);
}

.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--primary-glow);
}

.secondary-btn {
    padding: 0.8rem 1.5rem;
    background: transparent;
    border: 1px solid var(--border-glass);
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    font-weight: 600;
    transition: all var(--duration-fast);
}

.secondary-btn:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
    background: rgba(255,255,255,0.02);
}

/* Inputs */
.glass-input, input[type="text"], input[type="password"] {
    width: 100%;
    padding: 0.9rem 1rem;
    background: rgba(2, 6, 23, 0.5);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    transition: border-color 0.2s;
}

.glass-input:focus, input[type="text"]:focus, input[type="password"]:focus {
    border-color: var(--primary);
    outline: none;
}

/* --- Dashboard Specifics --- */
.dashboard-hero {
    margin-bottom: 3rem;
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(168, 85, 247, 0.05));
    border: 1px solid rgba(99, 102, 241, 0.2);
    position: relative;
    overflow: hidden;
}

.dashboard-hero::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, var(--primary-glow) 0%, transparent 70%);
    opacity: 0.4;
    pointer-events: none;
}

.hero-greeting {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.hero-stats {
    display: flex;
    gap: 2rem;
    margin-top: 1.5rem;
}

.hero-stat-item {
    display: flex;
    flex-direction: column;
}

.hero-stat-val {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font-heading);
    color: var(--text-primary);
}

.hero-stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.subject-card {
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    padding: 2rem;
    cursor: pointer;
    transition: all var(--duration-normal);
    position: relative;
    overflow: hidden;
}

.subject-card:hover {
    border-color: var(--primary);
    transform: translateY(-5px);
    background: linear-gradient(145deg, var(--bg-card), rgba(99, 102, 241, 0.05));
}

.subject-icon {
    width: 50px;
    height: 50px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
}

.subject-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.subject-desc {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* --- Quiz Interface --- */
.quiz-wrapper {
    max-width: 900px;
    margin: 0 auto;
    padding-top: 2rem;
}

.quiz-progress {
    width: 100%;
    height: 6px;
    background: var(--bg-secondary);
    border-radius: 10px;
    margin-bottom: 2rem;
    overflow: hidden;
}

.quiz-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    width: 0%;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.quiz-card {
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: 32px;
    padding: 3rem;
    position: relative;
}

.question-meta {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--primary);
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
}

.question-text {
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 2.5rem;
}

.options-grid {
    display: grid;
    gap: 1rem;
}

.option-btn {
    width: 100%;
    padding: 1.2rem 1.5rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    text-align: left;
    font-size: 1.05rem;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.option-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.2);
}

.option-btn.correct {
    background: rgba(16, 185, 129, 0.15) !important;
    border-color: var(--success) !important;
    color: var(--success) !important;
}

.option-btn.wrong {
    background: rgba(239, 68, 68, 0.15) !important;
    border-color: var(--danger) !important;
    color: var(--danger) !important;
}

/* --- Leaderboard Table --- */
.leaderboard-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 0.8rem;
}

.leaderboard-table th {
    text-align: left;
    padding: 1rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.leaderboard-row {
    background: var(--bg-card);
    transition: transform 0.2s;
}

.leaderboard-row td {
    padding: 1.2rem 1rem;
    border-top: 1px solid var(--border-glass);
    border-bottom: 1px solid var(--border-glass);
}

.leaderboard-row td:first-child {
    border-left: 1px solid var(--border-glass);
    border-top-left-radius: var(--radius-md);
    border-bottom-left-radius: var(--radius-md);
}

.leaderboard-row td:last-child {
    border-right: 1px solid var(--border-glass);
    border-top-right-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
}

.leaderboard-row:hover {
    transform: scale(1.01);
    background: rgba(255, 255, 255, 0.06);
}

.rank-cell {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.rank-1 .rank-cell { color: var(--gold); }
.rank-2 .rank-cell { color: #94a3b8; }
.rank-3 .rank-cell { color: #d97706; }

/* --- Modals & Overlays --- */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(2, 6, 23, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-card {
    width: 90%;
    max-width: 500px;
    padding: 2.5rem;
    position: relative;
    animation: fade-up 0.3s ease-out;
}

.close-icon-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    padding: 0.5rem;
    line-height: 1;
}

.close-icon-btn:hover {
    color: var(--text-primary);
}

/* --- Auth Screen Redesign --- */
.auth-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: var(--bg-main);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.auth-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* Left: Hero Section */
.auth-hero {
    flex: 1.2;
    background: radial-gradient(circle at bottom right, #1e1b4b 0%, #020617 80%);
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 4rem;
    overflow: hidden;
    border-right: 1px solid var(--border-glass);
}

.hero-content {
    position: relative;
    z-index: 2;
    max-width: 600px;
}

.logo-display {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.logo-icon-3d {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary), var(--tertiary));
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 800;
    color: white;
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.4);
    transform: rotate(-10deg);
}

.auth-hero h1 {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: -1px;
}

.hero-tagline {
    font-size: 3.5rem;
    line-height: 1.1;
    margin-bottom: 2rem;
    font-weight: 800;
}

.text-gradient {
    background: linear-gradient(90deg, var(--primary), var(--tertiary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.hero-desc {
    font-size: 1.1rem;
    color: var(--text-secondary);
    max-width: 480px;
    line-height: 1.6;
}

/* Hero Visual Graphics (CSS Only) */
.hero-visual {
    margin: 3rem 0;
    position: relative;
    height: 120px;
    display: flex;
    align-items: center;
}

.rank-card-visual {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    padding: 1rem;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 280px;
    backdrop-filter: blur(10px);
    transform: rotate(-5deg);
    box-shadow: 0 15px 35px rgba(0,0,0,0.3);
}

.rank-badge {
    width: 50px;
    height: 50px;
    background: var(--gold);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: black;
    font-size: 1.2rem;
}

.rank-info { flex: 1; }
.rank-name { font-weight: 700; margin-bottom: 0.3rem; }
.rank-bar { height: 6px; background: var(--bg-secondary); border-radius: 4px; overflow: hidden; }
.rank-bar::after { content: ''; display: block; width: 80%; height: 100%; background: var(--success); }

.vs-badge {
    position: absolute;
    left: 260px;
    top: 30%;
    background: var(--danger);
    color: white;
    font-weight: 900;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transform: rotate(15deg);
    box-shadow: 0 5px 15px rgba(239, 68, 68, 0.4);
    font-family: var(--font-heading);
    font-size: 1.2rem;
}

.hero-bg-effects {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 1;
}

.hero-blob {
    position: absolute;
    filter: blur(80px);
    opacity: 0.15;
    border-radius: 50%;
}
.hero-blob.blob-1 { width: 500px; height: 500px; background: var(--primary); top: -100px; left: -100px; }
.hero-blob.blob-2 { width: 400px; height: 400px; background: var(--tertiary); bottom: -50px; right: -50px; }

/* Right: Form Section */
.auth-form-side {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 4rem 6rem;
    background: rgba(2, 6, 23, 0.95);
    position: relative;
    z-index: 5;
}

.form-header { margin-bottom: 2.5rem; }
.form-header h3 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.auth-subtitle { color: var(--text-muted); font-size: 0.95rem; }

.auth-tabs {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-subtle);
}

.auth-tab {
    padding-bottom: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 600;
    position: relative;
    transition: all 0.2s;
}

.auth-tab.active {
    color: var(--primary);
}

.auth-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--primary);
}

.form-group { margin-bottom: 1.5rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-size: 0.9rem; color: var(--text-secondary); font-weight: 500; }

.password-input-wrapper { position: relative; }
.password-toggle {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    font-size: 1rem;
    color: var(--text-muted);
    cursor: pointer;
}

.error-msg {
    color: var(--danger);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    min-height: 1.2em;
}

.block-btn {
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
    letter-spacing: 0.5px;
    margin-top: 1rem;
}

.switch-text {
    margin-top: 2rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.switch-text span {
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
}
.switch-text span:hover { text-decoration: underline; }

/* Responsive Auth */
@media (max-width: 1024px) {
    .auth-hero { display: none; }
    .auth-form-side { padding: 2rem; width: 100%; flex: 1; }
    .auth-container { justify-content: center; }
}

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

@keyframes fade-up {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes move-blobs {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(50px, 100px) scale(1.1); }
}

/* Background Effects Re-implementation */
.bg-effects {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.blob {
    position: absolute;
    width: 600px;
    height: 600px;
    filter: blur(100px);
    border-radius: 50%;
    opacity: 0.1;
    animation: move-blobs 20s infinite alternate;
}

.blob-1 { background: var(--primary); top: -200px; left: -200px; }
.blob-2 { background: var(--tertiary); bottom: -200px; right: -200px; }

/* Focus Mode (Quiz) */
.app-shell.quiz-mode .sidebar {
    transform: translateX(-100%);
    width: 0;
    padding: 0;
    border: none;
    overflow: hidden;
}

.app-shell.quiz-mode .main-wrapper {
    margin-left: 0;
}

.app-shell.quiz-mode .top-bar {
    justify-content: center;
}

.app-shell.quiz-mode .top-bar-actions,
.app-shell.quiz-mode .page-title {
    display: none;
}

/* Responsive Media Queries */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: 0; padding: 0; }
    .main-wrapper { margin-left: 0; padding-bottom: 80px; }
    .mobile-nav { display: flex; }
    .top-bar { padding: 0 1rem; }
    .content-area { padding: 1.5rem; }
    .question-card { padding: 1.5rem; border-radius: 24px; }
    .question-text { font-size: 1.3rem; }
    .leaderboard-table { display: block; overflow-x: auto; }
}

/* --- Inspection Modal Specifics --- */
.inspect-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.inspect-avatar {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    overflow: hidden;
}

.inspect-avatar img { width: 100%; height: 100%; object-fit: cover; }

.inspect-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-box {
    background: rgba(255, 255, 255, 0.03);
    padding: 1rem;
    border-radius: var(--radius-md);
    text-align: center;
    display: flex;
    flex-direction: column;
}

.stat-box .val {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-box .lbl {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* History List Item (Mini) */
.history-item-mini {
    padding: 0.8rem;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}
.history-item-mini:last-child { border-bottom: none; }

/* Keep essential legacy classes if still used by JS directly */
.intro-container { /* ... kept above ... */ }
.intro-ring { /* ... kept above ... */ }

/* --- Enhanced Quiz UI --- */
.quiz-header-stats {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.stat-pill {
    background: rgba(2, 6, 23, 0.6);
    border: 1px solid var(--border-glass);
    padding: 0.6rem 1.2rem;
    border-radius: 100px;
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-primary);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-pill.correct-pill {
    border-color: rgba(16, 185, 129, 0.3);
    color: var(--success);
}

.stat-pill.remaining-pill {
    border-color: rgba(99, 102, 241, 0.3);
    color: var(--primary);
}

.difficulty-badge {
    padding: 0.3rem 0.8rem;
    background: rgba(255,255,255,0.1);
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.feedback-box {
    margin-top: 2rem;
    padding: 1.5rem;
    background: rgba(2, 6, 23, 0.6);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    text-align: center;
}

.feedback-box h3 {
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

/* Animations */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.shake-anim {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}

.pop-anim {
    animation: pop 0.3s ease-out;
}

/* --- Chapter Card Dropdown/Overlay Menu --- */
.chapter-dropdown {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.98); /* High opacity to cover content */
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.8rem;
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.chapter-dropdown.active {
    opacity: 1;
    pointer-events: auto;
}

.dropdown-option {
    width: 85%;
    padding: 0.7rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.dropdown-option:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: var(--primary);
    transform: translateX(5px);
}

.dropdown-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
}

.dropdown-close:hover {
    color: var(--text-primary);
}

/* =========================================
   CUSTOM ENHANCEMENTS
   ========================================= */

/* Portfolio Button in Top Bar */
.portfolio-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(168, 85, 247, 0.1));
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 100px;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
}

.portfolio-btn:hover {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(168, 85, 247, 0.15));
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.3);
}

.portfolio-icon {
    font-size: 1.1rem;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.portfolio-text {
    font-family: var(--font-heading);
}

/* Enhanced Welcome Screen */
.intro-welcome {
    text-align: center;
    z-index: 10;
    position: relative;
}

.welcome-line-1 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 2px;
    margin-bottom: 1rem;
    opacity: 0;
    animation: fadeInUp 0.8s ease forwards 0.5s;
}

.welcome-line-2 {
    font-size: 3rem;
    font-weight: 800;
    font-family: var(--font-heading);
    background: linear-gradient(90deg, var(--primary), var(--tertiary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 1rem;
    opacity: 0;
    animation: fadeInUp 0.8s ease forwards 1s;
}

.welcome-line-3 {
    font-size: 1rem;
    color: var(--text-secondary);
    opacity: 0;
    animation: fadeInUp 0.8s ease forwards 1.5s;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Highlight Current User in Leaderboard */
.leaderboard-row.current-user {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.2), rgba(168, 85, 247, 0.1)) !important;
    border: 2px solid var(--primary) !important;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.3);
    transform: scale(1.02);
}

.leaderboard-row.current-user td {
    border-color: var(--primary) !important;
    font-weight: 700;
    color: var(--primary);
}

.leaderboard-row.current-user .rank-cell {
    color: var(--primary);
    text-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .portfolio-text {
        display: none;
    }
    
    .portfolio-btn {
        padding: 0.6rem;
    }
    
    .welcome-line-1 {
        font-size: 1rem;
    }
    
    .welcome-line-2 {
        font-size: 2rem;
    }
    
    .welcome-line-3 {
        font-size: 0.9rem;
    }
}

/* =========================================
   COMMUNITY HUB STYLES
   ========================================= */

.community-layout {
    display: grid;
    grid-template-columns: 1fr 350px; /* Feed | Chat */
    gap: 2rem;
    height: calc(100vh - 140px); /* Fill remaining height */
    overflow: hidden;
}

/* Feed Section */
.feed-section {
    overflow-y: auto;
    padding-right: 1rem;
}

.create-post-card {
    margin-bottom: 2rem;
    padding: 1.5rem;
    border: 1px solid rgba(99, 102, 241, 0.3);
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.6), rgba(15, 23, 42, 0.8));
}

.post-input {
    width: 100%;
    background: rgba(0,0,0,0.2);
    border: none;
    padding: 0.8rem 1rem;
    border-radius: 2rem;
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.post-input:focus {
    outline: none;
    background: rgba(0,0,0,0.4);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.post-actions {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: rgba(255,255,255,0.1);
}

/* Post Cards */
.post-card {
    margin-bottom: 1.5rem;
    border-left: 4px solid transparent;
    transition: transform 0.2s;
}

.post-card:hover {
    transform: translateY(-2px);
    border-left-color: var(--primary);
}

.highlight-post {
    border-left-color: var(--gold);
    background: linear-gradient(to right, rgba(251, 191, 36, 0.05), rgba(30, 41, 59, 0.4));
}

.post-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.post-author {
    font-weight: 700;
    color: var(--text-primary);
}

.post-time {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.post-content {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.post-footer {
    display: flex;
    gap: 1rem;
    padding-top: 0.8rem;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.reaction-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    font-weight: 500;
    transition: color 0.2s;
}

.reaction-btn:hover {
    color: var(--primary);
}

.delete-post-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
}

.delete-post-btn:hover {
    color: var(--danger);
}

/* Chat Section */
.chat-section {
    height: 100%;
}

.chat-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    border: 1px solid rgba(168, 85, 247, 0.3); /* Purple border for confidence */
}

.chat-header {
    padding: 1rem;
    background: rgba(0,0,0,0.2);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    margin: 0;
    font-size: 1rem;
}

.live-indicator {
    font-size: 0.8rem;
    color: var(--success);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.blink-dot {
    width: 6px;
    height: 6px;
    background: var(--success);
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 5px var(--success);
    animation: blink 2s infinite;
}

@keyframes blink {
    0% { opacity: 1; }
    50% { opacity: 0.4; }
    100% { opacity: 1; }
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.chat-message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 85%;
    animation: slideInRight 0.3s ease;
}

.chat-message.my-message {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-bubble {
    background: rgba(255,255,255,0.05);
    padding: 0.6rem 0.8rem;
    border-radius: 12px;
    border-bottom-left-radius: 2px;
}

.chat-message.my-message .chat-bubble {
    background: var(--primary);
    color: white;
    border-radius: 12px;
    border-bottom-right-radius: 2px;
    border-bottom-left-radius: 12px;
}

.chat-user {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

.chat-message.my-message .chat-user {
    display: none; /* Hide name for self */
}

.chat-text {
    font-size: 0.9rem;
}

.chat-input-area {
    padding: 1rem;
    background: rgba(0,0,0,0.2);
    display: flex;
    gap: 0.5rem;
}

.chat-input-area input {
    flex: 1;
    background: rgba(255,255,255,0.05);
    border: none;
    padding: 0.6rem 1rem;
    border-radius: 1.5rem;
    color: white;
}

.send-btn {
    background: var(--primary);
    border: none;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(10px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Mobile Responsive */
@media (max-width: 900px) {
    .community-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 300px; /* Feed then Chat */
        height: auto;
        overflow: visible;
    }
    
    .chat-section {
        height: 400px;
        margin-top: 2rem;
    }
}
