* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: linear-gradient(145deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Microsoft YaHei', 'Noto Sans KR', 'Segoe UI', 'Malgun Gothic', sans-serif;
    touch-action: pan-x pan-y;
}

.game-container {
    width: 100%;
    max-width: 500px;
    height: 700px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 40px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.screen {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    transition: opacity 0.3s ease;
    opacity: 0;
    visibility: hidden;
    overflow-y: hidden;
    overflow-x: hidden;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

.background-layer {
    position: absolute;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    transition: background-image 0.5s ease;
    z-index: -1;
}

/* ========== 선택 화면 ========== */
.select-header {
    text-align: center;
    padding: 20px 15px;
    background: rgba(0, 0, 0, 0.7);
    color: gold;
    border-bottom: 2px solid rgba(255, 215, 0, 0.3);
}

.select-header h1 {
    font-size: 1.3rem;
    letter-spacing: 2px;
}

.select-header p {
    font-size: 0.7rem;
    color: #ddd;
    margin-top: 5px;
}

.character-selector {
    display: flex;
    flex-direction: column;
    padding: 15px;
    gap: 10px;
    height: calc(100% - 80px);
    overflow-y: auto;
}

.select-area {
    background: rgba(0, 0, 0, 0.75);
    border-radius: 20px;
    padding: 15px;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 215, 0, 0.3);
}

.select-area h2 {
    color: #ffd966;
    font-size: 1rem;
    margin-bottom: 10px;
    border-left: 3px solid gold;
    padding-left: 10px;
}

.char-list {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 15px;
    max-height: 120px;
    overflow-y: auto;
    padding: 5px;
}

.char-list::-webkit-scrollbar {
    width: 4px;
}

.char-list::-webkit-scrollbar-track {
    background: #2c2c3e;
    border-radius: 10px;
}

.char-list::-webkit-scrollbar-thumb {
    background: gold;
    border-radius: 10px;
}

.char-card {
    background: #2c2c3e;
    border-radius: 12px;
    padding: 8px 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    min-width: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.char-card:hover {
    transform: scale(1.02);
    background: #3a3a55;
}

.char-card.selected {
    border-color: gold;
    background: #3d3d5e;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.char-card img {
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.5);
}

.char-card .char-name {
    font-weight: bold;
    color: white;
    font-size: 0.8rem;
}

.char-card .char-stats {
    font-size: 0.6rem;
    color: #aaa;
}

.preview-area {
    text-align: center;
    margin-top: 10px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 12px;
}

.preview-area img {
    border-radius: 12px;
    background: #1a1a2e;
}

.preview-area span {
    color: #ffd966;
    font-size: 0.7rem;
    display: block;
    margin-top: 5px;
}

.weapon-select, .horse-select {
    margin-top: 12px;
    display: flex;
    gap: 10px;
    align-items: center;
    color: white;
    font-size: 0.85rem;
}

select {
    background: #1e1e2a;
    color: white;
    padding: 8px 12px;
    border-radius: 25px;
    border: 1px solid gold;
    cursor: pointer;
    font-size: 0.8rem;
    flex: 1;
}

select:focus {
    outline: none;
    border-color: #ff8c00;
    box-shadow: 0 0 5px rgba(255, 140, 0, 0.5);
}

.vs-area {
    text-align: center;
    padding: 10px;
}

.vs-text {
    font-size: 2rem;
    font-weight: bold;
    color: crimson;
    text-shadow: 2px 2px 4px black;
    display: inline-block;
    animation: pulse 1s ease infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.start-btn {
    background: linear-gradient(45deg, #d4af37, #ff8c00);
    border: none;
    padding: 14px 30px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 40px;
    margin-top: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    color: #1a1a2e;
}

.start-btn:active {
    transform: scale(0.96);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ========== 게임 화면 ========== */
.stats-container {
    display: flex;
    gap: 10px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
}

.stat-bar {
    flex: 1;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 16px;
    padding: 8px 10px;
    color: white;
    border: 1px solid rgba(255, 215, 0, 0.3);
}

.char-name {
    font-weight: bold;
    font-size: 1rem;
    margin-bottom: 6px;
    text-align: center;
    color: #ffd966;
}

.stat-row {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.7rem;
    margin: 5px 0;
}

.bar-bg {
    flex: 1;
    background: #2c2c3e;
    height: 10px;
    border-radius: 10px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    width: 100%;
    transition: width 0.2s ease;
}

.player-stats .bar-fill {
    background: linear-gradient(90deg, #e74c3c, #c0392b);
}

.enemy-stats .bar-fill {
    background: linear-gradient(90deg, #3498db, #2980b9);
}

.small-stats {
    display: flex;
    justify-content: space-around;
    gap: 8px;
    font-size: 0.6rem;
    margin-top: 8px;
    color: #ccc;
}

.action-log {
    background: rgba(0, 0, 0, 0.75);
    border-radius: 20px;
    margin: 10px;
    padding: 10px;
    backdrop-filter: blur(4px);
    position: absolute;
    top: 150px;
    left: 10px;
    right: 10px;
    z-index: 10;
}

.log-messages {
    height: 70px;
    overflow-y: auto;
    font-size: 0.7rem;
    color: #ffd966;
    margin-bottom: 5px;
    padding: 5px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
}

.log-messages div {
    padding: 2px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.log-messages::-webkit-scrollbar {
    width: 3px;
}

.log-messages::-webkit-scrollbar-track {
    background: #2c2c3e;
    border-radius: 10px;
}

.log-messages::-webkit-scrollbar-thumb {
    background: gold;
    border-radius: 10px;
}

.arena {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    position: absolute;
    bottom: 180px;
    left: 0;
    right: 0;
    height: 260px;
    padding: 20px 30px;
}

.character-area {
    width: 45%;
    text-align: center;
    transition: transform 0.3s ease;
}

.character-sprite img {
    width: 130px;
    height: 130px;
    object-fit: contain;
    transition: all 0.1s ease;
    display: block;
    margin: 0 auto;
}

.enemy-sprite img {
    transform: scaleX(-1);
}

.horse-icon {
    font-size: 1.8rem;
    margin-top: -10px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

/* ========== v3.0 필살기 이펙트 ========== */
.arrow-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 15;
}

.arrow {
    position: absolute;
    width: 50px;
    height: 50px;
    background: url('images/arrow.png') no-repeat center;
    background-size: contain;
    pointer-events: none;
    animation: arrowRain 1s ease-out forwards;
}

@keyframes arrowRain {
    0% {
        opacity: 1;
        transform: translate(0, 0) rotate(130deg);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx, 100px), var(--ty, 200px)) rotate(180deg);
    }
}

/* ========== v3.0 필살기 이펙트 - 2초 이상 화려하게 ========== */

.special-effect-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

/* 1. 화면 번쩍임 - 2초 (점멸 효과 추가) */
.screen-flash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    pointer-events: none;
    z-index: 200;
    animation: screenFlash 2s ease-out forwards;
}

@keyframes screenFlash {
    0% { opacity: 0.9; }
    10% { opacity: 0.3; }
    20% { opacity: 0.8; }
    30% { opacity: 0.2; }
    40% { opacity: 0.7; }
    50% { opacity: 0.1; }
    100% { opacity: 0; }
}

/* 2. 천둥번개 - 2초 (반복 번개 효과) */
.thunder-effect {
    position: absolute;
    width: 100%;/* 100% */
    height: 100%;/* 100% */
    top: 0;
    left: 0;
    background-size: cover;
    background-position: center;
    pointer-events: none;
    animation: thunderFlash 2s ease-out forwards;
}

@keyframes thunderFlash {
    0% { opacity: 0; filter: brightness(1); }
    10% { opacity: 1; filter: brightness(2.5); }
    20% { opacity: 0.3; filter: brightness(1); }
    30% { opacity: 1; filter: brightness(2); }
    45% { opacity: 0.5; filter: brightness(1.5); }
    60% { opacity: 1; filter: brightness(2.2); }
    75% { opacity: 0.3; filter: brightness(1); }
    85% { opacity: 0.8; filter: brightness(1.8); }
    100% { opacity: 0; filter: brightness(1); }
}

/* 3. 분열 파티클 - 2초 (더 멀리, 더 느리게) */
.special-slice {
    position: absolute;
    width: 60px;
    height: 60px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    pointer-events: none;
    animation: sliceFly 2s ease-out forwards;
}

@keyframes sliceFly {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1) rotate(0deg);
    }
    30% {
        opacity: 1;
        transform: translate(calc(var(--tx, 200px) * 0.5), calc(var(--ty, -200px) * 0.5)) scale(0.8) rotate(120deg);
    }
    60% {
        opacity: 0.7;
        transform: translate(calc(var(--tx, 200px) * 0.8), calc(var(--ty, -200px) * 0.8)) scale(0.6) rotate(240deg);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx, 200px), var(--ty, -200px)) scale(0.3) rotate(360deg);
    }
}

/* 4. 캐릭터 확대 애니메이션 - 1초 (잔류 효과) */
.character-sprite img.special-scale {
    animation: specialScale 1s ease-in-out forwards;
}

@keyframes specialScale {
    0% { transform: scale(1); filter: drop-shadow(0 0 0 gold); }
    30% { transform: scale(1.6); filter: drop-shadow(0 0 20px gold); }
    60% { transform: scale(1.3); filter: drop-shadow(0 0 10px orange); }
    100% { transform: scale(1); filter: drop-shadow(0 0 0 gold); }
}

/* 5. 추가: 잔상 효과 (선택 사항) */
.special-afterimage {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: radial-gradient(circle, rgba(255,215,0,0.3) 0%, rgba(255,0,0,0) 70%);
    pointer-events: none;
    animation: afterimageFade 2s ease-out forwards;
    z-index: 95;
}

@keyframes afterimageFade {
    0% { opacity: 0; }
    20% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 0; }
}

/* 캐릭터 확대 애니메이션 */
.character-sprite img.special-scale {
    animation: specialScale 0.3s ease-in-out forwards;
}

@keyframes specialScale {
    0% { transform: scale(1); }
    50% { transform: scale(1.5); }
    100% { transform: scale(1); }
}

.action-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 30px);
    max-width: 470px;
    background: transparent;
    z-index: 100;
}

.action-btn {
    background: linear-gradient(135deg, #2c2c3e, #1e1e2a);
    border: 1px solid rgba(255, 215, 0, 0.3);
    color: white;
    padding: 10px 5px;
    border-radius: 30px;
    font-weight: bold;
    font-size: 0.75rem;
    transition: all 0.08s linear;
    cursor: pointer;
    text-align: center;
}

.action-btn:active {
    transform: scale(0.94);
    background: linear-gradient(135deg, #d4af37, #ff8c00);
    color: #1a1a2e;
    border-color: gold;
}

.touch-guide {
    text-align: center;
    font-size: 0.6rem;
    color: rgba(255, 255, 255, 0.5);
    padding: 6px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 20px;
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 30px);
    max-width: 470px;
    z-index: 100;
}

/* 애니메이션 효과 */
.shake-animation {
    animation: shake 0.15s ease-in-out 0s 3;
}

@keyframes shake {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    25% { transform: translateX(-6px) rotate(-3deg); }
    75% { transform: translateX(6px) rotate(3deg); }
}

.hit-animation {
    animation: hitFlash 0.25s ease-out;
}

@keyframes hitFlash {
    0% { filter: brightness(1) drop-shadow(0 0 0 red); transform: translateX(0); }
    30% { filter: brightness(1.8) drop-shadow(0 0 8px red); transform: translateX(-4px); }
    60% { filter: brightness(1.8); transform: translateX(4px); }
    100% { filter: brightness(1); transform: translateX(0); }
}

.special-animation {
    animation: specialGlow 0.4s ease-out;
}

@keyframes specialGlow {
    0% { filter: drop-shadow(0 0 0 gold); transform: scale(1); }
    50% { filter: drop-shadow(0 0 20px gold) brightness(1.4); transform: scale(1.1); }
    100% { filter: drop-shadow(0 0 0 gold); transform: scale(1); }
}

/* 결과 화면 */
.result-box {
    background: rgba(0, 0, 0, 0.9);
    margin: 30% 20px;
    padding: 30px 20px;
    border-radius: 40px;
    text-align: center;
    backdrop-filter: blur(8px);
    border: 2px solid rgba(255, 215, 0, 0.5);
    animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.result-box h2 {
    font-size: 2rem;
    margin-bottom: 20px;
    color: gold;
}

.result-box p {
    color: #ddd;
    margin-bottom: 25px;
}

.result-box button {
    margin: 8px;
    padding: 12px 20px;
    background: linear-gradient(45deg, #d4af37, #ff8c00);
    border: none;
    border-radius: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.result-box button:active {
    transform: scale(0.96);
}

/* 반응형 */
@media (max-width: 480px) {
    .game-container {
        height: 100vh;
        max-width: 100%;
        border-radius: 0;
    }
    
    .character-sprite img {
        width: 100px;
        height: 100px;
    }
    
    .arena {
        bottom: 170px;
        padding: 15px 20px;
        height: 220px;
    }
    
    .action-log {
        top: 100px;
    }
    
    .action-buttons {
        bottom: 75px;
        gap: 6px;
    }
    
    .action-btn {
        font-size: 0.65rem;
        padding: 8px 3px;
    }
    
    .touch-guide {
        bottom: 28px;
        font-size: 0.55rem;
    }
    
    .arrow {
        width: 20px;
        height: 20px;
    }
    
    .special-slice {
        width: 40px;
        height: 40px;
    }
}

@media (max-width: 380px) {
    .arena {
        bottom: 160px;
        height: 200px;
    }
    
    .action-log {
        top: 95px;
    }
    
    .log-messages {
        height: 55px;
    }
    
    .action-buttons {
        bottom: 70px;
        gap: 5px;
    }
    
    .action-btn {
        font-size: 0.6rem;
        padding: 6px 2px;
    }
    
    .character-sprite img {
        width: 85px;
        height: 85px;
    }
    
    .horse-icon {
        font-size: 1.4rem;
    }
    
    .touch-guide {
        bottom: 25px;
    }
    
    .arrow {
        width: 18px;
        height: 18px;
    }
    
    .special-slice {
        width: 30px;
        height: 30px;
    }
}