@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@500;600;700;800;900&display=swap');

:root {
    /* Mekteb Sehara Color Palette */
    --bg-cream: #FAF6EE;
    --bg-sand: #F1E9D8;
    --bg-card: #FFFFFF;
    --bg-subtle: #F7F3EB;
    
    --emerald-900: #073B2E;
    --emerald-800: #0A4F3E;
    --emerald-700: #0D6852;
    --emerald-600: #118468;
    --emerald-500: #16A07E;
    --emerald-100: #E3F6F0;
    --emerald-50: #F1FAF7;

    --gold-700: #9E690C;
    --gold-600: #C68616;
    --gold-500: #E5A324;
    --gold-400: #F6BC46;
    --gold-200: #FDE7B2;
    --gold-100: #FEF5DC;

    --coral-600: #D63E3E;
    --coral-500: #E65555;
    --coral-100: #FDECEC;

    --sky-600: #1D6E95;
    --sky-500: #2989B5;
    --sky-100: #E5F4FA;

    --text-dark: #1E2D28;
    --text-body: #3E504A;
    --text-muted: #70827C;
    --border-light: #E4DCCB;
    --border-gold: #E8CF99;

    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 22px;
    --radius-xl: 28px;
    --radius-pill: 999px;

    --shadow-sm: 0 2px 8px rgba(10, 59, 46, 0.06);
    --shadow-md: 0 8px 24px rgba(10, 59, 46, 0.09);
    --shadow-lg: 0 14px 36px rgba(10, 59, 46, 0.13);
    --shadow-gold: 0 6px 20px rgba(229, 163, 36, 0.25);

    --font-main: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-cream);
    background-image: 
        radial-gradient(circle at 15% 10%, rgba(22, 160, 126, 0.07) 0%, transparent 45%),
        radial-gradient(circle at 85% 90%, rgba(229, 163, 36, 0.09) 0%, transparent 45%),
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg stroke='%230D6852' stroke-width='1' stroke-opacity='0.045'%3E%3Cpath d='M30 0l8.8 21.2L60 30l-21.2 8.8L30 60l-8.8-21.2L0 30l21.2-8.8z'/%3E%3Ccircle cx='30' cy='30' r='8'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    color: var(--text-dark);
    line-height: 1.5;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

.hidden {
    display: none !important;
}

/* Color Utilities */
.text-green { color: var(--emerald-600) !important; }
.text-blue { color: var(--sky-600) !important; }
.text-red { color: var(--coral-600) !important; }
.text-yellow { color: var(--gold-600) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-center { text-align: center !important; }

a {
    color: var(--emerald-700);
    text-decoration: none;
    font-weight: 700;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--emerald-500);
}

/* ==========================================================================
   TOP APP HEADER (MEKTEB SEHARA BAR)
   ========================================================================== */
.sehara-topbar {
    background: linear-gradient(135deg, var(--emerald-900) 0%, var(--emerald-700) 100%);
    color: #fff;
    padding: 10px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 16px rgba(7, 59, 46, 0.2);
    border-bottom: 3px solid var(--gold-500);
}

.topbar-inner {
    max-width: 1120px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    text-decoration: none;
}

.brand-logo:hover {
    color: #fff;
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--gold-400), var(--gold-600));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.6);
}

.brand-icon svg {
    width: 24px;
    height: 24px;
    fill: var(--emerald-900);
}

.brand-text {
    display: flex;
    flex-direction: column;
}

.brand-title {
    font-size: 1.3rem;
    font-weight: 900;
    letter-spacing: 0.5px;
    line-height: 1.05;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 6px;
}

.brand-subtitle {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--gold-200);
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-icon-circle {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.13);
    border: 1px solid rgba(255, 255, 255, 0.22);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1.05rem;
}

.btn-icon-circle:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
}

.ping-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(0, 0, 0, 0.25);
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 800;
    color: #fff;
}

.ping-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4CE0B3;
    box-shadow: 0 0 8px #4CE0B3;
}

/* ==========================================================================
   APP SHELL & RESPONSIVE GRID
   ========================================================================== */
.app-shell {
    max-width: 1120px;
    width: 100%;
    margin: 0 auto;
    padding: 16px 14px 90px;
    flex: 1;
}

/* Logged-out Landing Grid */
.landing-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    align-items: start;
}

@media (min-width: 900px) {
    .landing-grid {
        grid-template-columns: 380px 1fr;
        gap: 24px;
    }
}

/* Logged-in Game Layout */
.game-layout {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ==========================================================================
   PLAYER STATS RIBBON (COMPACT MOBILE + DESKTOP BAR)
   ========================================================================== */
.student-ribbon {
    background: var(--bg-card);
    border: 2px solid var(--border-gold);
    border-radius: var(--radius-lg);
    padding: 10px 14px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.student-identity {
    display: flex;
    align-items: center;
    gap: 10px;
}

.student-avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--emerald-600), var(--emerald-800));
    color: var(--gold-200);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 1.2rem;
    flex-shrink: 0;
    box-shadow: 0 3px 8px rgba(13, 104, 82, 0.25);
}

.student-meta {
    display: flex;
    flex-direction: column;
}

.student-name-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.student-name {
    font-weight: 900;
    font-size: 1.05rem;
    color: var(--emerald-900);
}

.combo-badge {
    display: inline-flex;
    align-items: center;
    background: linear-gradient(135deg, var(--gold-400), var(--gold-600));
    color: #fff;
    font-size: 0.72rem;
    font-weight: 900;
    padding: 2px 9px;
    border-radius: var(--radius-pill);
    letter-spacing: 0.3px;
    text-transform: uppercase;
    box-shadow: 0 2px 6px rgba(198, 134, 22, 0.3);
}

.student-stats-pills {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.stat-chip {
    background: var(--bg-subtle);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 5px 11px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 800;
}

.stat-chip-label {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
}

.stat-chip-val {
    font-weight: 900;
    font-size: 0.95rem;
}

.desktop-nav-links {
    display: none;
    align-items: center;
    gap: 6px;
}

@media (min-width: 768px) {
    .desktop-nav-links {
        display: flex;
    }
}

.nav-pill-btn {
    padding: 7px 14px;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: 800;
    background: var(--emerald-50);
    color: var(--emerald-800);
    border: 1px solid rgba(17, 132, 104, 0.2);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.nav-pill-btn:hover {
    background: var(--emerald-600);
    color: #fff;
}

.nav-pill-btn.logout {
    background: var(--coral-100);
    color: var(--coral-600);
    border-color: rgba(214, 62, 62, 0.2);
}

.nav-pill-btn.logout:hover {
    background: var(--coral-600);
    color: #fff;
}

/* ==========================================================================
   CARDS & PANELS (ORNATE SEHARA CONTAINERS)
   ========================================================================== */
.panel {
    background: var(--bg-card);
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    position: relative;
}

.panel-gold {
    border: 2px solid var(--border-gold);
}

.panel-header {
    background: linear-gradient(90deg, var(--emerald-800), var(--emerald-700));
    color: #fff;
    padding: 12px 18px;
    font-weight: 800;
    font-size: 0.98rem;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 2px solid var(--gold-500);
}

.panel-header-gold {
    background: linear-gradient(90deg, var(--gold-600), var(--gold-500));
    color: #fff;
    border-bottom: 2px solid var(--gold-700);
}

.panel-body {
    padding: 18px;
}

/* ==========================================================================
   HERO BANNER (LANDING VIEW)
   ========================================================================== */
.hero-banner {
    background: linear-gradient(135deg, var(--emerald-900) 0%, var(--emerald-700) 60%, var(--emerald-600) 100%);
    border-radius: var(--radius-xl);
    padding: 24px 20px;
    color: #fff;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    border: 2px solid var(--gold-500);
    margin-bottom: 18px;
}

.hero-banner::after {
    content: '';
    position: absolute;
    right: -30px;
    bottom: -40px;
    width: 180px;
    height: 180px;
    background: radial-gradient(circle, rgba(246, 188, 70, 0.25) 0%, transparent 70%);
    pointer-events: none;
}

.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(246, 188, 70, 0.2);
    border: 1px solid rgba(246, 188, 70, 0.55);
    color: var(--gold-200);
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    font-size: 0.78rem;
    font-weight: 800;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.main-title {
    font-size: clamp(1.45rem, 4vw, 2.1rem);
    font-weight: 900;
    color: #fff;
    line-height: 1.15;
    margin-bottom: 6px;
}

.page-heading {
    font-size: clamp(1.3rem, 3.5vw, 1.75rem);
    font-weight: 900;
    color: var(--emerald-900);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sub-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--emerald-100);
    opacity: 0.95;
}

/* ==========================================================================
   LIVE QUIZ ARENA (MOBILE KEYBOARD-FIRST DESIGN)
   ========================================================================== */
.quiz-stage-card {
    background: var(--bg-card);
    border: 2.5px solid var(--border-gold);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transition: all 0.2s ease;
}

.quiz-stage-top {
    background: linear-gradient(90deg, var(--emerald-900), var(--emerald-700));
    color: #fff;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.round-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 900;
    font-size: 0.88rem;
    color: var(--gold-200);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.round-number-badge {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    padding: 2px 10px;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
}

.phase-badge {
    font-size: 0.78rem;
    font-weight: 900;
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.phase-badge.text-green {
    background: #19B38B;
    color: #fff !important;
}

.phase-badge.text-red {
    background: var(--gold-500);
    color: var(--emerald-900) !important;
}

/* Timers Section */
.timers-strip {
    background: var(--bg-subtle);
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (max-width: 480px) {
    .timers-strip {
        grid-template-columns: 1fr;
        gap: 6px;
        padding: 8px 14px;
    }
}

.timer-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.bar-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--text-body);
}

.bar-wrap {
    background: #E2DBD0;
    height: 10px;
    border-radius: var(--radius-pill);
    overflow: hidden;
    position: relative;
}

.bar-fill {
    height: 100%;
    width: 100%;
    border-radius: var(--radius-pill);
    transition: width 0.18s linear;
}

.bg-green {
    background: linear-gradient(90deg, var(--emerald-600), #23C498);
}

.bg-red {
    background: linear-gradient(90deg, var(--gold-600), var(--gold-400));
}

/* Question Display Box */
.question-stage {
    min-height: 145px;
    padding: 24px 20px;
    background: 
        radial-gradient(circle at 50% 0%, rgba(246, 188, 70, 0.14), transparent 70%),
        linear-gradient(180deg, #FFFFFF 0%, #FCF9F2 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border-bottom: 1.5px dashed var(--border-gold);
    position: relative;
}

.question-ornament {
    color: var(--gold-500);
    font-size: 0.85rem;
    font-weight: 800;
    letter-spacing: 2px;
    margin-bottom: 8px;
    user-select: none;
}

.question-text {
    font-size: clamp(1.2rem, 3.8vw, 1.65rem);
    font-weight: 900;
    color: var(--emerald-900);
    line-height: 1.35;
    max-width: 720px;
    word-wrap: break-word;
}

/* Instant Feedback Toast inside Quiz Card */
.feedback-banner {
    margin: 10px 14px 0;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-weight: 800;
    font-size: 0.92rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    animation: popIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.feedback-banner.success {
    background: var(--emerald-100);
    color: var(--emerald-900);
    border: 1.5px solid var(--emerald-500);
}

.feedback-banner.error {
    background: var(--coral-100);
    color: var(--coral-600);
    border: 1.5px solid var(--coral-500);
}

.feedback-banner.warn {
    background: var(--gold-100);
    color: var(--gold-700);
    border: 1.5px solid var(--gold-500);
}

@keyframes popIn {
    0% { transform: scale(0.94); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Answer Input Area (100% Mobile Keyboard Friendly) */
.action-box {
    padding: 14px 16px 16px;
    background: var(--bg-card);
}

.action-input-row {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

#answer-input {
    flex: 1;
    margin-bottom: 0 !important;
    font-size: 1.08rem !important; /* >= 16px prevents iOS Safari zoom */
    font-weight: 800;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    border: 2.5px solid var(--border-gold);
    background: var(--bg-subtle);
    color: var(--emerald-900);
    transition: all 0.2s ease;
}

#answer-input:focus {
    background: #FFFFFF;
    border-color: var(--emerald-600);
    box-shadow: 0 0 0 4px rgba(22, 160, 126, 0.16);
}

#answer-input::placeholder {
    color: var(--text-muted);
    font-weight: 600;
}

#btn-submit {
    padding: 0 24px;
    font-size: 1rem;
    border-radius: var(--radius-md);
    min-height: 52px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-shrink: 0;
}

@media (max-width: 520px) {
    .action-input-row {
        flex-direction: row; /* Keep button beside input on mobile so keyboard doesn't cover button! */
        gap: 8px;
    }
    #answer-input {
        padding: 12px 14px;
    }
    #btn-submit {
        padding: 0 18px;
        min-height: 48px;
        font-size: 0.95rem;
    }
}

/* ==========================================================================
   WHEN VIRTUAL KEYBOARD IS OPEN ON MOBILE (iOS / ANDROID)
   ========================================================================== */
@media (max-width: 820px) {
    body.keyboard-open .sehara-topbar {
        padding: 6px 12px;
    }
    body.keyboard-open .brand-icon {
        width: 30px;
        height: 30px;
    }
    body.keyboard-open .brand-subtitle,
    body.keyboard-open .student-ribbon,
    body.keyboard-open .mobile-bottom-nav,
    body.keyboard-open .secondary-game-panels,
    body.keyboard-open .timer-round-item {
        display: none !important;
    }
    body.keyboard-open .app-shell {
        padding-top: 6px;
        padding-bottom: 12px;
    }
    body.keyboard-open .question-stage {
        min-height: 86px;
        padding: 12px 14px;
    }
    body.keyboard-open .question-ornament {
        display: none;
    }
    body.keyboard-open .question-text {
        font-size: 1.12rem;
    }
    body.keyboard-open .timers-strip {
        padding: 6px 12px;
    }
    body.keyboard-open .action-box {
        padding: 10px 12px;
    }
}

/* ==========================================================================
   FORMS, INPUTS & BUTTONS
   ========================================================================== */
.form-group {
    margin-bottom: 12px;
}

.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 800;
    color: var(--emerald-900);
    margin-bottom: 5px;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
select,
textarea {
    width: 100%;
    background: var(--bg-subtle);
    border: 2px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-dark);
    padding: 12px 14px;
    font-family: var(--font-main);
    font-size: 1rem; /* Explicitly 16px to prevent iOS zoom on focus */
    font-weight: 700;
    outline: none;
    margin-bottom: 10px;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    background: #FFFFFF;
    border-color: var(--emerald-600);
    box-shadow: 0 0 0 3px rgba(22, 160, 126, 0.15);
}

input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: #EAE4D7;
}

.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

@media (max-width: 420px) {
    .form-row-2 {
        grid-template-columns: 1fr;
        gap: 0;
    }
}

.captcha-box {
    background: var(--gold-100);
    border: 2px dashed var(--gold-500);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.captcha-question {
    font-size: 1.15rem;
    font-weight: 900;
    color: var(--emerald-900);
    white-space: nowrap;
}

.captcha-box input {
    margin-bottom: 0;
    max-width: 130px;
    text-align: center;
    background: #fff;
}

/* Buttons */
.btn-torn,
.btn-primary {
    background: linear-gradient(135deg, var(--emerald-600) 0%, var(--emerald-800) 100%);
    border: none;
    border-bottom: 3px solid var(--emerald-900);
    color: #fff;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-size: 0.98rem;
    font-weight: 900;
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(13, 104, 82, 0.25);
}

.btn-torn:hover:not(:disabled),
.btn-primary:hover:not(:disabled) {
    filter: brightness(1.07);
    transform: translateY(-1px);
}

.btn-torn:active:not(:disabled),
.btn-primary:active:not(:disabled) {
    transform: translateY(1px);
    border-bottom-width: 1px;
}

.btn-torn:disabled,
.btn-primary:disabled {
    background: #B8C4BF;
    border-bottom-color: #96A39E;
    color: #F2F5F4;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-gold {
    background: linear-gradient(135deg, var(--gold-400) 0%, var(--gold-600) 100%);
    border-bottom: 3px solid var(--gold-700);
    color: var(--emerald-900);
    box-shadow: var(--shadow-gold);
}

.btn-secondary {
    background: var(--bg-subtle);
    border: 2px solid var(--border-light);
    color: var(--text-body);
    box-shadow: none;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border-light);
}

.btn-full {
    width: 100%;
    margin-bottom: 8px;
}

/* ==========================================================================
   SECONDARY GAME PANELS (TABS ON MOBILE, 2-COL GRID ON DESKTOP)
   ========================================================================== */
.mobile-tabs-bar {
    display: flex;
    background: var(--bg-sand);
    padding: 5px;
    border-radius: var(--radius-md);
    gap: 6px;
    margin-bottom: 12px;
}

.mobile-tab-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-family: var(--font-main);
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--text-body);
    cursor: pointer;
    transition: all 0.2s ease;
}

.mobile-tab-btn.active {
    background: var(--bg-card);
    color: var(--emerald-800);
    box-shadow: var(--shadow-sm);
}

.secondary-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

@media (min-width: 860px) {
    .mobile-tabs-bar {
        display: none;
    }
    .secondary-grid {
        grid-template-columns: 1.15fr 0.85fr;
    }
    .secondary-grid > .panel.mobile-hidden-tab {
        display: block !important;
    }
}

@media (max-width: 859px) {
    .secondary-grid > .panel.mobile-hidden-tab {
        display: none !important;
    }
}

/* ==========================================================================
   TABLES (LEADERBOARDS & LOGS)
   ========================================================================== */
.torn-table {
    width: 100%;
    border-collapse: collapse;
}

.torn-table th {
    background: var(--bg-subtle);
    color: var(--text-muted);
    text-align: left;
    padding: 10px 14px;
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1.5px solid var(--border-light);
}

.torn-table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--bg-sand);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-dark);
}

.torn-table tr:last-child td {
    border-bottom: none;
}

.torn-table tr:hover td {
    background: var(--emerald-50);
}

.torn-table td.val-col {
    text-align: right;
    font-weight: 900;
    color: var(--emerald-700);
}

.me-row td {
    background: var(--gold-100) !important;
    font-weight: 900;
}

.me-row td:first-child {
    border-left: 4px solid var(--gold-500);
}

.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    border-radius: 8px;
    font-weight: 900;
    font-size: 0.85rem;
    background: var(--bg-subtle);
    color: var(--text-body);
}

.rank-1 { background: #FFF3C4; color: #9C6500; border: 1px solid #F5C451; font-size: 1.05rem; }
.rank-2 { background: #F0F4F8; color: #486581; border: 1px solid #BCCCDC; font-size: 1.05rem; }
.rank-3 { background: #FBE9E7; color: #8D4E35; border: 1px solid #FFAB91; font-size: 1.05rem; }

/* ==========================================================================
   PROFILE PAGE SPECIFIC
   ========================================================================== */
.profile-hero {
    background: linear-gradient(135deg, var(--emerald-800), var(--emerald-600));
    color: #fff;
    padding: 24px 20px;
    border-radius: var(--radius-xl);
    display: flex;
    align-items: center;
    gap: 18px;
    box-shadow: var(--shadow-md);
    border: 2px solid var(--gold-500);
    flex-wrap: wrap;
}

.profile-avatar-lg {
    width: 72px;
    height: 72px;
    border-radius: 22px;
    background: linear-gradient(135deg, var(--gold-400), var(--gold-600));
    color: var(--emerald-900);
    font-size: 2rem;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(0,0,0,0.2);
    border: 3px solid #fff;
    flex-shrink: 0;
}

.profile-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

@media (max-width: 500px) {
    .profile-stats-grid {
        grid-template-columns: 1fr;
    }
}

.stat-card {
    background: var(--bg-card);
    border: 2px solid var(--border-gold);
    border-radius: var(--radius-lg);
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.stat-card-value {
    font-size: 1.75rem;
    font-weight: 900;
    color: var(--emerald-700);
    line-height: 1.1;
    margin-bottom: 4px;
}

.stat-card-label {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
}

.achievement-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--bg-sand);
    font-weight: 800;
    color: var(--emerald-900);
}

.achievement-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: var(--gold-100);
    border: 1.5px solid var(--gold-400);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

/* ==========================================================================
   MOBILE BOTTOM NAVIGATION BAR
   ========================================================================== */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    border-top: 2px solid var(--border-gold);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px));
    z-index: 95;
    box-shadow: 0 -4px 16px rgba(10, 59, 46, 0.08);
}

@media (min-width: 768px) {
    .mobile-bottom-nav {
        display: none !important;
    }
    .app-shell {
        padding-bottom: 40px;
    }
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    color: var(--text-muted);
    font-size: 0.74rem;
    font-weight: 800;
    border-radius: var(--radius-sm);
    text-decoration: none;
}

.bottom-nav-item.active,
.bottom-nav-item:hover {
    color: var(--emerald-700);
}

.bottom-nav-item svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.2;
}

/* Subtle pulse animation for status transitions */
.glitch-anim {
    animation: gentlePulse 0.45s ease-in-out;
}

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