@import url('https://fonts.googleapis.com/css2?family=Crimson+Text:wght@400;600;700&family=Playfair+Display:wght@400;500;600;700&display=swap');

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Crimson Text', Georgia, serif;
    background: linear-gradient(135deg, #8B4513 0%, #A0522D  25%, #CD853F  50%, #D2691E 75%, #8B4513 100%);
    background-size: 400% 400%;
    animation: woodGrain 20s ease infinite;
    color: #2F1B14;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    font-weight: 400;
    line-height: 1.6;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(ellipse at center, transparent 0%, rgba(0,0,0,0.1) 100%);
    pointer-events: none;
    z-index: 0;
}

body::after {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at top, rgba(255, 215, 0, 0.15), transparent 45%),
        radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.1), transparent 40%),
        radial-gradient(circle at 80% 30%, rgba(255, 255, 255, 0.08), transparent 45%);
    mix-blend-mode: screen;
    pointer-events: none;
    z-index: 0;
}

.container {
    position: relative;
    z-index: 1;
}

@keyframes woodGrain {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.container {
    display: flex;
    gap: 30px;
    max-width: 1000px;
    width: 100%;
    margin: 0 auto;
    animation: slideUp 0.6s ease-out;
}

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

.game-section {
    flex: 1;
    max-width: 480px;
    background: linear-gradient(145deg, #DEB887 0%, #D2B48C 50%, #BC9A6A 100%);
    border-radius: 12px;
    padding: 30px;
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        inset 0 -1px 0 rgba(0, 0, 0, 0.2),
        0 10px 25px rgba(0, 0, 0, 0.3),
        0 5px 10px rgba(0, 0, 0, 0.2);
    border: 2px solid #8B7355;
    position: relative;
}

.game-section::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 16px;
    background: conic-gradient(from 120deg, rgba(255, 215, 0, 0.35), transparent 30%, rgba(255, 215, 0, 0.35));
    opacity: 0.6;
    filter: blur(12px);
    z-index: -1;
    animation: haloPulse 6s ease-in-out infinite;
}

.info-section {
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.info-section h3 {
    font-family: 'Playfair Display', serif;
    font-size: 24px;
    font-weight: 600;
    color: #5D4E37;
    margin: 0 0 15px 0;
    text-align: center;
    padding-bottom: 10px;
    border-bottom: 2px solid rgba(139, 115, 85, 0.3);
}

.header {
    margin-bottom: 30px;
}

.title-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 2px solid rgba(139, 115, 85, 0.3);
}

.title-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

h1 {
    font-family: 'Playfair Display', serif;
    font-size: 72px;
    font-weight: 700;
    color: #5D4E37;
    text-shadow: 
        2px 2px 0 #F5DEB3,
        4px 4px 8px rgba(0, 0, 0, 0.3);
    margin: 0;
    letter-spacing: -1px;
}

.supreme-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-radius: 999px;
    background: linear-gradient(135deg, #3C1810, #8B4513);
    color: #FFD700;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 215, 0, 0.6);
}

.supreme-badge i {
    font-size: 14px;
}

.supreme-tagline {
    text-align: center;
    margin-bottom: 20px;
    font-weight: 600;
    font-size: 16px;
    color: #5D4E37;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.score-container {
    display: flex;
    gap: 15px;
}

.score-box {
    background: linear-gradient(145deg, #F5DEB3 0%, #DEB887 100%);
    padding: 15px 25px;
    border-radius: 8px;
    color: #5D4E37;
    min-width: 120px;
    text-align: center;
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.5),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1),
        0 4px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    border: 1px solid #CD853F;
}

.score-box:hover {
    transform: translateY(-2px);
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.6),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1),
        0 6px 12px rgba(0, 0, 0, 0.3);
}

.score-label {
    font-size: 13px;
    font-weight: 600;
    display: block;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
    color: #8B7355;
}

#score, #best-score {
    font-size: 26px;
    font-weight: 700;
    color: #5D4E37;
}



.grid-size-selector {
    margin: 20px auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    background: rgba(245, 222, 179, 0.2);
    padding: 15px 20px;
    border-radius: 12px;
    border: 2px solid rgba(139, 69, 19, 0.2);
    max-width: 100%;
    box-sizing: border-box;
}

.grid-size-selector label {
    font-family: 'Playfair Display', serif;
    font-weight: 600;
    color: #8B4513;
    font-size: 16px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.grid-size-selector select {
    background: linear-gradient(135deg, #F5DEB3 0%, #DEB887 50%, #CD853F 100%);
    border: 3px solid #8B4513;
    border-radius: 12px;
    padding: 12px 16px;
    font-family: 'Playfair Display', serif;
    font-size: 15px;
    font-weight: 600;
    color: #2F1B14;
    cursor: pointer;
    min-width: 160px;
    max-width: 100%;
    box-sizing: border-box;
    box-shadow: 0 4px 8px rgba(139, 69, 19, 0.3), inset 0 1px 2px rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23654321' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px;
}

.grid-size-selector select:hover {
    background: linear-gradient(135deg, #DEB887 0%, #CD853F 50%, #A0522D 100%);
    box-shadow: 0 6px 12px rgba(139, 69, 19, 0.4), inset 0 1px 2px rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
    border-color: #654321;
}

.grid-size-selector select:focus {
    outline: none;
    border-color: #5D4E37;
    box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.3), 0 6px 12px rgba(139, 69, 19, 0.4);
    transform: translateY(-1px);
}

.grid-size-selector select option {
    background: #F5DEB3;
    color: #2F1B14;
    font-weight: 600;
    padding: 8px;
}

button {
    background: linear-gradient(145deg, #D2B48C 0%, #BC9A6A 100%);
    color: #5D4E37;
    border: 2px solid #8B7355;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s ease;
    text-transform: none;
    letter-spacing: 0.5px;
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1),
        0 4px 8px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 8px;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1),
        0 6px 12px rgba(0, 0, 0, 0.3);
    background: linear-gradient(145deg, #DEB887 0%, #D2B48C 100%);
}

button:active {
    transform: translateY(0px);
    box-shadow: 
        inset 0 2px 4px rgba(0, 0, 0, 0.2),
        0 2px 4px rgba(0, 0, 0, 0.1);
}

button i {
    font-size: 18px;
    transition: all 0.2s ease;
}

button:hover i {
    transform: scale(1.1);
}

button:active i {
    transform: scale(0.95);
}

/* Add focus styles for accessibility */
button:focus {
    outline: 3px solid rgba(205, 133, 63, 0.5);
    outline-offset: 2px;
}

/* Add loading state for buttons */
button.loading {
    position: relative;
    color: transparent;
}

button.loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin-left: -10px;
    margin-top: -10px;
    border: 2px solid transparent;
    border-top-color: #5D4E37;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.game-intro, .instructions {
    color: #5D4E37;
    margin-bottom: 15px;
    line-height: 1.6;
    font-size: 16px;
    font-weight: 400;
    text-align: center;
    background: rgba(245, 222, 179, 0.3);
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #CD853F;
}

.game-intro {
    font-weight: 500;
}

.instructions {
    font-size: 14px;
    margin-bottom: 0;
}

.game-container {
    background: linear-gradient(145deg, #8B7355 0%, #6B5B47 100%);
    padding: 20px;
    border-radius: 8px;
    position: relative;
    margin-top: 20px;
    user-select: none;
    box-shadow: 
        inset 0 2px 0 rgba(255, 255, 255, 0.1),
        inset 0 -2px 0 rgba(0, 0, 0, 0.2),
        0 8px 16px rgba(0, 0, 0, 0.3);
    border: 2px solid #5D4E37;
}

.game-layout {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.grid-area {
    flex: 1;
    aspect-ratio: 1;
    max-width: 500px;
}

.control-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 5px;
    min-width: 46px;
    align-items: center;
}

.game-control-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: linear-gradient(135deg, #8B4513, #A0522D);
    color: #FFF8DC;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 3px 6px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.2s ease;
    border: 1px solid #CD853F;
}

.game-control-btn:hover {
    background: linear-gradient(135deg, #A0522D, #CD853F);
    transform: translateY(-1px);
    box-shadow: 
        0 4px 8px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.game-control-btn:active {
    transform: translateY(0);
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.game-control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.game-control-btn i {
    pointer-events: none;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 12px;
    padding: 12px;
    position: relative;
    border-radius: 4px;
    aspect-ratio: 1;
    background: linear-gradient(145deg, #5D4E37 0%, #4A3C2A 100%);
    width: 100%;
    height: 100%;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.4);
}

.grid-container::after {
    content: '';
    position: absolute;
    inset: 8px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    pointer-events: none;
    mix-blend-mode: screen;
}

/* Dynamic grid sizes */
.grid-container.grid-4x4 {
    grid-template-columns: repeat(4, 1fr) !important;
    grid-template-rows: repeat(4, 1fr) !important;
    gap: 12px !important;
    padding: 12px !important;
}

.grid-container.grid-5x5 {
    grid-template-columns: repeat(5, 1fr) !important;
    grid-template-rows: repeat(5, 1fr) !important;
    gap: 10px !important;
    padding: 10px !important;
}

.grid-container.grid-6x6 {
    grid-template-columns: repeat(6, 1fr) !important;
    grid-template-rows: repeat(6, 1fr) !important;
    gap: 8px !important;
    padding: 8px !important;
}

.grid-cell {
    background: linear-gradient(145deg, #8B7355 0%, #6B5B47 100%);
    border-radius: 4px;
    transition: all 0.15s ease;
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        inset 0 -1px 0 rgba(0, 0, 0, 0.2);
    aspect-ratio: 1;
    min-width: 0;
    min-height: 0;
}

/* Grid cells are now positioned by CSS Grid automatically */

.tile {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 4px;
    font-weight: 700;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.15s ease;
    transform: scale(1);
    z-index: 1;
    border: 2px solid rgba(0, 0, 0, 0.2);
}

.tile span {
    font-family: 'Playfair Display', serif;
    font-size: 30px;
    font-weight: 700;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
    letter-spacing: -0.5px;
}

/* Wooden tile designs with natural wood tones */
.tile-2 { 
    background: linear-gradient(145deg, #F5DEB3 0%, #DEB887 100%);
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1),
        0 4px 8px rgba(0, 0, 0, 0.2);
    color: #8B4513;
}
.tile-4 { 
    background: linear-gradient(145deg, #DEB887 0%, #D2B48C 100%);
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1),
        0 4px 8px rgba(0, 0, 0, 0.2);
    color: #654321;
}
.tile-8 { 
    background: linear-gradient(145deg, #D2B48C 0%, #BC9A6A 100%);
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        inset 0 -1px 0 rgba(0, 0, 0, 0.15),
        0 4px 8px rgba(0, 0, 0, 0.25);
    color: #5D4E37;
}
.tile-16 { 
    background: linear-gradient(145deg, #CD853F 0%, #B8860B 100%);
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        inset 0 -1px 0 rgba(0, 0, 0, 0.15),
        0 4px 8px rgba(0, 0, 0, 0.25);
    color: #FFFFFF;
}
.tile-32 { 
    background: linear-gradient(145deg, #B8860B 0%, #A0522D 100%);
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.2),
        inset 0 -1px 0 rgba(0, 0, 0, 0.2),
        0 4px 8px rgba(0, 0, 0, 0.3);
    color: #FFFFFF;
}
.tile-64 { 
    background: linear-gradient(145deg, #A0522D 0%, #8B4513 100%);
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.2),
        inset 0 -1px 0 rgba(0, 0, 0, 0.2),
        0 4px 8px rgba(0, 0, 0, 0.3);
    color: #FFFFFF;
}
.tile-128 { 
    background: linear-gradient(145deg, #8B4513 0%, #722F37 100%);
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.15),
        inset 0 -1px 0 rgba(0, 0, 0, 0.25),
        0 6px 12px rgba(0, 0, 0, 0.35);
    color: #FFFFFF;
}
.tile-128 span { font-size: 26px; }
.tile-256 { 
    background: linear-gradient(145deg, #722F37 0%, #5C4033 100%);
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        inset 0 -1px 0 rgba(0, 0, 0, 0.3),
        0 6px 12px rgba(0, 0, 0, 0.4);
    color: #FFFFFF;
}
.tile-256 span { font-size: 26px; }
.tile-512 { 
    background: linear-gradient(145deg, #5C4033 0%, #4A2C2A 100%);
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        inset 0 -1px 0 rgba(0, 0, 0, 0.3),
        0 6px 12px rgba(0, 0, 0, 0.4);
    color: #FFD700;
}
.tile-512 span { font-size: 26px; }
.tile-1024 { 
    background: linear-gradient(145deg, #4A2C2A 0%, #3C1810 100%);
    box-shadow: 
        inset 0 1px 0 rgba(255, 215, 0, 0.2),
        inset 0 -1px 0 rgba(0, 0, 0, 0.4),
        0 8px 16px rgba(0, 0, 0, 0.5);
    color: #FFD700;
}
.tile-1024 span { font-size: 22px; }
.tile-2048 { 
    background: linear-gradient(145deg, #3C1810 0%, #2F1B14 100%);
    box-shadow: 
        inset 0 1px 0 rgba(255, 215, 0, 0.3),
        inset 0 -1px 0 rgba(0, 0, 0, 0.4),
        0 10px 20px rgba(0, 0, 0, 0.6),
        0 0 20px rgba(255, 215, 0, 0.3);
    color: #FFD700;
    border: 2px solid #FFD700;
}
.tile-2048 span { 
    font-size: 22px; 
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.tile-4096,
.tile-8192 {
    background: linear-gradient(145deg, #1d0f0a 0%, #120905 100%);
    box-shadow: 
        inset 0 1px 0 rgba(255, 215, 0, 0.4),
        inset 0 -1px 0 rgba(0, 0, 0, 0.5),
        0 12px 22px rgba(0, 0, 0, 0.6),
        0 0 25px rgba(255, 215, 0, 0.45);
    color: #FFD700;
    border: 2px solid rgba(255, 215, 0, 0.8);
}

.tile-4096 span,
.tile-8192 span {
    font-size: 20px;
}

.game-message {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(47, 27, 20, 0.95);
    backdrop-filter: blur(10px);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border-radius: 8px;
    color: #F5DEB3;
    z-index: 100;
}

.game-message.active {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

.game-message p {
    font-family: 'Playfair Display', serif;
    font-size: 42px;
    font-weight: 700;
    margin-bottom: 25px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
    color: #FFD700;
}

/* Tablet styles */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
        gap: 25px;
        max-width: 600px;
    }

    .info-section {
        width: 100%;
        order: 2;
    }

    .game-section {
        order: 1;
        max-width: 100%;
    }
    
    .game-layout {
        flex-direction: column;
        gap: 10px;
    }
    
    .control-area {
        flex-direction: row;
        justify-content: center;
        min-width: auto;
        gap: 8px;
    }
    
    .game-control-btn {
        width: 34px;
        height: 34px;
        font-size: 13px;
    }

    h1 {
        font-size: 64px;
    }

    .grid-size-selector {
        flex-direction: column;
        gap: 10px;
        padding: 12px 15px;
    }

    .grid-size-selector select {
        min-width: 140px;
        font-size: 14px;
        padding: 10px 14px;
        padding-right: 35px;
    }

    button {
        flex: 1;
        min-width: 120px;
        padding: 14px 20px;
    }
}

/* Mobile styles */
@media (max-width: 480px) {
    body {
        padding: 15px;
        min-height: 100vh;
        align-items: flex-start;
        padding-top: 20px;
    }
    
    .container {
        gap: 20px;
        width: 100%;
    }
    
    .control-area {
        gap: 6px;
    }
    
    .game-control-btn {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }
    
    .game-control-btn i {
        font-size: 13px;
    }

    .game-section {
        padding: 20px;
        border-radius: 16px;
        box-shadow: 
            inset 0 1px 0 rgba(255, 255, 255, 0.4),
            inset 0 -1px 0 rgba(0, 0, 0, 0.2),
            0 8px 20px rgba(0, 0, 0, 0.3);
    }

    .header {
        margin-bottom: 25px;
    }

    .title-section {
        flex-direction: column;
        gap: 15px;
        align-items: center;
        text-align: center;
    }

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

    h1 {
        font-size: 52px;
        margin-bottom: 0;
    }

    .score-container {
        justify-content: center;
        gap: 12px;
    }

    .grid-size-selector {
        flex-direction: column;
        gap: 8px;
        padding: 10px 12px;
        margin: 15px 0;
    }

    .grid-size-selector label {
        font-size: 14px;
        text-align: center;
    }

    .grid-size-selector select {
        min-width: 100%;
        width: 100%;
        font-size: 13px;
        padding: 8px 12px;
        padding-right: 30px;
        background-size: 14px;
        background-position: right 8px center;
    }

    .score-box {
        padding: 14px 20px;
        min-width: 110px;
        font-size: 14px;
    }

    #score, #best-score {
        font-size: 24px;
    }



    button {
        padding: 16px 12px;
        font-size: 13px;
        font-weight: 600;
        justify-content: center;
        min-height: 50px;
    }

    button i {
        font-size: 16px;
    }

    .game-intro, .instructions {
        font-size: 15px;
        text-align: center;
        margin-bottom: 12px;
    }

    .supreme-tagline {
        font-size: 12px;
        margin-bottom: 14px;
    }

    .game-container {
        padding: 16px;
        margin-top: 15px;
    }

    .grid-container {
        grid-gap: 10px;
    }

    .grid-cell {
        width: calc(25% - 7.5px);
        height: calc(25% - 7.5px);
    }

    /* Update grid cell positions for mobile */
    .grid-cell:nth-child(2) { left: calc(25% + 2.5px); }
    .grid-cell:nth-child(3) { left: calc(50% + 5px); }
    .grid-cell:nth-child(4) { left: calc(75% + 7.5px); }
    .grid-cell:nth-child(5) { top: calc(25% + 2.5px); }
    .grid-cell:nth-child(6) { left: calc(25% + 2.5px); top: calc(25% + 2.5px); }
    .grid-cell:nth-child(7) { left: calc(50% + 5px); top: calc(25% + 2.5px); }
    .grid-cell:nth-child(8) { left: calc(75% + 7.5px); top: calc(25% + 2.5px); }
    .grid-cell:nth-child(9) { top: calc(50% + 5px); }
    .grid-cell:nth-child(10) { left: calc(25% + 2.5px); top: calc(50% + 5px); }
    .grid-cell:nth-child(11) { left: calc(50% + 5px); top: calc(50% + 5px); }
    .grid-cell:nth-child(12) { left: calc(75% + 7.5px); top: calc(50% + 5px); }
    .grid-cell:nth-child(13) { top: calc(75% + 7.5px); }
    .grid-cell:nth-child(14) { left: calc(25% + 2.5px); top: calc(75% + 7.5px); }
    .grid-cell:nth-child(15) { left: calc(50% + 5px); top: calc(75% + 7.5px); }
    .grid-cell:nth-child(16) { left: calc(75% + 7.5px); top: calc(75% + 7.5px); }

    .tile span {
        font-size: 24px;
        font-weight: 800;
    }

    .tile-128 span, .tile-256 span, .tile-512 span { 
        font-size: 20px; 
    }
    
    .tile-1024 span, .tile-2048 span { 
        font-size: 18px; 
    }

    .stats-container {
        padding: 16px;
        gap: 10px;
    }

    .stat-box {
        padding: 12px 8px;
    }

    .stat-value {
        font-size: 20px;
    }

    .stat-label {
        font-size: 11px;
    }

    .game-message p {
        font-size: 36px;
        margin-bottom: 20px;
    }

    .grid-container {
        touch-action: none;
        position: relative;
        z-index: 10;
    }
}

@media (max-width: 1200px) {
    .container {
        flex-direction: column;
        align-items: center;
    }

    .info-section {
        width: 100%;
        max-width: 500px;
    }

    .game-section {
        margin-bottom: 20px;
    }





    button {
        padding: 10px 20px;
        font-size: 14px;
    }

    button i {
        font-size: 16px;
    }
}

/* Extra Small Mobile Devices */
@media (max-width: 320px) {
    body {
        padding: 10px;
        padding-top: 15px;
    }
    
    .container {
        gap: 15px;
    }
    
    .game-section {
        padding: 15px;
    }
    
    h1 {
        font-size: 42px;
    }
    
    .grid-size-selector {
        padding: 8px 10px;
        margin: 10px 0;
        border-radius: 8px;
    }
    
    .grid-size-selector label {
        font-size: 13px;
    }
    
    .grid-size-selector select {
        font-size: 12px;
        padding: 6px 10px;
        padding-right: 28px;
        border-radius: 8px;
        border-width: 2px;
    }
    
    .score-container {
        gap: 8px;
    }
    
    .score-box {
        padding: 10px 15px;
    }
    
    .score-label {
        font-size: 10px;
    }
    
    .game-container {
        padding: 12px;
    }
    
    .control-area {
        gap: 4px;
    }
    
    .game-control-btn {
        width: 28px;
        height: 28px;
        font-size: 11px;
    }
    
    .instructions, .game-intro {
        font-size: 13px;
    }
    
    .game-footer {
        margin-top: 20px;
        padding: 15px 0;
    }
    
    .footer-links {
        gap: 10px;
    }
    
    .footer-link {
        padding: 8px 12px;
        font-size: 12px;
        min-width: 80px;
    }
    
    .footer-copyright {
        font-size: 11px;
    }
}

@keyframes pop {
    0% { 
        transform: scale(0.8); 
        opacity: 0; 
    }
    100% { 
        transform: scale(1); 
        opacity: 1; 
    }
}

@keyframes merge {
    0% { 
        transform: scale(1); 
    }
    50% { 
        transform: scale(1.05); 
    }
    100% { 
        transform: scale(1); 
    }
}

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

@keyframes woodGrain {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.tile-new {
    animation: pop 0.25s ease-out;
    transform-origin: center;
}

.tile-merged {
    z-index: 2;
    animation: merge 0.3s ease-out;
}

/* Add subtle hover effect for desktop */
@media (hover: hover) {
    .game-container:hover .tile {
        transition: all 0.15s ease;
    }
}



/* Add subtle glow effect for high value tiles */
.tile-512, .tile-1024, .tile-2048 {
    position: relative;
}

.tile-2048::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, #FFD700, #FFA500, #FFD700);
    border-radius: inherit;
    z-index: -1;
    animation: goldGlow 2s ease-in-out infinite alternate;
}

@keyframes goldGlow {
    0% { opacity: 0.5; }
    100% { opacity: 0.8; }
}

@keyframes haloPulse {
    0%, 100% {
        opacity: 0.45;
        transform: scale(0.98);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.02);
    }
}





.leaderboard {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: 20px;
    border-radius: 15px;
    margin-top: 20px;
}

.leaderboard-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 15px;
    text-align: center;
}

.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.help-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(5px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.help-content {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: 30px;
    border-radius: 20px;
    max-width: 600px;
    width: 90%;
    color: white;
}

.shortcut-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.shortcut-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.key {
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 10px;
    border-radius: 5px;
    font-family: monospace;
}

.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 15px;
    padding: 24px;
    background: linear-gradient(145deg, #DEB887 0%, #D2B48C 100%);
    border-radius: 12px;
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        inset 0 -1px 0 rgba(0, 0, 0, 0.2),
        0 8px 20px rgba(0, 0, 0, 0.25);
    border: 2px solid #8B7355;
    position: relative;
}

.performance-section {
    margin: 25px 0;
    padding: 20px;
    background: linear-gradient(135deg, rgba(139, 69, 19, 0.1), rgba(160, 82, 45, 0.1));
    border-radius: 12px;
    border: 1px solid rgba(139, 69, 19, 0.2);
}

.performance-section h4 {
    color: #8B4513;
    font-family: 'Playfair Display', serif;
    font-size: 18px;
    margin-bottom: 15px;
    text-align: center;
}

.performance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 15px;
}

.performance-card {
    background: linear-gradient(135deg, #F5DEB3, #DEB887);
    border: 2px solid #CD853F;
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    box-shadow: 0 4px 8px rgba(139, 69, 19, 0.2);
    transition: transform 0.2s ease;
}

.performance-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(139, 69, 19, 0.3);
}

.performance-title {
    font-family: 'Playfair Display', serif;
    font-weight: 600;
    color: #8B4513;
    font-size: 14px;
    margin-bottom: 8px;
}

.performance-value {
    font-family: 'Crimson Text', serif;
    font-size: 24px;
    font-weight: bold;
    color: #654321;
    margin-bottom: 5px;
}

.performance-desc {
    font-size: 12px;
    color: #8B4513;
    opacity: 0.8;
}

.stats-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
}

.stat-box {
    background: linear-gradient(145deg, #F5DEB3 0%, #DEB887 100%);
    padding: 16px 12px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.5),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1),
        0 2px 4px rgba(0, 0, 0, 0.1);
    border: 1px solid #CD853F;
    transition: all 0.2s ease;
}

.stat-box:hover {
    transform: translateY(-1px);
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.6),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1),
        0 4px 8px rgba(0, 0, 0, 0.15);
}

.stat-value {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
    color: #5D4E37;
}

.stat-label {
    font-size: 12px;
    color: #8B7355;
    font-weight: 600;
}

/* Professional wooden theme styles */


.achievements {
    background: var(--container-bg);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 20px;
    box-shadow: var(--container-shadow);
}

.achievements-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 15px;
    text-align: center;
    color: var(--text-color);
}

.achievement-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    margin-bottom: 10px;
    transition: all 0.3s ease;
}

.achievement-item.unlocked {
    background: var(--accent-color);
    color: #fff;
}

.achievement-icon {
    font-size: 24px;
    opacity: 0.5;
}

.achievement-item.unlocked .achievement-icon {
    opacity: 1;
}



.final-stats {
    display: flex;
    gap: 30px;
    margin: 20px 0;
    justify-content: center;
}

.final-stats .stat-box {
    min-width: 120px;
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 12px;
}

/* Achievement Notifications */
.achievement-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: linear-gradient(135deg, #8B4513, #A0522D);
    border: 2px solid #CD853F;
    border-radius: 15px;
    padding: 20px;
    max-width: 350px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3), 
                inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transform: translateX(400px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 10000;
    border-image: linear-gradient(45deg, #CD853F, #DEB887) 1;
}

.achievement-notification.show {
    transform: translateX(0);
    opacity: 1;
}

.achievement-notification-content {
    display: flex;
    align-items: center;
    gap: 15px;
}

.achievement-notification-icon {
    font-size: 32px;
    color: #FFD700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    animation: trophy-bounce 0.6s ease-out;
}

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

.achievement-notification-text {
    color: #FFF8DC;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

.achievement-notification-title {
    font-size: 16px;
    font-weight: bold;
    font-family: 'Playfair Display', serif;
    margin-bottom: 4px;
}

.achievement-notification-subtitle {
    font-size: 14px;
    font-weight: 600;
    color: #FFD700;
    margin-bottom: 2px;
}

.achievement-notification-description {
    font-size: 12px;
    opacity: 0.9;
}

/* PWA Install Prompt */
.pwa-install-prompt {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10001;
    animation: fadeIn 0.3s ease;
}

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

.pwa-prompt-content {
    background: linear-gradient(135deg, #8B4513, #A0522D);
    border: 2px solid #CD853F;
    border-radius: 20px;
    padding: 30px;
    max-width: 400px;
    margin: 20px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

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

.pwa-prompt-content h3 {
    color: #FFF8DC;
    font-family: 'Playfair Display', serif;
    font-size: 24px;
    margin-bottom: 15px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.pwa-prompt-content p {
    color: #FFF8DC;
    font-family: 'Crimson Text', serif;
    font-size: 16px;
    margin-bottom: 25px;
    opacity: 0.9;
}

.pwa-prompt-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.pwa-install-btn, .pwa-dismiss-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    font-family: 'Crimson Text', serif;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.pwa-install-btn {
    background: linear-gradient(135deg, #228B22, #32CD32);
    color: white;
    border: 2px solid #90EE90;
}

.pwa-install-btn:hover {
    background: linear-gradient(135deg, #32CD32, #7CFC00);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(34, 139, 34, 0.4);
}

.pwa-dismiss-btn {
    background: linear-gradient(135deg, #F5DEB3, #DEB887);
    color: #654321;
    border: 2px solid #CD853F;
}

.pwa-dismiss-btn:hover {
    background: linear-gradient(135deg, #DEB887, #CD853F);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(139, 69, 19, 0.3);
}

/* Footer Styles */
.game-footer {
    margin-top: 30px;
    background: rgba(139, 69, 19, 0.95);
    border-top: 3px solid #8B4513;
    padding: 25px 0;
    text-align: center;
    backdrop-filter: blur(10px);
    border-radius: 15px 15px 0 0;
}

.footer-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 20px;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.footer-link {
    color: #F5DEB3;
    text-decoration: none;
    font-size: 16px;
    font-weight: 600;
    padding: 12px 20px;
    border-radius: 12px;
    transition: all 0.3s ease;
    background: rgba(245, 222, 179, 0.15);
    border: 2px solid rgba(245, 222, 179, 0.3);
    display: flex;
    align-items: center;
    gap: 8px;
}

.footer-link:hover {
    background: rgba(245, 222, 179, 0.25);
    color: #FFFFFF;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
    border-color: rgba(245, 222, 179, 0.5);
}

.footer-link i {
    font-size: 14px;
}

.footer-copyright {
    color: #DEB887;
    font-size: 13px;
    opacity: 0.9;
    margin: 0;
}

/* Legal Pages Styles */
.legal-page {
    max-width: 800px;
    margin: 0 auto;
    background: rgba(245, 222, 179, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    border: 3px solid #8B4513;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    margin-bottom: 80px; /* Space for footer */
}

.legal-header {
    background: linear-gradient(135deg, #8B4513, #A0522D);
    color: #F5DEB3;
    padding: 30px;
    text-align: center;
    position: relative;
}

.back-link {
    position: absolute;
    left: 30px;
    top: 30px;
    color: #F5DEB3;
    text-decoration: none;
    padding: 10px 15px;
    background: rgba(245, 222, 179, 0.2);
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.3s ease;
}

.back-link:hover {
    background: rgba(245, 222, 179, 0.3);
    transform: translateY(-2px);
}

.legal-header h1 {
    font-family: 'Playfair Display', serif;
    font-size: 2.5em;
    font-weight: 600;
    margin: 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.last-updated {
    margin-top: 10px;
    opacity: 0.8;
    font-style: italic;
}

.legal-content {
    padding: 40px;
    line-height: 1.8;
}

.legal-section {
    margin-bottom: 40px;
}

.legal-section h2 {
    color: #8B4513;
    font-family: 'Playfair Display', serif;
    font-size: 1.8em;
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #DEB887;
}

.legal-section h3 {
    color: #A0522D;
    font-size: 1.3em;
    font-weight: 600;
    margin: 25px 0 15px 0;
}

.legal-section ul, .legal-section ol {
    margin: 15px 0 15px 30px;
}

.legal-section li {
    margin-bottom: 8px;
}

.legal-section p {
    margin-bottom: 15px;
    text-align: justify;
}

/* Feature Grid for About Page */
.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
    margin: 30px 0;
}

.feature-item {
    background: rgba(139, 69, 19, 0.1);
    padding: 25px;
    border-radius: 15px;
    border: 2px solid rgba(139, 69, 19, 0.2);
    transition: all 0.3s ease;
}

.feature-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 16px rgba(139, 69, 19, 0.2);
    border-color: #8B4513;
}

.feature-item i {
    font-size: 2em;
    color: #8B4513;
    margin-bottom: 15px;
    display: block;
}

.feature-item h3 {
    color: #8B4513;
    margin-bottom: 10px;
}

/* Gameplay Information Styles */
.gameplay-info {
    display: grid;
    gap: 30px;
    margin: 30px 0;
}

.gameplay-objective, .gameplay-controls, .gameplay-tips {
    background: rgba(139, 69, 19, 0.05);
    padding: 25px;
    border-radius: 15px;
    border-left: 5px solid #8B4513;
}

.controls-list {
    display: grid;
    gap: 10px;
    margin: 15px 0;
}

.control-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: rgba(245, 222, 179, 0.3);
    border-radius: 8px;
}

.control-key {
    font-weight: bold;
    color: #8B4513;
    background: rgba(139, 69, 19, 0.1);
    padding: 5px 10px;
    border-radius: 5px;
    font-family: 'Courier New', monospace;
}

/* Technical Specifications */
.tech-specs {
    background: rgba(139, 69, 19, 0.05);
    padding: 25px;
    border-radius: 15px;
    margin: 20px 0;
}

.tech-specs h3 {
    color: #8B4513;
    margin-top: 25px;
    margin-bottom: 15px;
}

.tech-specs h3:first-child {
    margin-top: 0;
}

/* Installation Steps */
.installation-steps {
    margin: 20px 0;
}

.installation-steps h3 {
    color: #8B4513;
    margin: 25px 0 15px 0;
}

.installation-steps ol {
    background: rgba(139, 69, 19, 0.05);
    padding: 20px 20px 20px 50px;
    border-radius: 10px;
    margin: 15px 0;
}

/* Contact and Version Info */
.contact-info, .version-info {
    background: rgba(139, 69, 19, 0.05);
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
}

/* Legal Footer */
.legal-footer {
    background: linear-gradient(135deg, #8B4513, #A0522D);
    color: #F5DEB3;
    padding: 30px;
    text-align: center;
}

.legal-footer .footer-links {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.legal-footer .footer-links a {
    color: #F5DEB3;
    text-decoration: none;
    padding: 10px 20px;
    background: rgba(245, 222, 179, 0.1);
    border-radius: 8px;
    transition: all 0.3s ease;
    font-weight: 500;
}

.legal-footer .footer-links a:hover {
    background: rgba(245, 222, 179, 0.2);
    transform: translateY(-2px);
}

.legal-footer .copyright {
    margin: 0;
    opacity: 0.8;
    font-size: 14px;
}

/* Responsive Design for Footer and Legal Pages */
@media (max-width: 768px) {
    .footer-links {
        gap: 15px;
        flex-direction: column;
        align-items: center;
    }
    
    .footer-link {
        padding: 10px 15px;
        font-size: 14px;
        width: 150px;
        justify-content: center;
    }
    
    .legal-page {
        margin: 20px;
        margin-bottom: 40px;
    }
    
    .legal-header {
        padding: 20px;
    }
    
    .back-link {
        position: static;
        display: inline-block;
        margin-bottom: 20px;
    }
    
    .legal-header h1 {
        font-size: 2em;
    }
    
    .legal-content {
        padding: 20px;
    }
    
    .feature-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .footer-content {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .footer-links {
        gap: 20px;
    }
    
    .legal-footer .footer-links {
        gap: 15px;
    }
    
    .legal-footer .footer-links a {
        padding: 8px 15px;
        font-size: 14px;
    }
    
    .control-item {
        flex-direction: column;
        gap: 5px;
        text-align: center;
    }
} 
