/* ========================================
   NEON SNAKE - PREMIUM GAME DESIGN
   ======================================== */

/* ========= ROOT VARIABLES ========= */
:root {
    /* Color Palette - Matching Sudoku's Vibrant & Energetic Theme */
    --color-bg-primary: #0f0a2e;
    --color-bg-secondary: #1a0f3d;
    --color-bg-tertiary: #2d1b5e;
    
    --color-accent-primary: #00ffff;
    --color-accent-secondary: #ff00ff;
    --color-accent-tertiary: #ffd700; /* Gold */
    --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 (Enhanced to match Sudoku) */
    --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;
    
    /* Typography */
    --font-display: 'Orbitron', sans-serif;
    --font-body: 'Inter', sans-serif;
    
    /* ========= RESPONSIVE STAT VARIABLES (MATCHING SUDOKU) ========= */
    /* 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: 0.5rem 0.5rem;
    --stat-gap-md-landscape: 0.75rem;
    
    /* Desktop Portrait */
    --stat-icon-lg-portrait: 1.5rem;
    --stat-label-lg-portrait: 1.2rem;
    --stat-value-lg-portrait: 1.6rem;
    --stat-padding-lg-portrait: 0.5rem 1rem;
    
    /* Desktop Landscape */
    --stat-icon-lg-landscape: 1.6rem;
    --stat-label-lg-landscape: 1.2rem;
    --stat-value-lg-landscape: 1.6rem;
    --stat-padding-lg-landscape: 1rem;
    --stat-gap-lg-landscape: 0.75rem;

    /* Board Padding */
    --board-padding-sm-portrait: 15px;
    --board-padding-sm-landscape: 10px;
    --board-padding-md-portrait: 20px;
    --board-padding-md-landscape: 15px;
    --board-padding-lg: 30px;
    
    --board-padding: var(--board-padding-lg); /* Default */
}

/* ========= 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;
}

/* ========= UTILITIES ========= */
.hidden {
    display: none !important;
}

/* ========= 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 (MATCHING SUDOKU) ========= */
.app-container {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100vw;
    overflow-x: hidden;
}

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

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

.screen-content {
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

@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;
    box-shadow: var(--shadow-glow);
    animation: logoFloat 3s ease-in-out infinite;
}

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

.logo-icon {
    font-size: 3.5rem;
    filter: drop-shadow(0 0 10px var(--color-accent-primary));
}

.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 50px rgba(0, 245, 255, 0.6);
    animation: titleGlow 3s ease-in-out infinite;
}

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

/* 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;
    color: var(--color-accent-tertiary);
}

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

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

/* Level Selection (Embedded) */
.level-selection-section {
    width: 100%;
    max-width: 800px;
    margin: 0 auto var(--spacing-lg);
}

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

.level-grid-container {
    width: 100%;
    padding: 0;
}

.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-num {
    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);
}

/* Level Guide */
.level-guide-section {
    width: 100%;
    max-width: 800px;
    margin: 0 auto var(--spacing-lg);
}

.guide-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-md);
}



.guide-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 1rem;
    transition: all var(--transition-normal);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.guide-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--color-accent-primary);
    transform: translateY(-2px);
}

.guide-item.highlight {
    border-color: rgba(0, 245, 255, 0.3);
    background: rgba(0, 245, 255, 0.05);
}

.guide-item.special {
    border-color: rgba(252, 0, 255, 0.3);
    background: rgba(252, 0, 255, 0.05);
}

.guide-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

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

.guide-desc {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    line-height: 1.2;
}



.level-lock {
    font-size: 1.5rem;
    color: var(--color-text-muted);
    opacity: 0.7;
}


/* ========= GAME SCREEN (MATCHING SUDOKU) ========= */
#game-screen {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    max-width: 100%;
    padding: 0;
    overflow: hidden;
}

.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;
    justify-content: center;  /* Center the inner wrapper */
    gap: var(--spacing-sm);
    flex-shrink: 0;
    width: 100%;  /* Full width */
}

/* Wrapper to constrain toolbar content width to match game board */
.game-top-bar-inner {
    max-width: min(500px, calc(100vw - 2rem));  /* Match the game canvas max width */
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.game-stats {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    background: rgba(255, 255, 255, 0.03);
    padding: var(--spacing-md) var(--spacing-sm);
    border-radius: var(--radius-md);
}

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

.stat-info .stat-label {
    font-size: 0.65rem;  /* Mobile base */
    color: var(--color-text-muted);
}

.stat-info .stat-value {
    font-size: 0.9rem;  /* Mobile base */
    font-weight: 700;
    color: var(--color-text-primary);
}



/* Game Board Wrapper */
.game-board-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* Responsive padding - scales with screen size */
    /* Responsive padding - scales with screen size */
    padding: var(--board-padding);
    
    overflow: hidden;
    min-height: 0;
    position: relative;
    /* Ensure it fills available height */
    width: 100%;
    height: 100%;
}

.snake-canvas-container {
    position: relative;
    
    /* Clean dark background */
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    
    /* Simple solid neon border - ONE border only */
    border: 3px solid;
    border-image: linear-gradient(135deg, #00f5ff, #fc00ff) 1;
    border-radius: 12px;
    
    /* Subtle shadow for depth */
    box-shadow: 
        0 4px 20px rgba(0, 0, 0, 0.5),
        0 0 40px rgba(0, 245, 255, 0.2);
}

.snake-canvas-container.portal-active {
    border-style: dashed;
    animation: portalPulse 2s infinite;
}

@keyframes portalPulse {
    0% { box-shadow: 0 0 20px rgba(0, 245, 255, 0.2); }
    50% { box-shadow: 0 0 40px rgba(0, 245, 255, 0.6); }
    100% { box-shadow: 0 0 20px rgba(0, 245, 255, 0.2); }
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Pause Overlay */
.ui-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 5, 24, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: var(--spacing-md);
    z-index: 10;
    animation: fadeIn 0.2s ease;
}

.ui-overlay h2 {
    font-family: var(--font-display);
    font-size: 3rem;
    color: var(--color-text-primary);
    text-shadow: 0 0 15px var(--color-accent-tertiary);
}

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

/* Control Panel (Mobile) */
.control-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border-top: 1px solid var(--glass-border);
    padding: var(--spacing-sm);
    display: none; /* Hidden by default */
    justify-content: center;
    flex-shrink: 0;
}

.d-pad {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(2, 60px);
    gap: 10px;
    justify-items: center;
}

.control-btn {
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--color-text-primary);
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.control-btn:active {
    background: rgba(0, 245, 255, 0.2);
    border-color: var(--color-accent-primary);
}

.control-btn.up { grid-column: 2; grid-row: 1; }
.control-btn.left { grid-column: 1; grid-row: 2; }
.control-btn.down { grid-column: 2; grid-row: 2; }
.control-btn.right { grid-column: 3; grid-row: 2; }

/* ========= 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;
    border-radius: var(--radius-round);
    animation: glowPulse 2s ease-in-out infinite;
}

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

.trophy-icon, .defeat-icon {
    font-size: 6rem;
    position: relative;
    z-index: 1;
}

.end-title {
    font-family: var(--font-display);
    font-size: 3rem;
    margin-bottom: var(--spacing-xs);
}

.victory-title { color: var(--color-accent-primary); }
.defeat-title { color: var(--color-danger); }

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

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

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

.end-stat-card.highlight {
    border-color: var(--color-accent-primary);
    background: rgba(0, 245, 255, 0.1);
}

.end-stat-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.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);
}

.end-actions .btn-secondary {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
    color: white;
    font-weight: 700;
}

.end-actions .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: white;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.2);
}

/* ========= BUTTONS ========= */
.btn-primary, .btn-secondary, .btn-danger {
    padding: 1rem 2rem;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-normal);
    font-family: var(--font-display);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: linear-gradient(135deg, #00f5ff, #fc00ff);
    color: white;
    box-shadow: 0 4px 15px rgba(0, 245, 255, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 245, 255, 0.5);
    filter: brightness(1.1);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.15);
    color: var(--color-text-primary);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: var(--color-text-primary);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.btn-danger {
    background: linear-gradient(135deg, var(--color-danger), #cc0044);
    color: #fff;
}

.btn-large {
    font-size: 1.2rem;
    padding: 1.2rem 2.5rem;
}

.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);
    text-decoration: none;
    font-size: 1.2rem;
}

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

/* ========= 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-small {
        font-size: 1.2rem;
    }

    .game-top-bar {
        padding: 0.5rem;
    }
    
    .stat-item {
        padding: 0.25rem 0.5rem;
    }
    
    .btn-large {
        padding: 1rem 2rem;
        font-size: 1rem;
    }
    
    .guide-item {
        padding: 0.75rem;
        min-width: 0;
    }
    
    .guide-title {
        font-size: 0.85rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .guide-desc {
        font-size: 0.75rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .guide-header {
        font-size: 0.65rem;
    }
    
    .level-selection-section,
    .level-guide-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;
    }
    
    /* 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) {
    /* 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;
    }
    
    .level-card {
        min-height: 85px;
        padding: 0.6rem 0.4rem;
    }
    
    .guide-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .stat-card {
        padding: 1rem 1.5rem;
    }
    
    /* Game Screen */
    .stat-info .stat-label {
        font-size: 0.85rem;
    }
    
    .stat-info .stat-value {
        font-size: 1.2rem;
    }
    
    /* How to Play Section - Fix Overflow */
    .how-to-play-section {
        max-width: 100%;
        width: 100%;
    }
    
    .rules-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1.25rem;
        max-width: 100%;
    }
    
    .rule-card {
        padding: 1.25rem;
        min-width: 0;
        max-width: 100%;
    }
}

/* ========= BOARD PADDING RESPONSIVENESS ========= */

/* Smartphone Portrait */
@media (max-width: 480px) and (orientation: portrait) {
    :root {
        --board-padding: var(--board-padding-sm-portrait);
    }
}

/* ========= 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;
}

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

.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);
}

.stats-title .stats-icon {
    font-size: 1.75rem;
    color: var(--color-accent-primary);
}

.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;
    max-height: calc(90vh - 100px);
    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);
    position: sticky;
    top: 0;
    background: var(--color-bg-secondary);
    z-index: 1;
}

.stats-table tbody tr {
    transition: background var(--transition-fast);
}

.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-accent-primary) !important;
    font-weight: 700;
}



/* Smartphone Landscape */
@media (max-width: 900px) and (orientation: landscape) {
    :root {
        --board-padding: var(--board-padding-sm-landscape);
    }
}

/* Tablet Portrait */
@media (min-width: 481px) and (max-width: 1024px) and (orientation: portrait) {
    :root {
        --board-padding: var(--board-padding-md-portrait);
    }
}

/* Tablet Landscape */
@media (min-width: 901px) and (max-width: 1280px) and (orientation: landscape) {
    :root {
        --board-padding: var(--board-padding-md-landscape);
    }
}


