/* ===== CSS VARIABLES / THEMING ===== */
:root {
    --bg-page:      #f8f9fa;
    --bg-main:      #ffffff;
    --bg-infobox:   #f8f9fa;
    --bg-th:        #eaecf0;
    --bg-search:    #ffffff;
    --bg-infotype:  #cedff2;
    --text-primary: #202122;
    --text-muted:   #54595d;
    --text-caption: #444444;
    --link:         #3366cc;
    --border:       #a2a9b1;
    --border-soft:  #eaecf0;
    --border-head:  #a7d7f9;
    --shadow-head:  rgba(0,0,0,0.06);
    --tab-active-border: #3366cc;
    --radio-accent: #3366cc;
    --toc-active:   #202122;
}
body.dark {
    --bg-page:      #11151c;
    --bg-main:      #1e2329;
    --bg-infobox:   #252930;
    --bg-th:        #1e2329;
    --bg-search:    #27292b;
    --bg-infotype:  #1e3a5f;
    --text-primary: #eaecf0;
    --text-muted:   #9db5d8;
    --text-caption: #9db5d8;
    --link:         #9db5d8;
    --border:       #3a3f4b;
    --border-soft:  #2a2f38;
    --border-head:  #3a3f4b;
    --shadow-head:  rgba(0,0,0,0.3);
    --tab-active-border: #9db5d8;
    --radio-accent: #9db5d8;
    --toc-active:   #eaecf0;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, 'Linux Libertine', Georgia, Times, serif;
    font-size: 16px;
    line-height: 1.6;
    background: var(--bg-page);
    color: var(--text-primary);
    transition: background 0.2s, color 0.2s;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== HEADER ===== */
.mw-header {
    background: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px 7px;
    border-bottom: 1px solid var(--border-head);
    border-top: 3px solid #990000;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px var(--shadow-head);
    min-height: 58px;
}

.header-left { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.hamburger-menu {
    background: none; border: none; cursor: pointer;
    padding: 5px; display: flex; flex-direction: column; gap: 4px;
    border-radius: 2px;
}
.hamburger-menu:hover { background: rgba(51,102,204,0.08); }
.hamburger-menu span { display: block; width: 18px; height: 2px; background: var(--text-muted); }

.logo-container { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.logo-container img { width: 50px; height: 50px; }
.logo-text { display: flex; flex-direction: column; line-height: 1.15; }
.wiki-word {
    font-family: 'Linux Libertine','Linux Libertine O',Georgia,serif;
    font-size: 1.125rem; letter-spacing: 0.5px; color: var(--text-primary);
}
.wiki-sub { font-size: 0.6875rem; color: var(--text-muted); font-family: sans-serif; }

/* ===== SEARCH ===== */
.header-center { flex: 1; max-width: 560px; margin: 0 18px; }
.search-form { display: flex; }
.search-input-wrapper {
    flex: 1; display: flex; align-items: center; gap: 8px;
    border: 1px solid var(--border); border-right: none;
    border-radius: 2px 0 0 2px; padding: 5px 10px;
    background: var(--bg-search);
    transition: border-color 0.15s;
}
.search-input-wrapper:focus-within { border-color: var(--link); outline: 1px solid var(--link); }
.search-icon { flex-shrink: 0; opacity: 0.6; }
.search-input-wrapper input {
    border: none; outline: none; width: 100%;
    font-size: 0.9375rem; font-family: sans-serif;
    color: var(--text-primary); background: transparent;
}
.search-input-wrapper input::placeholder { color: var(--border); }
.search-btn {
    padding: 0 14px; border: 1px solid var(--border);
    border-radius: 0 2px 2px 0; background: var(--bg-infobox);
    font-size: 0.875rem; font-family: sans-serif; color: var(--text-primary);
    cursor: pointer; white-space: nowrap;
}
.search-btn:hover { background: var(--border-soft); }

/* ===== HEADER RIGHT ===== */
.header-right {
    display: flex; align-items: center; gap: 16px;
    font-size: 0.875rem; flex-shrink: 0; font-family: sans-serif;
}
.nav-link { color: var(--link); text-decoration: none; white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.nav-link:hover { text-decoration: underline; }
.donate-link { font-weight: 600; }

/* ===== INLINE SIDEBAR BUTTONS (show when sidebar hidden) ===== */
.inline-sidebar-btn {
    display: none;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 2px;
    padding: 4px 7px;
    cursor: pointer;
    color: var(--link);
    font-size: 0.8rem;
    font-family: sans-serif;
    align-items: center;
    gap: 5px;
    position: relative;
}
.inline-sidebar-btn:hover { background: rgba(51,102,204,0.08); }
.inline-sidebar-btn svg { flex-shrink: 0; }
/* Tooltip */
.inline-sidebar-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    background: var(--bg-main);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 2px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 200;
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}
.inline-sidebar-btn:hover::after { opacity: 1; }
.inline-sidebar-btn.visible { display: inline-flex; }

/* ===== MAIN GRID ===== */
.main-container {
    display: grid;
    grid-template-columns: 200px 1fr 210px;
    max-width: 1500px;
    margin: 0 auto;
    background: var(--bg-main);
    min-height: calc(100vh - 58px);
    transition: background 0.2s;
}

/* ===== SIDEBARS ===== */
.sidebar, .appearance-sidebar {
    padding: 16px 12px;
    font-size: 0.8125rem; line-height: 1.5;
    background: var(--bg-main);
    position: sticky; top: 58px;
    align-self: start;
    max-height: calc(100vh - 58px);
    overflow-y: auto;
    font-family: sans-serif;
    transition: background 0.2s;
}
.sidebar { border-right: 1px solid var(--border-soft); }
.appearance-sidebar { border-left: 1px solid var(--border-soft); }

.sidebar-collapsed .sidebar-inner,
.sidebar-collapsed #toc-list,
.sidebar-collapsed .app-section { display: none; }

.toc-header {
    display: flex; justify-content: space-between; align-items: center;
    font-weight: bold; font-size: 0.8125rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px; margin-bottom: 10px; color: var(--text-primary);
}
.hide-btn {
    border: none; background: none; color: var(--link);
    cursor: pointer; font-size: 0.75rem; padding: 0; font-family: sans-serif;
}
.hide-btn:hover { text-decoration: underline; }

#toc-list { list-style: none; padding: 0; margin: 0; }
#toc-list li { display: flex; align-items: baseline; gap: 5px; padding: 2px 0; }
#toc-list li a { color: var(--link); font-size: 0.8125rem; line-height: 1.4; }
#toc-list li a:hover { text-decoration: underline; }
.toc-num { color: var(--text-muted); font-size: 0.75rem; min-width: 16px; flex-shrink: 0; }

/* ===== ARTICLE ===== */
.article { padding: 20px 30px 40px; min-width: 0; }

.article-header {
    display: flex; justify-content: space-between; align-items: flex-end;
    border-bottom: 1px solid var(--border); padding-bottom: 3px; margin-bottom: 0;
}
.article-header-left { display: flex; align-items: center; gap: 8px; }

#firstHeading {
    font-family: 'Linux Libertine', Georgia, 'Times New Roman', Times, serif;
    font-size: 2em; font-weight: normal; margin: 0; padding: 0;
    color: var(--text-primary); line-height: 1.2; border: none;
}
.lang-selector {
    display: flex; align-items: center; gap: 5px;
    font-size: 0.8125rem; color: var(--link); cursor: pointer;
    border: 1px solid var(--border); padding: 3px 8px;
    border-radius: 2px; white-space: nowrap; margin-bottom: 4px;
    font-family: sans-serif;
}
.lang-selector:hover { background: rgba(51,102,204,0.06); }

.article-sub-nav {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.8125rem; border-bottom: 1px solid var(--border);
    margin-bottom: 16px; font-family: sans-serif;
}
.tabs { display: flex; }
.tab {
    color: var(--link); padding: 8px 14px; display: block;
    text-decoration: none; border-bottom: 3px solid transparent;
    margin-bottom: -1px; font-size: 0.8125rem;
}
.tab:hover { background: rgba(51,102,204,0.06); text-decoration: none; }
.tab.active { color: var(--toc-active); border-bottom-color: var(--tab-active-border); font-weight: 500; }
.tools { display: flex; }
.tool-link { color: var(--link); padding: 8px 10px; display: block; text-decoration: none; font-size: 0.8125rem; }
.tool-link:hover { background: rgba(51,102,204,0.06); text-decoration: none; }
.tool-link.active-tool { color: var(--toc-active); font-weight: 500; }

/* ===== CONTENT BODY ===== */
.content-body { font-size: 0.9375rem; line-height: 1.6; }
.content-body p { margin: 0 0 0.8em; }
.article-info-line {
    font-style: italic; font-size: 0.8125rem; color: var(--text-muted);
    margin: 0 0 14px; font-family: sans-serif;
}
.content-body h2 {
    font-family: 'Linux Libertine', Georgia, serif;
    font-size: 1.5em; font-weight: normal;
    border-bottom: 1px solid var(--border);
    padding: 8px 0 4px; margin: 20px 0 10px;
    color: var(--text-primary); clear: none;
}
.wiki-section { margin-bottom: 4px; }

/* ===== INFOBOX ===== */
.infobox {
    float: right; clear: right; width: 260px;
    background: var(--bg-infobox); border: 1px solid var(--border);
    margin: 0 0 16px 24px; padding: 6px;
    font-size: 0.8125rem; line-height: 1.4; font-family: sans-serif;
}
.infobox-name {
    text-align: center; font-size: 1.05em; font-weight: bold;
    padding: 4px 0 6px; border-bottom: 2px solid var(--border);
    margin-bottom: 6px; color: var(--text-primary);
}
.infobox-type {
    text-align: center; background: var(--bg-infotype);
    border: 1px solid var(--border); margin: 0 0 8px;
    padding: 2px 4px; font-size: 0.75rem; color: var(--text-primary);
}
.image-box {
    text-align: center; background: var(--bg-main);
    border: 1px solid var(--border-soft); margin-bottom: 8px; padding: 4px;
}
.image-box img { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.caption { font-size: 0.7rem; color: var(--text-caption); margin: 4px 0 0; line-height: 1.3; }
.infobox-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.infobox-table th, .infobox-table td { padding: 3px 5px; vertical-align: top; border: 1px solid var(--border); }
.infobox-table th { background: var(--bg-th); font-weight: normal; text-align: left; width: 42%; color: var(--text-primary); }
.infobox-table td { color: var(--text-primary); }
.status-secure { color: #14866d; font-weight: bold; }

/* ===== APPEARANCE SIDEBAR ===== */
.app-section { margin-bottom: 16px; font-family: sans-serif; }
.app-label {
    display: block; font-size: 0.6875rem; font-weight: bold;
    color: var(--text-muted); text-transform: uppercase;
    letter-spacing: 0.07em; margin-bottom: 6px;
}
.radio-group { display: flex; flex-direction: column; gap: 2px; }
.radio-row {
    display: flex; align-items: center; gap: 7px;
    font-size: 0.8125rem; cursor: pointer; padding: 3px 5px;
    border-radius: 3px; color: var(--text-primary);
}
.radio-row:hover { background: rgba(51,102,204,0.06); }
.radio-row input[type="radio"] { accent-color: var(--radio-accent); cursor: pointer; }

/* ===== FOOTER ===== */
.footer-hr { border: none; border-top: 1px solid var(--border); margin: 0 0 12px; }
.mw-footer { margin-top: 40px; clear: both; font-size: 0.75rem; color: var(--text-muted); font-family: sans-serif; line-height: 1.5; }
.mw-footer p { margin: 0 0 6px; }
.mw-footer a { color: var(--link); }

/* ===== SCROLLBAR ===== */
.sidebar::-webkit-scrollbar, .appearance-sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb, .appearance-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }