/* ====== Contained styles (scoped) ====== */
#autto-merge-animation {
    --bg1: #0b1220;
    --bg2: #0a0f1e;
    --card: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.10);
    --text: rgba(255, 255, 255, 0.92);
    --muted: rgba(255, 255, 255, 0.62);
    --shadow: 0 22px 60px rgba(0, 0, 0, 0.45);
    --shadowSoft: 0 16px 40px rgba(0, 0, 0, 0.35);
    --accent: #8280ff;
    --accent2: #40c8ff;

    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
    color: var(--text);
}

#autto-merge-animation * {
    box-sizing: border-box;
}

.ama-shell {
    width: min(980px, 100%);
    height: 29.1rem;
    margin: 0 auto;
    padding: 18px;
    border-radius: 22px;
    background:
        radial-gradient(1200px 600px at 10% 10%, rgba(130, 128, 255, 0.18), transparent 55%),
        radial-gradient(1000px 520px at 85% 30%, rgba(64, 200, 255, 0.12), transparent 55%),
        linear-gradient(180deg, var(--bg1), var(--bg2));
    border: 1px solid rgba(255, 255, 255, 0.10);
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
}

.ama-shell::before {
    content: "";
    position: absolute;
    inset: -2px;
    background:
        radial-gradient(900px 450px at 15% 85%, rgba(130, 128, 255, 0.12), transparent 60%),
        radial-gradient(800px 420px at 90% 70%, rgba(64, 200, 255, 0.10), transparent 62%);
    filter: blur(18px);
    opacity: .8;
    pointer-events: none;
}

.ama-stage {
    position: relative;
    height: 340px;
    min-height: 340px;
    display: grid;
    place-items: center;
}

.ama-row {
    position: relative;
    width: 100%;
    max-width: 920px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    align-items: center;
    z-index: 1;
}

@media (max-width: 820px) {
    .ama-shell {
        height: 53rem;
    }
    .ama-stage {
        height: 540px;
        min-height: 540px;
    }

    .ama-row {
        grid-template-columns: 1fr;
    }

    #ama-final {
        top: -160% !important;
    }
}

.ama-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadowSoft);
    overflow: hidden;
    position: relative;
}

.ama-cardHeader {
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
}

.ama-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ama-title strong {
    font-size: 13px;
    font-weight: 720;
    letter-spacing: .2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ama-title span {
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ama-pill {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.70);
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    gap: 8px;
}

.ama-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 4px rgba(130, 128, 255, 0.18);
}

/* Document mock */
.ama-docBody {
    padding: 14px 14px 16px;
}

.ama-docPaper {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 16px;
    padding: 14px;
    position: relative;
    overflow: hidden;
}

.ama-docPaper::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(90deg, rgba(130, 128, 255, 0.10), transparent 35%),
        radial-gradient(500px 160px at 20% 20%, rgba(64, 200, 255, 0.10), transparent 60%);
    opacity: .6;
    pointer-events: none;
}

.ama-docLine {
    height: 14px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    margin: 10px 0;
}

.ama-docLine.short {
    width: 72%;
}

.ama-docLine.tiny {
    width: 52%;
}

.ama-docLine.text {
    height: auto;
    background: transparent;
    margin: 10px 0;
    color: rgba(255, 255, 255, 0.78);
    font-size: 13px;
    line-height: 1.35;
    position: relative;
}

.ama-paragraph {
    margin: 10px 0 0;
    color: rgba(255, 255, 255, 0.72);
    font-size: 12.5px;
    line-height: 1.45;
    filter: blur(5px);
    opacity: 0.55;
}

.ama-blurRest .ama-docLine:not(.text),
.ama-blurRest .ama-paragraph {
    filter: blur(5px);
    opacity: 0.55;
}

.ama-field {
    display: inline-flex;
    gap: 8px;
    align-items: baseline;
    flex-wrap: wrap;
}

.ama-label {
    color: rgba(255, 255, 255, 0.68);
    font-weight: 600;
}

.ama-value,
.ama-var {
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    font-weight: 650;
    letter-spacing: .15px;
    white-space: nowrap;
}

.ama-var {
    border-color: rgba(130, 128, 255, 0.35);
    background: rgba(130, 128, 255, 0.16);
    color: rgba(255, 255, 255, 0.95);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 12px;
}

/* Typing simulation */
.ama-typeWrap {
    display: inline-flex;
    align-items: baseline;
    gap: 0;
    position: relative;
}

.ama-type {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .15px;
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.95);
    min-width: 40px;
    display: inline-block;
    vertical-align: baseline;
}

.ama-type.cursor::after {
    content: "";
    display: inline-block;
    width: 1.5px;
    height: 14px;
    background: rgba(255, 255, 255, 0.85);
    margin-left: 4px;
    transform: translateY(2px);
    animation: amaBlink .8s infinite;
}

@keyframes amaBlink {

    0%,
    45% {
        opacity: 1;
    }

    46%,
    100% {
        opacity: 0;
    }
}

/* Spreadsheet mock */
.ama-sheetBody {
    padding: 14px;
}

.ama-sheetGrid {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 16px;
    padding: 12px;
    overflow: hidden;
}

.ama-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.ama-tab {
    font-size: 12px;
    padding: 7px 10px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.78);
}

.ama-tab.active {
    background: rgba(130, 128, 255, 0.20);
    border-color: rgba(130, 128, 255, 0.38);
    color: rgba(255, 255, 255, 0.92);
}

.ama-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    background: rgba(10, 15, 30, 0.20);
}

.ama-table th,
.ama-table td {
    font-size: 12px;
    padding: 10px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.78);
}

.ama-table th {
    font-weight: 700;
    color: rgba(255, 255, 255, 0.72);
    background: rgba(255, 255, 255, 0.04);
    text-align: center;
}

.ama-rowIndex {
    width: 40px;
    text-align: center;
    color: rgba(255, 255, 255, 0.50);
    background: rgba(255, 255, 255, 0.03);
    font-weight: 700;
}

.ama-colHead {
    width: 50%;
}

.ama-cell-muted {
    color: rgba(255, 255, 255, 0.55);
}

.ama-cellGlow {
    box-shadow: 0 0 0 2px rgba(130, 128, 255, 0.35) inset, 0 0 24px rgba(130, 128, 255, 0.18);
    background: rgba(130, 128, 255, 0.14) !important;
    color: rgba(255, 255, 255, 0.92);
}

/* ====== Timeline (7s) ====== */
.ama-final {
    inset: 0;
    display: grid;
    place-items: center;
    pointer-events: none;
    z-index: 2;
    opacity: 0;
    align-self: center;
}

#ama-final {
    position: relative;
    top: -115%;
}

.ama-final .ama-card {
    width: min(520px, 92%);
}

/* Merge motion around ~4.6s-5.8s */
.ama-docWrap,
.ama-sheetWrap {
    transform: translateX(0) scale(1);
    opacity: 1;
}

#autto-merge-animation.run .ama-docWrap {
    animation: amaDocMerge 7s both;
}

#autto-merge-animation.run .ama-sheetWrap {
    animation: amaSheetMerge 7s both;
}

@keyframes amaDocMerge {

    0%,
    66% {
        transform: translateX(0) scale(1);
        opacity: 1;
    }

    78% {
        transform: translateX(115px) scale(0.98);
        opacity: 1;
    }

    86% {
        transform: translateX(155px) scale(0.96);
        opacity: 0.22;
    }

    100% {
        transform: translateX(155px) scale(0.96);
        opacity: 0;
    }
}

@keyframes amaSheetMerge {

    0%,
    66% {
        transform: translateX(0) scale(1);
        opacity: 1;
    }

    78% {
        transform: translateX(-115px) scale(0.98);
        opacity: 1;
    }

    86% {
        transform: translateX(-155px) scale(0.96);
        opacity: 0.16;
    }

    100% {
        transform: translateX(-155px) scale(0.96);
        opacity: 0;
    }
}

/* Final doc fades in near the end */
#autto-merge-animation.run .ama-final {
    animation: amaFinalIn 7s both;
}

@keyframes amaFinalIn {

    0%,
    78% {
        opacity: 0;
        transform: translateY(8px) scale(0.99);
    }

    88% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {

    #autto-merge-animation.run .ama-docWrap,
    #autto-merge-animation.run .ama-sheetWrap,
    #autto-merge-animation.run .ama-final {
        animation: none !important;
    }

    .ama-final {
        opacity: 1;
    }

    .ama-docWrap,
    .ama-sheetWrap {
        opacity: 0;
    }
}

/* JS intro fade-in (works even with .run animations) */
#autto-merge-animation.ama-intro .ama-docWrap,
#autto-merge-animation.ama-intro .ama-sheetWrap{
  opacity: 0;
  transform: translateY(10px) scale(0.985);
}