:root {
    color-scheme: light dark;

    &:has(> head > meta[name="color-scheme"][content="dark"]) {
        color-scheme: dark;
    }

    &:has(> head > meta[name="color-scheme"][content="light"]) {
        color-scheme: light;
    }

    --bg: light-dark(#f6f7f9, #0f1218);
    --surface: light-dark(#ffffff, #171c25);
    --surface-subtle: light-dark(#f0f3f7, #1f2633);
    --border: light-dark(#e3e7ee, #2b3344);
    --text: light-dark(#1c222d, #e7ecf4);
    --text-muted: light-dark(#5b6577, #9aa5b8);
    --accent: light-dark(#10896b, #3ad2a7);
    --accent-hover: light-dark(#0c6f56, #5be3bc);
    --danger: light-dark(#c93535, #f06565);
    --warn: light-dark(#b5720b, #f0b048);
    --shadow: light-dark(0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 4px rgba(0, 0, 0, 0.35));
    --radius: 12px;
    --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

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

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

img {
    max-width: 100%;
    height: auto;
}

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

.container {
    width: min(1140px, 100% - 32px);
    margin-inline: auto;
}

/* Header */
.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-block: 12px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
}

.brand-avatar {
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.brand-text strong {
    font-size: 1.1rem;
}

.brand-text small {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.nav-link {
    padding: 6px 12px;
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.94rem;
    font-weight: 500;
}

.nav-link:hover,
.nav-link.is-active {
    color: var(--accent);
    background: var(--surface-subtle);
}

.header-tools {
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-form input {
    width: 180px;
    padding: 7px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-subtle);
    color: var(--text);
    font-size: 0.9rem;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-subtle);
    color: var(--text);
    cursor: pointer;
    font-size: 1.05rem;
}

/* Theme toggle icon visibility driven purely by <meta name="color-scheme"> + OS preference */
.theme-option--to-light {
    display: none;
}

.theme-option--to-dark {
    display: inline;
}

@media (prefers-color-scheme: dark) {
    :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .theme-option--to-light {
        display: inline;
    }

    :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .theme-option--to-dark {
        display: none;
    }
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) .theme-option--to-light {
    display: inline;
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) .theme-option--to-dark {
    display: none;
}

/* Main layout */
.main-shell {
    padding-block: 28px 48px;
    min-height: calc(100vh - 150px);
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

/* Hero Carousel */
.hero-carousel {
    padding: 0;
    overflow: hidden;
    margin-bottom: 24px;
}

.carousel-viewport {
    position: relative;
}

.carousel-track {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    touch-action: manipulation;
}

.carousel-track::-webkit-scrollbar {
    display: none;
}

@media (prefers-reduced-motion: no-preference) {
    .carousel-track {
        scroll-behavior: smooth;
    }
}

.carousel-track:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.carousel-slide {
    position: relative;
    flex: 0 0 100%;
    min-width: 100%;
    scroll-snap-align: center;
    aspect-ratio: 1434 / 620;
    min-height: 260px;
    max-height: 460px;
    overflow: hidden;
    background: #101622;
}

/* Continuous looping via CSS order parking without DOM cloning (--current has no default so no-JS starts at slide 1) */
.carousel-track > :first-child {
    order: clamp(0, var(--current) - (var(--children-count, sibling-count()) - 2), 1);
}

.carousel-track > :last-child {
    order: calc(-1 * clamp(0, 1 - var(--current), 1));
}

.carousel-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 35%;
    user-select: none;
    pointer-events: none;
}

.hero-overlay {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    z-index: 1;
    padding: 56px 68px 46px;
    background: linear-gradient(
        to top,
        rgba(8, 13, 22, 0.84) 0%,
        rgba(8, 13, 22, 0.42) 55%,
        transparent 100%
    );
    color: #f8fafc;
}

.hero-kicker {
    display: inline-block;
    font-size: 0.74rem;
    letter-spacing: 0.14em;
    color: #6ee7c8;
    font-weight: 600;
}

.hero-title {
    margin: 6px 0;
    font-size: clamp(1.25rem, 2.4vw, 1.85rem);
    line-height: 1.3;
    text-shadow: 0 1px 10px rgba(0, 0, 0, 0.45);
}

.hero-subtitle {
    margin: 0;
    max-width: 640px;
    color: #e2e8f0;
    font-size: 0.94rem;
    text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
}

.hero-date {
    display: inline-block;
    margin-top: 8px;
    font-size: 0.78rem;
    color: #cbd5e1;
    letter-spacing: 0.04em;
}

.carousel-controls {
    position: absolute;
    inset-inline: 14px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
}

.carousel-btn {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.45);
    background: rgba(10, 15, 24, 0.58);
    color: #ffffff;
    font-size: 1.7rem;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
    backdrop-filter: blur(4px);
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.carousel-btn:hover {
    background: rgba(10, 15, 24, 0.82);
    border-color: rgba(255, 255, 255, 0.85);
}

.carousel-btn:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

.carousel-markers {
    position: absolute;
    inset-inline: 0;
    bottom: 10px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.carousel-marker {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 4px;
    border: 0;
    background: transparent;
    cursor: pointer;
    touch-action: manipulation;
}

.carousel-marker::after {
    content: "";
    display: block;
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.55);
    border: 1.5px solid rgba(10, 15, 24, 0.55);
    transition: width 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.carousel-marker[aria-current="true"]::after {
    width: 26px;
    background: #3ad2a7;
    border-color: #ffffff;
}

.carousel-marker:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 1px;
    border-radius: 999px;
}

@media (max-width: 640px) {
    .carousel-slide {
        aspect-ratio: 16 / 10;
        min-height: 230px;
    }

    .hero-overlay {
        padding: 36px 20px 44px;
    }

    .carousel-controls {
        inset-inline: 8px;
    }

    .carousel-btn {
        width: 34px;
        height: 34px;
        font-size: 1.35rem;
    }
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 24px;
    align-items: start;
}

.list-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 16px;
}

.list-header h1 {
    margin: 0;
    font-size: 1.4rem;
}

.article-list {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.article-card {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.article-card:not(:has(.article-cover)) {
    grid-template-columns: minmax(0, 1fr);
}

.article-cover img {
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    border-radius: 8px;
    cursor: zoom-in;
    display: block;
    background: var(--surface-subtle);
}

.article-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 0.84rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 600;
}

.badge-warn {
    background: color-mix(in srgb, var(--warn) 18%, transparent);
    color: var(--warn);
}

.article-title {
    margin: 0 0 8px;
    font-size: 1.22rem;
    line-height: 1.4;
}

.article-title a {
    color: var(--text);
}

.article-title a:hover {
    color: var(--accent);
}

.article-excerpt {
    margin: 0 0 12px;
    color: var(--text-muted);
    font-size: 0.93rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.read-more {
    font-size: 0.88rem;
    font-weight: 600;
}

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.sidebar h2 {
    margin: 0 0 12px;
    font-size: 1rem;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.about-card {
    text-align: center;
}

.about-photo {
    width: 100%;
    border-radius: 8px;
    margin-bottom: 10px;
}

.about-name {
    font-weight: 700;
    margin: 4px 0;
}

.visit-badge {
    margin-top: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--surface-subtle);
    font-size: 0.86rem;
}

.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-subtle);
    color: var(--text);
    font-size: 0.82rem;
}

.tag-pill span {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.tag-pill:hover,
.tag-pill.is-active {
    border-color: var(--accent);
    color: var(--accent);
}

.quote-list {
    margin: 0;
    padding-left: 18px;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.quote-list li + li {
    margin-top: 8px;
}

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

/* Detail page */
.article-detail {
    padding: 28px;
}

.detail-header h1 {
    margin: 8px 0 10px;
    font-size: clamp(1.45rem, 2.5vw, 1.95rem);
    line-height: 1.35;
}

.detail-desc {
    margin: 0 0 16px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.detail-cover {
    margin: 0 0 20px;
}

.detail-cover img {
    width: 100%;
    border-radius: 8px;
    cursor: zoom-in;
}

.prose {
    overflow-wrap: anywhere;
    font-size: 1rem;
}

.prose img {
    border-radius: 6px;
    margin-block: 10px;
    cursor: zoom-in;
}

.prose pre {
    padding: 14px 16px;
    border-radius: 8px;
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.88rem;
    line-height: 1.55;
}

.prose code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--surface-subtle);
}

.prose pre code {
    padding: 0;
    background: transparent;
}

.prose blockquote {
    margin: 16px 0;
    padding: 8px 16px;
    border-left: 3px solid var(--accent);
    background: var(--surface-subtle);
    color: var(--text-muted);
}

.prose table {
    width: 100%;
    border-collapse: collapse;
    margin-block: 16px;
}

.prose th,
.prose td {
    padding: 8px 10px;
    border: 1px solid var(--border);
    text-align: left;
}

.author-box {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 18px;
}

.author-avatar {
    border-radius: 50%;
    object-fit: cover;
}

.author-box h3 {
    margin: 0 0 4px;
    font-size: 1rem;
}

.author-box p {
    margin: 0;
}

.neighbor-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-top: 18px;
}

.neighbor-link {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 14px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.neighbor-link span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.neighbor-next {
    text-align: right;
}

/* Buttons & Forms */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 18px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 0.94rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-sm {
    min-height: 34px;
    padding: 0 12px;
    font-size: 0.85rem;
}

.btn-full {
    width: 100%;
}

.btn-primary {
    background: var(--accent);
    color: #ffffff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    color: #ffffff;
}

.btn-secondary {
    background: var(--surface-subtle);
    border-color: var(--border);
    color: var(--text);
}

.btn-danger {
    background: var(--danger);
    color: #ffffff;
}

.btn-disabled {
    background: var(--surface-subtle);
    color: var(--text-muted);
    opacity: 0.55;
    cursor: not-allowed;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 22px;
}

.pagination-info {
    color: var(--text-muted);
    font-size: 0.88rem;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
}

/* Auth & Admin */
.auth-wrap {
    max-width: 440px;
    margin: 24px auto;
}

.auth-card {
    max-width: 480px;
    margin-inline: auto;
}

.stack-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-row-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.editor-meta-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(200px, 1fr);
    gap: 14px;
    align-items: start;
}

.cover-field-row {
    display: flex;
    align-items: flex-end;
    gap: 16px;
}

.cover-field-inputs {
    flex: 1;
    min-width: 0;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.92rem;
    min-width: 0;
}

.field > label,
.field-label-text {
    font-weight: 500;
    color: var(--text);
}

.field-label-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.field-counter {
    font-size: 0.82rem;
    font-variant-numeric: tabular-nums;
}

.req-mark {
    color: var(--danger);
}

/* Direct-child form controls: never leak padding/width into nested rich-text toolbar controls */
.field > input,
.field > textarea,
.upload-row > input,
.inline-form > input,
.reply-inline-form > input {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-subtle);
    color: var(--text);
    font-family: inherit;
    font-size: max(1rem, 0.94rem);
    line-height: 1.45;
}

.field > textarea {
    padding: 12px 14px;
    line-height: 1.6;
    resize: vertical;
}

.field > input:focus-visible,
.field > textarea:focus-visible,
.upload-row > input:focus-visible,
.inline-form > input:focus-visible,
.reply-inline-form > input:focus-visible,
.ui-select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-color: var(--accent);
}

.field > input:user-invalid,
.field > textarea:user-invalid,
.ui-select:user-invalid {
    border-color: var(--danger);
}

/* Branded Select Styling: crisp cross-browser chevron fallback + progressive base-select */
.ui-select {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding-block: 10px;
    padding-inline: 12px 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background-color: var(--surface-subtle);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px 16px;
    color: var(--text);
    font-family: inherit;
    font-size: max(1rem, 0.94rem);
    line-height: 1.35;
    appearance: none;
    cursor: pointer;
}

@supports (appearance: base-select) {
    .ui-select,
    .ui-select::picker(select) {
        appearance: base-select;
    }

    .ui-select {
        display: inline-flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        background-image: none;
        padding-inline: 12px;
    }

    .ui-select::picker-icon {
        color: var(--text-muted);
        margin-inline-start: auto;
        transition: transform 0.15s ease;
    }

    .ui-select:open::picker-icon {
        transform: rotate(180deg);
    }

    .ui-select::picker(select) {
        background: var(--surface);
        color: var(--text);
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 4px;
        box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
    }

    .ui-select option {
        padding: 8px 10px;
        border-radius: 6px;
        color: var(--text);
        cursor: pointer;
    }

    .ui-select option:hover {
        background: var(--surface-subtle);
    }

    .ui-select option::checkmark {
        color: var(--accent);
    }
}

.upload-row,
.editor-toolbar,
.inline-form,
.form-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.is-hidden {
    display: none !important;
}

.editor-page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.editor-page-head h1 {
    margin: 0;
}

.cover-preview-wrap {
    flex: 0 0 160px;
    width: 160px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface-subtle);
}

.cover-preview-wrap img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
}

/* Rich Text Editor */
.rte-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.rte-mode-tabs {
    display: inline-flex;
    padding: 3px;
    border-radius: 8px;
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    gap: 3px;
}

.rte-mode-tab {
    padding: 4px 12px;
    border-radius: 6px;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.84rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
}

.rte-mode-tab.is-active {
    background: var(--surface);
    color: var(--accent);
    box-shadow: var(--shadow);
}

.rte-shell {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.rte-shell.is-dragover {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.rte-shell.is-fullscreen {
    position: fixed;
    inset: 14px;
    z-index: 60;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}

.rte-shell.is-fullscreen .rich-editor-canvas,
.rte-shell.is-fullscreen .rte-md-split,
.rte-shell.is-fullscreen .rte-source-pane textarea {
    flex: 1;
    max-height: none;
    height: 100%;
}

body.has-fullscreen-editor {
    overflow: hidden;
}

.rte-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding: 8px 10px;
    background: var(--surface-subtle);
    border-bottom: 1px solid var(--border);
}

.rte-group {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding-right: 6px;
    border-right: 1px solid var(--border);
}

.rte-group:last-child {
    border-right: 0;
    padding-right: 0;
}

.rte-group-right {
    margin-left: auto;
}

.rte-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 32px;
    padding: 0 7px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    font-size: 0.84rem;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
}

.rte-btn:hover {
    background: var(--surface);
    border-color: var(--border);
}

.rte-btn.is-active {
    background: color-mix(in srgb, var(--accent) 16%, transparent);
    border-color: var(--accent);
    color: var(--accent);
}

.rte-btn-accent {
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    color: var(--accent);
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
    font-weight: 600;
}

.rte-btn-accent:hover {
    background: var(--accent);
    color: #ffffff;
}

.rte-select {
    width: 104px;
    min-height: 32px;
    height: 32px;
    padding-block: 0;
    padding-inline: 10px 26px;
    border-radius: 6px;
    background-color: var(--surface);
    background-position: right 8px center;
    background-size: 14px 14px;
    font-size: 0.85rem;
    line-height: 1.2;
}

@supports (appearance: base-select) {
    .rte-select {
        padding-inline: 10px 8px;
    }
}

.rte-color-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.84rem;
    font-weight: 700;
    cursor: pointer;
    overflow: hidden;
}

.rte-color-btn.rte-color-bg {
    background: color-mix(in srgb, #facc15 35%, var(--surface));
}

.rte-color-btn input[type="color"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
}

.rich-editor-canvas {
    min-height: 420px;
    max-height: 68vh;
    overflow-y: auto;
    padding: 18px 22px;
    outline: none;
    background: var(--surface);
    color: var(--text);
}

.rich-editor-canvas:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    pointer-events: none;
}

.rich-editor-canvas img {
    max-width: 100%;
    border-radius: 6px;
    cursor: default;
}

.rich-editor-canvas td,
.rich-editor-canvas th {
    min-width: 60px;
}

.rte-md-pane {
    display: flex;
    flex-direction: column;
}

.rte-md-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 8px 12px;
    background: var(--surface-subtle);
    border-bottom: 1px solid var(--border);
    font-size: 0.84rem;
}

.rte-md-actions {
    display: flex;
    gap: 8px;
}

.rte-md-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 420px;
    max-height: 68vh;
}

.rte-md-split textarea {
    border: 0;
    border-right: 1px solid var(--border);
    border-radius: 0;
    resize: vertical;
    min-height: 420px;
    padding: 16px;
    background: var(--surface);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.92rem;
    line-height: 1.6;
}

.rte-md-preview {
    padding: 16px 20px;
    overflow-y: auto;
    background: var(--surface);
}

.rte-source-pane textarea {
    width: 100%;
    border: 0;
    border-radius: 0;
    min-height: 420px;
    padding: 16px;
    background: var(--surface);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.6;
    resize: vertical;
}

.rte-statusbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 12px;
    font-size: 0.82rem;
    background: var(--surface-subtle);
    border-top: 1px solid var(--border);
}

.rte-dialog {
    width: min(92vw, 520px);
    max-width: min(92vw, 520px);
}

.rte-dialog h2 {
    margin: 0;
    font-size: 1.1rem;
}

@media (max-width: 860px) {
    .rte-md-split {
        grid-template-columns: 1fr;
    }

    .rte-md-split textarea {
        border-right: 0;
        border-bottom: 1px solid var(--border);
        min-height: 240px;
    }
}

.upload-row input {
    flex: 1;
}

.inline-form input {
    width: auto;
    min-width: 220px;
}

.admin-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.admin-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tab-link {
    padding: 6px 12px;
    border-radius: 8px;
    color: var(--text-muted);
    font-weight: 500;
}

.tab-link.is-active,
.tab-link:hover {
    background: var(--surface-subtle);
    color: var(--accent);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

/* Guestbook */
.gb-stack {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.gb-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.gb-header-row h1 {
    margin: 0 0 4px;
    font-size: 1.45rem;
}

.gb-intro {
    margin: 0;
    font-size: 0.92rem;
}

.gb-tip {
    font-size: 0.86rem;
}

.gb-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.gb-item {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.gb-item-head {
    display: flex;
    align-items: center;
    gap: 12px;
}

.gb-avatar {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--accent) 16%, transparent);
    color: var(--accent);
    font-weight: 700;
    font-size: 1rem;
}

.gb-item-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.gb-item-author-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.gb-author {
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--text);
}

a.gb-author:hover {
    color: var(--accent);
}

.gb-floor {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.gb-time {
    font-size: 0.8rem;
}

.gb-content {
    color: var(--text);
    font-size: 0.96rem;
    line-height: 1.7;
    overflow-wrap: anywhere;
}

.gb-reply {
    padding: 12px 14px;
    border-radius: 8px;
    border-left: 3px solid var(--accent);
    background: var(--surface-subtle);
}

.gb-reply-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    font-size: 0.8rem;
}

.gb-reply p {
    margin: 0;
    font-size: 0.92rem;
    line-height: 1.65;
}

.admin-gb-item {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.admin-gb-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.reply-inline-form {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.reply-inline-form > input {
    flex: 1;
    min-height: 38px;
    padding: 6px 12px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-card strong {
    font-size: 1.65rem;
}

.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

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

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.admin-table th,
.admin-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.actions-cell {
    display: flex;
    gap: 8px;
    white-space: nowrap;
}

.alert {
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: 0.92rem;
}

.alert-error {
    background: color-mix(in srgb, var(--danger) 14%, transparent);
    color: var(--danger);
    border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
}

.alert-ok {
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    color: var(--accent);
    border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}

/* Native <dialog> — scroll containment + scoped display on [open] */
dialog {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    padding: 20px;
    max-width: min(92vw, 460px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

dialog:modal {
    overscroll-behavior: contain;
}

dialog::backdrop {
    background: rgba(10, 14, 22, 0.65);
    overflow: hidden;
    overscroll-behavior: contain;
}

dialog[open] {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.lightbox-dialog {
    max-width: min(94vw, 960px);
    padding: 14px;
}

.lightbox-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.lightbox-inner img {
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
}

.confirm-dialog h1 {
    margin: 0;
    font-size: 1.15rem;
}

.confirm-dialog p {
    margin: 0;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Footer */
.site-footer {
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding-block: 18px;
    text-align: center;
    font-size: 0.86rem;
    color: var(--text-muted);
}

.footer-inner p {
    margin: 0;
}

@media (max-width: 860px) {
    .content-grid {
        grid-template-columns: 1fr;
    }

    .article-card {
        grid-template-columns: 1fr;
    }

    .form-row-2,
    .editor-meta-grid,
    .stats-grid,
    .neighbor-nav {
        grid-template-columns: 1fr;
    }

    .cover-field-row {
        flex-direction: column;
        align-items: stretch;
    }

    .cover-preview-wrap {
        width: 100%;
        max-width: 240px;
        flex: none;
    }

    .reply-inline-form {
        flex-direction: column;
        align-items: stretch;
    }
}
