:root {
    --fund-color: #faf8ef;
    --bg-color: var(--fund-color);
    --text-color: #776e65;
    --text-light: #f9f6f2;
    --grid-bg: #bbada0;
    --cell-bg: rgba(238, 228, 218, 0.35);
    
    --brand-dark: #3a2e28;
    --brand-accent: #8b2b2b;
    --btn-bg: #8f7a66;
    --btn-hover: #9f8b77;

    /* Tile colors for different chair tiers */
    --t-2: #eee4da;
    --t-4: #ede0c8;
    --t-8: #f2b179;
    --t-16: #f59563;
    --t-32: #f67c5f;
    --t-64: #f65e3b;
    --t-128: #edcf72;
    --t-256: #edcc61;
    --t-512: #edc850;
    --t-1024: #edc53f;
    --t-2048: #edc22e; /* The Throne */
    
    --transition-speed: 150ms;
}

body.dark-mode {
    --bg-color: #1a1a2e; /* Argon Blue Dark */
    --text-color: #e6e6ea;
    --brand-dark: #f0f0f0;
    --grid-bg: #3a3a5a;
    --cell-bg: rgba(255, 255, 255, 0.1);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
}

.game-container {
    width: 500px;
    max-width: 100%;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.settings-bar {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 15px;
}

.icon-btn {
    background: var(--grid-bg);
    color: white;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.icon-btn:hover {
    transform: translateY(-2px) scale(1.05);
    background: var(--btn-hover);
}

.header-left h1 {
    font-size: 42px;
    font-weight: 900;
    color: var(--brand-dark);
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: -1px;
}

.subtitle {
    font-size: 18px;
    color: var(--brand-accent);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.scores-container {
    display: flex;
    gap: 10px;
}

.score-box {
    background: var(--grid-bg);
    padding: 10px 20px;
    border-radius: 6px;
    text-align: center;
    position: relative;
    min-width: 80px;
}

.score-label {
    color: #eee4da;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
}

.score-value {
    color: white;
    font-size: 20px;
    font-weight: 700;
}

.score-addition {
    position: absolute;
    right: 30px;
    color: rgba(119, 110, 101, 0.9);
    font-size: 20px;
    font-weight: bold;
    z-index: 100;
    animation: move-up 600ms ease-in;
    animation-fill-mode: both;
    pointer-events: none;
}

@keyframes move-up {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-50px); }
}

.game-intro {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    font-size: 16px;
    line-height: 1.5;
}

button {
    cursor: pointer;
    border: none;
    font-family: inherit;
    font-weight: 700;
    transition: all 0.2s ease;
}

.primary-btn {
    background: var(--brand-accent);
    color: white;
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 16px;
    box-shadow: 0 4px 0 #681f1f;
}

.primary-btn:hover {
    background: #9c3030;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #681f1f;
}

.primary-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #681f1f;
}

.secondary-btn {
    background: var(--btn-bg);
    color: white;
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 16px;
}

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

.grid-container {
    background: var(--grid-bg);
    border-radius: 8px;
    padding: 15px;
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

.grid-cell {
    background: var(--cell-bg);
    border-radius: 6px;
}

#tile-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 15px;
    pointer-events: none;
}

.tile {
    position: absolute;
    width: calc(25% - 15px);
    height: calc(25% - 15px);
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    font-size: 24px;
    transition: transform var(--transition-speed) ease-in-out;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    
    /* Using background size for chair sprites later */
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    
    /* Fallback text color */
    color: var(--text-light);
}

/* Base class for newly added tiles */
.tile-new {
    animation: appear 200ms ease-in-out;
    animation-fill-mode: backwards;
}

/* Base class for merged tiles */
.tile-merged {
    animation: pop 200ms ease-in-out;
    animation-fill-mode: backwards;
}

/* Interactive hover effect */
.tile {
    cursor: grab;
}

.tile > div {
    transition: transform 0.2s ease, text-shadow 0.2s ease;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.tile:hover > div {
    transform: scale(1.1);
    text-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

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

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

/* Positioning classes - generated dynamically but good to have a few here */
.tile-position-1-1 { transform: translate(0, 0); }

/* Value colors based on 2048 scale */
.tile-2 { background-color: var(--t-2); color: var(--text-color); font-size: 14px; text-align: center; line-height: 1.2; padding: 5px; }
.tile-4 { background-color: var(--t-4); color: var(--text-color); font-size: 14px; text-align: center; line-height: 1.2; padding: 5px; }
.tile-8 { background-color: var(--t-8); color: var(--text-light); }
.tile-16 { background-color: var(--t-16); color: var(--text-light); }
.tile-32 { background-color: var(--t-32); color: var(--text-light); }
.tile-64 { background-color: var(--t-64); color: var(--text-light); }
.tile-128 { background-color: var(--t-128); color: var(--text-light); box-shadow: 0 0 10px rgba(243, 215, 116, 0.4); font-size: 18px;}
.tile-256 { background-color: var(--t-256); color: var(--text-light); box-shadow: 0 0 15px rgba(243, 215, 116, 0.5); font-size: 18px;}
.tile-512 { background-color: var(--t-512); color: var(--text-light); box-shadow: 0 0 20px rgba(243, 215, 116, 0.6); font-size: 18px;}
.tile-1024 { background-color: var(--t-1024); color: var(--text-light); box-shadow: 0 0 25px rgba(243, 215, 116, 0.7); font-size: 16px;}
.tile-2048 { background-color: var(--t-2048); color: var(--text-light); box-shadow: 0 0 30px rgba(243, 215, 116, 0.8); font-size: 16px;}

.pixel-sprite {
    width: 60%;
    height: 60%;
    background-image: url('pixel_chairs_full.jpg');
    background-size: 600% 200%; /* 6 columns, 2 rows approx */
    background-repeat: no-repeat;
    image-rendering: pixelated;
    margin-bottom: 5px;
}

/* Mapping sprite positions roughly for the new 11-chair sheet */
.sprite-2 { background-position: 0% 0%; }
.sprite-8 { background-position: 40% 0%; }
.sprite-64 { background-position: 80% 0%; }
.sprite-2048 { background-position: 100% 100%; }

.game-message {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(238, 228, 218, 0.73);
    z-index: 100;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border-radius: 8px;
    animation: fade-in 800ms ease;
}

@keyframes fade-in {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

.game-message h2 {
    font-size: 50px;
    font-weight: 900;
    margin-bottom: 10px;
    color: var(--text-color);
}

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

.message-actions {
    display: flex;
    gap: 10px;
}

.controls-hint {
    margin-top: 20px;
    text-align: center;
    color: var(--text-color);
    font-size: 14px;
    opacity: 0.8;
}

.virtual-dpad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 15px;
    margin-bottom: 20px;
}

.dpad-row {
    display: flex;
    gap: 8px;
}

.dpad-btn {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    background: var(--grid-bg);
    color: white;
    font-size: 28px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.1s ease, background 0.1s ease;
}

.dpad-btn:active {
    transform: scale(0.92);
    background: var(--brand-accent);
}

.legend {
    margin-top: 30px;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.legend h3 {
    margin-bottom: 15px;
    color: var(--brand-dark);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 16px;
    border-bottom: 2px solid var(--cell-bg);
    padding-bottom: 8px;
}

.legend-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.legend-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.legend-swatch {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    color: white;
    font-weight: bold;
}

.legend-name {
    font-size: 11px;
    text-align: center;
    color: var(--text-color);
}

@media (max-width: 520px) {
    .game-container {
        padding: 10px;
    }
    .header-left h1 {
        font-size: 32px;
    }
    .grid-container {
        padding: 10px;
        gap: 10px;
    }
    .tile {
        width: calc(25% - 10px);
        height: calc(25% - 10px);
    }
}
