/* =============================================
   2048 퍼즐 게임 스타일
   테마: 다크 + 2048 클래식 컬러
   ============================================= */

html { background: #0f0f23; }

.p2-body {
    overflow: hidden;
    height: 100dvh;
    max-width: 480px;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: #f0f0f0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* Game Area */
.p2-game {
    width: 100%;
    height: 100dvh;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    position: relative;
    background: #0f0f23;
}

/* Top Bar */
.p2-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    z-index: 10;
    flex-shrink: 0;
}
.p2-back {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 14px;
    padding: 6px 12px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.2);
}
.p2-back:hover { color: #fff; }

.p2-scores {
    display: flex;
    gap: 8px;
}
.p2-score-box {
    background: rgba(237, 197, 63, 0.15);
    border: 1px solid rgba(237, 197, 63, 0.25);
    border-radius: 8px;
    padding: 4px 14px;
    text-align: center;
    min-width: 70px;
}
.p2-score-box span {
    display: block;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.p2-score-box strong {
    display: block;
    font-size: 18px;
    font-weight: 800;
    color: #edc53f;
}

/* Content */
.p2-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px 24px;
    overflow-y: auto;
}

/* ===== Intro ===== */
.state-intro .p2-content {
    justify-content: flex-start;
    padding-top: 32px;
}

.p2-intro-emoji { font-size: 72px; margin-bottom: 16px; }
.p2-intro-title {
    font-size: 36px;
    font-weight: 900;
    color: #edc53f;
    margin-bottom: 8px;
    letter-spacing: 2px;
}
.p2-intro-desc {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.6);
    line-height: 1.6;
    margin-bottom: 20px;
    text-align: center;
}
.p2-intro-desc strong { color: #edc53f; }

.p2-best-record {
    background: rgba(237, 197, 63, 0.1);
    border-radius: 10px;
    padding: 10px 18px;
    margin-bottom: 12px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
}

.p2-challenge {
    background: rgba(237, 197, 63, 0.15);
    border: 1px solid rgba(237, 197, 63, 0.3);
    border-radius: 12px;
    padding: 14px 20px;
    margin-bottom: 20px;
    font-size: 16px;
    color: #edc53f;
    text-align: center;
}
.p2-challenge strong { font-size: 22px; }

.p2-intro-controls {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.4);
}
.p2-intro-controls span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.p2-intro-btns {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.p2-btn-start {
    display: inline-block;
    padding: 16px 48px;
    background: linear-gradient(135deg, #edc53f, #d4a017);
    color: #1a1a2e;
    border: none;
    border-radius: 14px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s;
}
.p2-btn-start:active { transform: scale(0.95); }

.p2-btn-continue {
    display: inline-block;
    padding: 16px 32px;
    background: rgba(237, 197, 63, 0.15);
    border: 2px solid rgba(237, 197, 63, 0.4);
    border-radius: 14px;
    color: #edc53f;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s;
}
.p2-btn-continue:active { transform: scale(0.95); }

/* ===== Playing ===== */
.state-playing .p2-content {
    justify-content: flex-start;
    padding-top: 8px;
}

/* Board */
.p2-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    background: #1e1e3a;
    padding: 8px;
    border-radius: 10px;
    width: 100%;
    max-width: 360px;
    aspect-ratio: 1 / 1;
}

.p2-cell {
    background: #2d2d44;
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}

.p2-tile {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    border-radius: 6px;
    transition: none;
}

/* Tile colors */
.p2-tile[data-value="2"] { background: #eee4da; color: #776e65; }
.p2-tile[data-value="4"] { background: #ede0c8; color: #776e65; }
.p2-tile[data-value="8"] { background: #f2b179; color: #f9f6f2; }
.p2-tile[data-value="16"] { background: #f59563; color: #f9f6f2; }
.p2-tile[data-value="32"] { background: #f67c5f; color: #f9f6f2; }
.p2-tile[data-value="64"] { background: #f65e3b; color: #f9f6f2; }
.p2-tile[data-value="128"] { background: #edcf72; color: #f9f6f2; }
.p2-tile[data-value="256"] { background: #edcc61; color: #f9f6f2; }
.p2-tile[data-value="512"] { background: #edc850; color: #f9f6f2; }
.p2-tile[data-value="1024"] { background: #edc53f; color: #f9f6f2; }
.p2-tile[data-value="2048"] { background: #edc22e; color: #f9f6f2; box-shadow: 0 0 30px rgba(237, 194, 46, 0.6); }
.p2-tile[data-value="4096"] { background: #3c3a32; color: #f9f6f2; }
.p2-tile[data-value="8192"] { background: #3c3a32; color: #f9f6f2; }
.p2-tile[data-value="super"] { background: #3c3a32; color: #f9f6f2; }

/* Font size based on digit count */
.p2-tile { font-size: 32px; }
.p2-tile.p2-digits-3 { font-size: 26px; }
.p2-tile.p2-digits-4 { font-size: 22px; }
.p2-tile.p2-digits-5 { font-size: 18px; }

/* Animations */
@keyframes p2Pop {
    0% { transform: scale(0); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes p2Merge {
    0% { transform: scale(1); }
    30% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.p2-tile-new {
    animation: p2Pop 0.2s ease;
}

.p2-tile-merged {
    animation: p2Merge 0.2s ease;
}

/* Game Over Overlay */
.p2-gameover-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 15, 35, 0.75);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    z-index: 5;
    animation: p2FadeIn 0.3s ease;
}

@keyframes p2FadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.p2-gameover-text {
    font-size: 28px;
    font-weight: 900;
    color: #fff;
    margin-bottom: 12px;
}

.p2-gameover-btn {
    padding: 12px 32px;
    background: linear-gradient(135deg, #edc53f, #d4a017);
    color: #1a1a2e;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s;
}
.p2-gameover-btn:active { transform: scale(0.95); }

/* Win overlay */
.p2-win-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(237, 194, 46, 0.25);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    z-index: 5;
    animation: p2FadeIn 0.3s ease;
}

.p2-win-text {
    font-size: 36px;
    font-weight: 900;
    color: #edc22e;
    text-shadow: 0 0 20px rgba(237, 194, 46, 0.5);
    margin-bottom: 8px;
}

.p2-win-sub {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 16px;
}

.p2-win-btns {
    display: flex;
    gap: 12px;
}

.p2-btn-keep {
    padding: 12px 24px;
    background: linear-gradient(135deg, #edc53f, #d4a017);
    color: #1a1a2e;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s;
}
.p2-btn-keep:active { transform: scale(0.95); }

.p2-btn-end {
    padding: 12px 24px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s;
}
.p2-btn-end:active { transform: scale(0.95); }

/* Score addition popup */
.p2-score-add {
    position: absolute;
    font-size: 16px;
    font-weight: 800;
    color: #edc53f;
    pointer-events: none;
    animation: p2ScoreFloat 0.6s ease forwards;
    z-index: 20;
}

@keyframes p2ScoreFloat {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-30px); }
}

/* Playing bottom area */
.p2-playing-bottom {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
    width: 100%;
    max-width: 360px;
}

.p2-btn-undo, .p2-btn-newgame {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s;
}
.p2-btn-undo:active, .p2-btn-newgame:active { transform: scale(0.95); }

/* ===== Result ===== */
.state-result .p2-content {
    justify-content: flex-start;
    padding-top: 24px;
}

.p2-result-badge {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 3px solid;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    background: rgba(237, 197, 63, 0.08);
}
.p2-result-emoji { font-size: 40px; }
.p2-result-grade {
    font-size: 28px;
    font-weight: 900;
    margin-top: 2px;
}
.p2-result-label {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
}
.p2-result-pct {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 12px;
}

.p2-result-stats {
    display: flex;
    gap: 32px;
    margin-bottom: 16px;
}
.p2-stat { text-align: center; }
.p2-stat-val {
    display: block;
    font-size: 28px;
    font-weight: 800;
    color: #fff;
}
.p2-stat-label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
}

.p2-new-record {
    background: rgba(237, 197, 63, 0.15);
    border: 1px solid rgba(237, 197, 63, 0.3);
    color: #edc53f;
    padding: 8px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 12px;
}

.p2-challenge-result {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 10px 18px;
    margin-bottom: 12px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
}
.p2-challenge-win { color: #edc53f; }
.p2-challenge-lose { color: #9CA3AF; }

/* Buttons */
.p2-result-btns {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    justify-content: center;
}
.p2-btn-share, .p2-btn-retry, .p2-btn-submit {
    border: none;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s;
}
.p2-btn-share:active, .p2-btn-retry:active, .p2-btn-submit:active { transform: scale(0.95); }

.p2-btn-share {
    padding: 16px 32px;
    background: #FEE500;
    color: #191919;
    font-size: 17px;
    box-shadow: 0 4px 16px rgba(254, 229, 0, 0.3);
    flex: 1;
    min-width: 160px;
    border-radius: 12px;
}
.p2-btn-retry {
    padding: 16px 24px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Ranking */
.p2-ranking-section {
    width: 100%;
    max-width: 360px;
    padding-bottom: 40px;
}
.p2-ranking-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 12px;
    text-align: center;
}
.p2-ranking-form {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.p2-nickname-input {
    flex: 1;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    color: #fff;
    font-size: 14px;
    outline: none;
}
.p2-nickname-input::placeholder { color: rgba(255, 255, 255, 0.3); }
.p2-nickname-input:focus { border-color: rgba(237, 197, 63, 0.5); }

.p2-btn-submit {
    padding: 10px 20px;
    background: #edc53f;
    color: #1a1a2e;
    font-size: 14px;
    border-radius: 10px;
}

.p2-rankings-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.p2-rank-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    font-size: 13px;
}
.p2-rank-pos {
    width: 28px;
    text-align: center;
    font-weight: 700;
}
.p2-rank-name {
    flex: 1;
    color: #fff;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.p2-rank-tile {
    font-size: 12px;
    font-weight: 600;
    color: #edc53f;
}
.p2-rank-score {
    color: rgba(255, 255, 255, 0.5);
    font-size: 12px;
    min-width: 60px;
    text-align: right;
}
.p2-no-ranking {
    text-align: center;
    color: rgba(255, 255, 255, 0.3);
    font-size: 13px;
    padding: 16px;
}

/* Toast */
.p2-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 14px;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.p2-toast-show {
    opacity: 1;
    pointer-events: auto;
}

/* ===== Board Wrapper (for overlay positioning) ===== */
.p2-board-wrapper {
    position: relative;
    width: 100%;
    max-width: 360px;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .p2-board {
        gap: 6px;
        padding: 6px;
        border-radius: 8px;
    }
    .p2-tile { font-size: 28px; }
    .p2-tile.p2-digits-3 { font-size: 22px; }
    .p2-tile.p2-digits-4 { font-size: 18px; }
    .p2-tile.p2-digits-5 { font-size: 15px; }
    .p2-score-box { min-width: 60px; padding: 4px 10px; }
    .p2-score-box strong { font-size: 16px; }
    .p2-intro-title { font-size: 30px; }
}

@media (max-width: 360px) {
    .p2-board {
        gap: 4px;
        padding: 4px;
    }
    .p2-tile { font-size: 24px; }
    .p2-tile.p2-digits-3 { font-size: 20px; }
    .p2-tile.p2-digits-4 { font-size: 16px; }
    .p2-tile.p2-digits-5 { font-size: 13px; }
}
