:root {
    --bg: #0A0D13;
    --surface: #10141C;
    --surface-2: #151A23;
    --surface-3: #1A202B;

    --text: #F5F7FA;
    --muted: #8F98A7;
    --muted-2: #626B79;

    --accent: #FC9900;
    --accent-soft: rgba(252, 153, 0, .14);

    --border: rgba(255, 255, 255, .07);
    --border-strong: rgba(255, 255, 255, .1);

    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 22px;
    --radius-xl: 28px;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    --header-height: 68px;
    --bottom-nav-height: 72px;

    --ease-ios:
        cubic-bezier(.22, .61, .36, 1);
}


* {
    box-sizing: border-box;
}


html {
    background: var(--bg);
    color-scheme: dark;
    scroll-behavior: auto;
}


body {
    margin: 0;

    min-width: 320px;
    min-height: 100dvh;

    background:
        radial-gradient(
            circle at 85% -10%,
            rgba(252, 153, 0, .055),
            transparent 26rem
        ),
        var(--bg);

    color: var(--text);

    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "SF Pro Display",
        "SF Pro Text",
        Inter,
        Roboto,
        Arial,
        sans-serif;

    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;

    -webkit-tap-highlight-color: transparent;

    overscroll-behavior-y: none;
}


button,
input,
textarea {
    font: inherit;
}


button {
    color: inherit;
    border: 0;
    outline: 0;
    cursor: pointer;
}


button,
a {
    -webkit-tap-highlight-color: transparent;
}


svg {
    display: block;
}


.app-shell {
    width: 100%;
    min-height: 100dvh;
}


.app-main {
    width: 100%;
    min-height: 100dvh;

    padding-top:
        calc(var(--safe-top) + var(--header-height));

    padding-bottom:
        calc(
            var(--bottom-nav-height)
            + var(--safe-bottom)
            + 28px
        );
}


.page {
    display: none;
}


.page.active-page {
    display: block;
}


.top-bar {
    position: fixed;
    z-index: 100;

    top: 0;
    left: 0;
    right: 0;

    height:
        calc(
            var(--safe-top)
            + var(--header-height)
        );

    padding:
        calc(var(--safe-top) + 10px)
        18px
        10px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    background:
        rgba(10, 13, 19, .78);

    border-bottom:
        1px solid rgba(255, 255, 255, .035);

    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
}


.brand {
    color: var(--text);
    text-decoration: none;

    font-size: 21px;
    line-height: 1;
    font-weight: 760;

    letter-spacing: -.55px;
}


.top-actions {
    min-width: 46px;

    display: flex;
    align-items: center;
    justify-content: flex-end;

    gap: 10px;
}


.search-trigger {
    width: 44px;
    height: 44px;

    flex: 0 0 44px;

    display: grid;
    place-items: center;

    border-radius: 50%;

    background:
        rgba(255, 255, 255, .055);

    border:
        1px solid rgba(255, 255, 255, .055);

    transition:
        transform 140ms var(--ease-ios),
        background-color 140ms ease;
}


.search-trigger:active {
    transform: scale(.94);

    background:
        rgba(255, 255, 255, .09);
}


.search-trigger svg {
    width: 20px;
    height: 20px;

    fill: none;
    stroke: var(--text);
    stroke-width: 1.8;
    stroke-linecap: round;
}


.dock-stories {
    display: none;
}


.section {
    width: 100%;
    margin-top: 34px;
}


.section:first-child {
    margin-top: 20px;
}


.section-heading {
    padding: 0 18px;
    margin-bottom: 15px;

    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px;
}


.compact-heading {
    margin-bottom: 17px;
}


.eyebrow {
    display: block;
    margin-bottom: 5px;

    color: var(--accent);

    font-size: 10px;
    line-height: 1;
    font-weight: 750;

    text-transform: uppercase;
    letter-spacing: 1.35px;
}


.section-heading h1,
.section-heading h2 {
    margin: 0;

    color: var(--text);

    font-size: 24px;
    line-height: 1.06;
    font-weight: 760;

    letter-spacing: -.7px;
}


.text-action {
    padding: 8px 0;

    background: transparent;

    color: var(--muted);

    font-size: 12px;
    font-weight: 650;
}


.bottom-nav {
    position: fixed;
    z-index: 120;

    left: 50%;
    bottom:
        calc(
            10px
            + var(--safe-bottom)
        );

    transform: translateX(-50%);

    width:
        min(
            calc(100% - 32px),
            420px
        );

    height: var(--bottom-nav-height);

    padding: 6px;

    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));

    border:
        1px solid rgba(255, 255, 255, .07);

    border-radius: 24px;

    background:
        rgba(17, 21, 29, .9);

      box-shadow:
        0 18px 50px rgba(0, 0, 0, .36);

    -webkit-backdrop-filter: blur(22px);
    backdrop-filter: blur(22px);

    overflow: hidden;
}


.nav-active-pill {
    position: absolute;

    top: 6px;
    bottom: 6px;
    left: 6px;

    width:
        calc(
            (100% - 12px)
            / 3
        );

    border-radius: 18px;

    background:
        linear-gradient(
            135deg,
            #FFAB21,
            var(--accent)
        );

    box-shadow:
        0 8px 24px
        rgba(252, 153, 0, .18);

    transform: translateX(0);

    transition:
        transform 260ms
        cubic-bezier(.32, .72, 0, 1);
}


.bottom-nav[data-active="vip"]
.nav-active-pill {
    transform: translateX(100%);
}

.bottom-nav[data-active="upgrade"]
.nav-active-pill {
    transform: translateX(200%);
}


.nav-item {
    position: relative;
    z-index: 2;

    min-width: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    gap: 8px;

    background: transparent;

    color: var(--muted);

    border-radius: 18px;

    font-size: 13px;
    font-weight: 700;

    transition:
        color 180ms ease,
        transform 140ms var(--ease-ios);
}


.nav-item:active {
    transform: scale(.97);
}


.nav-item.active {
    color: #171009;
}


.nav-item svg {
    width: 18px;
    height: 18px;

    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}


@media (min-width: 760px) {

    .app-main {
        width: min(100%, 760px);
        margin-inline: auto;
    }

    .top-bar {
        padding-left:
            max(
                22px,
                calc((100vw - 760px) / 2 + 22px)
            );

        padding-right:
            max(
                22px,
                calc((100vw - 760px) / 2 + 22px)
            );
    }
}


@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;

        transition-duration: .01ms !important;

        scroll-behavior: auto !important;
    }
}

/* ===== SEARCH MORPH ===== */

.search-shell {
    width: 44px;
    height: 44px;

    display: flex;
    align-items: center;

    overflow: hidden;

    border-radius: 22px;

    background: rgba(255, 255, 255, .055);

    border:
        1px solid rgba(255, 255, 255, .055);

    transition:
        width 300ms cubic-bezier(.32, .72, 0, 1),
        background-color 180ms ease,
        border-color 180ms ease;
}

.top-actions.search-open .search-shell {
    width: min(66vw, 300px);

    background:
        rgba(23, 28, 37, .96);

    border-color:
        rgba(255, 255, 255, .08);
}

.search-shell .search-trigger {
    background: transparent;
    border: 0;

    flex: 0 0 42px;
}

.search-input {
    width: 0;
    min-width: 0;

    padding: 0;

    opacity: 0;

    border: 0;
    outline: 0;

    background: transparent;
    color: var(--text);

    font-size: 13px;
    font-weight: 520;

    pointer-events: none;

    transition:
        opacity 140ms ease;
}

.search-input::placeholder {
    color: var(--muted-2);
}

.top-actions.search-open .search-input {
    width: 100%;
    opacity: 1;

    pointer-events: auto;
}

.search-cancel {
    width: 36px;
    height: 36px;

    flex: 0 0 36px;

    padding: 0;

    display: grid;
    place-items: center;

    opacity: 0;

    transform: scale(.8);

    pointer-events: none;

    border-radius: 50%;

    background: transparent;
    color: var(--muted);

    transition:
        opacity 150ms ease,
        transform 220ms cubic-bezier(.32, .72, 0, 1);
}

.top-actions.search-open .search-cancel {
    opacity: 1;
    transform: scale(1);

    pointer-events: auto;
}

.search-cancel svg {
    width: 16px;
    height: 16px;

    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
}

.top-actions.search-open .dock-stories {
    opacity: 0 !important;

    transform:
        translateX(14px)
        translateY(0) !important;

    pointer-events: none;
}

.top-actions.search-open {
    flex: 1;
    justify-content: flex-end;
}

.top-actions.search-open + * {
    pointer-events: none;
}

@media (max-width: 390px) {
    .top-actions.search-open .search-shell {
        width: min(64vw, 260px);
    }
}


/* ===== SEARCH MOTION FINAL ===== */
.top-actions {
    flex: 1 1 auto;
    min-width: 0;
}

.search-shell {
    flex: 0 0 auto;
    width: 44px;
    max-width: none;
    will-change: width;
    transition:
        width 260ms cubic-bezier(.32, .72, 0, 1),
        background-color 160ms ease,
        border-color 160ms ease;
}

.top-actions.search-open {
    flex: 1 1 auto;
    min-width: 0;
    margin-left: 18px;
}

.top-actions.search-open .search-shell {
    width: calc(100vw - 72px);
    max-width: 350px;
}

.top-actions .dock-stories {
    display: flex;
}

@media (max-width: 390px) {
    .top-actions.search-open .search-shell {
        width: calc(100vw - 66px);
        max-width: 310px;
    }
}

/* ===== SEARCH FINAL WIDTH TUNE ===== */
.top-actions.search-open .search-shell {
    width: min(72vw, 300px);
}

@media (max-width: 390px) {
    .top-actions.search-open .search-shell {
        width: min(70vw, 280px);
    }
}

/* ===== SEARCH WIDTH SMALLER ===== */
.top-actions.search-open .search-shell {
    width: min(64vw, 270px);
}

@media (max-width: 390px) {
    .top-actions.search-open .search-shell {
        width: min(62vw, 240px);
    }
}

/* ===== SEARCH STORY FADE ONLY ===== */
.top-actions.search-open .dock-stories {
    opacity: 0 !important;
    transform: translateX(0) translateY(0) !important;
    transition:
        opacity 90ms ease-out,
        transform 240ms cubic-bezier(.32, .72, 0, 1) !important;
    pointer-events: none;
}

.top-bar.story-docked .top-actions:not(.search-open) .dock-stories {
    opacity: 1;
    transform: translateX(0) translateY(0);
    transition:
        opacity 90ms ease-out,
        transform 240ms cubic-bezier(.32, .72, 0, 1) !important;
}

/* ===== SEARCH CLOSE STORY CHILD FADE ===== */
.top-bar.story-docked .top-actions:not(.search-open) .dock-story {
    transition:
        transform 260ms cubic-bezier(.32, .72, 0, 1),
        opacity 260ms ease !important;
}

/* ===== SEARCH CLOSE STORY FADE TEST ===== */
.top-bar.story-docked .top-actions:not(.search-open) .dock-story {
    transition-delay: 0ms !important;
    transition:
        transform 240ms cubic-bezier(.32, .72, 0, 1),
        opacity 240ms linear !important;
}

/* ===== REAL SEARCH CLOSE FADE ===== */
.top-bar.story-docked .top-actions.search-closing .dock-stories {
    opacity: 0 !important;
    transform: translateX(0) translateY(0) !important;
    transition: none !important;
}

.top-bar.story-docked .top-actions.search-closing.search-close-fade .dock-stories {
    opacity: 1 !important;
    transform: translateX(0) translateY(0) !important;
    transition:
        opacity 90ms ease-out,
        transform 240ms cubic-bezier(.32, .72, 0, 1) !important;
}

/* ===== FIX STORY POSITION ONLY ===== */
.top-actions {
    position: relative;
    width: min(62vw, 240px);
    height: 44px;
    flex: 0 0 min(62vw, 240px);
}

.top-actions .dock-stories {
    position: absolute;
    top: 50%;
    right: 54px;
    z-index: 1;
    transform: translateY(-50%);
}

.top-actions .search-shell {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 2;
}

.top-actions.search-open .search-shell {
    width: min(62vw, 240px);
}

.top-actions.search-open .dock-stories {
    transform: translateY(-50%) !important;
    opacity: 0 !important;
}

.top-bar.story-docked .top-actions:not(.search-open) .dock-stories {
    transform: translateY(-50%) !important;
    opacity: 1;
}

/* ===== STORY SHRINK ONLY - NO FADE ===== */
.top-bar.story-docked .top-actions:not(.search-open) .dock-stories {
    opacity: 1 !important;
    transform: translateY(-50%) scale(1) !important;
    transition: transform 260ms cubic-bezier(.32, .72, 0, 1) !important;
}

.top-actions.search-open .dock-stories {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(-50%) scale(0) !important;
    transition: transform 260ms cubic-bezier(.32, .72, 0, 1) !important;
    pointer-events: none;
}


/* ===== FINAL PATCH: USER SETTINGS ===== */

.brand {
    border: 0;
    padding: 0;
    margin: 0;
    background: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.brand img {
    display: block;
    width: clamp(118px, 31vw, 134px);
    height: auto;
    max-height: 34px;
    object-fit: contain;
    object-position: left center;
}

.kg-settings-overlay {
    position: fixed;
    z-index: 10050;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    background: rgba(3, 5, 8, .60);
    -webkit-backdrop-filter: blur(7px);
    backdrop-filter: blur(7px);
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 190ms ease,
        visibility 190ms ease;
}

.kg-settings-overlay[hidden] {
    display: none !important;
}

.kg-settings-overlay.open {
    opacity: 1;
    visibility: visible;
}

.kg-settings-sheet {
    width: min(100%, 520px);
    padding:
        8px 16px
        calc(18px + env(safe-area-inset-bottom));
    border-radius: 24px 24px 0 0;
    border: 1px solid rgba(255,255,255,.08);
    border-bottom: 0;
    background:
        linear-gradient(
            180deg,
            rgba(25, 29, 38, .98),
            rgba(13, 16, 22, .995)
        );
    box-shadow:
        0 -18px 48px rgba(0,0,0,.34);
    transform: translateY(18px);
    transition:
        transform 220ms
        cubic-bezier(.22,.61,.36,1);
}

.kg-settings-overlay.open
.kg-settings-sheet {
    transform: translateY(0);
}

.kg-settings-handle {
    width: 38px;
    height: 4px;
    margin: 2px auto 15px;
    border-radius: 99px;
    background: rgba(255,255,255,.22);
}

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

.kg-settings-kicker {
    display: block;
    margin-bottom: 2px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.kg-settings-header h2 {
    margin: 0;
    color: var(--text);
    font-size: 22px;
    line-height: 1.15;
}

.kg-settings-close {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: rgba(255,255,255,.035);
    color: var(--muted);
}

.kg-settings-close svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
}

.kg-settings-group,
.kg-settings-row {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(255,255,255,.025);
}

.kg-settings-group {
    padding: 14px;
    margin-bottom: 10px;
}

.kg-settings-row {
    min-height: 72px;
    padding: 12px 14px;
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    transition:
        opacity 150ms ease,
        filter 150ms ease;
}

.kg-settings-copy {
    min-width: 0;
}

.kg-settings-copy strong {
    display: block;
    color: var(--text);
    font-size: 13px;
    line-height: 1.25;
}

.kg-settings-copy small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 10.5px;
    line-height: 1.4;
}

.kg-motion-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-top: 12px;
    padding: 4px;
    border-radius: 12px;
    background: rgba(0,0,0,.20);
}

.kg-motion-options button {
    min-height: 34px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    transition:
        background 150ms ease,
        color 150ms ease,
        transform 120ms ease;
}

.kg-motion-options button.active {
    color: var(--text);
    background: rgba(255,255,255,.095);
}
.kg-settings-toggle {
    position: relative;
    flex: 0 0 auto;
}

.kg-settings-toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.kg-settings-switch {
    width: 43px;
    height: 25px;
    display: block;
    position: relative;
    border-radius: 99px;
    border: 1px solid rgba(255,255,255,.10);
    background: rgba(255,255,255,.08);
    transition:
        background 150ms ease,
        opacity 150ms ease;
}

.kg-settings-switch span {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: rgba(255,255,255,.78);
    transition:
        transform 160ms cubic-bezier(.22,.61,.36,1),
        background 150ms ease;
}

.kg-settings-toggle
input:checked +
.kg-settings-switch {
    background: rgba(255,255,255,.24);
}

.kg-settings-toggle
input:checked +
.kg-settings-switch span {
    transform: translateX(18px);
    background: #fff;
}

.kg-settings-row.is-disabled {
    opacity: .40;
    filter: saturate(.45);
}

.kg-settings-toggle
input:disabled +
.kg-settings-switch {
    cursor: not-allowed;
}

/* Explicit Reduce = true zero-animation mode across the public project. */
html[data-motion-mode="reduced"] *,
html[data-motion-mode="reduced"] *::before,
html[data-motion-mode="reduced"] *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
}


/* ===== FINAL PATCH: IMAGE LOADING POLISH ===== */

/*
   #211 Soft image appearance
   #212 No image flash
   #213 Skeleton -> image crossfade
   #217 Progressive image loading
   #218 Image failure fallback
*/

.card-cover,
.normal-cover,
.story-inner,
.search-result-cover,
.detail-media-item,
.detail-related-cover {
    background:
        linear-gradient(
            145deg,
            rgba(255,255,255,.032),
            rgba(255,255,255,.012)
        ),
        #0b0e14;
}

.kg-progressive-image {
    opacity: 0;
    transition:
        opacity 220ms ease,
        filter 260ms ease;
    filter: saturate(.94) contrast(.98);
}

.kg-progressive-image.kg-image-loaded {
    opacity: 1;
    filter: none;
}

.kg-progressive-image.kg-image-error {
    opacity: 0 !important;
    visibility: hidden;
}

.kg-image-failed {
    position: relative;
    overflow: hidden;
}

.kg-image-failed::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(
            135deg,
            rgba(255,255,255,.035),
            rgba(255,255,255,.010)
        ),
        #0b0e14;
}

/*
   Story / important media stays visually ready while loading.
   Actual request priority is handled by settings.js.
*/
.story-inner,
.hottest-card .card-cover {
    contain: paint;
}

/*
   Reduced mode keeps the same no-flash behavior
   but removes the visible fade animation.
*/
html[data-motion-mode="reduced"]
.kg-progressive-image {
    transition: none !important;
}

html[data-motion-mode="reduced"]
.kg-progressive-image.kg-image-loaded {
    opacity: 1;
}


/* ===== FINAL BRAND / HEADER CONTROL ===== */
.kg-motion-options-two {
    grid-template-columns: repeat(2, 1fr);
}

.brand {
    position: relative !important;
    left: -3px !important;
    width: 58px !important;
    max-width: 58px !important;
    height: 44px;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    overflow: visible !important;
    background: transparent;
    pointer-events: none;
    user-select: none;
}

.brand img {
    display: block;
    width: 58px !important;
    height: 58px !important;
    max-width: 58px !important;
    max-height: 58px !important;
    object-fit: contain !important;
    object-position: left center !important;
}

.header-settings-trigger {
    position: absolute;
    inset: 0 auto auto 0;
    z-index: 4;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(255,255,255,.055);
    border-radius: 50%;
    background: rgba(255,255,255,.055);
    color: var(--text);
    opacity: 0;
    visibility: hidden;
    transform: scale(.84) rotate(-12deg);
    pointer-events: none;
    transition:
        opacity 160ms ease,
        transform 210ms var(--ease-ios),
        visibility 160ms ease,
        background-color 150ms ease;
}

.header-settings-trigger svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.65;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.top-actions .search-trigger {
    transition:
        opacity 160ms ease,
        transform 210ms var(--ease-ios),
        background-color 150ms ease;
}

.top-actions.vip-mode .search-shell {
    width: 44px !important;
    max-width: 44px !important;
}

.top-actions.vip-mode .search-trigger {
    opacity: 0;
    visibility: hidden;
    transform: scale(.84) rotate(10deg);
    pointer-events: none;
}

.top-actions.vip-mode .header-settings-trigger {
    opacity: 1;
    visibility: visible;
    transform: scale(1) rotate(0);
    pointer-events: auto;
}

.top-actions.vip-mode .search-input,
.top-actions.vip-mode .search-cancel {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.top-actions.vip-mode .dock-stories {
    opacity: 0 !important;
    transform: translateY(-50%) scale(.86) !important;
    pointer-events: none !important;
}

.nav-item.search-locked {
    opacity: .38;
    pointer-events: none;
}

/* Explicit Reduce = absolute zero motion across the public project. */
html[data-motion-mode="reduced"] *,
html[data-motion-mode="reduced"] *::before,
html[data-motion-mode="reduced"] *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
}


/* Explore/Upgrade never show VIP Story Dock. */
html:not([data-header-mode="vip"]) .dock-stories {
    opacity: 0 !important;
    visibility: hidden !important;
    transform: translateY(-50%) scale(0) !important;
    pointer-events: none !important;
}
