/* Homepage — layout & interaction system.
   Motion values follow Apple's fluid-interface guidance: critically damped
   springs by default, bounce only after a gesture that carried momentum,
   feedback on press, and a gentler equivalent under reduced-motion. */

.home {
    --home-ink: #16161d;
    --home-ink-2: rgba(22, 22, 29, 0.68);
    --home-ink-3: rgba(22, 22, 29, 0.52);
    --home-surface: #ffffff;
    --home-fill: #f2f2f5;
    --home-hairline: rgba(17, 12, 46, 0.08);
    --home-hairline-strong: rgba(17, 12, 46, 0.16);
    --home-chrome: rgba(255, 255, 255, 0.76);
    --home-chrome-edge: rgba(255, 255, 255, 0.65);
    --home-pill: #ffffff;
    --home-accent: #673de6;
    --home-lift: 0 2px 6px rgba(16, 24, 40, 0.06), 0 18px 40px -22px rgba(16, 24, 40, 0.42);
    --home-ease: cubic-bezier(0.32, 0.72, 0, 1);

    max-width: 1240px;
    margin: 0 auto;
    padding: 0 20px;
    font-optical-sizing: auto;
    color: var(--home-ink);
}

[data-color-mode="dark"] .home {
    --home-ink: #f3f3f5;
    --home-ink-2: rgba(243, 243, 245, 0.74);
    --home-ink-3: rgba(243, 243, 245, 0.56);
    --home-surface: #141416;
    --home-fill: #1c1c20;
    --home-hairline: rgba(255, 255, 255, 0.07);
    --home-hairline-strong: rgba(255, 255, 255, 0.16);
    --home-chrome: rgba(20, 20, 22, 0.7);
    --home-chrome-edge: rgba(255, 255, 255, 0.12);
    --home-pill: rgba(255, 255, 255, 0.11);
    --home-accent: #a78bfa;
    --home-lift: 0 2px 6px rgba(0, 0, 0, 0.5), 0 20px 44px -22px rgba(0, 0, 0, 0.9);
}

/* ---------------------------------------------------------------- hero --- */
.home-hero {
    max-width: 46rem;
    padding: clamp(24px, 4.5vw, 52px) 0 clamp(18px, 2.6vw, 26px);
}

.home-kicker {
    margin-bottom: 10px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--home-accent);
}

.home-headline {
    font-size: clamp(28px, 4.2vw, 44px);
    line-height: 1.08;
    letter-spacing: -0.025em;
    font-weight: 800;
    color: var(--home-ink);
    text-wrap: balance;
}

.home-lede {
    margin-top: 12px;
    font-size: clamp(15px, 1.35vw, 17px);
    line-height: 1.65;
    color: var(--home-ink-2);
    max-width: 42em;
}

.home-stat {
    margin-top: 16px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--home-ink-3);
    font-variant-numeric: tabular-nums;
}

/* Lightweight CTA: the header nav collapses on narrow screens, this is the
   entry point that survives there. */
.home-cta {
    margin-top: 18px;
}

.home-cta a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 999px;
    background-color: var(--home-ink);
    color: var(--home-surface);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.2s var(--home-ease), transform 0.14s var(--home-ease);
}

/* 全局 `a:not(.button):hover` 会把文字改成链接悬停色（同样是强调色），
   压到强调底上就糊成一片；这里显式指定反色文字，浅色/深色主题都成立。 */
.home-cta a:hover,
.home-cta a:focus-visible {
    background-color: var(--home-accent);
    color: var(--home-surface);
}

.home-cta a:active {
    transform: scale(0.97);
}

.home-cta a:focus-visible {
    outline: 2px solid var(--home-accent);
    outline-offset: 3px;
}

.home-stat[hidden] {
    display: none;
}

/* ------------------------------------------------- category rail (§12) --- */
/* Translucent floating chrome: content scrolls underneath, the material
   arrives once the page is scrolled so it never fights with the hero. */
.rail-bar {
    position: sticky;
    top: 8px;
    z-index: 40;
    border-radius: 999px;
    border: 1px solid var(--home-hairline);
    border-top-color: var(--home-chrome-edge);
    background-color: var(--home-chrome);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    box-shadow: 0 1px 1px rgba(16, 24, 40, 0.03), 0 10px 30px -20px rgba(16, 24, 40, 0.4);
    transition: box-shadow 0.3s var(--home-ease), border-color 0.3s ease,
        background-color 0.3s ease;
}

.rail-bar.is-stuck {
    border-color: var(--home-hairline-strong);
    border-top-color: var(--home-chrome-edge);
    box-shadow: 0 1px 1px rgba(16, 24, 40, 0.05), 0 16px 40px -18px rgba(16, 24, 40, 0.48);
}

.rail-scroller {
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: inherit;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    touch-action: pan-y;
    cursor: grab;
}

.rail-scroller::-webkit-scrollbar {
    display: none;
}

.rail-scroller.is-grabbing {
    cursor: grabbing;
    -webkit-user-select: none;
    user-select: none;
}

.rail-track {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    width: max-content;
    min-width: 100%;
    padding: 6px;
}

.rail-pill {
    position: absolute;
    top: 6px;
    left: 0;
    width: 0;
    height: 40px;
    border-radius: 999px;
    background-color: var(--home-pill);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 18px -10px rgba(16, 24, 40, 0.5);
    z-index: 0;
    opacity: 0;
    transition: opacity 0.24s ease;
    will-change: transform, width;
}

.rail-bar.is-ready .rail-pill {
    opacity: 1;
}

/* Small, cheap press feedback on the chip itself (§1 response). */
.rail-chip {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: none;
    height: 40px;
    padding: 0 14px;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.005em;
    white-space: nowrap;
    color: var(--home-ink-2);
    -webkit-tap-highlight-color: transparent;
    transition: color 0.18s ease, transform 0.14s var(--home-ease);
    touch-action: manipulation;
}

.rail-chip svg {
    width: 18px;
    height: 18px;
    flex: none;
}

.rail-chip:hover {
    color: var(--home-ink);
}

.rail-chip[aria-current="true"] {
    color: var(--home-ink);
}

.rail-chip:active {
    transform: scale(0.96);
}

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

/* ----------------------------------------------------------- sections --- */
.home-section {
    padding-top: clamp(26px, 3.6vw, 40px);
    scroll-margin-top: 88px;
}

.home-sections > .home-section:first-child {
    padding-top: clamp(18px, 2.4vw, 26px);
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.section-title {
    font-size: clamp(19px, 2.2vw, 24px);
    line-height: 1.2;
    letter-spacing: -0.02em;
    font-weight: 800;
    color: var(--home-ink);
}

.section-more {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: none;
    height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    color: var(--home-ink-2);
    background-color: transparent;
    transition: color 0.18s ease, background-color 0.18s ease, transform 0.14s var(--home-ease);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.section-more:hover {
    color: var(--home-ink);
    background-color: var(--home-fill);
}

.section-more:active {
    transform: scale(0.97);
}

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

.section-arrow {
    display: inline-block;
    transition: transform 0.24s var(--home-ease);
}

.section-more:hover .section-arrow {
    transform: translateX(3px);
}

/* -------------------------------------------------------------- cards --- */
.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
}

.tool-cell {
    min-width: 0;
}

.tool-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    border-radius: 16px;
    border: 1px solid var(--home-hairline);
    background-color: var(--home-surface);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
    overflow: hidden;
    color: inherit;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: transform 0.28s var(--home-ease), box-shadow 0.28s var(--home-ease),
        border-color 0.28s ease;
}

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

.tool-media {
    position: relative;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    background-color: var(--home-fill);
}

/* A card whose image never arrives still reads as a card: the media slot
   becomes an initial tile instead of a broken-image icon. */
.tool-cell.no-media .tool-media {
    display: flex;
    align-items: center;
    justify-content: center;
    background-image: linear-gradient(135deg, var(--home-fill), var(--home-surface));
}

.tool-cell.no-media .tool-media img {
    display: none;
}

.tool-cell.no-media .tool-media::after {
    content: attr(data-initial);
    font-size: 28px;
    line-height: 1;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--home-ink-3);
}

.tool-media img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transform: scale(1);
    transition: opacity 0.35s ease, transform 0.5s var(--home-ease);
}

.tool-media img.loaded {
    opacity: 1;
}

.tool-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 14px 14px;
    min-width: 0;
}

.tool-title {
    font-size: 15px;
    line-height: 1.35;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--home-ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tool-desc {
    font-size: 13px;
    line-height: 1.55;
    color: var(--home-ink-2);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: calc(2 * 1.55em);
}

.tool-source {
    margin-top: auto;
    padding-top: 2px;
    font-size: 12px;
    line-height: 1.4;
    font-weight: 600;
    color: var(--home-ink-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Hover lift only where a real pointer exists — no sticky hover on touch. */
@media (hover: hover) and (pointer: fine) {
    .tool-card:hover {
        transform: translateY(-2px);
        border-color: var(--home-hairline-strong);
        box-shadow: var(--home-lift);
        will-change: transform;
    }

    .tool-card:hover .tool-media img {
        transform: scale(1.04);
    }
}

/* Press feedback is instant and outranks the hover lift; release eases back
   (§1 response). Declared after the hover block on purpose. */
.tool-card:active {
    transform: translateY(-1px) scale(0.98);
    transition-duration: 0.09s;
}

/* -------------------------------------------------------------- mobile --- */
@media (max-width: 720px) {
    .home {
        padding: 0 16px;
    }

    .rail-bar {
        top: 6px;
    }

    .rail-track {
        padding: 5px;
    }

    .rail-chip {
        height: 38px;
        padding: 0 12px;
        font-size: 14px;
        gap: 6px;
    }

    .rail-pill {
        top: 5px;
        height: 38px;
    }

    .home-section {
        scroll-margin-top: 80px;
    }

    .tool-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 10px;
    }

    .tool-body {
        gap: 4px;
        padding: 10px 11px 12px;
    }

    .tool-title {
        font-size: 14px;
    }

    .tool-desc {
        font-size: 12px;
        line-height: 1.5;
        min-height: calc(2 * 1.5em);
    }

    .section-more {
        font-size: 12px;
        padding: 0 10px;
    }
}

/* ------------------------------------------------ accessibility (§14) --- */
@media (prefers-reduced-motion: reduce) {
    .rail-chip,
    .rail-pill,
    .tool-card,
    .tool-media img,
    .section-arrow,
    .section-more,
    .rail-bar {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }

    .tool-card:hover {
        transform: none;
    }

    .tool-card:hover .tool-media img {
        transform: none;
    }

    /* Press feedback is not vestibular motion: keep it, just don't lift. */
    .tool-card:active {
        transform: scale(0.98);
        transition-duration: 0.09s;
    }
}

@media (prefers-reduced-transparency: reduce) {
    .rail-bar,
    .rail-bar.is-stuck {
        background-color: var(--home-surface);
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
}

@media (prefers-contrast: more) {
    .rail-bar,
    .rail-bar.is-stuck {
        background-color: var(--home-surface);
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
        border-color: var(--home-ink);
    }

    .tool-card {
        border-color: var(--home-ink-3);
    }

    .rail-chip[aria-current="true"],
    .tool-title {
        color: var(--home-ink);
    }
}
