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

:root {
    --bg: #ffffff;
    --text: #1a1a1b;
    --text-muted: #787c7e;
    --border: #d3d6da;
    --key-bg: #e2e5e9;
    --board-bg: #bbada0;
    --cell-bg: #cdc1b4;
    --overlay: rgba(238, 228, 218, 0.73);
    --overlay-text: #776e65;
}

[data-theme="dark"] {
    --bg: #121213;
    --text: #f8f8f8;
    --text-muted: #818384;
    --border: #3a3a3c;
    --key-bg: #818384;
    --board-bg: #2e2b28;
    --cell-bg: #3d3833;
    --overlay: rgba(20, 18, 16, 0.75);
    --overlay-text: #f8f8f8;
}

html, body { height: 100%; }

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background 0.2s, color 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    overflow-x: hidden;
}

.header {
    width: 100%;
    max-width: 500px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}

.title { font-size: 1.25rem; font-weight: 700; letter-spacing: 0.15em; }
.header-right { display: flex; gap: 4px; }

.icon-btn {
    background: none; border: none; font-size: 1.1rem; color: var(--text-muted);
    cursor: pointer; width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--key-bg); }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: inline; }

.game {
    position: relative;
    width: 100%;
    max-width: 480px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
    gap: 14px;
}

.scores { display: flex; gap: 10px; width: min(440px, 92vw); justify-content: flex-end; }
.score-box {
    background: var(--board-bg); color: #fff; border-radius: 8px;
    padding: 6px 16px; text-align: center; min-width: 88px;
}
.score-label { font-size: 0.7rem; letter-spacing: 0.05em; opacity: 0.85; }
.score-val { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.board {
    position: relative;
    width: min(440px, 92vw);
    aspect-ratio: 1;
    background: var(--board-bg);
    border-radius: 10px;
    padding: 3%;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 3%;
    touch-action: none;
}

.cell {
    background: var(--cell-bg);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-size: clamp(1.1rem, 7vw, 2.2rem);
    transition: transform 0.08s ease;
}
.cell.pop { animation: pop 0.15s ease; }
@keyframes pop { 0% { transform: scale(0.5); } 100% { transform: scale(1); } }

/* 숫자별 색 (표준 2048 팔레트) */
.v2    { background: #eee4da; color: #776e65; }
.v4    { background: #ede0c8; color: #776e65; }
.v8    { background: #f2b179; color: #f9f6f2; }
.v16   { background: #f59563; color: #f9f6f2; }
.v32   { background: #f67c5f; color: #f9f6f2; }
.v64   { background: #f65e3b; color: #f9f6f2; }
.v128  { background: #edcf72; color: #f9f6f2; font-size: clamp(0.95rem, 6vw, 1.8rem); }
.v256  { background: #edcc61; color: #f9f6f2; font-size: clamp(0.95rem, 6vw, 1.8rem); }
.v512  { background: #edc850; color: #f9f6f2; font-size: clamp(0.95rem, 6vw, 1.8rem); }
.v1024 { background: #edc53f; color: #f9f6f2; font-size: clamp(0.8rem, 5vw, 1.5rem); }
.v2048 { background: #edc22e; color: #f9f6f2; font-size: clamp(0.8rem, 5vw, 1.5rem); }
.vbig  { background: #3c3a32; color: #f9f6f2; font-size: clamp(0.8rem, 5vw, 1.5rem); }

.new-btn {
    background: var(--board-bg); color: #fff; border: none;
    border-radius: 8px; padding: 10px 24px; font-size: 0.95rem;
    font-weight: 600; cursor: pointer; font-family: inherit;
}
.new-btn:active { transform: scale(0.98); }

.hint { font-size: 0.8rem; color: var(--text-muted); text-align: center; max-width: 340px; }

.overlay-msg {
    position: absolute; inset: 0; display: none;
    align-items: center; justify-content: center;
    background: var(--overlay); border-radius: 10px;
}
.overlay-msg.show { display: flex; }
.overlay-inner { text-align: center; color: var(--overlay-text); }
.overlay-inner p { font-size: 1.6rem; font-weight: 700; margin-bottom: 14px; }
