/* ==========================================================================
   Project Animation Demos
   Shared by the public site and the sandboxed admin preview.
   ========================================================================== */

.demo {
    position: relative;
    width: 100%;
    border: 1px solid var(--ln);
    border-radius: 16px;
    background: linear-gradient(160deg, var(--sf), var(--card-g2));
    overflow: hidden;
    isolation: isolate;
}

.demo-stage {
    position: relative;
    width: 100%;
    min-height: 240px;
    padding: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tx);
}

.demo--hero .demo-stage {
    min-height: 360px;
    padding: 24px;
}

.demo--card {
    height: 100%;
    border: 0;
    border-radius: 0;
    background: transparent;
}

.demo--card .demo-stage {
    height: 100%;
    min-height: 100%;
    padding: 10px;
}

.demo-frame {
    display: block;
    width: 100%;
    min-height: 240px;
    border: 0;
    background: transparent;
}

.demo--hero .demo-frame {
    min-height: 360px;
}

.demo--card .demo-frame {
    height: 100%;
    min-height: 100%;
}

/* --------------------------------------------------------------------------
   Pipeline
   -------------------------------------------------------------------------- */
.demo-pipeline {
    flex-direction: column;
    gap: 8px;
}

.demo-pipeline .demo-svg {
    display: block;
    width: 100%;
    max-width: 440px;
    height: auto;
}

.demo-dash {
    stroke-dasharray: 6 8;
    animation: demo-dash 1.2s linear infinite;
    animation-play-state: paused;
}

.demo.is-running .demo-dash {
    animation-play-state: running;
}

@keyframes demo-dash {
    to { stroke-dashoffset: -28; }
}

.demo-pulse {
    transform-box: fill-box;
    transform-origin: center;
    animation: demo-pulse 2.4s ease-in-out infinite;
    animation-play-state: paused;
}

.demo.is-running .demo-pulse {
    animation-play-state: running;
}

@keyframes demo-pulse {
    50% { transform: scale(1.12); }
}

.demo-caption {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    max-width: 440px;
    padding: 0 4px;
    color: var(--mu);
    font-size: 0.8rem;
}

.demo-caption b {
    color: var(--demo-accent, var(--mi));
}

/* --------------------------------------------------------------------------
   Counter
   -------------------------------------------------------------------------- */
.demo-counter {
    flex-direction: column;
    gap: 10px;
    text-align: center;
}

.demo-counter-value {
    font: 800 clamp(2.8rem, 9vw, 4.6rem) / 1 var(--fd);
    letter-spacing: -0.04em;
    color: var(--demo-accent, var(--am));
    font-variant-numeric: tabular-nums;
}

.demo-counter-label {
    color: var(--mu);
    font-size: 0.95rem;
}

.demo-meter {
    width: min(280px, 80%);
    height: 8px;
    margin-top: 8px;
    border-radius: 99px;
    background: var(--ln);
    overflow: hidden;
}

.demo-meter span {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--vi), var(--demo-accent, var(--am)));
    transform: scaleX(0.72);
    transform-origin: left;
}

.demo.is-running .demo-meter span {
    animation: demo-meter 2.6s ease-in-out infinite alternate;
}

@keyframes demo-meter {
    from { transform: scaleX(0.35); }
    to { transform: scaleX(1); }
}

/* --------------------------------------------------------------------------
   Log feed
   -------------------------------------------------------------------------- */
.demo-logfeed {
    display: block;
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
    padding: 18px;
    border: 1px solid var(--ln);
    border-radius: 16px;
    background: rgb(var(--bg-rgb) / 0.5);
}

.demo-log-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    color: var(--mu);
    font-size: 0.78rem;
    font-weight: 600;
}

.demo-live-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--demo-accent, var(--mi));
    box-shadow: 0 0 0 0 rgb(var(--mi-rgb) / 0.7);
    animation: demo-ping 1.8s infinite;
}

@keyframes demo-ping {
    to { box-shadow: 0 0 0 10px transparent; }
}

.demo-logfeed ul {
    display: grid;
    gap: 6px;
    min-height: 130px;
    margin: 0;
    padding: 0;
    list-style: none;
    align-content: start;
}

.demo-logfeed li {
    overflow: hidden;
    color: var(--demo-accent, var(--mi));
    font-size: 0.84rem;
    white-space: nowrap;
    text-overflow: ellipsis;
    opacity: 1;
}

.demo.is-running .demo-logfeed li {
    animation-name: demo-log-cycle;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

@keyframes demo-log-cycle {
    0%, 6% { opacity: 0; transform: translateY(8px); }
    12%, 88% { opacity: 1; transform: none; }
    96%, 100% { opacity: 0; transform: translateY(-8px); }
}

/* --------------------------------------------------------------------------
   Dashboard
   -------------------------------------------------------------------------- */
.demo-dashboard {
    display: block;
    padding: 16px;
}

.demo-browser {
    width: 100%;
    max-width: 460px;
    margin: 0 auto;
    border: 1px solid var(--ln);
    border-radius: 16px;
    background: var(--sf);
    overflow: hidden;
}

.demo-browser-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--ln);
    background: rgb(var(--bg-rgb) / 0.45);
}

.demo-browser-bar span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ln);
}

.demo-browser-bar span:first-child { background: var(--ro); }
.demo-browser-bar span:nth-child(2) { background: var(--am); }
.demo-browser-bar span:nth-child(3) { background: var(--mi); }

.demo-browser-bar b {
    margin-left: auto;
    color: var(--mu);
    font-size: 0.72rem;
    font-weight: 600;
}

.demo-dash-body {
    padding: 18px;
}

.demo-dash-metric small {
    display: block;
    color: var(--mu);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.demo-dash-metric strong {
    display: inline-block;
    margin: 4px 8px 0 0;
    color: var(--demo-accent, var(--vi));
    font: 800 2rem var(--fd);
}

.demo-dash-metric em {
    color: var(--mi);
    font-size: 0.72rem;
    font-style: normal;
    font-weight: 700;
}

.demo-dash-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 14px 0;
}

.demo-dash-card {
    padding: 10px;
    border: 1px solid var(--ln);
    border-radius: 10px;
    background: rgb(var(--bg-rgb) / 0.45);
}

.demo-dash-card small {
    display: block;
    margin-bottom: 4px;
    color: var(--mu);
    font-size: 0.64rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.demo-dash-card b {
    color: var(--tx);
    font-size: 0.86rem;
}

.demo.is-running .demo-dash-card {
    animation: demo-fade-up 0.6s ease-out both;
    animation-delay: calc(var(--i) * 0.12s);
}

@keyframes demo-fade-up {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

.demo-bars {
    display: flex;
    align-items: flex-end;
    gap: 7px;
    height: 100px;
    padding-top: 10px;
    border-top: 1px solid var(--ln);
}

.demo-bar {
    display: flex;
    flex: 1;
    align-items: flex-end;
    height: 100%;
    border-radius: 6px;
    background: rgb(var(--vi-rgb) / 0.08);
}

.demo-bar i {
    display: block;
    width: 100%;
    height: calc(var(--v) * 1%);
    border-radius: 6px 6px 0 0;
    background: linear-gradient(180deg, var(--demo-accent, var(--vi)), rgb(var(--vi-rgb) / 0.15));
    transform-origin: bottom;
}

.demo.is-running .demo-bar i {
    animation: demo-bar-grow 1s ease-out both;
    animation-delay: calc(var(--i) * 0.1s);
}

@keyframes demo-bar-grow {
    from { height: 0; }
    to { height: calc(var(--v) * 1%); }
}

/* --------------------------------------------------------------------------
   Scraper
   -------------------------------------------------------------------------- */
.demo-scraper {
    display: grid;
    grid-template-columns: 1fr 80px auto;
    grid-template-rows: auto auto;
    gap: 12px;
    align-items: center;
    width: 100%;
    max-width: 460px;
    margin: 0 auto;
}

.demo-scraper-sources {
    display: grid;
    gap: 8px;
}

.demo-source {
    overflow: hidden;
    padding: 9px 12px;
    border: 1px solid var(--ln);
    border-radius: 9px;
    background: rgb(var(--bg-rgb) / 0.55);
    color: var(--mu);
    font-size: 0.74rem;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.demo-scraper-track {
    position: relative;
    height: 110px;
    overflow: hidden;
}

.demo-page {
    position: absolute;
    left: 0;
    top: 20px;
    width: 14px;
    height: 18px;
    border-radius: 3px;
    background: var(--demo-accent, var(--mi));
    opacity: 0.9;
}

.demo-page::before {
    content: "";
    position: absolute;
    left: 3px;
    top: 4px;
    width: 8px;
    height: 1px;
    background: rgb(var(--bg-rgb) / 0.6);
    box-shadow: 0 3px 0 rgb(var(--bg-rgb) / 0.6), 0 6px 0 rgb(var(--bg-rgb) / 0.6);
}

.demo.is-running .demo-page {
    animation: demo-fly 2.2s linear infinite;
    animation-delay: calc(var(--i) * 0.4s);
}

@keyframes demo-fly {
    0% { opacity: 0; transform: translate(0, 0) rotate(0); }
    15% { opacity: 1; }
    100% { opacity: 0.1; transform: translate(80px, 40px) rotate(24deg); }
}

.demo-db {
    display: grid;
    justify-items: center;
    gap: 4px;
    padding: 14px 12px;
    border: 1px solid var(--demo-accent, var(--mi));
    border-radius: 12px;
    background: var(--sf);
    color: var(--demo-accent, var(--mi));
    font-size: 0.74rem;
    font-weight: 700;
    text-align: center;
}

.demo-db svg {
    width: 26px;
    height: 26px;
}

.demo-scraper-total {
    grid-column: 1 / -1;
    color: var(--mu);
    font-size: 0.8rem;
    text-align: center;
}

.demo-scraper-total b {
    margin-right: 4px;
    color: var(--demo-accent, var(--am));
    font: 800 1.4rem var(--fd);
}

/* --------------------------------------------------------------------------
   Inbox
   -------------------------------------------------------------------------- */
.demo-inbox {
    display: block;
    width: 100%;
    max-width: 380px;
    margin: 0 auto;
    padding: 16px;
    border: 1px solid var(--ln);
    border-radius: 16px;
    background: rgb(var(--bg-rgb) / 0.45);
}

.demo-inbox-head {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    color: var(--mu);
    font-size: 0.8rem;
    font-weight: 600;
}

.demo-inbox-head b {
    color: var(--demo-accent, var(--vi));
}

.demo-inbox ul {
    display: grid;
    gap: 8px;
    min-height: 190px;
    margin: 0;
    padding: 0;
    list-style: none;
    align-content: start;
}

.demo-mail {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--ln);
    border-radius: 10px;
    background: var(--sf);
    overflow: hidden;
}

.demo-mail-avatar {
    display: grid;
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    place-items: center;
    border-radius: 50%;
    background: rgb(var(--vi-rgb) / 0.2);
    color: var(--vi);
    font-size: 0.68rem;
    font-weight: 700;
}

.demo-mail-subject {
    flex: 1;
    overflow: hidden;
    color: var(--tx);
    font-size: 0.76rem;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.demo-mail-tag {
    padding: 2px 7px;
    border-radius: 99px;
    background: rgb(var(--am-rgb) / 0.15);
    color: var(--am);
    font-size: 0.6rem;
    white-space: nowrap;
}

.demo-mail-done {
    color: var(--mi);
    font-size: 0.6rem;
    font-weight: 700;
    white-space: nowrap;
}

.demo.is-running .demo-mail {
    animation: demo-mail-cycle var(--dur) linear infinite;
    animation-delay: var(--delay);
}

.demo.is-running .demo-mail-tag {
    animation: demo-tag-cycle var(--dur) linear infinite;
    animation-delay: calc(var(--delay) + 0.4s);
}

.demo.is-running .demo-mail-done {
    animation: demo-done-cycle var(--dur) linear infinite;
    animation-delay: calc(var(--delay) + 0.8s);
}

@keyframes demo-mail-cycle {
    0%, 5% { opacity: 0; transform: translateX(-18px); }
    12%, 86% { opacity: 1; transform: none; }
    96%, 100% { opacity: 0; transform: translateX(18px); }
}

@keyframes demo-tag-cycle {
    0%, 8% { opacity: 0; transform: scale(0.8); }
    14%, 86% { opacity: 1; transform: scale(1); }
    96%, 100% { opacity: 0; }
}

@keyframes demo-done-cycle {
    0%, 18% { opacity: 0; transform: translateX(-4px); }
    24%, 86% { opacity: 1; transform: none; }
    96%, 100% { opacity: 0; }
}

/* --------------------------------------------------------------------------
   Reduced motion: static first frame
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .demo .demo-anim,
    .demo .demo-dash,
    .demo .demo-pulse,
    .demo .demo-live-dot,
    .demo .demo-page,
    .demo .demo-mail,
    .demo .demo-mail-tag,
    .demo .demo-mail-done,
    .demo .demo-meter span,
    .demo .demo-bar i,
    .demo .demo-dash-card {
        animation: none !important;
    }
}

@media (max-width: 560px) {
    .demo-dash-cards {
        grid-template-columns: 1fr;
    }

    .demo-scraper {
        grid-template-columns: 1fr auto;
    }

    .demo-scraper-track {
        display: none;
    }

    .demo--hero .demo-stage,
    .demo--hero .demo-frame {
        min-height: 300px;
    }
}

/* --------------------------------------------------------------------------
   Project card preview
   -------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------
   Project card preview
   -------------------------------------------------------------------------- */
.pj .pimg {
    position: relative;
}

.pj-demo-wrap {
    position: absolute;
    inset: 0;
    z-index: 2;
    background: var(--bg);
    opacity: 1;
    pointer-events: none;
    transition: opacity 0.35s ease;
}

.pj-demo-wrap .demo {
    height: 100%;
}

.pj-demo-wrap .demo {
    visibility: visible;
}

.pj-demo-badge {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border: 1px solid rgb(var(--mi-rgb) / 0.35);
    border-radius: 99px;
    background: rgb(var(--bg-rgb) / 0.82);
    color: var(--mi);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.pj-demo-badge i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--mi);
    box-shadow: 0 0 0 0 rgb(var(--mi-rgb) / 0.7);
    animation: demo-ping 1.8s infinite;
}

/* --------------------------------------------------------------------------
   Animation blocks — <x-animation />
   The block reserves its own box from the animation's stored aspect ratio, so
   a card never shifts when the poster or the sandboxed frame arrives.
   -------------------------------------------------------------------------- */
.anim {
    position: relative;
}

.anim[data-demo-mode="manual"] {
    cursor: pointer;
}

.anim[data-demo-mode="manual"]:focus-visible {
    outline: 2px solid var(--vi);
    outline-offset: 3px;
}

.anim--fixed {
    aspect-ratio: var(--anim-ratio);
    min-height: 0;
}

.anim--fixed .demo-stage,
.anim--fixed .demo-frame {
    height: 100%;
    min-height: 0;
}

.anim-live {
    display: block;
    width: 100%;
    height: 100%;
}

.anim-poster {
    position: absolute;
    inset: 0;
    display: none;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
    background: var(--sf);
}

/* A one-shot animation stops at its final frame instead of repeating. */
.demo--once .demo-stage *,
.demo--once .demo-stage *::before,
.demo--once .demo-stage *::after,
.demo--once > .anim-live > .demo-frame {
    animation-iteration-count: 1;
}

@media (prefers-reduced-motion: reduce) {
    .anim--poster .anim-live {
        display: none;
    }

    .anim--poster .anim-poster {
        display: block;
    }
}
.pj-demo-wrap .demo {
    animation-play-state: running;
}

.pj-demo-wrap .demo-dash,
.pj-demo-wrap .demo-pulse,
.pj-demo-wrap .demo-meter span,
.pj-demo-wrap .demo-logfeed li,
.pj-demo-wrap .demo-dash-card,
.pj-demo-wrap .demo-bar i,
.pj-demo-wrap .demo-page,
.pj-demo-wrap .demo-mail,
.pj-demo-wrap .demo-mail-tag,
.pj-demo-wrap .demo-mail-done {
    animation-play-state: running;
}
/* --------------------------------------------------------------------------
   Automatic project card animations
   -------------------------------------------------------------------------- */

.pj-demo-wrap {
    opacity: 1;
    visibility: visible;
}

.pj-demo-wrap .demo {
    animation-play-state: running;
}

.pj-demo-wrap .demo-dash,
.pj-demo-wrap .demo-pulse {
    animation-play-state: running;
}

.pj-demo-wrap .demo-meter span {
    animation: demo-meter 2.6s ease-in-out infinite alternate;
}

.pj-demo-wrap .demo-logfeed li {
    animation: demo-log-cycle 5s linear infinite;
}

.pj-demo-wrap .demo-dash-card {
    animation: demo-fade-up 0.6s ease-out both;
    animation-delay: calc(var(--i) * 0.12s);
}

.pj-demo-wrap .demo-bar i {
    animation: demo-bar-grow 1s ease-out both;
    animation-delay: calc(var(--i) * 0.1s);
}

.pj-demo-wrap .demo-page {
    animation: demo-fly 2.2s linear infinite;
    animation-delay: calc(var(--i) * 0.4s);
}

.pj-demo-wrap .demo-mail {
    animation: demo-mail-cycle var(--dur, 5s) linear infinite;
    animation-delay: var(--delay, 0s);
}

.pj-demo-wrap .demo-mail-tag {
    animation: demo-tag-cycle var(--dur, 5s) linear infinite;
    animation-delay: calc(var(--delay, 0s) + 0.4s);
}

.pj-demo-wrap .demo-mail-done {
    animation: demo-done-cycle var(--dur, 5s) linear infinite;
    animation-delay: calc(var(--delay, 0s) + 0.8s);
}

@media (prefers-reduced-motion: reduce) {
    .pj-demo-wrap *,
    .pj-demo-wrap *::before,
    .pj-demo-wrap *::after {
        animation: none !important;
    }
}