/* Professional Wiki Design System - Polished Version */
:root {
    --primary-color: #00a0e9; 
    --primary-dark: #0077b3;
    --primary-light: #f0f9ff;
    --border-color: #cccccc;
    --bg-main: #ffffff;
    --bg-side: #f5f6f7;
    --text-main: #373a3c;
    --text-muted: #777777;
    --text-link: #00a0e9;
    --header-height: 46px; /* 더 콤팩트해진 헤더 */
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text-main);
    background-color: var(--bg-side);
    line-height: 1.6;
}

/* Header & Search */
.site-header {
    background-color: var(--primary-color);
    height: var(--header-height);
    position: sticky; top: 0; z-index: 2000;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.header-content {
    max-width: 1400px; margin: 0 auto; height: 100%;
    display: flex; align-items: center; padding: 0 1rem; gap: 1rem;
}
.logo { display: flex; align-items: center; gap: 0.4rem; text-decoration: none; color: white; font-weight: 800; font-size: 0.95rem; }
.logo img { height: 16px; filter: brightness(0) invert(1); } /* 요청하신 대로 아주 작게 유지 */

.search-container { flex: 1; max-width: 400px; min-width: 0; position: relative; }
.search-input { width: 100%; padding: 0.3rem 0.7rem; border-radius: 2px; border: none; font-size: 0.85rem; outline: none; }
.search-results {
    position: absolute; top: 110%; left: 0; right: 0;
    background: white; border: 1px solid var(--border-color);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1); display: none; z-index: 3000;
}
.search-results.active { display: block; }
.search-item { padding: 0.5rem 0.8rem; border-bottom: 1px solid #f0f0f0; cursor: pointer; font-size: 0.85rem; }
.search-item:hover { background: #f8f8f8; color: var(--primary-color); }

.top-nav { display: flex; align-items: center; gap: 1rem; margin-left: auto; }
.nav-link { color: white; text-decoration: none; font-size: 0.8rem; font-weight: 700; opacity: 0.9; }
.nav-link:hover { opacity: 1; }

/* Main Wiki Layout */
.wiki-outer-container {
    max-width: 1400px; margin: 1rem auto;
    display: grid; grid-template-columns: 1fr 300px; gap: 1rem; padding: 0 0.5rem;
}

.wiki-article {
    background: var(--bg-main); border: 1px solid var(--border-color);
    padding: 2.5rem 2.5rem 15rem 2.5rem; /* 문서 아래에 충분한 공백(15rem) 추가 */
    min-height: 85vh; position: relative;
}

/* Tabs */
.wiki-tabs-wrapper { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 1rem; border-bottom: 1px solid var(--border-color); }
.wiki-tabs { display: flex; }
.wiki-tab {
    padding: 0.4rem 1rem; background: #eee; border: 1px solid var(--border-color); border-bottom: none;
    font-size: 0.8rem; color: #666; text-decoration: none; margin-right: 1px; cursor: pointer;
}
.wiki-tab.back-tab { background: #f9f9f9; color: var(--primary-color); font-weight: bold; }
.wiki-tab.back-tab:hover { background: var(--primary-light); }
.wiki-tab.active { background: white; margin-bottom: -1px; font-weight: 700; color: var(--primary-color); border-top: 2px solid var(--primary-color); }

/* Content Headers */
.wiki-title { font-size: 2.4rem; font-weight: 800; margin-bottom: 0.2rem; border-bottom: 1px solid #eee; padding-bottom: 0.5rem; }
.wiki-subtitle { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1.5rem; display: flex; justify-content: space-between; }

/* Infobox */
.infobox {
    float: right; width: 320px; border: 1px solid var(--primary-color);
    margin: 0 0 1.2rem 1.2rem; background: white; font-size: 0.85rem;
}
.infobox-title { background: var(--primary-color); color: white; padding: 0.6rem; text-align: center; font-weight: 800; font-size: 1rem; }
.infobox-image { padding: 0.5rem; text-align: center; border-bottom: 1px solid #eee; }
.infobox-image img { width: 100%; height: auto; max-height: 400px; object-fit: contain; }
.infobox-table { width: 100%; border-collapse: collapse; }
.infobox-table th { background: #f0f0f0; width: 35%; padding: 0.5rem; border: 1px solid #eee; text-align: left; }
.infobox-table td { padding: 0.5rem; border: 1px solid #eee; font-weight: 700; }

/* Content Detail */
.wiki-content h2 { 
    border-bottom: 1px solid var(--border-color); 
    padding-bottom: 0.2rem; 
    margin: 2.5rem 0 0.4rem 0; /* 제목 아래 간격을 1rem -> 0.4rem으로 대폭 줄임 */
    font-size: 1.6rem; 
    color: #000; 
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.wiki-content h3 {
    margin: 2rem 0 0.3rem 0; /* 소제목 아래 간격도 0.8rem -> 0.3rem으로 줄임 */
    font-size: 1.3rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.section-edit-link {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
    text-decoration: none;
    border: 1px solid #ddd;
    padding: 0.1rem 0.4rem;
    border-radius: 2px;
}
.section-edit-link:hover {
    background: #f8f8f8;
    color: var(--primary-color);
    border-color: var(--primary-color);
}
.wiki-content p { margin-bottom: 1.1rem; line-height: 1.8; font-size: 1rem; }
.wiki-content a { color: var(--text-link); text-decoration: none; }
.wiki-content a:hover { text-decoration: underline; }

/* Portal Home */
/* Portal Home */
.portal-card { 
    background: var(--primary-light); 
    border: 1px solid var(--primary-color); 
    border-radius: 4px; 
    padding: 1.5rem; 
    margin-bottom: 2rem; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    cursor: pointer;
    transition: 0.2s;
}
.portal-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.portal-card h2 { margin: 0; border: none; font-size: 1.5rem; }
.portal-card p { margin: 0; font-weight: 500; }

.char-grid-portal { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 1rem; }

/* Home info grid (뉴스 + 가이드) */
.home-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}
.home-info-item {
    background: #fff;
    border: 1px solid var(--border-color);
    padding: 0.7rem;
    border-radius: 4px;
}
.home-info-item h2 {
    margin-top: 0;
    border-bottom: 2px solid var(--primary-light);
    padding-bottom: 0.3rem;
    margin-bottom: 0.5rem;
    font-size: 1rem;
}
.home-info-content {
    font-size: 0.88rem;
    line-height: 1.5;
    color: #444;
}
.char-card-mini { border: 1px solid #eee; background: white; text-decoration: none; color: inherit; transition: 0.2s; }
.char-card-mini:hover { border-color: var(--primary-color); transform: translateY(-2px); }
.char-card-mini img { width: 100%; aspect-ratio: 1 / 1.1; object-fit: cover; }
.char-card-mini span { display: block; padding: 0.4rem; text-align: center; font-size: 0.8rem; font-weight: 700; }

/* Editor */
.editor-wrap { background: white; }
.field-group { margin-bottom: 1.5rem; }
.field-label { font-weight: 800; font-size: 0.9rem; margin-bottom: 0.4rem; display: block; }
.field-input, .field-textarea { width: 100%; border: 1px solid #ddd; padding: 0.6rem; border-radius: 2px; font-size: 0.9rem; outline: none; }
.field-textarea { min-height: 250px; font-family: 'Consolas', monospace; resize: vertical; line-height: 1.5; }

.btn-group { display: flex; gap: 0.8rem; margin-top: 2rem; justify-content: center; }
.btn-save { background: var(--primary-color); color: white; border: none; padding: 0.8rem 4rem; font-weight: 800; cursor: pointer; border-radius: 2px; }
.btn-cancel { background: #888; color: white; border: none; padding: 0.8rem 2rem; text-decoration: none; font-weight: 700; border-radius: 2px; }

@media (max-width: 1024px) {
    .wiki-outer-container { grid-template-columns: 1fr; }
    .wiki-sidebar { display: none; }
}

/* 최근 변경 내역 (항상 하단에 표시) */
.recent-changes-inline {
    display: block;
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--border-color);
}

/* 모바일 화면 최적화 */
@media (max-width: 768px) {
    .infobox {
        float: none !important;
        width: 100% !important;
        margin: 0 0 1.5rem 0 !important;
        display: block !important;
    }
    .infobox img {
        max-width: 100%;
        height: auto;
    }
    .wiki-article {
        padding: 1rem 0.8rem 6rem 0.8rem;
    }
    .wiki-title {
        font-size: 1.5rem;
    }
    .wiki-subtitle {
        font-size: 0.75rem;
        flex-direction: column;
        gap: 0.2rem;
    }

    /* 헤더 모바일 최적화 */
    .header-content {
        padding: 0 0.5rem;
        gap: 0.5rem;
    }
    .logo span {
        display: none; /* 로고 텍스트 숨기기 - 공간 절약 */
    }
    .top-nav {
        gap: 0.5rem;
    }
    .nav-link {
        font-size: 0.72rem;
    }

    /* 포털 카드 모바일 최적화 */
    .portal-card {
        padding: 1.2rem;
        margin-bottom: 1rem;
        flex-wrap: wrap;
        gap: 1rem;
    }
    .portal-card h2 {
        font-size: 1.2rem !important;
        margin-bottom: 0.3rem;
    }
    .portal-card p {
        font-size: 0.85rem !important;
    }
    .portal-card > span {
        font-size: 1.5rem !important;
        margin-left: auto;
    }

    /* 뉴스/가이드 그리드: 1열로 변경 */
    .home-info-grid {
        grid-template-columns: 1fr;
        gap: 0.8rem;
        margin-bottom: 2rem;
    }

    /* 캐릭터 카드 그리드 최적화 */
    .char-grid-portal {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
        gap: 0.6rem;
    }
}

/* Gallery System */
.wiki-gallery-wrap {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: #fdfdfd;
    border: 1px solid #eee;
    border-radius: 4px;
}
.gallery-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
}
.gallery-title-row h3 {
    font-size: 0.9rem;
    font-weight: 800;
    color: #444;
}
.gallery-view-btn {
    font-size: 0.75rem;
    color: var(--primary-color);
    text-decoration: none;
    border: 1px solid var(--primary-color);
    padding: 0.2rem 0.6rem;
    border-radius: 3px;
    font-weight: 700;
    cursor: pointer;
}
.gallery-view-btn:hover {
    background: var(--primary-color);
    color: white;
}
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, 80px);
    gap: 0.5rem;
    justify-content: flex-start;
}
.gallery-item {
    width: 80px;
    height: 80px;
    border: 1px solid #eee;
    overflow: hidden;
    cursor: pointer;
    background: #f8f9fa;
    border-radius: 4px;
}
.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: 0.2s;
}
.gallery-item:hover img {
    transform: scale(1.05);
}

/* Full Grid Modal */
.full-grid-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: white;
    z-index: 6000;
    display: none;
    flex-direction: column;
    padding: 2rem;
    overflow-y: auto;
}
.full-grid-modal.active { display: flex; }
.full-grid-header {
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 2px solid #333; padding-bottom: 1rem; margin-bottom: 2rem;
}
.full-grid-title { font-size: 1.5rem; font-weight: 800; color: #333; }
.full-grid-close { font-size: 2rem; cursor: pointer; color: #333; }
.full-grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
}
.grid-thumb {
    aspect-ratio: 1/1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid #ddd;
    transition: 0.2s;
}
.grid-thumb:hover { transform: translateY(-5px); box-shadow: 0 5px 15px rgba(0,0,0,0.1); }
.grid-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* Modal for Gallery */
.gallery-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.9);
    z-index: 5000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.gallery-modal.active { display: flex; }
.modal-close {
    position: absolute; top: 1rem; right: 1.5rem;
    color: white; font-size: 3rem; cursor: pointer;
    z-index: 5010;
}
.modal-content {
    max-width: 95%;
    max-height: 85vh;
    display: flex;
    justify-content: center;
    align-items: center;
}
.modal-content img {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border: 2px solid rgba(255,255,255,0.1);
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
}
.modal-nav {
    display: flex; gap: 1rem; margin-top: 1.5rem;
}
.modal-nav-btn {
    color: white; font-size: 1rem; cursor: pointer; 
    border: 1px solid rgba(255,255,255,0.3); 
    background: rgba(255,255,255,0.1);
    padding: 0.6rem 1.5rem;
    border-radius: 4px;
    transition: 0.2s;
}
.modal-nav-btn:hover {
    background: rgba(255,255,255,0.2);
    border-color: white;
}

/* Edit Gallery UI */
.edit-gallery-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 0.4rem;
    margin-top: 0.8rem;
}
.edit-gallery-item {
    position: relative;
    aspect-ratio: 1/1;
    border: 1px solid #ddd;
    border-radius: 3px;
    overflow: hidden;
}
.edit-gallery-item img { width: 100%; height: 100%; object-fit: cover; }
.remove-gallery-img {
    position: absolute; top: 2px; right: 2px;
    background: rgba(0,0,0,0.5); color: white;
    width: 20px; height: 20px; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    font-weight: bold;
    border-radius: 50%;
}
.remove-gallery-img:hover { background: #dc2626; }
.gallery-clear-btn {
    font-size: 0.75rem; color: #ff4d4f; border: 1px solid #ff4d4f;
    background: white; padding: 0.2rem 0.5rem; border-radius: 3px;
    cursor: pointer; margin-top: 0.5rem;
}
.gallery-clear-btn:hover { background: #ff4d4f; color: white; }

/* === Wiki Extended Elements === */
.wiki-quote {
    border-left: 4px solid var(--primary-color);
    padding: 0.8rem 1.2rem;
    margin: 1rem 0;
    background: var(--primary-light);
    color: #555;
    font-style: italic;
    border-radius: 0 4px 4px 0;
}
.wiki-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.9rem;
}
.wiki-table th {
    background: var(--primary-color);
    color: white;
    padding: 0.5rem 0.8rem;
    border: 1px solid var(--primary-dark);
    text-align: left;
}
.wiki-table td {
    padding: 0.5rem 0.8rem;
    border: 1px solid var(--border-color);
}
.wiki-table tr:nth-child(even) td { background: var(--primary-light); }

.wiki-spoiler {
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    margin: 1rem 0;
}
.wiki-spoiler > summary {
    padding: 0.5rem 0;
    cursor: pointer;
    font-weight: 700;
    color: var(--text-muted);
    user-select: none;
    list-style: none;
    font-size: 0.9rem;
}
.wiki-spoiler > summary:hover { color: var(--primary-color); }
.wiki-spoiler > summary::before { content: '▶ '; }
.wiki-spoiler[open] > summary::before { content: '▼ '; }
.wiki-spoiler .spoiler-content { padding: 0.8rem 0; }

.wiki-callout {
    padding: 0.6rem 0;
    margin: 0.8rem 0;
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 0.5rem;
}
.wiki-callout-note { border-color: #f0c040; color: #7d6608; }
.wiki-callout-warn { border-color: #f5a0a0; color: #a00; }

/* Preview Modal */
.preview-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 9000;
    align-items: center;
    justify-content: center;
}
.preview-modal.active { display: flex; }
.preview-modal-inner {
    background: white;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 8px;
    padding: 2rem;
    position: relative;
}
.preview-modal-close {
    position: absolute; top: 1rem; right: 1.5rem;
    font-size: 1.5rem; cursor: pointer; color: #888;
}

/* Color Palette */
.color-palette {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 6px;
    z-index: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: none;
    grid-template-columns: repeat(6, 22px);
    gap: 3px;
}
.color-palette.open { display: grid; }
.color-swatch {
    width: 22px; height: 22px;
    border-radius: 3px;
    cursor: pointer;
    border: 1px solid rgba(0,0,0,0.15);
    transition: transform 0.1s;
}
.color-swatch:hover { transform: scale(1.2); }
.color-picker-wrap { position: relative; display: inline-block; }

/* Toolbar groups */
.toolbar-sep { width: 1px; background: #ccc; margin: 2px 3px; align-self: stretch; display: inline-block; }

/* Autocomplete List */
.autocomplete-list {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 250px;
    max-height: 200px;
    overflow-y: auto;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
}
.autocomplete-list.active { display: block; }
.autocomplete-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.9rem;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--primary-light); }
.autocomplete-item img {
    width: 24px;
    height: 24px;
    object-fit: cover;
    border-radius: 2px;
}
