/* Google Fonts에서 'Noto Serif KR' 폰트 불러오기 */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+KR:wght@400;700&display=swap');

/* ==================== 1. 기본 스타일 & 초기화 ==================== */
/* html이 전체 높이를 차지하도록 설정 */
html {
    height: 100%;
}

/* 모든 요소의 기본 여백/패딩을 제거하고, 테두리를 포함하여 크기를 계산하도록 설정 */
* { margin: 0; padding: 0; box-sizing: border-box; }

/* body 전체에 대한 기본 스타일 정의 */
body {
    font-family: 'Noto Serif KR', serif;
    background-color: #0d0d1a;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%; /* vh 대신 %를 사용하여 모바일 브라우저의 주소창에 따른 높이 변화 문제에 대응 */
    overflow: hidden;
    user-select: none; /* 드래그 방지 */
}

/* ==================== 2. 시작 메뉴 & 공통 UI ==================== */
#start-menu {
    text-align: center;
}

/* 볼륨 조절 버튼 (화면 우측 상단) */
#volume-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
    z-index: 101; /* 다른 모달 위에 표시될 수 있도록 */
}

/* 개별 볼륨 버튼 스타일 */
.volume-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 20px;
    padding: 0;
    box-shadow: none;
}

/* 볼륨 off 상태 스타일 */
.volume-btn.off {
    opacity: 0.5;
    text-decoration: line-through 3px red;
}

.game-title {
    font-size: 50px;
    color: #a78bfa;
    text-shadow: 0 0 15px #a78bfa;
    margin-bottom: 40px;
}

#start-menu div {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

/* 시작 메뉴의 버튼 스타일 */
.start-btn {
    padding: 12px 25px;
    font-size: 18px;
    width: 220px;
    background: #4b5563;
    box-shadow: 0 4px 0 #374151;
    position: relative; /* 'N' 배지 위치의 기준점 */
}

/* 새로운 콘텐츠 알림 'N' 배지 스타일 */
.new-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    background-color: #ef4444; /* 빨간색 */
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    font-weight: bold;
    display: flex; /* 내부 텍스트 중앙 정렬을 위해 flex 사용 */
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 5px rgba(255, 0, 0, 0.7);
    line-height: 1; /* 'N' 텍스트의 수직 정렬을 위함 */
}

/* 로그인 시 환영 메시지 스타일 */
.welcome-msg {
    font-size: 20px;
    color: #fbbf24;
    margin-bottom: 10px;
}

/* ==================== 3. 게임 화면 레이아웃 ==================== */
.game-container {
    width: 100%;
    height: 100%; /* 컨테이너가 body 높이를 꽉 채우도록 설정 */
    max-width: 1500px;
    background: rgba(30, 32, 50, 0.9);
    border: 2px solid #7c3aed;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 0 30px rgba(124, 58, 237, 0.5);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* 상단 정보 (층수, 턴, 골드, 버프) */
.header {
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 10px;
}
.floor-badge {
    background: #7c3aed;
    padding: 8px 16px;
    border-radius: 22px;
    font-size: 18px;
    font-weight: bold;
}

/* 전투 필드 (플레이어와 몬스터가 위치하는 영역) */
.battle-field {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px 10px;
    flex: 1;
    gap: 50px;
    position: relative; /* 데미지 텍스트 위치의 기준점 */
}

/* 몬스터들이 모여있는 영역 */
#monster-area {
    display: flex;
    gap: 20px;
    align-items: flex-end; /* 몬스터들을 하단에 정렬 */
}

/* 개별 몬스터를 감싸는 컨테이너 */
.monster-wrapper {
    position: relative;
    transition: transform 0.2s ease;
    cursor: pointer;
}

.monster-wrapper.targeted {
    transform: translateY(-10px); /* 선택된 몬스터를 위로 살짝 이동 */
}

.monster-wrapper.dead {
    cursor: not-allowed;
}

/* 현재 타겟으로 지정된 몬스터 위에 표시되는 화살표 */
.target-indicator {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 26px;
    color: #ef4444;
    display: none;
}

.monster-wrapper.targeted .target-indicator {
    display: block;
}

.monster-wrapper.dead .character {
    opacity: 0.4;
    filter: grayscale(1);
}

/* ==================== 4. 캐릭터 및 공통 UI 요소 ==================== */
/* 플레이어와 몬스터의 공통 스타일 */ .character {
    text-align: center;
    position: relative;
    transition: transform 0.15s ease-out, opacity 0.5s, filter 0.5s; /* 공격, 사망 등 애니메이션을 위함 */
}

.emoji { font-size: 130px; filter: drop-shadow(0 0 10px rgba(255,255,255,0.5)); transition: 0.2s; }
.name { font-size: 22px; margin-top: 10px; color: #ccc; font-weight: bold; }

/* 체력바 */
.hp-bar-bg {
    width: 180px; height: 20px; background: #333;
    border-radius: 10px; margin: 10px auto; overflow: hidden;
}
.hp-bar-fill {
    height: 100%; background: #ef4444; width: 100%;
    transition: width 0.3s ease;
}
.hp-text { font-size: 18px; color: #aaa; margin-top: 5px; }

/* ==================== 5. 애니메이션 및 효과 ==================== */
/* 피격 시 흔들림 효과 */
@keyframes shake {
    0% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-5px); }
    100% { transform: translateX(0); }
}
.hit { animation: shake 0.3s; color: red !important; }

/* 기절 효과 애니메이션 */
@keyframes stun-effect {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
}
.stunned .emoji {
    animation: stun-effect 0.5s infinite;
}
.stunned .target-indicator {
    display: none; /* 기절 시 타겟 표시 숨김 */
}

/* 떠오르는 텍스트(데미지, 힐 등)의 공통 스타일 및 애니메이션 */
.floating-text {
    position: absolute;
    font-size: 28px;
    font-weight: bold;
    text-shadow: 1px 1px 2px #000;
    pointer-events: none;
    animation: float-up-and-fade 1.2s ease-out forwards;
    z-index: 100;
    white-space: nowrap;
}

@keyframes float-up-and-fade {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(-70px);
        opacity: 0;
    }
}

/* 떠오르는 텍스트의 종류별 스타일 */
.floating-text.damage {
    color: #fff;
}

.floating-text.crit {
    color: #ffdd44; /* 금색 */
    font-size: 36px;
    font-weight: 900;
}

.floating-text.black-flash {
    color: red;
    font-size: 40px;
    font-weight: 900;
    text-shadow: 0 0 5px black, 0 0 10px red;
}

.floating-text.miss {
    color: #aaa;
    font-size: 24px;
}

.floating-text.stun {
    color: #fde047; /* 노란색 */
    font-size: 36px;
    font-weight: bold;
}

.floating-text.heal {
    color: #22c55e; /* 초록색 */
    font-size: 32px;
}

.floating-text.mp-heal {
    color: #60a5fa; /* 파란색 */
    font-size: 32px;
}

.floating-text.buff {
    color: #a855f7; /* 보라색 */
    font-size: 28px;
}

.floating-text.level-up {
    color: #fbbf24;
    font-size: 48px;
    font-weight: 900;
    text-shadow: 0 0 5px black, 0 0 10px #fbbf24;
}

/* ==================== 6. 하단 UI (로그, 상태바, 컨트롤) ==================== */
.log-box {
    background: rgba(0,0,0,0.5);
    height: 150px;
    border-radius: 10px;
    padding: 15px;
    overflow-y: auto;
    font-size: 16px;
    line-height: 1.6;
    border: 1px solid #444;
}
.log-msg { margin-bottom: 4px; }
/* 로그 메시지 종류별 색상 */
.log-player { color: #60a5fa; }
.log-monster { color: #f87171; }
.log-system { color: #fbbf24; font-weight: bold; }

/* MP 바 */
.mp-bar-container {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: rgba(0,0,0,0.3);
    border-radius: 10px;
    border: 1px solid #444;
}

.mp-bar-fill {
    height: 100%;
    background: #60a5fa; /* 파란색 */
    width: 100%;
    transition: width 0.5s ease;
}

/* 경험치 바 */
.xp-bar-container {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: rgba(0,0,0,0.3);
    border-radius: 10px;
    border: 1px solid #444;
}
.level-badge {
    font-size: 16px;
    font-weight: bold;
    color: #fbbf24;
}
.xp-bar-bg {
    flex-grow: 1;
    height: 20px;
    background: #333;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #555;
}
.xp-bar-fill {
    height: 100%;
    background: #8b5cf6;
    width: 0%;
    transition: width 0.5s ease;
}
.xp-text { font-size: 16px; color: #ccc; min-width: 150px; text-align: right; }

/* 컨트롤 패널 (버튼 영역) */
.controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

button {
    padding: 25px;
    border: none;
    border-radius: 12px;
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    transition: 0.2s;
    color: white;
    font-size: 24px;
}

button:active { transform: scale(0.95); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* 버튼 종류별 색상 */
.btn-inventory { background: #3b82f6; box-shadow: 0 4px 0 #1d4ed8; }
.btn-attack { background: #ef4444; box-shadow: 0 4px 0 #991b1b; }
.btn-buff { background: #8b5cf6; box-shadow: 0 4px 0 #5b21b6; }
.btn-heal { background: #10b981; box-shadow: 0 4px 0 #047857; }
.btn-armor { background: #a16207; box-shadow: 0 4px 0 #713f12; } /* 방어구 버튼 */
.btn-defend { background: #06b6d4; box-shadow: 0 4px 0 #0891b2; } /* 방어 버튼 */
.btn-defend-active {
    background: #22d3ee; /* 더 밝은 청록색 */
    box-shadow: 0 4px 0 #06b6d4;
}

/* 스킬 버튼용 추가 스타일 */
.skill-desc {
    font-size: 14px;
    font-weight: normal;
    color: #ccc;
}

.btn-back {
    grid-column: 1 / -1; /* 뒤로가기 버튼은 가로로 꽉 차게 */
}

/* 몬스터 기절 시 표시되는 아이콘 */
.stun-indicator {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 30px;
    display: none;
}

/* ==================== 7. 모달 (팝업창) 스타일 ==================== */
/* 레벨업 모달 */
#levelup-modal {
    position: absolute; top:0; left:0; width:100%; height:100%;
    background: rgba(0,0,0,0.8);
    display: none;
    justify-content: center; align-items: center; flex-direction: column; text-align: center;
    z-index: 10;
}
.levelup-text { font-size: 26px; color: #fbbf24; margin-bottom: 20px; font-weight: bold; }

@keyframes level-up-effect {
    0% { transform: scale(1) translateY(20px); opacity: 0; }
    50% { transform: scale(1.5) rotate(-5deg); opacity: 1; text-shadow: 0 0 20px #fff, 0 0 30px #fbbf24; }
    100% { transform: scale(1.2); opacity: 1; }
}

.levelup-text.animated {
    animation: level-up-effect 0.8s ease-out forwards;
}

/* 상점 모달 */
#shop-modal {
    position: absolute; top:0; left:0; width:100%; height:100%;
    background: rgba(0,0,0,0.8);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* 콘텐츠를 상단에 정렬하여 스크롤 시 잘리지 않도록 함 */
    padding-top: 5vh; /* 상단 여백 추가 */
    z-index: 20;
}
.shop-title { font-size: 40px; color: #fbbf24; margin-bottom: 20px; }
.shop-container { display: flex; flex-direction: column; gap: 20px; width: 90%; max-width: 1400px; max-height: 80vh; overflow-y: auto; }
.shop-row {
    display: flex;
    gap: 20px;
    width: 100%;
}
.shop-section { flex: 1; background: rgba(255,255,255,0.1); padding: 15px; margin-bottom: 20px; border-radius: 10px; }
.shop-section h3 { text-align: center; color: #ddd; margin-bottom: 15px; font-size: 22px; border-bottom: 1px solid #555; padding-bottom: 10px; }
.shop-items { display: flex; flex-direction: column; gap: 10px; }
.shop-btn {
    background: #4b5563; padding: 15px; font-size: 16px;
    display: flex; flex-direction: column; align-items: center; gap: 5px;
}
.shop-btn span { color: #fbbf24; }
.shop-btn .armor-emoji { font-size: 32px; line-height: 1; }
.shop-btn:hover { background: #6b7280; }

/* (사용되지 않음) 구 인벤토리 모달 */
/* 인벤토리 모달 */
#inventory-modal {
    position: absolute; top:0; left:0; width:100%; height:100%;
    background: rgba(0,0,0,0.9);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
}
.inventory-list { width: 80%; max-width: 500px; display: flex; flex-direction: column; gap: 10px; }
/* 아이템 목록 공통 스타일 (물약, 장비, 전리품 등에서 재사용) */
.inventory-item { background: #374151; padding: 22px; border-radius: 10px; display: flex; justify-content: space-between; align-items: center; }
.item-info { font-size: 22px; }
.btn-use { padding: 14px 28px; font-size: 20px; background: #10b981; box-shadow: 0 4px 0 #047857; }
.item-passive-effect {
    color: #f59e0b;
    font-weight: bold;
    font-size: 18px;
    border: 2px solid #f59e0b;
    padding: 8px 12px;
    border-radius: 8px;
}

/* 물약 사용 모달 */
#item-select-modal {
    position: absolute; top:0; left:0; width:100%; height:100%;
    background: rgba(0,0,0,0.85);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* 콘텐츠를 상단에 정렬 */
    padding-top: 5vh; /* 상단 여백 추가 */
    z-index: 15;
}
.potion-container {
    display: flex;
    gap: 15px;
    width: 90%;
    max-width: 2300px;
    margin-bottom: 20px;
}
.potion-section {
    flex: 1;
    background: rgba(0,0,0,0.3);
    padding: 20px;
    border-radius: 10px;
    border: 1px solid #444;
}
.potion-section h3 {
    text-align: center;
    color: #ddd;
    margin-bottom: 15px;
    font-size: 20px;
    border-bottom: 1px solid #555;
    padding-bottom: 10px;
}
.potion-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 50vh;
    overflow-y: auto;
}

/* 물약 사용 모달의 아이템 크기만 줄이기 위한 재정의 */
#item-select-modal .inventory-item {
    padding: 12px;
}
#item-select-modal .item-info {
    font-size: 16px;
}
#item-select-modal .btn-use {
    padding: 8px 16px;
    font-size: 14px;
}

/* 장비 및 스탯 관리 모달 */
#equipment-modal {
    position: absolute; top:0; left:0; width:100%; height:100%;
    background: rgba(0,0,0,0.9);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* 콘텐츠를 상단에 정렬 */
    padding: 5vh 20px; /* 상하 및 좌우 여백을 추가하여 콘텐츠가 화면 가장자리에 닿지 않도록 함 */
    z-index: 20;
}
#current-equipment-display {
    background: rgba(0,0,0,0.3);
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    border: 1px solid #444;
    text-align: center;
}
.current-equipment-item {
    font-size: 18px;
    color: #fbbf24;
}
.current-equipment-item:not(:last-child) {
    margin-bottom: 10px;
}
.equipment-container {
    display: flex;
    gap: 20px;
    width: 100%;
    /* max-width를 제거하여 항상 100% 너비를 사용하도록 함 */
}
.equipment-section {
    flex: 1;
    background: rgba(255,255,255,0.1);
    padding: 15px;
    border-radius: 10px;
}
.equipment-section h3 {
    text-align: center; color: #ddd; margin-bottom: 15px; font-size: 20px;
    border-bottom: 1px solid #555; padding-bottom: 10px;
}
.equipment-list { display: flex; flex-direction: column; gap: 10px; max-height: 40vh; overflow-y: auto; }

/* 장비 및 스탯 모달 통합 */
.modal-content { /* 모달 공통 컨텐츠 래퍼 */ }
.management-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    width: 100%; /* 컨테이너가 모달의 패딩 영역 내에서 100% 너비를 차지하도록 설정 */
    /* max-width를 제거하여 항상 화면 너비에 맞게 표시되도록 함 */
}
.management-section {
    flex: 1;
    background: rgba(0,0,0,0.2);
    padding: 1px;
    border-radius: 10px;
    border: 1px solid #444;
    display: flex;
    flex-direction: column;
}

/* 스탯 분배 관련 스타일 */
#stat-points-display {
    font-size: 20px;
    margin-bottom: 15px;
    text-align: center;
}
#stat-points-display span {
    color: #fbbf24;
    font-size: 24px;
}
.stat-up-list {
    width: 100%;
    gap: 10px;
    margin-bottom: 20px;
}
.stat-up-item {
    background: #374151; padding: 15px; border-radius: 10px;
    display: flex; justify-content: space-between; align-items: center;
    text-align: left;
}
.stat-info h4 { font-size: 18px; margin-bottom: 5px; }
.stat-info p { font-size: 14px; color: #ccc; }
#stat-current-values { text-align: center; margin-bottom: 15px; font-size: 16px; color: #ddd; }

/* 흑섬 발동 시 화면 깜빡임 효과 */
#black-flash-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: black;
    opacity: 0;
    z-index: 9999;
    pointer-events: none; /* 이벤트를 통과시켜 클릭 방해 안함 */
}

@keyframes black-flash-animation { /* 흑섬 발동 시 화면 깜빡임 애니메이션 */
    0% { opacity: 0.9; background-color: red; }
    50% { opacity: 1; background-color: black; }
    100% { opacity: 0; }
}

/* --- 8. 로그인/회원가입/스코어보드/공지사항 모달 --- */
/* 스코어보드 목록 아이템 스타일 */
.scoreboard-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline; /* 텍스트 기준선에 맞춰 정렬하여 줄바꿈 시에도 열이 맞도록 함 */
    padding: 8px;
    font-size: 18px;
    border-bottom: 1px solid #444;
}
.scoreboard-item:last-child { border-bottom: none; }
.scoreboard-item .rank { font-weight: bold; color: #fbbf24; margin-right: 10px; }
.scoreboard-item .name { color: #60a5fa; }
.scoreboard-item .score { font-weight: bold; }

/* 스코어보드 섹션 헤더 스타일 */
.scoreboard-header {
    text-align: center;
    color: #a78bfa;
    margin: 15px 0 5px 0;
    font-size: 16px;
}

/* 현재 진행 중인 게임 랭킹 아이템 스타일 */
.scoreboard-item.current-run {
    background-color: rgba(251, 191, 36, 0.1);
    border: 1px solid #fbbf24;
    border-radius: 8px;
}

/* 랭킹 1위 강조 스타일 */
.scoreboard-item.top-ranker {
    background-color: rgba(255, 215, 0, 0.15);
    border: 1px solid #ffd700;
    border-radius: 8px;
}

/* 스코어보드에서 내 최고기록 강조 스타일 */
.scoreboard-item.current-user-score {
    background-color: rgba(96, 165, 250, 0.1);
}

/* 국기 아이콘 스타일 */
.flag-icon {
    vertical-align: middle; /* 텍스트와 수직 정렬 */
    margin-right: 6px;
    height: 1em; /* 텍스트 크기에 맞게 높이 조절 */
}

/* 로그인/회원가입/프로필수정 공통 모달 스타일 */
#login-modal,
#register-modal,
#edit-profile-modal,
#find-account-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none; /* JS로 제어 */
    align-items: center;
    justify-content: center; /* 콘텐츠를 중앙에 정렬 */
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

#login-modal.visible,
#register-modal.visible,
#edit-profile-modal.visible,
#find-account-modal.visible {
    opacity: 1;
}

.login-content {
    background: #1e2032;
    border: 2px solid #7c3aed;
    border-radius: 15px;
    padding: 25px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 0 40px rgba(124, 58, 237, 0.6);
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

#login-modal.visible .login-content,
#register-modal.visible .login-content,
#edit-profile-modal.visible .login-content,
#find-account-modal.visible .login-content {
    transform: scale(1);
}

#login-form,
#register-form,
#find-account-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
}

/* 회원정보 수정 폼 그룹 스타일 */
#edit-profile-form .form-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

#edit-profile-form .form-group label {
    flex-basis: 70px; /* 라벨 너비 고정 */
    flex-shrink: 0;
    text-align: left;
    font-size: 16px;
    color: #ddd;
    font-weight: bold;
}

#login-form input,
#register-form input,
#edit-profile-form input,
#find-account-form input,
#login-form select,
#register-form select,
#edit-profile-form select {
    padding: 12px; font-size: 15px; border-radius: 8px; border: 1px solid #555; background: #333; color: #fff; font-family: inherit;
}

#login-form input[type="date"],
#register-form input[type="date"],
#edit-profile-form input[type="date"],
#find-account-form input[type="date"] { color-scheme: dark; }
.login-buttons { display: flex; gap: 10px; }
.login-buttons button {
    flex: 1;
    padding: 12px;
    font-size: 16px;
}

.switch-auth-msg {
    margin-top: 15px;
    font-size: 14px;
    color: #ccc;
}
.switch-auth-msg a {
    color: #a78bfa;
    text-decoration: none;
    font-weight: bold;
    cursor: pointer;
}
.switch-auth-msg a:hover { text-decoration: underline; }

/* 아이디/비번찾기 결과 표시 영역 */
#find-account-result {
    display: none; /* JS로 제어 */
    margin-top: 15px;
    padding: 12px;
    border-radius: 8px;
    background-color: rgba(0,0,0,0.2);
    font-weight: bold;
    line-height: 1.5;
    word-break: break-all; /* 긴 비밀번호 줄바꿈 처리 */
}

/* 스코어보드 팝업 모달 스타일 */
#scoreboard-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none; /* JS로 제어 */
    align-items: center;
    justify-content: center; /* 콘텐츠를 중앙에 정렬 */
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

#scoreboard-modal.visible {
    opacity: 1;
}

.scoreboard-content {
    background: #1e2032;
    border: 2px solid #7c3aed;
    border-radius: 15px;
    padding: 25px;
    width: 90%;
    max-width: 500px;
    text-align: center;
    box-shadow: 0 0 40px rgba(124, 58, 237, 0.6);
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

#scoreboard-modal.visible .scoreboard-content {
    transform: scale(1);
}

#scoreboard-list {
    max-height: 60vh;
    overflow-y: auto;
    margin-top: 20px;
    background: rgba(0,0,0,0.3);
    padding: 15px;
    border-radius: 10px;
}

/* 공통 모달 닫기 버튼 */
.modal-close-btn {
    margin-top: 20px;
    background: #4b5563;
    box-shadow: 0 4px 0 #374151;
    padding: 12px 30px;
    font-size: 16px;
}

/* 공지사항 팝업 모달 스타일 */
#notice-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none; /* JS로 제어 */
    align-items: center;
    justify-content: center; /* 콘텐츠를 중앙에 정렬 */
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

#notice-modal.visible {
    opacity: 1;
}

.notice-content {
    background: #1e2032;
    border: 2px solid #7c3aed;
    border-radius: 15px;
    padding: 25px;
    width: 90%;
    max-width: 600px;
    text-align: center;
    box-shadow: 0 0 40px rgba(124, 58, 237, 0.6);
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

#notice-modal.visible .notice-content {
    transform: scale(1);
}

#notice-list {
    max-height: 60vh;
    overflow-y: auto;
    margin-top: 20px;
    background: rgba(0,0,0,0.3);
    padding: 10px;
    border-radius: 10px;
    text-align: left;
}

.notice-item {
    padding: 12px;
    border-bottom: 1px solid #444;
    transition: background-color 0.2s;
    cursor: pointer;
}
.notice-item:last-child { border-bottom: none; }
.notice-item:hover { background-color: rgba(255, 255, 255, 0.05); cursor: pointer; }
.notice-item.active { background-color: rgba(255, 255, 255, 0.1); }

.notice-details {
    display: none;
    padding: 15px;
    margin-top: 15px;
    background-color: rgba(0,0,0,0.3);
    border-radius: 8px;
    border-top: 1px solid #555;
    color: #ccc;
    line-height: 1.7;
    white-space: pre-wrap; /* 줄바꿈 및 공백 유지 */
    font-size: 14px;
}
.notice-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.notice-version { font-weight: bold; color: #a78bfa; font-size: 1.1em; }
.notice-date { font-size: 0.9em; color: #999; }
.notice-summary { color: #ddd; }

/* 게임 오버 모달 */
#game-over-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85); /* 다른 모달보다 더 어둡게 */
    display: none; /* JS로 제어 */
    align-items: center;
    justify-content: center; /* 중앙 정렬 */
    z-index: 100;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

#game-over-modal.visible {
    opacity: 1;
}

/* ==================== 9. 반응형 웹을 위한 미디어 쿼리 ==================== */

/* 태블릿 (1200px 이하) */
@media (max-width: 1200px) {
    .emoji { font-size: 120px; }
    .name { font-size: 22px; }
    .hp-bar-bg { width: 160px; }
    button { padding: 40px; font-size: 32px; }
    .management-container {
        grid-template-columns: 1fr 1fr; /* 3열 -> 2열 */
        width: 100%;
    }
    .potion-container {
        flex-direction: column;
    }
    .controls {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* 태블릿 & 모바일 (992px 이하) */
@media (max-width: 992px) {
    .game-container {
        padding: 10px; /* 내부 여백 축소 */
    }
    .emoji { font-size: 100px; }
    .name { font-size: 20px; }
    .hp-bar-bg { width: 140px; }
    .hp-text { font-size: 18px; }
    .log-box { height: 180px; font-size: 18px; }
    button { padding: 30px; font-size: 24px; }
    .shop-row { flex-direction: column; }
    .management-container { grid-template-columns: 1fr; } /* 2열 -> 1열 */
}

/* 모바일 (768px 이하) */
@media (max-width: 768px) {
    body {
        padding: 5px; /* 화면 가장자리에 안전 여백을 추가합니다. */
    }
    .game-container {
        border-radius: 10px;
        gap: 8px; /* 요소 간 간격 축소 */
    }
    .battle-field {
        flex-direction: column;
        gap: 8px; /* 캐릭터 간 간격 축소 */
        padding: 5px; /* 전투 필드 여백 축소 */
    }
    .emoji { font-size: 65px; } /* 캐릭터 이모지 크기 축소 */
    .name { font-size: 15px; margin-top: 4px; } /* 이름 폰트 축소 */
    .hp-bar-bg { width: 90px; height: 15px; margin-top: 4px; } /* 체력바 크기 축소 */
    .potion-container {
            flex-direction: column; /* 모바일에서는 세로로 쌓이도록 변경 */
            overflow-y: auto; /* 세로 스크롤 활성화 */
            max-height: 65vh; /* 모달 내에서 스크롤되도록 최대 높이 지정 */
    }
        /* 모바일에서는 물약 컨테이너가 스크롤되므로, 내부 리스트의 스크롤은 비활성화하여 이중 스크롤 방지 */
        .potion-list {
            max-height: none;
            overflow-y: visible;
        }
    .hp-text { font-size: 13px; margin-top: 2px; } /* 체력 텍스트 축소 */
    .log-box {
        height: 90px; /* 로그 박스 높이 추가 축소 */
        font-size: 13px;
        padding: 8px;
    }
    .xp-bar-container, .mp-bar-container { padding: 8px; gap: 8px; } /* MP/XP 바 여백 축소 */
    .xp-bar-bg { height: 18px; }
    .xp-text, .level-badge { font-size: 13px; } /* 레벨/XP 텍스트 축소 */
    
    button {
        padding: 12px 8px; /* 컨트롤 버튼 여백 추가 축소 */
        font-size: 18px;
    }

    .floating-text { font-size: 24px; }
    .floating-text.crit { font-size: 32px; }
    .floating-text.level-up { font-size: 40px; }

    .shop-modal, .inventory-modal, .item-select-modal, .equipment-modal { padding: 10px; }
    .shop-title { font-size: 28px; }

    /* --- 장비 관리 모달 모바일 최적화 --- */
    /* 보유 무기/방어구 목록을 1열로 변경 */
    .equipment-container {
        flex-direction: column;
    }

    /* 장비 및 스탯 관련 폰트 크기 약 20% 축소 */
    .current-equipment-item {
        font-size: 14px; /* 18px -> 14px */
        margin-bottom: 8px;
    }
    .equipment-section h3 {
        font-size: 16px; /* 20px -> 16px */
    }
    #equipment-modal .item-info {
        font-size: 16px; /* 22px -> 16px (물약 모달과 통일) */
    }
    #equipment-modal .item-passive-effect {
        font-size: 14px; /* 18px -> 14px */
        padding: 6px 10px;
    }
    #stat-points-display { font-size: 16px; } /* 20px -> 16px */
    #stat-points-display span { font-size: 20px; } /* 24px -> 20px */
    .stat-info h4 { font-size: 15px; } /* 18px -> 15px */
    .stat-info p { font-size: 12px; } /* 14px -> 12px */
    #stat-current-values { font-size: 13px; } /* 16px -> 13px */

    /* --- 스코어보드 모바일 최적화 --- */
    .scoreboard-header {
        font-size: 13px; /* 16px -> 13px */
    }
    .scoreboard-item {
        font-size: 14px; /* 18px -> 14px */
        padding: 6px;
    }
    .scoreboard-item .score-time {
        font-size: 12px !important; /* 14px -> 12px (인라인 스타일 재정의) */
    }

    /* --- 회원정보 수정 모달 모바일 최적화 --- */
    #edit-profile-form .form-group {
        flex-direction: column; /* 라벨과 입력을 세로로 쌓음 */
        align-items: flex-start; /* 왼쪽 정렬 */
        gap: 5px; /* 간격 축소 */
    }

    #edit-profile-form .form-group label {
        flex-basis: auto; /* 너비 고정 해제 */
        font-size: 13px; /* 16px -> 13px (약 20% 감소) */
    }

    #edit-profile-form p {
        font-size: 12px !important; /* 14px -> 12px (인라인 스타일 재정의) */
    }

    #edit-profile-form button {
        font-size: 16px !important; /* 18px -> 16px (인라인 스타일 재정의) */
    }
}

/* 작은 모바일 (480px 이하) */
@media (max-width: 480px) {
    .game-title { font-size: 48px; }
    .start-btn { width: 200px; font-size: 18px; }
    .floor-badge { font-size: 12px; padding: 6px 10px; }
    .header { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; }
    .emoji { font-size: 55px; }
    .log-box { font-size: 12px; height: 80px; }
    .xp-bar-container, .mp-bar-container { padding: 5px; }
    .xp-bar-bg { height: 15px; }
    .xp-text, .level-badge { font-size: 12px; }

    /* 컨트롤 버튼을 더 작게 만듦 */
    .controls button {
        padding: 12px 4px; /* 세로 여백을 조금 늘려 텍스트가 잘리지 않도록 함 */
        font-size: 14px;
    }

    /* 모바일에서만 스탯 목록에 내부 스크롤(이중 스크롤)을 적용합니다. */
    .stat-up-list {
        max-height: 25vh; /* 모바일 화면에 맞는 적절한 높이 */
        overflow-y: auto;
    }
}
