/* Doodle Merge - Complete CSS Styling */
:root {
    --paper: #f5f5f0;
    --grid-line: #d0e8f0;
    --ink: #2a2a2a;
    --accent: #4a90e2;
    --tile-bg: #ffffff;
    --post-it: #fff9c4;
}

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

body {
    font-family: 'Kalam', cursive, sans-serif;
    background: var(--paper);
    background-image: 
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 20px 20px;
    color: var(--ink);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.game-container {
    width: 100%;
    max-width: 500px;
    text-align: center;
}

/* Header & HUD */
.game-header {
    margin-bottom: 15px;
}

.back-button {
    margin-bottom: 10px;
    text-align: left;
    position: relative;
    z-index: 10;
}

.back-link {
    display: inline-block;
    padding: 8px 15px;
    background: var(--post-it);
    border: 2px solid #8b8b8b;
    border-radius: 8px;
    text-decoration: none;
    font-family: 'Gloria Hallelujah', cursive;
    font-size: 0.9rem;
    color: var(--ink);
    transform: rotate(-1deg);
    transition: transform 0.2s;
    box-shadow: 2px 2px 0px rgba(0,0,0,0.1);
}

.back-link:hover {
    transform: rotate(0deg) scale(1.05);
}

.game-title h1 {
    font-family: 'Gloria Hallelujah', cursive;
    font-size: 2.5rem;
    color: var(--ink);
    text-shadow: 2px 2px 0px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.score-container {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 15px;
}

.score-display, .high-score-display {
    background: var(--post-it);
    border: 2px solid #8b8b8b;
    border-radius: 12px;
    padding: 10px 15px;
    text-align: center;
    transform: rotate(1deg);
    box-shadow: 3px 3px 0px rgba(0,0,0,0.1);
}

.high-score-display {
    transform: rotate(-1deg);
}

.score-label, .high-score-label {
    font-size: 0.8rem;
    font-weight: bold;
    margin-bottom: 5px;
}

.score-value, .high-score-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--accent);
}

/* Rank Display */
.rank-display {
    background: var(--post-it);
    border: 2px solid #8b8b8b;
    border-radius: 10px;
    padding: 8px 20px;
    margin-bottom: 20px;
    transform: rotate(-0.5deg);
    font-size: 1.1rem;
    font-weight: bold;
    display: inline-block;
}

.rank-value {
    color: var(--accent);
}

/* Main Game Board */
.game-board-container {
    position: relative;
    width: 100%;
    max-width: 400px;
    aspect-ratio: 1;
    margin: 0 auto 20px auto;
}

.game-board {
    position: relative;
    width: 100%;
    height: 100%;
    background: rgba(240, 240, 240, 0.9);
    background-image: 
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 25px 25px;
    border: 3px solid #8b8b8b;
    border-radius: 15px;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 8px;
    touch-action: none;
}

/* Grid Cells */
.grid-cell {
    background: rgba(220, 220, 220, 0.3);
    border: 1px solid var(--grid-line);
    border-radius: 8px;
    position: relative;
}

/* Tiles */
.tile {
    position: absolute;
    width: calc(25% - 6px);
    height: calc(25% - 6px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    color: var(--ink);
    transition: all 0.15s ease-in-out;
    z-index: 2;
    border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
    box-shadow: 3px 3px 6px rgba(0,0,0,0.1), -3px -3px 6px rgba(255,255,255,0.1);
}

/* Tile Colors */
.tile-2 { 
    background: #eee4da; 
    color: #776e65;
    border: 2px solid #d4c4b8;
}
.tile-4 { 
    background: #ede0c8; 
    color: #776e65;
    border: 2px solid #d4c4b8;
}
.tile-8 { 
    background: #f2b179; 
    color: #f9f6f2;
    border: 2px solid #e0a060;
}
.tile-16 { 
    background: #f59563; 
    color: #f9f6f2;
    border: 2px solid #e08050;
}
.tile-32 { 
    background: #f67c5f; 
    color: #f9f6f2;
    border: 2px solid #e06040;
}
.tile-64 { 
    background: #f65e3b; 
    color: #f9f6f2;
    border: 2px solid #e04020;
}
.tile-128 { 
    background: #edcf72; 
    color: #f9f6f2;
    font-size: 1.8rem;
    border: 2px solid #d0b050;
}
.tile-256 { 
    background: #edcc61; 
    color: #f9f6f2;
    font-size: 1.8rem;
    border: 2px solid #d0a040;
}
.tile-512 { 
    background: #edc850; 
    color: #f9f6f2;
    font-size: 1.8rem;
    border: 2px solid #d09030;
}
.tile-1024 { 
    background: #edc53f; 
    color: #f9f6f2;
    font-size: 1.5rem;
    border: 2px solid #d08020;
    box-shadow: 0 0 20px rgba(237, 197, 63, 0.5);
}
.tile-2048 { 
    background: #edc22e; 
    color: #f9f6f2;
    font-size: 1.5rem;
    border: 2px solid #d07010;
    box-shadow: 0 0 30px rgba(237, 194, 46, 0.7);
}
.tile-4096 { 
    background: #000000; 
    color: #ffffff;
    font-size: 1.3rem;
    border: 2px solid #ffffff;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

@keyframes pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
    100% {
        transform: scale(1);
    }
}

.tile-new {
    animation: slideIn 0.2s ease-in-out;
}

.tile-merged {
    animation: merge 0.2s ease-in-out;
}

.tile-pop {
    animation: pop 0.3s ease-in-out;
}

/* Controls */
.game-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
}

.btn-doodle {
    background: var(--post-it);
    border: 2px solid #8b8b8b;
    border-radius: 10px;
    padding: 12px 20px;
    font-family: 'Gloria Hallelujah', cursive;
    font-size: 1rem;
    font-weight: bold;
    color: var(--ink);
    cursor: pointer;
    transform: rotate(-1deg);
    transition: all 0.2s;
    box-shadow: 2px 2px 0px rgba(0,0,0,0.1);
}

.btn-doodle:hover {
    transform: rotate(0deg) scale(1.05);
    box-shadow: 3px 3px 0px rgba(0,0,0,0.15);
}

.btn-doodle:active {
    transform: rotate(0.5deg) scale(0.98);
}

/* Footer */
.signature {
    font-family: 'Gloria Hallelujah', cursive;
    font-size: 0.9rem;
    color: var(--ink);
    opacity: 0.7;
    margin-top: 10px;
}

/* Game Over Overlay */
.game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.game-over-content {
    background: var(--paper);
    border: 3px solid #8b8b8b;
    border-radius: 20px;
    padding: 30px;
    text-align: center;
    max-width: 350px;
    transform: rotate(-1deg);
}

.game-over-title {
    font-family: 'Gloria Hallelujah', cursive;
    font-size: 2rem;
    color: var(--ink);
    margin-bottom: 20px;
}

.final-score, .final-rank {
    font-size: 1.2rem;
    margin-bottom: 15px;
}

.final-score span:last-child,
.final-rank span:last-child {
    color: var(--accent);
    font-weight: bold;
    margin-left: 8px;
}

/* Mobile Optimization */
@media (max-width: 480px) {
    body {
        padding: 5px;
    }
    
    .game-container {
        max-width: 100%;
        padding: 5px;
    }
    
    .game-header {
        margin-bottom: 10px;
    }
    
    .back-button {
        margin-bottom: 8px;
        position: relative;
        z-index: 10;
    }
    
    .game-title h1 {
        font-size: 1.8rem;
        margin-bottom: 8px;
    }
    
    .score-container {
        flex-direction: row;
        gap: 6px;
        margin-bottom: 6px;
    }
    
    .score-display, .high-score-display {
        padding: 5px 8px;
        font-size: 0.8rem;
        transform: none;
    }
    
    .score-label, .high-score-label {
        font-size: 0.7rem;
    }
    
    .score-value, .high-score-value {
        font-size: 1.2rem;
    }
    
    .rank-display {
        font-size: 0.9rem;
        padding: 5px 12px;
        margin-bottom: 8px;
    }
    
    .game-board-container {
        max-width: 95vw;
        max-height: 70vh;
        margin: 0 auto 10px auto;
    }
    
    .game-board {
        gap: 4px;
        padding: 4px;
        touch-action: none;
    }
    
    .tile {
        font-size: 1.3rem;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 1.1rem;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 0.9rem;
    }
    
    .tile-4096 {
        font-size: 0.8rem;
    }
    
    .game-controls {
        flex-direction: row;
        gap: 10px;
        margin-bottom: 8px;
    }
    
    .btn-doodle {
        min-height: 44px;
        padding: 10px 15px;
        font-size: 0.9rem;
    }
    
    .signature {
        font-size: 0.7rem;
        margin-top: 3px;
        font-family: 'Kalam', cursive, sans-serif;
        font-weight: 700;
    }
}
