:root {
    --stories-nav-height: 68px;
    --stories-nav-bg: #ffffff;
    --stories-text: #52525b;
    --stories-active: #2563eb;
    --stories-border: #e5e7eb;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding-bottom: calc(var(--stories-nav-height) + env(safe-area-inset-bottom, 0px) + 12px);
    color: #18181b;
    background: #ffffff;
    font-family: system-ui, -apple-system, BlinkMacSystemFont,
        "Segoe UI", sans-serif;
}

.stories-bottom-nav {
    position: fixed;
    z-index: 1000;
    right: 0;
    bottom: 0;
    left: 0;

    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: center;

    min-height: var(--stories-nav-height);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));

    background: var(--stories-nav-bg);
    border-top: 1px solid var(--stories-border);
    box-shadow: 0 -4px 18px rgb(0 0 0 / 5%);
}

.stories-nav-item {
    display: flex;
    min-width: 0;
    min-height: 48px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;

    color: var(--stories-text);
    text-decoration: none;
    font-size: 11px;
    font-weight: 500;
    -webkit-tap-highlight-color: transparent;
}

.stories-nav-item svg {
    width: 23px;
    height: 23px;
    flex: 0 0 auto;
}

.stories-nav-item.is-active {
    color: var(--stories-active);
}

.stories-nav-item:focus-visible {
    outline: 2px solid var(--stories-active);
    outline-offset: -2px;
    border-radius: 8px;
}

@media (min-width: 768px) {
    body {
        padding-bottom: 0;
    }

    .stories-bottom-nav {
        right: auto;
        left: 50%;
        bottom: 16px;
        width: min(440px, calc(100% - 32px));
        transform: translateX(-50%);
        border: 1px solid var(--stories-border);
        border-radius: 18px;
        padding-bottom: 6px;
        box-shadow: 0 8px 32px rgb(0 0 0 / 12%);
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

.stories-header {
    padding: 16px;
    border-bottom: 1px solid #f1f1f1;
}

.stories-brand {
    color: #18181b;
    font-size: 22px;
    font-weight: 800;
    text-decoration: none;
}

.stories-content {
    width: 100%;
    max-width: 760px;
    margin-inline: auto;
    padding: 16px;
}

.stories-card {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e5e7eb;
}

.stories-card img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 12px;
}

.stories-card h2 {
    margin: 12px 0 8px;
    font-size: clamp(20px, 5vw, 28px);
    line-height: 1.25;
}

.stories-card h2 a {
    color: inherit;
    text-decoration: none;
}

.stories-excerpt {
    color: #52525b;
    line-height: 1.65;
}

/* Stories homepage */

.stories-home {
    width: 100%;
    max-width: 760px;
    margin-inline: auto;
    padding: 22px 16px 32px;
}

.stories-welcome {
    margin-bottom: 24px;
}

.stories-eyebrow {
    margin: 0 0 10px;
    color: var(--stories-active);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1.5px;
}

.stories-welcome h1 {
    max-width: 480px;
    margin: 0;
    font-size: clamp(30px, 8vw, 44px);
    font-weight: 800;
    letter-spacing: -1.5px;
    line-height: 1.08;
}

.stories-intro {
    max-width: 440px;
    margin: 12px 0 0;
    color: #71717a;
    font-size: 15px;
    line-height: 1.6;
}

.stories-categories {
    display: flex;
    gap: 8px;
    margin: 0 -16px 28px;
    padding: 2px 16px 8px;
    overflow-x: auto;
    scrollbar-width: none;
}

.stories-categories::-webkit-scrollbar {
    display: none;
}

.stories-category {
    flex: 0 0 auto;
    padding: 9px 15px;
    border: 1px solid #e4e4e7;
    border-radius: 999px;
    color: #3f3f46;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}

.stories-category:first-child {
    color: #fff;
    background: #2563eb;
    border-color: #2563eb;
}

.stories-section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.stories-section-heading h2 {
    margin: 0;
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.stories-feed {
    display: grid;
    gap: 22px;
}

.stories-card {
    min-width: 0;
    overflow: hidden;
}

.stories-card-image {
    display: block;
    overflow: hidden;
    border-radius: 14px;
    background: #f4f4f5;
}

.stories-card-image img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    transition: transform 200ms ease;
}

.stories-card-content {
    padding: 12px 2px 0;
}

.stories-card-meta {
    margin: 0 0 7px;
    color: #71717a;
    font-size: 12px;
    font-weight: 600;
}

.stories-card h3 {
    margin: 0;
    font-size: 19px;
    line-height: 1.35;
    letter-spacing: -0.3px;
}

.stories-card h3 a {
    color: #18181b;
    text-decoration: none;
}

.stories-card-excerpt {
    margin: 8px 0 0;
    color: #71717a;
    font-size: 14px;
    line-height: 1.6;
}


.stories-empty {
    padding: 24px;
    border: 1px dashed #d4d4d8;
    border-radius: 14px;
}

.stories-empty h3 {
    margin-top: 0;
}

.stories-empty p {
    margin-bottom: 0;
    color: #71717a;
}

@media (min-width: 600px) {
    .stories-home {
        padding-top: 32px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .stories-card-image img {
        transition: none;
    }
}

/* Pageview count on story cards */

.stories-post-views {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin: 0 0 10px;
    color: var(--stories-muted, #64748b);
    font-size: 12px;
    line-height: 1.5;
}

.stories-nav-item {
    white-space: nowrap;
    gap: 3px;
    font-size: 10px;
}

.stories-nav-item svg {
    width: 21px;
    height: 21px;
}

@media (min-width: 768px) {
    .stories-bottom-nav {
        width: min(520px, calc(100% - 32px));
    }
}


/* ========================================
   Stories Homepage Search
======================================== */

.stories-home-search {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 0px 0px 10px;
    box-sizing: border-box;
}

.stories-home-search-form {
    width: 100%;
    margin: 0;
}

.stories-home-search-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.stories-home-search-row {
    display: flex;
    align-items: stretch;
    width: 100%;
    min-height: 48px;
    overflow: hidden;
    border: 1px solid #d8d8d8;
    border-radius: 9px;
    background: #fff;
}

.stories-home-search-input {
    flex: 1;
    width: 0;
    min-width: 0;
    min-height: 46px;
    margin: 0;
    padding: 10px 14px;
    border: 0;
    border-radius: 0;
    outline: none;
    background: #fff;
    color: #222;
    font-family: inherit;
    font-size: 15px;
    box-shadow: none;
}

.stories-home-search-input:focus {
    border-color: #333;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

.stories-home-search-input::placeholder {
    color: #888;
    opacity: 1;
}

.stories-home-search-button {
    display: flex;
    flex: 0 0 46px;
    align-items: center;
    justify-content: center;
    min-width: 46px;
    min-height: 46px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: #222;
    color: #fff;
    cursor: pointer;
    box-shadow: none;
}

.stories-home-search-button:hover,
.stories-home-search-button:focus-visible {
    background: #b78624;
    color: #171717;
}

.stories-home-search-button:focus-visible {
    outline: 2px solid #222;
    outline-offset: -3px;
}

.stories-home-search-button svg {
    display: block;
    width: 21px;
    height: 21px;
}

@media (min-width: 600px) {
    .stories-home-search {
        padding: 18px 24px 10px;
    }
}


/* ========================================
   Stories: Focused Search Mode
======================================== */

.stories-search-focus-overlay {
    position: fixed;
    inset: 0;
    z-index: 9990;
    background: rgba(15, 15, 15, 0.48);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

body.stories-search-focus-active .stories-search-focus-overlay {
    opacity: 1;
    visibility: visible;
}

/* Keep the search box sharp and above the overlay */
body.stories-search-focus-active .stories-home-search {
    position: relative;
    z-index: 9992;
    background: transparent;
}

body.stories-search-focus-active .stories-home-search-row {
    border: 2px solid #000000;
    border-radius: 10px;
    box-shadow: 0 0 0 4px rgba(20, 21, 22, 0.22);
    background: #fff;
}

body.stories-search-focus-active .stories-home-search-input {
    background: #fff;
}

/* Keep the bottom navigation sharp and clickable */
body.stories-search-focus-active .stories-footer {
    z-index: 9995;
}

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .stories-search-focus-overlay {
        transition: none;
    }
}

/* Signed-in user avatar in the bottom navigation */
.stories-nav-avatar {
    display: block;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}


/* ========================================
   Stories: Horizontal Article Cards (Shared)
======================================== */

.stories-card-horizontal {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 14px;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 16px;
    overflow: hidden;
    border: 1px solid #e0e4eb;
    border-radius: 24px;
    background: #fff;
}

.stories-card-horizontal .stories-card-content {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    justify-content: space-between;
    min-width: 0;
    padding: 0;
}

.stories-card-category {
    display: inline-flex;
    align-self: flex-start;
    max-width: 100%;
    margin-bottom: 8px;
    padding: 5px 10px;
    overflow: hidden;
    border-radius: 999px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stories-card-title {
    display: block;
    margin: 0 0 10px;
    overflow: hidden;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: -0.2px;
}

.stories-card-title a {
    display: block;
    overflow: hidden;
    color: #111827;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stories-card-author {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    margin-bottom: 14px;
    color: #64748b;
    font-size: 12px;
    line-height: 1.4;
}

.stories-card-avatar {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    border-radius: 50%;
    object-fit: cover;
}

.stories-card-author-name {
    overflow: hidden;
    color: #111827;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stories-card-meta-separator {
    flex: 0 0 auto;
}

.stories-card-author time {
    flex: 0 0 auto;
    white-space: nowrap;
}

.stories-card-bottom,
.stories-card-actions,
.stories-card-reading {
    display: flex;
    align-items: center;
    min-width: 0;
}

.stories-card-bottom {
    justify-content: space-between;
    gap: 8px;
    margin-top: auto;
}

.stories-card-actions,
.stories-card-reading {
    gap: 7px;
}

.stories-card-like,
.stories-card-comment,
.stories-card-bookmark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: 34px;
    min-height: 32px;
    margin: 0;
    padding: 6px 9px;
    border: 0;
    border-radius: 999px;
    background: #f8fafc;
    color: #111827;
    font-family: inherit;
    font-size: 12px;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.stories-card-like svg,
.stories-card-comment svg,
.stories-card-bookmark svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.stories-card-like.is-liked {
    background: #fff1f2;
    color: #e11d48;
}

.stories-card-like.is-liked svg {
    fill: currentColor;
}

.stories-card-reading {
    justify-content: flex-end;
}

.stories-card-views {
    display: none;
}

.stories-card-reading-time {
    color: #111827;
    font-size: 12px;
    white-space: nowrap;
}

.stories-card-bookmark {
    width: 32px;
    min-width: 32px;
    height: 32px;
    padding: 6px;
}

.stories-card-bookmark.is-saved {
    background: #eff6ff;
    color: #2563eb;
}

.stories-card-image-horizontal {
    display: block;
    flex: 0 0 160px;
    width: 160px;
    min-width: 0;
    height: 160px;
    margin: 0;
    overflow: hidden;
    border-radius: 16px;
    background: #f1f5f9;
}

.stories-card-image-horizontal img {
    display: block;
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    object-fit: cover;
}

/* Keep the horizontal layout on tablets and desktops. */
@media (min-width: 600px) {
    .stories-feed {
        grid-template-columns: minmax(0, 1fr);
        gap: 22px;
    }

    .stories-card-horizontal,
    .stories-card-featured {
        grid-column: auto;
    }

    .stories-card-image-horizontal {
        flex-basis: 160px;
        width: 160px;
        height: 160px;
    }
}

/* Compact layout for narrow mobile screens. */
@media (max-width: 420px) {
    .stories-card-horizontal {
        gap: 10px;
        padding: 12px;
        border-radius: 20px;
    }

    .stories-card-image-horizontal {
        flex-basis: 104px;
        width: 104px;
        height: 132px;
        border-radius: 14px;
    }

    .stories-card-title {
        font-size: 14px;
    }

    .stories-card-author {
        gap: 5px;
        font-size: 10px;
    }

    .stories-card-avatar {
        width: 24px;
        height: 24px;
        flex-basis: 24px;
    }

    .stories-card-actions,
    .stories-card-reading {
        gap: 4px;
    }

    .stories-card-like,
    .stories-card-comment {
        gap: 4px;
        min-width: 30px;
        min-height: 30px;
        padding: 5px 6px;
        font-size: 11px;
    }

    .stories-card-like svg,
    .stories-card-comment svg {
        width: 16px;
        height: 16px;
        flex-basis: 16px;
    }

    .stories-card-reading-time {
        font-size: 10px;
    }

    .stories-card-bookmark {
        width: 28px;
        min-width: 28px;
        height: 28px;
    }
}


/* ========================================
   Stories Homepage: Pagination
======================================== */

.stories-home .stories-pagination {
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 28px 0 12px;
}

.stories-home .stories-pagination ul.page-numbers {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.stories-home .stories-pagination ul.page-numbers li {
    display: block;
    margin: 0;
    padding: 0;
    list-style: none;
}

.stories-home .stories-pagination .page-numbers {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    color: #374151;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    text-decoration: none;
    transition:
        background-color 150ms ease,
        color 150ms ease,
        border-color 150ms ease;
}

.stories-home .stories-pagination .page-numbers.current {
    border-color: #2563eb;
    background: #2563eb;
    color: #fff;
    font-weight: 700;
}

.stories-home .stories-pagination a.page-numbers:hover {
    border-color: #2563eb;
    background: #eff6ff;
    color: #1d4ed8;
}

.stories-home .stories-pagination a.page-numbers:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 3px;
}

.stories-home .stories-pagination .page-numbers.dots {
    min-width: auto;
    padding-inline: 4px;
    border-color: transparent;
    background: transparent;
}

@media (max-width: 420px) {
    .stories-home .stories-pagination {
        margin-top: 24px;
    }

    .stories-home .stories-pagination ul.page-numbers {
        gap: 6px;
    }

    .stories-home .stories-pagination .page-numbers {
        min-width: 36px;
        min-height: 36px;
        padding: 7px 9px;
        border-radius: 10px;
        font-size: 13px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .stories-home .stories-pagination .page-numbers {
        transition: none;
    }
}


/* Keep homepage pagination clear of the floating desktop navigation */
@media (min-width: 768px) {
    body:has(.stories-home) {
        padding-bottom: 120px;
    }

    .stories-home .stories-pagination {
        position: relative;
        z-index: 1;
        margin-bottom: 32px;
    }
}