/* ===================================================================
 * 타자마스터 — '아이잘한다' 디자인 시스템 (Primary Blue · Pretendard · 모던&심플)
 * 토큰은 apps/main-site/style.css 의 :root 와 동일.
 * 레이아웃 셸(.game-shell-body, .back-pill)은 /shared/game-shell.css.
 * =================================================================== */

:root {
    --color-primary: #2563eb;
    --color-primary-pressed: #1d4ed8;
    --color-primary-soft: #dbeafe;
    --color-secondary: #16a34a;
    --color-secondary-soft: #dcfce7;
    --color-xp: #f59e0b;
    --color-xp-soft: #fef3c7;
    --color-canvas: #ffffff;
    --color-surface-soft: #f7f7f7;
    --color-hairline: #e5e7eb;
    --color-text: #222222;
    --color-text-muted: #6a6a6a;
    --color-text-mute: #929292;
    --color-text-stone: #c1c1c1;
    --color-error: #c13515;
    --color-error-soft: #fde7e2;
    --radius-md: 8px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-pill: 32px;
    --elevation-1: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
    --elevation-2: 0 2px 6px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.08);
    /* 손가락 존 색 (검지/중지/약지/새끼) */
    --f-pinky: #fde7f3;
    --f-ring: #fef3c7;
    --f-middle: #dcfce7;
    --f-index: #dbeafe;
    --f-thumb: #eef2f7;
    --font-main: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, system-ui,
        'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

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

body {
    font-family: var(--font-main);
    color: var(--color-text);
    background: var(--color-surface-soft);
}

#game-container {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    position: relative;
    background: linear-gradient(180deg, #f8fbff 0%, #eef2f9 100%);
    overflow: hidden;
}

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 1.25rem;
    transition: opacity 0.25s ease;
    z-index: 10;
}

.screen.hidden,
.hidden {
    opacity: 0;
    pointer-events: none;
    z-index: -1;
}

/* ===== 제목 ===== */
h2.glow-text {
    font-size: 1.9rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--color-text);
    margin-bottom: 1.5rem;
    text-align: center;
}

h2.glow-text::after {
    content: '';
    display: block;
    width: 44px;
    height: 4px;
    margin: 0.5rem auto 0;
    border-radius: 2px;
    background: var(--color-primary);
}

/* ===== 시작 메뉴 ===== */
.menu {
    width: 100%;
    max-width: 620px;
    margin-bottom: 1.75rem;
}

.menu-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.menu-label {
    flex-shrink: 0;
    width: 72px;
    text-align: right;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-text-muted);
}

.seg {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.seg-btn {
    background: var(--color-canvas);
    border: 1px solid var(--color-hairline);
    color: var(--color-text);
    padding: 0.55rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-main);
    transition: border-color 0.15s, color 0.15s, background 0.15s, transform 0.1s;
}

.seg-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.seg-btn:active {
    transform: scale(0.96);
}

.seg-btn.active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
    box-shadow: var(--elevation-1);
}

.primary-btn {
    padding: 0.85rem 2.5rem;
    font-size: 1.05rem;
    font-weight: 700;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-pill);
    box-shadow: var(--elevation-1);
    cursor: pointer;
    font-family: var(--font-main);
    transition: background 0.2s, transform 0.1s;
}

.primary-btn:hover {
    background: var(--color-primary-pressed);
}

.primary-btn:active {
    transform: scale(0.97);
}

.stats-btn {
    padding: 0.85rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    background: var(--color-canvas);
    border: 1px solid var(--color-hairline);
    color: var(--color-text);
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-family: var(--font-main);
    transition: border-color 0.15s, color 0.15s;
}

.stats-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* ===== 게임 화면 레이아웃 ===== */
#game-ui {
    justify-content: flex-start;
    padding: 0;
}

.hud {
    width: 100%;
    flex-shrink: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0.7rem 1.5rem 0.7rem 6rem;
    background: var(--color-canvas);
    border-bottom: 1px solid var(--color-hairline);
    z-index: 20;
}

.hud-item {
    text-align: center;
}

.hud-item span {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--color-text-muted);
    display: block;
    margin-bottom: 0.1rem;
}

.hud-item div {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--color-text);
}

#hud-score div {
    color: var(--color-xp);
}

/* falling/practice 공통 무대 */
.stage {
    width: 100%;
    flex: 1 1 0;
    min-height: 0;
    position: relative;
    display: flex;
    flex-direction: column;
}

.stage.hidden {
    display: none;
}

/* ===== 주어진 입력 (자리/낱말/단문) ===== */
#practice-container {
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.pw-track {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    width: 100%;
    max-width: 900px;
}

.pw-side {
    flex: 1;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--color-text-stone);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

.pw-side:first-child {
    text-align: right;
}

.pw-side:last-child {
    text-align: left;
}

.pw-cur {
    flex-shrink: 0;
    max-width: 60%;
    font-size: 2.6rem;
    font-weight: 800;
    letter-spacing: 1px;
    background: var(--color-canvas);
    padding: 1.1rem 2rem;
    border-radius: var(--radius-lg);
    border: 2px solid var(--color-primary-soft);
    box-shadow: var(--elevation-2);
    word-break: keep-all;
    text-align: center;
}

.pw-ch {
    color: var(--color-text-mute);
    transition: color 0.1s;
}

.pw-ch.done {
    color: var(--color-secondary);
}

.pw-ch.bad {
    color: var(--color-error);
    background: var(--color-error-soft);
    border-radius: 4px;
}

.pw-ch.cur {
    color: var(--color-primary);
    border-bottom: 3px solid var(--color-primary);
}

.pw-hint {
    margin-top: 1.25rem;
    height: 1.3rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

/* ===== 입력창 ===== */
.input-area {
    width: 100%;
    flex-shrink: 0;
    padding: 0.9rem 1.5rem;
    background: var(--color-canvas);
    border-top: 1px solid var(--color-hairline);
    display: flex;
    justify-content: center;
}

#word-input {
    width: 100%;
    max-width: 460px;
    padding: 0.8rem 1rem;
    background: var(--color-surface-soft);
    border: 2px solid var(--color-hairline);
    border-radius: var(--radius-lg);
    color: var(--color-text);
    font-size: 1.2rem;
    font-family: var(--font-main);
    text-align: center;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

#word-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.input-area.sentence-input #word-input {
    max-width: 760px;
    text-align: left;
}

#word-input.error {
    border-color: var(--color-error) !important;
    box-shadow: 0 0 0 3px rgba(193, 53, 21, 0.15) !important;
    animation: shake 0.2s ease-in-out 0s 2 alternate;
}

#word-input.success-flash {
    border-color: var(--color-secondary);
    box-shadow: 0 0 0 3px var(--color-secondary-soft);
}

@keyframes shake {
    0% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-5px); }
    100% { transform: translateX(0); }
}

/* ===== 가상 키보드 ===== */
.keyboard-area {
    width: 100%;
    flex-shrink: 0;
    padding: 0.6rem 1rem 0.9rem;
    background: var(--color-canvas);
    border-top: 1px solid var(--color-hairline);
}

.vk {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
}

.vk-row {
    display: flex;
    gap: 6px;
    justify-content: flex-start;
}

/* 실제 키보드 계단(stagger) — 홈줄·아랫줄을 오른쪽으로 들여 좌우 손가락 자리를 맞춤 */
.vk-row:nth-child(2) {
    margin-left: clamp(13px, 3.2vw, 25px);
}

.vk-row:nth-child(3) {
    margin-left: clamp(20px, 4.8vw, 38px);
}

.vk-row:nth-child(4) {
    justify-content: center;
}

.vk-key {
    width: clamp(26px, 6.5vw, 50px);
    height: clamp(32px, 6.5vw, 50px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-hairline);
    background: var(--color-surface-soft);
    font-size: clamp(0.7rem, 1.6vw, 1rem);
    font-weight: 700;
    color: var(--color-text);
    position: relative;
    transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
}

.vk-wide {
    width: clamp(150px, 36vw, 300px);
}

/* 손가락 존 색 */
.f-pinky-l, .f-pinky-r { background: var(--f-pinky); }
.f-ring-l, .f-ring-r { background: var(--f-ring); }
.f-middle-l, .f-middle-r { background: var(--f-middle); }
.f-index-l, .f-index-r { background: var(--f-index); }
.f-thumb { background: var(--f-thumb); }

/* 자모 없는 기호 키 (좌우 균형용, 옅게 비활성) */
.vk-key.vk-sym {
    color: var(--color-text-stone);
    background: var(--color-canvas);
    opacity: 0.55;
}

/* 홈 키(F·J) 돌기 */
.vk-key.vk-home::after {
    content: '';
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 3px;
    border-radius: 2px;
    background: var(--color-text-mute);
}

/* 다음 칠 키 강조 */
.vk-key.vk-next {
    background: var(--color-primary) !important;
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    animation: vkpulse 0.9s ease-in-out infinite;
}

@keyframes vkpulse {
    0%, 100% { box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4); }
    50% { box-shadow: 0 5px 22px rgba(37, 99, 235, 0.7); }
}

.vk-key.vk-wrong {
    background: var(--color-error) !important;
    color: #fff;
}

/* ===== 타자게임: 낙하 ===== */
.hp-bubbles {
    width: 100%;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 0;
    background: var(--color-canvas);
    border-bottom: 1px solid var(--color-hairline);
}

.bubble {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--color-primary);
    transition: all 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.bubble.broken {
    background: var(--color-hairline);
    transform: scale(0.5);
}

#game-area {
    width: 100%;
    flex: 1 1 0;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

.word {
    position: absolute;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
    white-space: nowrap;
    padding: 0.4rem 1rem;
    border-radius: var(--radius-pill);
    background: var(--color-canvas);
    border: 2px solid var(--color-primary);
    box-shadow: var(--elevation-1);
    transform: translateX(-50%);
}

.word.matched {
    color: #fff;
    background: var(--color-secondary);
    border-color: var(--color-secondary);
    transform: translateX(-50%) scale(1.8);
    opacity: 0;
    transition: transform 0.3s ease-out, opacity 0.3s ease-out, background 0.1s;
}

/* ===== 게임 오버 ===== */
#game-over {
    overflow-y: auto;
}

#game-over h2.glow-text {
    margin-bottom: 1.25rem;
}

.game-over-content {
    width: 100%;
    max-width: 420px;
    margin-bottom: 1.5rem;
}

.final-stats {
    background: var(--color-canvas);
    border: 1px solid var(--color-hairline);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--elevation-1);
}

.final-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--color-hairline);
}

.final-stat-row:last-child {
    border-bottom: none;
}

.stat-label {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    font-weight: 500;
}

.stat-value {
    color: var(--color-primary);
    font-size: 1.3rem;
    font-weight: 800;
}

.gameover-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-content: center;
}

/* ===== 반응형 ===== */
@media (max-width: 640px) {
    h2.glow-text { font-size: 1.5rem; }

    .menu-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .menu-label {
        width: auto;
        text-align: left;
    }

    .seg {
        justify-content: center;
    }

    .pw-cur {
        font-size: 1.9rem;
        padding: 0.9rem 1.2rem;
        max-width: 80%;
    }

    .pw-side {
        font-size: 1rem;
    }

    .hud {
        padding: 0.6rem 1rem 0.6rem 5rem;
    }

    .hud-item div {
        font-size: 1.15rem;
    }

    .word {
        font-size: 1.25rem;
    }
}
