:root {
    color-scheme: light;
    font-family: Arial, sans-serif;
    --page-width: 1240px;
    --surface: #ffffff;
    --surface-muted: #f8fbff;
    --border: #d9e2ec;
    --text: #1f2933;
    --text-muted: #52606d;
    --accent: #0b5ed7;
    --accent-dark: #084298;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #f5f7fa;
    color: var(--text);
    line-height: 1.6;
    font-size: 16px;
}

body.theme-dark {
    color-scheme: dark;
    --surface: #111827;
    --surface-muted: #1f2937;
    --border: #374151;
    --text: #f3f4f6;
    --text-muted: #cbd5e1;
    --accent: #60a5fa;
    --accent-dark: #93c5fd;
    background: #030712;
}

a {
    color: var(--accent);
    text-underline-offset: 0.15em;
}

a:hover {
    color: var(--accent-dark);
}

h1,
h2,
h3 {
    line-height: 1.2;
    margin-top: 0;
}

p,
ul,
ol {
    margin-top: 0;
}

ul {
    padding-left: 1.25rem;
}

.site-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.site-header,
.site-footer {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.site-footer {
    border-top: 1px solid var(--border);
    border-bottom: 0;
    margin-top: auto;
}

.site-header__inner,
.site-main,
.site-footer__inner {
    width: min(var(--page-width), calc(100% - 3rem));
    margin: 0 auto;
}

.site-header__inner,
.site-footer__inner {
    padding: 1.25rem 0;
}

.site-main {
    padding: 2rem 0 3rem;
}

.site-branding {
    margin: 0 0 0.75rem;
    font-size: 1.7rem;
    font-weight: 700;
}

.site-branding a {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    color: inherit;
    text-decoration: none;
}

.site-branding__logo {
    width: 5rem;
    height: 5rem;
    object-fit: contain;
}

.site-nav {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
}

.site-nav a {
    display: inline-flex;
    align-items: center;
    min-height: 2.5rem;
    padding: 0.45rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-muted);
    text-decoration: none;
    font-weight: 600;
}

.site-nav__search {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-left: auto;
}

.site-nav__search form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin: 0;
}

.site-nav__search input[type="search"] {
    width: min(280px, 32vw);
    min-width: 180px;
    padding: 0.6rem 0.85rem;
    border-radius: 999px;
    background: #fff;
}

.site-nav__search button {
    min-height: 2.5rem;
    border-radius: 999px;
}

.site-dropdown--settings {
    margin-left: 0.25rem;
}

.site-dropdown--settings summary {
    justify-content: center;
    min-width: 2.75rem;
    padding: 0.45rem 0.7rem;
}

.site-dropdown__menu--settings {
    left: auto;
    right: 0;
    min-width: 220px;
}

.site-dropdown {
    position: relative;
}

.site-dropdown summary {
    display: inline-flex;
    align-items: center;
    min-height: 2.5rem;
    padding: 0.45rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-muted);
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}

.site-dropdown summary::-webkit-details-marker {
    display: none;
}

.site-dropdown summary::after {
    content: "▾";
    margin-left: 0.5rem;
    font-size: 0.8rem;
}

.site-dropdown[open] summary::after {
    content: "▴";
}

.site-dropdown__menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    z-index: 10;
    min-width: 320px;
    max-width: 520px;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
}

.site-dropdown__menu > * + * {
    margin-top: 1rem;
}

.site-dropdown__link {
    display: inline-flex;
    margin-bottom: 0.25rem;
    font-weight: 700;
}

.site-dropdown__menu--settings .site-dropdown__link,
.site-settings__toggle {
    display: flex;
    width: 100%;
    justify-content: flex-start;
    margin-bottom: 0;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-muted);
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
}

.site-settings__toggle::after {
    content: attr(data-theme-label);
    margin-left: auto;
    color: var(--text-muted);
    font-weight: 600;
}

.site-dropdown__menu--settings .site-dropdown__link:hover,
.site-dropdown__menu--settings .site-dropdown__link:focus-visible,
.site-settings__toggle:hover,
.site-settings__toggle:focus-visible {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

.site-dropdown__group {
    display: grid;
    gap: 0.5rem;
    position: relative;
}

.site-dropdown__group > a {
    display: inline-flex;
    font-weight: 700;
}

.site-dropdown__children {
    display: none;
    gap: 0.35rem;
    padding-left: 1rem;
    border-left: 2px solid var(--border);
}

.site-dropdown__group:hover .site-dropdown__children,
.site-dropdown__group:focus-within .site-dropdown__children {
    display: grid;
}

.site-dropdown__children a {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 0.1rem 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
}

.content-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
    padding: 1.5rem;
    min-width: 0;
}

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

.page-header__meta {
    max-width: 52rem;
    color: var(--text-muted);
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    margin-bottom: 1.5rem;
}

.action-row:last-child {
    margin-bottom: 0;
}

.split-layout {
    display: grid;
    grid-template-columns: minmax(0, 2.2fr) minmax(280px, 1fr);
    gap: 1.5rem;
    align-items: start;
}

.split-layout > *,
.form-grid > * {
    min-width: 0;
}

.stack {
    display: grid;
    gap: 1.5rem;
}

.meta-list {
    display: grid;
    gap: 0.75rem;
    margin: 0;
}

.meta-list dt {
    font-weight: 700;
}

.meta-list dd {
    margin: 0.25rem 0 0;
    color: var(--text-muted);
}

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

.tag-list a,
.tag-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    background: #e9f2ff;
    border: 1px solid #c7dcff;
    color: var(--accent-dark);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 600;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-muted);
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 700;
}

.status-pill--draft {
    border-color: #f1c27d;
    background: #fff7e6;
    color: #8a5a00;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    table-layout: fixed;
}

th,
td {
    padding: 0.9rem 1rem;
    border: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

th {
    background: var(--surface-muted);
    font-size: 0.95rem;
}

td p:last-child {
    margin-bottom: 0;
}

form > div {
    margin-bottom: 1rem;
}

label {
    display: inline-block;
    margin-bottom: 0.35rem;
    font-weight: 700;
}

input[type="text"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 0.75rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    font: inherit;
}

input[type="checkbox"],
input[type="radio"] {
    width: auto;
    margin-right: 0.5rem;
}

.publish-toggle-row {
    padding: 1rem 1.1rem;
    border: 2px solid #c7dcff;
    border-radius: 12px;
    background: #eef5ff;
    box-shadow: 0 4px 16px rgba(11, 94, 215, 0.08);
}

.publish-toggle-row label {
    margin-bottom: 0;
}

.publish-toggle-label {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--accent-dark);
}

.publish-toggle-checkbox {
    transform: scale(1.35);
    transform-origin: left center;
    accent-color: var(--accent);
}

.publish-toggle-row .form-help,
.publish-toggle-row ul {
    margin-top: 0.6rem;
}

.tag-autocomplete {
    position: relative;
    display: grid;
    gap: 0.75rem;
}

.tag-autocomplete__selected {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 1.5rem;
}

.tag-autocomplete__chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.7rem;
    border: 1px solid #c7dcff;
    border-radius: 999px;
    background: #e9f2ff;
    color: var(--accent-dark);
    font-size: 0.95rem;
    font-weight: 600;
}

.tag-autocomplete__chip button {
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 1rem;
    line-height: 1;
}

.tag-autocomplete__results {
    display: none;
    margin: 0;
    padding: 0.5rem;
    list-style: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.tag-autocomplete__results.is-visible {
    display: grid;
    gap: 0.25rem;
}

.tag-autocomplete__results button {
    justify-content: flex-start;
    min-height: 0;
    padding: 0.55rem 0.75rem;
    border: 0;
    background: transparent;
    color: var(--text);
    font-weight: 600;
}

.tag-autocomplete__results button:hover {
    background: var(--surface-muted);
    color: var(--text);
}

.tag-autocomplete__empty {
    padding: 0.25rem 0.1rem 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

textarea {
    min-height: 10rem;
    resize: vertical;
}

.markdown-editor__input {
    min-height: 24rem;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    line-height: 1.6;
}

.markdown-editor-panel {
    gap: 1rem;
}

.markdown-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.markdown-toolbar__button {
    min-height: 2.35rem;
    padding: 0.45rem 0.8rem;
}

.markdown-cheatsheet {
    display: grid;
    gap: 0.5rem;
}

.markdown-cheatsheet code {
    display: block;
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-muted);
    color: var(--text);
    white-space: pre-wrap;
}

button,
.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.75rem;
    padding: 0.65rem 1rem;
    border: 1px solid var(--accent);
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

button:hover,
.button-link:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #fff;
}

.button-link--secondary {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

.button-link--secondary:hover {
    background: var(--surface-muted);
    border-color: var(--border);
    color: var(--text);
}

.form-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
    gap: 1.5rem;
    align-items: start;
}

.form-panel,
.sidebar-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    min-width: 0;
}

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

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.text-content {
    overflow-wrap: anywhere;
}

.markdown-content {
    width: 90%;
}

.markdown-content > :first-child {
    margin-top: 0;
}

.markdown-content > :last-child {
    margin-bottom: 0;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4 {
    margin: 1.5rem 0 0.75rem;
}

.markdown-content p,
.markdown-content ul,
.markdown-content ol,
.markdown-content blockquote,
.markdown-content pre {
    margin: 0 0 1rem;
}

.markdown-content ul,
.markdown-content ol {
    padding-left: 1.5rem;
}

.markdown-content li + li {
    margin-top: 0.35rem;
}

.markdown-content blockquote {
    padding: 0.75rem 1rem;
    border-left: 4px solid var(--accent);
    border-radius: 0 8px 8px 0;
    background: var(--surface-muted);
    color: var(--text-muted);
}

.markdown-content code {
    padding: 0.12rem 0.35rem;
    border-radius: 6px;
    background: var(--surface-muted);
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.92em;
}

.markdown-content pre {
    width: 100%;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-muted);
    max-width: 100%;
    overflow-x: auto;
}

.markdown-content pre code {
    padding: 0;
    background: transparent;
}

.markdown-content a {
    word-break: break-word;
}

.markdown-content hr {
    margin: 1.5rem 0;
    border: 0;
    border-top: 1px solid var(--border);
}

.article-layout {
    max-width: 1040px;
    margin: 0 auto;
}

.article-content {
    font-size: 1.05rem;
    line-height: 1.8;
}

.article-preview {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-muted);
}

.article-preview__image-link {
    display: block;
}

.article-preview__image,
.article-preview__frame,
.article-preview__video {
    width: 100%;
    max-height: 640px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

.article-preview__image {
    display: block;
    width: auto;
    max-width: 100%;
    height: auto;
    object-fit: initial;
}

.article-preview__image--gif {
    cursor: pointer;
}

.article-preview__frame {
    min-height: 640px;
}

.article-preview__text {
    margin: 0;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    white-space: pre-wrap;
    overflow-x: auto;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
}

.pagination__pages {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.pagination__link,
.pagination__current {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-weight: 700;
    text-decoration: none;
}

.pagination__current {
    background: var(--surface-muted);
}

body.theme-dark .site-nav__search input[type="search"],
body.theme-dark .article-preview__frame,
body.theme-dark .article-preview__image,
body.theme-dark .article-preview__video,
body.theme-dark .article-preview__text,
body.theme-dark .site-dropdown__group,
body.theme-dark .tag-autocomplete__results,
body.theme-dark textarea,
body.theme-dark select,
body.theme-dark input[type="text"],
body.theme-dark input[type="password"] {
    background: var(--surface);
    color: var(--text);
}

body.theme-dark .tag-list a,
body.theme-dark .tag-pill,
body.theme-dark .tag-autocomplete__chip {
    background: rgba(96, 165, 250, 0.14);
    border-color: rgba(96, 165, 250, 0.35);
    color: #bfdbfe;
}

body.theme-dark .publish-toggle-row {
    background: rgba(96, 165, 250, 0.1);
    border-color: rgba(96, 165, 250, 0.35);
}

body.theme-dark .status-pill--draft {
    background: rgba(245, 158, 11, 0.14);
    border-color: rgba(245, 158, 11, 0.35);
    color: #fcd34d;
}

@media (max-width: 900px) {
    .site-header__inner,
    .site-main,
    .site-footer__inner {
        width: min(var(--page-width), calc(100% - 1.5rem));
    }

    .page-header,
    .split-layout,
    .form-grid {
        grid-template-columns: 1fr;
        display: grid;
    }

    .site-dropdown__menu {
        position: static;
        min-width: 0;
        max-width: none;
        margin-top: 0.5rem;
    }

    .site-nav__search {
        margin-left: 0;
        width: 100%;
    }

    .site-nav__search form {
        width: 100%;
    }

    .site-nav__search input[type="search"] {
        width: 100%;
    }

    .is-anonymous .site-branding {
        margin-bottom: 1rem;
    }

    .is-anonymous .site-nav {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .is-anonymous .site-nav > a,
    .is-anonymous .site-nav > details,
    .is-anonymous .site-nav > div {
        width: 100%;
    }

    .is-anonymous .site-nav a,
    .is-anonymous .site-dropdown summary,
    .is-anonymous .site-nav__search button {
        width: 100%;
        justify-content: center;
    }

    .is-anonymous .site-nav__search form {
        display: grid;
        grid-template-columns: 1fr;
    }

    .is-anonymous .site-dropdown--settings {
        margin-left: 0;
    }

    .is-anonymous .site-dropdown__group {
        gap: 0.75rem;
        padding: 0.75rem;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: #fff;
    }

    .is-anonymous .site-dropdown__children {
        display: grid;
        padding-left: 0.75rem;
    }

    .is-anonymous .site-dropdown__menu--settings {
        right: auto;
    }

    .is-anonymous .content-card,
    .is-anonymous .form-panel,
    .is-anonymous .sidebar-panel {
        padding: 1rem;
    }

    .is-anonymous .article-preview__frame {
        min-height: 320px;
    }
}
