@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;700;900&family=VT323&display=swap');

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

:root {
    --matrix-green: #00ff41;
    --matrix-dark-green: #008f11;
    --matrix-bg: #0d0208;
    --glow: 0 0 10px #00ff41, 0 0 20px #00ff41, 0 0 30px #00ff41;
}

body {
    font-family: 'VT323', 'Noto Sans KR', monospace;
    background: #000;
    color: var(--matrix-green);
    margin: 0;
    padding: 0;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
}

/* 16:9 Game Wrapper */
.game-wrapper {
    position: relative;
    width: 100vw;
    height: 56.25vw;
    max-height: 100vh;
    max-height: 100dvh;
    max-width: 177.78vh;
    background: transparent;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1;
}

/* Game Scaler - Fixed 1600x900 design */
.game-scaler {
    position: relative;
    width: 1600px;
    height: 900px;
    background: transparent;
    transform-origin: center center;
}

/* Matrix Rain Background (fullscreen) */
#matrix-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    opacity: 0.5;
}

/* Game Container */
.game-container {
    position: absolute;
    z-index: 1;
    width: 1200px;
    height: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 20px 40px;
    display: none;
    flex-direction: column;
}

.game-container.active {
    display: flex;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    margin-bottom: 10px;
}

.level-display, .points-display {
    font-size: 32px;
    text-shadow: var(--glow);
    letter-spacing: 3px;
    font-weight: bold;
}

.game-title {
    font-size: 36px;
    font-weight: 900;
    text-align: center;
    text-shadow: var(--glow);
    letter-spacing: 4px;
    animation: flicker 3s infinite;
}

@keyframes flicker {
    0%, 100% { opacity: 1; }
    92% { opacity: 1; }
    93% { opacity: 0.8; }
    94% { opacity: 1; }
    95% { opacity: 0.9; }
}

/* Control Buttons (positioned relative to wrapper, not scaler) */
.control-buttons {
    position: fixed;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    transform-origin: right center;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 300;
}

/* 팝업이 열렸을 때 컨트롤 버튼 숨기기 */
body:has(.info-overlay.show) .control-buttons,
body:has(.ranking-overlay.show) .control-buttons,
body:has(.modal-overlay.show) .control-buttons,
body:has(.confirm-overlay.show) .control-buttons,
body:has(.level-complete-overlay.show) .control-buttons,
body:has(.game-clear-overlay.show) .control-buttons {
    display: none;
}

.ctrl-btn {
    width: 50px;
    height: 50px;
    border: 2px solid var(--matrix-green);
    background: rgba(0, 0, 0, 0.8);
    color: var(--matrix-green);
    font-size: 20px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ctrl-btn:hover {
    background: var(--matrix-green);
    color: var(--matrix-bg);
    box-shadow: var(--glow);
}

.ctrl-btn.used {
    opacity: 0.3;
    pointer-events: none;
}

/* Question Area */
.question-area {
    text-align: center;
    margin: 5px 0 5px;
}

.progress-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.progress-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--matrix-green);
    background: transparent;
    transition: all 0.3s;
}

/* 미진행 상태 */
.progress-dot.pending {
    background: transparent;
    opacity: 0.4;
}

/* 진행중 상태 */
.progress-dot.current {
    background: var(--matrix-green);
    box-shadow: var(--glow);
    animation: currentPulse 1s infinite;
}

@keyframes currentPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* 완료 상태 */
.progress-dot.completed {
    background: var(--matrix-green);
    opacity: 1;
}

/* 패스 상태 */
.progress-dot.passed {
    background: #ff9900;
    border-color: #ff9900;
    opacity: 0.8;
}

/* 실패 상태 */
.progress-dot.failed {
    background: #ff0000;
    border-color: #ff0000;
    opacity: 0.8;
}

.question-text {
    font-size: 42px;
    margin-bottom: 15px;
    font-family: 'Noto Sans KR', sans-serif;
    font-weight: 700;
    line-height: 1.5;
    padding: 10px 20px;
}

/* Answer Boxes */
.answer-boxes {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.answer-box {
    width: 95px;
    height: 85px;
    border: 3px solid var(--matrix-green);
    background: rgba(0, 0, 0, 0.7);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    font-family: 'Noto Sans KR', sans-serif;
    font-weight: 700;
    color: var(--matrix-green);
    text-shadow: var(--glow);
    transition: all 0.3s;
}

.answer-box.filled {
    background: rgba(0, 255, 65, 0.15);
}

.answer-box.hint {
    color: #005a0a;
    font-size: 38px;
    text-shadow: none;
}

.answer-box.correct {
    background: rgba(0, 255, 65, 0.4);
    animation: correctFlash 0.5s;
}

.answer-box.wrong {
    border-color: #ff0000;
    background: rgba(255, 0, 0, 0.3);
    animation: shake 0.5s;
}

.answer-box.space-after {
    margin-right: 20px;
}

@keyframes correctFlash {
    0%, 100% { background: rgba(0, 255, 65, 0.4); }
    50% { background: rgba(0, 255, 65, 0.7); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

/* Hidden Input */
#hidden-input {
    position: absolute;
    left: -9999px;
    opacity: 0;
}

/* Stats Row */
.stats-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 80px;
    margin: 20px 0 0;
    padding: 0 10px;
    font-size: 22px;
}

.warning-text {
    position: fixed;
    left: 50%;
    bottom: 15%;
    transform: translateX(-50%);
    color: #ff4444;
    font-size: 28px;
    font-weight: bold;
    text-shadow: 0 0 20px #ff4444, 0 0 40px #ff4444;
    text-align: center;
    padding: 15px 30px;
    background: rgba(0, 0, 0, 0.85);
    border: 2px solid #ff4444;
    border-radius: 10px;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    pointer-events: none;
}

.warning-text.show {
    opacity: 1;
    visibility: visible;
    animation: warningPop 0.3s ease-out;
}

@keyframes warningPop {
    0% { transform: translateX(-50%) scale(0.8); }
    50% { transform: translateX(-50%) scale(1.1); }
    100% { transform: translateX(-50%) scale(1); }
}

/* Virtual Keyboard */
.keyboard {
    padding: 40px 0;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
}

.key {
    min-width: 95px;
    height: 85px;
    border: 2px solid var(--matrix-green);
    background: rgba(0, 0, 0, 0.7);
    color: var(--matrix-green);
    font-size: 40px;
    font-family: 'Noto Sans KR', sans-serif;
    font-weight: 700;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.key:hover {
    background: rgba(0, 255, 65, 0.2);
}

.key:active, .key.pressed {
    background: var(--matrix-green);
    color: var(--matrix-bg);
    transform: scale(0.95);
    box-shadow: var(--glow);
}

.key.special {
    min-width: 105px;
    font-size: 44px;
}

.key.wide {
    min-width: 160px;
    font-size: 28px;
    font-family: 'VT323', monospace;
}

.key.action-key {
    min-width: 80px;
    font-size: 22px;
    font-family: 'Noto Sans KR', sans-serif;
    color: #ffcc00;
    border-color: #ffcc00;
}

.key.action-key:hover {
    background: rgba(255, 204, 0, 0.2);
}

.key.action-key:active, .key.action-key.pressed {
    background: #ffcc00;
    color: var(--matrix-bg);
    box-shadow: 0 0 20px #ffcc00;
}

#hint-btn.used,
#pass-btn.disabled, #pass-btn-alt.disabled {
    opacity: 0.4;
    pointer-events: none;
    border-color: #666;
    color: #666;
}

/* Stats Display */
.stat-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.stat-label {
    opacity: 0.7;
}

.stat-value {
    text-shadow: var(--glow);
    font-weight: bold;
    font-size: 26px;
}

/* Timer Bar */
.timer-container {
    width: 100%;
    max-width: 500px;
    margin: 10px auto;
    height: 20px;
    min-height: 20px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
}

.timer-bar {
    height: 100%;
    min-height: 16px;
    background: linear-gradient(90deg, var(--matrix-dark-green), var(--matrix-green));
    width: 100%;
    transition: width 0.1s linear;
    box-shadow: var(--glow);
}

.timer-bar.warning {
    background: linear-gradient(90deg, #ff6600, #ff9900);
    box-shadow: 0 0 10px #ff9900, 0 0 20px #ff9900, 0 0 30px #ff9900;
}

.timer-bar.danger {
    background: linear-gradient(90deg, #cc0000, #ff0000);
    box-shadow: 0 0 10px #ff0000, 0 0 20px #ff0000, 0 0 30px #ff0000;
    animation: dangerPulse 0.5s infinite;
}

@keyframes dangerPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}


/* Result Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    z-index: 400;
    justify-content: center;
    align-items: center;
}

.modal-overlay.show, .confirm-overlay.show {
    display: flex;
}

.confirm-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    z-index: 400;
    justify-content: center;
    align-items: center;
}

.confirm-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
}

.modal-content {
    background: var(--matrix-bg);
    border: 3px solid var(--matrix-green);
    border-radius: 20px;
    padding: 50px;
    text-align: center;
    box-shadow: var(--glow);
    max-width: 500px;
    width: 90%;
    animation: modalPop 0.3s ease-out;
}

@keyframes modalPop {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.modal-title {
    font-size: 48px;
    margin-bottom: 20px;
    text-shadow: var(--glow);
}

.modal-message {
    font-size: 24px;
    margin-bottom: 15px;
    font-family: 'Noto Sans KR', sans-serif;
}

.modal-message strong {
    color: #fff;
    font-size: 28px;
}

.modal-score {
    font-size: 36px;
    margin: 30px 0;
    text-shadow: var(--glow);
}

.modal-btn {
    padding: 15px 40px;
    font-size: 24px;
    border: 2px solid var(--matrix-green);
    background: transparent;
    color: var(--matrix-green);
    cursor: pointer;
    border-radius: 10px;
    margin: 10px;
    transition: all 0.3s;
    font-family: 'VT323', monospace;
}

.modal-btn:hover {
    background: var(--matrix-green);
    color: var(--matrix-bg);
    box-shadow: var(--glow);
}

/* Info Overlay */
.info-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    z-index: 400;
    justify-content: center;
    align-items: center;
}

.info-overlay.show {
    display: flex;
}

/* Info Panel */
.info-panel {
    position: relative;
    background: var(--matrix-bg);
    border: 3px solid var(--matrix-green);
    border-radius: 20px;
    padding: 30px;
    max-width: 500px;
    width: 80%;
    max-height: 80%;
    display: flex;
    flex-direction: column;
    box-shadow: var(--glow);
    animation: modalPop 0.3s ease-out;
}

.info-content {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 10px;
}

.info-content::-webkit-scrollbar {
    width: 8px;
}

.info-content::-webkit-scrollbar-track {
    background: rgba(0, 255, 65, 0.1);
    border-radius: 4px;
}

.info-content::-webkit-scrollbar-thumb {
    background: var(--matrix-green);
    border-radius: 4px;
}

.info-content::-webkit-scrollbar-thumb:hover {
    background: var(--matrix-dark-green);
}

.info-panel h2 {
    font-size: 32px;
    margin-bottom: 25px;
    text-shadow: var(--glow);
}

.info-panel p {
    font-size: 18px;
    margin-bottom: 10px;
    line-height: 1.5;
    font-family: 'Noto Sans KR', sans-serif;
    text-align: left;
}

.info-section {
    margin-bottom: 18px;
    padding: 12px 15px;
    background: rgba(0, 255, 65, 0.05);
    border-radius: 10px;
    border-left: 3px solid var(--matrix-green);
}

.info-section h3 {
    font-size: 20px;
    margin-bottom: 10px;
    color: #ffcc00;
    text-shadow: 0 0 10px rgba(255, 204, 0, 0.5);
}

.info-section p {
    font-size: 16px;
    margin-bottom: 6px;
    padding-left: 5px;
}

.info-section p:last-child {
    margin-bottom: 0;
}

.info-panel .close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 30px;
    cursor: pointer;
    color: var(--matrix-green);
    transition: all 0.3s;
}

.info-panel .close-btn:hover {
    text-shadow: var(--glow);
}

.info-close-btn {
    display: block;
    margin: 20px auto 0;
    padding: 12px 40px;
}

/* Difficulty Selection */
.difficulty-panel {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--matrix-bg);
    border: 3px solid var(--matrix-green);
    border-radius: 20px;
    padding: 50px;
    z-index: 100;
    text-align: center;
    box-shadow: var(--glow);
}

.difficulty-panel.show {
    display: block;
}

.difficulty-panel h2 {
    font-size: 36px;
    margin-bottom: 35px;
    text-shadow: var(--glow);
}

.difficulty-btn {
    display: block;
    width: 100%;
    padding: 20px 70px;
    font-size: 28px;
    margin: 15px 0;
    border: 2px solid var(--matrix-green);
    background: transparent;
    color: var(--matrix-green);
    cursor: pointer;
    border-radius: 12px;
    transition: all 0.3s;
    font-family: 'VT323', monospace;
}

.difficulty-btn:hover {
    background: var(--matrix-green);
    color: var(--matrix-bg);
    box-shadow: var(--glow);
    transform: scale(1.02);
}


/* Score Popup Animation */
.score-popup {
    position: absolute;
    font-size: 60px;
    font-weight: bold;
    pointer-events: none;
    z-index: 50;
    animation: scoreFloat 1s ease-out forwards;
    font-family: 'VT323', monospace;
}

.score-popup.positive {
    color: var(--matrix-green);
    text-shadow: var(--glow);
}

.score-popup.negative {
    color: #ff0000;
    text-shadow: 0 0 10px #ff0000;
}

@keyframes scoreFloat {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-100px) scale(1.5);
    }
}

/* Penalty Indicator (next to potential score) */
.penalty-indicator {
    display: inline-block;
    margin-left: 10px;
    color: #ff4444;
    font-size: 26px;
    font-weight: bold;
    text-shadow: 0 0 10px #ff4444, 0 0 20px #ff4444;
    opacity: 0;
    pointer-events: none;
}

.penalty-indicator.show {
    animation: penaltyFlash 0.8s ease-out forwards;
}

@keyframes penaltyFlash {
    0% { 
        opacity: 0;
        transform: scale(0.5);
    }
    20% { 
        opacity: 1;
        transform: scale(1.3);
    }
    40% { 
        opacity: 1;
        transform: scale(1);
    }
    80% {
        opacity: 1;
        transform: scale(1);
    }
    100% { 
        opacity: 0;
        transform: scale(0.8);
    }
}

/* Start Screen */
.start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--matrix-bg);
    z-index: 200;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.start-screen.hidden {
    display: none;
}

.start-title {
    font-size: 64px;
    text-shadow: var(--glow);
    margin-bottom: 20px;
    animation: flicker 2s infinite;
    text-align: center;
}

.start-subtitle {
    font-size: 24px;
    margin-bottom: 50px;
    opacity: 0.8;
    font-family: 'Noto Sans KR', sans-serif;
}

.start-btn {
    padding: 25px 80px;
    font-size: 36px;
    border: 3px solid var(--matrix-green);
    background: transparent;
    color: var(--matrix-green);
    cursor: pointer;
    border-radius: 15px;
    transition: all 0.3s;
    font-family: 'VT323', monospace;
    animation: pulse 2s infinite;
}

.start-btn:hover {
    background: var(--matrix-green);
    color: var(--matrix-bg);
    box-shadow: var(--glow);
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}

/* Nickname Input Area */
.nickname-input-area {
    position: relative;
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}

.nickname-input {
    padding: 15px 60px 15px 25px;
    font-size: 24px;
    font-family: 'Noto Sans KR', sans-serif;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid var(--matrix-green);
    border-radius: 10px;
    color: var(--matrix-green);
    text-align: center;
    width: 320px;
    outline: none;
    transition: all 0.3s;
}

.nickname-input:focus {
    box-shadow: var(--glow);
    background: rgba(0, 255, 65, 0.1);
}

.nickname-input::placeholder {
    color: rgba(0, 255, 65, 0.4);
}

.random-nick-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 45px;
    height: 45px;
    font-size: 32px;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.random-nick-btn:hover {
    transform: translateY(-50%) rotate(180deg) scale(1.15);
    filter: drop-shadow(0 0 8px var(--matrix-green));
}

.nickname-hint {
    font-size: 16px;
    color: rgba(0, 255, 65, 0.5);
    margin-bottom: 30px;
    font-family: 'Noto Sans KR', sans-serif;
}

.ranking-btn {
    padding: 18px 50px;
    font-size: 24px;
    border: 2px solid #ffcc00;
    background: transparent;
    color: #ffcc00;
    cursor: pointer;
    border-radius: 12px;
    margin-top: 20px;
    transition: all 0.3s;
    font-family: 'VT323', monospace;
}

.ranking-btn:hover {
    background: #ffcc00;
    color: var(--matrix-bg);
    box-shadow: 0 0 20px #ffcc00;
}

/* Ranking Overlay */
.ranking-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    z-index: 400;
    justify-content: center;
    align-items: center;
}

.ranking-overlay.show {
    display: flex;
}

/* Ranking Panel */
.ranking-panel {
    position: relative;
    background: var(--matrix-bg);
    border: 3px solid var(--matrix-green);
    border-radius: 20px;
    padding: 30px;
    max-width: 600px;
    width: 90%;
    max-height: 80%;
    overflow-y: auto;
    box-shadow: var(--glow);
    animation: modalPop 0.3s ease-out;
}

.ranking-panel h2 {
    font-size: 32px;
    margin-bottom: 20px;
    text-shadow: var(--glow);
    text-align: center;
}

.ranking-panel .close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 30px;
    cursor: pointer;
    color: var(--matrix-green);
    transition: all 0.3s;
}

.ranking-panel .close-btn:hover {
    text-shadow: var(--glow);
}

.ranking-close-btn {
    display: block;
    margin: 20px auto 0;
    padding: 12px 40px;
}

.ranking-list {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 10px;
}

.ranking-list::-webkit-scrollbar {
    width: 8px;
}

.ranking-list::-webkit-scrollbar-track {
    background: rgba(0, 255, 65, 0.1);
    border-radius: 4px;
}

.ranking-list::-webkit-scrollbar-thumb {
    background: var(--matrix-green);
    border-radius: 4px;
}

.ranking-list::-webkit-scrollbar-thumb:hover {
    background: var(--matrix-dark-green);
}

/* My Record Box */
.ranking-my-record {
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(0, 255, 65, 0.1);
    border-radius: 10px;
    border: 1px solid var(--matrix-green);
}

.my-record-box {
    display: flex;
    justify-content: space-around;
    align-items: center;
    font-size: 20px;
}

.my-nick {
    color: #fff;
    font-weight: bold;
    font-size: 1.1em;
}

.my-rank {
    color: #ffcc00;
    font-weight: bold;
}

.my-score {
    color: var(--matrix-green);
}

.no-record {
    text-align: center;
    color: rgba(0, 255, 65, 0.5);
    font-size: 18px;
}

/* Ranking Table */
.ranking-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Noto Sans KR', sans-serif;
}

.ranking-table th,
.ranking-table td {
    padding: 12px 8px;
    text-align: center;
    border-bottom: 1px solid rgba(0, 255, 65, 0.3);
}

.ranking-table th {
    color: #ffcc00;
    font-size: 16px;
    font-weight: bold;
}

.ranking-table td {
    font-size: 18px;
}

.ranking-table tr.top-rank {
    background: rgba(255, 204, 0, 0.1);
}

.ranking-table tr.top-rank td {
    color: #fff;
    font-weight: bold;
}

.ranking-table tbody tr:hover {
    background: rgba(0, 255, 65, 0.15);
}

.no-rankings {
    text-align: center;
    color: rgba(0, 255, 65, 0.5);
    font-size: 20px;
    padding: 30px;
}

/* Rank Result in Modal */
.rank-result {
    font-size: 28px;
    color: #ffcc00;
    display: block;
    margin-top: 10px;
}

/* ===== Portrait Mode (세로모드) ===== */
@media (orientation: portrait) {
    /* 9:16 Game Wrapper for portrait */
    .game-wrapper {
        width: 56.25vh;
        height: 100vh;
        height: 100dvh;
        max-width: 100vw;
        max-height: 177.78vw;
    }
    
    /* Portrait scaler - 540x960 design */
    .game-scaler {
        width: 540px;
        height: 960px;
    }
    
    /* Control buttons at bottom horizontal */
    .control-buttons {
        position: fixed;
        right: auto;
        left: 50%;
        top: auto;
        bottom: 10px;
        transform: translateX(-50%);
        transform-origin: center bottom;
        flex-direction: row;
        gap: 15px;
    }
    
    .ctrl-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    
    /* Game Container adjustments */
    .game-container {
        width: 100%;
        padding: 15px 15px;
        justify-content: flex-start;
    }
    
    /* Header */
    .game-header {
        padding: 12px 0;
        margin-bottom: 8px;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .level-display, .points-display {
        font-size: 26px;
        letter-spacing: 2px;
    }
    
    .game-title {
        font-size: 28px;
        letter-spacing: 3px;
        width: 100%;
        order: -1;
        margin-bottom: 8px;
    }
    
    /* Question Area */
    .question-area {
        margin: 10px 0;
    }
    
    .progress-dots {
        gap: 8px;
        margin-bottom: 15px;
    }
    
    .progress-dot {
        width: 18px;
        height: 18px;
    }
    
    .question-text {
        font-size: 32px;
        margin-bottom: 15px;
        padding: 10px 15px;
        line-height: 1.5;
    }
    
    /* Answer boxes bigger */
    .answer-boxes {
        gap: 10px;
        margin-bottom: 20px;
    }
    
    .answer-box {
        width: 60px;
        height: 60px;
        font-size: 32px;
        border-width: 2px;
    }
    
    .answer-box.hint {
        font-size: 28px;
    }
    
    /* Stats row */
    .stats-row {
        gap: 40px;
        margin: 15px 0 0;
        font-size: 20px;
    }
    
    .stat-value {
        font-size: 24px;
    }
    
    /* Timer */
    .timer-container {
        max-width: 350px;
        height: 18px;
        min-height: 18px;
        margin: 12px auto;
    }
    
    .timer-bar {
        min-height: 16px;
    }
    
    /* Keyboard much smaller */
    .keyboard {
        padding: 10px 0 55px;
    }
    
    .keyboard-row {
        gap: 3px;
        margin-bottom: 3px;
    }
    
    .key {
        min-width: 36px;
        height: 40px;
        font-size: 20px;
        border-width: 1px;
        border-radius: 5px;
    }
    
    .key.special {
        min-width: 40px;
        font-size: 22px;
    }
    
    .key.wide {
        min-width: 58px;
        font-size: 14px;
    }
    
    .key.action-key {
        min-width: 36px;
        font-size: 12px;
        padding: 0 2px;
    }
    
    /* Start screen bigger */
    .start-title {
        font-size: 44px;
        margin-bottom: 20px;
    }
    
    .start-subtitle {
        font-size: 22px;
        margin-bottom: 40px;
    }
    
    .start-btn {
        padding: 22px 60px;
        font-size: 30px;
    }
    
    /* Modals bigger */
    .modal-content {
        padding: 35px;
        max-width: 90%;
    }
    
    .modal-title {
        font-size: 38px;
    }
    
    .modal-message {
        font-size: 22px;
    }
    
    .modal-score {
        font-size: 30px;
        margin: 25px 0;
    }
    
    .modal-btn {
        padding: 15px 35px;
        font-size: 24px;
    }
    
    /* Info panel */
    .info-panel {
        width: 90%;
        max-width: none;
        max-height: 85%;
        padding: 25px;
    }
    
    .info-panel h2 {
        font-size: 28px;
        margin-bottom: 20px;
    }
    
    .info-panel p {
        font-size: 14px;
        margin-bottom: 8px;
    }
    
    .info-content {
        max-height: 50vh;
    }
    
    .info-section {
        margin-bottom: 14px;
        padding: 10px 12px;
    }
    
    .info-section h3 {
        font-size: 16px;
        margin-bottom: 8px;
    }
    
    .info-section p {
        font-size: 14px;
        margin-bottom: 5px;
    }
    
    /* Warning text */
    .warning-text {
        font-size: 24px;
        padding: 12px 25px;
    }
    
    /* Score popup */
    .score-popup {
        font-size: 50px;
    }
    
    /* Nickname Input */
    .nickname-input-area {
        margin-bottom: 8px;
    }
    
    .nickname-input {
        padding: 12px 50px 12px 18px;
        font-size: 18px;
        width: 260px;
    }
    
    .random-nick-btn {
        right: 8px;
        width: 38px;
        height: 38px;
        font-size: 26px;
    }
    
    .nickname-hint {
        font-size: 14px;
        margin-bottom: 25px;
    }
    
    .ranking-btn {
        padding: 14px 35px;
        font-size: 20px;
        margin-top: 15px;
    }
    
    /* Ranking Panel */
    .ranking-panel {
        padding: 20px;
        max-width: 95%;
        max-height: 85%;
    }
    
    .ranking-panel h2 {
        font-size: 26px;
        margin-bottom: 15px;
    }
    
    .ranking-table th,
    .ranking-table td {
        padding: 10px 5px;
        font-size: 14px;
    }
    
    .my-record-box {
        font-size: 16px;
        flex-direction: column;
        gap: 8px;
    }
    
    .rank-result {
        font-size: 22px;
    }
}

/* ===== 정사각형 모드 (mode-square) ===== */
/* 화면 비율이 0.8~1.25 사이일 때 (시스템 키보드 올라온 상태 포함) */

/* 기본: keyboard-actions 숨김 */
.keyboard-actions {
    display: none;
}

/* 정사각형 모드 - UI 키보드 숨기고 중앙 정렬 */
body.mode-square .keyboard {
    display: none !important;
}

/* 정사각형 모드 - 하단 컨트롤 버튼 */
body.mode-square .control-buttons {
    position: fixed;
    right: auto;
    left: 50%;
    top: auto;
    bottom: 10px;
    transform: translateX(-50%);
    flex-direction: row;
    gap: 12px;
}

body.mode-square .ctrl-btn {
    width: 36px;
    height: 36px;
    font-size: 14px;
}

body.mode-square {
    align-items: flex-start;
}

body.mode-square .game-wrapper {
    width: var(--viewport-width, 100vw);
    height: var(--viewport-height, 100vh);
    max-width: none;
    max-height: none;
    align-items: flex-start;
}

body.mode-square .game-scaler {
    width: 540px;
    height: 540px;
}

body.mode-square .game-container {
    width: 100%;
    padding: 15px;
    justify-content: flex-start;
    height: 100%;
}

/* 헤더 - 한 줄로 */
body.mode-square .game-header {
    padding: 8px 0;
    margin-bottom: 8px;
    flex-wrap: nowrap;
    justify-content: space-between;
}

body.mode-square .game-title {
    font-size: 24px;
    letter-spacing: 2px;
    width: auto;
    order: 0;
    margin-bottom: 0;
}

body.mode-square .level-display,
body.mode-square .points-display {
    font-size: 20px;
    letter-spacing: 1px;
}

/* 진행 상태 */
body.mode-square .progress-dots {
    gap: 6px;
    margin-bottom: 12px;
}

body.mode-square .progress-dot {
    width: 14px;
    height: 14px;
}

/* 질문 텍스트 */
body.mode-square .question-text {
    font-size: 30px;
    margin-bottom: 15px;
    padding: 8px 12px;
    line-height: 1.4;
}

/* 정답 박스 */
body.mode-square .answer-boxes {
    gap: 10px;
    margin-bottom: 15px;
}

body.mode-square .answer-box {
    width: 55px;
    height: 55px;
    font-size: 28px;
}

body.mode-square .answer-box.hint {
    font-size: 24px;
}

/* 타이머 */
body.mode-square .timer-container {
    max-width: 320px;
    height: 14px;
    min-height: 14px;
    margin: 10px auto;
}

/* Stats row */
body.mode-square .stats-row {
    gap: 35px;
    margin: 12px 0 0;
    font-size: 18px;
}

body.mode-square .stat-value {
    font-size: 20px;
}

/* 정사각형 모드에서 힌트/패스 버튼 표시 */
body.mode-square .keyboard-actions {
    display: flex !important;
    justify-content: center;
    gap: 15px;
    margin-top: 15px;
}

body.mode-square .keyboard-actions .action-btn {
    padding: 12px 30px;
    font-size: 16px;
    border: 2px solid #ffcc00;
    background: transparent;
    color: #ffcc00;
    cursor: pointer;
    border-radius: 10px;
    font-family: 'Noto Sans KR', sans-serif;
    transition: all 0.3s;
}

body.mode-square .keyboard-actions .action-btn:hover,
body.mode-square .keyboard-actions .action-btn:active {
    background: rgba(255, 204, 0, 0.2);
}

body.mode-square .keyboard-actions .action-btn.used {
    opacity: 0.4;
    pointer-events: none;
    border-color: #666;
    color: #666;
}

body.mode-square .question-area {
    margin: 8px 0;
}

/* ===== 정사각형 모드 - 시작 화면 ===== */
body.mode-square .start-screen {
    padding: 20px;
    justify-content: flex-start;
    padding-top: 40px;
}

body.mode-square .start-title {
    font-size: 38px;
    margin-bottom: 15px;
}

body.mode-square .start-subtitle {
    font-size: 18px;
    margin-bottom: 25px;
}

body.mode-square .nickname-input-area {
    margin-bottom: 8px;
}

body.mode-square .nickname-input {
    padding: 12px 45px 12px 18px;
    font-size: 18px;
    width: 240px;
}

body.mode-square .random-nick-btn {
    right: 8px;
    width: 35px;
    height: 35px;
    font-size: 22px;
}

body.mode-square .nickname-hint {
    font-size: 13px;
    margin-bottom: 20px;
}

body.mode-square .start-btn {
    padding: 18px 50px;
    font-size: 26px;
}

body.mode-square .ranking-btn {
    padding: 12px 30px;
    font-size: 18px;
    margin-top: 15px;
}

/* ===== 정사각형 모드 - 모달/패널 ===== */
body.mode-square .modal-content {
    padding: 25px;
    max-width: 90%;
}

body.mode-square .modal-title {
    font-size: 32px;
    margin-bottom: 15px;
}

body.mode-square .modal-message {
    font-size: 18px;
}

body.mode-square .modal-score {
    font-size: 26px;
    margin: 20px 0;
}

body.mode-square .modal-btn {
    padding: 12px 30px;
    font-size: 20px;
}

body.mode-square .ranking-panel {
    padding: 20px;
    max-width: 95%;
    max-height: 90%;
}

body.mode-square .ranking-panel h2 {
    font-size: 24px;
    margin-bottom: 15px;
}

body.mode-square .info-panel {
    width: 90%;
    max-height: 90%;
    padding: 20px;
}

body.mode-square .info-panel h2 {
    font-size: 24px;
    margin-bottom: 15px;
}

body.mode-square .info-panel p {
    font-size: 13px;
    margin-bottom: 6px;
}

body.mode-square .info-content {
    max-height: 45vh;
}

body.mode-square .info-section {
    margin-bottom: 12px;
    padding: 8px 10px;
}

body.mode-square .info-section h3 {
    font-size: 15px;
    margin-bottom: 6px;
}

body.mode-square .info-section p {
    font-size: 13px;
    margin-bottom: 4px;
}

/* ===== Countdown Overlay ===== */
.countdown-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.98);
    z-index: 250;
    justify-content: center;
    align-items: center;
}

.countdown-overlay.show {
    display: flex;
}

.countdown-number {
    font-size: 200px;
    font-weight: 900;
    color: var(--matrix-green);
    text-shadow: 0 0 10px var(--matrix-green), 0 0 20px rgba(0, 255, 65, 0.5);
    animation: countdownPop 0.8s ease-out;
    font-family: 'VT323', monospace;
}

@keyframes countdownPop {
    0% {
        transform: scale(2);
        opacity: 0;
    }
    30% {
        transform: scale(0.9);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 포트레잇 모드 카운트다운 */
@media (orientation: portrait) {
    .countdown-number {
        font-size: 140px;
    }
}

/* 정사각형 모드 카운트다운 */
body.mode-square .countdown-number {
    font-size: 120px;
}

/* ===== Level Complete Modal ===== */
.level-complete-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.98);
    z-index: 400;
    justify-content: center;
    align-items: center;
}

.level-complete-overlay.show {
    display: flex;
}

.level-complete-title {
    font-size: 42px;
    color: #ffcc00;
    text-shadow: 0 0 20px #ffcc00, 0 0 40px #ffcc00;
    margin-bottom: 30px;
}

.level-stats {
    background: rgba(0, 255, 65, 0.08);
    border: 2px solid var(--matrix-green);
    border-radius: 15px;
    padding: 25px 35px;
    margin-bottom: 30px;
}

.level-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    font-size: 24px;
    font-family: 'Noto Sans KR', sans-serif;
    border-bottom: 1px solid rgba(0, 255, 65, 0.2);
}

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

.level-stat-row.bonus {
    color: #ffcc00;
}

.level-stat-row.bonus span:last-child {
    text-shadow: 0 0 10px #ffcc00;
    animation: bonusPulse 1s infinite;
}

@keyframes bonusPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.level-stat-row.total {
    font-size: 28px;
    font-weight: bold;
    padding-top: 18px;
    margin-top: 8px;
    border-top: 2px solid var(--matrix-green);
}

.level-stat-row.total span:last-child {
    color: #fff;
    text-shadow: var(--glow);
}

/* 포트레잇 모드 레벨 완료 */
@media (orientation: portrait) {
    .level-complete-title {
        font-size: 34px;
    }
    
    .level-stats {
        padding: 20px 25px;
    }
    
    .level-stat-row {
        font-size: 20px;
        padding: 10px 0;
    }
    
    .level-stat-row.total {
        font-size: 24px;
    }
}

/* 정사각형 모드 레벨 완료 */
body.mode-square .level-complete-title {
    font-size: 30px;
    margin-bottom: 20px;
}

body.mode-square .level-stats {
    padding: 18px 22px;
    margin-bottom: 20px;
}

body.mode-square .level-stat-row {
    font-size: 18px;
    padding: 8px 0;
}

body.mode-square .level-stat-row.total {
    font-size: 22px;
}

/* ===== Game Clear Modal (전체 클리어) ===== */
.game-clear-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.98);
    z-index: 500;
    justify-content: center;
    align-items: center;
}

.game-clear-overlay.show {
    display: flex;
}

#confetti-canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 1;
}

.game-clear-modal {
    position: relative;
    z-index: 2;
    max-width: 520px;
    animation: clearModalPop 0.6s ease-out;
}

@keyframes clearModalPop {
    0% { transform: scale(0.3) rotate(-10deg); opacity: 0; }
    50% { transform: scale(1.1) rotate(2deg); }
    70% { transform: scale(0.95) rotate(-1deg); }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.clear-badge {
    font-size: 32px;
    margin-bottom: 15px;
    animation: badgeBounce 1s infinite;
}

@keyframes badgeBounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

.clear-title {
    color: #ffcc00 !important;
    text-shadow: 0 0 20px #ffcc00, 0 0 40px #ffcc00 !important;
    font-size: 52px !important;
    margin-bottom: 10px !important;
}

.game-clear-modal .modal-message {
    font-size: 22px;
    color: #fff;
    margin-bottom: 25px;
}

.clear-stats {
    background: rgba(0, 255, 65, 0.08);
    border: 2px solid var(--matrix-green);
    border-radius: 15px;
    padding: 20px 30px;
    margin-bottom: 20px;
}

.clear-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    font-size: 22px;
    font-family: 'Noto Sans KR', sans-serif;
    border-bottom: 1px solid rgba(0, 255, 65, 0.2);
}

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

.clear-stat-row.final-score {
    font-size: 28px;
    font-weight: bold;
    padding-top: 18px;
    margin-top: 8px;
    border-top: 2px solid var(--matrix-green);
    border-bottom: none;
}

.clear-stat-row.final-score span:last-child {
    color: #ffcc00;
    text-shadow: 0 0 15px #ffcc00, 0 0 30px #ffcc00;
    animation: scoreGlow 1.5s infinite alternate;
}

@keyframes scoreGlow {
    0% { text-shadow: 0 0 15px #ffcc00, 0 0 30px #ffcc00; }
    100% { text-shadow: 0 0 25px #ffcc00, 0 0 50px #ffcc00, 0 0 70px #ff9900; }
}

.clear-rank-box {
    background: linear-gradient(135deg, rgba(255, 204, 0, 0.2), rgba(255, 153, 0, 0.2));
    border: 2px solid #ffcc00;
    border-radius: 15px;
    padding: 20px 30px;
    margin-bottom: 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 0 20px rgba(255, 204, 0, 0.3);
}

.clear-rank-label {
    font-size: 24px;
    font-family: 'Noto Sans KR', sans-serif;
    color: #ffcc00;
}

.clear-rank-value {
    font-size: 42px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 0 10px #ffcc00;
    animation: rankPulse 1s infinite;
}

@keyframes rankPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

#clear-restart-btn {
    font-size: 28px;
    padding: 18px 50px;
    background: linear-gradient(135deg, var(--matrix-dark-green), var(--matrix-green));
    border: none;
    color: var(--matrix-bg);
    font-weight: bold;
    box-shadow: var(--glow);
}

#clear-restart-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px var(--matrix-green), 0 0 50px var(--matrix-green);
}

/* 포트레잇 모드 게임 클리어 */
@media (orientation: portrait) {
    .game-clear-modal {
        max-width: 95%;
        padding: 30px;
    }
    
    .clear-badge {
        font-size: 26px;
    }
    
    .clear-title {
        font-size: 40px !important;
    }
    
    .game-clear-modal .modal-message {
        font-size: 18px;
        margin-bottom: 20px;
    }
    
    .clear-stats {
        padding: 15px 20px;
    }
    
    .clear-stat-row {
        font-size: 18px;
        padding: 10px 0;
    }
    
    .clear-stat-row.final-score {
        font-size: 24px;
    }
    
    .clear-rank-box {
        padding: 15px 20px;
    }
    
    .clear-rank-label {
        font-size: 20px;
    }
    
    .clear-rank-value {
        font-size: 34px;
    }
    
    #clear-restart-btn {
        font-size: 24px;
        padding: 15px 40px;
    }
    
    #confetti-canvas {
        width: 400px;
        height: 600px;
    }
}

/* 정사각형 모드 게임 클리어 */
body.mode-square .game-clear-modal {
    max-width: 90%;
    padding: 25px;
}

body.mode-square .clear-badge {
    font-size: 22px;
    margin-bottom: 10px;
}

body.mode-square .clear-title {
    font-size: 34px !important;
    margin-bottom: 8px !important;
}

body.mode-square .game-clear-modal .modal-message {
    font-size: 16px;
    margin-bottom: 15px;
}

body.mode-square .clear-stats {
    padding: 12px 18px;
    margin-bottom: 15px;
}

body.mode-square .clear-stat-row {
    font-size: 16px;
    padding: 8px 0;
}

body.mode-square .clear-stat-row.final-score {
    font-size: 20px;
}

body.mode-square .clear-rank-box {
    padding: 12px 18px;
    margin-bottom: 18px;
}

body.mode-square .clear-rank-label {
    font-size: 18px;
}

body.mode-square .clear-rank-value {
    font-size: 30px;
}

body.mode-square #clear-restart-btn {
    font-size: 20px;
    padding: 12px 35px;
}

body.mode-square #confetti-canvas {
    width: 350px;
    height: 450px;
}

/* 문제 출제 신청 모달 */
.submit-gag-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
}

.submit-gag-overlay.active {
    display: flex;
}

.submit-gag-modal {
    max-width: 450px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.submit-gag-modal .modal-title {
    font-size: 24px;
    margin-bottom: 10px;
}

.submit-desc {
    color: #aaa;
    font-size: 14px;
    margin-bottom: 20px;
    text-align: center;
}

.submit-field {
    margin-bottom: 15px;
}

.submit-field label {
    display: block;
    color: var(--matrix-green);
    font-size: 14px;
    margin-bottom: 5px;
}

.submit-field label .required {
    color: #ff6b6b;
}

.submit-field input {
    width: 100%;
    padding: 12px 15px;
    background: rgba(0, 255, 65, 0.1);
    border: 1px solid var(--matrix-dark-green);
    border-radius: 8px;
    color: #fff;
    font-size: 16px;
    font-family: 'Noto Sans KR', sans-serif;
}

.submit-field input:focus {
    outline: none;
    border-color: var(--matrix-green);
    box-shadow: 0 0 10px rgba(0, 255, 65, 0.3);
}

.submit-field input::placeholder {
    color: #666;
}

.submit-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.submit-buttons .modal-btn {
    flex: 1;
}

.submit-cancel-btn {
    background: rgba(100, 100, 100, 0.3) !important;
    border-color: #666 !important;
}

.submit-cancel-btn:hover {
    background: rgba(100, 100, 100, 0.5) !important;
}

.submit-confirm-btn {
    background: linear-gradient(135deg, #00ff41 0%, #008f11 100%) !important;
    color: #000 !important;
    font-weight: bold;
}

.submit-confirm-btn:hover {
    box-shadow: 0 0 20px rgba(0, 255, 65, 0.5);
}

.submit-result {
    margin-top: 20px;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.submit-result.success {
    background: rgba(0, 255, 65, 0.2);
    border: 1px solid var(--matrix-green);
    color: var(--matrix-green);
}

.submit-result.error {
    background: rgba(255, 100, 100, 0.2);
    border: 1px solid #ff6b6b;
    color: #ff6b6b;
}

