/* ==========================================
   ZType 스타일 타이핑 게임 CSS
   ========================================== */

/* 게임 컨테이너 */
#ztype-game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    z-index: 15000;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#ztype-game-container.active {
    display: flex;
}

/* 캔버스 */
#ztype-canvas {
    display: block;
    width: 480px;
    height: 720px;
    background: linear-gradient(180deg, #000428 0%, #004e92 100%);
    box-shadow: 0 0 30px #000;
}

/* 상단 우측 컨트롤 */
#ztype-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 6px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(0, 255, 255, 0.2);
    border-radius: 8px;
    z-index: 5;
    backdrop-filter: blur(4px);
}

.ztype-control-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.ztype-control-btn {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 1px solid rgba(0, 255, 255, 0.5);
    background: rgba(0, 0, 0, 0.5);
    color: #ccffff;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 0;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ztype-control-btn .material-icons {
    font-size: 16px;
    line-height: 1;
}

.ztype-control-close {
    border-color: rgba(255, 90, 90, 0.7);
    color: #ff9a9a;
    font-size: 14px;
    line-height: 1;
}

.ztype-control-btn.inactive {
    opacity: 0.45;
    border-color: rgba(255, 255, 255, 0.2);
    color: #cccccc;
}

.ztype-control-slider {
    gap: 4px;
    flex-direction: column;
    align-items: center;
}

.ztype-control-label {
    font-size: 10px;
    color: #9befff;
    min-width: 16px;
    text-align: center;
    opacity: 0.85;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ztype-control-label .material-icons {
    font-size: 14px;
    line-height: 1;
}

.ztype-control-value {
    font-size: 10px;
    color: #ccffff;
    min-width: 34px;
    text-align: center;
}

.ztype-lives-panel {
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.ztype-lives-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
}

.ztype-life-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 120, 120, 0.2);
    border: 1px solid rgba(255, 120, 120, 0.5);
    box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.4);
}

.ztype-life-dot.is-active {
    background: #ff6b6b;
    border-color: #ffb3b3;
    box-shadow: 0 0 6px rgba(255, 90, 90, 0.7);
}

#ztype-spawn-rate {
    width: 20px;
    height: 90px;
    accent-color: #00ffff;
    writing-mode: vertical-lr;
    direction: rtl;
}

/* 모바일 대응 */
@media (max-width: 820px), (max-height: 650px) {
    #ztype-canvas {
        width: 100vw;
        height: 75vh;
    }
}

/* 게임 UI 오버레이 - ✅ Canvas에 그리므로 숨김 */
#ztype-ui {
    display: none !important;
}

.ztype-stat {
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 20px;
    border-radius: 5px;
    border: 2px solid #00ffff;
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}

.ztype-stat-label {
    font-size: 12px;
    color: #00ffff;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.ztype-stat-value {
    font-size: 24px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 0 10px rgba(0, 255, 255, 0.8);
}

#ztype-lives .ztype-stat-value {
    color: #ff4444;
    text-shadow: 0 0 10px rgba(255, 68, 68, 0.8);
}

#ztype-combo .ztype-stat-value {
    color: #ffff00;
    text-shadow: 0 0 10px rgba(255, 255, 0, 0.8);
}

/* 입력 필드 컨테이너 */
#ztype-input-container {
    width: 100%;
    background: rgba(0, 0, 0, 0.9);
    padding: 15px 20px;
    border-top: 3px solid #00ffff;
    border-bottom: 2px solid #00ffff;
    box-shadow: 0 -5px 20px rgba(0, 255, 255, 0.3), 0 5px 20px rgba(0, 255, 255, 0.3);
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

#ztype-input-field {
    width: 90%;
    max-width: 400px;
    padding: 12px 20px;
    font-size: 20px;
    font-family: 'Courier New', 'Malgun Gothic', '맑은 고딕', monospace;
    font-weight: bold;
    text-align: center;
    background: rgba(0, 20, 40, 0.8);
    border: 2px solid #00ffff;
    border-radius: 8px;
    color: #52C41A;
    outline: none;
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.5), inset 0 0 10px rgba(0, 255, 255, 0.2);
    transition: all 0.3s ease;
}

#ztype-input-field:focus {
    border-color: #00ff88;
    box-shadow: 0 0 25px rgba(0, 255, 136, 0.8), inset 0 0 15px rgba(0, 255, 136, 0.3);
    color: #00ff88;
}

#ztype-input-field::placeholder {
    color: rgba(255, 255, 255, 0.3);
    font-style: italic;
}

/* 모바일 한글 조합 프리뷰 */
#ztype-composition-preview {
    display: none;
    width: 100%;
    min-height: 32px;
    padding: 6px 12px;
    box-sizing: border-box;
    background: transparent;
    color: #52C41A;
    font-size: 18px;
    font-weight: bold;
    font-family: 'Courier New', 'Malgun Gothic', '맑은 고딕', monospace;
    text-align: center;
    letter-spacing: 2px;
    border-top: 1px solid transparent;
    border-bottom: 1px solid transparent;
    opacity: 0;
    transition: opacity 0.12s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

#ztype-composition-preview.active {
    opacity: 1;
    background: rgba(0, 0, 0, 0.8);
    border-color: rgba(0, 255, 255, 0.35);
    pointer-events: auto;
}

#ztype-composition-text {
    flex: 1 1 auto;
    text-align: center;
    padding-left: 24px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#ztype-composition-clear {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    border: 1px solid rgba(0, 255, 255, 0.7);
    background: rgba(0, 0, 0, 0.6);
    color: #00ffff;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease, transform 0.12s ease;
}

#ztype-composition-clear.active {
    opacity: 1;
    pointer-events: auto;
}

#ztype-composition-clear:active {
    transform: scale(0.95);
}

/* 온스크린 키보드 컨테이너 */
#ztype-keyboard {
    width: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0.9) 100%), url('../media/background/keyboard-background.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    padding: 8px 6px;
    border-top: none;
    box-shadow: none;
    flex-shrink: 0;
    display: none; /* ✅ 기본적으로 숨김 */
}

/* 모바일에서만 키보드 표시 */
@media (max-width: 820px), (max-height: 650px) {
    #ztype-keyboard {
        display: block;
    }
}

/* 키보드 행 */
.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-bottom: 4px;
    width: 100%;
}

.keyboard-row:last-child {
    margin-bottom: 0;
}

/* 키보드 키 */
.keyboard-key {
    flex: 0 0 auto;
    min-width: 32px;
    padding: 0 6px;
    height: 42px;
    background: linear-gradient(180deg, #2a2a2a 0%, #1a1a1a 100%);
    border: 2px solid #444;
    border-radius: 5px;
    color: #fff;
    font-size: 15px;
    font-weight: bold;
    font-family: 'Courier New', 'Consolas', 'Monaco', 'Menlo', monospace;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    transition: all 0.1s ease;
    box-shadow: 0 3px 0 #000, 0 0 5px rgba(0, 255, 255, 0.2);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.keyboard-key:focus,
.keyboard-key:focus-visible {
    outline: none;
}

/* 백스페이스 키 (시각적 위계 완화) */
.keyboard-key[data-key="Backspace"] {
    min-width: 55px;
    border-color: #ff4444;
    font-size: 0.9em;
}

.keyboard-key[data-key="ToggleLang"] {
    min-width: 46px;
    border-color: #00aa88;
    font-size: 0.9em;
}

/* 키 눌림 효과 (JS에서 'active' 클래스 추가) - 반응형 transform */
.keyboard-key.active {
    transform: translateY(clamp(1px, 0.4vh, 3px));
    box-shadow: 0 0 0 #000, 0 0 15px rgba(0, 255, 255, 0.8);
    background: linear-gradient(180deg, #00ffff 0%, #00aaaa 100%);
    color: #000;
    border-color: #00ffff;
}

@media (hover: hover) and (pointer: fine) {
    .keyboard-key:hover {
        border-color: #00ffff;
        box-shadow: 0 3px 0 #000, 0 0 10px rgba(0, 255, 255, 0.5);
    }

    .keyboard-key[data-key="Backspace"]:hover {
        border-color: #ff6666;
        box-shadow: 0 3px 0 #000, 0 0 10px rgba(255, 68, 68, 0.5);
    }

    .keyboard-key[data-key="ToggleLang"]:hover {
        border-color: #00ffcc;
        box-shadow: 0 3px 0 #000, 0 0 10px rgba(0, 255, 204, 0.5);
    }
}

/* 모달 */
#ztype-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.95);
    border: 3px solid #00ffff;
    border-radius: 10px;
    padding: 40px;
    text-align: center;
    color: #fff;
    font-family: 'Courier New', 'Consolas', 'Monaco', 'Menlo', monospace;
    z-index: 10002;
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.5);
    min-width: 300px;
}

#ztype-modal.hidden {
    display: none;
}

#ztype-modal h2 {
    color: #00ffff;
    font-size: 32px;
    margin: 0 0 20px 0;
    text-transform: uppercase;
    letter-spacing: 3px;
    text-shadow: 0 0 20px rgba(0, 255, 255, 1);
}

#ztype-modal p {
    font-size: 18px;
    margin: 15px 0;
    color: #fff;
}

#ztype-modal .modal-score {
    font-size: 48px;
    color: #ffff00;
    font-weight: bold;
    margin: 20px 0;
    text-shadow: 0 0 20px rgba(255, 255, 0, 1);
}

#ztype-modal button {
    background: linear-gradient(180deg, #00ffff 0%, #00aaaa 100%);
    border: 2px solid #00ffff;
    border-radius: 5px;
    color: #000;
    font-size: 20px;
    font-weight: bold;
    font-family: 'Courier New', 'Consolas', 'Monaco', 'Menlo', monospace;
    padding: 15px 40px;
    margin: 20px 10px 0;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}

#ztype-modal button:hover {
    background: linear-gradient(180deg, #ffffff 0%, #00ffff 100%);
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.8);
    transform: scale(1.05);
}

#ztype-modal button:active {
    transform: scale(0.98);
}

/* 레벨업 알림 */
.level-up-notification {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    border: 3px solid #ffff00;
    border-radius: 10px;
    padding: 30px 60px;
    color: #ffff00;
    font-size: 36px;
    font-weight: bold;
    font-family: 'Courier New', 'Consolas', 'Monaco', 'Menlo', monospace;
    text-transform: uppercase;
    letter-spacing: 5px;
    z-index: 10003;
    pointer-events: none;
    animation: levelUpPulse 1s ease-in-out;
    text-shadow: 0 0 30px rgba(255, 255, 0, 1);
    box-shadow: 0 0 40px rgba(255, 255, 0, 0.8);
}

@keyframes levelUpPulse {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

/* 태블릿 최적화 */
@media (max-width: 1024px) {
    #ztype-ui {
        top: 15px;
        left: 15px;
        right: 15px;
    }

    .ztype-stat {
        padding: 8px 15px;
    }

    .ztype-stat-label {
        font-size: 11px;
    }

    .ztype-stat-value {
        font-size: 20px;
    }
}

/* 모바일 세로 모드 */
@media (max-width: 768px) {
    #ztype-ui {
        flex-direction: column;
        gap: 8px;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .ztype-stat {
        padding: 6px 12px;
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .ztype-stat-label {
        font-size: 10px;
        margin-bottom: 0;
    }

    .ztype-stat-value {
        font-size: 16px;
    }

    #ztype-keyboard {
        padding: 8px;
    }

    .keyboard-key {
        min-width: 28px;
        height: 38px;
        font-size: 13px;
    }

    .keyboard-key[data-key="Backspace"] {
        min-width: 48px;
    }

    #ztype-modal {
        width: 90%;
        padding: 30px 20px;
    }

    #ztype-modal h2 {
        font-size: 24px;
    }

    #ztype-modal p {
        font-size: 16px;
    }

    #ztype-modal .modal-score {
        font-size: 36px;
    }

    #ztype-modal button {
        font-size: 16px;
        padding: 12px 30px;
    }

    .level-up-notification {
        font-size: 24px;
        padding: 20px 40px;
    }
}

/* 작은 모바일 (iPhone SE 등) */
@media (max-width: 480px) {
    #ztype-keyboard {
        padding: 6px;
    }

    .keyboard-row {
        gap: 3px;
        margin-bottom: 3px;
    }

    .keyboard-key {
        min-width: 24px;
        padding: 0 4px;
        height: 34px;
        font-size: 12px;
    }

    .keyboard-key[data-key="Backspace"] {
        min-width: 42px;
    }

    .ztype-stat {
        padding: 5px 10px;
    }

    .ztype-stat-label {
        font-size: 9px;
    }

    .ztype-stat-value {
        font-size: 14px;
    }

    #ztype-modal h2 {
        font-size: 20px;
    }

    #ztype-modal p {
        font-size: 14px;
    }

    .level-up-notification {
        font-size: 20px;
        padding: 15px 30px;
    }
}

/* 매우 작은 화면 (갤럭시 폴드 등) */
@media (max-width: 380px) {
    .keyboard-key {
        min-width: 22px;
        padding: 0 3px;
        height: 30px;
        font-size: 11px;
    }

    .keyboard-key[data-key="Backspace"] {
        min-width: 38px;
    }

    .keyboard-row {
        gap: 2px;
        margin-bottom: 2px;
    }
}

/* 가로 모드 최적화 */
@media (max-height: 500px) and (orientation: landscape) {
    #ztype-ui {
        top: 5px;
        left: 10px;
        right: 10px;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .ztype-stat {
        padding: 4px 10px;
        flex: 0 0 auto;
    }

    .ztype-stat-label {
        font-size: 9px;
    }

    .ztype-stat-value {
        font-size: 14px;
    }

    #ztype-keyboard {
        padding: 5px;
    }

    .keyboard-key {
        height: 32px;
        min-width: 26px;
        font-size: 12px;
    }

    .keyboard-row {
        gap: 3px;
        margin-bottom: 2px;
    }

    #ztype-modal {
        padding: 20px;
    }

    #ztype-modal h2 {
        font-size: 20px;
        margin-bottom: 10px;
    }

    #ztype-modal p {
        font-size: 14px;
        margin: 8px 0;
    }

    #ztype-modal .modal-score {
        font-size: 28px;
        margin: 10px 0;
    }

    #ztype-modal button {
        font-size: 14px;
        padding: 10px 25px;
        margin: 10px 5px 0;
    }
}

/* 터치 디바이스 최적화 */
@media (hover: none) and (pointer: coarse) {
    .keyboard-key {
        cursor: default;
    }

    /* 터치 시 더 큰 터치 영역 제공 */
    .keyboard-key {
        min-height: 44px; /* iOS 권장 터치 영역 */
    }
}

/* 고해상도 디스플레이 최적화 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .ztype-stat {
        border-width: 1px;
    }

    #ztype-keyboard {
        border-top-width: 0;
    }

    .keyboard-key {
        border-width: 1px;
    }
}

/* 모바일 키보드 가시성/크기 개선 */
@media (max-width: 820px), (max-height: 650px) {
    #ztype-game-container {
        justify-content: flex-start;
        height: 100vh;
        height: 100dvh;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    #ztype-canvas {
        width: 100vw;
        height: calc(100vh - 30vh - 36px);
        height: calc(100dvh - 30dvh - 36px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        max-height: 70vh;
    }

    #ztype-input-container {
        display: none;
        height: 0;
        padding: 0;
        border: 0;
    }

    #ztype-composition-preview {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 36px;
        font-size: clamp(14px, 3.4vw, 18px);
        flex-shrink: 0;
        padding: 6px 10px;
    }

    #ztype-composition-clear {
        width: clamp(22px, 5vw, 28px);
        height: clamp(22px, 5vw, 28px);
        font-size: clamp(14px, 3vw, 18px);
    }

    #ztype-keyboard {
        display: flex;
        flex-direction: column;
        justify-content: center;
        height: 30vh;
        height: 30dvh;
        padding: 8px 6px 10px;
    }

    .keyboard-row {
        justify-content: space-between;
        gap: clamp(3px, 0.8vh, 6px);
        margin-bottom: clamp(3px, 0.8vh, 6px);
    }

    .keyboard-key {
        flex: 1 1 0;
        height: clamp(38px, 6vh, 54px);
        min-width: 0;
        font-size: clamp(12px, 3.2vw, 18px);
        border-radius: 8px;
    }

    .keyboard-key[data-key="Backspace"] {
        flex: 0.75 1 0;
        min-width: clamp(44px, 10vw, 72px);
    }

    .keyboard-key[data-key="ToggleLang"] {
        flex: 0.7 1 0;
        min-width: clamp(40px, 9vw, 66px);
    }
}
