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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    min-height: 100vh;
    color: #fff;
}

.screen { min-height: 100vh; display: flex; flex-direction: column; }
.screen.hidden { display: none !important; }

/* Settings */
.settings-container {
    max-width: 540px; margin: auto; padding: 40px;
    background: rgba(0,0,0,0.3); border-radius: 20px; text-align: center;
}
.settings-container h1 { font-size: 3.5rem; margin-bottom: 10px; text-shadow: 2px 2px 4px rgba(0,0,0,0.5); }
.settings-container h2 { font-size: 2rem; margin-bottom: 35px; font-weight: normal; opacity: 0.9; }
.setting-group { margin-bottom: 28px; }
.setting-group label { display: block; font-size: 1.4rem; margin-bottom: 12px; }
.button-group { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.setting-btn {
    padding: 14px 22px; font-size: 1.15rem;
    border: 3px solid #fff; background: transparent; color: #fff;
    border-radius: 12px; cursor: pointer; transition: all 0.2s;
    min-width: 160px; min-height: 60px;
}
.setting-btn:hover { background: rgba(255,255,255,0.2); transform: scale(1.05); }
.setting-btn:focus { outline: 4px solid #f39c12; outline-offset: 2px; }
.setting-btn.active { background: #fff; color: #2c3e50; font-weight: bold; }
.primary-btn {
    margin-top: 20px; padding: 20px 50px; font-size: 1.8rem;
    background: #e74c3c; color: #fff; border: none; border-radius: 15px;
    cursor: pointer; font-weight: bold; transition: all 0.2s;
    min-height: 70px; display: flex; width: 100%; align-items: center; justify-content: center;
    text-decoration: none;
}
.primary-btn:hover { background: #c0392b; transform: scale(1.03); }
.primary-btn:focus { outline: 4px solid #f39c12; outline-offset: 3px; }
.secondary-btn { margin-top: 15px; background: rgba(255,255,255,0.2); border: 3px solid #fff; }
.secondary-btn:hover { background: rgba(255,255,255,0.35); transform: scale(1.03); }
.back-btn { text-decoration: none; }

.rules-summary {
    background: rgba(255,255,255,0.1); border-radius: 12px;
    padding: 18px 22px; margin: 20px 0; text-align: left;
}
.rules-summary h3 { font-size: 1.3rem; margin-bottom: 10px; }
.rules-summary ul { list-style: none; }
.rules-summary li { font-size: 1.05rem; padding: 5px 0; opacity: 0.9; }
.rules-summary li::before { content: '• '; color: #f39c12; font-weight: bold; }

/* Header */
.game-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 25px; background: rgba(0,0,0,0.3);
    flex-wrap: wrap; gap: 10px; min-height: 80px;
}
.game-header h1 { font-size: 1.8rem; }
.header-center { display: flex; gap: 16px; align-items: center; }
.header-right { display: flex; gap: 12px; flex-wrap: wrap; }
.score-box {
    display: flex; flex-direction: column; align-items: center;
    background: rgba(255,255,255,0.15); padding: 10px 20px;
    border-radius: 12px; min-width: 90px;
}
.score-label { font-size: 0.9rem; opacity: 0.8; text-transform: uppercase; letter-spacing: 1px; }
.score-value { font-size: 1.8rem; font-weight: bold; font-variant-numeric: tabular-nums; }
.action-btn {
    padding: 14px 22px; font-size: 1.1rem;
    background: rgba(255,255,255,0.9); color: #2c3e50;
    border: none; border-radius: 10px; cursor: pointer;
    font-weight: bold; transition: all 0.2s; min-height: 52px;
    text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
.action-btn:hover { background: #fff; transform: scale(1.05); }
.action-btn:focus { outline: 4px solid #f39c12; outline-offset: 2px; }

/* Game Area */
.game-area {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 20px; gap: 16px;
}

.game-message {
    font-size: 1.6rem; font-weight: bold; text-align: center;
    padding: 14px 28px; border-radius: 12px;
    background: rgba(0,0,0,0.5); border: 3px solid #f39c12;
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: center;
}
.game-message.hidden { display: none !important; }
.game-message.win { color: #f1c40f; border-color: #f1c40f; }
.game-message.lose { color: #e74c3c; border-color: #e74c3c; }
.continue-btn {
    padding: 10px 20px; font-size: 1.1rem; font-weight: bold;
    background: #27ae60; color: #fff; border: none; border-radius: 10px;
    cursor: pointer; min-height: 44px; transition: all 0.2s;
}
.continue-btn:hover { background: #1e8449; transform: scale(1.05); }

/* Grid */
.grid-container {
    position: relative;
    background: #bbada0;
    border-radius: 10px;
    padding: 10px;
}
.grid-background {
    display: grid;
    gap: 10px;
}
.grid-cell-bg {
    background: rgba(238,228,218,0.35);
    border-radius: 6px;
}
.tile-container {
    position: absolute;
    top: 10px; left: 10px;
    right: 10px; bottom: 10px;
}

/* Tiles */
.tile {
    position: absolute;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
    font-weight: bold;
    transition: top 0.1s ease, left 0.1s ease;
}
.tile-new { animation: tile-appear 0.15s ease; }
.tile-merged { animation: tile-pop 0.2s ease; z-index: 20; }

@keyframes tile-appear {
    from { transform: scale(0); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}
@keyframes tile-pop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* Tile colors */
.tile-2    { background: #eee4da; color: #776e65; }
.tile-4    { background: #ede0c8; color: #776e65; }
.tile-8    { background: #f2b179; color: #f9f6f2; }
.tile-16   { background: #f59563; color: #f9f6f2; }
.tile-32   { background: #f67c5f; color: #f9f6f2; }
.tile-64   { background: #f65e3b; color: #f9f6f2; }
.tile-128  { background: #edcf72; color: #f9f6f2; }
.tile-256  { background: #edcc61; color: #f9f6f2; }
.tile-512  { background: #edc850; color: #f9f6f2; }
.tile-1024 { background: #edc53f; color: #f9f6f2; }
.tile-2048 { background: #edc22e; color: #f9f6f2; }
.tile-super { background: #3c3a32; color: #f9f6f2; }

/* D-pad */
.dpad {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 60px);
    gap: 6px;
}
.dpad-btn {
    font-size: 1.6rem;
    background: rgba(255,255,255,0.18);
    border: 2px solid rgba(255,255,255,0.35);
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    transition: all 0.12s;
    display: flex; align-items: center; justify-content: center;
}
.dpad-btn:hover  { background: rgba(255,255,255,0.35); transform: scale(1.1); }
.dpad-btn:active { background: rgba(255,255,255,0.5);  transform: scale(0.95); }
.dpad-btn:focus  { outline: 3px solid #f39c12; outline-offset: 2px; }
.dpad-up    { grid-column: 2; grid-row: 1; }
.dpad-left  { grid-column: 1; grid-row: 2; }
.dpad-down  { grid-column: 2; grid-row: 3; }
.dpad-right { grid-column: 3; grid-row: 2; }

.controls-hint {
    font-size: 1.1rem; opacity: 0.7; text-align: center;
}

@media (max-width: 768px) {
    .game-header { justify-content: center; }
    .header-left { display: none; }
    .header-center, .header-right { width: 100%; justify-content: center; }
    .controls-hint { font-size: 0.9rem; }
}
