/* Skip link for accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color, #EDB879);
    color: #fff;
    padding: 8px 16px;
    z-index: 10000;
    transition: top 0.2s;
    font-size: 14px;
    border-radius: 0 0 4px 0;
}
.skip-link:focus {
    top: 0;
}

:root {
    --primary-color: #EDB879;
    --primary-dark: #D4A574;
    --text-color: #ecf0f1;
    --text-light: #b0b0b0;
    --bg-color: #1a1a1a;
    --bg-dark: #0f0f0f;
    --tile-bg: #3d3330;
    --tile-text: #ecf0f1;
    --border-radius: 12px;
    --transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* 터치 최적화 */
button, a, input, [role="button"], [role="link"] {
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

input[type="text"], textarea {
    -webkit-user-select: text;
    user-select: text;
}

html, body {
    width: 100%;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
}

body {
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* App Loader */
.app-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.app-loader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}
.loader-emoji {
    font-size: 48px;
    animation: loader-bounce 1s ease-in-out infinite;
}
.loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: loader-spin 0.8s linear infinite;
}
.loader-text {
    font-size: 14px;
    color: var(--text-light);
    letter-spacing: 1px;
    font-weight: 500;
}
@keyframes loader-spin {
    to { transform: rotate(360deg); }
}
@keyframes loader-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Ad Banners */
.ad-banner {
    padding: 10px;
    background: var(--bg-dark);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: center;
}

.ad-banner ins {
    display: block;
}

/* Container */
.container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

/* Header */
.header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.header-title h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary-color);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-controls {
    display: flex;
    gap: 12px;
}

/* Language Selector */
.language-selector {
    position: relative;
}

.lang-toggle {
    font-size: 24px;
    background: none;
    border: 2px solid var(--primary-color);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    color: var(--primary-color);
}

.lang-toggle:hover, .lang-toggle:focus {
    background-color: var(--primary-color);
    color: white;
    transform: scale(1.1);
}

.lang-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-dark);
    border: 1px solid var(--primary-color);
    border-radius: var(--border-radius);
    padding: 8px;
    margin-top: 8px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    min-width: 200px;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.lang-menu.hidden {
    display: none;
}

.lang-option {
    padding: 8px 12px;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: var(--transition);
    color: var(--text-color);
}

.lang-option:hover, .lang-option.active {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
}

/* Stats Panel */
.stats-panel {
    display: flex;
    gap: 16px;
    width: 100%;
    margin-bottom: 24px;
    justify-content: center;
}

.stat-box {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    border-radius: var(--border-radius);
    padding: 16px 24px;
    text-align: center;
    min-width: 100px;
    box-shadow: 0 4px 12px rgba(237, 184, 121, 0.2);
}

.stat-label {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: white;
    font-variant-numeric: tabular-nums;
}

/* Game Area */
.game-area {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    max-width: 400px;
    margin-bottom: 24px;
    border-radius: var(--border-radius);
    background-color: var(--bg-dark);
    overflow: hidden;
}

.game-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 8px;
    padding: 12px;
    height: 100%;
    position: relative;
    background-color: inherit;
}

/* Tile */
.tile {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    border-radius: 8px;
    user-select: none;
    font-variant-numeric: tabular-nums;
    transition: var(--transition);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

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

.tile.moving {
    z-index: 10;
}

@keyframes pop-in {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

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

.tile.merge {
    animation: pop-merge 0.15s ease-out;
}

/* Tile Colors and Values */
.tile-2 { background: linear-gradient(135deg, #e8d8c8, #dcc8b8); color: #776e65; font-size: 32px; }
.tile-4 { background: linear-gradient(135deg, #dcc8b8, #d0bda8); color: #776e65; font-size: 32px; }
.tile-8 { background: linear-gradient(135deg, #ede0c8, #e8d4ba); color: #f9f6f2; font-size: 32px; }
.tile-16 { background: linear-gradient(135deg, #f2b179, #eaa664); color: #f9f6f2; font-size: 28px; }
.tile-32 { background: linear-gradient(135deg, #f59563, #ea9355); color: #f9f6f2; font-size: 28px; }
.tile-64 { background: linear-gradient(135deg, #f67c5f, #f05d49); color: #f9f6f2; font-size: 28px; }
.tile-128 { background: linear-gradient(135deg, #edcf72, #e3bf5e); color: #776e65; font-size: 24px; font-weight: 700; }
.tile-256 { background: linear-gradient(135deg, #edcc61, #e3b84f); color: #776e65; font-size: 24px; font-weight: 700; }
.tile-512 { background: linear-gradient(135deg, #edc850, #e2b83d); color: #f9f6f2; font-size: 24px; font-weight: 700; }
.tile-1024 { background: linear-gradient(135deg, #edc22e, #d9b61b); color: #f9f6f2; font-size: 20px; font-weight: 700; }
.tile-2048 { background: linear-gradient(135deg, #EDB879, #D4A574); color: #f9f6f2; font-size: 20px; font-weight: 700; box-shadow: 0 6px 16px rgba(237, 184, 121, 0.4); }
.tile-4096 { background: linear-gradient(135deg, #daa56b, #c39558); color: #f9f6f2; font-size: 18px; font-weight: 700; }
.tile-8192 { background: linear-gradient(135deg, #c89450, #b17b3a); color: #f9f6f2; font-size: 18px; font-weight: 700; }

@media (prefers-color-scheme: dark) {
    .tile-2, .tile-4 { background: linear-gradient(135deg, #5c5340, #4a4337); color: #d4c9bf; }
    .tile-8, .tile-16, .tile-32, .tile-64 { color: #2a2825; }
    .tile-128, .tile-256, .tile-512 { color: #2a2825; }
}

/* Game Overlay */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
    border-radius: var(--border-radius);
}

.game-overlay.show {
    display: flex;
}

.overlay-content {
    background: var(--bg-color);
    border-radius: var(--border-radius);
    padding: 32px 24px;
    text-align: center;
    max-width: 90%;
    border: 2px solid var(--primary-color);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

#overlay-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--primary-color);
}

#overlay-message {
    font-size: 16px;
    color: var(--text-light);
    margin-bottom: 24px;
    line-height: 1.6;
}

/* Controls */
.controls {
    display: flex;
    gap: 12px;
    width: 100%;
    margin-bottom: 24px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn {
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 12px rgba(237, 184, 121, 0.3);
}

.btn-primary:hover, .btn-primary:focus {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(237, 184, 121, 0.4);
}

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

.btn-secondary {
    background: var(--bg-dark);
    color: var(--text-color);
    border: 2px solid var(--primary-color);
}

.btn-secondary:hover, .btn-secondary:focus {
    background: var(--primary-color);
    color: white;
}

.btn-large {
    flex: 1;
    min-width: 140px;
}

/* CTA pulse animation */
@keyframes ctaPulse {
    0%, 100% { box-shadow: 0 4px 15px rgba(39, 174, 96, 0.3); }
    50% { box-shadow: 0 4px 30px rgba(39, 174, 96, 0.6), 0 0 60px rgba(39, 174, 96, 0.2); }
}
.btn-cta-pulse {
    animation: ctaPulse 2s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
    .btn-cta-pulse { animation: none !important; }
}

.btn.hidden {
    display: none;
}

/* Instructions */
.instructions {
    text-align: center;
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 24px;
    line-height: 1.8;
}

.instructions p {
    margin-bottom: 8px;
}

/* DopaBrain Apps Section */
.dopabrain-section {
    width: 100%;
    margin-top: 32px;
    padding-top: 32px;
    border-top: 2px solid var(--bg-dark);
}

.dopabrain-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
    text-align: center;
    color: var(--text-color);
}

.dopabrain-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
}

.dopabrain-card {
    background: var(--bg-dark);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.dopabrain-card:hover, .dopabrain-card:focus {
    border-color: var(--primary-color);
    transform: translateY(-4px);
    box-shadow: 0 6px 16px rgba(237, 184, 121, 0.2);
}

.dopabrain-icon {
    font-size: 32px;
}

.dopabrain-name {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Interstitial Ad */
.interstitial-ad {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.interstitial-ad.hidden {
    display: none;
}

.interstitial-content {
    position: relative;
    background: var(--bg-color);
    border-radius: 12px;
    padding: 24px;
    max-width: 90%;
}

.interstitial-close {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
    cursor: pointer;
    transition: var(--transition);
}

.interstitial-close:hover {
    transform: scale(1.1);
}

/* Responsive */
@media (max-width: 480px) {
    .header-title h1 {
        font-size: 24px;
    }

    .header {
        margin-bottom: 16px;
    }

    .container {
        padding: 12px;
    }

    .stats-panel {
        gap: 12px;
        margin-bottom: 16px;
    }

    .stat-box {
        padding: 12px 16px;
        min-width: 80px;
    }

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

    .tile {
        font-size: 20px;
    }

    .controls {
        margin-bottom: 16px;
        gap: 8px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 13px;
    }

    .dopabrain-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 360px) {
    .header-title h1 {
        font-size: 20px;
    }

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

    .stat-label {
        font-size: 11px;
    }

    .dopabrain-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Print Styles */
/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark, var(--bg-primary, var(--background, #0f0f23)));
}

::-webkit-scrollbar-thumb {
    background: #3498db;
    border-radius: 5px;
    border: 2px solid var(--bg-dark, var(--bg-primary, var(--background, #0f0f23)));
}

::-webkit-scrollbar-thumb:hover {
    background: #5cace2;
    opacity: 0.8;
}

/* Selection Color */
::selection {
    background: #3498db;
    color: white;
}

::-moz-selection {
    background: #3498db;
    color: white;
}

/* Focus Visible */
button:focus-visible,
a:focus-visible,
input:focus-visible,
[role="button"]:focus-visible {
    outline: 3px solid #3498db;
    outline-offset: 2px;
}

/* Light Mode */
[data-theme="light"] {
    --bg-color: #f5f5fa;
    --bg-dark: #ffffff;
    --text-color: #1a1a2e;
    --text-light: #5a5a70;
    --tile-bg: #ffffff;
    --tile-text: #1a1a2e;
}

[data-theme="light"] body {
    background-color: var(--bg-color);
}

[data-theme="light"] .app-loader {
    background: var(--bg-color);
}

[data-theme="light"] .lang-menu {
    background: var(--bg-dark);
    border-color: rgba(237, 184, 121, 0.2);
}

[data-theme="light"] .lang-option {
    color: var(--text-color);
}

[data-theme="light"] .lang-option:hover {
    background: rgba(237, 184, 121, 0.1);
}

[data-theme="light"] .game-container {
    background: rgba(237, 184, 121, 0.05);
    border-color: rgba(237, 184, 121, 0.15);
}

[data-theme="light"] .tile {
    background: var(--tile-bg);
    border-color: rgba(237, 184, 121, 0.2);
    color: var(--tile-text);
}

[data-theme="light"] .game-over-modal {
    background: var(--bg-dark);
    border-color: rgba(237, 184, 121, 0.2);
}

/* Theme Toggle */
.theme-toggle {
    position: fixed;
    top: 12px;
    right: 56px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
}

.theme-toggle:active {
    transform: scale(0.95);
}

[data-theme="light"] .theme-toggle {
    background: rgba(237, 184, 121, 0.1);
    border-color: rgba(237, 184, 121, 0.2);
    color: var(--text-color);
}

[data-theme="light"] .theme-toggle:hover {
    background: rgba(237, 184, 121, 0.15);
}

@media print {
    .ad-banner, .header-controls, .controls, .instructions, .dopabrain-section {
        display: none;
    }
}
