/* =========================================
   🌙 테마 색상 변수 선언 (라이트 / 다크)
   ========================================= */
:root {
    /* 라이트 모드 (기본) */
    --primary: #2c3e50;
    --accent: #e74c3c;
    --border: #e2e8f0;
    --nav-bg: #ffffff;
    --nav-link: #333333;
    --text-main: #333333;
    --text-sub: #718096;
    --glass-bg: rgba(255, 255, 255, 0.75);
    --card-bg: #ffffff;
    --input-bg: rgba(255, 255, 255, 0.9);
    --btn-bg: rgba(255, 255, 255, 0.9);
    --tag-bg: rgba(237, 242, 247, 0.8);
    --hover-bg: #f8fafc;
    --modal-overlay: rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] {
    /* 다크 모드 */
    --primary: #f1f5f9;
    --accent: #ff7675;
    --border: #4a5568;
    --nav-bg: #1a1a24;
    --nav-link: #e2e8f0;
    --text-main: #f8f9fa;
    --text-sub: #a0aec0;
    --glass-bg: rgba(30, 30, 40, 0.85);
    --card-bg: #2d3748;
    --input-bg: rgba(45, 55, 72, 0.9);
    --btn-bg: rgba(45, 55, 72, 0.9);
    --tag-bg: rgba(74, 85, 104, 0.8);
    --hover-bg: #4a5568;
    --modal-overlay: rgba(0, 0, 0, 0.8);
}

/* 다크 모드일 때 배경 이미지 어둡게 만들기 */
[data-theme="dark"] body {
    /* 옵션 A: 이미지를 유지하면서 엄청 어둡게 덮기 (현재 적용) */
    background-image: linear-gradient(rgba(15, 15, 20, 0.9), rgba(15, 15, 20, 0.9)), url('./image_bg/backgrond.jpg');
    
    /* 옵션 B: 아예 이미지를 없애고 완전 까만 배경으로 바꾸고 싶다면 
       위 background-image 줄을 지우고 아래 두 줄을 사용하세요.
    background-image: none;
    background-color: #121212; 
    */
}

/* =========================================
   1. 기본 설정 및 배경
   ========================================= */
body {
    font-family: 'Pretendard', sans-serif;
    margin: 0;
    padding: 80px 20px 20px 20px; 
    color: var(--primary);
    background-image: url('./image_bg/backgrond.jpg'); 
    background-size: cover;          
    background-position: center;     
    background-repeat: no-repeat;    
    background-attachment: fixed;
    transition: background-color 0.3s ease, color 0.3s ease; 
}

/* =========================================
   2. 상단 고정 네비게이션 바 (GNB)
   ========================================= */
#topNavbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 72px;
    background-color: var(--nav-bg);
    display: flex;
    align-items: center;
    padding: 0 30px;
    box-sizing: border-box;
    z-index: 1000;
    transition: background-color 0.3s ease;
}

.nav-logo { display: flex; align-items: center; }
.nav-logo img { height: 60px; display: block; }

.nav-menu {
    display: flex;
    gap: 25px;
    margin-left: 200px;
    height: 100%;
    flex: 1; /* 상단바의 남은 우측 공간을 모두 차지하도록 설정 */
}

.nav-link {
    text-decoration: none;
    color: var(--nav-link);
    font-size: 18px;
    font-weight: 600;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    height: 100%;
    box-sizing: border-box;
    border-bottom: 3px solid transparent;
}

.nav-link:hover { color: #b7d182; }
.nav-link.active {
    color: #9cc44e;
    font-weight: 800;
    border-bottom: 3px solid #9cc44e;
}

/* 다크모드 토글 버튼 */
.theme-toggle-btn {
    margin-left: auto; /* 우측 끝으로 밀어냄 */
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--nav-link);
    padding: 10px;
    transition: transform 0.3s ease;
}
.theme-toggle-btn:hover { transform: scale(1.1); }

/* =========================================
   3. 필터 및 헤더 영역
   ========================================= */
header {
    background-color: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 20px 25px;
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    margin-bottom: 20px;
    position: sticky;
    top: 70px;
    z-index: 100;
    transition: all 0.3s ease-in-out;
    overflow: hidden;
}

header.collapsed { padding-bottom: 15px; }
header.collapsed .filter-container { max-height: 0; opacity: 0; pointer-events: none; margin-bottom: 0; }
header.collapsed .toggle-icon { transform: rotate(180deg); }

.filter-container { max-height: 1000px; opacity: 1; transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); margin-bottom: 15px; }
.filter-group { border-bottom: 1px solid var(--border); padding: 10px 0; display: flex; align-items: flex-start; transition: border-color 0.3s ease; }
.filter-group:last-child { border-bottom: none; }
.group-label { width: 110px; font-weight: bold; font-size: 14px; padding-top: 8px; color: var(--text-sub); transition: color 0.3s ease; }
.group-content { flex: 1; display: flex; flex-wrap: wrap; gap: 8px; }

/* 검색창 */
.search-section { margin-top: 15px; padding-top: 15px; border-top: 2px solid var(--border); }
.search-row { display: flex; gap: 10px; align-items: center; }
.search-input { padding: 10px 15px; border: 1.5px solid var(--border); border-radius: 10px; font-size: 13px; font-weight: 500; outline: none; transition: 0.2s; width: 100%; box-sizing: border-box; background: var(--input-bg); color: var(--primary); }
.search-input:focus { border-color: #9cc44e; box-shadow: 0 0 8px rgba(156, 196, 78, 0.2); }
.w-1 { flex: 1; min-width: 80px; }
.w-4 { flex: 4; min-width: 200px; }

/* 버튼 및 태그 */
.opt-btn, .tag { transition: all 0.2s ease; cursor: pointer; font-weight: 600; }
.opt-btn { padding: 5px 15px; background: var(--btn-bg); border: 1.5px solid var(--border); border-radius: 30px; font-size: 13px; color: var(--text-main); }
.opt-btn:hover { background: var(--hover-bg); border-color: #9cc44e; color: #9cc44e; }
.opt-btn.active { background: #9cc44e; border-color: #9cc44e; color: white; }

.tag { padding: 3px 10px; background: var(--tag-bg); border-radius: 6px; font-size: 12px; color: var(--text-main); }
.tag::before { content: "#"; margin-right: 2px; }
.tag:hover { background: var(--hover-bg); color: #9cc44e; transform: translateY(-1px); }
.tag.active { background: #9cc44e; color: white; }

/* 헤더 컨트롤 */
.header-controls { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border); padding-top: 10px; }
.toggle-btn { display: flex; align-items: center; gap: 6px; background: none; border: none; color: var(--text-sub); font-size: 13px; font-weight: 600; cursor: pointer; }
.toggle-btn:hover { color: var(--primary); }
.toggle-icon { transition: transform 0.3s ease; }
.reset-btn { display: flex; align-items: center; gap: 5px; padding: 6px 14px; background: var(--hover-bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text-main); font-size: 12px; font-weight: 600; cursor: pointer; }

/* =========================================
   4. 메인 그리드 및 카드
   ========================================= */
.pokemon-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 12px; }

.pokemon-card { 
    background-color: var(--card-bg); 
    border-radius: 12px; 
    padding: 10px; 
    text-align: center; 
    border: 1px solid var(--border); 
    transition: all 0.3s ease; 
    cursor: pointer; 
}
.pokemon-card.highlight { border-color: #9cc44e; transform: scale(1.05); box-shadow: 0 8px 15px rgba(156, 196, 78, 0.2); z-index: 5; }
.pokemon-grid.dimmed .pokemon-card:not(.highlight) { opacity: 0.3; filter: grayscale(0.5); }
.pokemon-card:hover { transform: translateY(-8px) scale(1.05); border-color: #9cc44e; box-shadow: 0 10px 20px rgba(0,0,0,0.2); z-index: 10; }
.pokemon-card img { width: 100%; aspect-ratio: 1/1; object-fit: contain; }

.name-box { margin-top: 10px; line-height: 1.3; }
.id-number { font-size: 10px; color: var(--text-sub); font-weight: 500; }
.p-name { font-size: 13px; color: var(--text-main); font-weight: bold; display: block; margin-top: 2px; }

/* =========================================
   5. 상세 정보 모달
   ========================================= */
#detailModal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--modal-overlay); backdrop-filter: blur(5px); z-index: 2000; justify-content: center; align-items: center; }
.modal-content { background-color: var(--card-bg); color: var(--text-main); width: 90%; max-width: 650px; border-radius: 20px; padding: 40px; position: relative; display: grid; grid-template-columns: 1.2fr 1fr; gap: 30px; box-shadow: 0 20px 40px rgba(0,0,0,0.3); animation: slideUp 0.3s ease-out; transition: background-color 0.3s ease, color 0.3s ease; }
@keyframes slideUp { from { transform: translateY(50px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-close { position: absolute; top: 15px; right: 15px; cursor: pointer; background: var(--hover-bg); color: var(--text-main); border-radius: 50%; padding: 6px; border: none; z-index: 200; transition: background 0.3s ease; }
.modal-right { display: flex; flex-direction: column; gap: 15px; padding-left: 10px; padding-right: 35px; }

.modal-left { text-align: center; border-right: 1px solid var(--border); padding-right: 20px; }
.modal-img { width: 100%; max-width: 250px; object-fit: contain; margin-bottom: 20px; image-rendering: -webkit-optimize-contrast; image-rendering: crisp-edges; }
.modal-id { font-size: 18px; color: var(--text-sub); font-weight: 600; }
.modal-name { font-size: 32px; font-weight: 800; margin: 10px 0; }
.info-row { display: flex; align-items: center; gap: 15px; }
.info-row.env-row { margin-bottom: 30px; }
.info-row.flavor-row { margin-top: auto; padding-top: 10px; border-top: 1px dashed var(--border); }
.info-label { width: 60px; font-weight: 800; color: var(--text-sub); font-size: 15px; }
.info-value { font-size: 16px; font-weight: 600; background: var(--hover-bg); padding: 6px 15px; border-radius: 10px; flex: 1; }
.modal-bottom { grid-column: span 2; border-top: 1px solid var(--border); padding-top: 25px; margin-top: 10px; }
.bottom-title { font-weight: 800; margin-bottom: 15px; color: var(--text-main); }
.modal-tags { display: flex; flex-wrap: wrap; gap: 10px; }

/* =========================================
   6. 맨 위로 가기 버튼
   ========================================= */
#scrollTopBtn { display: none; position: fixed; bottom: 30px; right: 30px; z-index: 99; background-color: #9cc44e; color: white; border: none; outline: none; cursor: pointer; padding: 12px; border-radius: 50%; box-shadow: 0 4px 10px rgba(156, 196, 78, 0.3); transition: all 0.3s ease; }
#scrollTopBtn:hover { background-color: #8ab042; transform: translateY(-3px); }
#scrollTopBtn svg { width: 22px; height: 22px; display: block; }

/* =========================================
   7. 모바일 반응형
   ========================================= */
@media (max-width: 1024px) {
    .pokemon-grid { grid-template-columns: repeat(7, 1fr); }
}

@media (max-width: 768px) {
    body { padding: 80px 10px 10px 10px; }
    #topNavbar { padding: 0 15px; height: 60px; }
    .nav-logo img { height: 40px; }
    .nav-menu { margin-left: 20px; gap: 15px; }
    .nav-link { font-size: 15px; }
    
    header { padding: 15px; position: relative; top: 0; }
    .filter-container { max-height: 50vh; overflow-y: auto; }
    header.collapsed .filter-container { max-height: 0; }

    .pokemon-grid { grid-template-columns: repeat(4, 1fr); gap: 10px; }
    .search-row { flex-wrap: wrap; }
    .w-1 { flex: 1 1 30%; min-width: 80px; }
    .w-4 { flex: 1 1 100%; }

    .modal-content { grid-template-columns: 1fr; padding: 25px; max-height: 85vh; overflow-y: auto; gap: 15px; }
    .modal-left { border-right: none; border-bottom: 1px solid var(--border); padding-right: 0; padding-bottom: 15px; }
    .modal-img { max-width: 150px; margin-bottom: 10px; }
    .modal-name { font-size: 26px; }
    .modal-right { padding-right: 28px; }
    .modal-close { top: 10px; right: 10px; padding: 4px; }
    .modal-close svg { width: 18px; height: 18px; }

    #scrollTopBtn { bottom: 20px; right: 20px; padding: 10px; }
    #scrollTopBtn svg { width: 18px; height: 18px; }
}

@media (max-width: 480px) {
    .pokemon-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .filter-group { flex-direction: column; padding: 12px 0; }
    .group-label { padding-bottom: 8px; width: 100%; }
    .opt-btn { padding: 6px 12px; font-size: 12px; }
    .p-name { font-size: 12px; }
}

/* 아이콘이 화면 밖으로 밀리거나 가려지지 않도록 강제 조정 */
.theme-toggle-btn {
    margin-left: auto !important; /* 무조건 우측 끝에 붙도록 강제 */
    position: relative;
    z-index: 2000; /* 다른 투명 헤더 등에 가려지지 않도록 최상단으로 올림 */
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px; /* 아이콘이 찌그러지지 않도록 최소 너비 확보 */
}
/* =========================================
   상세 모달 3단 구조 (포켓몬 + 서식지)
   ========================================= */
.modal-content {
    width: 95%;
    max-width: 950px; /* 기존 650px에서 확장 */
    grid-template-columns: 1.2fr 1fr 1fr; /* 3단 분할 */
    gap: 20px;
}

.modal-habitat {
    border-left: 1px dashed var(--border);
    padding-left: 20px;
    display: flex;
    flex-direction: column;
}

.habitat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.habitat-nav {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--text-sub);
    font-size: 14px;
}

.habitat-nav button {
    background: var(--hover-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    padding: 4px 10px;
    color: var(--text-main);
    transition: all 0.2s;
}

.habitat-nav button:hover:not(:disabled) {
    background: #9cc44e;
    color: white;
    border-color: #9cc44e;
}

.habitat-nav button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.habitat-img {
    width: 100%;
    aspect-ratio: 1/1;
    object-fit: cover;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 12px;
    background: var(--card-bg);
}

.habitat-name {
    font-weight: 800;
    font-size: 16px;
    text-align: center;
    color: var(--text-main);
    word-break: keep-all;
}

.habitat-empty {
    text-align: center;
    color: var(--text-sub);
    margin-top: 50px;
    font-weight: 600;
    line-height: 1.5;
}

@media (max-width: 768px) {
    /* 모달창 전체 여백 및 크기 조정 */
    .modal-content { 
        width: 85%; /* 양옆 여백을 주기 위해 95%에서 85%로 축소 */
        max-width: 450px; 
        max-height: 80vh; /* 위아래 여유 공간 확보 */
        padding: 35px 20px 25px 20px; /* 위쪽 패딩을 늘려 닫기 버튼과 내용 분리 */
        grid-template-columns: 1fr; 
        gap: 15px; 
        border-radius: 20px;
        overflow-y: auto;
    }
    
    /* 닫기 버튼 크기 및 위치 조정 */
    .modal-close { 
        top: 12px; 
        right: 12px; 
        padding: 6px; 
    }
    .modal-close svg { 
        width: 20px; 
        height: 20px; 
    }

    .modal-left { 
        border-right: none; 
        border-bottom: 1px solid var(--border); 
        padding-right: 0; 
        padding-bottom: 15px; 
    }
    .modal-img { max-width: 150px; margin-bottom: 10px; }
    .modal-name { font-size: 26px; }
    .modal-right { padding-right: 0; }
    
    .modal-habitat { 
        border-left: none; 
        border-top: 1px dashed var(--border); 
        padding-left: 0; 
        padding-top: 20px; 
        margin-top: 10px; 
    }
}
