/* ============================================================
   1. WIKI BASE & 2-PANEL FIXED VIEWPORT LAYOUT
   ============================================================ */
:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #60a5fa;
    --accent-green: #10b981;
    --accent-green-light: #34d399;
    --accent-red: #ef4444;
    --accent-red-light: #f87171;
    --accent-amber: #f59e0b;
    --accent-amber-light: #fbbf24;
    --accent-purple: #8b5cf6;
    --accent-cyan: #06b6d4;
    --bg: #0b0f19;
    --sidebar-bg: #0d1322;
    --surface: #111827;
    --surface-card: #1f2937;
    --surface-card-hover: #283548;
    --text: #f9fafb;
    --text-light: #cbd5e1;
    --text-muted: #9ca3af;
    --border: #374151;
    --border-hover: #4b5563;
    --code-bg: #030712;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100vh !important;
    height: 100dvh !important;
    width: 100vw !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important; /* Window/document never scrolls */
    background-color: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.75;
    -webkit-text-size-adjust: 100%;
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* Top Navigation Bar */
.wiki-nav-top {
    background: rgba(13, 19, 34, 0.98);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    flex-shrink: 0;
    height: 58px;
    z-index: 100;
    backdrop-filter: blur(14px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-sizing: border-box;
    width: 100%;
}

.wiki-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: #ffffff;
    font-weight: 700;
    font-size: 1.05rem;
    white-space: nowrap;
    min-width: 0;
    flex-shrink: 0;
}

.wiki-logo img {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    flex-shrink: 0;
}

.wiki-logo span {
    white-space: nowrap;
    font-weight: 700;
}

.wiki-top-links {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    flex-shrink: 0;
}

.wiki-top-links a, .wiki-top-links button {
    color: var(--text-muted);
    text-decoration: none !important;
    font-size: 0.88rem;
    font-weight: 500;
    transition: color 0.2s ease;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.wiki-top-links a:hover, .wiki-top-links button:hover {
    color: #ffffff;
}

.btn-spotlight-trigger {
    background: var(--surface-card) !important;
    border: 1px solid var(--border) !important;
    color: var(--text-light) !important;
    padding: 6px 12px !important;
    border-radius: 8px !important;
    font-size: 0.82rem !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    font-family: inherit !important;
    outline: none !important;
    white-space: nowrap;
}

.btn-spotlight-trigger:hover {
    border-color: var(--primary-light) !important;
    color: #ffffff !important;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.3) !important;
}

.btn-spotlight-trigger kbd {
    background: #111827;
    border: 1px solid var(--border);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.72rem;
    color: #60a5fa;
    font-family: inherit;
}

.btn-lang-toggle {
    background: rgba(59, 130, 246, 0.15) !important;
    border: 1px solid rgba(59, 130, 246, 0.4) !important;
    color: #93c5fd !important;
    padding: 6px 10px !important;
    border-radius: 8px !important;
    font-size: 0.8rem !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    font-family: inherit !important;
    outline: none !important;
    white-space: nowrap;
}

.btn-kunihome {
    background: var(--surface-card) !important;
    border: 1px solid var(--border) !important;
    color: var(--text-light) !important;
    padding: 6px 12px !important;
    border-radius: 8px !important;
    font-size: 0.82rem !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    font-family: inherit !important;
    outline: none !important;
    text-decoration: none !important;
    transition: all 0.2s ease !important;
    white-space: nowrap;
}

.btn-kunihome:hover {
    border-color: var(--primary-light) !important;
    color: #ffffff !important;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.3) !important;
}

.btn-download {
    background: linear-gradient(135deg, #2563eb, #3b82f6) !important;
    color: #ffffff !important;
    padding: 6px 14px !important;
    border-radius: 8px;
    font-size: 0.84rem !important;
    font-weight: 600 !important;
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.4);
    text-decoration: none;
    transition: transform 0.2s, box-shadow 0.2s;
    white-space: nowrap;
}

.btn-download:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.6);
}

.sidebar-toggle-btn {
    display: none;
    background: linear-gradient(135deg, #2563eb, #3b82f6) !important;
    border: none !important;
    color: #ffffff !important;
    padding: 6px 12px !important;
    border-radius: 8px !important;
    font-size: 0.82rem !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4) !important;
    white-space: nowrap;
}

/* ============================================================
   2-PANEL INDEPENDENT VIEWPORT LAYOUT
   ============================================================ */
.wiki-layout {
    display: flex;
    width: 100vw;
    height: calc(100vh - 58px);
    height: calc(100dvh - 58px);
    overflow: hidden !important; /* Layout never scrolls */
    margin: 0;
    padding: 0;
    align-items: stretch;
    background: var(--bg);
}

/* PANEL 1: LEFT SIDEBAR (ROCK-SOLID PINNED & INDEPENDENT SCROLL) */
.wiki-sidebar {
    width: 310px;
    min-width: 290px;
    max-width: 330px;
    height: 100%;
    flex-shrink: 0;
    overflow-y: auto !important;
    overflow-x: hidden;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    padding: 20px 16px 80px 20px;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 130, 246, 0.3) transparent;
}

.wiki-sidebar::-webkit-scrollbar {
    width: 5px;
}

.wiki-sidebar::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.3);
    border-radius: 3px;
}

/* PANEL 2: RIGHT CONTENT AREA (INDEPENDENT SCROLL CONTAINER) */
.wiki-content {
    position: relative !important; /* Establishes offsetParent for accurate scrollSpy */
    flex: 1;
    min-width: 0;
    height: 100%;
    overflow-y: auto !important;
    overflow-x: hidden;
    background: var(--bg);
    padding: 28px 36px 40px 36px;
    box-sizing: border-box;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 130, 246, 0.4) transparent;
}

.wiki-content::-webkit-scrollbar {
    width: 7px;
}

.wiki-content::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.4);
    border-radius: 4px;
}

/* Keyboard Focus Accessibility */
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible {
    outline: none !important;
    box-shadow: 0 0 0 2px var(--primary-light) !important;
}

/* Tablet Views (769px to 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .wiki-sidebar {
        width: 260px;
        min-width: 250px;
        padding: 16px 12px 60px 14px;
    }
    .wiki-content {
        padding: 20px 20px 50px 20px;
    }
    .toc-accordion summary {
        padding: 8px 10px !important;
        font-size: 0.84rem !important;
    }
    .toc-sub-link {
        font-size: 0.78rem !important;
        padding: 5px 8px !important;
    }
    .btn-kunihome {
        display: none !important;
    }
}

/* Mobile & Small Tablet Screens (<= 768px) */
@media (max-width: 768px) {
    .wiki-nav-top {
        padding: 0 12px;
        height: 54px;
        gap: 8px;
    }
    .wiki-logo {
        gap: 8px;
        font-size: 0.92rem;
        max-width: 145px;
    }
    .wiki-logo span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .wiki-logo img {
        width: 24px;
        height: 24px;
    }
    
    /* Strictly hide non-essential desktop links */
    .btn-kunihome,
    .btn-download,
    .wiki-top-links a {
        display: none !important;
    }

    .wiki-top-links {
        gap: 6px;
    }

    .sidebar-toggle-btn {
        display: inline-flex !important;
        align-items: center;
        gap: 4px;
    }

    /* Hide desktop-only nav links (moved out of per-page inline <style>) */
    .desktop-only {
        display: none !important;
    }

    /* Larger touch targets for sidebar chapter links */
    .toc-sub-link {
        padding: 9px 10px !important;
        font-size: 0.85rem !important;
    }

    .btn-spotlight-trigger {
        padding: 6px 9px !important;
        font-size: 0.82rem !important;
        min-width: 36px;
        justify-content: center;
    }
    .btn-spotlight-trigger span,
    .btn-spotlight-trigger kbd {
        display: none !important;
    }
    .btn-spotlight-trigger::after {
        content: "🔍";
        font-size: 0.9rem;
    }

    .btn-lang-toggle {
        padding: 5px 8px !important;
        font-size: 0.75rem !important;
    }

    .wiki-layout {
        height: calc(100vh - 54px) !important;
        height: calc(100dvh - 54px) !important;
    }

    /* Mobile Drawer Fullscreen Overlay */
    .wiki-sidebar {
        display: none;
        position: fixed;
        top: 54px;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 54px) !important;
        height: calc(100dvh - 54px) !important;
        background: rgba(11, 15, 25, 0.98);
        backdrop-filter: blur(20px);
        z-index: 999;
        padding: 16px 14px 90px 14px;
        box-sizing: border-box;
    }

    .wiki-sidebar.show {
        display: block !important;
    }

    .wiki-content {
        padding: 16px 12px 60px 12px !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .wiki-hero {
        padding: 20px 16px !important;
        margin-bottom: 20px !important;
        border-radius: 16px !important;
    }

    .wiki-hero h1 {
        font-size: 1.45rem !important;
        line-height: 1.25 !important;
        margin-bottom: 10px !important;
    }

    .wiki-hero p {
        font-size: 0.88rem !important;
        line-height: 1.55 !important;
    }

    .wiki-section {
        padding: 20px 14px !important;
        margin-bottom: 20px !important;
        border-radius: 16px !important;
    }

    .wiki-section h2 {
        font-size: 1.22rem !important;
        gap: 8px !important;
        padding-bottom: 10px !important;
        margin-bottom: 14px !important;
        line-height: 1.35 !important;
    }

    .wiki-section h3 {
        font-size: 1.05rem !important;
        margin: 20px 0 10px 0 !important;
    }

    .wiki-section h4 {
        font-size: 0.95rem !important;
        margin: 16px 0 8px 0 !important;
    }

    .wiki-section p, .wiki-section li {
        font-size: 0.9rem !important;
        line-height: 1.65 !important;
    }

    .cards-grid, .wiki-cards-grid, .topics-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .guide-card, .topic-card {
        padding: 16px 14px !important;
        border-radius: 12px !important;
    }

    .screenshot-annotated-wrap {
        padding: 16px 12px !important;
        gap: 16px !important;
        margin: 18px 0 !important;
    }

    .screenshot-container {
        max-width: 150px !important;
    }

    .callout-pins-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    .pin-item {
        padding: 12px 12px !important;
        gap: 10px !important;
        border-radius: 10px !important;
    }

    .pin-text strong {
        font-size: 0.88rem !important;
    }

    .pin-text span {
        font-size: 0.8rem !important;
    }

    .simulator-card, .decay-demo-box, .confidence-meter-box {
        padding: 16px 12px !important;
        border-radius: 14px !important;
    }

    .sim-controls-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    table {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
}

@media (max-width: 440px) {
    .wiki-logo span {
        font-size: 0.85rem !important;
        max-width: 110px !important;
    }
    .btn-lang-toggle {
        padding: 4px 6px !important;
        font-size: 0.72rem !important;
    }
    .sidebar-toggle-btn {
        padding: 5px 9px !important;
        font-size: 0.78rem !important;
    }
}
