:root {
    --bg: #272822;
    --surface: #2e2f27;
    --surface-raised: #3e3d32;
    --surface-hover: #49483e;
    --text: #f8f8f2;
    --muted: #b8b8a0;
    --accent: #f92672;
    --border: #49483e;
    --code-bg: #3e3d32;
    --tag-pink: #f92672;
    --tag-green: #a6e22e;
    --tag-blue: #66d9ef;
    --tag-yellow: #e6db74;
    --tag-orange: #fd971f;
    --tag-purple: #ae81ff;
    --sidebar-width: 12rem;
    --content-width: 900px;
    --window-gutter: 2rem;
    --window-width: calc(
        var(--sidebar-width) + var(--content-width) + var(--window-gutter)
    );
    --max-width: var(--content-width);
    color-scheme: dark;
}

html[data-theme="light"] {
    --bg: #f8f8f2;
    --surface: #f1f1e8;
    --surface-raised: #e8e8dd;
    --surface-hover: #deded0;
    --text: #272822;
    --muted: #75715e;
    --accent: #f92672;
    --border: #c9c9bd;
    --code-bg: #eeeee6;
    --tag-pink: #d6266c;
    --tag-green: #6f8f1a;
    --tag-blue: #2591a8;
    --tag-yellow: #a68a1c;
    --tag-orange: #cc6a10;
    --tag-purple: #7e4fd1;
    color-scheme: light;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--bg);
    min-height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.7;
    margin: 0;
    min-height: 100vh;
}

.app-shell {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    margin: 0 auto;
    max-width: var(--window-width);
    min-height: 100vh;
}

.topbar,
.statusbar {
    align-items: center;
    background: var(--surface);
    color: var(--muted);
    display: flex;
    font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
    font-size: 0.75rem;
    min-height: 2.5rem;
    padding: 0 1rem;
}

.topbar {
    border-bottom: 1px solid var(--border);
    gap: 0.85rem;
}

.window-title {
    color: var(--text);
    font-family: inherit;
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
}

.window-context {
    color: var(--muted);
}

.workspace {
    display: flex;
    flex: 1;
    min-height: 0;
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    flex: 0 0 var(--sidebar-width);
    padding: 1.25rem 0.75rem;
}

.sidebar-label {
    color: var(--muted);
    font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    margin: 0 0 0.75rem 0.6rem;
}

.file-tree {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.tree-item {
    border-radius: 4px;
    color: var(--muted);
    font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
    font-size: 0.85rem;
    padding: 0.35rem 0.6rem;
    text-decoration: none;
}

.tree-item:hover,
.tree-item.is-active {
    background: var(--surface-hover);
    color: var(--text);
}

.tree-item.is-active {
    box-shadow: inset 2px 0 var(--accent);
}

.tree-icon {
    color: var(--accent);
    display: inline-block;
    margin-right: 0.4rem;
    text-align: center;
    width: 1rem;
}

.editor-pane {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.editor-tab {
    align-items: center;
    background: var(--surface-raised);
    border-bottom: 1px solid var(--border);
    color: var(--text);
    display: flex;
    gap: 0.75rem;
    padding: 1.75rem 2rem;
}

.tab-dot {
    background: var(--accent);
    border-radius: 50%;
    flex-shrink: 0;
    height: 0.6rem;
    width: 0.6rem;
}

.editor-tab-title {
    font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.25;
}

.editor-content {
    max-width: var(--max-width);
    padding: 1.5rem 2rem 5rem;
    width: 100%;
}

h1 {
    font-size: 2rem;
    font-weight: 650;
    line-height: 1.25;
    margin: 0 0 1.5rem;
}

h2,
h3 {
    font-weight: 700;
    line-height: 1.35;
    margin: 2rem 0 1rem;
}

h2 {
    font-size: 1.35rem;
}
h3 {
    font-size: 1.1rem;
}

p {
    margin: 0 0 1rem;
}

a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

a:hover {
    opacity: 0.8;
}

.article-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.content-intro + .article-list {
    margin-top: 2rem;
}

.article-list > li {
    align-items: baseline;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    padding: 0.8rem 0;
}

.article-list-main {
    align-items: baseline;
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.article-list > li:first-child {
    border-top: 1px solid var(--border);
}

.article-list a {
    text-decoration: none;
}

.article-list a:hover {
    text-decoration: underline;
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.tag-list li {
    border: none;
    margin: 0;
    padding: 0;
}

.tag-list a {
    --tag-color: hsl(calc(var(--tag-index) * 360 / var(--tag-count)) 70% 55%);
    background: color-mix(in srgb, var(--tag-color) 16%, transparent);
    border: 1px solid color-mix(in srgb, var(--tag-color) 45%, transparent);
    border-radius: 999px;
    color: var(--tag-color);
    display: inline-block;
    font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
    font-size: 0.7rem;
    padding: 0.15rem 0.6rem;
    text-decoration: none;
}

.tag-list a:hover {
    background: color-mix(in srgb, var(--tag-color) 28%, transparent);
    color: var(--tag-color);
    text-decoration: none;
}

article .tag-list {
    margin-bottom: 1.5rem;
}

.tag-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    list-style: none;
    margin: 0;
    padding: 0;
}

.content-intro + .tag-grid {
    margin-top: 2rem;
}

.tag-card {
    --tag-color: hsl(calc(var(--tag-index) * 360 / var(--tag-count)) 70% 55%);
    background: color-mix(in srgb, var(--tag-color) 10%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--tag-color) 35%, var(--border));
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    height: 100%;
    padding: 1.1rem 1.25rem;
    text-decoration: none;
    transition:
        background-color 0.15s ease,
        border-color 0.15s ease,
        transform 0.15s ease;
}

.tag-card:hover {
    background: color-mix(in srgb, var(--tag-color) 20%, var(--surface));
    border-color: var(--tag-color);
    text-decoration: none;
    transform: translateY(-2px);
}

.tag-card-name {
    color: var(--tag-color);
    font-size: 1.15rem;
    font-weight: 650;
}

.tag-card-count {
    color: var(--muted);
    font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
    font-size: 0.75rem;
}

.date {
    color: var(--muted);
    flex-shrink: 0;
    font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
    font-size: 0.75rem;
}

.draft-badge {
    border: 1px solid var(--accent);
    border-radius: 3px;
    color: var(--accent);
    font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
    font-size: 0.7rem;
    margin-left: 0.5rem;
    padding: 0.1rem 0.35rem;
    text-transform: uppercase;
}

article .date {
    display: block;
    margin-bottom: 2rem;
}

code,
pre {
    font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
}

code {
    background: var(--code-bg);
    border-radius: 3px;
    font-size: 0.9em;
    padding: 0.15em 0.35em;
}

pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow-x: auto;
    padding: 1rem;
}

pre code {
    background: none;
    padding: 0;
}

blockquote {
    border-left: 3px solid var(--accent);
    color: var(--muted);
    margin: 1.5rem 0;
    padding: 0.5rem 1rem;
}

blockquote p {
    margin-bottom: 0;
}

.statusbar {
    border-top: 1px solid var(--border);
    gap: 1rem;
    justify-content: space-between;
    position: sticky;
    bottom: 0;
    z-index: 1;
}

.statusbar-group {
    white-space: nowrap;
}

.statusbar a {
    color: inherit;
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    padding: 0.15rem 0.45rem;
    white-space: nowrap;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
    background: var(--surface-hover);
    border-color: var(--accent);
    color: var(--text);
}

@media (max-width: 640px) {
    .sidebar {
        flex-basis: 3.25rem;
        padding: 1.25rem 0.4rem;
    }

    .sidebar-label {
        font-size: 0;
        margin: 0;
    }

    .tree-item {
        font-size: 0;
        padding: 0.5rem;
        text-align: center;
    }

    .tree-icon {
        font-size: 1.1rem;
        line-height: 1;
        margin: 0;
    }

    .editor-content {
        padding: 1.25rem 1.25rem 3rem;
    }

    h1 {
        font-size: 1.65rem;
    }

    .editor-tab {
        padding: 1.25rem 1.25rem;
    }

    .editor-tab-title {
        font-size: 1.5rem;
    }

    .article-list > li {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.2rem;
    }

    .statusbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.25rem;
        padding-bottom: 0.6rem;
        padding-top: 0.6rem;
    }
}
