/* ============================================================
   Effects CSS: Animations, transitions, visual effects
   ============================================================ */

/* ============================================================
   Phase 1 — Cinematic Hero
   ============================================================ */

/* Hero entrance stagger - content visible by default for SSR/No-JS */
.hero-stagger {
    opacity: 1;
    transform: translateY(0) scale(1);
    transition: opacity 0.55s var(--ease-out), transform 0.55s var(--ease-out);
    will-change: transform, opacity;
}

/* JS will add .hero-loading first, then .hero-enter to trigger animation */
.hero.hero-loading .hero-stagger {
    opacity: 0;
    transform: translateY(20px) scale(0.99);
}

.hero.hero-enter .hero-stagger {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Stagger delays */
.hero-enter .hero-stagger.d1 {
    transition-delay: 0.04s;
}

.hero-enter .hero-stagger.d2 {
    transition-delay: 0.1s;
}

.hero-enter .hero-stagger.d2b {
    transition-delay: 0.16s;
}

.hero-enter .hero-stagger.d3 {
    transition-delay: 0.22s;
}

.hero-enter .hero-stagger.d4 {
    transition-delay: 0.3s;
}

.hero-enter .hero-stagger.d5 {
    transition-delay: 0.38s;
}

.hero-enter .hero-stagger.d6 {
    transition-delay: 0.46s;
}

.hero-stagger.d1 {
    transition-delay: 0.04s;
}

.hero-stagger.d2 {
    transition-delay: 0.1s;
}

.hero-stagger.d2b {
    transition-delay: 0.16s;
}

.hero-stagger.d3 {
    transition-delay: 0.22s;
}

.hero-stagger.d4 {
    transition-delay: 0.3s;
}

.hero-stagger.d5 {
    transition-delay: 0.38s;
}

.hero-stagger.d6 {
    transition-delay: 0.46s;
}

/* Animated stat counter */
.stat .n {
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

/* Gradient text remains static for readability */
.grad {
    background-size: 100% 100%;
    animation: none;
}

/* ============================================================
   Phase 2 — Scroll-Driven Storytelling (Cinematic)
   ============================================================ */

/* Chapter entrance — deep slide with staggered children */
section.chapter {
    transform: translateY(24px);
    opacity: 0;
    transition: transform 0.7s var(--ease-out), opacity 0.65s var(--ease-out);
    will-change: transform, opacity;
}

section.chapter.in-view {
    transform: translateY(0);
    opacity: 1;
}

section.chapter.in-view .chapter-head {
    animation: chapterChildIn 0.45s var(--ease-out) 0.04s both;
}

section.chapter.in-view .subhead {
    animation: chapterChildIn 0.45s var(--ease-out) 0.12s both;
}

@keyframes chapterChildIn {
    from {
        opacity: 0;
        transform: translateY(24px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Cinematic content reveal — paragraphs, callouts, tables, code blocks */
section.chapter>p,
section.chapter>.callout,
section.chapter>.split,
section.chapter>.schema-block,
section.chapter>.eq-block,
section.chapter>.threat-grid,
section.chapter>h3,
section.chapter>.lab,
section.chapter>.hr,
section.chapter>div[style*="overflow"],
section.chapter>.scroll-x {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.5s var(--ease-out), transform 0.5s var(--ease-out);
    will-change: transform, opacity;
}

section.chapter.in-view>p,
section.chapter.in-view>.callout,
section.chapter.in-view>.split,
section.chapter.in-view>.schema-block,
section.chapter.in-view>.eq-block,
section.chapter.in-view>.threat-grid,
section.chapter.in-view>h3,
section.chapter.in-view>.lab,
section.chapter.in-view>.hr,
section.chapter.in-view>div[style*="overflow"],
section.chapter.in-view>.scroll-x {
    opacity: 1;
    transform: translateY(0);
}

/* Keep a light sequential cadence without long delays */
section.chapter.in-view> :nth-child(n+3) {
    transition-delay: 0.06s;
}

/* Word-by-word heading reveal */
.chapter h2 .hw {
    display: inline;
    opacity: 1;
    transform: none;
    transition: none;
    will-change: transform, opacity;
}

section.chapter.in-view h2 .hw {
    opacity: 1;
    transform: none;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    section.chapter {
        transform: none !important;
        opacity: 1 !important;
    }

    section.chapter>p,
    section.chapter>.callout,
    section.chapter>.split,
    section.chapter>.schema-block,
    section.chapter>h3,
    section.chapter>.lab,
    section.chapter>.hr,
    section.chapter>div[style*="overflow"] {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }

    .chapter h2 .hw {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }

    .hr::after {
        animation: none !important;
    }
}

/* ============================================================
   Phase 3 — Micro-Interactions
   ============================================================ */

/* 3D card tilt — subtle lift only */
.tilt-card {
    --mx: 0.5;
    --my: 0.5;
    transition: transform 0.4s var(--ease);
}

.tilt-card:hover {
    transform: translateY(-3px);
}

/* Border glow spotlight */
.glow-card {
    --gx: 50%;
    --gy: 50%;
    position: relative;
}

.glow-card::before {
    content: "";
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    background: radial-gradient(800px circle at var(--gx) var(--gy),
            rgba(94, 231, 223, 0.15),
            rgba(180, 144, 202, 0.06) 30%,
            transparent 50%);
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
    z-index: 0;
}

.glow-card:hover::before {
    opacity: 1;
}

[data-theme="light"] .glow-card::before {
    background: radial-gradient(800px circle at var(--gx) var(--gy),
            rgba(8, 145, 178, 0.1),
            rgba(124, 58, 237, 0.04) 30%,
            transparent 50%);
}

/* Magnetic button hover */
.btn {
    transition: transform 0.3s var(--ease), border-color 0.2s ease, background 0.2s ease, box-shadow 0.3s ease;
}

/* Smooth bar segment transitions */
.seg {
    transition: width 0.5s var(--ease);
}

/* ============================================================
   Phase 4 — Lab Visual Upgrades
   ============================================================ */

/* Failure card severity tint (left border) */
.failuregrid .fail {
    border-left: 3px solid var(--stroke);
    transition: all 0.3s ease;
}

.failuregrid .fail:nth-child(3n+1) {
    border-left-color: rgba(255, 201, 61, 0.6);
}

.failuregrid .fail:nth-child(3n+2) {
    border-left-color: rgba(255, 95, 109, 0.55);
}

.failuregrid .fail:nth-child(3n) {
    border-left-color: rgba(180, 144, 202, 0.55);
}

.failuregrid .fail:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* Token chip entrance animation */
.tokchip {
    animation: tokChipIn 0.35s var(--ease-out) both;
}

@keyframes tokChipIn {
    from {
        opacity: 0;
        transform: scale(0.7) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* SVG edge particles */
.edge-particle {
    fill: var(--accent);
    opacity: 0.7;
    filter: drop-shadow(0 0 4px var(--accent));
}

[data-theme="light"] .edge-particle {
    fill: rgba(8, 145, 178, 0.7);
}

/* RAG card stagger entrance */
.ragcard {
    animation: ragCardIn 0.5s var(--ease-out) both;
}

@keyframes ragCardIn {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================================
   Phase 5 — Polish & Delight
   ============================================================ */

/* Cursor glow follower */
.cursor-glow {
    position: fixed;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
    opacity: 0;
    transition: opacity 0.3s ease;
    background: radial-gradient(circle,
            rgba(99, 167, 255, 0.05) 0%,
            rgba(217, 142, 95, 0.03) 40%,
            transparent 70%);
    transform: translate(-50%, -50%);
    will-change: left, top;
    mix-blend-mode: normal;
}

.cursor-glow.visible {
    opacity: 0.55;
}

[data-theme="light"] .cursor-glow {
    background: radial-gradient(circle,
            rgba(47, 111, 178, 0.05) 0%,
            rgba(182, 108, 60, 0.03) 40%,
            transparent 70%);
    mix-blend-mode: multiply;
}

/* Command palette upgrade */
.modal {
    transition: opacity 0.3s ease;
}

.modal.open {
    opacity: 1;
}

.modal-card {
    transform: translateY(20px) scale(0.97);
    transition: transform 0.4s var(--ease-out);
}

.modal.open .modal-card {
    transform: translateY(0) scale(1);
}

.res {
    transition: opacity 0.2s ease, transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

/* Continue reading toast */
.continue-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1500;
    border: 1px solid var(--stroke);
    border-radius: var(--radius-sm);
    background: var(--card3);
    backdrop-filter: blur(10px);
    padding: 12px 14px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--muted);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.28s ease, transform 0.28s var(--ease-out);
    pointer-events: none;
}

.continue-toast.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

[data-theme="light"] .continue-toast {
    background: rgba(255, 255, 255, 0.94);
}

.continue-toast .toast-btn {
    cursor: pointer;
    border: 1px solid var(--stroke);
    background: var(--card2);
    color: var(--text);
    padding: 6px 10px;
    border-radius: var(--radius-xs);
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.continue-toast .toast-btn:hover {
    border-color: var(--accent);
    background: var(--card3);
}

.continue-toast .toast-close {
    cursor: pointer;
    background: none;
    border: none;
    color: var(--faint);
    font-size: 18px;
    padding: 4px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.continue-toast .toast-close:hover {
    background: var(--card);
    color: var(--text);
}

/* ============================================================
   Overhaul motion clamps
   ============================================================ */
.token-stream,
.edge-particle {
    display: none !important;
}

.tokchip,
.ragcard {
    animation: none !important;
}

.btn,
.callout,
.lab,
.threat-card {
    transition-duration: 0.2s;
}

.callout:hover,
.lab:hover,
.threat-card:hover {
    transform: none !important;
}

/* ============================================================
   Benchmark table styling
   ============================================================ */
.bench-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
}

.bench-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    margin-top: 16px;
    display: block;
    overflow-x: auto;
}

.bench-table th,
.bench-table td {
    padding: 11px 16px;
    border: 1px solid var(--stroke);
    text-align: left;
}

.bench-table th {
    background: var(--card);
    color: var(--muted);
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.bench-table td {
    font-family: var(--mono);
    font-size: 13.5px;
    line-height: 1.4;
}

.bench-table tr.bench-best td {
    color: var(--accent3);
    background: rgba(0, 255, 157, 0.05);
}

.bench-table tr.bench-worst td {
    color: var(--danger);
    background: rgba(255, 95, 109, 0.05);
}

/* ============================================================
   Replay results
   ============================================================ */
.replay-results {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

@media (max-width: 720px) {
    .replay-results {
        grid-template-columns: 1fr;
    }
}

.replay-card {
    background: var(--card);
    border: 1px solid var(--stroke);
    border-radius: var(--radius);
    padding: 20px 22px;
    transition: all 0.3s ease;
}

.replay-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.replay-card .trial-label {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 10px;
    font-weight: 600;
}

.replay-card .trial-answer {
    font-size: 16px;
    line-height: 1.6;
}

.replay-card .trial-reasoning {
    color: var(--muted);
    font-size: 14px;
    margin-top: 10px;
    line-height: 1.6;
}

.compare-prompt-preview {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--faint);
    margin-top: 24px;
    max-height: 160px;
    overflow: auto;
    white-space: pre-wrap;
    padding: 20px;
    background: var(--card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--stroke);
}

.replay-card.divergent {
    border-color: var(--danger);
    background: rgba(255, 95, 109, 0.05);
}

.replay-card.converged {
    border-color: var(--accent3);
    background: rgba(0, 255, 157, 0.05);
}

.replay-verdict {
    margin-top: 20px;
    font-family: var(--mono);
    font-size: 14px;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    background: var(--card);
    border: 1px solid var(--stroke);
    font-weight: 600;
    transition: all 0.3s ease;
}

.replay-verdict.fail {
    border-color: var(--danger);
    color: var(--danger);
    background: rgba(255, 95, 109, 0.08);
}

.replay-verdict.pass {
    border-color: var(--accent3);
    color: var(--accent3);
    background: rgba(0, 255, 157, 0.08);
}

/* ============================================================
   Failure-first mode
   ============================================================ */
body.failure-first .chapter {
    opacity: 0.25;
    transition: opacity 0.5s var(--ease);
    position: relative;
}

body.failure-first .chapter.ff-active {
    opacity: 1;
}

body.failure-first .chapter.ff-active::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 0;
    bottom: 0;
    width: 4px;
    inset: auto;
    background: var(--danger);
    border-radius: 999px;
    opacity: 1;
    box-shadow: 0 0 20px var(--danger);
}

.ff-banner {
    display: none;
    max-width: min(100%, 1040px);
    margin-left: auto;
    margin-right: auto;
    background: linear-gradient(135deg, rgba(255, 95, 109, 0.1), rgba(180, 144, 202, 0.06));
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    padding: 28px 32px;
    margin-bottom: 32px;
}

body.failure-first .ff-banner {
    display: block;
}

.ff-banner .ff-title {
    font-weight: 800;
    font-size: 20px;
    color: var(--danger);
    margin-bottom: 12px;
    letter-spacing: -0.01em;
}

.ff-banner .ff-narrative {
    font-size: 15px;
    line-height: 1.7;
    color: var(--muted);
    margin-bottom: 8px;
}

.ff-step {
    display: inline-block;
    font-family: var(--mono);
    font-size: 11px;
    background: var(--card2);
    border: 1px solid var(--stroke);
    border-radius: var(--radius-xs);
    padding: 4px 12px;
    margin: 4px 8px 4px 0;
    color: var(--faint);
    font-weight: 500;
    transition: all 0.2s ease;
}

body.failure-first .ff-step {
    color: var(--danger);
    border-color: rgba(255, 95, 109, 0.4);
    background: rgba(255, 95, 109, 0.08);
}

.ff-exit {
    display: none;
    margin-top: 16px;
}

body.failure-first .ff-exit {
    display: inline-block;
}

/* ============================================================
   Token heatmap overlay
   ============================================================ */
.heatmap-wrap {
    position: relative;
}

.heatmap-toggle {
    margin-bottom: 16px;
    float: right;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--card);
    border: 1px solid var(--stroke);
    border-radius: var(--radius-xs);
    transition: all 0.2s ease;
}

.heatmap-toggle:hover {
    border-color: var(--accent);
    box-shadow: 0 0 16px var(--accent-glow);
}

.heatmap-canvas {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
    border-radius: inherit;
}

.hm-token {
    display: inline;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 13px;
    line-height: 2;
    transition: background 0.3s ease;
}

/* ============================================================
   Governance workflows
   ============================================================ */
.gov-timeline {
    position: relative;
    padding-left: 36px;
    margin-top: 24px;
    max-height: 50vh;
    overflow-y: auto;
}

.gov-timeline::before {
    content: "";
    position: absolute;
    left: 14px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--stroke);
    border-radius: 999px;
}

.gov-event {
    position: relative;
    margin-bottom: 20px;
    padding: 18px 22px;
    background: var(--card);
    border: 1px solid var(--stroke);
    border-radius: var(--radius);
    transition: all 0.3s var(--ease);
}

.gov-event:hover {
    transform: translateX(4px);
    border-color: var(--stroke2);
}

.gov-event::before {
    content: "";
    position: absolute;
    left: -24px;
    top: 18px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg0);
    box-shadow: 0 0 0 2px var(--accent);
    transition: all 0.3s ease;
}

.gov-event:hover::before {
    transform: scale(1.2);
}

.gov-event.gov-delete::before {
    background: var(--danger);
    box-shadow: 0 0 0 2px var(--danger);
}

.gov-event.gov-update::before {
    background: var(--accent3);
    box-shadow: 0 0 0 2px var(--accent3);
}

.gov-event.gov-stale::before {
    background: var(--warn);
    box-shadow: 0 0 0 2px var(--warn);
}

.gov-event.gov-refresh::before {
    background: var(--accent2);
    box-shadow: 0 0 0 2px var(--accent2);
}

.gov-event .gov-time {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--faint);
    font-weight: 500;
}

.gov-event .gov-action {
    font-weight: 700;
    font-size: 16px;
    margin: 8px 0;
    color: var(--text);
}

.gov-event .gov-detail {
    font-size: 14px;
    color: var(--muted);
    line-height: 1.7;
}

.gov-event.gov-active {
    border-color: var(--accent);
    box-shadow: 0 0 24px var(--accent-glow);
}

.gov-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.gov-version {
    font-family: var(--mono);
    font-size: 12.5px;
    color: var(--faint);
    padding: 8px 14px;
    background: var(--card);
    border: 1px solid var(--stroke);
    border-radius: var(--radius-xs);
    margin-top: 8px;
    display: inline-block;
    font-weight: 500;
}

/* ============================================================
   Token stream
   ============================================================ */
.token-stream {
    position: fixed;
    top: 0;
    right: 0;
    width: 40px;
    height: 100vh;
    pointer-events: none;
    z-index: 50;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.6s var(--ease);
    display: none;
}

.token-stream .t-particle {
    position: absolute;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--accent);
    opacity: 0.2;
    white-space: nowrap;
    animation: tokenFall linear infinite;
}

@keyframes tokenFall {
    0% {
        transform: translateY(-20px);
        opacity: 0.3;
    }

    100% {
        transform: translateY(100vh);
        opacity: 0;
    }
}

.overflow-demo {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--stroke);
    border-radius: var(--radius);
    padding: 20px;
    margin: 16px 0;
    min-height: 120px;
    background: var(--card);
}

.overflow-demo .ov-token {
    display: inline-block;
    font-family: var(--mono);
    font-size: 13px;
    padding: 4px 8px;
    margin: 3px;
    background: var(--card2);
    border-radius: var(--radius-xs);
    transition: all 0.3s ease;
}

.overflow-demo .ov-token.falling {
    animation: tokenFall 0.8s ease-in forwards;
}

/* ============================================================
   Print stylesheet
   ============================================================ */
@media print {

    .topbar,
    .toc,
    .cursor-glow,
    .continue-toast,
    .hero-cta,
    .progress,
    .lab,
    .modal,
    .btn,
    body::before {
        display: none !important;
    }

    body {
        background: white !important;
        color: #111 !important;
        font-size: 11pt;
    }

    .wrap {
        padding-top: 0;
    }

    .hero {
        display: block;
        padding: 24px 0;
    }

    .hero h1 {
        font-size: 28pt;
        color: #111;
    }

    .grad {
        background: none !important;
        color: #111 !important;
        -webkit-text-fill-color: #111 !important;
    }

    .grid {
        display: block;
        padding: 0;
    }

    section.chapter {
        opacity: 1 !important;
        transform: none !important;
        border-top: 1px solid #ccc;
        page-break-inside: avoid;
        margin-bottom: 28px;
        box-shadow: none;
        background: white;
    }

    .callout {
        border: 1px solid #ccc;
        background: #f9f9f9;
    }

    a {
        color: #111;
        text-decoration: underline;
    }

    footer {
        display: block;
        color: #666;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cursor-glow {
        display: none !important;
    }

    .modal,
    .modal-card {
        transition: none !important;
    }

    .tokchip,
    .ragcard {
        animation: none !important;
    }
}
