/**
 * Classroom Design System - Modern UI Styles
 * ระบบ CSS หลักสำหรับห้องเรียนออนไลน์
 * สร้างความสอดคล้องและความสวยงามทั่วทั้งเว็บ
 */


/* ==================== CSS VARIABLES (Design Tokens) ==================== */
:root {
    /* Primary Colors - โทนฟ้าน้ำเงินสะอาดตา */
    --primary-50: #eff6ff;
    --primary-100: #dbeafe;
    --primary-200: #bfdbfe;
    --primary-300: #93c5fd;
    --primary-400: #60a5fa;
    --primary-500: #3b82f6;
    --primary-600: #2563eb;
    --primary-700: #1d4ed8;
    --primary-800: #1e40af;
    --primary-900: #1e3a8a;

    /* Success Colors - เขียว */
    --success-50: #ecfdf5;
    --success-100: #d1fae5;
    --success-500: #10b981;
    --success-600: #059669;
    --success-700: #047857;

    /* Warning Colors - ส้ม */
    --warning-50: #fffbeb;
    --warning-100: #fef3c7;
    --warning-500: #f59e0b;
    --warning-600: #d97706;

    /* Danger Colors - แดง */
    --danger-50: #fef2f2;
    --danger-100: #fee2e2;
    --danger-500: #ef4444;
    --danger-600: #dc2626;

    /* Info Colors - ฟ้าอ่อน */
    --info-50: #ecfeff;
    --info-100: #cffafe;
    --info-500: #06b6d4;
    --info-600: #0891b2;

    /* Neutral Colors */
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    /* Gradients - โทนฟ้าน้ำเงินสะอาดตา */
    --gradient-primary: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    --gradient-primary-light: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
    --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --gradient-warning: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    --gradient-cool: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%);
    --gradient-sky: linear-gradient(135deg, #7dd3fc 0%, #38bdf8 50%, #0ea5e9 100%);
    --gradient-ocean: linear-gradient(135deg, #3b82f6 0%, #2563eb 50%, #1d4ed8 100%);
    --gradient-glass: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.1) 100%);

    /* Shadows - โทนฟ้า */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 10px 10px -5px rgba(0, 0, 0, 0.03);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.2);
    --shadow-glow-primary: 0 0 40px rgba(59, 130, 246, 0.25);
    --shadow-glow-success: 0 0 40px rgba(16, 185, 129, 0.25);
    --shadow-card: 0 4px 20px rgba(59, 130, 246, 0.08);
    --shadow-card-hover: 0 12px 40px rgba(59, 130, 246, 0.15);

    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.5rem;
    --radius-3xl: 2rem;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 300ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 500ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 500ms cubic-bezier(0.68, -0.55, 0.265, 1.55);

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
}

/* ==================== BASE STYLES ==================== */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 25%, #93c5fd 50%, #60a5fa 75%, #3b82f6 100%);
    background-size: 300% 300%;
    animation: gradientShift 20s ease infinite;
    overflow-x: hidden;
    margin: 0;
    min-height: 100vh;
    color: var(--gray-800);
    line-height: 1.6;
}

@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

/* ==================== TYPOGRAPHY ==================== */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 700;
    line-height: 1.3;
    color: var(--gray-800);
}

.text-gradient {
    background: linear-gradient(135deg, #2563eb 0%, #0ea5e9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: inline-block;
    padding: 0.1em 0.3em;
    margin: 0 -0.2em;
    line-height: 1.4;
}

/* ==================== GLASS MORPHISM ==================== */
.glass {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.glass-dark {
    background: rgba(17, 24, 39, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ==================== MAIN CONTAINER ==================== */
/* Main Container - เต็มจอ */
#app-container {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    min-height: 100vh;
}

/* ==================== ANIMATIONS ==================== */
.fade-in {
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== STREET FIGHTER MODE ==================== */
.sf-only {
    display: none;
}

#screen-battle-arena.sf-mode .sf-only {
    display: block;
}

#screen-battle-arena.sf-mode .classic-only {
    display: none;
}

#screen-battle-arena.sf-mode {
    background: radial-gradient(circle at top, #2a0c0c 0%, #120707 45%, #090404 100%);
    color: #f7eaea;
    font-family: 'Sarabun', sans-serif;
}

#screen-battle-arena.sf-mode #battle-question {
    font-family: 'Sarabun', sans-serif;
}

#screen-battle-arena.sf-mode .battle-choice-btn {
    background: #1b0a0a;
    border: 1px solid #3b0f0f;
    color: #f5dcdc;
}

#screen-battle-arena.sf-mode .battle-choice-btn:hover {
    background: #2a0f0f;
    border-color: #7a1c1c;
}

.sf-hp-bar {
    width: 150px;
    height: 10px;
    background: #2b2b2b;
    border: 1px solid #7a1c1c;
    border-radius: 999px;
    overflow: hidden;
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.7);
}

.sf-hp-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #ff3b3b 0%, #ffb34d 60%, #ffe27a 100%);
    transition: width 0.35s ease;
}

.sf-hp-text {
    margin-top: 6px;
    font-size: 10px;
    letter-spacing: 1px;
    color: #ffd2d2;
}

.sf-finisher-btn {
    background: linear-gradient(135deg, #ff3b3b 0%, #7a0c0c 100%);
    color: #fff5f5;
    border: 2px solid #ff6b6b;
    padding: 12px 20px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
    box-shadow: 0 8px 20px rgba(255, 59, 59, 0.35);
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.sf-finisher-btn:hover {
    transform: translateY(-2px) scale(1.02);
}

.sf-finisher-btn.disabled {
    opacity: 0.55;
    box-shadow: none;
}

.sf-finisher-tooltip {
    margin-top: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: #ffd2d2;
    border: 1px solid #7a1c1c;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 10px;
    letter-spacing: 0.5px;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.sf-finisher-tooltip.show {
    opacity: 1;
    transform: translateY(0);
}

.sf-ko-banner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 72px;
    color: #ff3b3b;
    text-shadow: 0 0 20px rgba(255, 59, 59, 0.9);
    z-index: 60;
    pointer-events: none;
    animation: sf-ko-pop 1.2s ease forwards;
}

.sf-finisher-banner {
    position: fixed;
    top: 32%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.7);
    background: radial-gradient(circle, rgba(255, 120, 120, 0.98) 0%, rgba(140, 10, 10, 0.98) 70%);
    border: 4px solid rgba(255, 255, 255, 0.9);
    color: #fff;
    padding: 34px 70px;
    border-radius: 28px;
    text-align: center;
    z-index: 20000;
    box-shadow: 0 24px 60px rgba(255, 80, 80, 0.75), 0 0 60px rgba(255, 180, 120, 0.65), 0 0 120px rgba(255, 80, 80, 0.35);
    animation: sf-finisher-pop 1.9s ease forwards;
}

.sf-finisher-banner::before {
    content: '';
    position: absolute;
    inset: -24px;
    border-radius: 32px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0) 65%);
    filter: blur(6px);
    opacity: 0.9;
    z-index: -1;
}

.sf-finisher-title {
    font-size: 46px;
    font-weight: 900;
    letter-spacing: 3px;
    text-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
}

.sf-finisher-sub {
    margin-top: 6px;
    font-size: 18px;
    font-weight: 700;
    opacity: 0.9;
}

@keyframes sf-finisher-pop {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4) rotate(-6deg); }
    25% { opacity: 1; transform: translate(-50%, -50%) scale(1.22) rotate(3deg); }
    55% { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(-2deg); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1.02) rotate(1deg); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.98) rotate(0deg); }
}

@keyframes sf-ko-pop {
    0% { transform: scale(0.4); opacity: 0; }
    30% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 0; }
}

.slide-up {
    animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.slide-in-right {
    animation: slideInRight 0.4s ease-out;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.scale-in {
    animation: scaleIn 0.3s ease-out;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.bounce-in {
    animation: bounceIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes bounceIn {
    from {
        opacity: 0;
        transform: scale(0.3);
    }

    50% {
        transform: scale(1.05);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.pulse-soft {
    animation: pulseSoft 2s ease-in-out infinite;
}

@keyframes pulseSoft {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.02);
    }
}

.float {
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.animate-spin {
    animation: spin 1s linear infinite;
}

.shimmer {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

/* ==================== BUTTONS ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    font-size: 1rem;
    border-radius: var(--radius-xl);
    border: none;
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left var(--transition-slow);
}

.btn:hover::before {
    left: 100%;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: var(--shadow-lg), 0 4px 14px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl), 0 8px 20px rgba(99, 102, 241, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-success {
    background: var(--gradient-success);
    color: white;
    box-shadow: var(--shadow-lg), 0 4px 14px rgba(16, 185, 129, 0.4);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl), 0 8px 20px rgba(16, 185, 129, 0.5);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    box-shadow: var(--shadow-lg), 0 4px 14px rgba(239, 68, 68, 0.4);
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl), 0 8px 20px rgba(239, 68, 68, 0.5);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--gray-300);
    color: var(--gray-700);
}

.btn-outline:hover {
    background: var(--gray-100);
    border-color: var(--gray-400);
    transform: translateY(-2px);
}

.btn-ghost {
    background: transparent;
    color: var(--gray-600);
}

.btn-ghost:hover {
    background: var(--gray-100);
    color: var(--primary-600);
}

/* ==================== CARDS ==================== */
.card {
    background: white;
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-card);
    transition: all var(--transition-base);
    border: 1px solid var(--gray-100);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-card-hover);
}

.card-interactive {
    cursor: pointer;
}

.card-interactive:hover {
    border-color: var(--primary-200);
}

.card-gradient {
    background: linear-gradient(135deg, white 0%, var(--gray-50) 100%);
}

.card-primary {
    background: var(--primary-50);
    border-color: var(--primary-200);
}

.card-success {
    background: var(--success-50);
    border-color: rgba(16, 185, 129, 0.2);
}

.card-warning {
    background: var(--warning-50);
    border-color: rgba(245, 158, 11, 0.2);
}

.card-danger {
    background: var(--danger-50);
    border-color: rgba(239, 68, 68, 0.2);
}

/* ==================== USER TYPE CARDS (Login Screen) ==================== */
.user-type-card {
    position: relative;
    padding: 2rem;
    border-radius: var(--radius-2xl);
    border: 2px solid transparent;
    background: white;
    transition: all var(--transition-base);
    overflow: hidden;
}

.user-type-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--gradient-primary);
    transform: scaleX(0);
    transition: transform var(--transition-base);
}

.user-type-card:hover::before {
    transform: scaleX(1);
}

.user-type-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-xl);
    border-color: var(--primary-200);
}

.user-type-card.student {
    background: linear-gradient(135deg, var(--info-50) 0%, white 100%);
}

.user-type-card.student:hover {
    border-color: var(--info-500);
}

.user-type-card.student::before {
    background: linear-gradient(90deg, var(--info-500), var(--info-600));
}

.user-type-card.student .icon-circle {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%) !important;
    box-shadow: 0 8px 20px rgba(249, 115, 22, 0.4);
}

.user-type-card.student:hover .icon-circle {
    box-shadow: 0 12px 30px rgba(249, 115, 22, 0.5);
}

.user-type-card.external {
    background: linear-gradient(135deg, var(--warning-50) 0%, white 100%);
}

.user-type-card.external:hover {
    border-color: var(--warning-500);
}

.user-type-card.external::before {
    background: linear-gradient(90deg, var(--warning-500), var(--warning-600));
}

.user-type-card.teacher {
    background: linear-gradient(135deg, var(--primary-50) 0%, white 100%);
}

.user-type-card.teacher:hover {
    border-color: var(--primary-500);
}

.user-type-card.teacher::before {
    background: linear-gradient(90deg, var(--primary-500), var(--primary-600));
}

.user-type-card.teacher .icon-circle {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.4);
}

.user-type-card.teacher:hover .icon-circle {
    box-shadow: 0 12px 30px rgba(59, 130, 246, 0.5);
}

/* ==================== ICON CIRCLES ==================== */
.icon-circle {
    width: 4rem;
    height: 4rem;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-md);
}

.icon-circle-primary {
    background: var(--gradient-primary);
    color: white;
}

.icon-circle-success {
    background: var(--gradient-success);
    color: white;
}

.icon-circle-info {
    background: linear-gradient(135deg, var(--info-500) 0%, var(--info-600) 100%);
    color: white;
}

.icon-circle-warning {
    background: linear-gradient(135deg, var(--warning-500) 0%, var(--warning-600) 100%);
    color: white;
}

/* ==================== FORMS ==================== */
.form-input {
    width: 100%;
    padding: 0.875rem 1rem;
    padding-left: 2.75rem;
    font-size: 1rem;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-xl);
    background: var(--gray-50);
    transition: all var(--transition-fast);
    color: var(--gray-800);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-500);
    background: white;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.form-input::placeholder {
    color: var(--gray-400);
}

.form-group {
    position: relative;
    margin-bottom: 1rem;
}

.form-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    transition: color var(--transition-fast);
    pointer-events: none;
}

.form-input:focus+.form-icon,
.form-group:focus-within .form-icon {
    color: var(--primary-500);
}

.form-label {
    display: block;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

/* ==================== TABS ==================== */
.tabs-container {
    display: flex;
    gap: 0.5rem;
    padding: 0.25rem;
    background: var(--gray-100);
    border-radius: var(--radius-xl);
    overflow-x: auto;
}

.tab {
    flex: 1;
    padding: 0.75rem 1rem;
    font-weight: 500;
    color: var(--gray-500);
    border-radius: var(--radius-lg);
    transition: all var(--transition-fast);
    white-space: nowrap;
    text-align: center;
    cursor: pointer;
}

.tab:hover:not(.tab-active):not(.tab-locked) {
    color: var(--gray-700);
    background: rgba(255, 255, 255, 0.5);
}

.tab-active {
    background: white;
    color: var(--primary-600);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.tab-locked {
    color: var(--gray-400);
    cursor: not-allowed;
    opacity: 0.6;
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--gray-100);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--gray-300), var(--gray-400));
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--gray-400), var(--gray-500));
}

.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 3px;
}

/* ==================== LOADING STATES ==================== */
.is-checking {
    cursor: wait;
    opacity: 0.7;
}

.loader {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 4px solid var(--primary-500);
    width: 40px;
    height: 40px;
    animation: spin 0.8s linear infinite;
}

.skeleton {
    background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 50%, var(--gray-200) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

#loading-overlay {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

#loading-overlay>div {
    animation: bounceIn 0.4s ease-out;
}

/* ==================== MODALS ==================== */
#image-modal,
#pdf-modal {
    transition: opacity 0.3s ease-in-out;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

#image-modal.hidden,
#pdf-modal.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ==================== PDF VIEWER ==================== */
/* PDF Modal Base Styles */
#pdf-modal {
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

/* PDF Toolbar Buttons - Base (Touch-friendly minimum size) */
.pdf-toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
    background: white;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-lg);
    color: var(--gray-700);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    position: relative;
    overflow: hidden;
    /* Prevent double-tap zoom on iOS */
    touch-action: manipulation;
    -ms-touch-action: manipulation;
}

.pdf-toolbar-btn:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.pdf-toolbar-btn:active {
    background: var(--gray-100);
    transform: translateY(0) scale(0.98);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.1s ease-out, background 0.1s ease-out;
}

/* Focus state for accessibility */
.pdf-toolbar-btn:focus-visible {
    outline: 3px solid var(--primary-500);
    outline-offset: 2px;
    border-color: var(--primary-500);
}

/* Disabled state */
.pdf-toolbar-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
    background: var(--gray-100);
    color: var(--gray-400);
}

/* Loading state for buttons */
.pdf-toolbar-btn.loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.pdf-toolbar-btn.loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid var(--gray-400);
    border-top-color: var(--primary-500);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.pdf-toolbar-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.pdf-toolbar-btn i {
    font-size: 0.875rem;
    pointer-events: none;
}

/* PDF Toolbar Container */
#pdf-toolbar,
.pdf-toolbar-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--gray-100);
    border-bottom: 1px solid var(--gray-200);
    flex-wrap: wrap;
    flex-shrink: 0;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--gray-300) var(--gray-100);
    -webkit-overflow-scrolling: touch;
}

#pdf-toolbar::-webkit-scrollbar,
.pdf-toolbar-container::-webkit-scrollbar {
    height: 6px;
}

#pdf-toolbar::-webkit-scrollbar-track,
.pdf-toolbar-container::-webkit-scrollbar-track {
    background: var(--gray-100);
}

#pdf-toolbar::-webkit-scrollbar-thumb,
.pdf-toolbar-container::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 3px;
}

#pdf-toolbar::-webkit-scrollbar-thumb:hover,
.pdf-toolbar-container::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

#pdf-toolbar>div,
.pdf-toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    white-space: nowrap;
    flex-shrink: 0;
}

/* PDF Canvas Container */
#pdf-canvas-container {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none;
    width: 100%;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem 0.5rem;
}

#pdf-canvas-container canvas {
    display: block;
    margin: 0 auto 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    max-width: 100%;
    height: auto;
    /* Touch gestures support - allow pinch-zoom and pan */
    touch-action: pan-x pan-y pinch-zoom;
    -ms-touch-action: pan-x pan-y pinch-zoom;
    /* Security: Prevent selection and drag */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none;
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    pointer-events: auto;
    /* Smooth transitions for zoom */
    transition: transform 0.1s ease-out;
}

/* PDF Viewer Container - Prevent text selection and drag */
#pdf-viewer-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: auto;
    background: var(--gray-200);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none;
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    /* Touch gestures support */
    touch-action: pan-x pan-y pinch-zoom;
    /* Prevent double-tap zoom on iOS */
    -ms-touch-action: pan-x pan-y pinch-zoom;
    /* Smooth scrolling */
    scroll-behavior: smooth;
    /* Better scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: var(--gray-400) var(--gray-200);
}

/* Custom scrollbar for PDF viewer */
#pdf-viewer-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#pdf-viewer-container::-webkit-scrollbar-track {
    background: var(--gray-200);
    border-radius: 4px;
}

#pdf-viewer-container::-webkit-scrollbar-thumb {
    background: var(--gray-400);
    border-radius: 4px;
    transition: background 0.2s ease;
}

#pdf-viewer-container::-webkit-scrollbar-thumb:hover {
    background: var(--gray-500);
}

/* Mobile scrollbar adjustments */
@media (max-width: 767px) {
    #pdf-viewer-container::-webkit-scrollbar {
        width: 6px;
        height: 6px;
    }
}

/* PDF Page Input and Select */
#pdf-page-input,
#pdf-zoom-select {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    background: white;
    color: var(--gray-700);
    min-height: 44px;
    touch-action: manipulation;
    transition: all var(--transition-fast);
}

#pdf-page-input:focus,
#pdf-zoom-select:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#pdf-zoom-select {
    min-width: 120px;
    cursor: pointer;
}

/* Touch-friendly styles */
.touch-manipulation {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

/* ==================== RESPONSIVE DESIGN - DESKTOP (>1024px) ==================== */
@media (min-width: 1025px) {

    /* Desktop: Full toolbar with all features */
    #pdf-toolbar,
    .pdf-toolbar-container {
        padding: 0.75rem 1.5rem;
        gap: 1rem;
        flex-wrap: nowrap;
    }

    .pdf-toolbar-group {
        gap: 0.75rem;
        flex-shrink: 0;
    }

    .pdf-toolbar-btn {
        padding: 0.625rem 1rem;
        min-width: auto;
        min-height: auto;
        font-size: 0.875rem;
        white-space: nowrap;
    }

    .pdf-toolbar-btn i {
        font-size: 1rem;
    }

    /* Show all labels on desktop */
    .pdf-toolbar-label {
        display: inline !important;
    }

    #pdf-toolbar>div {
        gap: 0.75rem;
    }

    #pdf-canvas-container {
        padding: 1.5rem;
    }

    #pdf-canvas-container canvas {
        margin-bottom: 1.5rem;
        max-width: 100%;
    }

    /* Desktop: Show all buttons */
    .pdf-toolbar-btn-rotate,
    .pdf-toolbar-btn-print {
        display: inline-flex !important;
    }

    /* Desktop: Better hover effects */
    .pdf-toolbar-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    }
}

/* ==================== RESPONSIVE DESIGN - TABLET (768px-1024px) ==================== */
@media (min-width: 768px) and (max-width: 1024px) {

    /* Tablet: Compact toolbar, show rotate buttons */
    #pdf-toolbar,
    .pdf-toolbar-container {
        padding: 0.625rem 1rem;
        gap: 0.75rem;
        flex-wrap: wrap;
    }

    .pdf-toolbar-group {
        gap: 0.5rem;
        flex-shrink: 0;
    }

    .pdf-toolbar-btn {
        padding: 0.5rem 0.75rem;
        min-width: 44px;
        min-height: 44px;
        font-size: 0.8125rem;
        touch-action: manipulation;
    }

    .pdf-toolbar-btn i {
        font-size: 0.875rem;
    }

    /* Show rotate buttons on tablet */
    .pdf-toolbar-btn-rotate {
        display: inline-flex !important;
    }

    /* Show print button on tablet */
    .pdf-toolbar-btn-print {
        display: inline-flex !important;
    }

    /* Hide text labels on tablet (icons only) */
    .pdf-toolbar-label {
        display: none !important;
    }

    #pdf-zoom-select {
        font-size: 0.8125rem;
        padding: 0.5rem 0.625rem;
        min-width: 120px;
        min-height: 44px;
        touch-action: manipulation;
    }

    #pdf-page-input {
        width: 3.5rem;
        font-size: 0.8125rem;
        padding: 0.5rem 0.375rem;
        min-height: 44px;
        touch-action: manipulation;
    }

    #pdf-canvas-container {
        padding: 1rem;
    }

    #pdf-canvas-container canvas {
        max-width: 100%;
        margin-bottom: 1.25rem;
    }

    /* Tablet: Better touch feedback */
    .pdf-toolbar-btn:active {
        transform: scale(0.97);
        background: var(--gray-100);
    }

    /* PDF Modal Header - Tablet */
    #pdf-modal>div:first-child {
        padding: 0.625rem 1rem;
        min-height: 48px;
    }

    #pdf-modal>div:first-child h3 {
        font-size: 1rem;
    }
}

/* ==================== RESPONSIVE DESIGN - MOBILE (<768px) ==================== */
@media (max-width: 767px) {

    /* Mobile: Minimal toolbar, larger touch targets, hide secondary features */
    #pdf-modal {
        height: 100vh;
        max-height: 100vh;
        overflow: hidden;
    }

    #pdf-toolbar,
    .pdf-toolbar-container {
        padding: 0.5rem;
        gap: 0.5rem;
        flex-wrap: wrap;
        justify-content: space-between;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .pdf-toolbar-group {
        flex: 1 1 auto;
        justify-content: center;
        min-width: 0;
        gap: 0.5rem;
        flex-wrap: nowrap;
    }

    /* Hide rotate and print buttons on mobile */
    .pdf-toolbar-btn-rotate,
    .pdf-toolbar-btn-print {
        display: none !important;
    }

    .pdf-toolbar-btn {
        padding: 0.625rem 0.75rem;
        min-width: 44px;
        min-height: 44px;
        font-size: 0.75rem;
        flex: 0 1 auto;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(59, 130, 246, 0.2);
        user-select: none;
        -webkit-user-select: none;
        /* Better spacing for touch */
        margin: 0.125rem;
    }

    /* Hide text labels on mobile, show icons only */
    .pdf-toolbar-label {
        display: none !important;
    }

    .pdf-toolbar-btn i {
        font-size: 0.875rem;
    }

    /* Touch feedback for mobile buttons */
    .pdf-toolbar-btn:active {
        background: var(--primary-100);
        border-color: var(--primary-400);
        transform: scale(0.95);
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    /* Smaller zoom select on mobile */
    #pdf-zoom-select {
        font-size: 0.75rem;
        padding: 0.5rem 0.625rem;
        min-width: 100px;
        min-height: 44px;
        flex: 1 1 auto;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(59, 130, 246, 0.2);
    }

    /* Smaller page input on mobile */
    #pdf-page-input {
        width: 3rem;
        font-size: 0.75rem;
        padding: 0.5rem 0.375rem;
        min-height: 44px;
        text-align: center;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(59, 130, 246, 0.2);
    }

    #pdf-canvas-container {
        padding: 0.75rem 0.5rem;
        -webkit-overflow-scrolling: touch;
    }

    #pdf-canvas-container canvas {
        margin-bottom: 1rem;
        max-width: calc(100% - 0.5rem);
        touch-action: pan-x pan-y pinch-zoom;
        -ms-touch-action: pan-x pan-y pinch-zoom;
    }

    /* PDF Header - Mobile optimization */
    #pdf-modal>div:first-child {
        padding: 0.5rem 0.75rem;
        height: auto;
        min-height: 48px;
        flex-shrink: 0;
    }

    #pdf-modal>div:first-child h3 {
        font-size: 0.875rem;
        line-height: 1.4;
    }

    #pdf-modal>div:first-child button {
        min-width: 44px;
        min-height: 44px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(239, 68, 68, 0.2);
    }

    /* PDF Loader - Mobile */
    #pdf-loader {
        padding: 0.5rem;
    }

    #pdf-loader>div {
        padding: 1rem;
        max-width: 95%;
    }

    #pdf-loader>div>div {
        width: 2.5rem;
        height: 2.5rem;
        margin-bottom: 0.75rem;
    }

    #pdf-loader>div p:first-of-type {
        font-size: 0.9375rem;
    }

    #pdf-loader>div>div[class*="bg-gray-200"] {
        width: 12rem;
        height: 0.375rem;
    }

    #pdf-progress-text {
        font-size: 0.75rem;
    }

    /* PDF Error - Mobile */
    #pdf-error {
        padding: 0.75rem;
    }

    #pdf-error>div {
        padding: 1.25rem;
        max-width: 95%;
    }

    #pdf-error>div i {
        font-size: 2.5rem;
        margin-bottom: 0.75rem;
    }

    #pdf-error>div p:first-of-type {
        font-size: 1rem;
    }

    #pdf-error-message {
        font-size: 0.8125rem;
    }

    #pdf-error>div button {
        padding: 0.75rem 1.5rem;
        font-size: 0.875rem;
        min-width: 44px;
        min-height: 44px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(239, 68, 68, 0.2);
    }
}

/* ==================== RESPONSIVE DESIGN - SMALL MOBILE (<480px) ==================== */
@media (max-width: 479px) {

    /* Extra small screens: Stack toolbar groups vertically */
    #pdf-toolbar,
    .pdf-toolbar-container {
        flex-direction: column;
        align-items: stretch;
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .pdf-toolbar-group {
        justify-content: center;
        margin-bottom: 0.375rem;
        width: 100%;
        gap: 0.5rem;
    }

    .pdf-toolbar-group:last-child {
        margin-bottom: 0;
    }

    .pdf-toolbar-btn {
        flex: 1 1 auto;
        min-width: 44px;
        min-height: 44px;
        padding: 0.625rem;
        font-size: 0.75rem;
    }

    .pdf-toolbar-btn i {
        font-size: 0.8125rem;
    }

    #pdf-zoom-select {
        flex: 1 1 auto;
        min-width: auto;
        width: 100%;
        min-height: 44px;
        font-size: 0.75rem;
        padding: 0.5rem;
    }

    #pdf-page-input {
        width: 2.75rem;
        min-height: 44px;
        font-size: 0.75rem;
        padding: 0.5rem 0.375rem;
    }

    #pdf-canvas-container {
        padding: 0.5rem 0.25rem;
    }

    #pdf-canvas-container canvas {
        max-width: calc(100% - 0.25rem);
        margin-bottom: 0.75rem;
    }

    /* PDF Header - Extra small mobile */
    #pdf-modal>div:first-child {
        padding: 0.5rem;
        min-height: 44px;
        flex-wrap: wrap;
    }

    #pdf-modal>div:first-child h3 {
        font-size: 0.8125rem;
        flex: 1 1 auto;
        min-width: 0;
    }

    #pdf-modal>div:first-child button {
        min-width: 40px;
        min-height: 40px;
        padding: 0.5rem;
        flex-shrink: 0;
    }

    /* Better touch targets for very small screens */
    .pdf-toolbar-btn {
        min-width: 48px;
        min-height: 48px;
    }

    /* Increase spacing between buttons */
    .pdf-toolbar-group {
        gap: 0.625rem;
    }
}

/* ==================== TOUCH GESTURES SUPPORT ==================== */
/* Touch feedback for buttons - Enhanced visual feedback */
@media (hover: none) and (pointer: coarse) {

    /* Touch device styles */
    .pdf-toolbar-btn {
        min-width: 44px;
        min-height: 44px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(59, 130, 246, 0.2);
        user-select: none;
        -webkit-user-select: none;
        transition: all 0.15s ease-out;
    }

    .pdf-toolbar-btn:active {
        background: var(--primary-100);
        border-color: var(--primary-400);
        transform: scale(0.95);
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    .pdf-toolbar-btn:focus {
        outline: 2px solid var(--primary-500);
        outline-offset: 2px;
    }

    #pdf-viewer-container {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        touch-action: pan-x pan-y pinch-zoom;
    }

    #pdf-canvas-container {
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x pan-y pinch-zoom;
    }

    #pdf-canvas-container canvas {
        touch-action: pan-x pan-y pinch-zoom;
        -ms-touch-action: pan-x pan-y pinch-zoom;
    }

    /* Input fields on touch devices */
    #pdf-page-input,
    #pdf-zoom-select {
        min-height: 44px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(59, 130, 246, 0.2);
        font-size: 16px;
        /* Prevent zoom on iOS */
    }

    /* Better spacing for touch targets */
    .pdf-toolbar-group {
        gap: 0.5rem;
    }
}

/* Touch device detection - extra spacing between buttons */
@media (max-width: 767px) and (hover: none) and (pointer: coarse) {

    #pdf-toolbar,
    .pdf-toolbar-container {
        gap: 0.625rem;
        padding: 0.625rem 0.5rem;
    }

    .pdf-toolbar-group {
        gap: 0.625rem;
    }

    .pdf-toolbar-btn {
        margin: 0.125rem;
        min-width: 48px;
        min-height: 48px;
    }

    /* Prevent text selection on touch */
    #pdf-toolbar,
    #pdf-toolbar * {
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        -webkit-touch-callout: none;
    }
}

/* Enhanced touch feedback animations */
@media (hover: none) and (pointer: coarse) {
    .pdf-toolbar-btn {
        position: relative;
        overflow: hidden;
    }

    .pdf-toolbar-btn::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        border-radius: 50%;
        background: rgba(59, 130, 246, 0.2);
        transform: translate(-50%, -50%);
        transition: width 0.3s ease-out, height 0.3s ease-out, opacity 0.3s ease-out;
        pointer-events: none;
        opacity: 0;
    }

    .pdf-toolbar-btn:active::after {
        width: 200px;
        height: 200px;
        opacity: 1;
    }

    /* Ripple effect for better visual feedback */
    .pdf-toolbar-btn:active {
        transition: transform 0.1s ease-out, background 0.1s ease-out, box-shadow 0.1s ease-out;
    }
}

/* ==================== ORIENTATION SUPPORT ==================== */
/* Landscape orientation adjustments */
@media (max-width: 767px) and (orientation: landscape) {
    #pdf-modal {
        height: 100vh;
        max-height: 100vh;
    }

    #pdf-toolbar,
    .pdf-toolbar-container {
        padding: 0.375rem 0.5rem;
        gap: 0.375rem;
        flex-wrap: nowrap;
    }

    .pdf-toolbar-group {
        gap: 0.375rem;
        flex-shrink: 0;
    }

    .pdf-toolbar-btn {
        padding: 0.5rem 0.625rem;
        min-width: 44px;
        min-height: 44px;
        font-size: 0.75rem;
    }

    #pdf-zoom-select {
        min-width: 90px;
        font-size: 0.75rem;
        padding: 0.5rem 0.5rem;
    }

    #pdf-page-input {
        width: 2.75rem;
        font-size: 0.75rem;
        padding: 0.5rem 0.25rem;
    }

    #pdf-canvas-container {
        padding: 0.5rem;
    }

    #pdf-canvas-container canvas {
        margin-bottom: 0.75rem;
    }

    /* PDF Header - Landscape */
    #pdf-modal>div:first-child {
        padding: 0.375rem 0.5rem;
        min-height: 44px;
    }

    #pdf-modal>div:first-child h3 {
        font-size: 0.8125rem;
    }
}

/* Portrait orientation - more vertical space */
@media (max-width: 767px) and (orientation: portrait) {

    #pdf-toolbar,
    .pdf-toolbar-container {
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .pdf-toolbar-group {
        gap: 0.5rem;
    }

    #pdf-canvas-container {
        padding: 1rem 0.5rem;
    }

    #pdf-canvas-container canvas {
        margin-bottom: 1rem;
    }

    /* PDF Header - Portrait */
    #pdf-modal>div:first-child {
        padding: 0.5rem 0.75rem;
        min-height: 48px;
    }
}

/* Orientation change animation */
@media (max-width: 767px) {

    #pdf-modal,
    #pdf-toolbar,
    #pdf-canvas-container {
        transition: padding 0.3s ease-out, gap 0.3s ease-out;
    }
}

/* Tablet orientation support */
@media (min-width: 768px) and (max-width: 1024px) {
    /* Landscape tablet */
    @media (orientation: landscape) {

        #pdf-toolbar,
        .pdf-toolbar-container {
            padding: 0.5rem 1rem;
            gap: 0.625rem;
        }

        .pdf-toolbar-btn {
            padding: 0.5rem 0.75rem;
            min-width: 44px;
            min-height: 44px;
        }

        #pdf-canvas-container {
            padding: 0.75rem;
        }
    }

    /* Portrait tablet */
    @media (orientation: portrait) {

        #pdf-toolbar,
        .pdf-toolbar-container {
            padding: 0.625rem 1rem;
            gap: 0.75rem;
        }

        #pdf-canvas-container {
            padding: 1rem;
        }
    }
}

/* ==================== ADAPTIVE LAYOUT ==================== */
/* Flexible layout that adapts to screen size */
#pdf-toolbar,
.pdf-toolbar-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    box-sizing: border-box;
}

/* Ensure buttons don't shrink too much */
.pdf-toolbar-btn {
    flex-shrink: 0;
    white-space: nowrap;
}

.pdf-toolbar-group {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    flex-shrink: 0;
}

/* Page number display - responsive */
#pdf-toolbar span,
.pdf-toolbar-container span {
    white-space: nowrap;
    font-size: 0.875rem;
    color: var(--gray-600);
    user-select: none;
    -webkit-user-select: none;
}

@media (max-width: 767px) {

    #pdf-toolbar span,
    .pdf-toolbar-container span {
        font-size: 0.75rem;
    }
}

/* Adaptive font sizes */
@media (min-width: 1025px) {

    #pdf-toolbar span,
    .pdf-toolbar-container span {
        font-size: 0.875rem;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {

    #pdf-toolbar span,
    .pdf-toolbar-container span {
        font-size: 0.8125rem;
    }
}

/* Adaptive toolbar groups - stack on small screens */
@media (max-width: 640px) {
    .pdf-toolbar-group {
        flex: 1 1 100%;
        justify-content: center;
        margin-bottom: 0.25rem;
    }

    .pdf-toolbar-group:last-child {
        margin-bottom: 0;
    }
}

/* Better spacing for toolbar groups */
.pdf-toolbar-group+.pdf-toolbar-group {
    margin-left: 0.5rem;
}

@media (max-width: 767px) {
    .pdf-toolbar-group+.pdf-toolbar-group {
        margin-left: 0;
    }
}

/* Adaptive font sizes based on viewport */
@media (max-width: 480px) {

    #pdf-toolbar,
    .pdf-toolbar-container {
        font-size: 0.75rem;
    }

    .pdf-toolbar-btn {
        font-size: 0.6875rem;
    }

    .pdf-toolbar-btn i {
        font-size: 0.8125rem;
    }
}

/* Grid layout for very small screens */
@media (max-width: 360px) {

    #pdf-toolbar,
    .pdf-toolbar-container {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .pdf-toolbar-group {
        grid-column: 1 / -1;
        justify-content: center;
    }

    .pdf-toolbar-group:last-child {
        grid-column: 1 / -1;
    }
}

/* Responsive container adjustments */
#pdf-viewer-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: auto;
    position: relative;
}

#pdf-canvas-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    min-height: 100%;
    box-sizing: border-box;
}

/* Smooth transitions for responsive changes */
#pdf-toolbar,
.pdf-toolbar-container,
.pdf-toolbar-btn,
#pdf-zoom-select,
#pdf-page-input {
    transition: padding 0.2s ease-out,
        font-size 0.2s ease-out,
        min-width 0.2s ease-out,
        min-height 0.2s ease-out,
        gap 0.2s ease-out;
}

/* PDF Modal Header - Responsive */
#pdf-modal>div:first-child {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    min-height: 48px;
}

#pdf-modal>div:first-child h3 {
    font-weight: 700;
    color: var(--gray-800);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

#pdf-modal>div:first-child h3 i {
    color: var(--danger-500);
    flex-shrink: 0;
}

#pdf-modal>div:first-child button {
    flex-shrink: 0;
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

/* PDF Loader - Responsive */
#pdf-loader {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 20;
}

#pdf-loader>div {
    text-align: center;
    padding: 1.5rem;
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--gray-100);
    max-width: 90%;
}

#pdf-loader>div>div {
    display: inline-block;
    width: 3rem;
    height: 3rem;
    border: 4px solid var(--gray-200);
    border-top-color: var(--primary-500);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

#pdf-loader>div p:first-of-type {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 0.5rem;
}

#pdf-loader>div>div[class*="bg-gray-200"] {
    width: 16rem;
    max-width: 100%;
    height: 0.5rem;
    background: var(--gray-200);
    border-radius: var(--radius-full);
    margin: 1rem auto 0;
    overflow: hidden;
}

#pdf-progress-bar {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    transition: width 0.3s ease-out;
}

#pdf-progress-text {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin-top: 0.5rem;
}

/* PDF Error Display - Responsive */
#pdf-error {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.95);
    z-index: 20;
    padding: 1rem;
}

#pdf-error>div {
    text-align: center;
    padding: 1.5rem;
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--danger-200);
    max-width: 90%;
    width: 100%;
}

#pdf-error>div i {
    color: var(--danger-500);
    font-size: 3rem;
    margin-bottom: 1rem;
}

#pdf-error>div p:first-of-type {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 0.5rem;
}

#pdf-error-message {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin-bottom: 1rem;
    word-break: break-word;
}

#pdf-error>div button {
    padding: 0.625rem 1.25rem;
    background: var(--danger-500);
    color: white;
    border-radius: var(--radius-lg);
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
}

#pdf-error>div button:hover {
    background: var(--danger-600);
    transform: translateY(-1px);
}

#pdf-error>div button:active {
    transform: translateY(0);
}

/* PDF Loading Animation */
@keyframes pdfFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#pdf-canvas-container canvas {
    animation: pdfFadeIn 0.3s ease-out;
}

.modal-content {
    background: white;
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-2xl);
    animation: scaleIn 0.3s ease-out;
}

/* ==================== ALERTS & TOASTS ==================== */
.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-xl);
    border: 1px solid transparent;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.alert-error {
    background: var(--danger-50);
    border-color: var(--danger-100);
    color: var(--danger-600);
}

.alert-success {
    background: var(--success-50);
    border-color: var(--success-100);
    color: var(--success-600);
}

.alert-warning {
    background: var(--warning-50);
    border-color: var(--warning-100);
    color: var(--warning-600);
}

.alert-info {
    background: var(--info-50);
    border-color: var(--info-100);
    color: var(--info-600);
}

/* ==================== BADGES ==================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-full);
    white-space: nowrap;
}

.badge-primary {
    background: var(--primary-100);
    color: var(--primary-700);
}

.badge-success {
    background: var(--success-100);
    color: var(--success-700);
}

.badge-warning {
    background: var(--warning-100);
    color: var(--warning-600);
}

.badge-danger {
    background: var(--danger-100);
    color: var(--danger-600);
}

.badge-info {
    background: var(--info-100);
    color: var(--info-600);
}

/* ==================== PROGRESS BARS ==================== */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--gray-200);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    transition: width var(--transition-slow);
}

.progress-bar-success .progress-bar-fill {
    background: var(--gradient-success);
}

/* ==================== GAME LAYER ==================== */
#game-layer-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    background: var(--gray-900);
    color: white;
    display: none;
}

#game-video-layer {
    transform: scaleX(-1);
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.6;
    position: absolute;
    display: block;
}

#gameCanvas {
    transform: scaleX(-1);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    cursor: pointer;
}

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    padding: 15px;
    box-sizing: border-box;
}

#ui-overlay.mode-touch {
    justify-content: space-between;
}

#ui-overlay.mode-camera {
    justify-content: flex-end;
    gap: 10px;
}

.hud-panel {
    background: rgba(0, 0, 0, 0.9);
    border-radius: var(--radius-2xl);
    padding: 1rem;
    pointer-events: auto;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* ==================== ANSWER BOXES ==================== */
.answer-box {
    background: rgba(255, 255, 255, 0.98);
    color: var(--gray-800);
    padding: 1rem;
    border-radius: var(--radius-xl);
    font-size: 1rem;
    display: flex;
    align-items: center;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all var(--transition-fast);
    height: auto;
    min-height: 80px;
    pointer-events: auto;
    cursor: pointer;
    overflow: hidden;
    word-wrap: break-word;
    border: 2px solid transparent;
}

.answer-box:hover {
    transform: scale(1.02);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.answer-box:active {
    transform: scale(0.98);
    background: var(--gray-100);
}

.answer-box img {
    max-height: 80px;
    max-width: 100%;
    object-fit: contain;
    border-radius: var(--radius-sm);
    margin: 0 auto;
}

.choice-badge {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-right: 0.875rem;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    font-size: 1.125rem;
}

/* ==================== BADGE COLORS ==================== */
.bg-A {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

.bg-B {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
}

.bg-C {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.bg-D {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

/* ==================== CONTENT IMAGES ==================== */
.content-image {
    max-height: 200px;
    border-radius: var(--radius-lg);
    cursor: zoom-in;
    border: 2px solid var(--gray-200);
    margin: 0.5rem auto;
    display: block;
    background: white;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.content-image:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-300);
}

/* ==================== READING SCREEN ==================== */
#reading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    transition: opacity 0.5s;
    padding: 20px;
    box-sizing: border-box;
}

#reading-screen.mode-camera {
    justify-content: flex-end;
    padding-bottom: 5vh;
}

#reading-screen.mode-touch {
    justify-content: flex-start;
    padding-top: 5vh;
}

#reading-content {
    background: rgba(17, 24, 39, 0.98);
    padding: 2rem;
    border-radius: var(--radius-2xl);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    max-width: 95%;
    width: 1000px;
    pointer-events: auto;
    max-height: 55vh;
    overflow-y: auto;
    margin-bottom: 1rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* ==================== SWAL OVERRIDE ==================== */
.swal2-container {
    z-index: 100000 !important;
}

.swal2-popup {
    border-radius: var(--radius-2xl) !important;
    box-shadow: var(--shadow-2xl) !important;
}

.swal2-confirm {
    border-radius: var(--radius-xl) !important;
    background: var(--gradient-primary) !important;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4) !important;
}

.swal2-cancel {
    border-radius: var(--radius-xl) !important;
}

/* ==================== TABLE STYLES ==================== */
.table-container {
    border-radius: var(--radius-xl);
    overflow: hidden;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    background: linear-gradient(180deg, var(--gray-50) 0%, var(--gray-100) 100%);
    padding: 0.875rem 1rem;
    font-weight: 600;
    color: var(--gray-700);
    text-align: left;
    border-bottom: 2px solid var(--gray-200);
}

.data-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
}

.data-table tr:hover {
    background: var(--gray-50);
}

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

.sticky-header thead {
    position: sticky;
    top: 0;
    z-index: 30;
}

.sticky-header thead th {
    background: var(--gray-50);
}

.sticky-column-1 {
    position: sticky;
    left: 0;
    z-index: 20;
    background: inherit;
}

.sticky-column-2 {
    position: sticky;
    left: 5rem;
    z-index: 20;
    background: inherit;
}

/* ==================== STATS CARDS ==================== */
.stats-card {
    padding: 1.25rem;
    border-radius: var(--radius-xl);
    background: white;
    border: 1px solid var(--gray-100);
    transition: all var(--transition-base);
}

.stats-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stats-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stats-label {
    font-size: 0.875rem;
    color: var(--gray-500);
}

/* ==================== SUBJECT CARDS ==================== */
.subject-card {
    position: relative;
    padding: 1.5rem;
    border-radius: var(--radius-2xl);
    background: white;
    border: 1px solid var(--gray-200);
    transition: all var(--transition-base);
    overflow: hidden;
    cursor: pointer;
}

.subject-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 6px;
    background: var(--gradient-primary);
}

.subject-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-xl), var(--shadow-glow-primary);
    border-color: var(--primary-200);
}

.subject-card-icon {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: var(--radius-xl);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1rem;
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* ==================== LESSON ITEMS ==================== */
.lesson-item {
    padding: 1rem;
    border-radius: var(--radius-xl);
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    transition: all var(--transition-fast);
    cursor: pointer;
}

.lesson-item:hover {
    background: white;
    border-color: var(--primary-300);
    box-shadow: var(--shadow-md);
    transform: translateX(4px);
}

.lesson-item.completed {
    background: var(--success-50);
    border-color: rgba(16, 185, 129, 0.3);
}

.lesson-item.locked {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ==================== CONFIRMATION SECTION ==================== */
.confirmation-card {
    background: linear-gradient(135deg, var(--info-50) 0%, var(--primary-50) 100%);
    border: 1px solid var(--primary-200);
    border-radius: var(--radius-2xl);
    padding: 2rem;
    text-align: center;
    animation: scaleIn 0.4s ease-out;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    :root {
        --space-4: 0.75rem;
        --space-6: 1rem;
        --space-8: 1.5rem;
    }

    .btn {
        padding: 0.625rem 1.25rem;
        font-size: 0.9375rem;
    }

    .card {
        border-radius: var(--radius-xl);
    }

    .subject-card {
        padding: 1.25rem;
    }

    .stats-value {
        font-size: 1.5rem;
    }
}

@media (max-width: 640px) {
    .sticky-column-2 {
        position: static;
    }

    body {
        background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
        animation: none;
    }

    .tabs-container {
        padding: 0.125rem;
    }

    .tab {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
}

/* ==================== PRINT STYLES ==================== */
@media print {
    body {
        background: white !important;
        animation: none !important;
    }

    .no-print {
        display: none !important;
    }

    .print-break {
        page-break-after: always;
    }

    .card,
    #app-container {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}

/* ==================== ACCESSIBILITY ==================== */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    body {
        animation: none;
    }
}

/* Focus states for accessibility */
*:focus-visible {
    outline: 3px solid var(--primary-500);
    outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid var(--primary-500);
    outline-offset: 2px;
}

/* ==================== UTILITY CLASSES ==================== */
.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-3 {
    gap: 0.75rem;
}

.gap-4 {
    gap: 1rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mt-6 {
    margin-top: 1.5rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.mb-6 {
    margin-bottom: 1.5rem;
}

.p-4 {
    padding: 1rem;
}

.p-6 {
    padding: 1.5rem;
}

.px-4 {
    padding-left: 1rem;
    padding-right: 1rem;
}

.py-3 {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
}

.rounded-xl {
    border-radius: var(--radius-xl);
}

.rounded-2xl {
    border-radius: var(--radius-2xl);
}

.rounded-full {
    border-radius: var(--radius-full);
}

.shadow-md {
    box-shadow: var(--shadow-md);
}

.shadow-lg {
    box-shadow: var(--shadow-lg);
}

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

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hidden {
    display: none !important;
}

.opacity-0 {
    opacity: 0;
}

.opacity-100 {
    opacity: 1;
}

.transition-all {
    transition: all var(--transition-base);
}

.cursor-pointer {
    cursor: pointer;
}

.cursor-not-allowed {
    cursor: not-allowed;
}

.relative {
    position: relative;
}

.absolute {
    position: absolute;
}

.fixed {
    position: fixed;
}

.inset-0 {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
}

.w-full {
    width: 100%;
}

.h-full {
    height: 100%;
}

.min-h-screen {
    min-height: 100vh;
}

.overflow-hidden {
    overflow: hidden;
}

.overflow-auto {
    overflow: auto;
}

.overflow-x-auto {
    overflow-x: auto;
}

.border {
    border: 1px solid var(--gray-200);
}

.border-b {
    border-bottom: 1px solid var(--gray-200);
}

/* ==================== PIN INPUT STYLES ==================== */
/* Custom styles for PIN input fields */
.pin-input {
    width: 3.5rem;
    /* Increased size */
    height: 4rem;
    text-align: center;
    font-size: 1.75rem;
    font-weight: 600;
    color: #1f2937;
    /* gray-800 */
    background-color: #f9fafb;
    /* gray-50 */
    border-radius: 0.75rem;
    /* More rounded */
    border: 2px solid #e5e7eb;
    /* gray-200 */
    transition: all 0.2s ease-in-out;
    caret-color: #3b82f6;
    /* blue-500 */
}

.pin-input:focus {
    outline: none;
    border-color: #3b82f6;
    /* blue-500 */
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
    transform: scale(1.05);
}

/* Hide number input spinners */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
}

/* Spinner animation */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.spinner {
    animation: spin 1s linear infinite;
}

/* Content block styles for complex content (HTML, images) */
.content-block {
    line-height: 1.6;
    width: 100%;
}

.content-block img {
    max-width: 100%;
    height: auto;
    margin-top: 0.5rem;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
}

.content-block a {
    color: #2563eb;
    /* blue-600 */
    text-decoration: underline;
    transition: color 0.2s;
}

.content-block a:hover {
    color: #1d4ed8;
    /* blue-700 */
}

/* ==================== FLOATING CHAT WIDGET ==================== */

/* Chat Widget Container */
.chat-widget-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Floating Toggle Button */
.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 8px 32px rgba(59, 130, 246, 0.4), 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    /* overflow: hidden; -- Removed to allow badge to show */
}

.chat-toggle-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%);
    border-radius: 50%;
}

.chat-toggle-btn:hover {
    transform: scale(1.1) translateY(-4px);
    box-shadow: 0 12px 40px rgba(59, 130, 246, 0.5), 0 8px 20px rgba(0, 0, 0, 0.2);
}

.chat-toggle-btn:active {
    transform: scale(0.95);
}

.chat-toggle-btn.active {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    box-shadow: 0 8px 32px rgba(220, 38, 38, 0.4);
}

.chat-toggle-btn.active i::before {
    content: "\f00d";
    /* fa-xmark */
}

/* Unread Badge */
.chat-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.5);
    animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

/* Chat Box */
.chat-box {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 550px;
    max-height: calc(100vh - 140px);
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 8px 24px rgba(59, 130, 246, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(59, 130, 246, 0.1);
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    pointer-events: none;
}

.chat-box.chat-box-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 42px;
    height: 42px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.chat-header-info h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: white;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    opacity: 0.9;
}

.chat-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    animation: pulse-dot 2s infinite;
}

.chat-status-dot.online {
    background: #22c55e;
}

@keyframes pulse-dot {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.chat-action-btn {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 10px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

/* Chat Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
    display: flex;
    flex-direction: column;
}

.chat-messages-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Load More Button */
.chat-load-more {
    text-align: center;
    padding: 8px;
    margin-bottom: 12px;
}

.chat-load-more button {
    padding: 8px 16px;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 999px;
    color: #3b82f6;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.chat-load-more button:hover {
    background: rgba(59, 130, 246, 0.2);
}

/* Message Styles */
.chat-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 85%;
    animation: slideUp 0.3s ease-out;
}

.chat-message.mine {
    flex-direction: row-reverse;
    margin-left: auto;
}

.chat-message.deleted {
    max-width: 100%;
    opacity: 0.6;
}

.chat-message-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.chat-message.teacher-msg .chat-message-avatar {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
}

.chat-message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.chat-message-sender {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: #64748b;
    padding-left: 4px;
}

.chat-sender-name {
    font-weight: 500;
}

.chat-sender-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
}

.chat-sender-badge.teacher {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    color: #92400e;
}

.chat-delete-btn {
    margin-left: auto;
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: #94a3b8;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s;
}

.chat-message:hover .chat-delete-btn {
    opacity: 1;
}

.chat-delete-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.chat-message-bubble {
    padding: 12px 16px;
    background: white;
    border-radius: 18px;
    border-top-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.chat-message.mine .chat-message-bubble {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border-top-left-radius: 18px;
    border-top-right-radius: 4px;
    border: none;
}

.chat-message.teacher-msg .chat-message-bubble {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-color: rgba(251, 191, 36, 0.2);
}

.chat-message-text {
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.5;
    font-size: 0.95rem;
}

.chat-message-text a {
    color: inherit;
    text-decoration: underline;
    opacity: 0.9;
}

.chat-message-image {
    margin-bottom: 8px;
}

.chat-message-image img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s;
}

.chat-message-image img:hover {
    transform: scale(1.02);
}

.chat-message-time {
    font-size: 0.65rem;
    color: #94a3b8;
    padding-left: 4px;
}

.chat-message.mine .chat-message-time {
    text-align: right;
    padding-right: 4px;
    padding-left: 0;
}

.chat-message-deleted {
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 12px;
    color: #94a3b8;
    font-size: 0.85rem;
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Typing Indicator */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    margin-top: 8px;
}

.chat-typing-dots {
    display: flex;
    gap: 4px;
}

.chat-typing-dots span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite both;
}

.chat-typing-dots span:nth-child(2) {
    animation-delay: 0.16s;
}

.chat-typing-dots span:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes typing-bounce {

    0%,
    80%,
    100% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

#chat-typing-text {
    font-size: 0.8rem;
    color: #64748b;
    font-style: italic;
}

/* Image Preview */
.chat-image-preview {
    padding: 12px 16px;
    background: #f1f5f9;
    border-top: 1px solid #e2e8f0;
    position: relative;
}

.chat-image-preview img {
    max-width: 100%;
    max-height: 120px;
    border-radius: 12px;
    object-fit: contain;
}

.chat-remove-image {
    position: absolute;
    top: 8px;
    right: 20px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-remove-image:hover {
    background: #ef4444;
    transform: scale(1.1);
}

/* Input Area */
.chat-input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.chat-input-container.paused-mode {
    background: #f8fafc;
    opacity: 0.8;
}

.chat-input-container.paused-mode #chat-input {
    background: #e2e8f0;
    cursor: not-allowed;
}

.chat-input-actions {
    display: flex;
    gap: 4px;
}

.chat-input-btn {
    width: 38px;
    height: 38px;
    background: transparent;
    border: none;
    border-radius: 10px;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-input-btn:hover {
    background: #f1f5f9;
    color: #3b82f6;
}

.chat-input-wrapper {
    flex: 1;
    min-width: 0;
}

#chat-input {
    width: 100%;
    padding: 10px 14px;
    background: #f1f5f9;
    border: 2px solid transparent;
    border-radius: 16px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    min-height: 40px;
    max-height: 120px;
    line-height: 1.4;
    transition: all 0.2s;
}

#chat-input:focus {
    outline: none;
    background: white;
    border-color: #3b82f6;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

#chat-input::placeholder {
    color: #94a3b8;
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border: none;
    border-radius: 14px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    flex-shrink: 0;
}

.chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}

.chat-send-btn:active {
    transform: scale(0.95);
}

/* Improved Emoji & Sticker Picker */
.chat-emoji-picker {
    position: absolute;
    bottom: 75px;
    left: 16px;
    right: 16px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 24px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.5);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow: hidden;
    animation: slideUp 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.chat-emoji-tabs {
    display: flex;
    padding: 10px;
    background: rgba(0, 0, 0, 0.03);
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.chat-emoji-tabs::-webkit-scrollbar {
    display: none;
}

.chat-emoji-tab-btn {
    padding: 6px 14px;
    border: none;
    background: transparent;
    border-radius: 99px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.chat-emoji-tab-btn:hover {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.chat-emoji-tab-btn.active {
    background: #3b82f6;
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.chat-emoji-content {
    padding: 12px;
    max-height: 250px;
    overflow-y: auto;
}

.chat-emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 4px;
}

.chat-emoji-btn {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    background: transparent;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-emoji-btn:hover {
    background: rgba(59, 130, 246, 0.1);
    transform: scale(1.2);
}

/* Stickers Grid */
.chat-stickers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 12px;
}

.chat-sticker-btn {
    aspect-ratio: 1;
    background: transparent;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-sticker-btn:hover {
    background: rgba(59, 130, 246, 0.05);
    transform: scale(1.1);
}

.chat-sticker-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Loading Spinner */
.chat-loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(59, 130, 246, 0.2);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 8px auto;
}

/* Responsive */
@media (max-width: 480px) {
    .chat-widget-container {
        bottom: 16px;
        right: 16px;
    }

    .chat-toggle-btn {
        width: 54px;
        height: 54px;
        font-size: 1.3rem;
    }

    .chat-box {
        bottom: 70px;
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
        max-height: calc(100vh - 100px);
        right: -8px;
        border-radius: 20px;
    }

    .chat-header {
        padding: 14px 16px;
    }

    .chat-emoji-grid {
        grid-template-columns: repeat(8, 1fr);
    }

    .chat-emoji-btn {
        width: 36px;
        height: 36px;
    }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
    .chat-box {
        background: rgba(30, 41, 59, 0.98);
        border-color: rgba(59, 130, 246, 0.2);
    }

    .chat-messages {
        background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    }

    .chat-message-bubble {
        background: #334155;
        color: #e2e8f0;
        border-color: rgba(255, 255, 255, 0.05);
    }

    .chat-input-container {
        background: #1e293b;
        border-color: #334155;
    }

    #chat-input {
        background: #334155;
        color: #e2e8f0;
    }

    #chat-input::placeholder {
        color: #64748b;
    }

    .chat-emoji-picker {
        background: #1e293b;
    }

    .chat-emoji-btn:hover {
        background: #334155;
    }
}

/* ==================== CHAT TABS ==================== */
.chat-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    background: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
    overflow-x: auto;
    flex-shrink: 0;
}

.chat-tab {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    background: transparent;
    border: none;
    border-radius: 10px;
    color: #64748b;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.chat-tab:hover {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.chat-tab.active {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

/* Private Badge */
.chat-private-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: white;
    border-radius: 50%;
    font-size: 0.6rem;
    margin-left: 4px;
}

/* Responsive tabs */
@media (max-width: 480px) {
    .chat-tabs {
        padding: 6px 8px;
    }

    .chat-tab {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
}

/* Ban Button */
.chat-ban-btn {
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: #94a3b8;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s;
    margin-left: 4px;
}

.chat-message:hover .chat-ban-btn {
    opacity: 1;
}

.chat-ban-btn:hover {
    background: rgba(220, 38, 38, 0.1);
    color: #dc2626;
}

/* ==================== CHAT EXPANDED ==================== */
.chat-box.chat-box-expanded {
    width: 900px !important;
    height: 85vh !important;
    max-height: 900px;
    bottom: 24px;
    right: 24px;
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    z-index: 1000;
}

@media (max-width: 920px) {
    .chat-box.chat-box-expanded {
        width: calc(100% - 32px) !important;
        right: 16px;
        bottom: 80px;
        height: 70vh !important;
    }
}

/* Fix Teacher Message Contrast */
.chat-message.teacher-msg .chat-message-bubble {
    color: #451a03 !important;
    background-color: #fcd34d !important;
    border: 1px solid #f59e0b !important;
}

/* ==================== BATTLE SYSTEM ==================== */
.battle-choice-btn {
    width: 100%;
    padding: 1.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--gray-800);
    background: white;
    border: 2px solid transparent;
    /* เตรียมสำหรับการ highlight */
    border-radius: var(--radius-xl);
    text-align: left;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    position: relative;
    overflow: hidden;
}

.battle-choice-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    border-color: var(--primary-300);
}

.battle-choice-btn:active {
    transform: translateY(-2px);
    background: var(--gray-50);
}

/* Selected State (Waiting for opponent) */
.battle-choice-btn.selected {
    background: var(--primary-50);
    border-color: var(--primary-500);
    color: var(--primary-700);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
}

/* Correct State */
.battle-choice-btn.correct {
    background: var(--success-50);
    border-color: var(--success-500);
    color: var(--success-700);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
    animation: pulse-green 0.5s;
}

/* Wrong State */
.battle-choice-btn.wrong {
    background: var(--danger-50);
    border-color: var(--danger-500);
    color: var(--danger-700);
    opacity: 0.7;
}

.battle-choice-btn.correct::after {
    content: '✓';
    position: absolute;
    right: 1.5rem;
    color: var(--success-500);
    font-weight: 800;
    font-size: 1.5rem;
}

.battle-choice-btn.wrong::after {
    content: '✗';
    position: absolute;
    right: 1.5rem;
    color: var(--danger-500);
    font-weight: 800;
    font-size: 1.5rem;
}

@keyframes pulse-green {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

#battle-timer-ring {
    transition: stroke-dashoffset 1s linear;
}

/* ==================== 3D ONLINE LIBRARY ==================== */
#library-3d-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#library-3d-canvas-wrap {
    min-height: 520px;
}

@media (max-width: 768px) {
    #library-3d-canvas-wrap {
        min-height: 420px;
    }
}