/* ============================================
   WCAG AA Dark Mode Contrast Fixes
   gray-400 (#9CA3AF) on gray-800 (#1F2937) = 3.9:1 (FAILS)
   gray-300 (#D1D5DB) on gray-800 (#1F2937) = 7.0:1 (PASSES)
   ============================================ */
.dark .text-gray-400,
.dark .dark\:text-gray-400 {
    color: #D1D5DB !important;
    /* gray-300 for WCAG AA compliance */
}

.dark .text-gray-500,
.dark .dark\:text-gray-500 {
    color: #9CA3AF !important;
    /* gray-400 - slightly lighter in dark mode */
}

/* Footer text in dark mode needs better contrast */
.dark footer {
    color: #9CA3AF !important;
    /* Ensure footer text is readable */
}

.ad-container {
    min-height: 90px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
}

/* Blog Card Hover Effects */
.blog-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.blog-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

/* Mobile tap feedback */
.blog-card:active {
    transform: scale(0.98);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.sticky-header {
    position: sticky;
    top: 0;
    z-index: 40;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

#xp-bar {
    transition: width 0.5s ease-in-out;
}


html,
body {
    /* overflow must NOT be hidden/clip/scroll for position:sticky to work */
    max-width: 100vw;
}

/* Help modal card - ensure solid background, centered, and visible */
#help-modal>div,
#stats-modal>div,
#settings-modal>div,
#difficulty-modal>div {
    background: #ffffff !important;
    color: #000000 !important;
    position: relative !important;
    z-index: 60;
    margin: auto;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

/* Dark mode backgrounds for modal cards */
.dark #help-modal>div,
.dark #stats-modal>div,
.dark #settings-modal>div,
.dark #difficulty-modal>div {
    background: #1f2937 !important;
    color: #ffffff !important;
}

/* Dark mode styling for select dropdowns in modals */
.dark #settings-modal select,
.dark #difficulty-modal select {
    background-color: #374151 !important;
    color: #ffffff !important;
    border-color: #4b5563 !important;
}

.confetti {
    position: fixed;
    top: -10px;
    width: 10px;
    height: 10px;
    opacity: 0.9;
    pointer-events: none;
    z-index: 10000;
    animation: fallAndSway 3s ease-out forwards;
}

@keyframes fallAndSway {
    0% {
        transform: translateY(0) translateX(0) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(100vh) translateX(var(--sway, 0px)) rotate(720deg);
        opacity: 0;
    }
}

.key {
    min-width: 44px;
    min-height: 44px;
}

.key-wide {
    width: 55px !important;
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 1rem;
    margin-bottom: 1rem;
}

.streak-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-weight: bold;
    font-size: 0.8rem;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), inset 0 1px 1px rgba(255, 255, 255, 0.3);
}

.bronze {
    background: linear-gradient(145deg, #cd7f32, #a05d21);
}

.silver {
    background: linear-gradient(145deg, #c0c0c0, #a9a9a9);
}

.gold {
    background: linear-gradient(145deg, #ffd700, #daa520);
}

.diamond {
    background: linear-gradient(145deg, #b9f2ff, #89cff0);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
}

/* Mobile responsiveness - hide XP bar on very small screens */
@media (max-width: 374px) {
    #xp-display {
        display: none !important;
    }

    .header-stats-divider:last-of-type {
        display: none !important;
    }
}

/* Sidebar ad containers - desktop only */
.sidebar-ad-container {
    width: 160px;
    min-height: 600px;
    position: sticky;
    top: 20px;
}

/* FAQ styles */
.faq-item {
    border-bottom: 1px solid #e5e7eb;
}

/* Hide sidebars on screens smaller than 1280px */
@media (max-width: 1279px) {
    .sidebar-ad-container {
        display: none;
    }
}

/* Blog card styles - ensure dark mode compatibility */
.blog-card-title {
    color: #1f2937;
}

.dark .blog-card-title {
    color: #ffffff !important;
}

.dark .blog-card {
    background-color: #1f2937 !important;
}

/* =================================================================
   MOBILE OPTIMIZATIONS
   ================================================================= */

/* Fix 1: Hide popup modals on mobile (daily reminder, welcome, etc) */
@media (max-width: 640px) {

    #daily-reminder-modal,
    #welcome-modal,
    #reminder-modal {
        display: none !important;
    }
}

/* Fix 2: Fix header overlap on mobile - hide left stats, show only logo and buttons */
@media (max-width: 640px) {

    /* Hide the stats section on mobile header to prevent overlap */
    header .flex.items-center.gap-2.min-w-\[200px\],
    header .flex.items-center.gap-2.min-w-\[270px\] {
        display: none !important;
    }

    /* Center the logo on mobile - override absolute positioning from game pages */
    header a[href="index.html"],
    header a[href="../index.html"] {
        position: static !important;
        left: auto !important;
        transform: none !important;
        flex-grow: 1;
        text-align: center;
        font-size: 1.25rem !important;
    }

    /* Hide Blog link on mobile for all pages */
    header a[href="blog/index.html"],
    header a[href="../blog/index.html"] {
        display: none !important;
    }

    /* Ensure header buttons stay visible on mobile */
    header .flex.items-center.gap-1.min-w-\[120px\] {
        min-width: auto !important;
    }

    /* Reduce header padding on mobile */
    header .py-2 {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }
}

/* Fix 3: Hide DEV MODE section in footer on mobile */
@media (max-width: 640px) {

    footer .dev-mode,
    footer .dev-links,
    footer [class*="dev-"],
    footer nav+nav,
    footer nav:nth-of-type(2) {
        display: none !important;
    }
}

/* Fix 4: Optimize Help/Stats/Settings modals for mobile */
@media (max-width: 640px) {

    #help-modal>div,
    #stats-modal>div,
    #settings-modal>div,
    #difficulty-modal>div {
        max-height: 85vh !important;
        overflow-y: auto !important;
        margin: 1rem !important;
        padding: 1rem !important;
        font-size: 0.9rem;
    }

    /* Ensure close button is always visible */
    .modal-close-btn {
        position: sticky;
        top: 0;
        z-index: 10;
        background: inherit;
    }

    /* Reduce modal header sizes on mobile */
    #help-modal h2,
    #stats-modal h2,
    #settings-modal h2 {
        font-size: 1.5rem !important;
    }

    /* Make modal content more compact */
    #stats-modal-content {
        padding: 1rem !important;
    }
}

/* Fix 5: Fix footer wrapping on mobile */
@media (max-width: 640px) {
    footer nav {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem !important;
    }

    footer nav a {
        font-size: 0.875rem !important;
        padding: 0.25rem !important;
    }

    footer nav span.inline-block {
        display: none !important;
    }
}

/* Bonus: Improve touch targets on mobile */
@media (max-width: 640px) {

    button,
    a.block {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Fix 6: Mobile keyboard overflow - reduce key size to fit 10 keys in 375px viewport */
@media (max-width: 400px) {

    /* Reduce keyboard container gaps */
    #keyboard-container .flex {
        gap: 2px !important;
    }

    /* Reduce number/operator key width from 40px to 32px */
    #keyboard-container .key {
        width: 32px !important;
        min-width: 32px !important;
        height: 44px !important;
        font-size: 0.875rem !important;
        padding: 0 2px !important;
    }

    /* Reduce ENTER/DELETE key width from 64px to 52px */
    #keyboard-container .key.w-16,
    #keyboard-container .key[data-key="ENTER"],
    #keyboard-container .key[data-key="Delete"] {
        width: 52px !important;
        min-width: 52px !important;
        font-size: 0.7rem !important;
    }

    /* Ensure keyboard container doesn't overflow */
    #keyboard-container {
        max-width: 100vw !important;
        padding: 0 4px !important;
        box-sizing: border-box !important;
    }
}

/* =================================================================
   MOBILE HAMBURGER MENU
   ================================================================= */

/* Hamburger Button */
.hamburger-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 44px;
    height: 44px;
    padding: 10px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 60;
    gap: 5px;
}

.hamburger-line {
    display: block;
    width: 24px;
    height: 2px;
    background-color: #3A86FF;
    border-radius: 2px;
    transition: all 0.3s ease;
    transform-origin: center;
}

/* Animated X state */
.hamburger-btn.active .hamburger-line:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.hamburger-btn.active .hamburger-line:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.hamburger-btn.active .hamburger-line:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* Backdrop */
.mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    z-index: 55;
}

.mobile-nav-backdrop.open {
    opacity: 1;
    visibility: visible;
}

/* Navigation Drawer - Slides from RIGHT */
.mobile-nav-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    height: 100dvh;
    background: #ffffff;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 56;
    transform: translateX(100%);
    transition: transform 0.25s ease, visibility 0.25s ease;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 0;
    visibility: hidden;
    /* CRITICAL: Prevents drawer from affecting layout width when closed */
}

.dark .mobile-nav-drawer {
    background: #1f2937;
}

.mobile-nav-drawer.open {
    transform: translateX(0);
    visibility: visible;
}

/* Stats Header */
.mobile-nav-stats {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 20px 16px;
    background: linear-gradient(135deg, #3A86FF 0%, #5A9CFF 100%);
    color: white;
    font-size: 1rem;
}

.mobile-nav-stats strong {
    font-weight: 700;
}

/* Section Styling */
.mobile-nav-section {
    padding: 12px 0;
    border-bottom: 1px solid #e5e7eb;
}

.dark .mobile-nav-section {
    border-bottom-color: #374151;
}

.mobile-nav-section h3 {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    padding: 8px 20px;
    margin: 0;
}

.dark .mobile-nav-section h3 {
    color: #9ca3af;
}

/* Navigation Links */
.mobile-nav-link {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    font-size: 1rem;
    font-weight: 500;
    color: #374151;
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.dark .mobile-nav-link {
    color: #e5e7eb;
}

.mobile-nav-link:hover,
.mobile-nav-link:focus {
    background-color: #f3f4f6;
    color: #3A86FF;
}

.dark .mobile-nav-link:hover,
.dark .mobile-nav-link:focus {
    background-color: #374151;
    color: #5A9CFF;
}

.mobile-nav-link.active {
    color: #3A86FF;
    background-color: #eff6ff;
    font-weight: 600;
    border-left: 3px solid #3A86FF;
}

.dark .mobile-nav-link.active {
    color: #5A9CFF;
    background-color: rgba(58, 134, 255, 0.1);
    border-left-color: #5A9CFF;
}

/* Button Links (Stats/Settings/Dark Mode) */
.mobile-nav-btn {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 14px 20px;
    font-size: 1rem;
    font-weight: 500;
    color: #374151;
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: background-color 0.15s ease;
}

.dark .mobile-nav-btn {
    color: #e5e7eb;
}

.mobile-nav-btn:hover,
.mobile-nav-btn:focus {
    background-color: #f3f4f6;
}

.dark .mobile-nav-btn:hover,
.dark .mobile-nav-btn:focus {
    background-color: #374151;
}

/* Footer Section */
.mobile-nav-footer {
    margin-top: auto;
    border-top: 1px solid #e5e7eb;
    border-bottom: none;
}

.dark .mobile-nav-footer {
    border-top-color: #374151;
}

/* Legal Links */
.mobile-nav-legal {
    padding: 16px 20px;
    font-size: 0.75rem;
    color: #9ca3af;
    text-align: center;
}

.mobile-nav-legal a {
    color: #9ca3af;
    text-decoration: none;
}

.mobile-nav-legal a:hover {
    color: #3A86FF;
    text-decoration: underline;
}

/* Hide hamburger and drawer on desktop */
@media (min-width: 640px) {

    .hamburger-btn,
    .mobile-nav-drawer,
    .mobile-nav-backdrop {
        display: none !important;
    }
}

/* Mobile spacer for header balance */
.mobile-header-spacer {
    width: 44px;
    flex-shrink: 0;
}

/* =================================================================
   2-COLUMN GRID LAYOUT FOR AD REVENUE OPTIMIZATION
   ================================================================= */

/* Desktop 2-column grid - Custom implementation since Tailwind arbitrary 
   values like lg:grid-cols-[1fr_340px] aren't in the compiled CSS */
@media (min-width: 1024px) {
    .grid.lg\:grid-cols-\[1fr_340px\] {
        grid-template-columns: 1fr 340px !important;
    }

    .grid.lg\:grid-cols-\[1fr_320px\] {
        grid-template-columns: 1fr 320px !important;
    }

    /* Sidebar must stretch to full grid height for sticky to work */
    #sidebar-right {
        width: 340px;
        flex-shrink: 0;
        align-self: stretch;
        /* Stretch to match main content height */
    }

    /* Sticky ad container inside sidebar - this is what actually sticks */
    #sidebar-right>div {
        position: sticky !important;
        top: 6rem !important;
        /* 96px = top-24 */
    }

    /* Fixed width ad unit inside sidebar */
    #sidebar-right .w-\[300px\] {
        width: 300px !important;
    }

    #sidebar-right .h-\[600px\] {
        height: 600px !important;
    }
}

/* Mobile: hide sidebar, ensure single column stack */
@media (max-width: 1023px) {
    #sidebar-right {
        display: none !important;
    }
}

/* =================================================================
   FAQ ACCORDION UTILITIES
   ================================================================= */
details>summary {
    list-style: none;
}

details>summary::-webkit-details-marker {
    display: none;
}