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

:root {
    --bg-color: #faf8ef;
    --text-color: #776e65;
    --grid-bg: #bbada0;
    --cell-bg: rgba(238, 228, 218, 0.35);
    --header-bg: #8f7a66;
    --btn-bg: #8f7a66;
    --btn-hover: #9f8b77;
}

body {
    font-family: 'Segoe UI', 'Arial', 'Helvetica Neue', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    touch-action: none;
    user-select: none;
}

header {
    width: 100%;
    max-width: 500px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

h1 {
    font-size: 64px;
    font-weight: 700;
    color: #776e65;
    text-align: center;
}

.header-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.scores {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.score-box {
    background: var(--header-bg);
    color: white;
    padding: 10px 25px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100px;
}

.score-box span:first-child {
    font-size: 13px;
    text-transform: uppercase;
    font-weight: 600;
    opacity: 0.8;
}

.score-box span:last-child {
    font-size: 24px;
    font-weight: 700;
    transition: transform 0.2s, color 0.3s;
}

/* Score bump animation */
@keyframes scoreBump {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.3);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes newRecord {
    0% {
        transform: scale(1);
        color: white;
    }

    25% {
        transform: scale(1.4);
        color: #fbbf24;
    }

    50% {
        transform: scale(1.2);
        color: #f59e0b;
    }

    75% {
        transform: scale(1.3);
        color: #fbbf24;
    }

    100% {
        transform: scale(1);
        color: white;
    }
}

.score-box.bump span:last-child {
    animation: scoreBump 0.25s ease-out;
}

.score-box.new-record span:last-child {
    animation: newRecord 0.6s ease-out;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

#language-select {
    padding: 10px 15px;
    font-size: 16px;
    border: none;
    border-radius: 6px;
    background: var(--btn-bg);
    color: white;
    cursor: pointer;
    outline: none;
}

#language-select option {
    background: white;
    color: var(--text-color);
}

#new-game-btn {
    padding: 10px 20px;
    font-size: 16px;
    font-weight: 700;
    border: none;
    border-radius: 6px;
    background: var(--btn-bg);
    color: white;
    cursor: pointer;
    transition: background 0.2s;
}

#new-game-btn:hover {
    background: var(--btn-hover);
}

main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 10px;
}

.game-container {
    position: relative;
    width: 500px;
    height: 500px;
    background: var(--grid-bg);
    border-radius: 6px;
    padding: 15px;
}

.grid-background {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 15px;
    width: 100%;
    height: 100%;
}

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

#tiles-container {
    position: absolute;
    top: 15px;
    left: 15px;
    right: 15px;
    bottom: 15px;
}

.tile {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 45px;
    font-weight: 700;
    border-radius: 3px;
    transition: top 0.15s ease-in-out, left 0.15s ease-in-out;
}

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

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

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

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

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

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

.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;
    font-size: 40px;
}

.tile-256 {
    background: #edcc61;
    color: #f9f6f2;
    font-size: 40px;
}

.tile-512 {
    background: #edc850;
    color: #f9f6f2;
    font-size: 40px;
}

.tile-1024 {
    background: #edc53f;
    color: #f9f6f2;
    font-size: 32px;
}

.tile-2048 {
    background: #edc22e;
    color: #f9f6f2;
    font-size: 32px;
}

.tile-super {
    background: #3c3a32;
    color: #f9f6f2;
    font-size: 28px;
}

.game-message {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(238, 228, 218, 0.73);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    border-radius: 6px;
    animation: fadeIn 0.3s ease-in-out;
}

.game-message.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

#message-text {
    font-size: 48px;
    font-weight: 700;
    color: #776e65;
    text-align: center;
}

#message-btn {
    padding: 15px 30px;
    font-size: 18px;
    font-weight: 700;
    border: none;
    border-radius: 6px;
    background: var(--btn-bg);
    color: white;
    cursor: pointer;
    transition: background 0.2s;
}

#message-btn:hover {
    background: var(--btn-hover);
}

@media (max-width: 520px) {
    header {
        padding: 15px;
    }

    h1 {
        font-size: 48px;
    }

    .game-container {
        width: calc(100vw - 20px);
        height: calc(100vw - 20px);
        max-width: 500px;
        max-height: 500px;
        padding: 10px;
    }

    .grid-background {
        gap: 10px;
    }

    #tiles-container {
        top: 10px;
        left: 10px;
        right: 10px;
        bottom: 10px;
    }

    .tile {
        font-size: 28px;
    }

    .tile-128,
    .tile-256,
    .tile-512 {
        font-size: 26px;
    }

    .tile-1024,
    .tile-2048 {
        font-size: 22px;
    }

    .tile-super {
        font-size: 18px;
    }

    #message-text {
        font-size: 32px;
    }

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

    .score-box span:last-child {
        font-size: 20px;
    }
}

/* Dev Panel Styles */
.dev-panel {
    width: 100%;
    max-width: 500px;
    margin: 20px auto;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    color: white;
    box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
}

.dev-panel.hidden {
    display: none;
}

.dev-panel h3 {
    margin-bottom: 15px;
    font-size: 18px;
}

.dev-control {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.dev-control label {
    font-weight: 600;
}

#win-target {
    padding: 8px 12px;
    font-size: 16px;
    font-weight: 700;
    border: none;
    border-radius: 6px;
    background: white;
    color: #667eea;
    cursor: pointer;
}

#apply-dev-settings {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 700;
    border: none;
    border-radius: 6px;
    background: #ffd700;
    color: #333;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

#apply-dev-settings:hover {
    background: #ffed4a;
    transform: scale(1.02);
}

.dev-btn-danger {
    width: 100%;
    padding: 10px;
    margin-top: 10px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    background: #e74c3c;
    color: white;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.dev-btn-danger:hover {
    background: #c0392b;
    transform: scale(1.02);
}

.dev-note {
    margin-top: 15px;
    font-size: 12px;
    opacity: 0.8;
}

/* Statistics Panel */
.stats-panel {
    width: 100%;
    max-width: 500px;
    margin: 20px auto;
}

.stats-toggle {
    width: 100%;
    padding: 12px 20px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #6aaa64 0%, #538d4e 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stats-toggle:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 15px rgba(106, 170, 100, 0.4);
}

.stats-content {
    margin-top: 10px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    animation: slideDown 0.3s ease;
}

.stats-content.hidden {
    display: none;
}

.stats-empty-message {
    text-align: center;
    padding: 15px;
    font-size: 14px;
    color: #666;
    background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%);
    border-radius: 8px;
    margin-bottom: 15px;
    animation: pulse 2s ease-in-out infinite;
}

.stats-empty-message.hidden {
    display: none;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

.stats-grid.dimmed {
    opacity: 0.4;
    filter: grayscale(30%);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

.stat-item {
    text-align: center;
    padding: 15px 10px;
    background: #f5f5f5;
    border-radius: 8px;
}

.stat-value {
    display: block;
    font-size: 24px;
    font-weight: 700;
    color: #776e65;
}

.stat-label {
    display: block;
    font-size: 11px;
    color: #999;
    text-transform: uppercase;
    margin-top: 5px;
}

@media (max-width: 520px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

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

/* Achievements Panel */
.achievements-panel {
    width: 100%;
    max-width: 500px;
    margin: 10px auto 20px;
}

.achievements-toggle {
    width: 100%;
    padding: 12px 20px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.achievements-toggle:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.4);
}

.achievements-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
}

.achievements-content {
    margin-top: 10px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    animation: slideDown 0.3s ease;
}

.achievements-content.hidden {
    display: none;
}

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

.achievement-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 5px;
    border-radius: 8px;
    background: #f5f5f5;
    transition: transform 0.2s, background 0.2s, box-shadow 0.3s, opacity 0.3s;
    position: relative;
}

.achievement-item.locked {
    opacity: 0.35;
    filter: grayscale(100%);
    background: #e5e5e5;
}

.achievement-item.locked .achievement-icon {
    filter: brightness(0.6);
}

.achievement-item.locked .achievement-name {
    color: #999;
}

.achievement-item.unlocked {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.5), 0 0 30px rgba(251, 191, 36, 0.2);
    animation: achievementGlow 2s ease-in-out infinite alternate;
}

@keyframes achievementGlow {
    from {
        box-shadow: 0 0 10px rgba(251, 191, 36, 0.4), 0 0 20px rgba(251, 191, 36, 0.15);
    }

    to {
        box-shadow: 0 0 20px rgba(251, 191, 36, 0.6), 0 0 40px rgba(251, 191, 36, 0.25);
    }
}

@keyframes achievementUnlock {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(251, 191, 36, 0);
    }

    50% {
        transform: scale(1.2);
        box-shadow: 0 0 30px rgba(251, 191, 36, 0.8);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 15px rgba(251, 191, 36, 0.5);
    }
}

.achievement-item.just-unlocked {
    animation: achievementUnlock 0.6s ease-out;
}

.achievement-item:hover {
    transform: scale(1.05);
}

.achievement-item.locked:hover {
    transform: scale(1.02);
    opacity: 0.5;
}

.achievement-icon {
    font-size: 24px;
    margin-bottom: 5px;
    transition: filter 0.3s, transform 0.3s;
}

.achievement-item.unlocked .achievement-icon {
    filter: drop-shadow(0 0 4px rgba(251, 191, 36, 0.6));
}

.achievement-name {
    font-size: 9px;
    text-align: center;
    color: #666;
    line-height: 1.2;
}

.achievement-item.unlocked .achievement-name {
    color: #92400e;
    font-weight: 600;
}

/* Achievement Toast */
.achievement-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: white;
    padding: 15px 25px;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(245, 158, 11, 0.4);
    display: flex;
    align-items: center;
    gap: 15px;
    z-index: 1000;
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.achievement-toast.show {
    transform: translateX(-50%) translateY(0);
}

.achievement-toast.hidden {
    display: flex;
}

.achievement-toast #toast-icon {
    font-size: 32px;
}

.toast-content {
    display: flex;
    flex-direction: column;
}

#toast-title {
    font-size: 12px;
    opacity: 0.9;
}

#toast-name {
    font-size: 18px;
    font-weight: 700;
}

@media (max-width: 520px) {
    .achievements-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .achievement-icon {
        font-size: 20px;
    }

    .achievement-name {
        font-size: 8px;
    }
}

/* Tips Panel */
.tips-panel {
    width: 100%;
    max-width: 500px;
    margin: 10px auto 20px;
}

.tips-toggle {
    width: 100%;
    padding: 12px 20px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.tips-toggle:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.tips-content {
    margin-top: 10px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    animation: slideDown 0.3s ease;
}

.tips-content.hidden {
    display: none;
}

.tips-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.tips-list li {
    padding: 12px 15px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
    border-radius: 8px;
    font-size: 14px;
    color: #5b21b6;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tips-basic li {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    color: #1e40af;
}

.tips-basic li::before {
    content: "•";
    font-weight: bold;
    color: #3b82f6;
}

.tips-advanced li {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    color: #92400e;
}

.tips-advanced li::before {
    content: "";
}

.tips-list li:last-child {
    margin-bottom: 0;
}

.tips-section-title {
    font-size: 14px;
    font-weight: 700;
    color: #374151;
    margin: 0 0 10px 0;
    padding-bottom: 5px;
    border-bottom: 2px solid #e5e7eb;
}

.tips-section-title:not(:first-child) {
    margin-top: 20px;
}

.tips-intro {
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 12px;
}

.strategy-links {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.strategy-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-radius: 10px;
    text-decoration: none;
    color: #92400e;
    transition: transform 0.2s, box-shadow 0.2s;
}

.strategy-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(251, 191, 36, 0.4);
}

.strategy-icon {
    font-size: 20px;
}

.strategy-name {
    font-size: 13px;
    font-weight: 600;
}

@media (max-width: 520px) {
    .strategy-links {
        grid-template-columns: 1fr;
    }
}

/* Share Panel */
.share-panel {
    width: 100%;
    max-width: 500px;
    margin: 10px auto 20px;
}

.share-toggle {
    width: 100%;
    padding: 12px 20px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.share-toggle:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}

.share-content {
    margin-top: 10px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    animation: slideDown 0.3s ease;
}

.share-content.hidden {
    display: none;
}

.share-intro {
    font-size: 14px;
    color: #6b7280;
    margin-bottom: 15px;
    text-align: center;
}

.share-preview {
    background: linear-gradient(135deg, #f0fdfa 0%, #ccfbf1 100%);
    border: 1px solid #5eead4;
    border-radius: 8px;
    padding: 12px 15px;
    margin-bottom: 15px;
    font-size: 13px;
    line-height: 1.5;
}

.share-preview .preview-label {
    display: block;
    font-weight: 600;
    color: #0d9488;
    margin-bottom: 5px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.share-preview .preview-text {
    color: #374151;
    display: block;
    word-break: break-word;
}

.share-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.share-btn {
    flex: 1;
    min-width: 100px;
    padding: 12px 15px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.share-btn:hover {
    transform: translateY(-2px);
}

.share-twitter {
    background: #000000;
}

.share-twitter:hover {
    background: #333333;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.share-facebook {
    background: #1877f2;
}

.share-facebook:hover {
    background: #166fe5;
    box-shadow: 0 4px 12px rgba(24, 119, 242, 0.4);
}

.share-copy {
    background: #6b7280;
}

.share-copy:hover {
    background: #4b5563;
    box-shadow: 0 4px 12px rgba(107, 114, 128, 0.4);
}

.share-copy.copied {
    background: #10b981;
}

.share-icon {
    font-size: 16px;
    font-weight: 700;
}

@media (max-width: 520px) {
    .share-buttons {
        flex-direction: column;
    }

    .share-btn {
        min-width: auto;
    }
}