/* Memex Static Theme - Nord Color Scheme with Light/Dark Mode Support */

/* ===== NORD COLOR PALETTE ===== */
:root {
    /* Nord Polar Night (dark backgrounds) */
    --nord0: #2e3440;
    --nord1: #3b4252;
    --nord2: #434c5e;
    --nord3: #4c566a;

    /* Nord Snow Storm (light backgrounds/text) */
    --nord4: #d8dee9;
    --nord5: #e5e9f0;
    --nord6: #eceff4;

    /* Nord Frost (accent colors) */
    --nord7: #8fbcbb;
    --nord8: #88c0d0;
    --nord9: #81a1c1;
    --nord10: #5e81ac;

    /* Nord Aurora (semantic colors) */
    --nord11: #bf616a;  /* red */
    --nord12: #d08770;  /* orange */
    --nord13: #ebcb8b;  /* yellow */
    --nord14: #a3be8c;  /* green */
    --nord15: #b48ead;  /* purple */

    /* ===== DARK THEME (Default) ===== */
    /* Background hierarchy */
    --bg-abyss: #242933;
    --bg-void: var(--nord0);
    --bg-deep: var(--nord1);
    --bg-surface: var(--nord2);
    --bg-elevated: var(--nord3);
    --bg-hover: #505868;

    /* Borders */
    --border-void: var(--nord1);
    --border-subtle: var(--nord2);
    --border-focus: var(--nord3);

    /* Text hierarchy */
    --text-primary: var(--nord6);
    --text-secondary: var(--nord4);
    --text-tertiary: #a0a8b5;
    --text-muted: #8892a2;

    /* Primary accent (Frost cyan) */
    --accent-primary: var(--nord8);
    --accent-bright: var(--nord7);
    --accent-soft: var(--nord9);
    --accent-muted: rgba(136, 192, 208, 0.15);
    --accent-ghost: rgba(136, 192, 208, 0.08);

    /* Secondary accent (Aurora yellow/orange) */
    --accent-secondary: var(--nord13);
    --accent-secondary-bright: #f0d399;
    --accent-secondary-soft: var(--nord12);
    --accent-secondary-muted: rgba(235, 203, 139, 0.15);
    --accent-secondary-ghost: rgba(235, 203, 139, 0.08);

    /* Status colors (Aurora) */
    --success: var(--nord14);
    --success-muted: rgba(163, 190, 140, 0.2);
    --error: var(--nord11);
    --error-muted: rgba(191, 97, 106, 0.2);
    --warning: var(--nord13);
    --purple: var(--nord15);
    --purple-muted: rgba(180, 142, 173, 0.15);

    /* Shadows */
    --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
    --glow-accent: 0 0 30px rgba(136, 192, 208, 0.2);

    /* Typography */
    --font-display: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --duration-fast: 150ms;
    --duration-normal: 250ms;

    /* Color scheme hint for browser */
    color-scheme: dark light;
}

/* ===== LIGHT THEME ===== */
@media (prefers-color-scheme: light) {
    :root {
        /* Background hierarchy (inverted) */
        --bg-abyss: var(--nord6);
        --bg-void: var(--nord5);
        --bg-deep: var(--nord6);
        --bg-surface: #ffffff;
        --bg-elevated: var(--nord5);
        --bg-hover: var(--nord4);

        /* Borders */
        --border-void: var(--nord4);
        --border-subtle: #c9d1dc;
        --border-focus: var(--nord9);

        /* Text hierarchy */
        --text-primary: var(--nord0);
        --text-secondary: var(--nord1);
        --text-tertiary: var(--nord2);
        --text-muted: var(--nord3);

        /* Primary accent (darker for contrast) */
        --accent-primary: var(--nord10);
        --accent-bright: var(--nord9);
        --accent-soft: var(--nord8);
        --accent-muted: rgba(94, 129, 172, 0.15);
        --accent-ghost: rgba(94, 129, 172, 0.08);

        /* Secondary accent */
        --accent-secondary: var(--nord12);
        --accent-secondary-bright: var(--nord13);
        --accent-secondary-soft: #c97b60;
        --accent-secondary-muted: rgba(208, 135, 112, 0.15);
        --accent-secondary-ghost: rgba(208, 135, 112, 0.08);

        /* Status colors (slightly adjusted for light bg) */
        --success: #8aab7a;
        --success-muted: rgba(138, 171, 122, 0.2);
        --error: #b5545e;
        --error-muted: rgba(181, 84, 94, 0.2);
        --warning: #d9a654;
        --purple: #a6799a;
        --purple-muted: rgba(166, 121, 154, 0.15);

        /* Shadows (softer for light mode) */
        --shadow-lg: 0 25px 50px -12px rgba(46, 52, 64, 0.15);
        --glow-accent: 0 0 30px rgba(94, 129, 172, 0.15);
    }
}

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

html {
    font-size: 16px;
}

body {
    font-family: var(--font-display);
    background: var(--bg-abyss);
    color: var(--text-primary);
    line-height: 1.7;
    min-height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Ambient background glow (subtle) */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(136, 192, 208, 0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(180, 142, 173, 0.02) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(235, 203, 139, 0.01) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

@media (prefers-color-scheme: light) {
    body::before {
        background:
            radial-gradient(ellipse at 20% 20%, rgba(94, 129, 172, 0.05) 0%, transparent 50%),
            radial-gradient(ellipse at 80% 80%, rgba(180, 142, 173, 0.03) 0%, transparent 50%),
            radial-gradient(ellipse at 50% 50%, rgba(208, 135, 112, 0.02) 0%, transparent 70%);
    }
}

/* ===== APP GRID LAYOUT ===== */
.app {
    display: grid;
    grid-template-columns: 260px 1fr 300px;
    grid-template-rows: 64px 1fr;
    height: 100vh;
    position: relative;
    z-index: 1;
}

/* Responsive: collapse to single column on mobile */
@media (max-width: 1024px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: 64px 1fr;
    }
    .sidebar, .panel {
        display: none;
    }
}

/* ===== HEADER ===== */
.header {
    grid-column: 1 / -1;
    background: linear-gradient(180deg, var(--bg-deep) 0%, var(--bg-void) 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    border-bottom: 1px solid var(--border-void);
    position: relative;
}

.header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--border-subtle) 20%,
        var(--accent-primary) 50%,
        var(--border-subtle) 80%,
        transparent 100%
    );
    opacity: 0.3;
}

/* Logo */
.logo {
    display: flex;
    align-items: center;
    gap: 14px;
    text-decoration: none;
}

.logo-mark {
    width: 36px;
    height: 36px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-mark::before {
    content: '';
    position: absolute;
    inset: 0;
    border: 1px solid var(--accent-primary);
    border-radius: 8px;
    opacity: 0.6;
    transform: rotate(45deg);
}

.logo-mark::after {
    content: '';
    position: absolute;
    inset: 4px;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--purple) 100%);
    border-radius: 4px;
    opacity: 0.8;
    transform: rotate(45deg);
}

.logo-text {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--text-primary);
}

.logo-text span {
    opacity: 0.4;
    font-weight: 400;
}

/* Header nav links */
.header-nav {
    display: flex;
    gap: 8px;
}

.nav-link {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 400;
    color: var(--text-tertiary);
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 14px;
    border: 1px solid var(--border-void);
    border-radius: 8px;
    transition: all var(--duration-fast) ease;
}

.nav-link:hover {
    color: var(--text-secondary);
    background: var(--bg-surface);
    border-color: var(--border-subtle);
}

.nav-link.active {
    background: var(--accent-muted);
    border-color: var(--accent-primary);
    color: var(--accent-bright);
}

/* Search */
.search-container {
    flex: 1;
    max-width: 520px;
    margin: 0 48px;
    position: relative;
}

#search-input {
    width: 100%;
    padding: 12px 20px 12px 48px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    font-weight: 400;
    transition: all var(--duration-normal) var(--ease-out);
}

#search-input:hover {
    border-color: var(--border-focus);
    background: var(--bg-elevated);
}

#search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: var(--bg-elevated);
    box-shadow: 0 0 0 4px var(--accent-muted), 0 0 40px var(--accent-muted);
}

#search-input::placeholder {
    color: var(--text-muted);
    font-weight: 300;
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

#search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    max-height: 420px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: var(--shadow-lg), var(--glow-accent);
}

#search-results.active {
    display: block;
}

.search-result {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-void);
    cursor: pointer;
    transition: all var(--duration-fast) ease;
}

.search-result:last-child {
    border-bottom: none;
}

.search-result:hover {
    background: var(--bg-hover);
}

.search-result a {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--accent-bright);
    text-decoration: none;
}

.search-result .search-tags {
    font-family: var(--font-display);
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ===== SIDEBAR ===== */
.sidebar {
    background: var(--bg-void);
    border-right: 1px solid var(--border-void);
    overflow-y: auto;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 12px 20px 8px;
    font-family: var(--font-mono);
    font-size: 0.625rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

/* Sidebar navigation tabs */
.nav-tabs {
    display: flex;
    gap: 4px;
    padding: 0 12px;
    margin-bottom: 16px;
}

.nav-tab {
    flex: 1;
    padding: 8px 12px;
    background: transparent;
    border: 1px solid var(--border-void);
    border-radius: 8px;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 400;
    cursor: pointer;
    transition: all var(--duration-fast) ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.nav-tab:hover {
    background: var(--bg-surface);
    border-color: var(--border-subtle);
    color: var(--text-secondary);
}

.nav-tab.active {
    background: var(--accent-muted);
    border-color: var(--accent-primary);
    color: var(--accent-bright);
}

.sidebar-section {
    margin-bottom: 8px;
}

/* Tree navigation */
.tree {
    padding: 0 8px;
    flex: 1;
    overflow-y: auto;
}

.tree-item {
    padding: 7px 12px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    transition: all var(--duration-fast) ease;
}

.tree-item:hover {
    background: var(--bg-surface);
}

.tree-item.active {
    background: var(--accent-ghost);
}

.tree-item.active .tree-label {
    color: var(--accent-bright);
}

.tree-icon {
    font-size: 0.6875rem;
    width: 14px;
    text-align: center;
    flex-shrink: 0;
}

.tree-icon.folder {
    color: var(--accent-secondary);
}

.tree-icon.file {
    color: var(--accent-primary);
    opacity: 0.6;
}

.tree-label {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-secondary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-children {
    margin-left: 14px;
    padding-left: 10px;
    border-left: 1px solid var(--border-void);
}

.sidebar-footer {
    margin-top: auto;
    padding: 16px 20px;
    border-top: 1px solid var(--border-void);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    text-align: center;
}

.sidebar-footer a {
    color: var(--text-muted);
    text-decoration: none;
    opacity: 0.6;
    transition: opacity var(--duration-fast) ease;
}

.sidebar-footer a:hover {
    opacity: 1;
    color: var(--accent-primary);
}

.tree-folder-header {
    padding: 7px 12px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: all var(--duration-fast) ease;
}

.tree-folder-header:hover {
    background: var(--bg-surface);
}

.tree-folder-header .tree-label {
    color: var(--text-primary);
    font-weight: 500;
}

/* ===== MAIN CONTENT ===== */
.main {
    background: var(--bg-abyss);
    overflow-y: auto;
    position: relative;
}

.reader-container {
    padding: 56px 64px;
    max-width: 820px;
    margin: 0 auto;
}

@media (max-width: 1024px) {
    .reader-container {
        padding: 32px 24px;
    }
}

/* Entry header */
.entry-header {
    margin-bottom: 40px;
    padding-bottom: 32px;
    border-bottom: 1px solid var(--border-void);
    position: relative;
}

.entry-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 80px;
    height: 1px;
    background: var(--accent-primary);
    opacity: 0.5;
}

.entry-path {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-bottom: 16px;
    letter-spacing: 0.02em;
    text-decoration: none;
}

.entry-path:hover {
    color: var(--text-secondary);
}

.entry-meta {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}

.entry-meta-item {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: var(--text-muted);
}

.entry-meta-item span {
    color: var(--text-secondary);
}

/* Tags */
.entry-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.tag {
    padding: 4px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    font-family: var(--font-mono);
    font-size: 0.625rem;
    font-weight: 400;
    color: var(--accent-bright);
    letter-spacing: 0.02em;
    text-decoration: none;
    transition: all var(--duration-fast) ease;
}

.tag:hover {
    background: var(--accent-ghost);
    border-color: var(--accent-primary);
}

/* Entry content */
.entry-content {
    font-size: 1.0625rem;
    line-height: 1.85;
    color: var(--text-secondary);
}

.entry-content h1, .entry-content h2, .entry-content h3,
.entry-content h4, .entry-content h5, .entry-content h6 {
    font-family: var(--font-display);
    color: var(--text-primary);
    margin: 40px 0 20px;
    font-weight: 500;
    line-height: 1.3;
}

.entry-content h1 { font-size: 1.75rem; }
.entry-content h2 {
    font-size: 1.375rem;
    color: var(--accent-bright);
}
.entry-content h3 { font-size: 1.125rem; }

.entry-content p {
    margin-bottom: 20px;
}

.entry-content a {
    color: var(--accent-primary);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color var(--duration-fast) ease;
}

.entry-content a:hover {
    border-bottom-color: var(--accent-primary);
}

/* Wikilinks */
.wikilink {
    color: var(--accent-secondary-bright) !important;
    background: var(--accent-secondary-ghost);
    padding: 2px 8px;
    border-radius: 4px;
    border-bottom: none !important;
    font-family: var(--font-mono);
    font-size: 0.9em;
    transition: all var(--duration-fast) ease;
}

.wikilink:hover {
    background: var(--accent-secondary-muted);
}

.wikilink-broken {
    color: var(--error) !important;
    background: var(--error-muted);
    border-bottom: 1px dashed var(--error) !important;
}

/* Code */
.entry-content code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--bg-surface);
    padding: 3px 8px;
    border-radius: 4px;
    color: var(--accent-secondary-bright);
}

.entry-content pre {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 20px 24px;
    margin: 28px 0;
    overflow-x: auto;
}

.entry-content pre code {
    background: transparent;
    padding: 0;
    font-size: 0.8125rem;
    color: var(--text-primary);
    line-height: 1.6;
}

/* Lists */
.entry-content ul, .entry-content ol {
    margin: 20px 0;
    padding-left: 28px;
}

.entry-content li {
    margin-bottom: 10px;
}

/* Blockquotes */
.entry-content blockquote {
    border-left: 2px solid var(--accent-primary);
    padding-left: 24px;
    margin: 28px 0;
    color: var(--text-tertiary);
    font-style: italic;
}

/* Tables */
.entry-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 28px 0;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
}

.entry-content th,
.entry-content td {
    padding: 12px 16px;
    text-align: left;
    border: 1px solid var(--border-subtle);
}

.entry-content th {
    background: var(--bg-surface);
    color: var(--accent-bright);
    font-weight: 500;
    text-transform: uppercase;
    font-size: 0.6875rem;
    letter-spacing: 0.05em;
}

.entry-content tr:nth-child(even) {
    background: var(--bg-deep);
}

.entry-content tr:hover {
    background: var(--bg-surface);
}

/* ===== RIGHT PANEL ===== */
.panel {
    background: var(--bg-void);
    border-left: 1px solid var(--border-void);
    overflow-y: auto;
    padding: 24px 20px;
}

.panel-section {
    margin-bottom: 28px;
}

.panel-header {
    font-family: var(--font-mono);
    font-size: 0.625rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel-header::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-void);
}

.link-list {
    list-style: none;
}

.link-item {
    padding: 10px 12px;
    margin-bottom: 4px;
    background: var(--bg-surface);
    border-radius: 8px;
    transition: all var(--duration-fast) ease;
    border: 1px solid transparent;
}

.link-item:hover {
    border-color: var(--border-subtle);
    background: var(--bg-elevated);
    transform: translateX(2px);
}

.link-item a {
    text-decoration: none;
    display: block;
}

.link-title {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.link-path {
    font-family: var(--font-mono);
    font-size: 0.625rem;
    color: var(--text-muted);
}

.relation-group {
    margin-bottom: 16px;
}

.relation-subheader {
    font-family: var(--font-mono);
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin: 8px 0;
}

.relation-item .relation-meta {
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.relation-type {
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--bg-deep);
    border: 1px solid var(--border-subtle);
    font-family: var(--font-mono);
    font-size: 0.625rem;
    color: var(--accent-bright);
}

.relation-direction {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.empty-state {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: var(--text-muted);
    text-align: center;
    padding: 20px;
    font-style: italic;
}

/* ===== INDEX PAGE ===== */
.index-container {
    padding: 56px 64px;
}

.index-container h1 {
    font-family: var(--font-display);
    font-size: 2.25rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 40px;
}

.index-section {
    margin-bottom: 48px;
}

.index-section h2 {
    font-family: var(--font-mono);
    font-size: 0.625rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.index-section h2::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-void);
}

.entry-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.entry-list li {
    padding: 12px 16px;
    background: var(--bg-surface);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 12px;
    border: 1px solid transparent;
    transition: all var(--duration-fast) ease;
}

.entry-list li:hover {
    border-color: var(--border-subtle);
    background: var(--bg-elevated);
    transform: translateX(4px);
}

.entry-list a {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    font-weight: 400;
    color: var(--text-primary);
    text-decoration: none;
}

.entry-list .entry-date {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Tags section */
.tags-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* ===== TAG PAGE ===== */
.tag-page-container {
    padding: 56px 64px;
}

.tag-page-container h1 {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.tag-count {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-bottom: 32px;
}

.back-link {
    margin-top: 40px;
}

.back-link a {
    color: var(--accent-primary);
    text-decoration: none;
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

/* ===== GRAPH PAGE ===== */
.graph-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(ellipse at center, var(--bg-deep) 0%, var(--bg-abyss) 100%);
}

#graph {
    width: 100%;
    height: 100%;
}

#graph svg {
    width: 100%;
    height: 100%;
    cursor: grab;
}

#graph svg:active {
    cursor: grabbing;
}

.graph-tooltip {
    position: fixed;
    display: none;
    padding: 10px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-primary);
    max-width: 300px;
    z-index: 1000;
    pointer-events: none;
    box-shadow: var(--shadow-lg);
}

.graph-tooltip strong {
    color: var(--accent-bright);
}

.graph-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 220px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 12px 14px;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: var(--text-secondary);
    z-index: 5;
    box-shadow: var(--shadow-lg);
}

.graph-controls-header {
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.graph-control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.graph-control-item {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.graph-control-item input {
    accent-color: var(--accent-primary);
}

.graph-control-subheader {
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.graph-control-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 140px;
    overflow-y: auto;
    padding-right: 4px;
}

.graph-control-empty {
    font-size: 0.625rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Mermaid diagrams */
.mermaid {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 24px;
    margin: 28px 0;
    text-align: center;
}

/* Code highlighting */
.hljs {
    background: transparent !important;
}

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

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-focus);
}

/* ===== MOBILE RESPONSIVE ===== */

/* Mobile menu button (hamburger) - hidden on desktop */
.mobile-menu-btn {
    display: none;
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 10px;
    margin-left: -10px;
    position: relative;
    z-index: 1001;
}

.mobile-menu-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 1px;
    transition: all var(--duration-fast) var(--ease-out);
    position: absolute;
    left: 11px;
}

.mobile-menu-btn span:nth-child(1) { top: 14px; }
.mobile-menu-btn span:nth-child(2) { top: 21px; }
.mobile-menu-btn span:nth-child(3) { top: 28px; }

/* Hamburger to X animation */
.mobile-menu-btn.active span:nth-child(1) {
    transform: rotate(45deg);
    top: 21px;
}

.mobile-menu-btn.active span:nth-child(2) {
    opacity: 0;
    transform: translateX(-10px);
}

.mobile-menu-btn.active span:nth-child(3) {
    transform: rotate(-45deg);
    top: 21px;
}

/* Mobile search toggle */
.mobile-search-btn {
    display: none;
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 10px;
    color: var(--text-secondary);
}

.mobile-search-btn svg {
    width: 20px;
    height: 20px;
}

/* Sidebar overlay backdrop */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    transition: opacity var(--duration-normal) var(--ease-out);
}

.sidebar-overlay.active {
    opacity: 1;
}

/* Bottom navigation bar - mobile only */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-deep);
    border-top: 1px solid var(--border-void);
    z-index: 998;
    padding: 0 16px;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-inner {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 100%;
    max-width: 400px;
    margin: 0 auto;
}

.bottom-nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 16px;
    color: var(--text-muted);
    text-decoration: none;
    font-family: var(--font-mono);
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: color var(--duration-fast) ease;
    min-width: 64px;
}

.bottom-nav-link svg {
    width: 20px;
    height: 20px;
    opacity: 0.7;
    transition: opacity var(--duration-fast) ease;
}

.bottom-nav-link.active,
.bottom-nav-link:hover {
    color: var(--accent-bright);
}

.bottom-nav-link.active svg,
.bottom-nav-link:hover svg {
    opacity: 1;
}

/* Mobile search overlay */
.search-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg-abyss);
    z-index: 1002;
    padding: 16px;
    flex-direction: column;
    opacity: 0;
    transform: translateY(-20px);
    transition: opacity var(--duration-normal) var(--ease-out),
                transform var(--duration-normal) var(--ease-out);
}

.search-overlay.active {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

.search-overlay-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.search-overlay-close {
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-overlay-close svg {
    width: 24px;
    height: 24px;
}

.search-overlay-input {
    flex: 1;
    padding: 14px 20px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 1rem;
}

.search-overlay-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px var(--accent-muted);
}

.search-overlay-results {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.search-overlay-results .search-result {
    padding: 16px;
    border-bottom: 1px solid var(--border-void);
}

.search-overlay-results .search-result a {
    font-size: 0.9375rem;
}

/* ===== TABLET BREAKPOINT (768px - 1024px) ===== */
@media (max-width: 1024px) and (min-width: 769px) {
    .app {
        grid-template-columns: 220px 1fr;
    }

    .panel {
        display: none;
    }

    .search-container {
        margin: 0 24px;
        max-width: 380px;
    }

    .reader-container,
    .index-container,
    .tag-page-container {
        padding: 40px 32px;
    }
}

/* ===== MOBILE BREAKPOINT (<768px) ===== */
@media (max-width: 768px) {
    /* Body adjustments for mobile */
    body {
        overflow: auto;
        padding-bottom: 56px; /* Space for bottom nav */
    }

    body.menu-open {
        overflow: hidden;
    }

    /* App grid becomes single column */
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: 56px 1fr;
        height: auto;
        min-height: 100vh;
    }

    /* Header mobile layout */
    .header {
        padding: 0 12px;
        height: 56px;
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .mobile-menu-btn {
        display: block;
    }

    /* Logo adjustments */
    .logo {
        gap: 10px;
    }

    .logo-mark {
        width: 28px;
        height: 28px;
    }

    .logo-text {
        font-size: 1.125rem;
    }

    .logo-text span {
        display: none;
    }

    /* Hide desktop search and nav in header */
    .search-container {
        display: none;
    }

    .header-nav {
        display: none;
    }

    /* Show mobile search button */
    .mobile-search-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Show sidebar overlay */
    .sidebar-overlay {
        display: block;
        pointer-events: none;
    }

    .sidebar-overlay.active {
        pointer-events: auto;
    }

    /* Sidebar becomes slide-out drawer */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        max-width: 85vw;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform var(--duration-normal) var(--ease-out);
        padding-top: 72px;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Hide right panel */
    .panel {
        display: none;
    }

    /* Show bottom nav */
    .bottom-nav {
        display: block;
    }

    /* Main content adjustments */
    .main {
        overflow: visible;
    }

    .reader-container {
        padding: 24px 16px;
        padding-bottom: 80px; /* Extra space above bottom nav */
    }

    .index-container,
    .tag-page-container {
        padding: 24px 16px;
        padding-bottom: 80px;
    }

    /* Entry header mobile */
    .entry-header {
        margin-bottom: 24px;
        padding-bottom: 20px;
    }

    .entry-meta {
        gap: 12px;
        flex-direction: column;
    }

    /* Entry content mobile typography */
    .entry-content {
        font-size: 1rem;
        line-height: 1.75;
    }

    .entry-content h1 { font-size: 1.5rem; }
    .entry-content h2 { font-size: 1.25rem; }
    .entry-content h3 { font-size: 1.0625rem; }

    .entry-content pre {
        padding: 16px;
        margin: 20px -16px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .entry-content pre code {
        font-size: 0.75rem;
    }

    .entry-content blockquote {
        margin-left: 0;
        padding-left: 16px;
    }

    /* Prevent content overflow */
    .reader-container {
        overflow-x: hidden;
        max-width: 100vw;
    }

    .entry-content {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .entry-content code {
        word-break: break-all;
    }

    /* Tables: wrap in scrollable container */
    .entry-content table {
        display: table;
        width: max-content;
        min-width: 100%;
        margin: 20px 0;
    }

    /* Create scrollable wrapper using overflow on parent when table overflows */
    .entry-content {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .entry-content th,
    .entry-content td {
        padding: 10px 12px;
    }

    /* Index page mobile */
    .index-container h1 {
        font-size: 1.75rem;
        margin-bottom: 28px;
    }

    .entry-list li {
        padding: 14px;
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .entry-list a {
        font-size: 0.875rem;
    }

    /* Tags cloud mobile */
    .tags-cloud {
        gap: 6px;
    }

    .tag {
        padding: 6px 12px;
        font-size: 0.6875rem;
    }

    /* Graph container mobile */
    .graph-container {
        position: relative;
        height: calc(100vh - 56px - 56px); /* Header + bottom nav */
    }

    .graph-controls {
        left: 12px;
        right: 12px;
        top: auto;
        bottom: 72px;
        width: auto;
    }

    .graph-control-list {
        max-height: 120px;
    }

    /* Tree items larger for touch */
    .tree-item {
        padding: 12px;
        min-height: 44px;
    }

    .tree-folder-header {
        padding: 12px;
        min-height: 44px;
    }

    .nav-tab {
        padding: 12px;
        min-height: 44px;
    }

    /* Sidebar footer mobile */
    .sidebar-footer {
        padding: 20px;
    }
}

/* ===== SMALL MOBILE (<480px) ===== */
@media (max-width: 480px) {
    .reader-container,
    .index-container,
    .tag-page-container {
        padding: 20px 12px;
        padding-bottom: 80px;
    }

    .entry-content pre {
        margin: 16px -12px;
        padding: 14px 12px;
    }

    .index-container h1 {
        font-size: 1.5rem;
    }

    .logo-text {
        font-size: 1rem;
    }
}

/* ===== LANDSCAPE MOBILE ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .sidebar {
        width: 260px;
    }

    .bottom-nav {
        height: 48px;
    }

    body {
        padding-bottom: 48px;
    }
}

/* ===== DARK MODE ADJUSTMENTS FOR MOBILE ===== */
@media (max-width: 768px) {
    .sidebar-overlay {
        background: rgba(0, 0, 0, 0.7);
    }
}

@media (max-width: 768px) and (prefers-color-scheme: light) {
    .sidebar-overlay {
        background: rgba(46, 52, 64, 0.5);
    }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .sidebar-overlay,
    .search-overlay,
    .mobile-menu-btn span {
        transition: none;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .header,
    .sidebar,
    .panel,
    .bottom-nav,
    .mobile-menu-btn,
    .mobile-search-btn {
        display: none !important;
    }

    .app {
        display: block;
    }

    .main {
        overflow: visible;
    }

    .reader-container,
    .index-container,
    .tag-page-container {
        padding: 0;
        max-width: none;
    }
}
