/* ===== DESIGN SYSTEM - 드리미 파스텔 테마 ===== */
:root {
    --bg-dark: #1a1026;
    --bg-panel: rgba(60, 30, 80, 0.55);
    --bg-panel-border: rgba(255, 180, 230, 0.2);
    --accent-glow: rgba(255, 150, 220, 0.3);
    --text-primary: #ffe8f6;
    --text-secondary: #c9a0d0;
    --text-accent: #ffb8e0;
    --border-radius: 20px;
    --font-family: 'Outfit', sans-serif;
}

/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--bg-dark);
    background-image:
        radial-gradient(ellipse at 15% 30%, rgba(180, 80, 200, 0.18) 0%, transparent 55%),
        radial-gradient(ellipse at 85% 60%, rgba(100, 60, 180, 0.15) 0%, transparent 55%),
        radial-gradient(ellipse at 50% 90%, rgba(255, 120, 180, 0.1) 0%, transparent 50%);
    color: var(--text-primary);
    font-family: var(--font-family);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* ===== 떠다니는 별/반짝이 배경 ===== */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        radial-gradient(1.5px 1.5px at 10% 15%, rgba(255, 200, 255, 0.5), transparent),
        radial-gradient(1px 1px at 25% 45%, rgba(200, 180, 255, 0.4), transparent),
        radial-gradient(1.5px 1.5px at 40% 20%, rgba(255, 180, 220, 0.5), transparent),
        radial-gradient(1px 1px at 55% 75%, rgba(180, 200, 255, 0.4), transparent),
        radial-gradient(2px 2px at 70% 35%, rgba(255, 170, 230, 0.5), transparent),
        radial-gradient(1px 1px at 85% 60%, rgba(200, 160, 255, 0.4), transparent),
        radial-gradient(1.5px 1.5px at 15% 80%, rgba(255, 200, 240, 0.45), transparent),
        radial-gradient(1px 1px at 60% 10%, rgba(180, 180, 255, 0.4), transparent),
        radial-gradient(2px 2px at 90% 85%, rgba(255, 160, 200, 0.5), transparent),
        radial-gradient(1px 1px at 35% 55%, rgba(220, 180, 255, 0.35), transparent);
    animation: twinkle 6s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: 0;
}

@keyframes twinkle {
    0% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.6;
    }
}

/* ===== GAME LAYOUT ===== */
.game-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    padding: 20px;
    animation: fadeInUp 0.8s ease-out;
    position: relative;
    z-index: 1;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== PANELS ===== */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 160px;
}

.panel-box {
    background: var(--bg-panel);
    border: 1px solid var(--bg-panel-border);
    border-radius: var(--border-radius);
    padding: 16px;
    backdrop-filter: blur(16px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 200, 240, 0.08);
    transition: box-shadow 0.3s ease;
}

.panel-box:hover {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 200, 240, 0.08), 0 0 24px var(--accent-glow);
}

.panel-box h3 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-align: center;
}

/* ===== HOLD / NEXT PIECE CANVASES ===== */
.hold-box canvas,
.next-box canvas {
    display: block;
    margin: 0 auto;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.2);
}

.next-pieces {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ===== STATS ===== */
.stats-box {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: var(--text-secondary);
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 800;
    background: linear-gradient(135deg, #ffb8e0, #c8a0ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ===== GAME BOARD ===== */
.game-board-container {
    position: relative;
    border-radius: 24px 24px 8px 8px;
    overflow: hidden;
    box-shadow:
        0 0 50px rgba(200, 100, 255, 0.12),
        0 20px 60px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--bg-panel-border);
}

#gameCanvas {
    display: block;
    background: rgba(15, 8, 25, 0.92);
}

/* ===== OVERLAY ===== */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(20, 10, 35, 0.88);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: opacity 0.4s ease;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-content {
    text-align: center;
    animation: pulse 2s ease-in-out infinite alternate;
}

@keyframes pulse {
    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.03);
    }
}

.overlay-content h1 {
    font-weight: 800;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.title-sub {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 4px;
    background: linear-gradient(90deg, #ffd1f0, #ffe0a3, #d1c4ff, #ffd1f0);
    background-size: 300% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 3s ease-in-out infinite;
}

.title-main {
    font-size: 2.4rem;
    font-weight: 800;
    background: linear-gradient(135deg, #ff80c0, #c080ff, #80d0ff, #ff80c0);
    background-size: 300% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: neonFlow 4s ease-in-out infinite;
    filter: drop-shadow(0 0 15px rgba(255, 128, 192, 0.5)) drop-shadow(0 0 30px rgba(192, 128, 255, 0.3));
}

@keyframes shimmer {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

@keyframes neonFlow {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

.overlay-content p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

#startBtn {
    padding: 12px 36px;
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #e060a0, #b060e0);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.3s;
    box-shadow: 0 4px 20px rgba(200, 80, 180, 0.35);
}

#startBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 28px rgba(200, 80, 180, 0.55);
}

#startBtn:active {
    transform: translateY(0);
}

/* ===== CONTROLS BOX ===== */
.controls-box {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.control-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

kbd {
    display: inline-block;
    padding: 2px 7px;
    font-family: var(--font-family);
    font-size: 0.7rem;
    background: rgba(255, 180, 230, 0.1);
    border: 1px solid rgba(255, 180, 230, 0.2);
    border-radius: 5px;
    color: var(--text-accent);
    line-height: 1.4;
}

/* ===== LINE CLEAR FLASH ===== */
@keyframes lineClear {
    0% {
        background: rgba(255, 200, 240, 0.8);
    }

    100% {
        background: transparent;
    }
}

/* ===== RESPONSIVE & MOBILE CONTROLS ===== */
@media (max-width: 640px) {
    body {
        padding: 0;
        margin: 0;
        height: 100vh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        touch-action: none;
    }

    .game-wrapper {
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        gap: 5px;
        padding: 5px 0;
        height: 100vh;
        width: 100vw;
    }

    /* 상단 패널 (홀드 + 점수) - 너비를 조절하여 기준점으로 삼음 */
    .side-panel {
        flex-direction: row;
        width: 90vw;
        max-width: 320px;
        /* 이 너비를 게임 보드와 맞춤 */
        height: auto;
        gap: 8px;
        justify-content: center;
        margin-bottom: 5px;
    }

    .left-panel {
        order: 1;
    }

    .right-panel {
        display: none;
    }

    /* 공간 부족으로 모바일 다음 블록 숨김 */

    .panel-box {
        padding: 8px;
        border-radius: 12px;
        flex: 1;
        max-width: none;
        height: 55px;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 10px;
        background: rgba(40, 20, 60, 0.4);
    }

    .panel-box h3 {
        display: none;
    }

    .hold-box canvas {
        width: 35px !important;
        height: 35px !important;
    }

    .stats-box {
        flex-direction: column;
        gap: 0;
    }

    .stat {
        flex-direction: row;
        gap: 5px;
        align-items: baseline;
    }

    .stat-label {
        font-size: 0.5rem;
    }

    .stat-value {
        font-size: 0.9rem;
    }

    /* 메인 보드 - 상단 박스 너비와 완벽하게 일치시키고 1:2 비율 유지 */
    .game-board-container {
        order: 2;
        width: 90vw;
        max-width: 320px;
        aspect-ratio: 1 / 2;
        height: auto;
        margin: 0 auto;
        display: flex;
        align-items: center;
        justify-content: center;
        border: none;
    }

    #gameCanvas {
        width: 100%;
        height: 100%;
        display: block;
    }

    /* 하단 컨트롤 */
    .mobile-controls {
        order: 3;
        display: flex;
        width: 100%;
        max-width: 400px;
        justify-content: space-around;
        padding: 10px 15px 30px 15px;
        margin-top: auto;
    }

    .control-group {
        display: flex;
        gap: 8px;
    }

    .movement {
        align-items: flex-end;
    }

    .primary {
        align-items: flex-end;
    }

    .touch-btn {
        width: 50px;
        height: 50px;
        font-size: 1rem;
        border-radius: 50%;
        background: var(--bg-panel);
        border: 1px solid var(--bg-panel-border);
        color: var(--text-primary);
        display: flex;
        align-items: center;
        justify-content: center;
        backdrop-filter: blur(10px);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    }

    .touch-btn.primary {
        width: 65px;
        height: 65px;
        font-size: 0.8rem;
        background: linear-gradient(135deg, #ff80c0, #c080ff);
    }

    .touch-btn.secondary {
        width: 42px;
        height: 42px;
        font-size: 0.8rem;
    }

    .touch-btn:active {
        transform: scale(0.9);
        background: rgba(255, 180, 230, 0.4);
    }
}

/* PC에서는 모바일 오버레이 숨김 */
@media (min-width: 641px) {
    .mobile-controls {
        display: none;
    }
}