/* ==========================================================================
   Layout — fixed 64px header, fixed 280px sidebar, offset content column.
   ========================================================================== */

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

html {
    scroll-behavior: smooth;
    scroll-padding-top: 88px;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    overflow-x: hidden;
}

/* --------------------------------------------------------------------------
   Background canvas
   -------------------------------------------------------------------------- */

.bg-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0.6;
}

/* --------------------------------------------------------------------------
   Skip link
   -------------------------------------------------------------------------- */

.skip-link {
    position: absolute;
    top: -100px;
    left: 16px;
    z-index: 2000;
    padding: 10px 18px;
    background: var(--accent-color);
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: 12px;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    background: var(--bg-header);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border-color);
}

.header-brand {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 22px;
    line-height: 1;
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.header-title {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

/* --------------------------------------------------------------------------
   Search
   -------------------------------------------------------------------------- */

.search-container {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    pointer-events: none;
    transition: color var(--transition-fast);
}

.search-container:focus-within .search-icon {
    color: var(--accent-color);
}

.search-input {
    width: 260px;
    height: 38px;
    padding: 0 38px 0 38px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    outline: none;
    transition: width var(--transition-base), border-color var(--transition-fast),
                background var(--transition-fast), box-shadow var(--transition-fast);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    width: 320px;
    border-color: var(--accent-color);
    background: var(--bg-hover);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.search-input::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

.search-shortcut {
    position: absolute;
    right: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    pointer-events: none;
}

.search-container:focus-within .search-shortcut {
    opacity: 0;
}

.search-results {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 420px;
    max-width: calc(100vw - 32px);
    max-height: 400px;
    overflow-y: auto;
    padding: 6px;
    background: var(--bg-sidebar);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1100;
}

.search-results[hidden] {
    display: none;
}

/* --------------------------------------------------------------------------
   Theme toggle & hamburger
   -------------------------------------------------------------------------- */

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    font-size: 16px;
    line-height: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast),
                transform var(--transition-fast);
}

.theme-toggle:hover {
    background: var(--bg-hover);
    border-color: var(--accent-color);
    transform: rotate(15deg);
}

[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="light"] .theme-icon-dark { display: none; }

.hamburger-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 38px;
    height: 38px;
    padding: 0 8px;
    background: transparent;
    border: none;
    cursor: pointer;
}

.hamburger-line {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: transform var(--transition-base), opacity var(--transition-fast);
}

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */

.sidebar {
    position: fixed;
    top: 64px;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 900;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg-sidebar);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-right: 1px solid var(--border-color);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 16px 12px 40px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

/* --------------------------------------------------------------------------
   Main content
   -------------------------------------------------------------------------- */

.main-content {
    position: relative;
    z-index: 1;
    margin-left: 280px;
    margin-top: 64px;
    padding: 32px 40px 96px;
    min-height: calc(100vh - 64px);
}

.topic-container {
    max-width: 860px;
    margin: 0 auto;
}

/* --------------------------------------------------------------------------
   Back to top
   -------------------------------------------------------------------------- */

.back-to-top {
    position: fixed;
    right: 28px;
    bottom: 28px;
    z-index: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    color: #fff;
    background: var(--gradient-accent);
    border: none;
    border-radius: 50%;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast),
                opacity var(--transition-base);
}

.back-to-top[hidden] {
    display: none;
}

.back-to-top:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg), 0 0 24px var(--accent-glow);
}

/* --------------------------------------------------------------------------
   Accessibility
   -------------------------------------------------------------------------- */

:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
    border-radius: 4px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 1024px) {
    .sidebar { width: 260px; }
    .main-content { margin-left: 260px; padding: 28px 28px 80px; }
    .search-input { width: 200px; }
    .search-input:focus { width: 260px; }
}

@media (max-width: 768px) {
    .hamburger-btn { display: flex; }
    .sidebar { transform: translateX(-100%); width: 300px; z-index: 1001; }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.active { display: block; }
    .main-content { margin-left: 0; padding: 24px 16px 80px; }
    .header { padding: 0 12px; gap: 8px; }
    .header-title { font-size: 17px; }
    .search-input { width: 150px; }
    .search-input:focus { width: 190px; }
    .search-shortcut { display: none; }
    .search-results { width: calc(100vw - 24px); right: -44px; }
}

@media (max-width: 480px) {
    .main-content { padding: 18px 12px 72px; }
    .header-title { display: none; }
    .search-input { width: 130px; padding-right: 12px; }
    .search-input:focus { width: 170px; }
    .back-to-top { right: 16px; bottom: 16px; }
}
