/* ========================================
   LETTERQUEST - PREMIUM GAME APP DESIGN
   ======================================== */

/* ========= ROOT VARIABLES ========= */
:root {
    /* Color Palette - Vibrant & Energetic */
    --color-bg-primary: #0f0a2e;
    --color-bg-secondary: #1a0f3d;
    --color-bg-tertiary: #2d1b5e;
    --color-accent-primary: #00ffff;
    --color-accent-secondary: #ff00ff;
    --color-accent-gold: #ffea00;
    --color-text-primary: #ffffff;
    --color-text-secondary: #e0d5ff;
    --color-text-muted: #a892ee;
    --color-success: #00ff9d;
    --color-danger: #ff2d5f;
    --color-warning: #ffc200;
    
    /* Glass Effect */
    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.15);
    --glass-blur: 20px;
    
    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 25px rgba(0, 255, 255, 0.5);
    --shadow-glow-pink: 0 0 25px rgba(255, 0, 255, 0.5);
    
    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;
    
    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-round: 50%;
    
    /* Transitions */
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
    
    /* Typography */
    --font-display: 'Orbitron', sans-serif; /* Using Orbitron if available, else fallback */
    --font-body: 'Outfit', sans-serif;
    
    /* ========= RESPONSIVE STAT VARIABLES ========= */
    /* Smartphone Portrait */
    --stat-icon-sm-portrait: 1.2rem;
    --stat-label-sm-portrait: 0.6rem;
    --stat-value-sm-portrait: 0.9rem;
    --stat-padding-sm-portrait: 0.25rem 0.5rem;
    --stat-gap-sm-portrait: 0.25rem;
    
    /* Smartphone Landscape */
    --stat-icon-sm-landscape: 1.2rem;
    --stat-label-sm-landscape: 0.6rem;
    --stat-value-sm-landscape: 0.9rem;
    --stat-padding-sm-landscape: 0.25rem 0.5rem;
    --stat-gap-sm-landscape: 0.5rem;
    
    /* Tablet Portrait */
    --stat-icon-md-portrait: 1.4rem;
    --stat-label-md-portrait: 0.7rem;
    --stat-value-md-portrait: 1rem;
    --stat-padding-md-portrait: 0.5rem 0.75rem;
    
    /* Tablet Landscape */
    --stat-icon-md-landscape: 1.8rem;
    --stat-label-md-landscape: 0.8rem;
    --stat-value-md-landscape: 1.2rem;
    --stat-padding-md-landscape: 1rem 0.5rem;
    --stat-gap-md-landscape: 0.75rem;
    --stat-min-width-md-landscape: 140px;
    
    /* Desktop Portrait */
    --stat-icon-lg-portrait: 1.5rem;
    --stat-label-lg-portrait: 0.75rem;
    --stat-value-lg-portrait: 1.1rem;
    --stat-padding-lg-portrait: 0.5rem 1rem;
    
    /* Desktop Landscape */
    --stat-icon-lg-landscape: 1.6rem;
    --stat-label-lg-landscape: 0.8rem;
    --stat-value-lg-landscape: 1.15rem;
    --stat-padding-lg-landscape: 1rem;
    --stat-gap-lg-landscape: 0.75rem;
}

/* ========= RESET & BASE ========= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

/* ========= ANIMATED BACKGROUND ========= */
.bg-gradient {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(
        circle at 20% 30%, 
        rgba(0, 255, 255, 0.25) 0%, 
        transparent 50%
    ),
    radial-gradient(
        circle at 80% 70%, 
        rgba(255, 0, 255, 0.25) 0%, 
        transparent 50%
    ),
    linear-gradient(
        135deg,
        var(--color-bg-primary) 0%,
        var(--color-bg-secondary) 100%
    );
    z-index: -2;
    animation: gradientShift 15s ease infinite;
}

@keyframes gradientShift {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.9; }
}

.bg-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(rgba(0, 255, 255, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 50px 50px;
    z-index: -1;
    animation: gridMove 20s linear infinite;
}

@keyframes gridMove {
    0% { transform: translate(0, 0); }
    100% { transform: translate(50px, 50px); }
}

/* ========= MAIN CONTAINER ========= */
.app-container {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.screen {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    animation: fadeIn 0.5s ease;
    position: relative;
}

.screen.hidden {
    display: none !important;
}

.screen-content {
    padding: var(--spacing-lg);
}

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

/* ========= START SCREEN ========= */
.start-screen-nav {
    position: absolute;
    top: var(--spacing-md);
    left: var(--spacing-md);
    z-index: 10;
}

.game-header {
    text-align: center;
    margin-bottom: var(--spacing-xl);
}

.logo-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
}

.logo-circle {
    width: 120px;
    height: 120px;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border: 2px solid var(--glass-border);
    border-radius: var(--radius-round);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    box-shadow: var(--shadow-glow);
    animation: logoFloat 3s ease-in-out infinite;
}

@keyframes logoFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.game-title {
    font-family: var(--font-display);
    font-size: 4rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--color-accent-primary), var(--color-accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 0.2em;
    text-shadow: 0 0 40px rgba(0, 245, 255, 0.5);
    animation: titleGlow 3s ease-in-out infinite;
}

@keyframes titleGlow {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.2); }
}

.game-subtitle {
    font-size: 1.1rem;
    color: var(--color-text-secondary);
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* Stats Overview */
.stats-overview {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
    flex-wrap: wrap;
    max-width: 100%;
    padding: 0 var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

.stat-card {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border: 2px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md) var(--spacing-lg);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-md);
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--color-accent-primary);
    box-shadow: var(--shadow-glow);
}

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

.stat-value {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-accent-gold), var(--color-warning));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

/* Level Selection */
.level-section {
    margin-top: var(--spacing-xl);
}

.section-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    text-align: center;
    margin-bottom: var(--spacing-lg);
    color: var(--color-text-secondary);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(85px, 1fr));
    gap: 0.75rem;
    width: 100%;
    margin: 0 auto;
}

.level-card {
    min-height: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: var(--color-text-primary);
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
    padding: 0.75rem 0.5rem;
    gap: 0.25rem;
}


.level-card:hover:not(.locked) {
    transform: translateY(-4px);
    border-color: var(--color-accent-primary);
    box-shadow: var(--shadow-glow);
    background: rgba(0, 245, 255, 0.1);
}

.level-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(0, 0, 0, 0.2);
    border-color: transparent;
}

.level-card.locked:hover {
    transform: none;
    box-shadow: none;
}

.level-card.completed {
    border-color: var(--color-success);
    background: rgba(0, 255, 136, 0.05);
}

.level-card.completed:hover {
    border-color: var(--color-success);
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
}

.level-card.current {
    border-color: var(--color-accent-primary);
    background: rgba(0, 245, 255, 0.1);
    box-shadow: var(--shadow-glow);
    animation: currentLevelPulse 2s infinite;
}

@keyframes currentLevelPulse {
    0% { box-shadow: 0 0 10px rgba(0, 245, 255, 0.3); }
    50% { box-shadow: 0 0 20px rgba(0, 245, 255, 0.6); border-color: var(--color-accent-secondary); }
    100% { box-shadow: 0 0 10px rgba(0, 245, 255, 0.3); }
}

.level-number {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
}

.level-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-height: 20px;
}

.level-stars {
    color: var(--color-accent-gold);
    font-size: 0.8rem;
    display: flex;
    gap: 2px;
}

.level-score {
    font-size: 0.7rem;
    color: var(--color-text-secondary);
    font-weight: 600;
}

.lock-icon {
    font-size: 1.2rem;
    color: var(--color-text-muted);
}

/* ========= GAME SCREEN ========= */
#game-screen {
    display: grid;
    grid-template-areas: 
        "header"
        "board"
        "panel";
    grid-template-rows: auto 1fr auto;
    grid-template-columns: 100%;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    max-width: none;
    overflow: hidden;
    padding: 0;
    z-index: 100;
}

.game-top-bar { grid-area: header; }
.game-board-wrapper { grid-area: board; }
.control-panel { grid-area: panel; }

.game-top-bar {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    flex-shrink: 0;
}

.btn-icon-only {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-icon-only:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--color-accent-primary);
    box-shadow: var(--shadow-glow);
}

/* Game Stats in Top Bar */
.game-stats {
    flex: 1;
    display: flex;
    justify-content: space-around;
    gap: var(--spacing-sm);
    flex-wrap: wrap; /* Allow wrapping like Sudoku */
}

.stat-item {
    display: flex;
    flex-direction: row; /* Explicitly set horizontal layout */
    align-items: center;
    gap: var(--spacing-md);
    background: rgba(255, 255, 255, 0.03);
    padding: 0.5rem 0.75rem; /* More compact padding */
    border-radius: var(--radius-md);
}

.stat-item .stat-icon {
    font-size: 1.5rem; /* Desktop icon size */
    flex-shrink: 0; /* Prevent icon from shrinking */
}

.stat-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-info .stat-label {
    font-size: 0.9rem; /* Smaller label */
    color: var(--color-text-muted);
    text-transform: uppercase;
    white-space: nowrap;
}

.stat-info .stat-value {
    font-size: 1rem; /* Smaller value */
    font-weight: 700;
    color: var(--color-text-primary);
    background: none;
    -webkit-text-fill-color: currentColor;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

#timer-display {
    display: inline-block;
    min-width: 60px; /* Reserve space for 00:00 */
    text-align: left;
}

/* Game Board */
.game-board-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-sm);
    overflow: hidden;
    min-height: 0;
}

.letter-grid {
    display: grid;
    /* grid-template-columns set by JS based on level size */
    gap: 4px;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border: 3px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: var(--spacing-sm);
    box-shadow: var(--shadow-lg);
    
    /* Responsive base sizing - Single robust calculation */
    width: min(500px, calc(100vw - 2rem), calc(100vh - 300px));
    height: auto;
    aspect-ratio: 1;
    margin: 0 auto;
}

.grid-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem; /* Will need to scale for larger grids */
    font-weight: 700;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    transition: all var(--transition-fast);
    color: var(--color-text-primary);
}

/* Dynamic Font Size based on grid size - handled in JS or media queries */
.grid-cell.small-text {
    font-size: 0.8rem;
}

.grid-cell:hover {
    background: rgba(0, 245, 255, 0.1);
    border-color: var(--color-accent-primary);
}

.grid-cell.selecting {
    background: rgba(0, 245, 255, 0.3);
    border-color: var(--color-accent-primary);
    box-shadow: 0 0 10px rgba(0, 245, 255, 0.2);
}

.grid-cell.found {
    background: rgba(0, 255, 136, 0.2);
    border-color: var(--color-success);
    color: var(--color-success);
    animation: foundPulse 0.5s ease;
}

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

/* Control Panel (Word List) */
.control-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border-top: 1px solid var(--glass-border);
    padding: var(--spacing-sm) var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    flex-shrink: 0;
}

.word-list-container {
    width: 100%;
    overflow-y: auto;
}

.word-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.word-item {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
}

.word-item.found {
    background: rgba(0, 255, 136, 0.1);
    border-color: var(--color-success);
    color: var(--color-success);
    text-decoration: line-through;
}

/* Orientation-based CONTENT styling */
@media screen and (orientation: landscape) {
    #game-screen {
        grid-template-areas: "header board panel";
        grid-template-columns: auto 1fr auto;
        grid-template-rows: 100%;
    }

    /* When toolbar is on LEFT, make it full height */
    .game-top-bar {
        flex: 0 0 auto;
        height: 100%;
        display: flex;
        flex-direction: column;
        width: auto;
        /* Remove min/max width constraints to let it size naturally like Sudoku */
    }
    
    /* Style stats vertically */
    .game-stats {
        flex: 1;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
    }
    
    .stat-item {
        width: 100%; /* Fill the toolbar width */
        padding: var(--spacing-md);
        flex-direction: column;
        text-align: center;
        gap: 0.5rem;
        min-width: 140px; /* Prevent flickering */
    }
    
    /* When control panel is on RIGHT (positioned by JS), style words vertically */
    .control-panel {
        flex: 1; /* Take full available height */
        height: 100%;
        display: flex;
        flex-direction: column;
        max-width: 220px; /* Slightly reduced */
    }
    
    .word-list-container {
        flex: 1; /* Expand to fill control panel */
        overflow-y: auto;
    }
    
    .word-list {
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: stretch;
        height: 100%;
    }
    
    .word-item {
        width: 100%;
        text-align: center;
        flex-shrink: 0;
    }
}

/* Compact sizing for smaller landscape screens */
@media screen and (max-width: 1024px) and (orientation: landscape) {
    /* Removed max-width to allow toolbar to fit larger stat content */
    
    .game-stats {
        gap: 0.4rem;
    }
    
    .control-panel {
        max-width: 200px;
    }
    
    .word-item {
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }
}

/* ========= END SCREENS ========= */
.end-screen .screen-content {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}

.end-screen-animation {
    margin: var(--spacing-xl) 0;
}

.trophy-container,
.defeat-container {
    position: relative;
    display: inline-block;
}

.trophy-glow,
.defeat-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 150px;
    height: 150px;
    background: radial-gradient(circle, rgba(0, 245, 255, 0.4), transparent);
    border-radius: var(--radius-round);
    animation: glowPulse 2s ease-in-out infinite;
}

.defeat-glow {
    background: radial-gradient(circle, rgba(255, 51, 102, 0.4), transparent);
}

@keyframes glowPulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.5; }
    50% { transform: translate(-50%, -50%) scale(1.2); opacity: 0.8; }
}

.trophy-icon,
.defeat-icon {
    font-size: 6rem;
    position: relative;
    z-index: 1;
    animation: bounceIn 0.6s ease;
}

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

.end-title {
    font-family: var(--font-display);
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: var(--spacing-sm);
}

.victory-title {
    background: linear-gradient(135deg, var(--color-success), var(--color-accent-primary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.defeat-title {
    background: linear-gradient(135deg, var(--color-danger), var(--color-warning));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.end-subtitle {
    color: var(--color-text-secondary);
    font-size: 1.1rem;
    margin-bottom: var(--spacing-lg);
}

.end-stats {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
    margin: var(--spacing-xl) 0;
}

.end-stat-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    min-width: 120px;
}

.end-stat-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.end-stat-value {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text-primary);
}

.end-actions {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
}

/* Buttons */
.btn-primary,
.btn-secondary {
    padding: 1rem 2rem;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-accent-primary), var(--color-accent-secondary));
    border: none;
    color: white;
    box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--color-text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}



/* ==========================================
   RESPONSIVE BREAKPOINTS - STANDARDIZED
   ========================================== */

/* ========= SMARTPHONE PORTRAIT (≤480px) ========= */
@media only screen and (max-width: 480px) and (orientation: portrait) {
    .game-title {
        font-size: 2rem;
        letter-spacing: 0.1em;
    }
    
    .stat-card {
        flex-direction: column;
        text-align: center;
    }
    
    .btn-icon-only {
        width: 50px;
        height: 50px;
    }
    
    .game-stats {
        gap: var(--stat-gap-sm-portrait);
    }
    
    .stat-item {
        padding: var(--stat-padding-sm-portrait);
        gap: var(--stat-gap-sm-portrait);
    }
    
    .stat-item .stat-icon {
        font-size: var(--stat-icon-sm-portrait);
    }
    
    .stat-info .stat-label {
        font-size: var(--stat-label-sm-portrait);
    }
    
    .stat-info .stat-value {
        font-size: var(--stat-value-sm-portrait);
    }
    
    .word-list {
        gap: 0.25rem;
    }
    
    .word-item {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
}

/* ========= SMARTPHONE LANDSCAPE (≤812px) ========= */
@media only screen and (max-width: 812px) and (orientation: landscape) {
    .btn-icon-only {
        width: 50px;
        height: 50px;
    }
    
    .game-stats {
        gap: var(--stat-gap-sm-landscape);
    }
    
    .stat-item {
        flex-direction: row; /* Horizontal for limited height */
        text-align: left;
        gap: var(--stat-gap-sm-landscape);
        min-width: 0;
        width: 100%;
        padding: var(--stat-padding-sm-landscape);
    }
    
    .stat-item .stat-icon {
        font-size: var(--stat-icon-sm-landscape);
    }
    
    .stat-info .stat-label {
        font-size: var(--stat-label-sm-landscape);
    }
    
    .stat-info .stat-value {
        font-size: var(--stat-value-sm-landscape);
    }
    
    .word-item {
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
    }
}

/* ========= TABLET PORTRAIT (600px-900px) ========= */
@media only screen and (min-width: 600px) and (max-width: 900px) and (orientation: portrait) {
    .stat-item {
        padding: var(--stat-padding-md-portrait);
    }
    
    .stat-item .stat-icon {
        font-size: var(--stat-icon-md-portrait);
    }
    
    .stat-info .stat-label {
        font-size: var(--stat-label-md-portrait);
    }
    
    .stat-info .stat-value {
        font-size: var(--stat-value-md-portrait);
    }
}

/* ========= TABLET LANDSCAPE (900px-1200px) ========= */
@media only screen and (min-width: 900px) and (max-width: 1200px) and (orientation: landscape) {
    .stat-item {
        padding: var(--stat-padding-md-landscape);
        flex-direction: row; /* Horizontal layout */
        text-align: left;
        gap: var(--stat-gap-md-landscape);
        min-width: var(--stat-min-width-md-landscape);
    }
    
    .stat-item .stat-icon {
        font-size: var(--stat-icon-md-landscape);
    }
    
    .stat-info .stat-label {
        font-size: var(--stat-label-md-landscape);
    }
    
    .stat-info .stat-value {
        font-size: var(--stat-value-md-landscape);
    }
}

/* ========= DESKTOP PORTRAIT (≥1200px) ========= */
@media only screen and (min-width: 1200px) and (orientation: portrait) {
    .stat-item {
        padding: var(--stat-padding-lg-portrait);
    }
    
    .stat-item .stat-icon {
        font-size: var(--stat-icon-lg-portrait);
    }
    
    .stat-info .stat-label {
        font-size: var(--stat-label-lg-portrait);
    }
    
    .stat-info .stat-value {
        font-size: var(--stat-value-lg-portrait);
    }
}

/* ========= DESKTOP LANDSCAPE (≥1200px) ========= */
@media only screen and (min-width: 1200px) and (orientation: landscape) {
    .stat-item {
        padding: var(--stat-padding-lg-landscape);
        gap: var(--stat-gap-lg-landscape);
    }
    
    .stat-item .stat-icon {
        font-size: var(--stat-icon-lg-landscape);
    }
    
    .stat-info .stat-label {
        font-size: var(--stat-label-lg-landscape);
    }
    
    .stat-info .stat-value {
        font-size: var(--stat-value-lg-landscape);
    }
}

/* General mobile adjustments (up to 768px) */


/* ========= STATS STYLING ========= */
.stat-value-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1;
}

.win-text { color: var(--color-accent-primary); }
.lose-text { color: var(--color-accent-secondary); }
.divider {
    color: var(--color-text-muted);
    font-weight: 400;
    font-size: 1.5rem;
    margin: 0 4px;
}

.stat-hint {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    margin-top: 4px;
    opacity: 0.5;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.3s ease;
    position: absolute;
    bottom: 8px;
    right: 12px;
}

.stat-card:hover .stat-hint {
    opacity: 1;
    color: var(--color-accent-primary);
    transform: translateX(-2px);
}

/* Stats Modal */
.stats-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000 !important;
    padding: var(--spacing-md);
    animation: fadeIn 0.3s ease;
    max-width: none !important; /* Override .screen max-width */
    margin: 0 !important; /* Override .screen margin */
}

.stats-modal {
    background: var(--color-bg-secondary);
    border: 2px solid var(--glass-border);
    border-radius: var(--radius-xl);
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
    display: flex;
    flex-direction: column;
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--glass-border);
}

.stats-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.btn-close {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--color-danger);
    color: var(--color-danger);
}

.stats-table-container {
    padding: var(--spacing-lg);
    overflow-x: auto;
    overflow-y: auto;
}

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

.stats-table thead th {
    padding: var(--spacing-md);
    text-align: left;
    font-family: var(--font-display);
    font-size: 0.875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-secondary);
    border-bottom: 2px solid var(--glass-border);
}

.stats-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.stats-table tbody td {
    padding: var(--spacing-md);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--color-text-primary);
}

.stat-highlight { color: var(--color-success) !important; font-weight: 700; }
.stat-danger { color: var(--color-danger) !important; font-weight: 700; }

@media (max-width: 600px) {
    .stats-table thead th, .stats-table tbody td {
        padding: var(--spacing-sm) var(--spacing-xs);
        font-size: 0.8rem;
    }
}

/* ========= NOTIFICATIONS ========= */
.game-notification {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    left: auto !important;
    top: auto !important;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border: 2px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-sm) var(--spacing-md);
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center;
    gap: var(--spacing-md);
    box-shadow: var(--shadow-lg);
    z-index: 9999 !important;
    transform: translateY(100px);
    opacity: 0;
    transition: all var(--transition-normal);
    min-width: 300px;
    max-width: 350px;
    overflow: hidden;
    cursor: pointer;
}

.game-notification.show {
    transform: translateY(0);
    opacity: 1;
}

.game-notification:hover {
    border-color: var(--color-accent-primary);
    box-shadow: var(--shadow-glow);
}

/* Grace Period Notification Specific */
.grace-period-notification {
    position: relative;
}

.grace-period-notification:hover {
    border-color: var(--color-accent-primary);
    box-shadow: var(--shadow-glow);
}

.notification-icon {
    font-size: 1.2rem;
    color: var(--color-accent-primary);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-round);
    flex-shrink: 0;
}

.notification-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
}

.notification-title {
    font-family: var(--font-display);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--color-text-primary);
    margin-bottom: 0;
    line-height: 1.2;
}

.notification-message {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.notification-timer {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-accent-gold);
    margin-left: auto;
}

.notification-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--color-accent-primary), var(--color-accent-secondary));
    width: 100%;
    transition: width 1s linear;
    box-shadow: 0 0 10px var(--color-accent-primary);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ========= RESPONSIVE ========= */

/* ========= MOBILE RESPONSIVE (max-width: 480px) ========= */
@media (max-width: 480px) {
    /* Level Grid */
    .level-grid {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
        gap: 0.5rem;
    }
    
    .level-card {
        min-height: 80px;
        padding: 0.5rem 0.25rem;
    }
    
    /* Header */
    h1.game-title {
        font-size: 1.8rem;
        letter-spacing: 0.05em;
    }
    
    .logo-circle {
        width: 80px;
        height: 80px;
    }
    
    .logo-icon {
        font-size: 2.5rem;
    }
    
    .screen-content {
        padding: 1rem;
    }
    
    .stats-overview {
        padding: 0 0.5rem;
    }
    
    .stat-card {
        padding: 0.75rem 1rem;
        min-width: 0;
        flex: 1 1 100%;
        max-width: 100%;
    }
    
    .stat-icon {
        font-size: 1.5rem;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .stat-label {
        font-size: 0.75rem;
    }
    
    .section-title {
        font-size: 1.2rem;
    }
    
    .level-selection-section {
        max-width: 100%;
        width: 100%;
    }
    
    .how-to-play-section {
        margin-top: 2rem;
        margin-bottom: 2rem;
        max-width: 100%;
        width: 100%;
    }
    
    .rules-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        max-width: 100%;
    }
    
    .rule-card {
        padding: 1rem;
        min-width: 0;
    }
    
    .rule-icon {
        font-size: 2rem;
    }
    
    .rule-icon i {
        font-size: 2rem;
    }
    
    .rule-title {
        font-size: 0.95rem;
    }
    
    .rule-text {
        font-size: 0.8rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .difficulty-grid {
        grid-template-columns: 1fr;
    }
    
    /* Game Elements */
    .word-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    }
    
    .letter-tile {
        font-size: 1.5rem;
        padding: 1rem;
    }
    
    .letter-grid {
        border-width: 2px;
        padding: 0.5rem;
        gap: 3px;
    }
    
    .grid-cell {
        font-size: 1rem;
    }
    
    .word-item {
        padding: 0.3rem 0.5rem;
        font-size: 0.7rem;
    }
    
    /* Stats Modal */
    .stats-modal {
        width: 95%;
        max-height: 85vh;
    }

    .stats-header {
        padding: var(--spacing-md);
    }

    .stats-title {
        font-size: 1.25rem;
    }

    .stats-table-container {
        padding: var(--spacing-sm);
    }

    .stats-table thead th,
    .stats-table tbody td {
        padding: var(--spacing-sm) var(--spacing-xs);
        font-size: 0.8rem;
    }
}

/* ========= TABLET RESPONSIVE (481px - 1024px) ========= */
@media (min-width: 481px) and (max-width: 1024px) {
    /* Prevent horizontal overflow */
    html,
    body {
        overflow-x: hidden;
        max-width: 100vw;
        width: 100%;
    }
    
    .app-container {
        max-width: 100%;
        width: 100%;
        overflow-x: hidden;
    }
    
    .screen {
        max-width: 100%;
        width: 100%;
        overflow-x: hidden;
    }
    
    .screen-content {
        max-width: 100%;
        width: 100%;
        overflow-x: hidden;
        padding: 0 1rem;
        box-sizing: border-box;
    }
    
    /* Start Screen */
    h1.game-title {
        font-size: 2.5rem;
        letter-spacing: 0.1em;
    }
    
    .logo-circle {
        width: 100px;
        height: 100px;
    }
    
    .level-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 0.75rem;
        max-width: none;
        width: 100%;
    }
    
    .level-card {
        min-height: 85px;
        padding: 0.6rem 0.4rem;
    }
    
    .stat-card {
        padding: 1rem 1.5rem;
    }
    
    /* Ensure all sections don't overflow */
    .level-selection-section,
    .level-section,
    .how-to-play-section {
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
    }
    
    /* How to Play Section - Fix Overflow */
    .rules-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1.25rem;
        max-width: 100%;
        width: 100%;
    }
    
    .rule-card {
        padding: 1.25rem;
        min-width: 0;
        max-width: 100%;
    }
    
    /* Footer */
    footer {
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
    }
}
