:root {
    /* Colors */
    --bg-primary: #0a0e17;
    --bg-secondary: #131a28;
    --bg-tertiary: #1a2332;
    --bg-card: #111827;

    --border-subtle: #1e293b;
    --border-default: #334155;
    --border-accent: #3b82f6;

    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;

    --accent-primary: #3b82f6;
    --accent-primary-rgb: 59, 130, 246;
    --accent-secondary: #60a5fa;
    --accent-success: #22c55e;
    --accent-success-rgb: 34, 197, 94;
    --accent-warning: #f59e0b;
    --accent-warning-rgb: 245, 158, 11;
    --accent-danger: #ef4444;
    --accent-danger-rgb: 239, 68, 68;
    --accent-purple: #a855f7;
    --accent-purple-rgb: 168, 85, 247;
    --accent-info: #0ea5e9;
    --accent-info-rgb: 14, 165, 233;

    --color-on-accent: #ffffff;
    --color-on-dark: #ffffff;

    /* Card Colors */
    --bg-card-hover: #1e293b;
    --bg-card-active: #2d3e5a;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 24px rgba(var(--accent-primary-rgb), 0.2);
    --shadow-glow-success: 0 0 24px rgba(var(--accent-success-rgb), 0.2);

    /* Focus */
    --focus-ring: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--accent-primary);
    --focus-ring-offset: 2px;

    /* Radii */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Typography */
    --font-mono: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
    --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --transition-slow: 0.3s ease;
}

[data-theme="light"] {
    --bg-primary: #fdfaf0;
    --bg-secondary: #fefcf5;
    --bg-tertiary: #f4efe2;
    --bg-card: #fefcf5;
    
    --bg-card-hover: #f4efe2;
    --bg-card-active: #e6e0d0;

    --border-subtle: #d6d0c0;
    --border-default: #b5ad9b;
    --border-accent: #3b82f6;

    --text-primary: #3d3b35;
    --text-secondary: #5c5950;
    --text-muted: #736f66;
    
    --color-on-dark: #3d3b35;
}

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

[hidden] {
    display: none !important;
}

html {
    color-scheme: dark;
    scroll-behavior: smooth;
    scroll-margin-top: var(--space-xl);
    -webkit-text-size-adjust: 100%;
}

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.7;
    letter-spacing: 0.01em;
    height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
h4 { font-size: 16px; }

p {
    line-height: 1.7;
    color: var(--text-secondary);
}

code, pre {
    font-family: var(--font-mono);
    font-size: 0.9em;
}

/* Focus States */
:focus {
    outline: none;
}

:focus-visible {
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

/* Selection */
::selection {
    background: rgba(var(--accent-primary-rgb), 1);
    color: var(--color-on-accent);
}

/* Skip Link */
.skip-link {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent-primary);
    color: var(--color-on-accent);
    padding: var(--space-sm) var(--space-md);
    z-index: 9999;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    border-radius: var(--radius-md);
    transition: top var(--transition-fast), background-color var(--transition-fast);
}

.skip-link:focus {
    top: var(--space-md);
    background: var(--accent-secondary);
}

/* Layout */
.layout {
    display: flex;
    flex: 1;
    min-height: 0;
    height: 100vh;
    overflow: hidden;
}

.main-content {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}

.main-content [id] {
    scroll-margin-top: 80px;
}

.page {
    flex: 1;
    padding: var(--space-xl);
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.page-header {
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
}

.page-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
    text-wrap: balance;
}

.page-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
}

/* Form Elements */
input, select, textarea, button {
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
}

input::placeholder, textarea::placeholder {
    color: var(--text-muted);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
    html {
        scroll-behavior: auto;
    }
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    padding: var(--space-md) 0;
    flex-shrink: 0;
    height: 100vh;
    position: sticky;
    top: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0 var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: var(--space-md);
    text-decoration: none;
}

.brand-icon {
    font-size: 24px;
}

.brand-text {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.nav-section {
    flex: 1;
    padding: 0 var(--space-sm);
}

.nav-section-title {
    display: block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: var(--space-xs) var(--space-sm);
    margin-bottom: var(--space-xs);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    margin-bottom: var(--space-xs);
    transition: background-color var(--transition-fast), color var(--transition-fast);
    font-size: 14px;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item:focus-visible {
    box-shadow: var(--focus-ring);
}

.nav-item.active {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-purple));
    color: var(--color-on-accent);
}

.nav-item.active .nav-icon {
    filter: brightness(0) invert(1);
}

/* Sidebar Anchor Links */
.sidebar-anchors {
    padding: 0 var(--space-sm);
    margin-top: var(--space-md);
    border-top: 1px solid var(--border-subtle);
    padding-top: var(--space-md);
}

.sidebar-anchors-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: 0 var(--space-sm);
    margin-bottom: var(--space-sm);
}

.nav-anchor {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    font-size: 12px;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.nav-anchor:hover {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.nav-anchor:focus-visible {
    box-shadow: var(--focus-ring);
}

.nav-anchor::before {
    content: '';
    width: 4px;
    height: 4px;
    background: var(--border-default);
    border-radius: 50%;
    flex-shrink: 0;
}

.nav-anchor:hover::before {
    background: var(--accent-primary);
}

.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: var(--space-md);
    border-top: 1px solid var(--border-subtle);
}

.version-badge {
    display: inline-block;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    color: var(--text-primary);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: var(--space-sm);
    width: 100%;
    min-height: 36px;
    transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.theme-toggle:hover {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

.theme-toggle:focus-visible {
    box-shadow: var(--focus-ring);
}

.theme-icon-light,
.theme-icon-dark {
    font-size: 14px;
    line-height: 1;
}

.theme-label {
    font-weight: 500;
}

/* Footer */
.footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-subtle);
    padding: var(--space-md) var(--space-xl);
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-md);
}

.footer-brand {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: 13px;
    color: var(--text-secondary);
}

.footer-icon {
    font-size: 16px;
}

.footer-links {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 13px;
}

.footer-links a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.footer-links a:hover {
    color: var(--accent-primary);
}

.footer-links a:focus-visible {
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

.footer .separator {
    color: var(--text-muted);
}

.footer-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* Utility */
.domain-placeholder {
    text-align: center;
    color: var(--text-muted);
    padding: var(--space-xl);
    font-size: 14px;
}

/* Mobile */
@media (max-width: 768px) {
    .layout {
        flex-direction: column;
    }

    .page {
        padding: var(--space-md);
    }

    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        padding: var(--space-sm);
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--border-subtle);
    }

    .brand {
        padding: 0 var(--space-sm);
        margin-bottom: 0;
        border-bottom: none;
    }

    .brand-text {
        display: none;
    }

    .nav-section {
        display: flex;
        flex: 1;
        padding: 0;
        justify-content: center;
        gap: var(--space-xs);
    }

    .nav-section-title {
        display: none;
    }

    .nav-item {
        padding: var(--space-sm) var(--space-md);
        margin-bottom: 0;
    }

    .nav-item span:not(.nav-icon) {
        display: none;
    }

    .sidebar-footer {
        display: none;
    }

    .footer {
        padding: var(--space-md);
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
    }
}
