/* The Omen Den palette, shared with Jackdaw Inputs (read off https://www.theomenden.com):
   accent #8f2c8d, header/footer plum #250f24, dark canvas #141414, dark-scheme accent tint #ae66aa.

   Retinting Fluent's brand tokens is what colours the UI: the primary button, the nav's active indicator,
   checked switches/radios and focus rings all paint from these, so nothing below recolours a component by
   class. Backgrounds keep one value in both schemes (white text on #8f2c8d is about 7.1:1); foregrounds
   land on the page background, so the dark scheme takes the lighter tint to stay legible. */
:root {
    --colorBrandBackground: #8f2c8d;
    --colorBrandBackgroundHover: #a3399f;
    --colorBrandBackgroundPressed: #6d2168;
    --colorBrandBackgroundSelected: #7d2779;
    --colorBrandStroke1: #8f2c8d;
    --colorBrandStroke2: #6d2168;

    --colorBrandForeground1: #8f2c8d;
    --colorBrandForeground2: #a3399f;
    --colorBrandForegroundLink: #8f2c8d;
    --colorBrandForegroundLinkHover: #a3399f;
    --colorBrandForegroundLinkPressed: #6d2168;
    --colorBrandForegroundLinkSelected: #8f2c8d;
    --colorCompoundBrandForeground1: #8f2c8d;
    --colorCompoundBrandForeground1Hover: #a3399f;
    --colorCompoundBrandForeground1Pressed: #6d2168;
    --colorCompoundBrandStroke: #8f2c8d;
    --colorCompoundBrandStrokeHover: #a3399f;
    --colorCompoundBrandStrokePressed: #6d2168;

    /* The fill of checked switches, checkboxes and radios; without it they stay Fluent's default blue. */
    --colorCompoundBrandBackground: #8f2c8d;
    --colorCompoundBrandBackgroundHover: #a3399f;
    --colorCompoundBrandBackgroundPressed: #6d2168;

    /* The 3px rule across the top of each card, as on theomenden.com. */
    --omenCardRule: #8f2c8d;

    /* Accents that sit beside the plum, so sections and categories can be told apart. Fills carry white
       icons (each at least 3:1 against white, the bar for graphics); the *-text values are for text on the
       page background and are swapped for lighter tints in the dark scheme below. */
    --omenAccentTeal: #0f766e;
    --omenAccentAmber: #b45309;
    --omenAccentBlue: #1d4ed8;
    --omenAccentRose: #be185d;
    --omenAccentTealText: #0f766e;
    --omenAccentAmberText: #92400e;
    --omenAccentBlueText: #1d4ed8;
    --omenAccentRoseText: #be185d;
}

/* A rounded icon tile in an accent gradient, used beside section headings. data-accent picks the hue. */
.omen-icon-chip {
    --chip-from: #a3399f;
    --chip-to: #5b1a59;
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: var(--borderRadiusLarge, 8px);
    background: linear-gradient(135deg, var(--chip-from), var(--chip-to));
    box-shadow: var(--shadow4);
}

.omen-icon-chip[data-accent="teal"] { --chip-from: #14b8a6; --chip-to: var(--omenAccentTeal); }
.omen-icon-chip[data-accent="amber"] { --chip-from: #d97706; --chip-to: var(--omenAccentAmber); }
.omen-icon-chip[data-accent="rose"] { --chip-from: var(--omenAccentRose); --chip-to: #8f2c8d; }

.omen-icon-chip-large {
    width: 3rem;
    height: 3rem;
    border-radius: var(--borderRadiusXLarge, 12px);
}

/* WCAG 2.2 target size (2.5.8): Fluent draws the info button at 20px; 24px is the AA minimum. */
.fluent-label-info button {
    min-width: 24px;
    min-height: 24px;
}

/* Label info popovers otherwise stretch to the window width; keep them a readable measure. The host is a zero-width anchor, so the cap goes on its content. */
.fluent-label-info fluent-popover-b > * {
    display: block;
    max-width: min(22rem, 90vw);
}

@media (forced-colors: active) {
    .omen-icon-chip {
        background: CanvasText;
        forced-color-adjust: none;
    }
}

/* Open Dyslexic: self-hosted (OFL-1.1) from wwwroot/fonts/opendyslexic, as in the OAuth broker. Browsers
   fetch only the faces actually used. Roboto comes from Google Fonts (linked in index.html). */
@font-face {
    font-family: "OpenDyslexic";
    src: url("../fonts/opendyslexic/OpenDyslexic-Regular.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "OpenDyslexic";
    src: url("../fonts/opendyslexic/OpenDyslexic-Bold.woff2") format("woff2");
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "OpenDyslexic";
    src: url("../fonts/opendyslexic/OpenDyslexic-Italic.woff2") format("woff2");
    font-weight: 400;
    font-style: italic;
    font-display: swap;
}

@font-face {
    font-family: "OpenDyslexic";
    src: url("../fonts/opendyslexic/OpenDyslexic-BoldItalic.woff2") format("woff2");
    font-weight: 700;
    font-style: italic;
    font-display: swap;
}

/* The layout wrapper carries data-font. `display: contents` keeps it out of Fluent's layout grid, while
   inheritance (including of --fontFamilyBase into the components' shadow DOM) still flows through it.
   font-family is re-declared because plain text would otherwise keep body's already-resolved Segoe. */
.omen-theme-root {
    display: contents;
    font-family: var(--fontFamilyBase);
}

.omen-theme-root[data-font="roboto"] {
    --fontFamilyBase: "Roboto", "Segoe UI", system-ui, sans-serif;
}

.omen-theme-root[data-font="opendyslexic"] {
    --fontFamilyBase: "OpenDyslexic", "Segoe UI", system-ui, sans-serif;
}

/* Lifted surfaces: cards sit on a deeper shadow with the brand rule across the top (pair with
   FluentCard Class="omen-surface"); buttons get a light shadow that deepens on hover. Subtle and
   transparent buttons stay flat, since they are meant to read as part of the surface they sit on. */
.omen-surface {
    border-radius: var(--borderRadiusXLarge, 12px);
    border-top: var(--strokeWidthThicker, 3px) solid var(--omenCardRule);
    box-shadow: var(--shadow16);
}

fluent-button:not([appearance="subtle"]):not([appearance="transparent"]),
fluent-anchor-button:not([appearance="subtle"]):not([appearance="transparent"]) {
    box-shadow: var(--shadow4);
    border-radius: var(--borderRadiusMedium, 4px);
    transition: box-shadow 0.1s ease-out, scale 0.1s ease-out;
}

    fluent-button:not([appearance="subtle"]):not([appearance="transparent"]):hover,
    fluent-anchor-button:not([appearance="subtle"]):not([appearance="transparent"]):hover {
        box-shadow: var(--shadow8);
    }

/* A press sinks the button a touch, so a click registers before whatever it starts has finished. Every button eases,
   subtle ones included; the lifted buttons above repeat scale in their own transition list. */
fluent-button,
fluent-anchor-button {
    transition: scale 0.1s ease-out;
}

fluent-button:active,
fluent-anchor-button:active {
    scale: 0.97;
}

/* Windows high contrast: shadows are invisible there, and system colours replace the brand rule. */
@media (forced-colors: active) {
    .omen-surface,
    fluent-button,
    fluent-anchor-button {
        box-shadow: none;
    }

    .omen-surface {
        border-top-color: CanvasText;
    }
}

/* Dark scheme: brand text and outlined/subtle button labels land on the #292929 card surface, where the
   site's #ae66aa is only 3.7:1, below the 4.5:1 WCAG AA needs for text. #c288bd is 5.2:1 on cards and
   6.6:1 on the canvas; hover and pressed go lighter still, so no state drops below AA. The 3px card rule
   keeps #ae66aa: it is a non-text boundary, where 3:1 is the bar. */
@media (prefers-color-scheme: dark) {
    :root {
        --colorBrandForeground1: #c288bd;
        --colorBrandForeground2: #d6add2;
        --colorBrandForegroundLink: #c288bd;
        --colorBrandForegroundLinkHover: #d6add2;
        --colorBrandForegroundLinkPressed: #cc9bc8;
        --colorBrandForegroundLinkSelected: #c288bd;
        --colorCompoundBrandForeground1: #c288bd;
        --colorCompoundBrandForeground1Hover: #d6add2;
        --colorCompoundBrandForeground1Pressed: #cc9bc8;
        --colorCompoundBrandStroke: #c288bd;
        --colorCompoundBrandStrokeHover: #d6add2;
        --colorCompoundBrandStrokePressed: #cc9bc8;
        --omenCardRule: #ae66aa;
        --omenAccentTealText: #5eead4;
        --omenAccentAmberText: #fcd34d;
        --omenAccentBlueText: #93c5fd;
        --omenAccentRoseText: #f9a8d4;
    }

    /* `html body`, not `body`: Fluent's theme arrives through adoptedStyleSheets, which cascade after every
       linked sheet, so only higher specificity wins. Dark scheme only, or light mode would get near-black
       text on this near-black canvas. */
    html body {
        background-color: #141414;
    }
}

/* Page entrance. Each top-level block of a page rises in a beat after the one before; a route change renders the
   new page's elements fresh, so this replays on every navigation. Only the start state is filled (backwards):
   nothing keeps a translate after landing, which would break the setup preview's position: sticky. */
.content > * {
    animation: omen-rise 0.4s cubic-bezier(0.2, 0, 0, 1) backwards;
}

.content > :nth-child(2) {
    animation-delay: 60ms;
}

.content > :nth-child(3) {
    animation-delay: 120ms;
}

.content > :nth-child(4) {
    animation-delay: 180ms;
}

.content > :nth-child(n + 5) {
    animation-delay: 240ms;
}

/* Status bars fade in as they appear, e.g. the Twitch link panel moving from code to linked. */
fluent-message-bar {
    animation: omen-fade 0.25s ease-out backwards;
}

@keyframes omen-rise {
    from {
        opacity: 0;
        translate: 0 0.75rem;
    }
}

@keyframes omen-fade {
    from {
        opacity: 0;
    }
}

/* FocusOnNavigate focuses the h1 after each navigation for screen readers; the heading is still focused
   and announced, it just does not flash a ring at sighted users on every route change. */
h1:focus {
    outline: none;
}

code {
    color: var(--colorBrandForeground1);
}

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

    #blazor-error-ui .dismiss {
        cursor: pointer;
        position: absolute;
        right: 0.75rem;
        top: 0.5rem;
    }

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred.";
    }

/* The app's crow while the app downloads, full colour on a transparent background so it reads on light and dark
   pages. A speech bubble keeps popping out just above its beak: Fluent UI's Chat 24 icon (the Blazor icon components
   are not loaded yet, so its paths are inlined), the Filled shape in white under the Regular outline in black. */
.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
    background: url("../art/branding/corvus-communico.webp") center / contain no-repeat;
    /* A slight shake from the feet; the bubble is a pseudo-element of this box, so it shakes along. */
    transform-origin: 50% 90%;
    animation: loading-shake 0.8s ease-in-out infinite;
}

@keyframes loading-shake {
    0%, 100% {
        rotate: 0deg;
    }

    25% {
        rotate: -3deg;
    }

    75% {
        rotate: 3deg;
    }
}

    .loading-progress::after {
        content: "";
        position: absolute;
        left: 6.9rem;
        top: -0.9rem;
        width: 2.75rem;
        height: 2.75rem;
        background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22C10.3596 22 8.77516 21.6039 7.35578 20.8583L3.06538 21.9753C2.6111 22.0937 2.1469 21.8213 2.02858 21.367C1.99199 21.2266 1.99198 21.0791 2.02855 20.9386L3.1449 16.6502C2.3972 15.2294 2 13.6428 2 12C2 6.47715 6.47715 2 12 2Z'/%3E%3Cpath fill='black' d='M12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22C10.3817 22 8.81782 21.6146 7.41286 20.888L3.58704 21.9553C2.92212 22.141 2.23258 21.7525 2.04691 21.0876C1.98546 20.8676 1.98549 20.6349 2.04695 20.4151L3.11461 16.5922C2.38637 15.186 2 13.6203 2 12C2 6.47715 6.47715 2 12 2ZM12 3.5C7.30558 3.5 3.5 7.30558 3.5 12C3.5 13.4696 3.87277 14.8834 4.57303 16.1375L4.72368 16.4072L3.61096 20.3914L7.59755 19.2792L7.86709 19.4295C9.12006 20.1281 10.5322 20.5 12 20.5C16.6944 20.5 20.5 16.6944 20.5 12C20.5 7.30558 16.6944 3.5 12 3.5ZM8.75 13H13.2483C13.6625 13 13.9983 13.3358 13.9983 13.75C13.9983 14.1297 13.7161 14.4435 13.35 14.4932L13.2483 14.5H8.75C8.33579 14.5 8 14.1642 8 13.75C8 13.3703 8.28215 13.0565 8.64823 13.0068L8.75 13H13.2483H8.75ZM8.75 9.5H15.2545C15.6687 9.5 16.0045 9.83579 16.0045 10.25C16.0045 10.6297 15.7223 10.9435 15.3563 10.9932L15.2545 11H8.75C8.33579 11 8 10.6642 8 10.25C8 9.8703 8.28215 9.55651 8.64823 9.50685L8.75 9.5H15.2545H8.75Z'/%3E%3C/svg%3E") center / contain no-repeat;
        /* The icon's tail is its bottom-left corner, so it grows out of the beak from there. */
        transform-origin: bottom left;
        animation: loading-chat 1.8s ease-out infinite;
    }

@keyframes loading-chat {
    0% {
        scale: 0;
        opacity: 0;
    }

    25% {
        scale: 1.1;
        opacity: 1;
    }

    35%, 75% {
        scale: 1;
        opacity: 1;
        translate: 0 0;
    }

    100% {
        scale: 1;
        opacity: 0;
        translate: 0 -0.75rem;
    }
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 9rem) 0 auto 0;
}

    .loading-progress-text:after {
        content: var(--blazor-load-percentage-text, "Loading");
    }

@media (prefers-reduced-motion: reduce) {
    fluent-button,
    fluent-anchor-button {
        transition: none;
    }

    fluent-button:active,
    fluent-anchor-button:active {
        scale: none;
    }

    .content > *,
    fluent-message-bar {
        animation: none;
    }

    /* The crow and its chat bubble hold still; the percentage text still shows progress. */
    .loading-progress,
    .loading-progress::after {
        animation: none;
    }
}

/* ---- Overlay output (/overlay, and the setup page's preview) ----
   The classes and data-* attributes here are the overlay's public surface: users restyle it with OBS
   custom CSS, so rename none of them. Settings arrive as custom properties on .chat. */
html:has(.overlay-root),
body:has(.overlay-root) {
    background: transparent !important;
    overflow: hidden;
}

.overlay-root {
    height: 100vh;
}

.chat {
    --chat-slide-from: -1em;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-start;
    gap: 0.35em;
    height: 100%;
    margin: 0;
    padding: 0.5em;
    list-style: none;
    overflow: hidden;
    font-family: var(--chat-font-family, "Segoe UI", system-ui, sans-serif);
    font-size: var(--chat-font-size, 20px);
    line-height: 1.4;
    color: var(--chat-text, #ffffff);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.chat[data-direction="top"] {
    justify-content: flex-start;
}

.chat[data-align="right"] {
    --chat-slide-from: 1em;
    align-items: flex-end;
    text-align: right;
}

.chat-message {
    flex-shrink: 0;
    max-width: 100%;
    padding: 0.2em 0.6em;
    border-radius: 0.5em;
    background: var(--chat-background, transparent);
    overflow-wrap: anywhere;
    transform-origin: left center;
    /* One animation list with a slot per effect, so an entrance, a pop, a shake and an exit can all apply
       to one message. Each slot is "none" until a rule below fills it. Pop animates scale and shake
       animates translate, separate from the entrance's transform, so they never fight over a property. */
    --chat-enter: none;
    --chat-pop: none;
    --chat-shake: none;
    --chat-exit: none;
    animation: var(--chat-enter), var(--chat-pop), var(--chat-shake), var(--chat-exit);
}

.chat[data-align="right"] .chat-message {
    transform-origin: right center;
}

/* Staggered: odd messages (by arrival, fixed per message) sit on the right. */
.chat[data-align="staggered"] .chat-message[data-parity="odd"] {
    align-self: flex-end;
    text-align: right;
    transform-origin: right center;
}

/* Entry side for the Slide entrance. Auto slides in from the side a message sits on: the alignment's side
   (set on .chat above), or each message's own side when staggered. */
.chat[data-align="staggered"][data-entry="auto"] .chat-message[data-parity="odd"],
.chat[data-entry="right"] .chat-message,
.chat[data-entry="alternating"] .chat-message[data-parity="odd"] {
    --chat-slide-from: 1em;
}

.chat[data-entry="left"] .chat-message,
.chat[data-entry="alternating"] .chat-message[data-parity="even"] {
    --chat-slide-from: -1em;
}

/* Zebra stripes: odd messages take the stripe colour (already at the background opacity). Only the colour,
   so a theme's background images (sheen, grain, vignette) stay on striped messages too. */
.chat[data-stripes] .chat-message[data-parity="odd"] {
    background-color: var(--chat-stripe, var(--chat-background, transparent));
}

/* Borders. A message's own --chat-border-color (the chatter's name colour) overrides the overlay's. */
.chat[data-border="solid"] .chat-message {
    border: var(--chat-border-width, 2px) solid var(--chat-border-color, #ffffff);
}

.chat[data-border="dashed"] .chat-message {
    border: var(--chat-border-width, 2px) dashed var(--chat-border-color, #ffffff);
}

/* Depth: a tight shadow for the edge and a wide one for lift, so messages stand off busy gameplay or a
   transparent scene. The overlay's padding grows with depth so .chat's overflow clip spares the shadow. */
.chat[data-shadow="soft"] .chat-message {
    box-shadow: 0 1px 2px var(--chat-shadow-near), 0 2px 6px var(--chat-shadow-far);
}

.chat[data-shadow="medium"] {
    padding: 0.75em;
}

.chat[data-shadow="medium"] .chat-message {
    box-shadow: 0 2px 4px var(--chat-shadow-near), 0 6px 14px var(--chat-shadow-far);
}

.chat[data-shadow="deep"] {
    padding: 1em;
}

.chat[data-shadow="deep"] .chat-message {
    box-shadow: 0 4px 8px var(--chat-shadow-near), 0 12px 28px var(--chat-shadow-far);
}

/* ---- Preset themes (data-theme) ----
   A preset fills in the settings above; these rules add what settings cannot express. They sit after the
   settings rules so that, where both set the same property at equal specificity, the theme wins. */

/* Frosted Glass. An OBS browser source cannot blur the game beneath it (backdrop-filter only sees this
   page), so the glass is a look-alike: a top highlight, a diagonal sheen and a faint grain over the milky
   fill, ringed by a soft bright edge. The grain is an inline SVG (CSP allows data: images). The text is
   dark, so its shadow is a light emboss instead of the default dark drop shadow. */
.chat[data-theme="frosted"] {
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}

.chat[data-theme="frosted"] .chat-message {
    background-image:
        linear-gradient(to bottom, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.55) 1px, transparent 1px),
        linear-gradient(135deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 55%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.14'/%3E%3C/svg%3E");
    outline: 1px solid rgba(255, 255, 255, 0.35);
    outline-offset: -1px;
}

/* Ansi Code: square terminal lines with a green prompt, bracketed clock and a blinking block cursor on
   the newest line. Name colours are snapped to the ANSI palette in OverlayStyle.NameColor. */
.chat[data-theme="ansi"] {
    text-shadow: none;
}

.chat[data-theme="ansi"] .chat-message {
    border-radius: 0;
}

.chat[data-theme="ansi"] .chat-message::before {
    content: ">";
    margin-inline-end: 0.5em;
    color: #23d18b;
}

.chat[data-theme="ansi"] .chat-time {
    color: #808080;
    opacity: 1;
}

.chat[data-theme="ansi"] .chat-time::before {
    content: "[";
}

.chat[data-theme="ansi"] .chat-time::after {
    content: "]";
}

.chat[data-theme="ansi"][data-direction="bottom"] .chat-message:not([data-leaving]):last-child .chat-text::after,
.chat[data-theme="ansi"][data-direction="top"] .chat-message:not([data-leaving]):first-child .chat-text::after {
    content: "\2588";
    margin-inline-start: 0.15em;
    animation: chat-blink 1s steps(1) infinite;
}

@keyframes chat-blink {
    50% {
        opacity: 0;
    }
}

/* Pixel Art, after snes.css: square panels in a stepped white frame with a dark outer line and notched
   corners, all drawn with hard box-shadows, plus a hard pixel text shadow. The frame replaces the Depth
   setting's shadow; the extra gap and padding keep frames from touching or being clipped. */
.chat[data-theme="pixel"] {
    gap: 1.1em;
    padding: 1em;
    line-height: 1.7;
    text-shadow: 2px 2px 0 #000000;
}

.chat[data-theme="pixel"] .chat-message {
    margin: 4px;
    border-radius: 0;
    background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.18));
    box-shadow:
        0 -4px 0 #ffffff, 0 4px 0 #ffffff, -4px 0 0 #ffffff, 4px 0 0 #ffffff,
        -4px -4px 0 #0a0f30, 4px -4px 0 #0a0f30, -4px 4px 0 #0a0f30, 4px 4px 0 #0a0f30,
        0 -8px 0 #0a0f30, 0 8px 0 #0a0f30, -8px 0 0 #0a0f30, 8px 0 0 #0a0f30;
}

.chat[data-theme="pixel"] img {
    image-rendering: pixelated;
}

/* Blood Moon: a dark vignette inside each panel and a blood-red glow on the gothic names. */
.chat[data-theme="bloodmoon"] .chat-message {
    background-image: radial-gradient(120% 140% at 50% 0%, transparent 55%, rgba(0, 0, 0, 0.4));
}

.chat[data-theme="bloodmoon"] .chat-name {
    letter-spacing: 0.02em;
    text-shadow: 0 0 6px rgba(190, 20, 30, 0.65), 0 1px 2px #000000;
}

/* Headache: a light theme, so no dark text shadow (names are darkened in OverlayStyle.NameColor), and a
   hairline edge so white panels hold their shape over bright scenes. */
.chat[data-theme="headache"] {
    text-shadow: none;
}

.chat[data-theme="headache"] .chat-message {
    outline: 1px solid rgba(0, 0, 0, 0.08);
    outline-offset: -1px;
}

.chat[data-animation="slide"] .chat-message {
    --chat-enter: chat-slide 0.3s ease-out;
}

.chat[data-animation="fade"] .chat-message {
    --chat-enter: chat-fade 0.4s ease-out;
}

/* Typewriter: the name shows at once and the text is uncovered left to right, one step per character.
   OverlayChat sets the step count and duration per message.
   shortcut: a wrapped message is uncovered column by column across all its lines at once; typing line
   by line needs a span per character, too heavy for OBS. Revisit if long messages look wrong. */
.chat[data-animation="typewriter"] .chat-text {
    animation: chat-type var(--chat-type-time, 0.6s) steps(var(--chat-type-steps, 20)) both;
}

/* Cheers pop once, after the entrance; keywords shake once. */
.chat-message[data-effect~="pop"] {
    --chat-pop: chat-pop 0.5s 0.15s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.chat-message[data-effect~="shake"] {
    --chat-shake: chat-shake 0.6s 0.3s ease-in-out both;
}

/* Exits play while OverlayChat keeps a leaving message for MessageExits.Duration (1s), so keep them shorter. */
.chat-message[data-leaving="fade"] {
    --chat-exit: chat-fade-out 0.5s ease-in forwards;
}

/* Dissolve: a soft-edged sweep erases the message from its end while a fine checker of "pixels"
   lingers behind it, and the remains blur, drift up and fade like dust. */
.chat-message[data-leaving="dissolve"] {
    --chat-exit: chat-dissolve 0.9s ease-in forwards;
    -webkit-mask-image: linear-gradient(90deg, #000 40%, transparent 60%), repeating-conic-gradient(#000 0 25%, transparent 0 50%);
    mask-image: linear-gradient(90deg, #000 40%, transparent 60%), repeating-conic-gradient(#000 0 25%, transparent 0 50%);
    -webkit-mask-size: 250% 100%, 0.25em 0.25em;
    mask-size: 250% 100%, 0.25em 0.25em;
    -webkit-mask-repeat: no-repeat, repeat;
    mask-repeat: no-repeat, repeat;
}

@keyframes chat-slide {
    from {
        opacity: 0;
        transform: translateX(var(--chat-slide-from));
    }
}

@keyframes chat-fade {
    from {
        opacity: 0;
    }
}

@keyframes chat-type {
    from {
        clip-path: inset(0 100% 0 0);
    }

    to {
        clip-path: inset(0);
    }
}

@keyframes chat-pop {
    0%,
    100% {
        scale: 1;
    }

    40% {
        scale: 1.12;
    }
}

@keyframes chat-shake {
    0%,
    100% {
        translate: 0;
    }

    15% {
        translate: -0.25em;
    }

    30% {
        translate: 0.25em;
    }

    45% {
        translate: -0.18em;
    }

    60% {
        translate: 0.18em;
    }

    75% {
        translate: -0.08em;
    }
}

@keyframes chat-fade-out {
    to {
        opacity: 0;
    }
}

@keyframes chat-dissolve {
    0% {
        -webkit-mask-position: 0% 0, 0 0;
        mask-position: 0% 0, 0 0;
    }

    55% {
        opacity: 1;
        filter: blur(0);
    }

    100% {
        -webkit-mask-position: 100% 0, 0 0;
        mask-position: 100% 0, 0 0;
        opacity: 0;
        filter: blur(3px);
        translate: 0 -0.5em;
    }
}

.chat-time {
    margin-inline-end: 0.4em;
    font-size: 0.8em;
    opacity: 0.75;
}

.chat-badge {
    height: 1.1em;
    margin-inline-end: 0.2em;
    vertical-align: middle;
}

.chat-pronouns {
    margin-inline-end: 0.3em;
    padding: 0 0.35em;
    border-radius: 0.3em;
    background: rgb(255 255 255 / 0.15);
    font-size: 0.75em;
    vertical-align: middle;
}

.chat-name {
    font-family: var(--chat-name-font-family, inherit);
    font-weight: 700;
}

.chat-colon {
    margin-inline-end: 0.3em;
}

.chat-emote {
    height: 1.6em;
    margin: -0.3em 0.1em;
    vertical-align: middle;
}

/* Zero-width emotes (7TV, BetterTTV, FrankerFaceZ, or BetterTTV's z!) over the emote before them: every image
   sits in one grid cell, centred, so the stack is as wide as its widest image. */
.chat-emote-stack {
    display: inline-grid;
    place-items: center;
    margin: -0.3em 0.1em;
    vertical-align: middle;
}

.chat-emote-stack > .chat-emote,
.chat-emote-stack > .chat-emote-wide {
    grid-area: 1 / 1;
    margin: 0;
}

/* Wide (BetterTTV w!, FrankerFaceZ ffzW): the hidden copy sizes the first column, the two columns are equal, and
   the emote spans both, so it is stretched to exactly double its own width whatever its shape. */
.chat-emote-wide {
    display: inline-grid;
    grid-template-columns: 1fr 1fr;
    margin: -0.3em 0.1em;
    vertical-align: middle;
}

.chat-emote-wide > .chat-emote {
    grid-area: 1 / 1;
    margin: 0;
}

.chat-emote-wide > .chat-emote:first-child {
    grid-column: 1 / 3;
    width: 100%;
}

.chat-emote-wide > .chat-emote:last-child {
    visibility: hidden;
}

/* Emote effects from BetterTTV modifier words and FrankerFaceZ effect emotes (EmoteModifiers). Each kind owns one
   property (flips scale, turns rotate, movement translate, colour filter, reveals clip-path) and the animations
   are listed through variables, so several effects combine on one emote. */
.chat-emote[data-modifiers] {
    filter: var(--chat-emote-cursed,) var(--chat-emote-hyper,);
    animation: var(--chat-emote-spin, none), var(--chat-emote-move, none), var(--chat-emote-rainbow, none),
        var(--chat-emote-reveal, none);
}

/* "Gigantify an Emote" Power-up, bought with bits: three times the size, sitting on the text's baseline. */
.chat-emote[data-modifiers~="giant"] {
    height: 4.8em;
    margin-block: 0.1em;
    vertical-align: bottom;
}

.chat-emote[data-modifiers~="flip-x"] {
    scale: -1 1;
}

.chat-emote[data-modifiers~="flip-y"] {
    scale: 1 -1;
}

.chat-emote[data-modifiers~="flip-x"][data-modifiers~="flip-y"] {
    scale: -1 -1;
}

.chat-emote[data-modifiers~="rotate-left"] {
    rotate: -90deg;
}

.chat-emote[data-modifiers~="rotate-right"] {
    rotate: 90deg;
}

.chat-emote[data-modifiers~="cursed"] {
    --chat-emote-cursed: grayscale(1) brightness(0.7) contrast(2.5);
}

.chat-emote[data-modifiers~="hyper-red"] {
    --chat-emote-hyper: brightness(0.2) sepia(1) brightness(2.2) contrast(3) saturate(8);
}

.chat-emote[data-modifiers~="rainbow"] {
    --chat-emote-rainbow: chat-emote-rainbow 2s linear infinite;
}

.chat-emote[data-modifiers~="spin"] {
    --chat-emote-spin: chat-emote-spin 1.5s linear infinite;
}

/* shake, jam and bounce all move the emote; when an emote has several, the last listed here wins. */
.chat-emote[data-modifiers~="shake"] {
    --chat-emote-move: chat-emote-shake 0.1s linear infinite;
}

.chat-emote[data-modifiers~="jam"] {
    --chat-emote-move: chat-emote-jam 0.6s linear infinite;
}

.chat-emote[data-modifiers~="bounce"] {
    --chat-emote-move: chat-emote-bounce 0.5s ease-in-out infinite alternate;
}

.chat-emote[data-modifiers~="appear"] {
    --chat-emote-reveal: chat-emote-appear 3s linear infinite;
}

.chat-emote[data-modifiers~="leave"] {
    --chat-emote-reveal: chat-emote-leave 3s linear infinite;
}

/* shortcut: FrankerFaceZ scrolls a repeating background; this slides the image through its box once per loop,
   with offsets that clear emotes up to 5em wide. */
.chat-emote[data-modifiers~="slide"] {
    --chat-emote-reveal: chat-emote-slide 2s linear infinite;
}

@keyframes chat-emote-rainbow {
    from {
        filter: var(--chat-emote-cursed,) var(--chat-emote-hyper,) hue-rotate(0deg);
    }

    to {
        filter: var(--chat-emote-cursed,) var(--chat-emote-hyper,) hue-rotate(360deg);
    }
}

@keyframes chat-emote-spin {
    from {
        rotate: 0deg;
    }

    to {
        rotate: 360deg;
    }
}

@keyframes chat-emote-shake {
    0%,
    100% {
        translate: 1px 1px;
    }

    25% {
        translate: -1px -2px;
    }

    50% {
        translate: -2px 0;
    }

    75% {
        translate: 2px -1px;
    }
}

@keyframes chat-emote-jam {
    0%,
    100% {
        translate: 0;
        rotate: 0deg;
    }

    25% {
        translate: -2px -2px;
        rotate: -6deg;
    }

    75% {
        translate: 2px -2px;
        rotate: 6deg;
    }
}

@keyframes chat-emote-bounce {
    from {
        translate: 0;
    }

    to {
        translate: 0 -0.25em;
    }
}

@keyframes chat-emote-appear {
    from {
        clip-path: inset(0 100% 0 0);
    }

    to {
        clip-path: inset(0);
    }
}

@keyframes chat-emote-leave {
    from {
        clip-path: inset(0);
    }

    to {
        clip-path: inset(0 0 0 100%);
    }
}

@keyframes chat-emote-slide {
    from {
        object-position: 5em 50%;
    }

    to {
        object-position: -5em 50%;
    }
}

/* GIPHY GIFs posted in chat by Tier 2 and 3 subscribers: on a line of their own, capped so one GIF cannot fill
   the overlay. */
.chat-gif {
    display: block;
    max-width: 100%;
    max-height: 8em;
    margin-block: 0.25em;
    border-radius: 0.25em;
}

/* Cheermotes: the tier colour is set inline by OverlayChat (adjusted for WCAG AA contrast); data-tier
   stays as a hook for OBS custom CSS. */
.chat-cheer {
    font-weight: 700;
}

/* Twitch's cheermote image, sized like an emote; the bit amount follows in .chat-cheer. */
.chat-cheermote {
    height: 1.6em;
    margin: -0.3em 0.1em;
    vertical-align: middle;
}

/* "Highlight my message" channel-point redemptions: a bar in the text colour along the start edge. A
   pseudo-element, so the message's fill, theme images, border and depth stay as they are, and text contrast is
   unchanged; the bar itself is the AA-checked text colour. ::before belongs to the ANSI theme's prompt. */
.chat-message[data-highlight] {
    position: relative;
}

.chat-message[data-highlight]::after {
    content: "";
    position: absolute;
    inset-block: 0.25em;
    inset-inline-start: 0.15em;
    width: 0.2em;
    border-radius: 0.1em;
    background: currentColor;
}

/* Reduced motion on the PC drawing the overlay: no effects, and leaving messages vanish at once. */
@media (prefers-reduced-motion: reduce) {
    .chat-message,
    .chat-text,
    .chat-text::after,
    .chat-emote {
        animation: none !important;
    }

    .chat-message[data-leaving] {
        visibility: hidden;
    }
}
