/* Lenz News v2 — a Digg-shaped reading view.
   Near-black page, one column of cards in the middle, sets on the left and
   today's ranked stories on the right. */

:root {
    --bg: #151517;
    --panel: #1c1c1f;
    --panel-hover: #202024;
    --surface: #1e1e20;
    --text: #fdfdff;
    --muted: rgba(253, 253, 255, 0.7);
    --faint: rgba(253, 253, 255, 0.45);
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);
    --accent: #6ba4ff;
    --up: #3aa267;
    --down: #cc434d;
    /* Two strengths of hover wash, and the rail's scrollbar, so both themes
       read the same way. */
    --wash: rgba(255, 255, 255, 0.06);
    --wash-soft: rgba(255, 255, 255, 0.04);
    --scroll: rgba(255, 255, 255, 0.18);
    /* Darker than the page, so the sidebar reads as its own surface. */
    --sidebar-bg: #101012;
    /* The ranking card's rows, a shade above the card they sit in. */
    --rail-card: #202024;
    /* What a chosen set or category is filled with, in either theme. */
    --accent-fill: color-mix(in srgb, var(--accent) 22%, var(--panel-hover));
    --tip-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
}

/* Light mode keeps the same shapes and dimensions; only the paper changes.
   The toggle in the sidebar writes data-theme on <html>. */
:root[data-theme="light"] {
    --bg: #ebebf3;
    --panel: #ffffff;
    --panel-hover: #f1f1f6;
    --surface: #fbfbfe;
    --text: #15151a;
    /* A touch stronger than the dark values, so small secondary text keeps
       the same legibility on white paper. */
    --muted: rgba(21, 21, 26, 0.74);
    --faint: rgba(21, 21, 26, 0.56);
    --border: rgba(18, 18, 24, 0.1);
    --border-strong: rgba(18, 18, 24, 0.2);
    --accent: #1c66eb;
    --up: #15803d;
    --down: #c0272f;
    --wash: rgba(18, 18, 24, 0.05);
    --wash-soft: rgba(18, 18, 24, 0.035);
    --scroll: rgba(18, 18, 24, 0.2);
    /* Lighter than the page, so the sidebar reads as its own surface. */
    --sidebar-bg: #fafafd;
    /* Barely off white, so the rows and ticker boxes read as their own blocks
       on the white rail without needing an edge. */
    --rail-card: #f5f5fa;
    --tip-shadow: 0 10px 24px rgba(18, 18, 24, 0.18);
    color-scheme: light;
}

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

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

body {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 24rem minmax(0, 1fr);
    background: var(--bg);
    color: var(--text);
    font-family:
        "Inter",
        "Segoe UI",
        system-ui,
        -apple-system,
        sans-serif;
    font-size: 16px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- sidebar */

.sidebar {
    position: sticky;
    top: 0;
    /* Sticky already makes this a stacking context, so it needs a stacking
       level of its own: the content is nudged left over the sidebar's edge,
       and without this it would paint — and catch clicks — above the fold
       handle and the folded tooltips. */
    z-index: 10;
    align-self: start;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1.35rem 1rem;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

/* The theme switch: a sun while the page is dark, a moon while it's light. */
.theme-toggle {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    /* Sits level with the wordmark, which carries its own bottom padding. */
    margin: 0 0.4rem 0.4rem 0;
    padding: 0;
    color: var(--muted);
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    transition:
        color 0.15s ease,
        background 0.15s ease,
        border-color 0.15s ease;
}

.theme-toggle:hover {
    color: var(--text);
    background: var(--panel-hover);
    border-color: var(--border-strong);
}

.theme-toggle svg {
    width: 1rem;
    height: 1rem;
}

.theme-toggle .icon-moon {
    display: none;
}

:root[data-theme="light"] .theme-toggle .icon-sun {
    display: none;
}

:root[data-theme="light"] .theme-toggle .icon-moon {
    display: block;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0 0.4rem 0.4rem;
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-decoration: none;
}

/* The wordmark folds down to this home icon when the sidebar is collapsed. */
.brand-home {
    display: none;
    width: 1.2rem;
    height: 1.2rem;
}

.brand-home svg {
    width: 100%;
    height: 100%;
}

.brand-dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: var(--accent);
}

.brand-prefix {
    font-weight: 300;
    letter-spacing: 0.06em;
}

.brand-name {
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.brand:hover {
    opacity: 0.85;
}

/* The handle that folds the sidebar away, riding the divider line. */
.sidebar-toggle {
    position: absolute;
    top: 50%;
    right: -0.85rem;
    transform: translateY(-50%);
    z-index: 5;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.7rem;
    height: 1.7rem;
    padding: 0;
    color: var(--muted);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    transition:
        color 0.15s ease,
        background 0.15s ease,
        border-color 0.15s ease;
}

.sidebar-toggle:hover {
    color: var(--text);
    background: var(--panel-hover);
    border-color: var(--border-strong);
}

.sidebar-toggle svg {
    width: 0.9rem;
    height: 0.9rem;
    transition: transform 0.2s ease;
}

:root[data-sidebar="collapsed"] .sidebar-toggle svg {
    transform: rotate(180deg);
}

/* Folded: the rail keeps only the icons — a home mark for the wordmark and
   each set's own icon — so the feed gets the width back. */
@media (min-width: 52.01rem) {
    :root[data-sidebar="collapsed"] body {
        grid-template-columns: 4.9rem minmax(0, 1fr);
    }

    :root[data-sidebar="collapsed"] .sidebar {
        align-items: center;
        padding: 1.2rem 0.55rem;
    }

    :root[data-sidebar="collapsed"] .sidebar-head {
        flex-direction: column;
        gap: 0.55rem;
        width: 100%;
    }

    :root[data-sidebar="collapsed"] .brand {
        justify-content: center;
        width: 2.6rem;
        height: 2.6rem;
        padding: 0;
        background: var(--panel);
        border: 1px solid var(--border);
        border-radius: 0.8rem;
    }

    :root[data-sidebar="collapsed"] .brand-home {
        display: inline-flex;
        color: var(--text);
    }

    :root[data-sidebar="collapsed"] .brand-dot,
    :root[data-sidebar="collapsed"] .brand-prefix,
    :root[data-sidebar="collapsed"] .brand-name {
        display: none;
    }

    :root[data-sidebar="collapsed"] .theme-toggle {
        margin: 0;
    }

    :root[data-sidebar="collapsed"] .sets {
        align-items: center;
        width: 100%;
    }

    :root[data-sidebar="collapsed"] .set-button {
        justify-content: center;
        gap: 0;
        width: 2.8rem;
        height: 2.8rem;
        padding: 0;
        border-radius: 0.9rem;
    }

    :root[data-sidebar="collapsed"] .set-icon {
        width: 1.25rem;
        height: 1.25rem;
    }

    :root[data-sidebar="collapsed"] .set-label,
    :root[data-sidebar="collapsed"] .set-count,
    :root[data-sidebar="collapsed"] .subsets {
        display: none;
    }

    /* Folded icons name themselves on hover (and on keyboard focus) with the
       same rounded pill the expanded rail uses, plus a caret pointing at the
       icon. data-tip is kept in step with the label in app.js. */
    :root[data-sidebar="collapsed"] [data-tip] {
        position: relative;
    }

    :root[data-sidebar="collapsed"] [data-tip]::after {
        content: attr(data-tip);
        position: absolute;
        top: 50%;
        left: calc(100% + 1rem);
        z-index: 20;
        padding: 0.5rem 0.9rem;
        font-size: 0.95rem;
        font-weight: 500;
        line-height: 1.2;
        white-space: nowrap;
        color: var(--text);
        background: var(--panel-hover);
        border: 1px solid var(--border-strong);
        border-radius: 999px;
        box-shadow: var(--tip-shadow);
        opacity: 0;
        pointer-events: none;
        transform: translate(-0.3rem, -50%);
        transition:
            opacity 0.12s ease,
            transform 0.12s ease;
    }

    /* The caret: a small square turned on its corner, wearing the pill's two
       leading borders so it reads as part of the same box. */
    :root[data-sidebar="collapsed"] [data-tip]::before {
        content: "";
        position: absolute;
        top: 50%;
        left: calc(100% + 0.72rem);
        z-index: 21;
        width: 0.55rem;
        height: 0.55rem;
        background: var(--panel-hover);
        border-left: 1px solid var(--border-strong);
        border-bottom: 1px solid var(--border-strong);
        opacity: 0;
        pointer-events: none;
        transform: translateY(-50%) rotate(45deg);
        transition: opacity 0.12s ease;
    }

    :root[data-sidebar="collapsed"] [data-tip]:hover::after,
    :root[data-sidebar="collapsed"] [data-tip]:focus-visible::after {
        opacity: 1;
        transform: translate(0, -50%);
    }

    :root[data-sidebar="collapsed"] [data-tip]:hover::before,
    :root[data-sidebar="collapsed"] [data-tip]:focus-visible::before {
        opacity: 1;
    }
}

.rail-title {
    padding: 0 0.5rem;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--faint);
}

.sets {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

/* Each set is a full pill: icon, name, and how many categories it holds. */
.set-button {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    width: 100%;
    padding: 0.8rem 1.1rem;
    font: inherit;
    font-size: 1rem;
    font-weight: 500;
    color: var(--muted);
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    transition:
        background 0.15s ease,
        color 0.15s ease;
}

.set-button:hover {
    background: var(--surface);
    color: var(--text);
}

.set-button[aria-current="true"] {
    background: var(--accent-fill);
    color: var(--text);
    font-weight: 600;
}

.set-icon {
    display: inline-flex;
    flex-shrink: 0;
    width: 1.15rem;
    height: 1.15rem;
    color: var(--faint);
}

.set-icon svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.set-button:hover .set-icon,
.set-button[aria-current="true"] .set-icon {
    color: var(--accent);
}

/* With one of the set's categories filtered, the category carries the
   highlight and the set pill above it drops back to plain — it stays
   aria-current, it just stops looking chosen. */
.sets.has-category .set-button[aria-current="true"] {
    background: transparent;
}

.sets.has-category .set-button[aria-current="true"]:hover {
    background: var(--surface);
}

.set-count {
    margin-left: auto;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    color: var(--faint);
}

/* The active set's categories, hanging under its button. Same shape as a set
   pill, a size down, with the category's own dot standing in for the icon. */
.subsets {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    /* Inset by the same amount left and right, so the smaller pills sit
       inside the width of the set pill above them. */
    margin: 0.15rem 2.1rem 0.55rem 2.1rem;
}

.subset {
    display: flex;
    align-items: center;
    gap: 0.1rem;
    width: 100%;
    padding: 0.16rem 0.35rem 0.16rem 0.12rem;
    /* A quiet fill instead of an edge, so the category pills read as softer
       than the set pill they sit under. */
    background: color-mix(in srgb, var(--panel-hover) 70%, transparent);
    border-radius: 999px;
    transition: background 0.15s ease;
}

/* The name is the filter; the eye beside it is the hide switch. */
.subset-main {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex: 1;
    min-width: 0;
    padding: 0.28rem 0.45rem;
    font: inherit;
    font-size: 0.83rem;
    text-align: left;
    color: var(--muted);
    background: none;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    transition: color 0.15s ease;
}

.subset:hover {
    background: color-mix(in srgb, var(--panel-hover) 100%, transparent);
}

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

/* The category the feed is filtered to: tinted with the accent, since there
   is no edge left to colour. */
.subset.is-filtered {
    background: var(--accent-fill);
}

.subset.is-filtered .subset-main {
    color: var(--text);
}

.subset.is-filtered .subset-count {
    color: var(--muted);
}

/* Its stories are out of the feed: the eye is struck through and the pill
   goes quiet, but it stays clickable so it can be brought back. */
.subset.is-hidden .subset-main {
    color: var(--faint);
}

.subset.is-hidden .subset-dot {
    opacity: 0.35;
}

.subset-eye {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.7rem;
    height: 1.7rem;
    padding: 0;
    color: var(--faint);
    background: none;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    transition:
        color 0.15s ease,
        background 0.15s ease;
}

.subset-eye:hover {
    color: var(--text);
    background: var(--surface);
}

.subset-eye .eye-slash {
    opacity: 0;
    transition: opacity 0.15s ease;
}

.subset.is-hidden .subset-eye .eye-slash {
    opacity: 1;
}

.subset-dot {
    flex-shrink: 0;
    width: 0.38rem;
    height: 0.38rem;
    border-radius: 50%;
    background: var(--border-strong);
}

.subset-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.subset-count {
    flex-shrink: 0;
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    color: var(--faint);
}

.ghost-btn {
    padding: 0.5rem 0.8rem;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    cursor: pointer;
    transition:
        background 0.15s ease,
        border-color 0.15s ease;
}

.ghost-btn:hover {
    background: var(--panel-hover);
    border-color: var(--border-strong);
}

.ghost-btn:focus-visible,
.feed-refresh:focus-visible,
.set-button:focus-visible,
.sidebar-toggle:focus-visible,
.card:focus-visible,
.top-toggle:focus-visible,
.card-story:focus-visible,
.card-sources a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ------------------------------------------------------------------- feed */

/* Feed and top stories side by side, the pair centred in the space beside
   the sidebar. */
.content {
    --refresh-size: 2.15rem;
    --content-gap: clamp(1.25rem, 2.5vw, 2.5rem);
    grid-column: 2;
    display: grid;
    grid-template-columns: var(--refresh-size) minmax(0, 52.8rem) 25.2rem;
    justify-content: center;
    align-items: start;
    gap: var(--content-gap);
    padding: 1.75rem clamp(1rem, 2.5vw, 2rem) 4rem;
}

.feed {
    min-width: 0;
}

/* The refresh strip sits outside the pair being centred, so the stories are
   centred on their own width and the button merely hangs off their left edge.
   A relative nudge keeps the grid's own measurements untouched. */
@media (min-width: 72.01rem) {
    .content {
        position: relative;
        left: calc(-0.5 * (var(--refresh-size) + var(--content-gap)));
    }
}

/* Refresh keeps its own column beside the stories: stuck to the top of the
   feed, it hangs in the gutter and stays in reach down the list. */
.feed-refresh {
    position: sticky;
    top: 0.45rem;
    align-self: start;
    display: grid;
    place-items: center;
    width: var(--refresh-size);
    height: var(--refresh-size);
    margin-top: 0.45rem;
    /* Keeps the circle clear of the sidebar's edge, since the centring nudge
       pushes the whole strip left into that padding. */
    margin-left: 0.5rem;
    color: var(--muted);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 50%;
    box-shadow: var(--tip-shadow);
    cursor: pointer;
    transition:
        background 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease,
        transform 0.12s ease;
}

.feed-refresh svg {
    width: 1.05rem;
    height: 1.05rem;
}

/* The ring tracks the wait until the next poll: a faint circle that the accent
   arc fills, clockwise from twelve o'clock. */
.feed-refresh .refresh-ring {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    pointer-events: none;
}

.refresh-ring circle {
    fill: none;
    stroke-width: 2;
}

.refresh-ring-track {
    stroke: color-mix(in srgb, var(--text) 9%, transparent);
}

/* The dash lengths live on the element as presentation attributes, set by
   app.js — Firefox won't take calc() for stroke-dashoffset, and a full ring
   was what that looked like. */
.refresh-ring-fill {
    stroke: var(--accent);
    stroke-linecap: round;
}

.feed-refresh:hover {
    color: var(--text);
    background: var(--panel-hover);
    border-color: var(--border-strong);
}

.feed-refresh:active {
    transform: scale(0.94);
}

.feed-refresh.is-busy svg {
    animation: refresh-spin 0.9s linear infinite;
}

@keyframes refresh-spin {
    to {
        transform: rotate(360deg);
    }
}

.feed-list {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    max-width: 52.8rem;
}

.card {
    display: flex;
    flex-direction: column;
    padding: 0.95rem 1rem;
    color: inherit;
    background: var(--panel);
    border-radius: 0.9rem;
    cursor: pointer;
    transition: background 0.15s ease;
}

.card:hover {
    background: var(--panel-hover);
}

/* Only the headline and the picture lead to the story — every other click is
   the card asking for its "also on" panel, so the two sit side by side. */
.card-main {
    display: flex;
    align-items: flex-start;
    gap: 0.9rem;
}

.card-thumb-link {
    flex-shrink: 0;
    display: block;
}

.card-expand {
    margin-top: 0.8rem;
    padding-top: 0.7rem;
    border-top: 1px solid var(--border);
    cursor: auto;
}

.card-expand-label {
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--faint);
}

.card-sources {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    margin-top: 0.35rem;
    list-style: none;
}

.card-sources a {
    display: grid;
    grid-template-columns: 7.5rem minmax(0, 1fr);
    gap: 0.6rem;
    padding: 0.32rem 0.35rem;
    border-radius: 0.4rem;
    color: var(--muted);
    text-decoration: none;
}

.card-sources a:hover {
    background: var(--surface);
    color: var(--text);
}

/* The outlet this card came from leads the list. */
.card-sources a.is-current .card-source-title {
    color: var(--text);
    font-weight: 600;
}

.card-source-outlet {
    padding-top: 0.1rem;
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--faint);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-source-title {
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--text);
}

/* A story that arrived with a poll stays lit for 30 seconds (NEW_CARD_MS in
   app.js drops the class at the same moment), then eases back to normal. */
.card.is-new {
    animation: card-arrive 30s ease-out both;
}

@keyframes card-arrive {
    0% {
        background: color-mix(
            in srgb,
            var(--card-accent, var(--accent)) 26%,
            var(--panel)
        );
        border-color: var(--card-accent, var(--accent));
    }
    5%,
    90% {
        background: color-mix(
            in srgb,
            var(--card-accent, var(--accent)) 15%,
            var(--panel)
        );
        border-color: color-mix(
            in srgb,
            var(--card-accent, var(--accent)) 55%,
            transparent
        );
    }
    100% {
        background: var(--panel);
        border-color: var(--border);
    }
}

.card-body {
    flex: 1;
    min-width: 0;
}

.card-kicker {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.3rem;
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--faint);
}

.card-kicker .dot {
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 50%;
    background: var(--accent);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.01em;
    color: var(--text);
}

/* Headline and excerpt share one link laid over the text block: the whole
   block is the target, but it still reads as plain type inside the card. */
.card-story {
    display: block;
    color: inherit;
    text-decoration: none;
}

.card-story:hover .card-title {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.card-blurb {
    margin-top: 0.35rem;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.55rem;
    font-size: 0.72rem;
    color: var(--faint);
}

.card-meta img {
    width: 0.85rem;
    height: 0.85rem;
    border-radius: 0.15rem;
    object-fit: contain;
}

/* "+2 others", between the outlet and the age. */
.card-others {
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

.card-outlet {
    color: var(--muted);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-thumb {
    width: 5.5rem;
    aspect-ratio: 1 / 1;
    flex-shrink: 0;
    object-fit: cover;
    border-radius: 0.55rem;
    background: var(--surface);
}

.card-thumb-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.85rem;
    background: rgba(255, 255, 255, 0.92);
}

.card-thumb-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.card-thumb-initial {
    font-size: 1.3rem;
    font-weight: 600;
    color: #161617;
}

.feed-more {
    max-width: 52.8rem;
    padding-top: 1rem;
}

.feed-more .ghost-btn {
    width: 100%;
}

.state-note {
    padding: 2.5rem 0.25rem;
    font-size: 0.85rem;
    color: var(--faint);
}

/* Skeleton while the first stories land. */
.card.is-loading {
    display: block;
    height: 6.5rem;
    background: linear-gradient(
        100deg,
        var(--panel) 20%,
        var(--panel-hover) 40%,
        var(--panel) 60%
    );
    background-size: 220% 100%;
    animation: shimmer 1.4s linear infinite;
}

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

/* ------------------------------------------------------------------- rail */

/* The markets strip and the ranking card stack in one sticky column. */
.side {
    position: sticky;
    top: 1.75rem;
    align-self: start;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: calc(100vh - 3.5rem);
}

/* Index moves above the ranking: Dow, Nasdaq and the S&P, read from CNBC. */
.markets {
    flex-shrink: 0;
    padding: 0.75rem;
    background: var(--panel);
    border-radius: 0.9rem;
    transition: opacity 0.2s ease;
}

.markets.is-stale {
    opacity: 0.55;
}

.markets-row {
    display: flex;
    gap: 0.5rem;
}

.tick {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.45rem 0.5rem 0.5rem;
    background: var(--rail-card);
    border-radius: 0.6rem;
}

.tick-name {
    font-size: 0.58rem;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tick-change,
.tick-pct {
    font-size: 0.88rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    color: var(--muted);
}

.tick-pct {
    font-size: 0.8rem;
}

.tick-value {
    font-size: 0.68rem;
    font-variant-numeric: tabular-nums;
    color: var(--faint);
}

.tick-change.up,
.tick-pct.up {
    color: var(--up);
}

.tick-change.down,
.tick-pct.down {
    color: var(--down);
}

/* Today's ranking is its own card, not a full-height sidebar. */
.rail {
    position: static;
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    margin: 0;
    padding: 1.05rem 0.75rem 0.9rem;
    background: var(--panel);
    border-radius: 0.9rem;
    scrollbar-width: thin;
    scrollbar-color: var(--scroll) transparent;
}

.rail::-webkit-scrollbar {
    width: 8px;
}

.rail::-webkit-scrollbar-thumb {
    background: var(--scroll);
    border-radius: 1rem;
}

.rail-title {
    padding: 0.15rem 0.5rem 0.7rem;
}

/* The story count, sitting under the ranking card. */
.side-note {
    margin: 0;
    padding: 0 0.75rem;
    font-size: 0.78rem;
    letter-spacing: 0.02em;
    color: var(--faint);
}

/* The set's address in that line leads back to the set. */
.side-note-link {
    color: inherit;
    text-decoration: underline;
    text-decoration-color: var(--border-strong);
    text-underline-offset: 0.15em;
}

.side-note-link:hover {
    color: var(--text);
    text-decoration-color: currentColor;
}

/* Sits just under the count line, not a full gap away from it. */
.side-note-old {
    margin-top: -0.55rem;
}

.top-list {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    list-style: none;
}

/* Every top story is its own small card inside the rail, and opens in place
   the way a top-story card does on the board. */
.top-item {
    background: var(--rail-card);
    border-radius: 0.7rem;
    overflow: hidden;
    transition: background 0.15s ease;
}

.top-toggle {
    display: flex;
    gap: 0.55rem;
    width: 100%;
    padding: 0.6rem 0.65rem;
    font: inherit;
    text-align: left;
    color: inherit;
    background: transparent;
    border: 0;
    border-radius: 0;
    cursor: pointer;
    transition: background 0.15s ease;
}

.top-toggle:hover,
.top-item.expanded .top-toggle {
    background: var(--wash-soft);
}

.top-rank {
    flex-shrink: 0;
    width: 1.1rem;
    font-size: 0.78rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.45;
    color: var(--faint);
}

.top-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.top-headline {
    font-size: 0.84rem;
    font-weight: 500;
    line-height: 1.4;
    color: var(--text);
}

.top-meta {
    margin-top: 0.2rem;
    font-size: 0.7rem;
    color: var(--faint);
}

.top-expand {
    padding: 0.7rem 0.7rem 0.8rem;
    border-top: 1px solid var(--border);
}

.top-why {
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--muted);
}

.top-why strong {
    font-weight: 600;
    color: var(--text);
}

/* The rail's panel borrows the feed cards' "Seen on" rows; only the outlet
   column narrows, because the rail is short on width. */
.top-seen-label {
    margin-top: 0.7rem;
}

.top-seen a {
    grid-template-columns: 5.5rem minmax(0, 1fr);
    gap: 0.5rem;
    padding: 0.3rem;
}

.rail-empty {
    padding: 0.25rem 0.5rem;
    font-size: 0.76rem;
    line-height: 1.5;
    color: var(--faint);
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 72rem) {
    body {
        grid-template-columns: 21rem minmax(0, 1fr);
    }

    /* Not enough room for the pair, so the ranking card drops under the feed
       and both take the full width of what's left. */
    .content {
        grid-template-columns: minmax(0, 1fr);
    }

    /* With one column there is no gutter to hang in, so the button floats
       over the page instead. */
    .feed-refresh {
        position: fixed;
        top: auto;
        right: 1.1rem;
        bottom: 1.1rem;
        margin-top: 0;
        z-index: 40;
    }

    .side {
        position: static;
        max-height: none;
    }

    .rail {
        overflow: visible;
    }
}

@media (max-width: 52rem) {
    body {
        display: block;
    }

    /* Stacked under the feed's header, the sidebar is a bar rather than a
       column, so there is nothing to fold away. */
    .sidebar-toggle {
        display: none;
    }

    .sidebar {
        position: static;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.6rem;
        padding: 0.85rem 1rem;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .sets {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    .set-button {
        width: auto;
        gap: 0.45rem;
        padding: 0.5rem 0.8rem;
        font-size: 0.85rem;
        background: var(--surface);
        border-radius: 999px;
    }

    .set-icon {
        width: 1rem;
        height: 1rem;
    }

    /* On a phone the categories read as a row of small pills under the sets. */
    .subsets {
        flex-basis: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.35rem;
        margin: 0 0 0.25rem;
        padding: 0;
        border-left: 0;
    }

    .subset {
        padding: 0.12rem 0.3rem 0.12rem 0.1rem;
    }

    .subset-main {
        padding: 0.24rem 0.45rem;
        font-size: 0.78rem;
    }

    .set-count {
        display: none;
    }

    .content {
        padding: 1.1rem 1rem 3rem;
    }

    .card-thumb {
        width: 4.5rem;
    }

    /* A phone has no room for a column of outlet names beside headlines. */
    .card-sources a {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }

    /* Without the fade, a new story still reads as new for its 30 seconds. */
    .card.is-new {
        background: color-mix(
            in srgb,
            var(--card-accent, var(--accent)) 12%,
            var(--panel)
        );
        border-color: color-mix(
            in srgb,
            var(--card-accent, var(--accent)) 45%,
            transparent
        );
    }
}
