/* ═══════════════════════════════════════════════════════════════
   CUCH.org — Chinese Universal Content Hub
   Wikipedia-inspired encyclopedia design
   ═══════════════════════════════════════════════════════════════ */

/* Screen reader only — visually hidden but available to assistive tech */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus visible — keyboard navigation indicator */
:focus-visible {
    outline: 2px solid var(--accent, #c8102e);
    outline-offset: 2px;
}

:root {
    --primary: #1a3a5c;
    --primary-light: #2d5f8a;
    --primary-dark: #0f2440;
    --accent: #c8102e;
    --accent-light: #e8384f;
    --bg: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #eaecf0;
    --text: #202122;
    --text-secondary: #54595d;
    --text-muted: #72777d;
    --border: #a2a9b1;
    --border-light: #c8ccd1;
    --link: #0645ad;
    --link-hover: #0b0080;
    --link-visited: #5a3696;
    --success: #00af89;
    --warning: #fc3;
    --error: #d33;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.1);
    --radius: 4px;
    --max-width: 1200px;
    --header-height: 56px;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', 'Noto Sans SC', 'Noto Sans JP', 'Noto Sans KR', sans-serif;
    color: var(--text);
    background: var(--bg-secondary);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--link);
    text-decoration: none;
    transition: color 0.2s;
}

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

a:visited {
    color: var(--link-visited);
}

img {
    max-width: 100%;
    height: auto;
}

/* ─── Header ────────────────────────────────────────────────── */

.site-header {
    background: var(--primary);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow-md);
}

.header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    height: var(--header-height);
    gap: 1.5rem;
}

.site-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #fff;
    font-size: 1.4rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.site-logo:hover {
    color: #fff;
    text-decoration: none;
}

.site-logo .logo-icon {
    font-size: 1.6rem;
    background: var(--accent);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-family: serif;
}

.site-logo .logo-subtitle {
    font-size: 0.65rem;
    font-weight: 400;
    opacity: 0.8;
    display: block;
    line-height: 1.1;
}

/* Search bar */
.search-bar {
    flex: 1;
    max-width: 500px;
    position: relative;
}

.search-bar input {
    width: 100%;
    padding: 0.45rem 0.75rem 0.45rem 2.2rem;
    border: none;
    border-radius: 20px;
    font-size: 0.9rem;
    background: rgba(255,255,255,0.15);
    color: #fff;
    outline: none;
    transition: background 0.2s;
}

.search-bar input::placeholder {
    color: rgba(255,255,255,0.6);
}

.search-bar input:focus {
    background: rgba(255,255,255,0.25);
}

.search-bar .search-icon {
    position: absolute;
    left: 0.7rem;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255,255,255,0.6);
    font-size: 0.85rem;
}

/* Navigation */
.header-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.header-nav a {
    color: rgba(255,255,255,0.85);
    padding: 0.35rem 0.6rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    text-decoration: none;
    transition: background 0.2s;
    white-space: nowrap;
}

.header-nav a:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
    text-decoration: none;
}

/* Language selector */
.lang-selector {
    position: relative;
}

.lang-btn {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.25);
    color: #fff;
    padding: 0.35rem 0.6rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.lang-btn:hover {
    background: rgba(255,255,255,0.2);
}

.lang-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 180px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 1001;
    margin-top: 0.25rem;
}

.lang-selector:hover .lang-dropdown,
.lang-dropdown.active {
    display: block;
}

.lang-dropdown a {
    display: block;
    padding: 0.4rem 0.75rem;
    color: var(--text);
    font-size: 0.85rem;
    border-bottom: 1px solid var(--bg-tertiary);
}

.lang-dropdown a:hover {
    background: var(--bg-secondary);
    text-decoration: none;
    color: var(--link);
}

.lang-dropdown a.active-lang {
    font-weight: 600;
    color: var(--primary);
}

/* ─── Main layout ───────────────────────────────────────────── */

.page-container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 1.5rem 1rem;
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 1.5rem;
}

.page-container.full-width {
    grid-template-columns: 1fr;
}

.main-content {
    min-width: 0;
}

/* ─── Sidebar ───────────────────────────────────────────────── */

.sidebar {
    font-size: 0.875rem;
}

.sidebar-box {
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    overflow: hidden;
}

.sidebar-box h3 {
    background: var(--bg-tertiary);
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
}

.sidebar-box ul {
    list-style: none;
    padding: 0.5rem 0;
}

.sidebar-box li a {
    display: block;
    padding: 0.3rem 0.75rem;
    color: var(--link);
    font-size: 0.85rem;
}

.sidebar-box li a:hover {
    background: var(--bg-secondary);
    text-decoration: none;
}

.sidebar-box li.active a {
    font-weight: 600;
    color: var(--primary);
    background: var(--bg-secondary);
}

/* ─── Breadcrumbs ───────────────────────────────────────────── */

.breadcrumbs {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.breadcrumbs a {
    color: var(--link);
}

.breadcrumbs span {
    margin: 0 0.3rem;
}

/* ─── Article content ───────────────────────────────────────── */

.article-card {
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.article-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--bg-tertiary);
}

.article-header h1 {
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    margin-bottom: 0.5rem;
}

.article-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.article-meta span {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

/* TOC */
.toc-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    max-width: 400px;
}

.toc-box h2 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.toc-box ul {
    list-style: none;
    padding-left: 0;
}

.toc-box ul ul {
    padding-left: 1rem;
}

.toc-box li {
    margin-bottom: 0.2rem;
}

.toc-box a {
    font-size: 0.85rem;
    color: var(--link);
}

/* Article body (rendered markdown) */
.article-body {
    line-height: 1.75;
    font-size: 0.95rem;
}

.article-body h2 {
    font-size: 1.4rem;
    font-weight: 600;
    margin: 1.5rem 0 0.75rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--bg-tertiary);
    color: var(--text);
}

.article-body h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 1.25rem 0 0.5rem;
    color: var(--text);
}

.article-body h4 {
    font-size: 1rem;
    font-weight: 600;
    margin: 1rem 0 0.4rem;
}

.article-body p {
    margin-bottom: 0.75rem;
}

.article-body ul, .article-body ol {
    margin: 0.5rem 0 0.75rem 1.5rem;
}

.article-body li {
    margin-bottom: 0.25rem;
}

.article-body blockquote {
    border-left: 3px solid var(--primary-light);
    padding: 0.5rem 1rem;
    margin: 0.75rem 0;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-style: italic;
}

.article-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.9rem;
}

.article-body th, .article-body td {
    border: 1px solid var(--border-light);
    padding: 0.5rem 0.75rem;
    text-align: left;
}

.article-body th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.article-body code {
    background: var(--bg-tertiary);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.88em;
}

.article-body pre {
    background: var(--primary-dark);
    color: #e8e8e8;
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 0.75rem 0;
}

.article-body pre code {
    background: none;
    padding: 0;
    color: inherit;
}

/* Infobox (Wikipedia-style) */
.infobox {
    float: right;
    clear: right;
    width: 280px;
    margin: 0 0 1rem 1.5rem;
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    overflow: hidden;
    font-size: 0.85rem;
}

.infobox-header {
    background: var(--primary);
    color: #fff;
    padding: 0.6rem 0.75rem;
    font-weight: 600;
    text-align: center;
}

.infobox-image {
    width: 100%;
    background: var(--bg-secondary);
    text-align: center;
    padding: 0.5rem;
}

.infobox-image img {
    max-width: 100%;
    max-height: 200px;
    object-fit: contain;
}

.infobox-caption {
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 0.25rem 0.5rem;
    text-align: center;
}

.infobox-row {
    display: flex;
    border-top: 1px solid var(--bg-tertiary);
}

.infobox-label {
    width: 40%;
    padding: 0.4rem 0.5rem;
    background: var(--bg-secondary);
    font-weight: 500;
    color: var(--text-secondary);
}

.infobox-value {
    width: 60%;
    padding: 0.4rem 0.5rem;
}

/* Category badges */
.category-badges {
    margin: 1rem 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.category-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: 12px;
    font-size: 0.78rem;
    text-decoration: none;
    transition: background 0.2s;
}

.category-badge:hover {
    background: var(--primary-light);
    color: #fff;
    text-decoration: none;
}

/* ─── Homepage ──────────────────────────────────────────────── */

.hero {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    padding: 3rem 2rem;
    text-align: center;
    border-radius: var(--radius);
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
}

.hero h1 {
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.hero .hero-sub {
    font-size: 1.1rem;
    opacity: 0.85;
    margin-bottom: 1.5rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.hero-search {
    max-width: 500px;
    margin: 0 auto 1.5rem;
    display: flex;
    gap: 0.5rem;
}

.hero-search input {
    flex: 1;
    padding: 0.6rem 1rem;
    border: none;
    border-radius: 20px;
    font-size: 1rem;
    outline: none;
}

.hero-search button {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.6rem 1.25rem;
    border-radius: 20px;
    font-size: 0.95rem;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.hero-search button:hover {
    background: var(--accent-light);
}

.hero-stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-top: 1rem;
    font-size: 0.9rem;
}

.hero-stats .stat {
    text-align: center;
}

.hero-stats .stat-number {
    font-size: 1.5rem;
    font-weight: 700;
    display: block;
}

.hero-stats .stat-label {
    opacity: 0.75;
    font-size: 0.8rem;
}

/* Language grid */
.lang-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.5rem;
    margin: 1.5rem 0;
}

.lang-grid a {
    display: block;
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    text-align: center;
    font-size: 0.85rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.lang-grid a:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow);
    text-decoration: none;
}

.lang-grid .lang-code {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

/* Article list */
.article-list {
    display: grid;
    gap: 0.75rem;
}

.article-item {
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    transition: box-shadow 0.2s;
}

.article-item:hover {
    box-shadow: var(--shadow-md);
}

.article-item h3 {
    font-size: 1.05rem;
    margin-bottom: 0.3rem;
}

.article-item h3 a {
    color: var(--link);
}

.article-item .article-summary {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.article-item .article-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ─── Section headers ───────────────────────────────────────── */

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary-light);
}

.section-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary);
}

.section-header a {
    font-size: 0.85rem;
}

/* ─── Footer ────────────────────────────────────────────────── */

.site-footer {
    background: var(--primary-dark);
    color: rgba(255,255,255,0.8);
    padding: 2rem 0;
    margin-top: 3rem;
}

.footer-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 2rem;
}

.footer-col h4 {
    color: #fff;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.footer-col ul {
    list-style: none;
}

.footer-col li {
    margin-bottom: 0.3rem;
}

.footer-col a {
    color: rgba(255,255,255,0.7);
    font-size: 0.82rem;
}

.footer-col a:hover {
    color: #fff;
    text-decoration: none;
}

.footer-bottom {
    max-width: var(--max-width);
    margin: 1.5rem auto 0;
    padding: 1rem 1rem 0;
    border-top: 1px solid rgba(255,255,255,0.15);
    text-align: center;
    font-size: 0.78rem;
    color: rgba(255,255,255,0.5);
}

/* ─── Pagination ────────────────────────────────────────────── */

.pagination {
    display: flex;
    gap: 0.3rem;
    justify-content: center;
    margin: 2rem 0;
}

.pagination a, .pagination span {
    padding: 0.4rem 0.7rem;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    font-size: 0.85rem;
}

.pagination a:hover {
    background: var(--bg-secondary);
    text-decoration: none;
}

.pagination .active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.pagination .disabled {
    color: var(--text-muted);
    opacity: 0.5;
}

/* ─── Search results ────────────────────────────────────────── */

.search-result {
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
}

.search-result h3 {
    font-size: 1.05rem;
    margin-bottom: 0.25rem;
}

.search-result .search-snippet {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.search-result mark {
    background: #fef3c7;
    padding: 0 0.15rem;
    border-radius: 2px;
}

/* ─── About / static pages ──────────────────────────────────── */

.static-page {
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
}

.static-page h1 {
    font-size: 1.6rem;
    margin-bottom: 1rem;
    color: var(--primary);
}

.static-page h2 {
    font-size: 1.2rem;
    margin: 1.5rem 0 0.75rem;
    color: var(--text);
}

.static-page p {
    margin-bottom: 0.75rem;
}

.static-page pre {
    background: var(--primary-dark);
    color: #e8e8e8;
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 0.75rem 0;
    font-size: 0.85rem;
}

.static-page code {
    background: var(--bg-tertiary);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.88em;
}

/* ─── 404 / Error ───────────────────────────────────────────── */

.error-page {
    text-align: center;
    padding: 4rem 2rem;
}

.error-page h1 {
    font-size: 4rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.error-page p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* ─── Responsive ────────────────────────────────────────────── */

/* Hamburger button — hidden on desktop */
.hamburger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    flex-direction: column;
    gap: 5px;
    z-index: 1001;
}
.hamburger span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all 0.3s ease;
}
.hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}
.hamburger.active span:nth-child(2) {
    opacity: 0;
}
.hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

@media (max-width: 900px) {
    .page-container {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .infobox {
        float: none;
        width: 100%;
        margin: 1rem 0;
    }
}

@media (max-width: 768px) {
    .header-inner {
        flex-wrap: wrap;
        height: auto;
        padding: 0.75rem 1rem;
        gap: 0.75rem;
    }

    .site-logo {
        font-size: 1.2rem;
    }

    .search-bar {
        order: 5;
        max-width: 100%;
        width: 100%;
    }

    /* Hamburger visible on mobile */
    .hamburger {
        display: flex;
    }

    /* Mobile nav: slide-down panel */
    .header-nav {
        display: none;
        order: 10;
        width: 100%;
        flex-direction: column;
        gap: 0;
        background: var(--bg-primary);
        border-top: 1px solid var(--border-color);
        border-bottom: 1px solid var(--border-color);
    }
    .header-nav.mobile-open {
        display: flex;
    }
    .header-nav a {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--border-color);
    }

    .hero h1 {
        font-size: 1.6rem;
    }

    .hero-stats {
        flex-direction: column;
        gap: 1rem;
    }

    .lang-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ─── Print ─────────────────────────────────────────────────── */

@media print {
    .site-header, .sidebar, .site-footer, .search-bar, .toc-box {
        display: none;
    }

    .page-container {
        grid-template-columns: 1fr;
    }

    .article-body {
        font-size: 12pt;
    }
}
