:root {
    --bg: #fafaf9;
    --surface: #ffffff;
    --surface-2: #f4f4f2;
    --text: #1c1917;
    --text-2: #57534e;
    --text-3: #a8a29e;
    --border: #e7e5e4;
    --accent: #5b5bd6;
    --accent-hover: #4a4ac4;
    --accent-soft: #eeeefc;
    --pink: #e5484d;
    --amber: #d97706;
    --danger: #dc2626;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(28, 25, 23, .04), 0 4px 16px rgba(28, 25, 23, .04);
    --shadow-hover: 0 2px 4px rgba(28, 25, 23, .06), 0 12px 32px rgba(28, 25, 23, .08);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111110;
        --surface: #1a1918;
        --surface-2: #232220;
        --text: #eeeeec;
        --text-2: #b5b3ad;
        --text-3: #6f6d66;
        --border: #2e2d2a;
        --accent: #8b8bf0;
        --accent-hover: #a3a3f5;
        --accent-soft: #24244a;
        --shadow: none;
        --shadow-hover: 0 0 0 1px var(--border);
    }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.6 var(--font);
    -webkit-font-smoothing: antialiased;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { line-height: 1.25; letter-spacing: -.01em; }
h1:focus { outline: none; }
code { font-family: var(--mono); font-size: .875em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }

.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 20px; }
.site-main { flex: 1; padding-top: 32px; padding-bottom: 64px; }
.narrow { max-width: 640px; }
.muted { color: var(--text-2); }
.section-gap { margin-top: 48px; }
.icon { vertical-align: -2px; }

/* Header */
.site-header {
    position: sticky; top: 0; z-index: 10;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); }
.brand:hover { color: var(--text); }
.brand-mark {
    width: 22px; height: 22px; border-radius: 7px;
    background: conic-gradient(from 210deg, #5b5bd6, #e5484d, #f5a524, #30a46c, #5b5bd6);
}
.header-nav { display: flex; align-items: center; gap: 12px; }
.header-nav form { margin: 0; }
.nav-link { color: var(--text-2); font-weight: 500; padding: 6px 8px; }
.nav-link:hover { color: var(--text); }
.nav-user { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
.nav-user img { border-radius: 50%; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 38px; padding: 0 16px;
    border: 1px solid transparent; border-radius: 9px;
    background: var(--accent); color: #fff;
    font: inherit; font-weight: 600; font-size: 14px;
    cursor: pointer; white-space: nowrap;
    transition: background-color .15s, border-color .15s, color .15s, transform .1s;
}
.btn:hover { background: var(--accent-hover); color: #fff; }
.btn:active { transform: scale(.97); }
.btn:focus-visible, .chip:focus-visible, .card:focus-visible, input:focus-visible, select:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger:hover { background: var(--danger); color: #fff; }

/* Hero & search */
.hero { text-align: center; padding: 32px 0 28px; }
.hero h1 { font-size: clamp(28px, 4vw, 40px); margin: 0 0 12px; }
.hero p { color: var(--text-2); margin: 0 auto 24px; max-width: 560px; }
.search { display: flex; gap: 8px; max-width: 560px; margin: 0 auto; }
.search input { flex: 1; }

input[type=search], input[type=text], input:not([type]), select {
    height: 42px; padding: 0 14px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); color: var(--text);
    font: inherit; width: 100%;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.search input { height: 46px; font-size: 16px; }
.search .btn { height: 46px; padding: 0 22px; }

/* Chips & filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0 32px; }
.chip {
    display: inline-flex; align-items: center; gap: 4px;
    height: 30px; padding: 0 12px; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text-2); font-size: 13px; font-weight: 500;
}
.chip:hover { color: var(--text); border-color: var(--text-3); }
.chip.active { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip.active a { color: inherit; margin-left: 2px; }
.chip-cat { height: 24px; padding: 0 9px; font-size: 12px; background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chip-cat:hover { color: var(--accent); border-color: transparent; }
.chip-tag small { color: var(--text-3); }

.list-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.list-meta { color: var(--text-2); font-size: 14px; display: flex; align-items: center; gap: 10px; }
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.tab { padding: 5px 14px; border-radius: 7px; color: var(--text-2); font-size: 13px; font-weight: 500; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card {
    display: flex; flex-direction: column; gap: 8px;
    padding: 18px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text); box-shadow: var(--shadow);
    transition: box-shadow .2s, transform .2s, border-color .2s;
}
.card:hover { color: var(--text); box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-repo { font-size: 12px; color: var(--text-3); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title { margin: 4px 0 0; font-size: 17px; word-break: break-word; }
.card-desc {
    margin: 0; color: var(--text-2); font-size: 14px; flex: 1;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; font-size: 13px; color: var(--text-3); }
.card-author { display: flex; align-items: center; gap: 6px; }
.card-author img { border-radius: 50%; }
.stats { display: flex; gap: 10px; font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 64px 0; color: var(--text-2); }
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 32px; color: var(--text-2); font-variant-numeric: tabular-nums; }

.tag-cloud { margin-top: 56px; }
.tag-cloud h2 { font-size: 15px; color: var(--text-2); font-weight: 600; margin: 0 0 12px; }
.tag-cloud div { display: flex; flex-wrap: wrap; gap: 8px; }

/* Detail */
.detail {
    display: grid; grid-template-columns: minmax(0, 1fr) 320px; column-gap: 40px; align-items: start;
    grid-template-areas: "head side" "body side";
}
.detail-head { grid-area: head; padding-bottom: 24px; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.detail-body { grid-area: body; min-width: 0; }
.detail-head h1 { font-size: 32px; margin: 12px 0 8px; word-break: break-word; }
.detail-desc { color: var(--text-2); font-size: 16px; margin: 0 0 16px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.detail-side { grid-area: side; position: sticky; top: 84px; display: flex; flex-direction: column; gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel-title { font-size: 14px; margin: 0 0 12px; }
.action-row { display: flex; gap: 8px; margin-top: 10px; }
.action-row form { margin: 0; flex: 1; display: flex; }
.action-row > .btn, .action-row form .btn { flex: 1; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 18px 0 0; font-size: 13px; }
.meta dt { color: var(--text-3); }
.meta dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.meta .author { display: flex; align-items: center; gap: 6px; }
.meta .author img { border-radius: 50%; }
.install { margin: 0; padding-left: 18px; font-size: 13px; color: var(--text-2); }
.install li + li { margin-top: 6px; }

/* Markdown */
.markdown { font-size: 15px; line-height: 1.75; overflow-wrap: break-word; }
.markdown > :first-child { margin-top: 0; }
.markdown h1 { font-size: 26px; } .markdown h2 { font-size: 21px; margin-top: 2em; } .markdown h3 { font-size: 17px; margin-top: 1.6em; }
.markdown pre { background: var(--surface-2); border-radius: 10px; padding: 14px 16px; overflow-x: auto; font-size: 13px; line-height: 1.6; }
.markdown pre code { background: none; padding: 0; font-size: inherit; }
.markdown blockquote { margin: 1em 0; padding: 4px 16px; border-left: 3px solid var(--border); color: var(--text-2); }
.markdown table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 12px; text-align: left; }
.markdown th { background: var(--surface-2); }
.markdown img { max-width: 100%; border-radius: 8px; }
.markdown hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }

/* Forms */
.lead { color: var(--text-2); margin-top: -4px; }
.form { display: flex; flex-direction: column; gap: 20px; margin-top: 28px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 600; font-size: 14px; }
.field em { font-style: normal; font-weight: 400; color: var(--text-3); margin-left: 4px; }
.field small { color: var(--text-3); font-size: 12px; }
.form .btn { align-self: flex-start; height: 42px; padding: 0 22px; }
.validation-message { color: var(--danger); font-size: 13px; }
.invalid { border-color: var(--danger) !important; }
.alert {
    padding: 12px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 16px;
    background: color-mix(in srgb, var(--danger) 10%, transparent);
    color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
    overflow-wrap: anywhere;
}
.form .alert { margin: 0; }

.site-footer { border-top: 1px solid var(--border); padding: 24px 0; color: var(--text-3); font-size: 13px; text-align: center; }
.site-footer .footer-icp { margin-top: 8px; }
.site-footer .footer-icp a { color: var(--text-3); }
.site-footer .footer-icp a:hover { color: var(--text); text-decoration: underline; }

#blazor-error-ui {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
    padding: 12px 20px; background: var(--danger); color: #fff;
}
#blazor-error-ui a { color: #fff; text-decoration: underline; margin-left: 8px; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 16px; }

@media (max-width: 860px) {
    .detail { grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "side" "body"; }
    .detail-side { position: static; margin-bottom: 32px; }
    .detail-head h1 { font-size: 26px; }
}
@media (max-width: 520px) {
    .container { padding: 0 16px; }
    .nav-user span { display: none; }
    .list-head { flex-direction: column; align-items: stretch; }
    .tabs { justify-content: space-between; }
    .tab { flex: 1; text-align: center; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
}

/* Status */
.status { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 600; vertical-align: middle; }
.status-published { background: color-mix(in srgb, #30a46c 14%, transparent); color: #2b9a66; }
.status-draft { background: color-mix(in srgb, var(--amber) 14%, transparent); color: var(--amber); }
.status-hidden { background: var(--surface-2); color: var(--text-3); }
.card-badges { display: flex; gap: 6px; align-items: center; }
.notice {
    padding: 12px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 20px;
    background: var(--accent-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}

/* Admin */
.back-link { display: inline-block; color: var(--text-2); font-size: 14px; margin-bottom: 8px; }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.admin-head h1 { margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.admin-filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.admin-filters input { flex: 1; min-width: 200px; }
.admin-filters select { width: auto; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th { text-align: left; font-weight: 600; color: var(--text-3); font-size: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.admin-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tbody tr:hover { background: var(--surface-2); }
.admin-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.admin-table .nowrap { white-space: nowrap; color: var(--text-2); }
.row-title { font-weight: 600; color: var(--text); }
.row-sub { font-size: 12px; color: var(--text-3); font-family: var(--mono); margin-top: 2px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.row-actions form { margin: 0; }
.admin-split { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 40px; align-items: start; }
.admin-split .form { margin-top: 0; }
.admin-split .preview { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; max-height: 80vh; overflow: auto; }
.admin-split .preview .markdown { font-size: 13px; }
.form-inline { margin: 20px 0 24px; }
.input-with-btn { display: flex; gap: 8px; }
.input-with-btn .btn { height: 42px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.source-line { font-size: 13px; color: var(--text-2); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; overflow-wrap: anywhere; }
textarea {
    padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); color: var(--text); font: inherit; width: 100%; resize: vertical;
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.small { font-size: 13px; margin: 0 0 12px; }
.panel .btn-block + .btn-block { margin-top: 8px; }
@media (max-width: 860px) {
    .admin-split { grid-template-columns: minmax(0, 1fr); }
    .field-row { grid-template-columns: 1fr; }
}
