/* ═══════════════════════════════════════════════════════════════════════════════
   MATHDLE - COMPREHENSIVE STYLING
   Daily Mathematical Word Puzzle Game
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════════════════════════
   CSS VARIABLES & COLOR SCHEME
   ═══════════════════════════════════════════════════════════════════════════════ */

:root {
    /* Brand colours */
    --mathdle-primary: #C90C0F;
    --mathdle-secondary: #FAB719;
    
    /* Game tile states (Wordle-inspired) */
    --tile-correct: #6AAA64;
    --tile-present: #C9B458;
    --tile-absent: #787C7E;
    --tile-empty: #FFFFFF;
    --tile-border-empty: #334155;
    --tile-border-filled: #475569;
    
    /* Keyboard colours */
    --key-bg: #1F2937;
    --key-bg-absent: #475569;
    --key-bg-present: #FACC15;
    --key-bg-correct: #22C55E;
    --key-text: #FFFFFF;
    --key-text-default: #E2E8F0;
    
    /* UI elements */
    --background: #0B1120;
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --border-color: #1F2937;
    --modal-bg: rgba(15, 23, 42, 0.98);
    --overlay-bg: rgba(2, 6, 23, 0.65);
    
    /* Spacing */
    --tile-size: 62px;
    --tile-gap: 5px;
    --key-height: 58px;
    --key-gap: 4px;
    
    /* Animations */
    --animation-speed: 0.25s;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #080F1D;
        --text-primary: #F8FAFC;
        --text-secondary: #94A3B8;
        --tile-empty: #0F172A;
        --tile-border-empty: #1E293B;
        --tile-border-filled: #334155;
        --key-bg: #1F2937;
        --key-text-default: #E2E8F0;
        --modal-bg: rgba(12, 19, 33, 0.95);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   LAYOUT & STRUCTURE
   ═══════════════════════════════════════════════════════════════════════════════ */

body.mathdle-page {
    background: radial-gradient(circle at 15% 15%, rgba(59, 130, 246, 0.12), transparent 55%),
                radial-gradient(circle at 85% 25%, rgba(236, 72, 153, 0.12), transparent 50%),
                linear-gradient(180deg, #0B1120 0%, #0F172A 100%);
    color: var(--text-primary);
    font-family: 'Rockwell', 'Rockwell Nova', 'Roboto Slab', serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Ensure html has no margin/padding that could push header down */
html {
    margin: 0;
    padding: 0;
}

/* Game menu modernisation */
body.mathdle-page.game-menu-active {
    --menu-bg-start: #111827;
    --menu-bg-end: #1f2937;
    /* --game-primary is set by the template from accentColors config */
    --game-primary-dark: #cc6600;
    --game-secondary: #38BDF8;
    --menu-card-bg: rgba(15, 23, 42, 0.65);
    --menu-card-border: rgba(255, 255, 255, 0.12);
    --menu-text-light: #F8FAFC;
}

.calculadle-menu {
    position: relative;
    z-index: 2;
    max-width: 880px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.mathdle-menu .game-menu-hero {
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-align: center;
}

.mathdle-menu .game-menu-hero__icon {
    font-size: 3rem;
    color: var(--game-secondary);
    filter: drop-shadow(0 8px 18px rgba(250, 183, 25, 0.35));
}

.mathdle-menu .game-menu-hero__title h1 {
    font-size: 3.5rem;
    letter-spacing: 0.1em;
    margin: 0;
    color: #fff;
    text-transform: uppercase;
}

.mathdle-menu .game-menu-hero__subtitle {
    margin: 0 auto;
    max-width: 600px;
    font-size: 1.15rem;
    color: rgba(248, 250, 252, 0.85);
}

.mathdle-menu .game-menu-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 18px;
}

.mathdle-menu .game-menu-stats .stat-card {
    background: rgba(15, 23, 42, 0.7);
    border-radius: 18px;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.45);
    text-align: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.mathdle-menu .game-menu-stats .stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 24px 50px rgba(15, 23, 42, 0.55);
}

.mathdle-menu .game-menu-stats .stat-value {
    display: block;
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--game-primary);
    margin-bottom: 6px;
}

.mathdle-menu .game-menu-stats .stat-label {
    display: flex;
    gap: 6px;
    justify-content: center;
    align-items: center;
    font-size: 0.95rem;
    color: rgba(248, 250, 252, 0.75);
}

.mathdle-menu .game-menu-preview {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 24px;
    border-radius: 20px;
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.mathdle-menu .game-menu-preview__badge {
    padding: 10px 18px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--game-secondary), #ffd166);
    font-weight: 600;
    letter-spacing: 0.04em;
    color: #1f2937;
    text-transform: uppercase;
    font-size: 0.85rem;
}

.mathdle-menu .game-menu-preview__body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 220px;
}

.mathdle-menu .game-menu-preview__date {
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
}

.mathdle-menu .game-menu-preview__countdown {
    font-size: 0.95rem;
    color: rgba(250, 183, 25, 0.9);
    font-weight: 600;
}

.mathdle-menu .game-menu-preview__extras {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mathdle-menu .game-menu-preview__extras li {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
    color: rgba(248, 250, 252, 0.75);
}

.mathdle-menu .game-menu-preview__extras li strong {
    font-weight: 600;
    color: rgba(248, 250, 252, 0.9);
}

.mathdle-menu .game-menu-preview__status {
    padding: 10px 18px;
    border-radius: 999px;
    font-weight: 600;
    color: #10b981;
    background: rgba(16, 185, 129, 0.15);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mathdle-menu .game-menu-preview__status.status-completed {
    color: #22d3ee;
    background: rgba(34, 211, 238, 0.15);
}

.mathdle-menu .game-menu-preview__status.status-playing {
    color: #facc15;
    background: rgba(250, 204, 21, 0.18);
}

.mathdle-menu .game-menu-actions {
    gap: 18px;
}

.game-menu-button.success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border-color: rgba(16, 185, 129, 0.6);
    color: #ecfdf5;
}

.game-menu-button.success:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
}

.game-menu-button .game-menu-button-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.game-menu-button-subtext {
    font-size: 0.85rem;
    opacity: 0.75;
}

/* Mobile menu styles are handled by shared game-menu.css */
/* Removed conflicting mobile menu styles to ensure shared mobile menu applies correctly */

/* Hide menu when not active */
#mode-select.game-menu-screen:not(.active) {
    display: none;
}

/* Hide game screen initially */
#game-screen {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    position: absolute !important;
    left: -9999px !important;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
}

/* Hide container when game screen is not active */
#game-screen:not(.active) .mathdle-container {
    display: none !important;
    visibility: hidden !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
}

/* Show game screen when active */
#game-screen.active {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    position: relative !important;
    left: auto !important;
    width: auto !important;
    height: auto !important;
    background: transparent;
    padding: 0;
    margin: 0;
}

.mathdle-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 24px;
    box-shadow: 0 25px 60px rgba(2, 6, 23, 0.55);
    position: relative;
    padding-top: 80px;
    /* Ensure container doesn't create containing block for fixed header */
    transform: none;
    will-change: auto;
    overflow: hidden; /* Prevent scrolling */
}

/* Desktop: Remove padding-top from container since header is outside */
@media (min-width: 769px) {
    .mathdle-container {
        padding-top: 0 !important; /* Header is outside container, no padding needed */
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   GAME TOP BAR - Use shared game-header.css styling
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Ensure header spans full width and uses shared styling - positioned relative to viewport */
/* Header is now outside container, so it's positioned relative to body/viewport */
.game-top-bar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    margin: 0 !important;
    padding: 0.75rem 1rem !important; /* Reduced padding */
    background: rgba(0, 0, 0, 0.95) !important;
    backdrop-filter: blur(10px) !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3) !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    z-index: 10000 !important;
    transform: none !important;
    box-sizing: border-box !important; /* Ensure padding is included in width */
}

/* Also apply to header inside container if it exists (for backwards compatibility) */
.mathdle-container .game-top-bar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    margin: 0 !important;
    padding: 1rem 2rem !important;
    background: rgba(0, 0, 0, 0.95) !important;
    backdrop-filter: blur(10px) !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3) !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    z-index: 10000 !important;
    transform: none !important;
}

/* Desktop centering - ensure container is centered on larger screens */
@media (min-width: 769px) {
    body.mathdle-page {
        display: flex;
        justify-content: center;
        align-items: flex-start;
        padding: 0;
    }
    
    .mathdle-container {
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        position: relative;
    }
    
    /* Header always spans full viewport width on desktop - now outside container so it's properly fixed */
    .game-top-bar {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        transform: none !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding: 0.75rem 1rem !important; /* Reduced padding for better fit */
        box-sizing: border-box !important;
    }
    
    /* Make buttons more compact on desktop */
    .game-top-bar .button-group {
        gap: 0.5rem !important; /* Reduced gap between buttons */
        flex-wrap: wrap !important; /* Allow wrapping if needed */
    }
    
    .game-top-bar .top-bar-btn {
        padding: 0.4rem 0.75rem !important; /* Reduced padding */
        font-size: 0.85rem !important; /* Slightly smaller font */
        white-space: nowrap !important;
    }
    
    /* Make title more compact */
    .game-top-bar .game-title-header {
        font-size: 1.5rem !important; /* Reduced from default */
        letter-spacing: 1px !important;
        flex-shrink: 1 !important; /* Allow title to shrink if needed */
        min-width: 0 !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    /* Increase game board size significantly to fill 95% height */
    :root {
        --tile-size: 95px; /* Increased from 78px to fill more space */
        --tile-gap: 7px; /* Slightly increase gap proportionally */
        --key-height: 72px; /* Increased from 58px (58 * 1.25 = 72.5, rounded to 72) */
        --key-gap: 5px; /* Slightly increased */
    }
    
    /* Remove ALL blank space above and below the answer grid */
    .mathdle-board-container {
        padding: 0 !important; /* No padding at all */
        margin: 0 !important;
        justify-content: center !important; /* Center vertically */
        flex: 0 1 95% !important; /* Take 95% of available space */
        align-items: center !important;
    }
    
    .mathdle-board {
        padding: 0 !important; /* No padding */
        margin: 0 !important;
        max-width: 550px !important; /* Increased from 450px to accommodate larger tiles */
        width: 100% !important;
        border-radius: 0 !important; /* Remove rounded corners for tighter fit */
    }
    
    /* Increase tile font size proportionally */
    .mathdle-tile {
        font-size: 3rem !important; /* Increased from 2.5rem to match larger tiles */
    }
    
    /* Increase keyboard letter size */
    .key-btn {
        font-size: 1rem !important; /* Increased from 0.8rem */
        font-weight: bold !important;
    }
    
    /* Add a little space between grid and keyboard - make keyboard full viewport width */
    .mathdle-keyboard {
        padding: 0 4px 0 !important; /* No vertical padding */
        margin-top: 12px !important; /* Small gap between grid and keyboard */
        margin-bottom: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100% !important; /* Full width of container (which is now 100vw) */
        max-width: 100% !important;
        border-top: none !important; /* Remove border between board and keyboard */
        border-radius: 0 !important; /* Remove rounded corners */
    }
    
    .keyboard-row {
        margin-bottom: 4px !important; /* Reduced gap between rows */
    }
    
    /* Ensure container fits without scrolling */
    .mathdle-container {
        min-height: auto !important;
        height: calc(100vh - 80px) !important; /* Full height minus header */
        max-height: calc(100vh - 80px) !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        justify-content: space-between !important; /* Push keyboard to bottom */
    }
    
    /* Game board fills 95% of remaining height with gap above keyboard */
    .mathdle-board-container {
        overflow-y: auto !important; /* Allow scrolling if needed */
        overflow-x: hidden !important;
        flex: 0 1 95% !important; /* Take 95% of available space */
        min-height: 0 !important; /* Allow flex shrinking */
        margin-top: 0 !important; /* No margin at top */
        margin-bottom: 12px !important; /* Gap above keyboard */
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important; /* Center board vertically */
    }
    
    /* Keyboard stuck to bottom of page */
    .mathdle-keyboard {
        flex-shrink: 0 !important;
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        position: relative !important;
    }
    
    /* Reduce row gap in board */
    .mathdle-row {
        gap: 4px !important; /* Reduced from 6px */
    }
}

/* Body padding for header */
body.mathdle-page:has(#game-screen.active),
body.mathdle-page.with-game-header {
    padding-top: 80px;
    margin: 0;
}

/* Override title color to Mathdle red (instead of standard yellow) */
.mathdle-page .game-top-bar .game-title-header {
    color: #C90C0F !important;
}

/* Ensure game screen has proper styling when active */
#game-screen.active {
    display: flex !important;
    background: transparent;
}

/* Ensure modals appear above everything */
.mathdle-modal-overlay {
    z-index: 10000 !important;
}

/* Mobile menu overlay */
.game-header-mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    z-index: 1000;
}

.game-header-mobile-overlay.active {
    display: block;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   GAME BOARD
   ═══════════════════════════════════════════════════════════════════════════════ */

.mathdle-board-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 32px 18px 18px;
    overflow-y: auto;
}

.mathdle-board {
    display: flex;
    flex-direction: column;
    gap: var(--tile-gap);
    align-items: center;
    margin: 0 auto;
    padding: 24px 20px;
    background: rgba(8, 14, 30, 0.85);
    border-radius: 20px;
    border: 1px solid rgba(148, 163, 184, 0.15);
    box-shadow: inset 0 1px 0 rgba(248, 250, 252, 0.04);
    max-width: 360px;
    width: 100%;
}

.mathdle-row {
    display: flex;
    gap: var(--tile-gap);
}

.mathdle-tile {
    width: var(--tile-size);
    height: var(--tile-size);
    border: 2px solid var(--tile-border-empty);
    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: bold;
    text-transform: uppercase;
    font-family: 'Rockwell', 'Rockwell Nova', 'Roboto Slab', serif;
    background: var(--tile-empty);
    color: #0F172A;
    user-select: none;
    box-sizing: border-box;
}

.mathdle-tile.filled {
    border-color: var(--tile-border-filled);
    background: #FFFFFF !important;
    color: #0F172A !important;
    animation: pop 0.1s ease;
}

/* Ensure filled tiles are visible on mobile */
@media (max-width: 768px) {
    .mathdle-tile.filled {
        background: #FFFFFF !important;
        color: #0F172A !important;
        border-color: var(--tile-border-filled) !important;
    }
}

.mathdle-tile.correct {
    background: var(--tile-correct) !important;
    border-color: var(--tile-correct) !important;
    color: white !important;
}

.mathdle-tile.present {
    background: var(--tile-present) !important;
    border-color: var(--tile-present) !important;
    color: white !important;
}

.mathdle-tile.absent {
    background: var(--tile-absent) !important;
    border-color: var(--tile-absent) !important;
    color: white !important;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Pop animation when letter is added */
@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Flip animation when tile is revealed */
.mathdle-tile.flipping {
    animation: flip 0.5s ease;
}

@keyframes flip {
    0% { 
        transform: rotateX(0);
    }
    50% { 
        transform: rotateX(-90deg);
    }
    100% { 
        transform: rotateX(0);
    }
}

/* Shake animation for invalid word */
.mathdle-row.invalid {
    animation: shake 0.6s ease;
}

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

/* Bounce animation for winning */
.mathdle-tile.winning {
    animation: bounce 0.6s ease;
    animation-delay: calc(var(--tile-index) * 0.1s);
}

@keyframes bounce {
    0%, 20% { transform: translateY(0); }
    40% { transform: translateY(-30px); }
    50% { transform: translateY(5px); }
    60% { transform: translateY(-15px); }
    80% { transform: translateY(2px); }
    100% { transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   KEYBOARD
   ═══════════════════════════════════════════════════════════════════════════════ */

.mathdle-keyboard {
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
    padding: 16px 4px 28px;
    background: rgba(8, 14, 30, 0.8);
    border-top: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 0 0 24px 24px;
    box-shadow: inset 0 -1px 0 rgba(248, 250, 252, 0.04);
    box-sizing: border-box;
    overflow-x: hidden;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: var(--key-gap);
    margin-bottom: var(--key-gap);
    flex-wrap: nowrap;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.key-btn {
    min-width: 0;
    flex: 1 1 0;
    height: var(--key-height);
    padding: 0 4px;
    background: var(--key-bg);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    color: var(--key-text-default);
    cursor: pointer;
    user-select: none;
    transition: all 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.key-btn:hover {
    filter: brightness(0.95);
}

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

.key-btn.key-enter,
.key-btn.key-backspace {
    flex: 1.3 1 0;
    min-width: 0;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 0 3px;
}

.key-btn.key-enter i {
    font-size: 0.7rem;
}

.key-btn.absent {
    background: var(--key-bg-absent);
    color: var(--key-text);
}

.key-btn.present {
    background: var(--key-bg-present);
    color: var(--key-text);
}

.key-btn.correct {
    background: var(--key-bg-correct);
    color: var(--key-text);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   MESSAGES & NOTIFICATIONS
   ═══════════════════════════════════════════════════════════════════════════════ */

.mathdle-message {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: var(--background);
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.3s ease, slideUp 0.3s ease 2.5s;
    opacity: 0;
    animation-fill-mode: forwards;
}

.mathdle-message.success {
    background: var(--tile-correct);
    color: white;
}

.mathdle-message.error {
    background: var(--mathdle-primary);
    color: white;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   MODALS
   ═══════════════════════════════════════════════════════════════════════════════ */

.mathdle-modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: var(--overlay-bg);
    display: none;
    align-items: center !important;
    justify-content: center !important;
    z-index: 9999 !important;
    backdrop-filter: blur(3px);
    margin: 0 !important;
    padding: 0 !important;
}

.mathdle-modal-overlay.active {
    display: flex !important;
}

.mathdle-modal {
    background: var(--modal-bg);
    border-radius: 16px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    border: 1px solid rgba(148, 163, 184, 0.18);
    box-shadow: 0 30px 70px rgba(2, 6, 23, 0.65);
    color: var(--text-primary);
    margin: 0 auto !important; /* Ensure centered */
    box-sizing: border-box !important; /* Include padding in width */
}

/* Ensure stats modal content is properly centered and fills width */
.stats-modal .mathdle-modal {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important; /* Stretch children to full width */
}

.stats-modal .stats-grid,
.stats-modal .guess-distribution {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
}

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

/* ═══════════════════════════════════════════════════════════════════════════════
   RESULTS MODAL
   ═══════════════════════════════════════════════════════════════════════════════ */

.results-content {
    text-align: center;
}

.results-content h2 {
    font-size: 2rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.results-word {
    margin: 20px 0;
}

.word-label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.word-answer {
    display: block;
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--mathdle-primary);
    letter-spacing: 0.2em;
}

.word-definition {
    font-size: 1rem;
    color: var(--text-secondary);
    margin: 15px 0;
    font-style: italic;
}

.results-score {
    margin: 30px 0;
}

.score-value {
    font-size: 3rem;
    font-weight: bold;
    color: var(--tile-correct);
}

.score-label {
    font-size: 1rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.results-guesses {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: 30px;
}

/* Streak Display */
.results-streak {
    background: linear-gradient(135deg, rgba(255, 107, 0, 0.1), rgba(255, 193, 7, 0.1));
    border-radius: 12px;
    padding: 20px;
    margin: 20px 0;
}

.streak-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
}

.streak-icon {
    font-size: 2rem;
}

.streak-value {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--mathdle-primary);
}

.streak-label {
    font-size: 1rem;
    color: var(--text-secondary);
}

.progress-bar {
    background: rgba(0, 0, 0, 0.1);
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    background: linear-gradient(90deg, var(--mathdle-secondary), var(--mathdle-primary));
    height: 100%;
    transition: width 0.5s ease;
}

.progress-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Stats Summary */
.results-stats-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin: 25px 0;
}

.stat-item {
    text-align: center;
}

.stat-item .stat-value {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--text-primary);
}

.stat-item .stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Guess Distribution */
.guess-distribution {
    margin: 30px 0;
    text-align: left;
}

.guess-distribution h3 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.distribution-bars {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bar-label {
    font-size: 1rem;
    font-weight: bold;
    color: var(--text-primary);
    width: 20px;
}

.bar-container {
    flex: 1;
    background: transparent; /* Transparent by default - only show background when bar has content */
    height: 24px;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

/* Show background only when bar-container has a bar-fill with content */
.bar-container:has(.bar-fill[style*="width"]:not([style*="width: 0%"]):not([style*="width: 0px"])) {
    background: rgba(0, 0, 0, 0.1);
}

.bar-fill {
    background: var(--tile-correct);
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 8px;
    min-width: 0;
    transition: width 0.5s ease;
}

/* Hide bar-fill when width is 0% */
.bar-fill[style*="width: 0%"],
.bar-fill[style*="width: 0px"] {
    display: none;
}

.bar-fill.current {
    background: var(--mathdle-primary);
}

.bar-count {
    color: white;
    font-size: 0.85rem;
    font-weight: bold;
}

/* Results Actions */
.results-actions {
    display: flex;
    gap: 10px;
    margin: 25px 0;
    justify-content: center;
}

.share-btn,
.view-stats-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.share-btn {
    background: var(--mathdle-primary);
    color: white;
}

.share-btn:hover {
    background: #a00a0d;
    transform: translateY(-2px);
}

.view-stats-btn {
    background: var(--border-color);
    color: var(--text-primary);
}

.view-stats-btn:hover {
    background: var(--tile-absent);
    color: white;
    transform: translateY(-2px);
}

/* Next Mathdle Countdown */
.next-mathdle {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.countdown-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.countdown-time {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--mathdle-primary);
    font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   HOW TO PLAY MODAL
   ═══════════════════════════════════════════════════════════════════════════════ */

.how-to-play-modal h2 {
    font-size: 1.8rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.how-to-play-modal p {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.tutorial-section {
    margin: 25px 0;
}

.tutorial-section h3 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.example-row {
    display: flex;
    gap: 5px;
    margin: 15px 0;
    justify-content: center;
}

.example-tile {
    width: 50px;
    height: 50px;
    border: 2px solid var(--tile-border-empty);
    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: bold;
    background: var(--tile-empty);
    color: var(--text-primary);
}

.example-tile.correct {
    background: var(--tile-correct);
    border-color: var(--tile-correct);
    color: white;
}

.example-tile.present {
    background: var(--tile-present);
    border-color: var(--tile-present);
    color: white;
}

.example-tile.absent {
    background: var(--tile-absent);
    border-color: var(--tile-absent);
    color: white;
}

.tutorial-section ul {
    list-style: none;
    padding: 0;
}

.tutorial-section li {
    padding: 8px 0;
    padding-left: 25px;
    position: relative;
}

.tutorial-section li:before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--mathdle-primary);
    font-size: 1.5rem;
    line-height: 1;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   STATISTICS MODAL
   ═══════════════════════════════════════════════════════════════════════════════ */

.stats-modal h2 {
    font-size: 1.8rem;
    margin-bottom: 25px;
    text-align: center;
    color: var(--text-primary);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* Changed from 4 to 3 columns for better layout */
    gap: 20px;
    margin-bottom: 30px;
    width: 100%; /* Ensure full width */
    max-width: 100%; /* Prevent overflow */
}

.stat-box {
    text-align: center;
    padding: 15px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
}

.stat-box .stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--mathdle-primary);
    display: block;
}

.stat-box .stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 5px;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   PRACTICE MODE INDICATOR
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Practice mode indicator removed */

/* ═══════════════════════════════════════════════════════════════════════════════
   RESPONSIVE DESIGN
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Tablet */
@media (max-width: 768px) {
    :root {
        --tile-size: 56px;
        --tile-gap: 4px;
        --key-height: 52px;
    }
    
    .mathdle-tile {
        font-size: 1.75rem;
    }
    
    .game-title-header {
        font-size: 1.5rem;
    }
    
    .results-stats-summary {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .mathdle-stats-preview {
        gap: 15px;
    }
    
    .mathdle-stats-preview .stat-value {
        font-size: 1.8rem;
    }
    
    .mathdle-stats-preview .stat-label {
        font-size: 0.8rem;
    }
}

/* Mobile */
@media (max-width: 480px) {
    :root {
        --tile-size: 50px;
        --tile-gap: 4px;
        --key-height: 48px;
        --key-gap: 4px;
    }
    
    .mathdle-tile {
        font-size: 1.5rem;
    }
    
    /* Ensure filled tiles are visible on mobile - override any dark mode settings */
    .mathdle-tile.filled {
        background: #FFFFFF !important;
        color: #0F172A !important;
        border-color: #475569 !important;
    }
    
    .mathdle-keyboard {
        padding: 12px 2px 24px;
    }
    
    .keyboard-row {
        gap: 2px;
        margin-bottom: 2px;
    }
    
    .key-btn {
        flex: 1 1 0;
        min-width: 0;
        padding: 0 2px;
        font-size: 0.6rem;
    }
    
    .key-btn.key-enter,
    .key-btn.key-backspace {
        flex: 1.2 1 0;
        min-width: 0;
        font-size: 0.55rem;
        padding: 0 2px;
    }
    
    .key-btn.key-enter i {
        font-size: 0.5rem;
    }
    
    .game-title-header {
        font-size: 1.3rem;
    }
    
    /* Ensure button group is hidden on mobile (burger menu shows instead) */
    .mathdle-page .game-top-bar .button-group {
        display: none !important;
    }
    
    /* Ensure burger menu is visible on mobile */
    .mathdle-page .game-top-bar .game-header-burger {
        display: block !important;
    }
    
    .top-bar-btn {
        font-size: 0.8rem;
        padding: 6px 10px;
    }
    
    .top-bar-btn span {
        display: none;
    }
    
    .mathdle-modal {
        padding: 20px;
        width: 95%;
    }
    
    .word-answer {
        font-size: 2rem;
    }
    
    .score-value {
        font-size: 2.5rem;
    }
    
    .mathdle-stats-preview {
        gap: 10px;
    }
    
    .mathdle-stats-preview .stat-box {
        min-width: 80px;
    }
    
    .mathdle-stats-preview .stat-value {
        font-size: 1.5rem;
    }
    
    .mathdle-stats-preview .stat-label {
        font-size: 0.7rem;
    }
    
    .daily-word-number {
        font-size: 1.1rem;
    }
    
    .daily-date {
        font-size: 0.85rem;
    }
    
    .time-until-next {
        font-size: 0.85rem;
    }
}

/* Very small screens */
@media (max-width: 360px) {
    :root {
        --tile-size: 45px;
        --tile-gap: 3px;
        --key-height: 44px;
    }
    
    .mathdle-tile {
        font-size: 1.3rem;
    }
    
    .key-btn {
        min-width: 26px;
        padding: 0 4px;
        font-size: 0.7rem;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   UTILITY CLASSES
   ═══════════════════════════════════════════════════════════════════════════════ */

.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-out {
    animation: fadeOut 0.3s ease;
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Ensure proper flex layout for game header - full width on desktop, positioned relative to viewport */
.mathdle-page .game-top-bar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 1rem 2rem !important;
    background: rgba(0, 0, 0, 0.95) !important;
    backdrop-filter: blur(10px) !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3) !important;
    margin: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    z-index: 10000 !important;
    transform: none !important;
}

/* Ensure full viewport width on desktop */
@media (min-width: 769px) {
    .mathdle-page .game-top-bar {
        width: 100vw !important;
        max-width: 100vw !important;
    }
}

/* Ensure button group displays properly on desktop */
@media (min-width: 769px) {
    .mathdle-page .game-top-bar .button-group {
        display: flex !important;
        gap: 1rem !important;
        align-items: center !important;
        flex-wrap: wrap !important;
    }
    
    .mathdle-page .game-top-bar .game-header-burger {
        display: none !important;
    }
}

/* Ensure buttons are properly styled */
.mathdle-page .game-top-bar .top-bar-btn {
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    white-space: nowrap !important;
    text-decoration: none !important;
}

/* Ensure title is properly positioned */
.mathdle-page .game-top-bar .game-title-header {
    margin: 0 !important;
    flex-shrink: 0 !important;
}

.calculadle-title-board {
    display: inline-flex;
    gap: 6px;
    margin: 0 auto 18px;
    padding: 5px 6px;
    background: rgba(8, 14, 30, 0.7);
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    box-shadow: 0 12px 28px rgba(2, 6, 23, 0.45);
    max-width: 100%;
    box-sizing: border-box;
    flex-wrap: wrap;
    justify-content: center;
}

.calculadle-title-board .title-tile {
    width: 48px;
    height: 48px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-size: 1.55rem;
    font-weight: 700;
    color: #111827;
    border-radius: 8px;
    text-transform: uppercase;
    font-family: 'Rockwell', 'Rockwell Nova', 'Roboto Slab', serif;
    box-shadow: 0 6px 12px rgba(15, 23, 42, 0.35);
    animation: tileReveal 0.45s ease forwards;
    transform-origin: center;
    flex-shrink: 0;
}

/* Responsive title board - make smaller on smaller screens */
@media (max-width: 768px) {
    .calculadle-title-board {
        gap: 4px;
        padding: 4px 5px;
        margin-bottom: 12px;
    }
    .calculadle-title-board .title-tile {
        width: 40px;
        height: 40px;
        font-size: 1.3rem;
        border-radius: 6px;
    }
}

@media (max-width: 480px) {
    .calculadle-title-board {
        gap: 3px;
        padding: 3px 4px;
        margin-bottom: 10px;
    }
    .calculadle-title-board .title-tile {
        width: 36px;
        height: 36px;
        font-size: 1.15rem;
        border-radius: 5px;
    }
}

.calculadle-title-board .title-tile.correct {
    background: #22C55E;
}

.calculadle-title-board .title-tile.present {
    background: #FACC15;
}

.calculadle-title-board .title-tile:nth-child(1) { animation-delay: 0.05s; }
.calculadle-title-board .title-tile:nth-child(2) { animation-delay: 0.1s; }
.calculadle-title-board .title-tile:nth-child(3) { animation-delay: 0.15s; }
.calculadle-title-board .title-tile:nth-child(4) { animation-delay: 0.2s; }
.calculadle-title-board .title-tile:nth-child(5) { animation-delay: 0.25s; }
.calculadle-title-board .title-tile:nth-child(6) { animation-delay: 0.3s; }
.calculadle-title-board .title-tile:nth-child(7) { animation-delay: 0.35s; }
.calculadle-title-board .title-tile:nth-child(8) { animation-delay: 0.4s; }
.calculadle-title-board .title-tile:nth-child(9) { animation-delay: 0.45s; }
.calculadle-title-board .title-tile:nth-child(10) { animation-delay: 0.5s; }

@keyframes tileReveal {
    0% {
        transform: rotateX(-90deg);
        opacity: 0;
    }
    100% {
        transform: rotateX(0deg);
        opacity: 1;
    }
}

/* Ensure stats are properly aligned on mobile */
@media (max-width: 768px) {
    .mathdle-menu .game-menu-stats {
        display: flex !important;
        flex-direction: row !important;
        grid-template-columns: none !important;
        gap: var(--menu-spacing-xs, 0.5rem) !important;
    }
    
    .mathdle-menu .game-menu-stats .stat-card {
        flex: 1 !important;
        min-width: 0 !important;
        padding: var(--menu-spacing-sm, 0.85rem) !important;
    }
}

