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

/* 로고 텍스트 중앙 정렬 */
.logo-char,
.logo-box {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
}

/* 아이템 버튼 포커스 테두리 제거 */
.item-btn:focus,
.item-btn:active,
button:focus,
button:active,
.practice-choice-btn:focus,
.practice-choice-btn:active {
    outline: none !important;
}

/* 선택지 버튼 기본 스타일 통일 */
.practice-choice-btn {
    border: 3px solid rgba(255, 255, 255, 0.2) !important;
}

.practice-choice-btn:hover {
    border-color: #3b82f6 !important;
}

body {
    font-family: 'Segoe UI', 'Nanum Square', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f7ff; /* 기본 배경은 연한 파랑 */
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100); /* ✅ iOS vh 보정 */
    color: #1e293b;
    line-height: 1.5;
    overflow-x: hidden;
}

/* --- Design Tokens (디자인수정.html 기반) --- */
:root {
    --primary-bg: linear-gradient(to bottom right, #22d3ee, #60a5fa, #a855f7); /* cyan-400 to purple-500 */
    --bubble-card-shadow: 0 15px 0 0 rgba(0, 0, 0, 0.05);
    --btn-shadow: 0 6px 0 0 rgba(0, 0, 0, 0.2);
    --yellow-game: #fbbf24;
    --pink-game: #ec4899;
    --purple-game: #a855f7;
    --blue-game: #3b82f6;
    --vh: 1vh; /* 모바일 뷰포트 높이 */
}

/* 모바일 모드 */
body.mobile-mode {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
    overscroll-behavior-y: contain;
}

body.mobile-mode input,
body.mobile-mode textarea,
body.mobile-mode select {
    -webkit-user-select: text;
    user-select: text;
}

/* 모달 내부 콘텐츠도 스크롤 가능 */
.mobile-mode #practice-questions-modal,
.mobile-mode #student-ranking-modal,
.mobile-mode #achievements-modal,
.mobile-mode #shop-modal,
.mobile-mode #team-modal {
    touch-action: pan-y !important;
}

/* --- Layout Containers --- */
.container {
    max-width: 1200px;
    width: 100%;
    margin: 2vh auto;
    padding: 0 2vw;
    box-sizing: border-box;
}

/* --- Bubble Card Style --- */
.game-section {
    background: white;
    border-radius: 2.5rem; /* 40px */
    border: 4px solid white;
    box-shadow: var(--bubble-card-shadow);
    padding: 40px;
    margin-bottom: 30px;
    position: relative;
    overflow: hidden;
}

/* --- Header Design --- */
header {
    text-align: center;
    margin-bottom: 40px;
    position: relative;
}

/* 홈 버튼 */
.home-button {
    position: fixed;
    top: 20px;
    left: 20px;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #74b9ff, #0984e3);
    border: 3px solid white;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(9, 132, 227, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 9999;
    text-decoration: none;
}

.home-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(9, 132, 227, 0.5);
}

.home-button:active {
    transform: scale(0.95);
}

.home-button svg {
    width: 28px;
    height: 28px;
    fill: white;
}

/* 모바일 홈 버튼 */
@media (max-width: 768px) {
    .home-button {
        width: 45px;
        height: 45px;
        top: 15px;
        left: 15px;
    }
    
    .home-button svg {
        width: 24px;
        height: 24px;
    }
}

header h1 {
    font-size: 3.5rem;
    font-weight: 900;
    color: #1e3a8a;
    letter-spacing: -0.05em;
    text-shadow: 0 4px 0 rgba(0,0,0,0.05);
}

/* --- Button Styles --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 32px;
    border: none;
    border-radius: 1.25rem; /* 20px */
    font-size: 1.2rem;
    font-weight: 900;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--btn-shadow);
    text-decoration: none;
    user-select: none;
}

.btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-primary {
    background-color: var(--yellow-game);
    color: #78350f; /* amber-900 */
}

.btn-primary:hover {
    background-color: #fbcf33;
}

.btn-secondary {
    background-color: var(--purple-game);
    color: white;
}

.btn-secondary:hover {
    background-color: #bc6ef9;
}

.btn-pink {
    background-color: var(--pink-game);
    color: white;
}

.btn-pink:hover {
    background-color: #f472b6;
}

/* --- Form Styles --- */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: 900;
    color: #1e3a8a;
}

input[type="text"], 
input[type="password"],
input[type="number"],
select {
    width: 100%;
    padding: 18px;
    border: 4px solid #f1f5f9; /* blue-50 */
    border-radius: 1.25rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: #000000;
    outline: none;
    transition: border-color 0.2s;
    background: #f8fafc;
}

input:focus, select:focus {
    border-color: var(--yellow-game);
    background: white;
}

option {
    color: #000000;
}

/* --- Login Area Specific --- */
#login-area {
    max-width: 600px;
    margin: 100px auto;
    background: white;
    background-image: radial-gradient(circle at 90% 10%, #fef3c7 0%, transparent 40%);
}

#login-area h2 {
    font-size: 2.5rem;
    font-weight: 900;
    text-align: center;
    color: #1e3a8a;
    margin-bottom: 30px;
}

/* --- Monitoring / Grid View --- */
#students-circle-view, #game-setup-students-circle-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 12px;
    background: #f1f5f9;
    padding: 24px;
    border-radius: 2rem;
    border: 4px solid #f1f5f9;
}

.circle-student {
    aspect-ratio: 1;
    background: white;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    border: 2px solid transparent;
    transition: all 0.2s;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.circle-student.online {
    border-color: #fbef33;
    transform: scale(1.1);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.circle-student.offline {
    opacity: 0.3;
    filter: grayscale(1);
}

/* --- Battle Mode (Dark Theme) --- */
#practice-questions-modal {
    background-color: #111827 !important; /* gray-900 */
    overflow-y: scroll !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100); /* ✅ iOS vh 보정 */
    display: flex;
    flex-direction: column;
}

/* 문제 영역이 전체 스크롤을 담당 */
#practice-question-area {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* 스크롤바 스타일 - 데스크탑 */
#practice-question-area::-webkit-scrollbar {
    width: 12px;
}

#practice-question-area::-webkit-scrollbar-track {
    background: rgba(17, 24, 39, 0.8);
}

#practice-question-area::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 6px;
}

#practice-question-area::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

.battle-header-pill {
    background: rgba(31, 41, 55, 0.8); /* gray-800/80 */
    padding: 12px 24px;
    border-radius: 9999px;
    border: 2px solid #374151;
    display: flex;
    align-items: center;
    gap: 16px;
}

#practice-question-text {
    font-size: 6rem !important;
    font-weight: 900;
    font-style: italic;
    letter-spacing: -0.05em;
    background: linear-gradient(to bottom, #ffffff, #d1d5db);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 10px 0 rgba(59, 130, 246, 0.3));
    margin: 0 0 30px 0 !important;
}

#play-pronunciation-btn {
    display: flex;
    align-items: center;
    justify-content: center;
}

#play-pronunciation-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.5);
}

#play-pronunciation-btn:active {
    transform: scale(0.95);
}

#practice-choices {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px !important;
}

.practice-choice-btn {
    padding: 32px !important;
    background: rgba(31, 41, 55, 0.5) !important;
    border: 4px solid #374151 !important;
    border-radius: 2rem !important;
    font-size: 2rem !important;
    font-weight: 900;
    color: #ffffff !important;
    transition: all 0.2s !important;
    position: relative;
    overflow: hidden;
}

.practice-choice-btn:hover {
    background: #3b82f6 !important;
    border-color: white !important;
    color: #ffffff !important;
    transform: translateY(-4px);
}

.practice-choice-btn::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.05);
}

/* --- Ranking & Results --- */
.ranking-item {
    background: white;
    border-radius: 1.5rem;
    padding: 16px;
    border: 4px solid #f1f5f9;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all 0.2s;
}

.ranking-item.top3 {
    background: #fffdf0;
    border-color: #fef3c7;
}

.rank-badge {
    width: 48px;
    height: 48px;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 1.25rem;
}

.rank-1 { background: #fbbf24; color: white; }
.rank-2 { background: #d1d5db; color: white; }
.rank-3 { background: #fb923c; color: white; }

/* --- Animations --- */
@keyframes wiggle {
    0%, 100% { transform: rotate(-1deg); }
    50% { transform: rotate(1deg); }
}
.animate-wiggle { animation: wiggle 0.2s infinite; }

@keyframes bounce-custom {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}
.animate-bounce-game { animation: bounce-custom 1s infinite ease-in-out; }

/* --- Urgent Mode --- */
.timer-urgent {
    color: #ef4444 !important;
    transform: scale(1.25);
    transition: transform 0.2s;
}

.timer-bar-urgent {
    background: #ef4444 !important;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.8);
}

/* --- Bonus Mission --- */
.bonus-mission-card {
    background: linear-gradient(to right, #ec4899, #a855f7) !important;
    border-radius: 1.5rem !important;
    padding: 20px !important;
    box-shadow: 0 10px 20px rgba(236, 72, 153, 0.3) !important;
    animation: pulse 2s infinite !important;
}

/* --- Badges --- */
.growth-badge {
    background: rgba(255, 255, 255, 0.2) !important;
    border: 2px solid white !important;
    padding: 8px 16px !important;
    border-radius: 1rem !important;
    font-weight: 900 !important;
}


/* 아이템 버튼 호버 효과 */
.item-btn:hover {
    transform: scale(1.1) !important;
}

.item-btn:hover .item-text {
    opacity: 1 !important;
}

.item-btn:active {
    transform: scale(0.95) !important;
}

/* --- Responsive Design --- */

/* 태블릿 (769px ~ 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 95%;
        padding: 0 3vw;
        margin: 3vh auto;
    }
    
    header h1 {
        font-size: clamp(2rem, 4vw, 2.5rem);
    }
    
    .btn {
        padding: clamp(12px, 2vw, 14px) clamp(24px, 4vw, 28px);
        font-size: clamp(1rem, 2vw, 1.1rem);
    }
    
    .game-section {
        padding: clamp(25px, 3vw, 30px);
        margin-bottom: clamp(20px, 3vh, 25px);
    }
    
    input[type="text"],
    input[type="password"],
    input[type="number"],
    select {
        padding: clamp(12px, 2vw, 14px);
        font-size: clamp(0.95rem, 1.5vw, 1rem);
    }
}

/* 모바일 (max-width: 768px) */
@media (max-width: 768px) {
    /* 기본 레이아웃 - 가독성 최적화 */
    body {
        font-size: 14px; /* 7px → 14px: 가독성 확보 */
        overflow-x: hidden;
    }
    
    .container {
        max-width: 100%;
        margin: 5px auto;
        padding: 0 5px;
    }
    
    /* 게임 섹션 */
    .game-section {
        border-radius: 0.75rem;
        padding: 10px 7.5px;
        margin-bottom: 7.5px;
    }
    
    /* 헤더 */
    header h1 {
        font-size: 1.2rem; /* 16.8px - 제목으로 적절한 크기 */
        margin-bottom: 5px;
    }
    
    /* 로그인 영역 */
    #login-area {
        margin: 10px auto;
        padding: 12.5px 10px;
        max-width: 95%;
    }
    
    #login-area h2 {
        font-size: 1rem; /* 14px - 읽기 좋은 크기 */
        margin-bottom: 10px;
    }
    
    /* 버튼 */
    .btn {
        padding: 8px 14px; /* 터치하기 좋은 크기로 증가 */
        font-size: 0.857rem; /* 12px - 버튼 텍스트 최소 크기 */
        border-radius: 0.5rem;
    }
    
    /* 입력 필드 */
    input[type="text"], 
    input[type="password"],
    input[type="number"],
    select {
        padding: 10px; /* 터치 영역 확대 */
        font-size: 0.857rem; /* 12px - 입력 텍스트 읽기 좋음 */
        border-radius: 0.5rem;
        border-width: 1.5px;
    }
    
    .form-group {
        margin-bottom: 7.5px;
    }
    
    /* 배틀 모드 */
    #practice-question-text {
        font-size: 1.714rem !important; /* 24px - 문제 텍스트는 크게 */
        margin: 0 0 15px 0 !important;
    }
    
    #practice-choices {
        grid-template-columns: 1fr !important;
        gap: 12px !important; /* 터치 여유 확보 */
        margin-top: 0 !important;
        height: auto !important; /* 콘텐츠에 맞춰 높이 자동 조정 */
        min-height: auto !important;
    }
    
    .practice-choice-btn {
        padding: 14px !important; /* 터치 영역 확대 */
        font-size: 1rem !important; /* 14px - 선택지 읽기 좋음 */
        border-radius: 0.75rem !important;
    }
    
    .battle-header-pill {
        padding: 6px 12px; /* 헤더 여유 확보 */
        gap: 8px;
        font-size: 0.714rem; /* 10px - 헤더 정보 읽기 가능 */
    }
    
    /* 모달 - 스크롤 최적화 */
    #practice-questions-modal {
        overflow-y: auto !important; /* hidden → auto: 콘텐츠 넘칠 때 스크롤 */
        overflow-x: hidden !important;
        min-height: 100vh !important; /* height → min-height: 콘텐츠가 길면 늘어남 */
        min-height: calc(var(--vh, 1vh) * 100) !important; /* ✅ iOS vh 보정 */
        min-height: calc(var(--vh, 1vh) * 100) !important;
        max-height: none !important; /* 높이 제한 제거 */
        position: fixed !important;
        top: 0;
        left: 0;
        width: 100vw;
        display: flex !important;
        flex-direction: column !important;
    }
    
    /* 문제 영역이 스크롤 담당 - 스크롤 최적화 */
    #practice-question-area {
        overflow-y: scroll !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain;
        flex: none !important; /* flex: 1 제거 - 콘텐츠 높이 제한 해제 */
        height: auto !important; /* 콘텐츠에 맞춰 늘어남 */
        min-height: calc(var(--vh, 1vh) * 80) !important; /* 최소 높이 확보 */
        padding-bottom: 120px !important; /* 충분한 하단 여백 */
    }
    
    /* 모바일 스크롤바 항상 표시 */
    #practice-question-area {
        scrollbar-width: thin !important;
        scrollbar-color: rgba(255, 255, 255, 0.4) rgba(17, 24, 39, 0.5) !important;
    }
    
    #practice-question-area::-webkit-scrollbar {
        width: 10px !important;
        display: block !important;
        -webkit-appearance: none !important;
    }

    #practice-question-area::-webkit-scrollbar-track {
        background: rgba(17, 24, 39, 0.8) !important;
        border-radius: 0 !important;
    }

    #practice-question-area::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.5) !important;
        border-radius: 5px !important;
        border: 2px solid rgba(17, 24, 39, 0.8) !important;
    }

    #practice-question-area::-webkit-scrollbar-thumb:active {
        background: rgba(255, 255, 255, 0.7) !important;
    }
    
    #practice-questions-modal > div:first-child,
    #student-ranking-modal > div,
    #achievements-modal > div,
    #levelup-modal > div,
    #shop-modal > div,
    #team-modal > div {
        max-width: 95% !important;
        width: 95% !important;
        max-height: none !important;
        padding: 10px !important;
        margin: 5px auto !important;
    }
    
    /* 모든 모달 스크롤 가능하게 */
    #student-ranking-modal,
    #achievements-modal,
    #levelup-modal,
    #shop-modal,
    #team-modal {
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain;
    }
    
    /* 랭킹 아이템 */
    .ranking-item {
        padding: 10px;
        gap: 8px;
        border-radius: 0.5rem;
        flex-wrap: wrap;
    }
    
    .rank-badge {
        width: 28px; /* 터치 영역 확대 */
        height: 28px;
        font-size: 0.714rem; /* 10px - 읽기 가능 */
    }
    
    /* 학생 서클 뷰 */
    #students-circle-view, 
    #game-setup-students-circle-view {
        grid-template-columns: repeat(auto-fill, minmax(32px, 1fr)); /* 터치 영역 확대 */
        gap: 6px;
        padding: 10px;
        border-radius: 0.75rem;
    }
    
    .circle-student {
        font-size: 0.857rem; /* 12px - 학생 번호 읽기 좋음 */
    }
    
    /* 게임 설정 영역 */
    #game-settings-area > div {
        padding: 10px 7.5px !important;
    }
    
    /* 그리드 레이아웃 1열로 */
    [style*="grid-template-columns: repeat(2"] {
        grid-template-columns: 1fr !important;
    }
    
    [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    
    /* 텍스트 크기 조정 */
    h1 { font-size: 1.2rem !important; } /* 16.8px */
    h2 { font-size: 1rem !important; } /* 14px */
    h3 { font-size: 0.857rem !important; } /* 12px */
    
    /* 닫기 버튼 - 44px 터치 영역 */
    [id$="-modal-btn"] {
        width: 44px !important; /* 터치 영역 확대 */
        height: 44px !important;
        font-size: 1.5rem !important; /* X 표시 크게 */
        top: 8px !important;
        right: 8px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* 콤보 카운터 - 1/2 크기로 축소 */
    #combo-counter {
        top: 80px !important;
        right: 15px !important;
        pointer-events: none;
    }
    
    #combo-counter > div {
        width: 40px !important; /* 모바일: 데스크톱 30px의 약 1.3배 */
        height: 40px !important;
        padding: 5px 8px !important;
        border-radius: 8px !important;
        border: 2px solid white !important;
    }
    
    #combo-counter div[style*="font-size: 9px"] {
        font-size: 12px !important; /* 🔥 아이콘 */
    }
    
    #combo-counter-number {
        font-size: 11px !important; /* 콤보 숫자 */
    }
    
    #combo-counter div[style*="font-size: 4px"] {
        font-size: 6px !important; /* COMBO 텍스트 */
    }
    
    /* 타이머 텍스트 1/4 크기 */
    #practice-question-timer-text {
        font-size: 0.625rem !important; /* 원래 2.5rem의 1/4 */
    }
    
    /* 보너스 미션 카드 */
    #bonus-mission-card {
        top: 40px !important;
        left: 10px !important;
        padding: 8px 12px !important;
        font-size: 0.714rem !important; /* 10px - 읽기 가능 */
        pointer-events: none;
    }
    
    /* 스크롤 영역 확보 */
    #practice-questions-modal .practice-choice-btn {
        touch-action: manipulation;
    }
    
    /* 아이템 사용 버튼 */
    #item-buttons-container {
        gap: 8px !important;
        margin-bottom: 12px !important;
    }
    
    .item-btn {
        width: 44px !important; /* 터치 영역 확대 */
        height: 44px !important;
        padding: 8px !important;
    }
    
    .item-btn .item-icon {
        font-size: 1.4rem !important; /* 아이콘 크게 */
    }
    
    .item-btn .item-text {
        font-size: 0.714rem !important; /* 10px - 읽기 가능 */
        top: 46px !important;
        padding: 6px 10px !important;
    }
    
    /* 업적 카드 */
    .achievement-card {
        padding: 12px !important;
        font-size: 0.857rem !important; /* 12px - 읽기 가능 */
    }
    
    /* 상점 아이템 */
    .shop-item-card {
        padding: 12px !important;
    }
    
    /* 상점 버튼들 */
    .purchase-btn {
        padding: 8px !important;
        font-size: 0.857rem !important;
    }
    
    /* 팀 카드 */
    .team-card {
        padding: 12px !important;
    }
    
    /* 대기 화면 */
    #student-waiting-area {
        padding: 20px 12px !important;
    }
    
    #student-waiting-area h2 {
        font-size: 1.143rem !important; /* 16px - 제목 크게 */
    }
    
    #student-waiting-area p {
        font-size: 0.857rem !important; /* 12px - 읽기 가능 */
    }
    
    /* 경험치 바 */
    [style*="level-display"] {
        font-size: 0.857rem !important; /* 12px */
    }
    
    /* 로딩 화면 */
    #loading-rabbit {
        font-size: 3rem !important; /* 토끼 크게 */
    }
    
    #loading-message {
        font-size: 1rem !important; /* 14px - 메시지 읽기 좋음 */
    }
    
    #loading-submessage {
        font-size: 0.857rem !important; /* 12px */
    }
    
    /* ✅ 4단계: 터치 영역 44px 확보 (애플/구글 가이드라인) */
    button, 
    a, 
    .clickable,
    input[type="button"],
    input[type="submit"],
    .btn,
    select,
    .practice-choice-btn,
    .item-btn {
        min-height: 44px !important; /* 애플/구글 가이드라인 */
        min-width: 44px !important;
        touch-action: manipulation; /* 더블탭 줌 방지 */
    }
    
    /* 입력창도 터치 편의성 확보 */
    input[type="text"],
    input[type="password"],
    input[type="number"],
    textarea {
        min-height: 44px !important;
        padding: 12px !important; /* 충분한 패딩 */
        font-size: 16px !important; /* iOS 자동 줌 방지 */
    }
    
    /* 가로 스크롤 방지 */
    * {
        max-width: 100%;
    }
}

/* 작은 모바일 (360px 이하) */
@media (max-width: 360px) {
    body {
        font-size: 13px; /* 가독성 유지 */
    }
    
    header h1 {
        font-size: 1.077rem; /* 14px */
    }
    
    #practice-question-text {
        font-size: 1.538rem !important; /* 20px - 작은 화면에서도 읽기 좋음 */
    }
    
    .practice-choice-btn {
        padding: 12px !important;
        font-size: 0.923rem !important; /* 12px */
    }
    
    .btn {
        padding: 7px 12px;
        font-size: 0.846rem; /* 11px */
    }
}

/* 가로 모드 대응 */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        font-size: 13px; /* 가로 모드에서도 가독성 유지 */
    }
    
    .container {
        margin: 4px auto;
    }
    
    #practice-questions-modal > div:first-child {
        max-height: 98vh !important;
        overflow-y: auto;
    }
    
    header h1 {
        font-size: 1.077rem; /* 14px */
    }
}

/* 아주 작은 화면 (iPhone SE 등, 320px 이하) */
@media (max-width: 320px) {
    body {
        font-size: 12px; /* 최소 가독성 확보 */
    }
    
    .btn {
        padding: 6px 10px;
        font-size: 0.833rem; /* 10px */
    }
    
    #practice-question-text {
        font-size: 1.5rem !important; /* 18px */
    }
    
    .practice-choice-btn {
        padding: 10px !important;
        font-size: 0.917rem !important; /* 11px */
    }
}

/* 터치 디바이스 최적화 */
@media (hover: none) and (pointer: coarse) {
    button, .btn, a {
        min-height: 40px; /* 터치 영역 확대 */
        min-width: 40px;
    }
    
    .practice-choice-btn {
        min-height: 48px !important; /* 선택지는 더 크게 */
    }
}

/* 프린트 숨김 */
@media print {
    #practice-questions-modal,
    #student-ranking-modal,
    #achievements-modal,
    #shop-modal,
    #team-modal,
    #loading-overlay {
        display: none !important;
    }
}

/* --- Notification Animations --- */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
}

/* 로딩 화면 애니메이션 */
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-20px);
    }
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

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

/* 업적 팝업 애니메이션 */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes sparkle {
    0%, 100% {
        opacity: 0;
        transform: scale(0.5) rotate(0deg);
    }
    50% {
        opacity: 1;
        transform: scale(1) rotate(180deg);
    }
}

/* 업적 카드 호버 효과 */
.achievement-card {
    transition: all 0.3s ease;
    cursor: pointer;
}

.achievement-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.15) !important;
}

/* 업적 탭 스타일 */
.achievements-tab.active {
    background: white !important;
    color: #667eea !important;
    border-bottom: 3px solid #667eea !important;
}

/* 프로그레스 바 */
.achievement-progress {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.achievement-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    transition: width 0.5s ease;
    border-radius: 4px;
}

/* 경험치 획득 애니메이션 (단계 2.2.3) */
@keyframes expBounce {
    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: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* 레벨업 애니메이션 (단계 2.2.4) */
@keyframes levelupBounce {
    0% {
        transform: scale(0.3);
        opacity: 0;
    }
    50% {
        transform: scale(1.05);
        opacity: 1;
    }
    70% {
        transform: scale(0.95);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes sparkle {
    0%, 100% {
        opacity: 0.3;
        transform: scale(0.8) rotate(0deg);
    }
    50% {
        opacity: 1;
        transform: scale(1.2) rotate(180deg);
    }
}

.sparkle-star {
    animation: sparkle 1.5s infinite;
}

/* 콤보 애니메이션 (단계 2.3.1) */
@keyframes comboBounce {
    0% {
        transform: scale(0.5) rotate(-10deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.15) rotate(5deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

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

.combo-active {
    animation: comboPulse 0.6s ease-in-out infinite;
}

/* 
    ���� �ǵ�� �ִϸ��̼� (�ܰ� 1.2.1)
    */

/* ���� ���� �� �޽� ȿ�� */
@keyframes correctPulse {
    0%, 100% {
        background-color: #22c55e;
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    }
    50% {
        background-color: #16a34a;
        transform: scale(1.05);
        box-shadow: 0 0 20px 10px rgba(34, 197, 94, 0.4);
    }
}

/* ���� ���� �� ��鸲 ȿ�� */
@keyframes wrongShake {
    0%, 100% {
        transform: translateX(0);
        background-color: #ef4444;
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-10px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(10px);
    }
}

/* Ÿ�̸� ��� ������ */
@keyframes timerWarning {
    0%, 100% {
        color: #ef4444;
        transform: scale(1);
    }
    50% {
        color: #dc2626;
        transform: scale(1.15);
    }
}

/* �� ��¦�� ȿ�� */
@keyframes starSparkle {
    0% {
        opacity: 0;
        transform: translate(var(--tx, 0), var(--ty, 0)) scale(0) rotate(0deg);
    }
    50% {
        opacity: 1;
        transform: translate(var(--tx, 0), var(--ty, 0)) scale(1.2) rotate(180deg);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx, 0), var(--ty, 0)) scale(0) rotate(360deg);
    }
}

/* �ִϸ��̼� ���� Ŭ���� */
.correct-answer {
    animation: correctPulse 0.6s ease-in-out;
    border-color: #22c55e !important;
}

.wrong-answer {
    animation: wrongShake 0.5s ease-in-out;
    border-color: #ef4444 !important;
}

.timer-warning {
    animation: timerWarning 1s infinite;
    font-weight: 900 !important;
}

.star-effect {
    position: fixed;
    font-size: 2rem;
    animation: starSparkle 1s ease-out forwards;
    pointer-events: none;
    z-index: 999999;
}

/* --- 큰 화면 최적화 (1025px 이상) --- */
@media (min-width: 1025px) {
    .container {
        max-width: min(1400px, 90vw);
        padding: 0 2vw;
    }
    
    header h1 {
        font-size: clamp(3rem, 5vw, 4rem);
    }
    
    .game-section {
        padding: clamp(35px, 3vw, 50px);
    }
    
    /* 모달 크기 조정 */
    #practice-questions-modal,
    #student-ranking-modal,
    #achievements-modal,
    #shop-modal,
    #team-modal {
        padding: 2vw;
    }
}

/* --- 초대형 화면 최적화 (1920px 이상) --- */
@media (min-width: 1920px) {
    .container {
        max-width: 1600px;
    }
    
    header h1 {
        font-size: 4.5rem;
    }
    
    .btn {
        padding: 20px 40px;
        font-size: 1.4rem;
    }
}

/* --- 세로 모드 최적화 --- */
@media (max-width: 768px) and (orientation: portrait) {
    body {
        font-size: 7px;
    }
    
    .container {
        margin: 1vh auto;
        padding: 0 2vw;
    }
    
    header h1 {
        font-size: 1.2rem !important;
    }
}

/* --- 가로 모드 최적화 --- */
@media (max-width: 768px) and (orientation: landscape) {
    .container {
        margin: 2vh auto;
    }
    
    #practice-questions-modal {
        overflow-y: auto !important;
    }
    
    header h1 {
        font-size: 1.5rem !important;
    }
}

/* --- 최종 결과 모달 탭 버튼 --- */
.ranking-tab-btn {
    transition: all 0.2s ease;
}

.ranking-tab-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.ranking-tab-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
}

.ranking-tab-content {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- 학생/선생님 버튼 반응형 --- */
.student-action-btn,
.teacher-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
}

.student-action-btn .btn-icon,
.teacher-action-btn .btn-icon {
    font-size: 1.5rem;
}

.student-action-btn .btn-text,
.teacher-action-btn .btn-text {
    display: inline;
}

/* 배틀 시작 버튼은 큰 아이콘 */
#practice-questions-btn .btn-icon {
    font-size: 1.8rem;
}

/* 작은 화면에서는 아이콘만 표시 */
@media (max-width: 768px) {
    .student-action-btn,
    .teacher-action-btn {
        padding: 15px !important;
        min-width: 60px;
    }
    
    .student-action-btn .btn-icon,
    .teacher-action-btn .btn-icon {
        font-size: 2rem;
    }
    
    .student-action-btn .btn-text,
    .teacher-action-btn .btn-text {
        display: none;
    }
    
    /* 배틀 시작 버튼은 더 큰 아이콘 */
    #practice-questions-btn {
        padding: 25px !important;
    }
    
    #practice-questions-btn .btn-icon {
        font-size: 3rem;
    }
}

/* 매우 작은 화면 */
@media (max-width: 480px) {
    .student-action-btn,
    .teacher-action-btn {
        padding: 12px !important;
        min-width: 50px;
    }
    
    .student-action-btn .btn-icon,
    .teacher-action-btn .btn-icon {
        font-size: 1.8rem;
    }
    
    #practice-questions-btn {
        padding: 20px !important;
    }
    
    #practice-questions-btn .btn-icon {
        font-size: 2.5rem;
    }
}

/* --- 학생 대기 화면 레벨 정보 모바일 최적화 --- */
@media (max-width: 768px) {
    #student-waiting-area > div:first-child {
        padding: 15px !important;
        margin-bottom: 15px !important;
    }
    
    #student-waiting-area > div:first-child > div {
        gap: 15px !important;
    }
    
    #student-waiting-area > div:first-child > div > div:first-child > div:first-child {
        width: 60px !important;
        height: 60px !important;
        font-size: 2rem !important;
    }
    
    #student-waiting-area > div:first-child > div > div:last-child {
        padding: 15px 20px !important;
    }
    
    #student-level-number,
    #student-stars-display {
        font-size: 1.5rem !important;
    }
    
    #student-level-name {
        font-size: 1.1rem !important;
        padding: 6px 15px !important;
    }
}

/* ============================================
   🎯 3단계: 인라인 스타일 → CSS 클래스 변환
   ============================================ */

/* --- 문제 풀기 모달 --- */
#practice-questions-modal {
    display: none !important; /* 기본적으로 항상 숨김 */
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100); /* ✅ iOS vh 보정 */
    background-color: #111827;
    z-index: 10001;
    overflow-y: scroll;
    visibility: hidden !important; /* 추가 보호 */
    opacity: 0 !important; /* 추가 보호 */
}

/* 모달이 활성화되었을 때만 표시 */
#practice-questions-modal.active {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* --- 모달 공통 스타일 --- */
.modal-base {
    background: white;
    border-radius: 12px;
    padding: 0;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto; /* 스크롤 가능하도록 변경 */
    overflow-x: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    position: relative;
    -webkit-overflow-scrolling: touch; /* iOS 부드러운 스크롤 */
}

/* 모달 스크롤바 스타일 */
.modal-base::-webkit-scrollbar {
    width: 8px;
}

.modal-base::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 0 12px 12px 0;
}

.modal-base::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 4px;
}

.modal-base::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #5568d3 0%, #653a8b 100%);
}

/* Firefox 스크롤바 */
.modal-base {
    scrollbar-width: thin;
    scrollbar-color: #667eea #f1f1f1;
}

/* 랭킹 리스트 컨테이너 스크롤바 스타일 */
#student-ranking-list::-webkit-scrollbar {
    width: 6px;
}

#student-ranking-list::-webkit-scrollbar-track {
    background: #f8f9fa;
    border-radius: 3px;
}

#student-ranking-list::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 3px;
}

#student-ranking-list::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}

#student-ranking-modal .modal-base > div[style*="padding: 25px"] {
    /* 랭킹 리스트를 감싸는 div에 스크롤 적용 */
    -webkit-overflow-scrolling: touch;
}

#student-ranking-modal .modal-base > div[style*="padding: 25px"]::-webkit-scrollbar {
    width: 8px;
}

#student-ranking-modal .modal-base > div[style*="padding: 25px"]::-webkit-scrollbar-track {
    background: #f8f9fa;
    border-radius: 4px;
}

#student-ranking-modal .modal-base > div[style*="padding: 25px"]::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 4px;
}

#student-ranking-modal .modal-base > div[style*="padding: 25px"]::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #5568d3 0%, #653a8b 100%);
}

/* 랭킹 스크롤 컨테이너 스타일 */
#student-ranking-scroll-container {
    -webkit-overflow-scrolling: touch;
}

#student-ranking-scroll-container::-webkit-scrollbar {
    width: 10px;
}

#student-ranking-scroll-container::-webkit-scrollbar-track {
    background: #f8f9fa;
    border-radius: 5px;
    margin: 5px;
}

#student-ranking-scroll-container::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 5px;
    border: 2px solid #f8f9fa;
}

#student-ranking-scroll-container::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #5568d3 0%, #653a8b 100%);
}

/* Firefox */
#student-ranking-scroll-container {
    scrollbar-width: thin;
    scrollbar-color: #667eea #f8f9fa;
}

/* 업적 리스트 컨테이너 스크롤바 스타일 */
#achievements-list-container {
    -webkit-overflow-scrolling: touch;
}

#achievements-list-container::-webkit-scrollbar {
    width: 10px;
}

#achievements-list-container::-webkit-scrollbar-track {
    background: #f8f9fa;
    border-radius: 5px;
    margin: 5px;
}

#achievements-list-container::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 5px;
    border: 2px solid #f8f9fa;
}

#achievements-list-container::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #5568d3 0%, #653a8b 100%);
}

/* Firefox */
#achievements-list-container {
    scrollbar-width: thin;
    scrollbar-color: #667eea #f8f9fa;
}

/* 모달 닫기 버튼 고정 - 스크롤해도 항상 화면 상단에 보이게 */
#close-student-ranking-modal-btn,
#close-achievements-modal-btn,
#close-shop-modal-btn,
#close-team-modal-btn {
    position: sticky !important;
    top: 10px !important;
    z-index: 10010 !important;
}

/* 업적 탭 버튼 스타일 */
.achievements-tab {
    transition: all 0.3s ease;
}

.achievements-tab:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.2);
}

.achievements-tab.active {
    background: #667eea !important;
    color: white !important;
    border-bottom: 2px solid #667eea !important;
}

@media (max-width: 768px) {
    /* 모바일에서 닫기 버튼 위치 조정 */
    #close-student-ranking-modal-btn,
    #close-achievements-modal-btn,
    #close-shop-modal-btn,
    #close-team-modal-btn {
        top: 5px !important;
    }
    
    /* 모바일에서 탭 버튼 높이 조정 */
    .achievements-tab {
        padding: 6px 12px !important;
        font-size: 0.85rem !important;
    }
}

.modal-large {
    max-width: 1200px;
    border-radius: 2.5rem;
    border: 8px solid white;
    background: #f0f7ff;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    margin: 20px auto;
    max-height: 90vh;
    overflow-y: auto;
    scroll-behavior: auto; /* 즉시 스크롤 (애니메이션 없음) */
    position: relative;
    top: 0; /* 항상 최상단에서 시작 */
}

.modal-medium {
    max-width: 900px;
}

.modal-small {
    max-width: 600px;
}

.modal-xsmall {
    max-width: 500px;
}

/* --- 레벨/업적 팝업 --- */
.popup-levelup {
    position: relative;
    width: 75vw;
    height: 75vh;
    max-width: 75vw;
    max-height: 75vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 3rem;
    padding: 60px 40px;
    text-align: center;
    box-shadow: 0 30px 60px rgba(0,0,0,0.5);
    border: 8px solid white;
    animation: levelupBounce 0.6s ease-out;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.popup-achievement {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    max-width: 400px;
}

/* --- 게임 설정 영역 --- */
.setting-box {
    background: #f8fafc;
    border-radius: 2rem;
    border: 4px solid #f1f5f9;
    padding: 30px;
}

.setting-box-compact {
    padding: 20px;
}

/* --- 타이머/진행바 영역 --- */
.timer-area {
    width: 100%;
    max-width: 700px;
    margin: 60px auto 0;
    text-align: center;
}

.timer-display {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
}

.timer-bar-container {
    flex: 1;
    max-width: 600px;
    background-color: #1f2937;
    border-radius: 9999px;
    overflow: hidden;
    height: 24px;
    border: 4px solid #374151;
    padding: 4px;
}

.timer-bar {
    height: 100%;
    width: 100%;
    background: #3b82f6;
    border-radius: 9999px;
    transition: width 1s linear;
}

/* --- 팀 표시 --- */
.team-display {
    margin-bottom: 30px;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 1.5rem;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
}

/* --- 보너스 미션 카드 --- */
.bonus-card {
    position: absolute;
    top: 100px;
    left: 40px;
    z-index: 10002;
    max-width: 450px;
}

/* --- 중앙 정렬 콘텐츠 --- */
.center-content {
    width: 100%;
    max-width: 1000px;
    text-align: center;
}

/* --- 로그인 영역 --- */
.login-container {
    text-align: center;
    background: white;
    padding: 60px 80px;
    border-radius: 3rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-width: 500px;
    position: relative;
    overflow: hidden;
}

/* --- 레벨 진행 바 --- */
.level-progress-wrapper {
    min-width: 400px;
}

/* --- Flex 유틸리티 --- */
.flex-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.flex-col {
    display: flex;
    flex-direction: column;
}

/* --- 모바일 대응 조정 --- */
@media (max-width: 768px) {
    .modal-base,
    .modal-large,
    .modal-medium,
    .modal-small,
    .modal-xsmall {
        width: 95%;
        max-width: none;
        border-radius: 1.5rem;
        border-width: 4px;
        max-height: 90vh; /* 모바일에서 더 큰 영역 사용 */
        overflow-y: auto !important; /* 스크롤 강제 적용 */
    }
    
    /* 모바일 랭킹 모달 내부 스크롤 영역 */
    #student-ranking-modal .modal-base > div[style*="padding: 25px"] {
        max-height: calc(80vh - 250px) !important; /* 헤더와 버튼 공간 제외 */
        overflow-y: auto !important;
    }
    
    /* 모바일 업적 모달 내부 스크롤 영역 */
    #achievements-list-container {
        max-height: calc(70vh - 200px) !important;
        overflow-y: auto !important;
    }
    
    .login-container {
        padding: 30px 20px;
        max-width: none;
        width: 90%;
    }
    
    .popup-levelup {
        padding: 40px 20px;
        width: 90vw;
        height: 85vh;
        max-width: 90vw;
        max-height: 85vh;
    }
    
    .level-progress-wrapper {
        min-width: auto;
        width: 100%;
    }
    
    .timer-area {
        margin: 30px auto 0;
        max-width: 100%;
    }
    
    .setting-box {
        padding: 15px;
    }
    
    .team-display {
        max-width: none;
        width: 100%;
    }
    
    .bonus-card {
        top: 80px;
        left: 15px;
        max-width: 200px;
    }
}
