:root {
    --bg-color: #0f0f0f; 
    --card-bg: #1a1a1a; 
    --text-color: #d4c4a9;
    --accent-color: #c7b377; 
    --border-color: #333; 
    --active-border: #a08d55;
    --rune-orange: #dba858; 
    --effect-color: #51688b;
}

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

body { 
    font-family: 'Malgun Gothic', sans-serif; 
    background-color: var(--bg-color); 
    color: var(--text-color); 
    padding: 20px; 
    line-height: 1.6; 
}

header { 
    text-align: center; 
    margin-bottom: 30px; 
    padding: 20px 0; 
    border-bottom: 1px solid var(--border-color); 
}

h1 { font-size: 2rem; color: var(--accent-color); margin-bottom: 10px; }
p { color: #888; font-size: 0.9rem; }
h2 { color: var(--accent-color); margin: 30px 0 15px; text-align: center; }

/* Grid & Layout */
.rune-container { 
    display: grid; 
    grid-template-columns: repeat(9, 1fr); 
    gap: 8px; 
    max-width: 750px; 
    margin: 0 auto; 
    background-color: #0a0a0a; 
    padding: 15px; 
    border: 2px solid #332a1e; 
    box-shadow: inset 0 0 20px rgba(0,0,0,1); 
}

.filter-section { 
    max-width: 1200px; 
    margin: 0 auto 40px; 
    background-color: #151515; 
    padding: 25px; 
    border-radius: 10px; 
    border: 1px solid #333; 
}

.filter-group h3 { 
    font-size: 1rem; 
    color: var(--accent-color); 
    margin-bottom: 15px; 
    border-left: 3px solid var(--accent-color); 
    padding-left: 10px; 
}

.filter-controls { 
    display: flex; /* Flex로 변경 (줄바꿈 대응) */
    flex-wrap: wrap;
    gap: 30px; 
    margin-top: 30px; 
    padding-top: 20px; 
    border-top: 1px solid #333; 
}

.tag-container { display: flex; flex-wrap: wrap; gap: 10px; }

/* Interactive Elements */
.filter-tag { 
    background-color: #000; 
    border: 1px solid #444; 
    color: #888; 
    padding: 6px 15px; 
    border-radius: 20px; 
    font-size: 0.85rem; 
    cursor: pointer; 
    transition: all 0.2s; 
}
.filter-tag:hover { border-color: var(--rune-orange); color: #ccc; }
.filter-tag.active { background-color: var(--rune-orange); border-color: var(--rune-orange); color: #000; font-weight: bold; }

/* Rune Card Styles */
.rune-card { 
    background-color: #1a1a1a; 
    border: 1px solid #3d3020; 
    aspect-ratio: 1/1; 
    padding: 5px; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    cursor: pointer; 
    position: relative; 
    user-select: none; 
    min-height: 70px; 
    
    /* 💡 3D 회전 애니메이션 효과 적용 */
    transition: all 0.1s ease, transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

/* =========================================
   내 보관함(보유 룬 기반) 버튼
========================================= */
.personalize-btn-container {
    grid-column: span 3; 
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
}

/* 기본 상태: 묵직한 돌 질감과 황금색(디아블로 테마) */
.personalize-btn {
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, #2b2b2b, #141414);
    color: #c7b377;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    font-family: inherit;
    letter-spacing: 1px;
    border: none;
    
    box-shadow: 
        inset 0 3px 8px rgba(0,0,0,0.8),
        inset 0 -2px 5px rgba(255,255,255,0.05),
        0 0 0 1px #000,
        0 0 0 3px #3d3020,
        0 5px 10px rgba(0,0,0,0.5);
        
    text-shadow: 0 2px 2px rgba(0,0,0,0.8);
    transition: all 0.3s ease;
    position: relative;
    top: 0;
}

.personalize-btn:hover {
    background: linear-gradient(to bottom, #353535, #1a1a1a);
    color: var(--rune-orange);
}

.personalize-btn:active {
    top: 2px;
    box-shadow: 
        inset 0 4px 10px rgba(0,0,0,0.9),
        inset 0 -1px 3px rgba(255,255,255,0.02),
        0 0 0 1px #000,
        0 0 0 3px #3d3020,
        0 2px 5px rgba(0,0,0,0.6);
}

/* 활성화 상태 (.active): 자수정(보라색) 테마로 전환 */
.personalize-btn.active {
    background: linear-gradient(to bottom, #2c1e33, #150c1a);
    color: #bfa3cc; 
    box-shadow: 
        inset 0 3px 8px rgba(0,0,0,0.8),
        inset 0 -2px 5px rgba(255,255,255,0.05),
        0 0 0 1px #000,
        0 0 0 3px #382240,
        0 5px 10px rgba(0,0,0,0.5);
}

.personalize-btn.active:hover {
    background: linear-gradient(to bottom, #382540, #1b1022);
    color: #d8bce8;
}

.personalize-btn.active:active {
    top: 2px;
    box-shadow: 
        inset 0 4px 10px rgba(0,0,0,0.9),
        inset 0 -1px 3px rgba(255,255,255,0.02),
        0 0 0 1px #000,
        0 0 0 3px #382240,
        0 2px 5px rgba(0,0,0,0.6);
}

/* =========================================
   개인화 모드 (.personalize-mode) 테마 전환
========================================= */
/* 1. 카드가 360도 회전하며 은은한 보랏빛 배경으로 변경 */
.personalize-mode .rune-card:not(.empty) {
    transform: rotateY(360deg);
    background-color: #1e1525;
    border-color: #382240;
}

/* 2. 마우스 호버 시 보라색 효과 */
.personalize-mode .rune-card:hover:not(.empty) {
    background-color: #2c1a35;
    border-color: #8e44ad;
}

/* 3. 룬을 선택했을 때 황금색 대신 보라색 테두리와 네온 효과 */
.personalize-mode .rune-card.selected {
    background-color: #2b1331;
    border-color: #9b59b6;
    box-shadow: 0 0 10px rgba(155, 89, 182, 0.5);
}

/* =========================================
   내 보관함(보유 룬 기반) 버튼
========================================= */
.personalize-btn-container {
    grid-column: span 3; 
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
}

/* 💡 기본 상태: 묵직한 돌 질감과 황금색(디아블로 테마) */
.personalize-btn {
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, #2b2b2b, #141414);
    color: #c7b377;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    font-family: inherit;
    letter-spacing: 1px;
    border: none;
    
    box-shadow: 
        inset 0 3px 8px rgba(0,0,0,0.8),
        inset 0 -2px 5px rgba(255,255,255,0.05),
        0 0 0 1px #000,
        0 0 0 3px #3d3020, /* 기본 갈색 테두리 */
        0 5px 10px rgba(0,0,0,0.5);
        
    text-shadow: 0 2px 2px rgba(0,0,0,0.8);
    transition: all 0.3s ease;
    position: relative;
    top: 0;
}

.personalize-btn:hover {
    background: linear-gradient(to bottom, #353535, #1a1a1a);
    color: var(--rune-orange);
}

.personalize-btn:active {
    top: 2px;
    box-shadow: 
        inset 0 4px 10px rgba(0,0,0,0.9),
        inset 0 -1px 3px rgba(255,255,255,0.02),
        0 0 0 1px #000,
        0 0 0 3px #3d3020,
        0 2px 5px rgba(0,0,0,0.6);
}

/* 💡 활성화 상태 (.active): 자수정(보라색) 테마로 전환 */
.personalize-btn.active {
    background: linear-gradient(to bottom, #2c1e33, #150c1a);
    color: #bfa3cc; 
    box-shadow: 
        inset 0 3px 8px rgba(0,0,0,0.8),
        inset 0 -2px 5px rgba(255,255,255,0.05),
        0 0 0 1px #000,
        0 0 0 3px #382240, /* 보랏빛 돌 테두리 */
        0 5px 10px rgba(0,0,0,0.5);
}

.personalize-btn.active:hover {
    background: linear-gradient(to bottom, #382540, #1b1022);
    color: #d8bce8;
}

.personalize-btn.active:active {
    top: 2px;
    box-shadow: 
        inset 0 4px 10px rgba(0,0,0,0.9),
        inset 0 -1px 3px rgba(255,255,255,0.02),
        0 0 0 1px #000,
        0 0 0 3px #382240,
        0 2px 5px rgba(0,0,0,0.6);
}


.rune-card.empty { 
    background-color: #080808; 
    border: 1px solid #151515; 
    cursor: default; 
    pointer-events: none; 
    box-shadow: inset 0 0 5px rgba(0,0,0,0.5); 
}
.rune-card:hover:not(.empty) { background-color: #252525; border-color: #c7b377; z-index: 10; opacity: 1; }
.rune-card.selected { background-color: #2a2215; border-color: #dba858; box-shadow: 0 0 8px rgba(219, 168, 88, 0.4); opacity: 1 !important; }

/* [수정됨] 룬 아이콘 (이미지 대응) */
.rune-icon { 
    width: 100%; 
    height: 100%; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    overflow: hidden;
    margin-bottom: 2px;
    font-weight: bold; 
    font-size: 0.8rem;
    color: #dba858;
}

.rune-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(1px 1px 2px #000);
}

.rune-name { font-size: 0.7rem; color: #888; }

/* Runeword List */
.runeword-container { 
    max-width: 1200px; 
    margin: 0 auto; 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); 
    gap: 20px; 
}
.runeword-card { background-color: var(--card-bg); border: 1px solid var(--border-color); padding: 20px; border-radius: 8px; }
.runeword-name { font-size: 1.2rem; color: var(--rune-orange); margin-bottom: 4px; font-weight: bold; }
.runeword-info { font-size: 0.85rem; color: #aaa; margin-bottom: 12px; }
.rw-level { color: var(--accent-color); font-weight: bold; }
.runeword-runes { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 15px; align-items: center; }

.rw-rune-item { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; transition: transform 0.2s; }
.rw-rune-item:hover { transform: scale(1.1); }

/* [수정됨] 리스트 내 작은 아이콘 */
.rw-rune-icon { 
    width: 32px; 
    height: 32px; 
    background-color: transparent; 
    border-radius: 4px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-weight: bold; 
    color: var(--rune-orange); 
    font-size: 0.8rem; 
}

.rw-rune-name { font-size: 0.7rem; color: #888; }

.runeword-effects { font-size: 0.85rem; color: var(--effect-color); border-top: 1px solid #333; padding-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.effect-line { position: relative; padding-left: 12px; }
.effect-line::before { content: "•"; position: absolute; left: 0; color: var(--accent-color); }

/* =========================================
   [최종] 선택된 룬 자체 발광 효과 (배경/테두리 없음)
========================================= */
.rw-rune-icon.highlight-aura {
    /* 배경 효과는 모두 없애고 크기 커지는 애니메이션만 유지 */
    transform: scale(1.15); 
    transition: all 0.3s ease;
}

.rw-rune-icon.highlight-aura img {
    /* 1. brightness(1.3): 룬 이미지 자체를 30% 더 밝게
       2. 첫 번째 drop-shadow: 룬 바로 겉면에 강렬한 금빛
       3. 두 번째 drop-shadow: 조금 더 넓은 범위로 퍼지는 주황빛 */
    filter: brightness(1.3) 
            drop-shadow(0 0 6px rgba(255, 215, 0, 1)) 
            drop-shadow(0 0 10px rgba(255, 140, 0, 0.9));
    transition: filter 0.3s ease;
}

/* Tooltip */
#tooltip { 
    position: fixed; 
    display: none; 
    background-color: rgba(0, 0, 0, 0.9); 
    border: 1px solid var(--accent-color); 
    padding: 12px; 
    color: #fff; 
    font-size: 0.85rem; 
    z-index: 1000; 
    pointer-events: none; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.8); 
    max-width: 250px; 
}
.tooltip-title { color: var(--rune-orange); font-weight: bold; font-size: 1rem; margin-bottom: 5px; }
.tooltip-level { color: #888; margin-bottom: 8px; font-size: 0.75rem; }
.tooltip-section { margin-top: 5px; border-top: 1px solid #333; padding-top: 5px; }
.tooltip-label { color: var(--accent-color); font-weight: bold; font-size: 0.8rem; }
.tooltip-value { color: var(--effect-color); }

/* =========================================
   📱 모바일 최적화 (반응형 UI)
========================================= */
@media screen and (max-width: 768px) {
    /* 1. 필터 섹션(룬 그리드와 카테고리)을 가로에서 세로로 변경 */
    .filter-section {
        flex-direction: column;
    }
    
    .filter-controls {
        margin-left: 0;
        margin-top: 20px;
    }

    /* 2. 룬 배열 컨테이너에 가로 스크롤 추가 (화면 밖으로 튀어나가는 것 방지) */
    .rune-container {
        overflow-x: auto;
        padding-bottom: 15px;
    }

    /* 3. 룬워드 리스트의 폰트 및 여백을 모바일에 맞게 축소 */
    .runeword-card {
        padding: 15px;
    }

    .runeword-name {
        font-size: 1.2rem;
    }

    .rw-type, .rw-level, .rw-sockets {
        font-size: 0.8rem;
    }

    .runeword-effects {
        font-size: 0.8rem;
    }

    /* 4. 검색창 너비를 화면에 꽉 차게 변경 */
    #search-input {
        width: 95%;
        font-size: 0.95rem;
    }
}

/* 룬워드 리스트의 '홈(소켓)' 텍스트 색상 및 굵기 변경 */
.rw-sockets {
    color: #8ab865 !important; /* 디아블로 특유의 짙은 황금색 */
    font-weight: bold !important;
}

/* =========================================
   최적화: 분리된 인라인 스타일 (index.html에서 이관)
========================================= */
#main-title {
    cursor: pointer;
    display: inline-block;
}

.search-section {
    max-width: 1200px; 
    margin: 0 auto 20px; 
    display: flex; 
    flex-direction: row; 
    justify-content: center; 
    align-items: center; 
    gap: 10px; 
    padding: 0 10px;
}

.search-input-field {
    flex: 1; 
    max-width: 500px; 
    padding: 12px; 
    font-size: 1rem; 
    background-color: #222; 
    border: 1px solid #444; 
    color: var(--text-color); 
    border-radius: 5px;
}

.sort-dropdown {
    padding: 12px; 
    font-size: 0.95rem; 
    background-color: #222; 
    border: 1px solid #444; 
    color: var(--rune-orange); 
    border-radius: 5px; 
    cursor: pointer; 
    outline: none; 
    min-width: 130px;
}

/* =========================================
   최적화 Step C: 자바스크립트에서 분리된 인라인 스타일
========================================= */
.empty-result { grid-column: 1/-1; text-align: center; color: #888; padding: 30px; }
.rune-plus { color: #444; margin-top: -15px; }
.rw-rune-name.active-text { color: var(--rune-orange); font-weight: bold; }
.rw-type { color: #aaa; }
.rw-subtype { color: #d4c4a9; font-size: 0.8em; margin-left: 5px; }
.rw-note { color: #e05a5a; font-size: 0.85em; margin-top: 8px; padding-top: 5px; border-top: 1px dashed #333; }

/* =========================================
   래더 전용 깃발 아이콘 스타일
========================================= */
.runeword-card {
    position: relative; /* 깃발의 기준점이 되도록 설정 (기존에 있다면 생략) */
}

.ladder-flag {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 35px; /* 깃발의 크기. 취향에 맞게 조절해 */
    height: auto;
    filter: drop-shadow(1px 1px 3px rgba(0,0,0,0.8));
    z-index: 5;
}

/* =========================================
   래더 토글 버튼 및 비활성화 상태 UI
========================================= */
/* 토글 버튼 자체 스타일 */
.ladder-toggle-btn {
    width: 30px;
    height: auto;
    cursor: pointer;
    transition: all 0.3s ease;
    filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.8));
}

/* 버튼이 꺼졌을 때 (흑백 + 투명도) */
.ladder-toggle-btn.inactive {
    filter: grayscale(100%) opacity(40%);
}

/* 리스트가 스탠다드 모드일 때 래더 전용 카드의 상태 */
.ladder-inactive-mode .runeword-card.is-ladder {
    opacity: 0.3; /* 카드 전체를 흐리게 */
    filter: grayscale(100%); /* 흑백 처리 */
    cursor: not-allowed;
}

/* 흐려진 카드에 마우스를 올렸을 때 뜨는 툴팁 (CSS만으로 구현) */
.ladder-inactive-mode .runeword-card.is-ladder::after {
    content: '래더에서만 제작 가능';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.9);
    color: #ff4444;
    padding: 8px 16px;
    border: 1px solid #ff4444;
    border-radius: 5px;
    font-weight: bold;
    font-size: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    z-index: 10;
    white-space: nowrap;
}

/* 마우스 호버 시 툴팁 나타남 */
.ladder-inactive-mode .runeword-card.is-ladder:hover::after {
    opacity: 1;
}

/* =========================================
   상단 네비게이션 바 (GNB) 스타일 - 디아블로 뱃지 테마 적용
========================================= */
.top-nav {
    margin-top: 25px;
    display: flex;
    justify-content: center;
}

.top-nav ul {
    list-style: none;
    display: flex;
    gap: 15px; /* 메뉴 버튼 사이의 간격 */
    padding: 0;
    margin: 0;
}

/* 💡 기존 둥근 테두리를 제거하고 뱃지 디자인 적용 */
.top-nav a {
    display: inline-block;
    text-decoration: none;
    color: #a0a0a0; /* 차분하고 탁한 텍스트 색상 */
    font-size: 0.95rem;
    padding: 6px 16px;
    
    /* 디아블로 뱃지 특유의 질감과 테두리 */
    background-color: #151515; 
    border: 1px solid #3d3020; 
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.9);
    outline: 1px solid #0a0a0a;
    
    transition: all 0.2s ease;
}

/* 마우스를 올렸을 때의 호버 효과 */
.top-nav a:hover:not(.disabled) {
    color: var(--rune-orange);
    background-color: #1a1a1a;
    border-color: #7a6040; /* 테두리 색상 살짝 밝게 */
}

/* 현재 머물고 있는 페이지 (활성화 상태) */
.top-nav a.active {
    color: var(--rune-orange);
    background-color: #221a10; /* 살짝 오렌지빛이 도는 짙은 갈색 배경 */
    border-color: var(--rune-orange);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.9);
    font-weight: bold;
}

/* 준비 중인 메뉴 (비활성화 상태) */
.top-nav a.disabled {
    color: #444;
    cursor: not-allowed;
    background-color: #111;
    border-color: #222;
}

/* =========================================
   디아블로 스타일 텍스트 뱃지 UI
========================================= */
.d2-badge {
    display: inline-block;
    background-color: #151515; /* 아주 어두운 회색 배경 */
    border: 1px solid #3d3020; /* 룬 카드와 통일감 있는 어두운 갈색 테두리 */
    color: #a0a0a0; /* 차분하고 탁한 텍스트 색상 */
    padding: 3px 10px;
    font-size: 0.85rem;
    line-height: 1.2;
    /* 내부 그림자로 안쪽이 깊어 보이는 입체감 부여 */
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.9);
    /* 바깥쪽에 검은색 테두리를 한 겹 더 둘러서 액자 같은 느낌 강조 */
    outline: 1px solid #0a0a0a; 
    vertical-align: middle;
}

/* =========================================
   최상단 이동 버튼 (Scroll to Top)
========================================= */
.scroll-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 45px;
    height: 45px;
    background-color: #151515;
    color: var(--rune-orange);
    border: 1px solid #3d3020;
    border-radius: 50%; /* 완전한 원형 */
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.8), inset 0 0 8px rgba(0, 0, 0, 0.9);
    outline: 1px solid #0a0a0a;
    
    /* 기본 상태는 투명하게 숨김 */
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
}

/* 마우스 호버 시 살짝 떠오르는 효과 */
.scroll-to-top:hover {
    background-color: #221a10;
    border-color: var(--rune-orange);
    transform: translateY(-3px);
}

/* 자바스크립트로 스크롤을 내렸을 때 클래스가 추가되며 나타남 */
.scroll-to-top.show {
    opacity: 1;
    visibility: visible;
}

/* =========================================
   되돌리기(초기화) 1x1 버튼 
========================================= */
.rune-card.reset-card {
    background: linear-gradient(to bottom, #2b2b2b, #141414);
}

.rune-card.reset-card:hover {
    border-color: #c0392b;
    box-shadow: 0 0 10px rgba(192, 57, 43, 0.4);
}

.rune-card.reset-card:hover .rune-icon,
.rune-card.reset-card:hover .rune-name {
    color: #e74c3c !important;
}

.rune-card.reset-card:active {
    transform: translateY(2px) scale(0.95);
}

/* 💡 개인화 모드(보랏빛)가 켜져도 초기화 버튼은 고유의 색상과 붉은 호버 효과 유지 */
.personalize-mode .rune-card.reset-card {
    background: linear-gradient(to bottom, #2b2b2b, #141414) !important;
    border-color: #3d3020 !important; 
}

.personalize-mode .rune-card.reset-card:hover {
    border-color: #c0392b !important;
    box-shadow: 0 0 10px rgba(192, 57, 43, 0.4) !important;
}

.personalize-mode .rune-card.reset-card:hover .rune-icon,
.personalize-mode .rune-card.reset-card:hover .rune-name {
    color: #e74c3c !important;
}