/* ═══════════════════════════════════ 테마 변수 ══ */
:root {
    --bg-top:       #f0fdf4;
    --bg-bottom:    #f8fafc;
    --panel:        rgba(255, 255, 255, 0.88);
    --panel-strong: rgba(255, 255, 255, 0.96);
    --line:         rgba(226, 232, 240, 0.8);
    --text:         #1e293b;
    --muted:        #64748b;
    --accent:       #22c55e;
    --accent-strong:#16a34a;
    --shadow-soft:  0 18px 42px rgba(100, 116, 139, 0.12);
    --shadow-strong:0 20px 32px rgba(100, 116, 139, 0.18);
    --board-bg:     #f0f4ff;
    --board-border: rgba(99, 102, 241, 0.45);
}

/* ═══════════════════════════════════ 기본 ══ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* body는 .game-shell-body (공유 CSS)에서 100dvh flex column 처리 */
html, body {
    font-family: 'Noto Sans KR', sans-serif;
    background: linear-gradient(160deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
    color: var(--text);
}

/* ═══════════════════════════════════ 배경 장식 ══ */
.page-glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.25;
    pointer-events: none;
    z-index: 0;
    animation: drift 14s ease-in-out infinite alternate;
}
.glow-a { width: 520px; height: 520px; background: #bbf7d0; top: -120px; left: -80px; }
.glow-b { width: 360px; height: 360px; background: #d1fae5; bottom: 40px; right: -60px; animation-delay: -6s; }
@keyframes drift {
    from { transform: translate(0, 0) scale(1); }
    to   { transform: translate(30px, 20px) scale(1.06); }
}

/* ═══════════════════════════════════ 앱 래퍼 ══ */
#app {
    position: relative;
    z-index: 1;
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding-top: 3.5rem; /* back-pill 공간 */
}

.game-shell {
    flex: 1 1 0;
    min-height: 0;
    max-width: 1000px;
    width: 100%;
    margin: 0 auto;
    padding: 0.5rem 1rem 0.75rem;
    display: flex;
    flex-direction: column;
}

.play-layout {
    flex: 1 1 0;
    min-height: 0;
    align-items: center !important;
}

/* ═══════════════════════════════════ 2열 레이아웃 ══ */
.play-layout {
    display: grid;
    grid-template-columns: 200px auto;
    gap: 1.2rem;
    align-items: start;
    justify-content: center;
}

/* ═══════════════════════════════════ 사이드 패널 ══ */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.panel-block {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 20px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow-soft);
    padding: 0.9rem 1rem;
}

/* ── 통계 라벨/값 (레트로 픽셀 폰트) ── */
.stat-label {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.45rem;
    color: var(--muted);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 0.35rem;
}

.stat-value {
    font-family: 'Press Start 2P', monospace;
    font-size: 1rem;
    color: var(--accent-strong);
    letter-spacing: 0.05em;
    line-height: 1;
}

.stat-row {
    display: flex;
    gap: 1rem;
}

/* ── NEXT 피스 캔버스 ── */
#next-canvas {
    display: block;
    width: 100%;
    max-width: 120px;
    height: auto;
    background: var(--board-bg);
    border: 2px solid var(--board-border);
    border-radius: 6px;
    image-rendering: pixelated;
    margin-top: 0.4rem;
}

/* ── 버튼 ── */
.action-grid {
    display: grid;
    gap: 0.5rem;
}

.action-btn {
    width: 100%;
    padding: 0.65rem 0.5rem;
    border: 1px solid rgba(24, 95, 99, 0.16);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.76);
    color: var(--text);
    font-family: 'Press Start 2P', monospace;
    font-size: 0.5rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.1s;
    letter-spacing: 0.08em;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.95);
    transform: translateY(-1px);
}

.action-btn.primary {
    color: #fff;
    background: linear-gradient(135deg, #22c55e 0%, #10b981 100%);
    border-color: transparent;
}

.action-btn.primary:hover {
    background: linear-gradient(135deg, #16a34a 0%, #059669 100%);
}

/* ── 키 안내 ── */
.keys-block {
    font-size: 0.7rem;
    color: var(--muted);
}

.key-row {
    margin-bottom: 0.35rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    line-height: 1.4;
}

kbd {
    display: inline-block;
    background: rgba(0, 0, 0, 0.07);
    border: 1px solid rgba(0, 0, 0, 0.14);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.65rem;
    font-family: monospace;
    white-space: nowrap;
}

/* ═══════════════════════════════════ 보드 카드 ══ */
.board-card {
    align-self: start;
    position: relative;
    background: var(--board-bg);
    border: 3px solid var(--board-border);
    border-radius: 8px;
    box-shadow:
        0 0 20px rgba(99, 102, 241, 0.15),
        0 8px 24px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    display: inline-block; /* shrink-wrap the canvas */
}

/* CRT 주사선 오버레이 */
.board-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(99, 102, 241, 0.04) 2px,
        rgba(99, 102, 241, 0.04) 4px
    );
    pointer-events: none;
    z-index: 5;
}

.board-frame {
    position: relative;
    display: block;
    line-height: 0;
}

#board-canvas {
    display: block;
    max-height: min(720px, calc(100dvh - 80px));
    width: auto;
    image-rendering: pixelated;
}

/* ═══════════════════════════════════ 결과 오버레이 ══ */
.board-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.78);
    z-index: 20;
    backdrop-filter: blur(3px);
}

.board-overlay.hidden { display: none; }

.overlay-card {
    text-align: center;
    padding: 2rem 1.5rem;
}

.overlay-eyebrow {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.45rem;
    color: var(--accent);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    margin-bottom: 0.8rem;
}

.overlay-card h2 {
    font-family: 'Press Start 2P', monospace;
    font-size: 1.2rem;
    color: #fff;
    margin-bottom: 0.75rem;
    letter-spacing: 0.05em;
}

.overlay-card p {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.55rem;
    color: #d1fae5;
    margin-bottom: 1.5rem;
    letter-spacing: 0.1em;
}

.overlay-card .action-btn {
    width: auto;
    padding: 0.7rem 1.4rem;
    font-size: 0.55rem;
}

/* ═══════════════════════════════════ 반응형 ══ */
@media (max-width: 680px) {
    .play-layout {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    .side-panel {
        width: 100%;
        max-width: 400px;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.6rem;
    }

    .panel-block { flex: 1 1 calc(50% - 0.3rem); min-width: 0; }

    .keys-block { display: none; }

    #board-canvas {
        max-height: min(480px, calc(100vw * 2 - 32px));
    }
}
