:root {
    color-scheme: light;
    --canvas: #f7f8fa;
    --surface: #ffffff;
    --surface-hover: #fafaff;
    --surface-muted: #f0f1f5;
    --header-surface: #f7f8faf2;
    --ink: #202127;
    --ink-soft: #454750;
    --muted: #656976;
    --line: #e5e7ed;
    --line-strong: #d4d7e0;
    --accent: #5e6ad2;
    --accent-ink: #4d56b2;
    --accent-soft: #eef0fc;
    --focus-ring: #5e6ad226;
    --gutter: clamp(18px, 2.2vw, 36px);
    --page-width: 1680px;
    --sidebar-width: 196px;
    --layout-gap: 28px;
    --header-height: 72px;
    --tabs-height: 52px;
    --anchor-offset: calc(var(--header-height) + 20px);
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    --motion: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: var(--anchor-offset); }
body {
    min-width: 320px;
    margin: 0;
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
button, input { font: inherit; }
button, a, input { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
::selection { background: var(--accent-soft); color: var(--ink); }
[hidden] { display: none !important; }
:where(a, button):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.skip-link {
    position: fixed;
    z-index: 30;
    top: 10px;
    left: 10px;
    padding: 12px 16px;
    transform: translateY(-150%);
    border-radius: 8px;
    background: var(--ink);
    color: var(--surface);
}
.skip-link:focus { transform: translateY(0); }
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    clip-path: inset(50%);
}

.page-shell {
    width: min(100%, var(--page-width));
    min-height: 100vh;
    margin: 0 auto;
    padding: 0 var(--gutter);
}
.masthead {
    position: sticky;
    z-index: 20;
    top: 0;
    display: grid;
    height: var(--header-height);
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    align-items: center;
    gap: var(--layout-gap);
    border-bottom: 1px solid var(--line);
    background: var(--header-surface);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}
.wordmark, .footer-wordmark {
    width: fit-content;
    color: var(--ink);
    font-size: 26px;
    font-weight: 650;
    letter-spacing: 0;
    line-height: 1.2;
    text-decoration: none;
}
.wordmark span, .footer-wordmark span { color: var(--accent); }
.masthead-main { display: flex; min-width: 0; align-items: center; gap: 24px; }
.header-context { flex: 1 0 auto; }
.header-context h1 { margin: 0; font-size: 17px; font-weight: 600; line-height: 1.4; }
.header-summary { min-height: 18px; margin: 3px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; white-space: nowrap; }
.header-summary strong { font-weight: 500; font-variant-numeric: tabular-nums; }
.summary-divider { padding: 0 8px; }
.search-summary { color: var(--accent-ink); }
.search-field {
    display: flex;
    min-width: 0;
    min-height: 46px;
    flex: 0 1 420px;
    align-items: center;
    gap: 10px;
    padding-left: 14px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--surface);
    transition: border-color .16s var(--motion), box-shadow .16s var(--motion);
}
.search-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.search-icon { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linecap: round; }
.search-field input { width: 100%; min-width: 0; height: 44px; padding: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 14px; }
.search-field input::placeholder { color: var(--muted); opacity: 1; }
.search-field input::-webkit-search-cancel-button { display: none; }
.search-shortcut { margin-right: 12px; }
kbd { display: grid; width: 22px; height: 24px; place-items: center; border: 1px solid var(--line); border-radius: 4px; background: var(--canvas); color: var(--muted); font-family: var(--sans); font-size: 12px; }
.search-clear { display: grid; width: 44px; height: 44px; flex: none; place-items: center; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.search-clear svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.search-clear:hover { background: var(--surface-muted); color: var(--ink); }

.directory-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    align-items: start;
    gap: var(--layout-gap);
    padding: 20px 0 28px;
}
.directory-sidebar {
    position: sticky;
    top: calc(var(--header-height) + 20px);
    align-self: start;
    max-height: calc(100vh - var(--header-height) - 40px);
    max-height: calc(100dvh - var(--header-height) - 40px);
    padding: 4px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
}
.sidebar-heading { display: flex; min-height: 36px; align-items: center; justify-content: space-between; padding: 0 10px; font-size: 13px; font-weight: 600; }
.sidebar-total { color: var(--muted); font-size: 12px; font-weight: 400; }
.sidebar-total b { font-weight: 500; font-variant-numeric: tabular-nums; }
.index-nav { display: grid; gap: 4px; padding-top: 8px; }
.index-link {
    display: grid;
    min-height: 44px;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--ink-soft);
    text-decoration: none;
    transition: color .16s var(--motion), background-color .16s var(--motion);
}
.index-link:hover { background: var(--surface-muted); color: var(--ink); }
.index-link[aria-current="location"] { background: var(--accent-soft); color: var(--accent-ink); }
.index-link-title { overflow: hidden; font-size: 13px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.index-link-count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.index-link[aria-current="location"] .index-link-count { color: var(--accent-ink); }
.sidebar-top { display: flex; min-height: 44px; align-items: center; justify-content: space-between; margin: 12px 10px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; text-decoration: none; }
.sidebar-top:hover { color: var(--accent-ink); }

.directory-main { min-width: 0; }
.category-section { margin: 0 0 28px; scroll-margin-top: 0; }
.category-section:last-child { margin-bottom: 0; }
.category-heading { display: flex; min-height: 40px; align-items: center; gap: 12px; }
.category-heading h2 { min-width: 0; margin: 0; font-size: 19px; font-weight: 600; line-height: 1.4; overflow-wrap: anywhere; }
.category-total { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.category-total strong { font-weight: 500; font-variant-numeric: tabular-nums; }
.site-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: 12px;
    padding-top: 8px;
}
.site-entry {
    display: grid;
    min-width: 0;
    min-height: 88px;
    grid-template-columns: 36px minmax(0, 1fr) 14px;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: inherit;
    text-decoration: none;
    transition: border-color .16s var(--motion), background-color .16s var(--motion);
}
.site-icon { display: grid; width: 36px; height: 36px; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--accent-ink); font-size: 16px; font-weight: 600; }
.site-icon img { display: block; width: 26px; height: 26px; object-fit: contain; }
.site-icon.icon-fallback { background: var(--accent-soft); }
.site-entry-copy { display: grid; min-width: 0; gap: 4px; }
.site-entry-name { overflow: hidden; color: var(--ink); font-size: 15px; font-weight: 600; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.site-entry-description { display: -webkit-box; min-width: 0; overflow: hidden; color: var(--muted); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.site-entry-arrow { color: var(--muted); font-size: 15px; text-align: center; }

.empty-state { display: grid; justify-items: start; gap: 12px; padding: 40px 0; }
.empty-icon { width: 28px; height: 28px; fill: none; stroke: var(--accent); stroke-width: 1.4; stroke-linecap: round; }
.empty-state h2 { margin: 0; font-size: 20px; font-weight: 600; }
.empty-state p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.reset-search { min-height: 44px; margin-top: 4px; padding: 0 16px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--ink-soft); font-size: 13px; cursor: pointer; }
.reset-search:hover { border-color: var(--accent); color: var(--accent-ink); }

.page-footer { display: flex; min-height: 80px; flex-wrap: wrap; align-items: center; gap: 20px; padding: 16px 0; border-top: 1px solid var(--line); color: var(--muted); }
.footer-wordmark { font-size: 20px; }
.footer-legal { display: flex; min-width: 0; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-left: auto; }
.footer-icp { font-size: 12px; line-height: 1.6; text-decoration: none; }
.footer-icp:hover { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 3px; }
.footer-security { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.footer-security img { flex: none; object-fit: contain; }
.back-to-top { display: flex; min-height: 44px; align-items: center; gap: 8px; font-size: 12px; text-decoration: none; }
.back-to-top:hover { color: var(--accent-ink); }
.noscript-message { position: fixed; z-index: 40; inset: 0 0 auto; margin: 0; padding: 12px; background: var(--ink); color: var(--surface); text-align: center; }

@media (hover: hover) {
    .site-entry:hover { border-color: var(--line-strong); background: var(--surface-hover); }
    .site-entry:hover .site-entry-arrow { color: var(--accent-ink); }
}

@media (max-width: 1080px) {
    :root { --gutter: 24px; --sidebar-width: 180px; --layout-gap: 24px; }
}

@media (max-width: 820px) {
    :root { --anchor-offset: calc(var(--header-height) + var(--tabs-height) + 16px); }
    .masthead { grid-template-columns: 112px minmax(0, 1fr); gap: 20px; }
    .masthead-main { gap: 20px; }
    .directory-layout { display: block; padding-top: 0; }
    .directory-sidebar {
        z-index: 10;
        top: var(--header-height);
        max-height: none;
        margin: 0 calc(-1 * var(--gutter));
        padding: 0 var(--gutter);
        overflow: visible;
        border-bottom: 1px solid var(--line);
        background: var(--canvas);
    }
    .sidebar-heading, .sidebar-top { display: none; }
    .index-nav { display: flex; min-height: var(--tabs-height); align-items: center; gap: 4px; padding: 4px 2px; overflow-x: auto; scrollbar-width: none; }
    .index-nav::-webkit-scrollbar { display: none; }
    .index-link { flex: none; }
    .index-link-count { display: none; }
    .directory-main { padding-top: 16px; }
}

@media (max-width: 640px) {
    :root { --gutter: 18px; }
    .masthead { grid-template-columns: auto minmax(0, 1fr); gap: 16px; margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter); }
    .wordmark { font-size: 23px; }
    .masthead-main { display: block; }
    .header-context { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }
    .search-field { width: 100%; gap: 8px; padding-left: 12px; }
    .search-field input { font-size: 16px; }
    .search-shortcut { display: none; }
    .category-heading h2 { font-size: 18px; }
    .category-section { margin-bottom: 24px; }
    .site-entry { gap: 10px; padding: 12px; }
    .site-entry-name { font-size: 14px; }
    .page-footer { gap: 12px; }
    .footer-legal { flex-basis: 100%; order: 2; margin: 0; }
    .back-to-top { margin-left: auto; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { transition-duration: .01ms !important; }
}
