:root {
    /* DEFAULT DARK THEME (Zinc) */
    --bg-body: #09090b;
    --bg-card: #18181b; 
    --bg-hover: #27272a;
    --border: #3f3f46;
    --border-light: #52525b;
    
    --text-main: #f4f4f5;
    --text-muted: #a1a1aa;
    
    --accent: #38bdf8;        /* Sky Blue */
    --accent-dim: rgba(56, 189, 248, 0.1);
    
    --code-bg: #121214;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.05);
    
    --hero-gradient: linear-gradient(135deg, #fff 0%, #94a3b8 100%);
    
    --sidebar-width: 280px;
    --nav-height: 64px;
}

/* LIGHT THEME */
[data-theme="light"] {
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --border: #e2e8f0;
    --border-light: #cbd5e1;
    --text-main: #0f172a;
    --text-muted: #475569;
    --accent: #0284c7;
    --accent-dim: rgba(14, 165, 233, 0.15);
    --code-bg: #f1f5f9;
    --glass-bg: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(0, 0, 0, 0.05);
    --hero-gradient: linear-gradient(135deg, #0f172a 0%, #475569 100%);
}

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

body {
    background-color: var(--bg-body);
    background-image: 
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 40px 40px;
    background-blend-mode: overlay;
    color: var(--text-main);
    font-family: 'Inter', -apple-system, sans-serif;
    line-height: 1.6;
    display: flex; flex-direction: column; min-height: 100vh;
}

a { text-decoration: none; color: inherit; transition: all 0.2s ease; }
a:hover { color: var(--accent); }
.cross-link { border-bottom: 1px dashed var(--accent); color: var(--accent); }

/* --- Nav & Mobile --- */
nav {
    height: var(--nav-height);
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    opacity: 0.95;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky; top: 0; z-index: 50;
}
nav .container { display: flex; align-items: center; justify-content: space-between; height: 100%; }

.logo { font-weight: 800; font-size: 1.4rem; font-family: 'JetBrains Mono', monospace; letter-spacing: -1px; color: var(--text-main); }
.logo span { color: var(--accent); }

.nav-controls { display: flex; align-items: center; gap: 15px; }

/* Hamburger Menu (Mobile Only) */
.mobile-toggle { display: none; background: none; border: none; font-size: 1.5rem; color: var(--text-main); cursor: pointer; }

/* --- Layouts --- */
.container { max-width: 1400px; margin: 0 auto; padding: 0 24px; width: 100%; }
.doc-layout { display: flex; gap: 40px; margin-top: 40px; align-items: flex-start; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    position: sticky; top: 100px; 
    max-height: calc(100vh - 120px);
    display: flex; flex-direction: column;
    padding-right: 16px;
    border-right: 1px solid var(--border);
    flex-shrink: 0;
}
.sidebar-list { overflow-y: auto; flex: 1; padding-right: 5px; margin-bottom: 20px; }
.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sidebar h3 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin: 24px 0 12px 0; font-weight: 600; }
.sidebar a {
    display: block; padding: 8px 12px; border-radius: 6px;
    font-size: 0.9rem; color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    border-left: 2px solid transparent;
}
.sidebar a:hover { background: var(--bg-hover); color: var(--text-main); }
.sidebar a.active { background: var(--accent-dim); color: var(--accent); border-left-color: var(--accent); }

.content { flex: 1; min-width: 0; padding-bottom: 80px; }

/* --- Breadcrumbs --- */
.breadcrumb { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 10px; font-family: 'JetBrains Mono', monospace; }
.breadcrumb a:hover { color: var(--accent); text-decoration: underline; }
.breadcrumb span { margin: 0 8px; color: var(--border-light); }

/* --- Search --- */
.search-wrapper { position: relative; width: 300px; }
#search-input {
    width: 100%; padding: 8px 12px; border-radius: 8px;
    background: var(--bg-hover); border: 1px solid var(--border);
    color: var(--text-main); font-family: inherit; outline: none;
    transition: all 0.2s;
}
#search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.search-dropdown {
    position: absolute; top: 120%; left: 0; width: 100%;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 12px; overflow: hidden;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5); z-index: 100; display: none;
}
.search-result-item a { display: block; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.search-result-item.selected, .search-result-item a:hover { background: var(--bg-hover); padding-left: 20px; border-left: 3px solid var(--accent); }

/* --- Hero & Cards --- */
.hero-wrapper {
    position: relative; height: 85vh;
    display: flex; align-items: center; justify-content: center;
    background: radial-gradient(circle at 50% 50%, var(--accent-dim) 0%, transparent 70%);
}
#hero-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 0; opacity: 0.6; }
.hero-content { position: relative; z-index: 2; text-align: center; width: 100%; max-width: 900px; }
.hero-text h1 {
    font-size: 4rem; line-height: 1; margin-bottom: 20px;
    background: var(--hero-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.cmd-palette {
    background: var(--bg-card); 
    border: 1px solid var(--border); 
    border-radius: 12px;
    padding: 16px; 
    display: flex; 
    align-items: center; 
    margin: 40px auto; 
    max-width: 600px;
    box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    
    /* --- ADD THIS LINE --- */
    z-index: 100; 
    
    position: relative;
}
.cmd-palette input { background: transparent; border: none; color: var(--text-main); font-size: 1.2rem; width: 100%; outline: none; }
.arch-grid-hero { display: flex; justify-content: center; gap: 20px; margin-top: 60px; flex-wrap: wrap; }
.arch-card-glass {
    width: 220px; height: 160px; background: var(--glass-bg);
    border: 1px solid var(--glass-border); border-radius: 16px; padding: 24px;
    text-align: left; display: flex; flex-direction: column; justify-content: space-between;
    transition: all 0.3s;
}
.arch-card-glass:hover { transform: translateY(-10px); border-color: var(--accent); }
.card-icon { font-family: 'JetBrains Mono'; font-size: 2.5rem; color: var(--text-muted); }
.card-info h2 { font-size: 1.2rem; margin: 0; color: var(--text-main); }

/* --- Components --- */
.syntax-box {
    background: var(--code-bg); padding: 24px; border-radius: 12px;
    border: 1px solid var(--border); font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem; color: var(--accent); margin: 24px 0;
}
.panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 24px; margin-bottom: 24px; }
.code-block { 
    background: var(--code-bg); 
    padding: 16px; 
    border-radius: 8px; 
    border: 1px solid var(--border); 
    color: var(--text-main); 
    font-family: 'JetBrains Mono'; 
    overflow-x: auto;       /* Keep horizontal scroll for long lines */
    overflow-y: visible;    /* Disable vertical scroll */
    max-height: none;       /* Allow box to grow infinitely */
    min-height: 100px;      /* Increase default height */
    display: flex;          /* Centers short content vertically if needed */
    align-items: center;    
}
.badge { display: inline-block; padding: 4px 8px; border-radius: 6px; font-size: 0.75rem; background: var(--bg-hover); border: 1px solid var(--border); color: var(--text-muted); font-weight: bold; }
.mono { font-family: 'JetBrains Mono'; } .accent { color: var(--accent); }

.bit-row { display: flex; gap: 2px; width: 100%; overflow-x: auto; padding-bottom: 4px; }
.bit-box { background: var(--bg-hover); border: 1px solid var(--border); padding: 8px 12px; flex: 1; text-align: center; min-width: max-content; font-family: 'JetBrains Mono'; font-size: 0.85rem; color: var(--text-main); }
.bit-box:hover { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.table-container { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--bg-card); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { background: var(--bg-hover); padding: 16px; text-align: left; font-size: 0.8rem; color: var(--text-muted); }
.data-table td { padding: 16px; border-bottom: 1px solid var(--border); font-size: 0.95rem; color: var(--text-main); }
.data-table tr:hover { background: var(--bg-hover); }

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    .sidebar { 
        display: none; /* Hidden by default on mobile */
        position: fixed; top: var(--nav-height); left: 0; width: 100%; height: calc(100vh - var(--nav-height));
        background: var(--bg-body); z-index: 40; border-right: none;
    }
    .sidebar.active { display: flex; }
    .mobile-toggle { display: block; }
    .doc-layout { flex-direction: column; }
    .search-wrapper { display: none; } /* Hide header search on mobile to save space */
    .hero-text h1 { font-size: 3rem; }
    .bit-row { flex-wrap: wrap; }
    .bit-box { flex: 1 1 30%; } /* Wrap bit boxes on small screens */
    .meta-grid, .operand-list { grid-template-columns: 1fr; }
    div[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
}

.theme-toggle { background: transparent; border: 1px solid var(--border); color: var(--text-muted); width: 40px; height: 40px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.theme-toggle:hover { background: var(--bg-hover); color: var(--accent); }

/* Highlighting Interaction */
.highlight {
    background-color: var(--accent-dim) !important;
    border-color: var(--accent) !important;
    color: var(--accent) !important;
    cursor: default;
    /* Optional: Subtle transform to make it pop */
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 10;
}

/* Ensure the operand row handles the transform gracefully */
.operand-row {
    position: relative;
    /* transition is defined inline in the template for simplicity, but cleaner here: */
    transition: all 0.2s ease;
}

/* --- Copy Button Styles --- */
.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 8px;
    opacity: 0; /* Hidden until hover */
    transition: opacity 0.2s, background 0.2s;
    color: var(--text-muted);
}

.copy-btn:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

.code-block:hover .copy-btn {
    opacity: 1;
}

/* --- Sidebar Grouping --- */
.nav-group {
    margin-bottom: 12px;
}

.nav-group summary {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px 4px;
    list-style: none; /* Hide default triangle */
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: color 0.2s;
}

.nav-group summary:hover {
    color: var(--text-main);
}

/* Custom arrow for summary */
.nav-group summary::after {
    content: '›';
    font-size: 1.2rem;
    transition: transform 0.2s;
    line-height: 0;
}

.nav-group[open] summary::after {
    transform: rotate(90deg);
}

/* Hide standard marker in Chrome/Safari */
.nav-group summary::-webkit-details-marker {
    display: none;
}

.group-links {
    padding-left: 8px;
    border-left: 1px solid var(--border);
    margin-left: 4px;
}

.group-links a {
    font-size: 0.85rem;
    padding: 4px 12px;
    display: block;
    color: var(--text-muted);
    border-radius: 4px;
}

.group-links a:hover {
    color: var(--accent);
    background: transparent; /* Override default hover bg */
}

.group-links a.active {
    color: var(--accent);
    background: var(--accent-dim);
    font-weight: 500;
    border-left: none; /* Remove old border style */
}

/* --- Syntax Highlighting Overrides (Prism.js) --- */
/* Force code blocks to match the dark theme background */
code[class*="language-"], pre[class*="language-"] {
    background: var(--code-bg) !important;
    text-shadow: none !important;
    font-family: 'JetBrains Mono', monospace !important;
    font-size: 0.9rem !important;
    border: none !important;
    margin: 0 !important;
    padding: 0 !important; /* Let parent container handle padding */
}
