:root {
    color-scheme: light;

    --bg: #eef3fb;

    --bg-aurora:
        radial-gradient(52rem 36rem at 85% -8%, rgba(53, 104, 224, 0.14), transparent 62%),
        radial-gradient(46rem 32rem at -12% 28%, rgba(11, 125, 150, 0.12), transparent 60%),
        radial-gradient(50rem 34rem at 50% 118%, rgba(122, 98, 233, 0.12), transparent 62%);

    --surface: rgba(255, 255, 255, 0.62);
    --surface-solid: #fbfcfe;
    --tint: rgba(255, 255, 255, 0.50);
    --tint-2: rgba(255, 255, 255, 0.82);
    --hover: rgba(23, 48, 89, 0.06);
    --blur: 14px;

    --line: rgba(23, 48, 89, 0.10);
    --line-2: rgba(23, 48, 89, 0.22);
    --stroke: rgba(255, 255, 255, 0.80);
    --ring: 0 0 0 1px var(--stroke);

    --text: #0d1b2e;
    --text-2: #3f5065;
    --text-3: #52627a;

    --accent: #2150c9;
    --accent-2: #0b7d96;
    --accent-soft: #e4ecfb;
    --accent-line: #b3c7ee;
    --on-accent: #ffffff;
    --grad-accent: linear-gradient(135deg, #3568e0, var(--accent-2));

    --r-1: 10px;
    --r-2: 14px;
    --r-3: 20px;
    --r-4: 26px;
    --r-pill: 999px;

    --sh-1: 0 1px 2px rgba(12, 30, 60, 0.04), 0 8px 24px -12px rgba(12, 30, 60, 0.20);
    --sh-2: 0 2px 6px rgba(12, 30, 60, 0.05), 0 18px 44px -18px rgba(12, 30, 60, 0.28);
    --sh-accent: 0 10px 28px -12px rgba(33, 80, 201, 0.60);

    --font-sans: system-ui, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-mono: ui-monospace, "SFMono-Regular", Consolas, monospace;

    --fs-xs: 0.75rem;
    --fs-sm: 0.8125rem;
    --fs-md: 0.9375rem;
    --fs-base: 1rem;
    --fs-lg: 1.125rem;
    --fs-title: clamp(1.5rem, 1.28rem + 0.9vw, 1.875rem);
    --fs-display: clamp(2.25rem, 1.5rem + 3vw, 3.25rem);

    --s-1: 4px;
    --s-2: 8px;
    --s-3: 12px;
    --s-4: 16px;
    --s-5: 24px;
    --s-6: 32px;
    --s-7: 48px;
    --s-8: 72px;

    --w-page: 1040px;
    --nav-h: 64px;

    --ease: cubic-bezier(0.22, 0.8, 0.28, 1);
    --t-fast: 0.15s var(--ease);
    --t: 0.24s var(--ease);
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --bg: #080d17;

    --bg-aurora:
        radial-gradient(52rem 36rem at 85% -8%, rgba(111, 162, 255, 0.16), transparent 62%),
        radial-gradient(46rem 32rem at -12% 28%, rgba(94, 211, 232, 0.10), transparent 60%),
        radial-gradient(50rem 34rem at 50% 118%, rgba(143, 123, 255, 0.14), transparent 62%);

    --surface: rgba(27, 36, 54, 0.60);
    --surface-solid: #1b2436;
    --tint: rgba(255, 255, 255, 0.05);
    --tint-2: rgba(255, 255, 255, 0.10);
    --hover: rgba(255, 255, 255, 0.07);

    --line: rgba(255, 255, 255, 0.10);
    --line-2: rgba(255, 255, 255, 0.20);
    --stroke: rgba(255, 255, 255, 0.14);

    --text: #eef2f9;
    --text-2: #a8b6cc;
    --text-3: #8b9ab2;

    --accent: #78a9ff;
    --accent-2: #5ed3e8;
    --accent-soft: #1c2a44;
    --accent-line: #3a4d73;
    --on-accent: #06142c;
    --grad-accent: linear-gradient(135deg, #6fa2ff, var(--accent-2));

    --sh-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
    --sh-2: 0 2px 6px rgba(0, 0, 0, 0.4), 0 18px 44px -18px rgba(0, 0, 0, 0.7);
    --sh-accent: 0 10px 28px -12px rgba(0, 0, 0, 0.7);
}

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

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

input,
textarea {
    -webkit-user-select: text;
    user-select: text;
}

img {
    -webkit-user-drag: none;
    user-drag: none;
    -webkit-touch-callout: none;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;

    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: 1.7;
    color: var(--text);
    background: var(--bg);

    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;

    -webkit-user-select: none;
    user-select: none;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background: var(--bg-aurora);
    pointer-events: none;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
}

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

svg {
    display: block;
    max-width: 100%;
}

[hidden] { display: none !important; }

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

h1,
h2,
h3 {
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.025em;
    text-wrap: balance;
}

p { text-wrap: pretty; }

.icon {
    width: 1em;
    height: 1em;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.skip {
    position: fixed;
    top: var(--s-4);
    left: var(--s-4);
    z-index: 200;
    padding: var(--s-2) var(--s-4);
    font-size: var(--fs-md);
    background: var(--surface-solid);
    border-radius: var(--r-2);
    box-shadow: var(--sh-1), var(--ring);
    transform: translateY(-200%);
}

.skip:focus-visible { transform: none; }

.wrap,
.page {
    width: 100%;
    max-width: var(--w-page);
    margin-inline: auto;
    padding-inline: var(--s-5);
}

.page {
    flex: 1 0 auto;
    padding-top: calc(var(--nav-h) + var(--s-7));
    padding-bottom: var(--s-8);
}

.nav {
    position: fixed;
    inset: 0 0 auto;
    z-index: 100;
    height: var(--nav-h);
    background: var(--surface);
    -webkit-backdrop-filter: blur(var(--blur)) saturate(1.4);
    backdrop-filter: blur(var(--blur)) saturate(1.4);
    box-shadow: var(--ring);
    transition: box-shadow var(--t);
}

.nav.is-stuck { box-shadow: var(--sh-1), var(--ring); }

.nav__inner {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    height: 100%;
}

.brand {
    display: inline-flex;
    align-items: center;
    flex: none;
    justify-self: start;
    transition: opacity var(--t-fast);
}

.brand:hover { opacity: 0.75; }

.brand img {
    height: 35px;
    width: auto;
    max-width: 132px;
    object-fit: contain;
}

.nav__menu {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    height: 100%;
    justify-self: center;
}

.nav__link {
    position: relative;
    display: flex;
    align-items: center;
    height: 100%;
    padding-inline: var(--s-3);
    font-size: var(--fs-md);
    color: var(--text-2);
    white-space: nowrap;
    transition: color var(--t-fast);
}

.nav__link::after {
    content: "";
    position: absolute;
    left: var(--s-3);
    right: var(--s-3);
    bottom: 0;
    height: 2px;
    border-radius: 1px;
    background: var(--accent);
    opacity: 0;
    transform: scaleX(0.6);
    transition: opacity var(--t-fast), transform var(--t-fast);
}

.nav__link:hover { color: var(--text); }

.nav__link[aria-current="page"] {
    color: var(--accent);
    font-weight: 600;
}

.nav__link[aria-current="page"]::after {
    opacity: 1;
    transform: scaleX(1);
}

.nav__actions {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    justify-self: end;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex: none;
    font-size: var(--fs-lg);
    color: var(--text-2);
    border-radius: var(--r-2);
    transition: color var(--t-fast), background var(--t-fast);
}

.icon-btn:hover { color: var(--accent); background: var(--tint); }

.theme-toggle__ico {
    display: none;
    align-items: center;
    justify-content: center;
}

.theme-toggle[data-mode="auto"] .theme-toggle__ico[data-for="auto"],
.theme-toggle[data-mode="light"] .theme-toggle__ico[data-for="light"],
.theme-toggle[data-mode="dark"] .theme-toggle__ico[data-for="dark"] { display: flex; }

.hero {
    text-align: center;
    padding-bottom: var(--s-6);
}

.hero__title {
    font-size: var(--fs-display);
    line-height: 1.1;
    letter-spacing: -0.035em;
}

.hero__note {
    margin-top: var(--s-3);
    font-size: var(--fs-sm);
    line-height: 1.5;
    color: var(--text-3);
}

.grad-text {
    background: var(--grad-accent);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.ornament {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    margin-bottom: var(--s-6);
}

.ornament::before,
.ornament::after {
    content: "";
    width: 26px;
    height: 1px;
}

.ornament::before { background: linear-gradient(90deg, transparent, var(--accent-line)); }
.ornament::after { background: linear-gradient(90deg, var(--accent-line), transparent); }

.ornament__dot {
    width: 4px;
    height: 4px;
    border-radius: var(--r-pill);
    background: var(--accent);
}

.toolbar {
    position: relative;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s-3);
    margin-bottom: var(--s-4);
}

.category {
    position: relative;
    flex: none;
    height: 46px;
    background: var(--surface);
    -webkit-backdrop-filter: blur(var(--blur)) saturate(1.4);
    backdrop-filter: blur(var(--blur)) saturate(1.4);
    border-radius: var(--r-2);
    box-shadow: var(--sh-1), var(--ring);
    transition: box-shadow var(--t);
}

.category:focus-within,
.category.is-open {
    box-shadow: var(--sh-2), 0 0 0 2px var(--accent-line);
}

/* 卡片带 backdrop-filter 会生成层叠上下文，展开时需把分类框抬到卡片之上 */
.category.is-open {
    z-index: 3;
}

.category__btn {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    height: 100%;
    padding-inline: var(--s-4);
    font-size: var(--fs-md);
    color: var(--text);
    border-radius: inherit;
    white-space: nowrap;
}

.category__btn .icon {
    font-size: var(--fs-sm);
    color: var(--text-3);
    transition: transform var(--t), color var(--t-fast);
}

.category.is-open .category__btn .icon {
    color: var(--accent);
    transform: rotate(180deg);
}

.category__list {
    position: absolute;
    top: calc(100% + var(--s-2));
    left: 0;
    z-index: 20;
    min-width: 128px;
    max-height: 264px;
    overflow-y: auto;
    padding: var(--s-1);
    background: var(--surface-solid);
    border-radius: var(--r-2);
    box-shadow: var(--sh-2), var(--ring);
    transform-origin: top center;
    animation: pop-in 0.16s var(--ease);
}

@keyframes pop-in {
    from { opacity: 0; transform: translateY(-4px) scale(0.97); }
    to { opacity: 1; transform: none; }
}

.category__option {
    display: flex;
    align-items: center;
    min-height: 36px;
    padding-inline: var(--s-3);
    font-size: var(--fs-md);
    color: var(--text-2);
    border-radius: var(--r-1);
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--t-fast), color var(--t-fast);
}

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

.category__option[aria-selected="true"] {
    color: var(--accent);
    font-weight: 600;
    background: var(--accent-soft);
}

.search {
    display: flex;
    flex: 1 1 260px;
    align-items: center;
    gap: var(--s-2);
    height: 46px;
    padding-inline: var(--s-4);
    background: var(--surface);
    -webkit-backdrop-filter: blur(var(--blur)) saturate(1.4);
    backdrop-filter: blur(var(--blur)) saturate(1.4);
    border-radius: var(--r-2);
    box-shadow: var(--sh-1), var(--ring);
    transition: box-shadow var(--t);
}

.search:focus-within {
    box-shadow: var(--sh-2), 0 0 0 2px var(--accent-line);
}

.search .icon {
    font-size: var(--fs-md);
    color: var(--text-3);
}

.search input {
    flex: 1 1 auto;
    min-width: 0;
    border: none;
    outline: none;
    background: none;
    color: var(--text);
    font: inherit;
    font-size: var(--fs-md);
}

.search input::placeholder { color: var(--text-3); }

.count {
    font-size: var(--fs-sm);
    color: var(--text-3);
    white-space: nowrap;
}

.plugins {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--s-4);
    scroll-margin-top: calc(var(--nav-h) + var(--s-4));
}

.plugin--skeleton { gap: var(--s-3); }

.skeleton__head {
    display: flex;
    align-items: center;
    gap: var(--s-3);
}

.skeleton__chip {
    width: 40px;
    height: 40px;
    flex: none;
    border-radius: var(--r-2);
}

.skeleton__lines {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 6px;
}

.skeleton__line {
    display: block;
    height: 12px;
    border-radius: 6px;
}

.skeleton__chip,
.skeleton__line {
    background: linear-gradient(90deg, var(--tint), var(--tint-2), var(--tint));
    background-size: 220% 100%;
    animation: shimmer 1.2s linear infinite;
}

@keyframes shimmer {
    from { background-position: 120% 0; }
    to { background-position: -120% 0; }
}

.pager {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--s-2);
    margin-top: var(--s-5);
}

.pager__btn {
    min-width: 38px;
    height: 38px;
    padding: 0 12px;
    font-size: var(--fs-sm);
    color: var(--text-2);
    background: var(--surface);
    -webkit-backdrop-filter: blur(var(--blur)) saturate(1.4);
    backdrop-filter: blur(var(--blur)) saturate(1.4);
    border-radius: var(--r-pill);
    box-shadow: var(--sh-1), var(--ring);
    transition: color var(--t-fast), background var(--t-fast);
}

.pager__btn:hover:not(:disabled) { color: var(--accent); }

.pager__btn[aria-current="page"] {
    color: var(--accent);
    font-weight: 600;
    background: var(--accent-soft);
    box-shadow: var(--ring);
}

.pager__btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.plugin {
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
    /* 长 id 等不可断行内容会把卡片最小内容宽度撑大，限制为可收缩 */
    min-width: 0;
    padding: var(--s-5);
    background: var(--surface);
    -webkit-backdrop-filter: blur(var(--blur)) saturate(1.4);
    backdrop-filter: blur(var(--blur)) saturate(1.4);
    border-radius: var(--r-3);
    box-shadow: var(--sh-1), var(--ring);
}

.plugin__head {
    display: flex;
    align-items: center;
    gap: var(--s-3);
}

.plugin__tag {
    margin-left: auto;
    padding: 2px 10px;
    font-size: var(--fs-xs);
    color: var(--text-2);
    background: var(--tint);
    border-radius: var(--r-pill);
    white-space: nowrap;
}

.plugin__icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: none;
    font-size: var(--fs-lg);
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: var(--r-2);
}

.plugin__title { min-width: 0; }

.plugin__name {
    font-size: var(--fs-lg);
    font-weight: 600;
    letter-spacing: -0.015em;
}

.plugin__id {
    overflow: hidden;
    margin-top: 2px;
    font-size: var(--fs-xs);
    line-height: 1.4;
    color: var(--text-3);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.scrollable { overflow: hidden; }

.scrollable__inner {
    display: inline-block;
    vertical-align: top;
    white-space: nowrap;
}

.scrollable.is-scrollable:not(:hover) {
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 16px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 16px), transparent);
}

.scrollable.is-scrollable:hover {
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 12px), transparent);
    mask-image: linear-gradient(90deg, transparent, #000 12px, #000 calc(100% - 12px), transparent);
}

.scrollable.is-scrollable:hover > .scrollable__inner {
    animation: marquee var(--dur, 4s) linear infinite alternate;
}

@keyframes marquee {
    from { transform: translateX(0); }
    to { transform: translateX(var(--scroll, 0)); }
}

.plugin__desc {
    display: -webkit-box;
    overflow: hidden;
    font-size: var(--fs-md);
    line-height: 1.7;
    color: var(--text-2);
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.plugin__meta {
    display: grid;
    gap: var(--s-2);
    margin-top: auto;
    padding: var(--s-3) var(--s-4);
    background: var(--tint);
    border-radius: var(--r-2);
}

.plugin__meta > div {
    display: flex;
    align-items: baseline;
    gap: var(--s-3);
    min-width: 0;
}

.plugin__meta dt {
    flex: none;
    width: 3.2em;
    font-size: var(--fs-xs);
    line-height: 1.5;
    color: var(--text-3);
}

.plugin__meta dd {
    flex: 1;
    min-width: 0;
    font-size: var(--fs-sm);
    font-weight: 500;
    line-height: 1.5;
    color: var(--text);
}

.plugin__link {
    font-weight: 600;
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: var(--accent-line);
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: color var(--t-fast), text-decoration-color var(--t-fast);
}

.plugin__link:hover {
    text-decoration-color: currentColor;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    padding: 10px 18px;
    font-size: var(--fs-md);
    font-weight: 500;
    line-height: 1.3;
    color: var(--text);
    border-radius: var(--r-2);
    white-space: nowrap;
    transition: filter var(--t-fast);
}

.btn--primary {
    color: var(--on-accent);
    background: var(--grad-accent);
    box-shadow: var(--sh-accent);
}

.btn--primary:hover { filter: brightness(1.07); }

.btn .icon { font-size: 1em; opacity: 0.9; }

.plugin__download { width: 100%; }

.status {
    padding: var(--s-7) var(--s-5);
    text-align: center;
    font-size: var(--fs-md);
    color: var(--text-2);
}

.status__retry {
    margin-top: var(--s-3);
    padding: 7px 16px;
    font-size: var(--fs-sm);
    color: var(--text-2);
    background: var(--surface);
    border-radius: var(--r-pill);
    box-shadow: var(--sh-1), var(--ring);
    transition: color var(--t-fast);
}

.status__retry:hover { color: var(--accent); }

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .search,
    .plugin {
        background: var(--surface-solid);
    }
}

@media (max-width: 820px) {
    .plugin {
        gap: var(--s-3);
        padding: var(--s-4);
    }

    .plugin__meta {
        gap: 6px;
        padding: var(--s-2) var(--s-3);
    }

    .status { padding-inline: var(--s-4); }
}

@media (max-width: 600px) {
    .wrap,
    .page { padding-inline: var(--s-4); }

    .page {
        padding-top: calc(var(--nav-h) + var(--s-5));
        padding-bottom: var(--s-7);
    }

    .brand img {
        height: 30px;
        max-width: 112px;
    }

    .nav__link {
        padding-inline: 8px;
        font-size: var(--fs-sm);
    }

    .hero { padding-bottom: var(--s-5); }

    .hero__title { font-size: 1.75rem; }

    .ornament { margin-bottom: var(--s-5); }

    /* 工具栏改为两行：搜索占满整行，分类与计数同排 */
    .toolbar {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        gap: var(--s-2) var(--s-3);
        margin-bottom: var(--s-3);
    }

    .search {
        grid-column: 1 / -1;
        height: 44px;
        padding-inline: var(--s-3);
    }

    /* 16px，低于此值 iOS Safari 聚焦输入框时会自动放大页面 */
    .search input { font-size: var(--fs-base); }

    .category { height: 40px; }

    .category__btn {
        padding-inline: var(--s-3);
        font-size: var(--fs-sm);
    }

    .count {
        align-self: center;
        justify-self: end;
    }

    .plugins {
        /* 必须用 minmax(0, 1fr)：裸 1fr 的最小值是 auto，会被长 id 撑破容器 */
        grid-template-columns: minmax(0, 1fr);
        gap: var(--s-3);
    }

    .plugin {
        gap: var(--s-3);
        padding: var(--s-4);
        border-radius: var(--r-2);
    }

    .plugin__head { gap: var(--s-2); }

    .plugin__icon {
        width: 34px;
        height: 34px;
        font-size: var(--fs-md);
    }

    .plugin__name { font-size: var(--fs-base); }

    .plugin__desc {
        font-size: var(--fs-sm);
        -webkit-line-clamp: 4;
    }

    .plugin__download { min-height: 44px; }

    .pager {
        gap: 6px;
        margin-top: var(--s-4);
    }

    .pager__btn {
        min-width: 40px;
        height: 40px;
        padding: 0 10px;
    }

    .status { padding: var(--s-6) var(--s-4); }
}

/* 触摸设备没有 hover，滚动动画永远不触发：标题改为换行，完整显示 */
@media (hover: none) {
    .scrollable__inner { white-space: normal; }

    .scrollable.is-scrollable:not(:hover),
    .scrollable.is-scrollable:hover {
        overflow: visible;
        -webkit-mask-image: none;
        mask-image: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }

    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
    }
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }

::-webkit-scrollbar-thumb {
    background: var(--line-2);
    border: 3px solid transparent;
    background-clip: content-box;
    border-radius: var(--r-pill);
}

::selection {
    background: var(--accent-soft);
    color: var(--text);
}
