/*
 * Shared pieces (knowledge/brand.md "Layout and components"): section titles over the rule,
 * the category tag and its quieter kicker, timestamps and meta lines, the wisecrack,
 * buttons, cards on the white page, the prompt box with its Copy button, "see all" links;
 * then the pieces of item pages and listings: breadcrumbs, bylines, block headings,
 * hairline lists, term pills, notices, section tabs and paging; the Tested line, callouts,
 * the path line and the filter panel; a prompt's tool tabs and fill-in hint; the video
 * player and the reel length chip; form fields.
 */

@layer components {
    /* Hidden on screen, still read out. */
    .visually-hidden {
        position: absolute !important;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    /* Section titles: condensed capitals over the 4 px purple rule. */
    .section-title {
        margin: 0 0 var(--space-4);
        padding-top: var(--space-2);
        border-top: var(--rule-heavy);
        font-family: var(--font-display);
        font-size: var(--text-section-size);
        font-weight: 800;
        letter-spacing: var(--text-section-tracking);
        line-height: 1;
        text-transform: uppercase;
    }

    /* The category tag: an acid pill with ink text. Rare on purpose (the lead only). */
    .tag {
        margin: 0 0 var(--space-3);

        & a {
            display: inline-block;
            padding: 3px var(--space-3);
            border-radius: var(--radius-pill);
            background: var(--color-acid);
            color: var(--color-ink);
            font-family: var(--font-display);
            font-size: var(--text-tag-size);
            font-weight: 700;
            letter-spacing: var(--text-tag-tracking);
            line-height: 1.3;
            text-decoration: none;
            text-transform: uppercase;
        }

        & a:hover {
            background: var(--color-tip);
        }
    }

    /* The same label without the pill, everywhere else. */
    .kicker {
        margin: 0 0 var(--space-1);

        & a {
            color: var(--color-ink);
            font-family: var(--font-display);
            font-size: var(--text-tag-size);
            font-weight: 700;
            letter-spacing: var(--text-tag-tracking);
            text-decoration: none;
            text-transform: uppercase;
        }

        & a:hover {
            text-decoration-line: underline;
            text-decoration-color: var(--color-acid);
            text-decoration-thickness: 3px;
        }
    }

    /* Bylines, times and details under a card: small monospaced capitals in grey. */
    .meta {
        margin: var(--space-2) 0 0;
        color: var(--color-ink-muted);
        font-family: var(--font-mono);
        font-size: var(--text-timestamp-size);
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    /* The one-line joke under a news headline (BR5): plain italic, no marker (K7). */
    .wisecrack {
        margin: var(--space-1) 0 0;
        font-size: var(--text-wisecrack-size);
        font-style: italic;
        font-weight: 500;
        line-height: 1.3;
    }

    .see-all {
        margin: var(--space-4) 0 0;
        font-weight: 600;
    }

    /* Buttons: acid pills with a 2 px ink outline, no shadow. */
    .button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 44px;
        padding: var(--space-1) var(--space-5);
        border: 2px solid var(--color-ink);
        border-radius: var(--radius-pill);
        background: var(--color-acid);
        color: var(--color-ink);
        font-family: var(--font-display);
        font-size: var(--text-button-size);
        font-weight: 800;
        text-decoration: none;
        text-transform: uppercase;
        cursor: pointer;

        &:hover {
            background: var(--color-tip);
        }

        &[hidden] {
            display: none;
        }
    }

    /* Cards: items on the white page, no boxes. Titles are ink links. */
    .card {
        min-width: 0;

        & img {
            display: block;
            width: 100%;
            border-radius: var(--radius-image);
            background: var(--color-image-ground);
        }

    }

    /* Zero specificity, so each line's own class sets its spacing. */
    :where(.card) p {
        margin: 0;
    }

    .card-title {
        margin: 0;
        font-family: var(--font-display);
        font-size: var(--text-list-size);
        font-weight: 700;
        line-height: var(--text-heading-leading);

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

        & a:hover {
            text-decoration-line: underline;
            text-decoration-color: var(--color-acid);
            text-decoration-thickness: 3px;
        }
    }

    .card-image {
        display: block;
    }

    .card-summary {
        margin-top: var(--space-2);
        color: var(--color-ink-muted);
    }

    .why-it-matters {
        margin-top: var(--space-2);
    }

    /* A prompt as typed: monospaced on deep purple, the [blanks] in acid. */
    .prompt-text {
        margin: 0;
        padding: var(--space-4);
        border-radius: var(--radius-panel);
        background: var(--color-purple-deep);
        color: var(--color-bg);

        & mark {
            padding: 0 2px;
            border-radius: 3px;
            background: var(--color-acid);
            color: var(--color-ink);
        }
    }

    .copy-box {
        --focus-color: var(--color-purple);

        & .button {
            min-width: 10rem;
            margin-top: var(--space-3);
        }

        & .button[data-copied] {
            color: var(--color-success);
        }
    }

    /* "Copied!" is only read out (the button says it); a failure is shown. */
    .copy-status:not([data-failed]) {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .copy-status[data-failed] {
        margin: var(--space-3) 0 0;
        padding: var(--space-2) var(--space-3);
        border-radius: var(--radius-panel);
        background: var(--color-error-bg);
        color: var(--color-error);
        font-size: var(--text-small-size);
    }

    /* A prompt's tool tabs (brand.md "Prompt card"): outlined pills, the selected one deep purple. A lone label ("Works with any AI") looks selected. */
    .tool-tabs {
        margin: 0 0 var(--space-3);

        & ul {
            display: flex;
            flex-wrap: wrap;
            gap: var(--space-2);
            margin: 0;
            padding: 0;
            list-style: none;
        }

        & li {
            margin: 0;
        }
    }

    .tool-tab {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
        padding: var(--space-1) var(--space-4);
        border: 2px solid var(--color-ink);
        border-radius: var(--radius-pill);
        color: var(--color-ink);
        font-family: var(--font-display);
        font-size: 18px;
        font-weight: 700;
        text-decoration: none;
        text-transform: uppercase;

        &:is(a):hover {
            background: var(--color-lavender);
        }

        &:is(span, [aria-current]) {
            border-color: var(--color-purple-deep);
            background: var(--color-purple-deep);
            color: var(--color-bg);
        }
    }

    /* "Swap the [highlighted bits]…": the hint once above a prompt, its mark as in the prompt. */
    .prompt-hint {
        margin: 0 0 var(--space-3);
        color: var(--color-ink-muted);
        font-size: var(--text-small-size);

        & mark {
            padding: 0 2px;
            border-radius: 3px;
            background: var(--color-acid);
            color: var(--color-ink);
        }
    }

    /* Breadcrumbs: one quiet line of small text; the current page is cut short with an ellipsis. */
    .breadcrumbs {
        margin-bottom: var(--space-5);
        font-size: var(--text-small-size);

        & ol {
            display: flex;
            gap: var(--space-2);
            margin: 0;
            padding: 0;
            list-style: none;
            white-space: nowrap;
        }

        & li {
            margin: 0;
        }

        & li + li::before {
            content: "›" / "";
            margin-right: var(--space-2);
            color: var(--color-ink-muted);
        }

        & [aria-current] {
            min-width: 0;
            overflow: hidden;
            color: var(--color-ink-muted);
            text-overflow: ellipsis;
        }
    }

    /* Who and when, in the timestamp style; author names stay links. */
    .byline {
        margin: 0;
        color: var(--color-ink-muted);
        font-family: var(--font-mono);
        font-size: var(--text-timestamp-size);
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    /*
     * A block inside an item's page (Sources, Learn how, What you need…): its heading in
     * condensed capitals over a hairline.
     */
    .item-block,
    .related-links {
        margin-top: var(--space-7);

        & > h2 {
            margin-bottom: var(--space-2);
            padding-top: var(--space-2);
            border-top: 2px solid var(--color-ink);
            font-size: var(--text-section-size);
            font-weight: 800;
            letter-spacing: var(--text-section-tracking);
            text-transform: uppercase;
        }
    }

    /* Lists, not cards: no bullets, a hairline between the lines. */
    .hairline-list,
    .related-links ul {
        margin: 0;
        padding: 0;
        list-style: none;

        & li {
            margin: 0;
            padding-block: var(--space-3);
        }

        & li + li {
            border-top: var(--rule-hairline);
        }
    }

    .source-original {
        color: var(--color-ink-muted);
        font-family: var(--font-mono);
        font-size: var(--text-timestamp-size);
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    /* Cross-links: the target's title as a headline link, its summary in grey. */
    .related-links li {
        color: var(--color-ink-muted);

        & a {
            color: var(--color-ink);
            font-family: var(--font-display);
            font-size: 21px;
            font-weight: 700;
            line-height: var(--text-heading-leading);
            text-decoration: none;
        }

        & a:hover {
            text-decoration-line: underline;
            text-decoration-color: var(--color-acid);
            text-decoration-thickness: 3px;
        }
    }

    /* Topics and AI tools: a small label, then outlined pills. */
    .term-links {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-2);
        margin: var(--space-4) 0 0;

        & a {
            display: inline-flex;
            align-items: center;
            min-height: 32px;
            padding: 2px var(--space-3);
            border: 1px solid var(--color-ink);
            border-radius: var(--radius-pill);
            color: var(--color-ink);
            font-size: var(--text-small-size);
            font-weight: 500;
            text-decoration: none;
        }

        & a:hover {
            background: var(--color-lavender);
        }
    }

    .term-links-label {
        margin-right: var(--space-1);
        color: var(--color-ink-muted);
        font-family: var(--font-mono);
        font-size: var(--text-timestamp-size);
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    .short-version {
        margin: var(--space-5) 0 0;
        font-weight: 600;
    }

    /* A reel's length (brand.md): a small peach chip in the timestamp style. */
    .length-chip {
        display: inline-block;
        padding: 1px var(--space-2);
        border-radius: var(--radius-pill);
        background: var(--color-warning);
        color: var(--color-ink);
        font-family: var(--font-mono);
        font-size: var(--text-timestamp-size);
        font-weight: 500;
        letter-spacing: 0.04em;
        vertical-align: 0.1em;
    }

    /*
     * A video behind its thumbnail (K17): the box keeps the video's shape before and after
     * the tap, so nothing moves; Play is the brand button in the middle. Vertical videos
     * never grow taller than most of the screen.
     */
    .video-player {
        margin: var(--space-5) 0;
    }

    .video-frame {
        position: relative;
        display: grid;
        place-items: center;
        overflow: hidden;
        border-radius: var(--radius-image);
        background: var(--color-purple-deep);
        aspect-ratio: 16 / 9;

        & > :is(.video-poster, iframe) {
            grid-area: 1 / 1;
            width: 100%;
            height: 100%;
            border: 0;
            object-fit: cover;
        }
    }

    .video-player-vertical .video-frame {
        width: min(100%, 22rem, calc(80svh * 9 / 16));
        aspect-ratio: 9 / 16;
    }

    .video-play {
        --focus-color: var(--color-acid);

        grid-area: 1 / 1;
        display: inline-flex;
        gap: var(--space-2);
        align-items: center;
        z-index: 1;
        min-height: 48px;
        padding: var(--space-2) var(--space-5);
        border: 2px solid var(--color-ink);
        border-radius: var(--radius-pill);
        background: var(--color-acid);
        color: var(--color-ink);
        font-family: var(--font-display);
        font-size: var(--text-button-size);
        font-weight: 800;
        text-transform: uppercase;
        cursor: pointer;

        &:hover {
            background: var(--color-tip);
        }

        &[hidden] {
            display: none;
        }
    }

    .video-link {
        margin: var(--space-2) 0 0;
        font-size: var(--text-small-size);
    }

    /* Notices: archived items on peach, as the warning callout. */
    .archived-notice {
        margin: var(--space-5) 0;
        padding: var(--space-3) var(--space-4);
        border-radius: var(--radius-panel);
        background: var(--color-warning);
    }

    /* Section tabs over a listing: outlined pills, the current one deep purple. Scrolls sideways on phones. */
    .tabs {
        margin: 0 calc(-1 * var(--layout-gutter)) var(--space-6);
        padding: 0 var(--layout-gutter);
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scroll-padding-inline: var(--layout-gutter);

        /* As wide as its tabs, so the row's end padding scrolls into view after the last one. */
        & ul {
            display: flex;
            gap: var(--space-2);
            width: max-content;
            margin: 0;
            padding: var(--focus-room) 0 var(--space-2);
            list-style: none;
        }

        & li {
            flex: none;
            margin: 0;
        }

        & a {
            display: inline-flex;
            align-items: center;
            min-height: 44px;
            padding: var(--space-1) var(--space-4);
            border: 2px solid var(--color-ink);
            border-radius: var(--radius-pill);
            color: var(--color-ink);
            font-family: var(--font-display);
            font-size: 18px;
            font-weight: 700;
            text-decoration: none;
            text-transform: uppercase;
            white-space: nowrap;
        }

        & a:hover {
            background: var(--color-lavender);
        }

        & a[aria-current] {
            border-color: var(--color-purple-deep);
            background: var(--color-purple-deep);
            color: var(--color-bg);
        }
    }

    @media (min-width: 64rem) {
        .tabs {
            margin-inline: calc(-1 * var(--focus-room));
            padding-inline: var(--focus-room);

            & ul {
                flex-wrap: wrap;
                width: auto;
            }
        }
    }

    /* Paging: Newer and Older as outlined pills either side of the count. */
    .pager {
        margin-top: var(--space-7);
        padding-top: var(--space-4);
        border-top: var(--rule-hairline);

        & p {
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: center;
            gap: var(--space-4);
            margin: 0;
        }
    }

    .pager-link {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
        padding: var(--space-1) var(--space-5);
        border: 2px solid var(--color-ink);
        border-radius: var(--radius-pill);
        color: var(--color-ink);
        font-family: var(--font-display);
        font-size: var(--text-button-size);
        font-weight: 800;
        text-decoration: none;
        text-transform: uppercase;

        &:hover {
            background: var(--color-lavender);
        }
    }

    .pager-count {
        color: var(--color-ink-muted);
        font-family: var(--font-mono);
        font-size: var(--text-timestamp-size);
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    .empty-state {
        max-width: var(--measure);
        font-size: var(--text-wisecrack-size);
    }

    /* When the steps were last checked (K13): under the byline, in the same style. */
    .tested-on {
        margin: var(--space-1) 0 0;
        color: var(--color-ink-muted);
        font-family: var(--font-mono);
        font-size: var(--text-timestamp-size);
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    /* Callouts (G4): tip on pale green, warning on peach, the aside outlined in purple and in italic. */
    .callout {
        margin: var(--space-5) 0;
        padding: var(--space-4);
        border-radius: var(--radius-panel);

        & > :first-child {
            margin-top: 0;
        }

        & > :last-child {
            margin-bottom: 0;
        }

        & > p:first-child strong {
            font-family: var(--font-display);
            font-size: var(--text-tag-size);
            font-weight: 700;
            letter-spacing: var(--text-tag-tracking);
            text-transform: uppercase;
        }

        & p {
            margin-bottom: var(--space-2);
        }
    }

    .callout-tip {
        background: var(--color-tip);
    }

    .callout-warning {
        background: var(--color-warning);
    }

    .callout-aside {
        border: 2px solid var(--color-purple);
        font-style: italic;
        font-weight: 500;

        & > p:first-child strong {
            font-style: normal;
            color: var(--color-purple);
        }
    }

    /* "Part 3 of 6 in…" with the path's previous and next items, between hairlines; the well done on pale green. */
    .path-stops {
        margin-top: var(--space-7);
        border-block: var(--rule-hairline);

        & p {
            margin: 0;
            padding-block: var(--space-3);
        }

        & p + p {
            border-top: var(--rule-hairline);
        }

        & .path-finished {
            margin-bottom: var(--space-3);
            padding-inline: var(--space-4);
            border: 0;
            border-radius: var(--radius-panel);
            background: var(--color-tip);
            font-weight: 600;
        }
    }

    /*
     * The filter panel (K14): a "Filter" pill that opens the fields, side by side where
     * there's room; "Show results" is the brand button.
     */
    .filters-panel {
        margin-bottom: var(--space-6);

        & > summary {
            display: inline-flex;
            align-items: center;
            gap: var(--space-2);
            min-height: 44px;
            padding: var(--space-1) var(--space-4);
            border: 2px solid var(--color-ink);
            border-radius: var(--radius-pill);
            font-family: var(--font-display);
            font-size: 18px;
            font-weight: 700;
            text-transform: uppercase;
            list-style: none;
            cursor: pointer;
        }

        & > summary::-webkit-details-marker {
            display: none;
        }

        & > summary::after {
            content: "▾" / "";
        }

        &[open] > summary {
            border-color: var(--color-purple-deep);
            background: var(--color-purple-deep);
            color: var(--color-bg);
        }

        & > summary:hover {
            background: var(--color-lavender);
            color: var(--color-ink);
        }
    }

    .filters {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
        gap: var(--space-4);
        align-items: end;
        margin-top: var(--space-4);
        padding: var(--space-4);
        border: var(--rule-hairline);
        border-radius: var(--radius-panel);

        & label {
            display: block;
            margin-bottom: var(--space-1);
            font-size: var(--text-small-size);
            font-weight: 600;
        }

        & select {
            width: 100%;
            min-height: 44px;
            padding: var(--space-2) var(--space-3);
            border: 1px solid var(--color-ink-muted);
            border-radius: var(--radius-image);
            background: var(--color-bg);
            color: var(--color-ink);
            font: inherit;
        }

        & .filter-check {
            display: flex;
            align-items: center;
            gap: var(--space-2);
            min-height: 44px;
            margin: 0;
            font-size: var(--text-body-size);
            font-weight: 400;
        }

        & input[type="checkbox"] {
            width: 20px;
            height: 20px;
            margin: 0;
            accent-color: var(--color-purple);
        }
    }

    .filter-actions {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-4);
        grid-column: 1 / -1;
        margin: 0;
    }

    /* Form fields (sign-in, and Phase 7's contact form): the label over the field, a hint under it. */
    .form-field {
        margin-bottom: var(--space-5);

        & label {
            display: block;
            margin-bottom: var(--space-1);
            font-weight: 600;
        }

        & input {
            width: 100%;
            min-height: 48px;
            padding: var(--space-2) var(--space-3);
            border: 1px solid var(--color-ink-muted);
            border-radius: var(--radius-image);
            background: var(--color-bg);
            color: var(--color-ink);
            font: inherit;
        }
    }

    .hint {
        display: block;
        margin-top: var(--space-1);
        color: var(--color-ink-muted);
        font-size: var(--text-small-size);
    }

    .form-error {
        margin: 0 0 var(--space-5);
        padding: var(--space-3) var(--space-4);
        border-radius: var(--radius-panel);
        background: var(--color-error-bg);
        color: var(--color-error);
    }
}
