/*
 * The pals' 24 hour stories (stories/, web-app-stories.js): the story tray at the top of the chats
 * list (the phone's CharacterStoryTray) and the full-screen story viewer (CharacterStoryView).
 */

:root {
    /* words and lines drawn over a story picture: white on a dark scrim in both themes, like the phone */
    --wa-story-on-photo: #FFFFFF;
    --wa-story-on-photo-muted: rgba(255, 255, 255, 0.85);
    --wa-story-on-photo-faint: rgba(255, 255, 255, 0.72);
    --wa-story-photo-scrim-light: rgba(0, 0, 0, 0.08);
    --wa-story-photo-scrim-mid: rgba(0, 0, 0, 0.05);
    --wa-story-photo-scrim-strong: rgba(0, 0, 0, 0.78);
    --wa-story-progress-track: rgba(255, 255, 255, 0.3);
    /* the viewer is always dark (the phone forces its dark theme there) */
    --wa-story-viewer-background: #000000;
    --wa-story-viewer-scrim-top: rgba(0, 0, 0, 0.55);
    --wa-story-viewer-scrim-bottom-mid: rgba(0, 0, 0, 0.62);
    --wa-story-viewer-scrim-bottom: rgba(0, 0, 0, 0.92);
    --wa-story-viewer-dash-track: rgba(255, 255, 255, 0.35);
    --wa-story-viewer-field: rgba(255, 255, 255, 0.15);
    --wa-story-viewer-hint: rgba(255, 255, 255, 0.7);
    --wa-story-viewer-button-outline: rgba(255, 255, 255, 0.5);
    --wa-story-card-shadow: 0 2px 4px rgba(0, 0, 0, 0.18), 0 4px 10px rgba(0, 0, 0, 0.12);
}

/* ==================== the story tray ==================== */

/* the row measures itself, so a card is two and a half to a row of any width (the phone's pager) */
.wa-story-tray-spot { container-type: inline-size; }
.wa-story-tray {
    /* tall 9:16 cards, the shape the story photos are made in: (width - 16 start - 2 × 8 gaps) / 2.5
       wide, never taller than 42% of the window (a shorter card narrows with it, so it stays 9:16) */
    --wa-story-card-height: min(calc((100cqw - 32px) / 2.5 * 16 / 9), 42vh);
    --wa-story-card-size: calc(var(--wa-story-card-height) * 9 / 16);
}
.wa-story-tray-rail {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    /* 16px at both ends, like the pager: the row stops flush with the last card, never scrolling into
       empty space after it; the moving-on then glides back to the first (web-app-stories.js) */
    padding: 4px 16px 0 16px;
    scroll-padding-inline-start: 16px;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
}
.wa-story-tray-rail::-webkit-scrollbar { display: none; }
/* phones: the tray tops the chats list; wide screens: it runs the full width above both panes */
.wa-story-tray-spot--wide-screens { display: none; }
/* gap under the phone tray so the first chat row sits off the story cards (matches the app) */
.wa-story-tray-spot--in-list { padding-bottom: 12px; }
@media (min-width: 900px) {
    .wa-story-tray-spot--in-list { display: none; }
    .wa-story-tray-spot--wide-screens {
        display: block;
        flex: none;
        padding-bottom: 12px;
        border-bottom: 1px solid var(--md-outline-variant);
    }
    /* fixed-size tall cards from the left, as many as fit, the rest a scroll away */
    .wa-story-tray-spot--wide-screens .wa-story-tray { --wa-story-card-height: min(320px, 34vh); }
}
/* a mouse can't swipe: round arrows at the ends instead of a scrollbar, each hidden while there is
   nothing more that way (web-app-stories.js); fingers swipe and never see them */
.wa-story-tray { position: relative; }
.wa-story-tray-arrow {
    position: absolute;
    top: calc(50% + 2px);
    z-index: 2;
    width: 40px;
    height: 40px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--md-outline-variant);
    border-radius: 999px;
    background: var(--md-surface-container-high);
    color: var(--md-on-surface);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    transform: translateY(-50%);
}
.wa-story-tray-arrow .wa-icon svg { width: 24px; height: 24px; }
.wa-story-tray-arrow--back { left: 8px; }
.wa-story-tray-arrow--back .wa-icon { transform: scaleX(-1); }
.wa-story-tray-arrow--forward { right: 8px; }
.wa-story-tray-arrow:hover { background: var(--md-surface-container-highest); }
.wa-story-tray-arrow:focus-visible { outline: none; box-shadow: var(--wa-focus-ring); }
@media (hover: hover) and (pointer: fine) {
    .wa-story-tray-arrow { display: inline-flex; }
}
.wa-story-tray-arrow[hidden] { display: none; }
.wa-story-tray-item {
    position: relative;
    flex: 0 0 var(--wa-story-card-size);
    display: flex;
    flex-direction: column;
    align-items: center;
    scroll-snap-align: start;
    /* the neighbours sit a touch smaller than the card in focus (the phone's 0.96) */
    transform: scale(0.96);
    transition: transform 200ms ease;
}
.wa-story-tray-item.is-focused { transform: none; }
.wa-story-tray-card {
    display: block;
    width: 100%;
    aspect-ratio: 9 / 16;
    box-sizing: border-box;
    /* the ring: 1px grey once read, 2px gradient while unread, with a 2px gap inside */
    padding: 3px;
    border: 1px solid var(--md-outline-variant);
    border-radius: 20px;
    background: var(--md-background);
    box-shadow: var(--wa-story-card-shadow);
    color: var(--wa-story-on-photo);
    text-decoration: none;
}
.wa-story-tray-item.is-unread .wa-story-tray-card {
    padding: 4px;
    border: 2px solid transparent;
    background:
        linear-gradient(var(--md-background), var(--md-background)) padding-box,
        var(--wa-pal-story-ring) border-box;
}
.wa-story-tray-card:focus-visible { outline: none; box-shadow: var(--wa-focus-ring); }
.wa-story-tray-photo-frame {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 16px;
    overflow: hidden;
    background: var(--md-surface-container-high);
}
.wa-story-tray-photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.wa-story-tray-scrim {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, var(--wa-story-photo-scrim-light) 0%, var(--wa-story-photo-scrim-mid) 45%, var(--wa-story-photo-scrim-strong) 100%);
}
/* the thin bar the card in focus fills before the row moves on */
.wa-story-tray-progress {
    position: absolute;
    top: 6px;
    left: 8px;
    right: 8px;
    height: 3px;
    border-radius: 999px;
    overflow: hidden;
    background: var(--wa-story-progress-track);
}
.wa-story-tray-progress-fill {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--wa-story-on-photo);
    transform: scaleX(0);
    transform-origin: left center;
}
.wa-story-tray-text {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.wa-story-tray-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-story-tray-name { font-size: calc(14px * var(--wa-text-scale, 1)); line-height: calc(20px * var(--wa-text-scale, 1)); font-weight: 700; }
/* loading: the phone's tall placeholder cards */
.wa-story-tray--loading .wa-story-tray-rail { overflow: hidden; }
.wa-story-tray-card--placeholder {
    flex: 0 0 var(--wa-story-card-size);
    padding: 0;
    border: 0;
    box-shadow: none;
    background: var(--md-surface-container-highest);
    animation: wa-loading-look-pulse 1s linear infinite alternate;
}
/* every grey card after the first sits a touch smaller, like the real tray's neighbours */
.wa-story-tray-card--placeholder ~ .wa-story-tray-card--placeholder { transform: scale(0.96); }

@media (prefers-reduced-motion: reduce) {
    .wa-story-tray-item { transition: none; }
    .wa-story-tray-card--placeholder { animation: none; }
}

/* ==================== the story viewer ==================== */

/* full screen over everything but dialogs and toasts, like the phone's own screen */
.wa-story-viewer {
    position: fixed;
    inset: 0;
    z-index: 30;
    overflow: hidden;
    background: var(--wa-story-viewer-background);
    color: var(--wa-story-on-photo);
    color-scheme: dark;
    user-select: none;
    -webkit-user-select: none;
}
html:has(.wa-app-screen:not([hidden]) .wa-story-viewer) { overflow: hidden; }
.wa-story-viewer-stage { position: absolute; inset: 0; display: flex; justify-content: center; }
.wa-story-viewer-story { position: relative; width: 100%; height: 100%; }
.wa-story-viewer-story[hidden],
.wa-story-viewer-photo[hidden],
.wa-story-viewer-pal[hidden],
.wa-story-viewer-caption[hidden] { display: none; }
.wa-story-viewer-photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
/* a window wider than tall letterboxes the 9:16 picture instead of cropping it (the phone's landscape
   rule); the bars and the message box keep to the picture's width */
@media (min-aspect-ratio: 1/1) {
    .wa-story-viewer-story { width: auto; aspect-ratio: 9 / 16; }
    .wa-story-viewer .wa-story-viewer-chrome { max-width: calc(100vh * 9 / 16); }
}
.wa-story-viewer-scrim-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 22%;
    background: linear-gradient(to bottom, var(--wa-story-viewer-scrim-top), transparent);
    pointer-events: none;
}
.wa-story-viewer-scrim-bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 42%;
    background: linear-gradient(to bottom, transparent, var(--wa-story-viewer-scrim-bottom-mid), var(--wa-story-viewer-scrim-bottom));
    pointer-events: none;
}
.wa-story-viewer-chrome {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
    box-sizing: border-box;
}
.wa-story-viewer-progress { display: flex; gap: 2px; }
.wa-story-viewer-progress-segment { flex: 1; height: 2px; border-radius: 999px; overflow: hidden; background: var(--wa-story-viewer-dash-track); }
.wa-story-viewer-progress-fill {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--wa-story-on-photo);
    transform: scaleX(0);
    transform-origin: left center;
}
.wa-story-viewer-header-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.wa-story-viewer-pal {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    color: var(--wa-story-on-photo);
    text-decoration: none;
}
.wa-story-viewer-pal-face { flex: none; width: 40px; height: 40px; border-radius: 999px; object-fit: cover; }
.wa-story-viewer-pal-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: calc(14px * var(--wa-text-scale, 1));
    line-height: calc(20px * var(--wa-text-scale, 1));
    font-weight: 500;
}
.wa-story-viewer-close {
    flex: none;
    margin-left: auto;
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: var(--wa-story-on-photo);
}
.wa-story-viewer-close .wa-icon svg { width: 24px; height: 24px; }
.wa-story-viewer-close:focus-visible,
.wa-story-viewer-pal:focus-visible,
.wa-story-viewer-send:focus-visible { outline: 2px solid var(--wa-story-on-photo); outline-offset: 2px; }
/* the picture's tap area: hold to pause, left third back, the rest on */
.wa-story-viewer-tap-zone { flex: 1; min-height: 0; touch-action: manipulation; -webkit-touch-callout: none; }
.wa-story-viewer-bottom { padding-top: 32px; }
.wa-story-viewer-caption {
    margin: 0 0 8px;
    font-size: calc(14px * var(--wa-text-scale, 1));
    line-height: calc(20px * var(--wa-text-scale, 1));
    color: var(--wa-story-on-photo);
    overflow-wrap: anywhere;
    user-select: text;
    -webkit-user-select: text;
}
.wa-story-viewer-message-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 48px;
    padding: 0 4px 0 16px;
    border-radius: 999px;
    background: var(--wa-story-viewer-field);
}
.wa-story-viewer-message-field { flex: 1; min-width: 0; display: flex; }
.wa-story-viewer-message {
    flex: 1;
    min-width: 0;
    border: 0;
    padding: 8px 0;
    background: transparent;
    color: var(--wa-story-on-photo);
    caret-color: var(--wa-story-on-photo);
    font: inherit;
    font-size: calc(14px * var(--wa-text-scale, 1));
    outline: none;
}
.wa-story-viewer-message::placeholder { color: var(--wa-story-viewer-hint); }
/* the field sits inside the rounded bar: the bar shows the focus, not a box around the words */
.wa-story-viewer-message:focus-visible { outline: none; box-shadow: none; }
.wa-story-viewer-message-bar:focus-within { box-shadow: inset 0 0 0 1px var(--wa-story-viewer-button-outline); }
.wa-story-viewer-send {
    flex: none;
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--wa-story-on-photo);
    cursor: pointer;
}
.wa-story-viewer-send:disabled { opacity: 0.38; cursor: default; }
.wa-story-viewer-send .wa-icon svg { width: 24px; height: 24px; }

/* "Story not available" (the phone's StoryNotAvailableContent) */
.wa-story-viewer--gone { display: flex; align-items: center; justify-content: center; padding: 16px; }
.wa-story-viewer-gone { display: flex; flex-direction: column; align-items: center; text-align: center; max-width: 420px; }
.wa-story-viewer-gone-icon { color: var(--wa-story-on-photo-faint); }
.wa-story-viewer-gone-icon .wa-icon svg { width: 56px; height: 56px; }
.wa-story-viewer-gone-title { margin: 16px 0 0; font-size: calc(16px * var(--wa-text-scale, 1)); line-height: calc(24px * var(--wa-text-scale, 1)); font-weight: 500; }
.wa-story-viewer-gone-message { margin: 8px 0 0; font-size: calc(14px * var(--wa-text-scale, 1)); line-height: calc(20px * var(--wa-text-scale, 1)); color: var(--wa-story-on-photo-faint); }
.wa-story-viewer-go-back {
    margin-top: 24px;
    min-width: 50%;
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 24px;
    border: 1px solid var(--wa-story-viewer-button-outline);
    border-radius: 999px;
    color: var(--wa-story-on-photo);
    font-weight: 600;
    text-decoration: none;
}
.wa-story-viewer-go-back:focus-visible { outline: 2px solid var(--wa-story-on-photo); outline-offset: 2px; }
