/* ========================================
   CSS Variables - Dream Puff Theme
   ======================================== */
:root {
    /* Colors from Dream Puff */
    --primary-color: #D4A574;
    --secondary-color: #8B6F47;
    --accent-color: #F5E6D3;
    --bg-color: #FEFDFB;
    --text-dark: #2C2416;
    --text-light: #F5E6D3;

    /* Grid colors */
    --grid-bg: #8B6F47;
    --cell-empty: rgba(212, 165, 116, 0.35);

    /* Typography */
    --font-heading: 'Playfair Display', serif;
    --font-body: 'Inter', sans-serif;

    /* Tile colors */
    --tile-2: #FAF8F5;
    --tile-4: #F5E6D3;
    --tile-8: #E8D4B8;
    --tile-16: #D4A574;
    --tile-32: #C49565;
    --tile-64: #B08550;
    --tile-128: #9A7040;
    --tile-256: #8B6F47;
    --tile-512: #7A5F3A;
    --tile-1024: #6B5030;
    --tile-2048: #FFD700;
    --tile-super: #DAA520;
}

/* ========================================
   Base Styles
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background:
        linear-gradient(135deg, rgba(245, 230, 211, 0.35) 0%, rgba(254, 253, 251, 0.80) 100%),
        url('../puff_lg5pq0lg5pq0lg5p.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    background-repeat: no-repeat;
    color: var(--text-dark);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========================================
   Game Page Wrapper
   ======================================== */
.game-page-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    padding-top: 80px; /* Account for fixed navbar */
}

/* ========================================
   Game Container
   ======================================== */
.game-container {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(139, 111, 71, 0.15);
    padding: 30px;
    max-width: 500px;
    width: 100%;
}

/* ========================================
   Header
   ======================================== */
.game-header {
    text-align: center;
    margin-bottom: 20px;
}

.game-title {
    font-family: var(--font-heading);
    font-size: 3rem;
    color: var(--secondary-color);
    margin-bottom: 5px;
}

.game-subtitle {
    font-size: 0.9rem;
    color: var(--primary-color);
    font-weight: 500;
}

/* ========================================
   Score Container
   ======================================== */
.score-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
}

.score-box {
    background: var(--secondary-color);
    border-radius: 8px;
    padding: 10px 25px;
    text-align: center;
    min-width: 100px;
}

.score-label {
    display: block;
    font-size: 0.7rem;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.score-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--bg-color);
}

.score-value.pop {
    animation: scorePop 0.2s ease-out;
}

@keyframes scorePop {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

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

.btn-primary {
    background: var(--primary-color);
    color: var(--text-dark);
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: transparent;
    color: var(--secondary-color);
    border: 2px solid var(--secondary-color);
    padding: 10px 20px;
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background: var(--secondary-color);
    color: var(--bg-color);
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.85rem;
}

#sound-toggle-btn {
    padding: 10px 14px;
    font-size: 1.2rem;
}

/* Timer Display */
.timer-display {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--secondary-color);
    border-radius: 8px;
    color: var(--bg-color);
}

.timer-icon {
    font-size: 1rem;
}

.timer-value {
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    min-width: 45px;
    text-align: center;
}

/* ========================================
   Game Grid
   ======================================== */
.grid-container {
    position: relative;
    margin: 0 auto 20px;
}

.game-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 12px;
    background: var(--grid-bg);
    border-radius: 12px;
    padding: 12px;
    aspect-ratio: 1;
    max-width: 100%;
    touch-action: none; /* Prevent scrolling/zooming on mobile */
    -webkit-user-select: none; /* Prevent text selection on iOS */
    user-select: none;
}

.cell {
    background: var(--cell-empty);
    border-radius: 8px;
    aspect-ratio: 1;
}

/* ========================================
   Tiles
   ======================================== */
.tile {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-family: var(--font-body);
    font-weight: 700;
    user-select: none;
    transition: top 0.1s ease-out, left 0.1s ease-out;
}

.tile-2 {
    background: var(--tile-2);
    color: var(--secondary-color);
}

.tile-4 {
    background: var(--tile-4);
    color: var(--secondary-color);
}

.tile-8 {
    background: var(--tile-8);
    color: var(--bg-color);
}

.tile-16 {
    background: var(--tile-16);
    color: var(--bg-color);
}

.tile-32 {
    background: var(--tile-32);
    color: var(--bg-color);
}

.tile-64 {
    background: var(--tile-64);
    color: var(--bg-color);
}

.tile-128 {
    background: var(--tile-128);
    color: var(--bg-color);
}

.tile-256 {
    background: var(--tile-256);
    color: var(--bg-color);
}

.tile-512 {
    background: var(--tile-512);
    color: var(--bg-color);
}

.tile-1024 {
    background: var(--tile-1024);
    color: var(--bg-color);
}

.tile-2048 {
    background: var(--tile-2048);
    color: var(--text-dark);
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.6);
}

.tile-super {
    background: var(--tile-super);
    color: var(--text-dark);
    box-shadow: 0 0 30px rgba(218, 165, 32, 0.6);
}

/* Tile spawn animation */
.tile-new {
    animation: tileSpawn 0.15s ease-out;
}

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

/* Tile merge animation */
.tile-merged {
    animation: tileMerge 0.15s ease-out;
}

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

/* ========================================
   Game Overlay
   ======================================== */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(254, 253, 251, 0.9);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.game-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-content {
    text-align: center;
    padding: 20px;
}

.overlay-title {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.overlay-title.win {
    color: #DAA520;
}

.overlay-title.lose {
    color: #e74c3c;
}

.overlay-message {
    color: var(--secondary-color);
    margin-bottom: 20px;
    font-size: 1.1rem;
}

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

/* ========================================
   Instructions
   ======================================== */
.instructions {
    text-align: center;
    color: var(--secondary-color);
    font-size: 0.85rem;
    margin-bottom: 20px;
    padding: 0 10px;
}

/* ========================================
   Player Section
   ======================================== */
.player-section {
    text-align: center;
    margin-bottom: 20px;
}

.player-greeting {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

#greeting-text {
    color: var(--secondary-color);
    font-weight: 500;
}

.name-editor {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.name-editor.hidden {
    display: none;
}

.name-editor input {
    padding: 8px 12px;
    border: 2px solid var(--primary-color);
    border-radius: 6px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.name-editor input:focus {
    border-color: var(--secondary-color);
}

/* ========================================
   Game Back Link
   ======================================== */
.game-back-link {
    text-align: center;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 2px solid var(--accent-color);
}

.game-back-link .back-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s ease;
}

.game-back-link .back-link:hover {
    color: var(--secondary-color);
}

/* ========================================
   Responsive - Tablet
   ======================================== */
@media (max-width: 1023px) {
    .game-container {
        padding: 25px;
        max-width: 450px;
    }

    .game-title {
        font-size: 2.5rem;
    }

    .game-grid {
        gap: 10px;
        padding: 10px;
    }
}

/* ========================================
   Responsive - Mobile
   ======================================== */
@media (max-width: 767px) {
    body {
        padding: 10px;
    }

    .game-container {
        padding: 20px;
        max-width: 100%;
    }

    .game-title {
        font-size: 2rem;
    }

    .score-container {
        gap: 10px;
    }

    .score-box {
        padding: 8px 20px;
        min-width: 80px;
    }

    .score-value {
        font-size: 1.25rem;
    }

    .game-grid {
        gap: 8px;
        padding: 8px;
    }

    .controls {
        gap: 10px;
    }

    .btn-primary {
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    .overlay-title {
        font-size: 2rem;
    }

    .instructions {
        font-size: 0.8rem;
    }

    .player-greeting {
        flex-direction: column;
        gap: 10px;
    }
}

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