:root {
    --bg: #1e1e1e;
    --bg-panel: #252526;
    --bg-elevated: #2d2d30;
    --border: #333;
    --text: #d4d4d4;
    --muted: #9a9a9a;
    --accent: #569cd6;
    --accent-soft: #9cdcfe;
    --danger: #c53b3b;
    --danger-hover: #a02d2d;
    --google: #4285f4;
    --google-hover: #3367d6;
    --reader-bg: #1a1a1a;
    --reader-text: #e8e4dc;
    --reader-max: 42rem;
    --font-ui: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    --font-prose: "Georgia", "Times New Roman", serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text);
}

a { color: var(--accent-soft); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-panel);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand {
    color: var(--accent);
    font-weight: 700;
    white-space: nowrap;
    text-decoration: none;
}

.nav {
    display: flex;
    gap: 0.35rem;
    flex: 1;
    flex-wrap: wrap;
}

.nav-link {
    color: var(--muted);
    padding: 0.35rem 0.7rem;
    border-radius: 4px;
    text-decoration: none;
}

.nav-link:hover,
.nav-link.is-active {
    color: var(--text);
    background: var(--bg-elevated);
    text-decoration: none;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: var(--accent-soft);
    white-space: nowrap;
}

.logout-btn {
    background: var(--danger);
    color: #fff;
    border: none;
    padding: 0.35rem 0.7rem;
    border-radius: 4px;
    text-decoration: none;
}

.logout-btn:hover {
    background: var(--danger-hover);
    text-decoration: none;
}

.page {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
}

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    width: min(400px, 100%);
    margin: 4rem auto;
    background: var(--bg-panel);
    padding: 2rem;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.login-container h1 {
    color: var(--accent);
    margin-top: 0;
    font-size: 1.35rem;
}

.google-btn {
    display: inline-block;
    background: var(--google);
    color: #fff;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    font-weight: 700;
    margin-top: 1rem;
    text-decoration: none;
}

.google-btn:hover {
    background: var(--google-hover);
    text-decoration: none;
}

.hero-panel {
    background: var(--bg-panel);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.hero-panel h1 {
    color: var(--accent);
    margin: 0 0 0.5rem;
}

.hero-panel p { margin: 0; color: var(--muted); }

.eyebrow {
    font-size: 0.85rem;
    color: var(--muted);
    margin: 0 0 0.75rem;
}

.section-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.section-card {
    display: block;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    color: inherit;
    text-decoration: none;
    transition: border-color 0.15s ease, transform 0.15s ease;
}

.section-card:hover {
    border-color: var(--accent);
    text-decoration: none;
    transform: translateY(-1px);
}

.section-card h2 {
    margin: 0 0 0.5rem;
    color: var(--accent);
    font-size: 1.2rem;
}

.section-card p {
    margin: 0 0 1rem;
    color: var(--muted);
    font-size: 0.95rem;
}

.section-card .meta {
    color: var(--accent-soft);
    font-size: 0.85rem;
}

.doc-list {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--bg-panel);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.doc-list li + li { border-top: 1px solid var(--border); }

.doc-list a {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1rem 1.15rem;
    color: inherit;
    text-decoration: none;
}

.doc-list a:hover { background: var(--bg-elevated); }

.doc-title { color: var(--accent-soft); font-weight: 600; }
.doc-meta { color: var(--muted); font-size: 0.85rem; }

.doc-folder .doc-title { color: var(--text); }

.doc-list.compact a {
    flex-direction: row;
    justify-content: space-between;
    padding: 0.55rem 0.85rem;
}

.doc-list.compact a.is-current {
    background: var(--bg-elevated);
    font-weight: 600;
}

.doc-siblings {
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.empty { color: var(--muted); }

.note-view {
    max-width: 720px;
    margin: 0 auto;
    background: var(--bg-panel);
    padding: 1.5rem;
    border-radius: 8px;
}

.prose {
    line-height: 1.7;
    font-size: 1.05rem;
}

.prose h1, .prose h2, .prose h3 {
    color: var(--accent);
    line-height: 1.3;
}

.prose h3 {
    margin-top: 2rem;
    margin-bottom: 0.5rem;
    font-size: 1.15rem;
}

.prose h3 + p img,
.prose h3 + img {
    margin-top: 0.25rem;
}

.prose p { margin: 0 0 1em; }
.prose blockquote {
    margin: 1em 0;
    padding: 0.25em 0 0.25em 1em;
    border-left: 3px solid var(--accent);
    color: var(--muted);
}

.prose img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 1em auto;
    border-radius: 6px;
}

.prose table {
    width: 100%;
    margin: 1em 0;
    border-collapse: collapse;
    border: 1px solid var(--border);
}

.prose th,
.prose td {
    padding: 0.5em 0.75em;
    border: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.prose th {
    background: var(--bg-elevated);
    color: var(--accent-soft);
    font-weight: 600;
}

.prose tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.02);
}

/* —— Reader —— */
body.reader-mode {
    background: var(--reader-bg);
}

body.reader-mode .topbar { display: none; }

.reader-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

.reader-toc {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: auto;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    padding: 1rem;
}

.toc-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    gap: 0.5rem;
}

.toc-head a { color: var(--accent-soft); font-size: 0.9rem; }

.reader-toc ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.reader-toc li a {
    display: block;
    padding: 0.55rem 0.65rem;
    border-radius: 4px;
    color: var(--muted);
    text-decoration: none;
}

.reader-toc li a:hover,
.reader-toc li.is-current a {
    background: var(--bg-elevated);
    color: var(--text);
}

.reader {
    max-width: calc(var(--reader-max) + 6rem);
    margin: 0 auto;
    padding: 1.25rem 1.5rem 4rem;
    width: 100%;
}

.reader-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.reader-controls { display: flex; gap: 0.35rem; }

.ghost-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 4px;
    padding: 0.35rem 0.65rem;
    cursor: pointer;
}

.ghost-btn:hover { border-color: var(--accent); }

.reader-body {
    font-family: var(--font-prose);
    font-size: var(--reader-size, 1.125rem);
    line-height: 1.85;
    color: var(--reader-text);
    max-width: var(--reader-max);
    margin: 0 auto;
}

.reader-body h1,
.reader-body h2,
.reader-body h3 {
    font-family: var(--font-ui);
    color: var(--accent-soft);
}

.reader-nav {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    max-width: var(--reader-max);
    margin: 2.5rem auto 0;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.reader-nav.compact { max-width: none; margin-top: 2rem; }
.reader-nav a { color: var(--accent-soft); }

.progress-bar {
    position: fixed;
    left: 0;
    bottom: 0;
    height: 3px;
    width: 0;
    background: var(--accent);
    z-index: 30;
    transition: width 0.05s linear;
}

body.reader-light {
    --reader-bg: #f7f8fa;
    --reader-text: #1f2430;
    --bg-panel: #ffffff;
    --bg-elevated: #eef1f5;
    --border: #d7dde5;
    --text: #1f2430;
    --muted: #667085;
    --accent: #2f6fed;
    --accent-soft: #1d4ed8;
}

.toc-toggle { display: none; }

@media (max-width: 900px) {
    .reader-shell { grid-template-columns: 1fr; }

    .reader-toc {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(300px, 88vw);
        transform: translateX(-105%);
        transition: transform 0.2s ease;
        z-index: 40;
        box-shadow: 8px 0 24px rgba(0, 0, 0, 0.35);
    }

    .reader-toc.is-open { transform: translateX(0); }
    .toc-toggle { display: inline-flex; }
    .topbar { flex-wrap: wrap; }
    .user-info { width: 100%; justify-content: flex-end; }
}
