/**
 * The full-page Agent (/agent), as a 14 s loop (home page #chat, played by js/home.js).
 *
 * One timeline, written as keyframe percentages of --cs-t:
 *   0–33 %   the welcome screen; the request types into the composer (10–30 %)
 *   35 %     it is sent and lands in the thread
 *   40–50 %  the agent asks which formats; the pointer picks one
 *   53–70 %  the agent plans and generates
 *   71–84 %  the new board arrives in the chat; the pointer opens it
 *   96–100 % back to the welcome screen
 *
 * Modelled on the app's AgentPage: conversation list, welcome starters,
 * QuestionCard, activity steps and the artifact card.
 */

.chat-grid {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    gap: clamp(2rem, 4vw, 4rem);
    align-items: center;
}

.chat-copy h2 { margin: 0.6rem 0 1.1rem; font-size: clamp(2rem, 3.4vw, 2.9rem); line-height: 1.08; letter-spacing: -0.03em; }

.chat-points {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    margin: 1.5rem 0 0;
    padding: 0;
    list-style: none;
}

.chat-points li {
    position: relative;
    padding-left: 1.4rem;
    font-size: 0.975rem;
    line-height: 1.55;
    color: rgba(209, 213, 219, 0.92);
}

.chat-points li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.55em;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #05c7bb;
}

@media (max-width: 899.98px) {
    .chat-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ── The app window ────────────────────────────────────────────────────── */

.chat-scene {
    --cs-t: 14s;
    --cs-bg: #1b1c1d;
    --cs-surface: #232526;
    --cs-raised: #2b2e2f;
    --cs-border: rgba(255, 255, 255, 0.10);
    --cs-text: #dde0e2;
    --cs-muted: #989ea1;
    --cs-faint: #5e6366;
    --cs-accent: #05c7bb;
    --cs-ok: #43c283;

    position: relative;
    display: grid;
    grid-template-columns: 11rem minmax(0, 1fr);
    height: 30rem;
    overflow: hidden;
    border: 1px solid var(--cs-border);
    border-radius: 1.1rem;
    background: var(--cs-bg);
    box-shadow: 0 40px 90px -40px rgba(0, 0, 0, 0.8);
    color: var(--cs-text);
    font: 13px/1.45 'Inter', system-ui, sans-serif;
    text-align: left;
    -webkit-font-smoothing: antialiased;
}

.chat-scene p { margin: 0; }

.cs-side {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 14px 10px;
    border-right: 1px solid var(--cs-border);
    background: #18191a;
}

.cs-new {
    margin-bottom: 10px;
    padding: 7px 10px;
    border: 1px solid var(--cs-border);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
}

.cs-side__label {
    padding: 0 8px 4px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--cs-faint);
}

.cs-sess {
    padding: 6px 8px;
    border-radius: 7px;
    overflow: hidden;
    font-size: 12px;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--cs-muted);
}

.cs-sess.is-on { background: var(--cs-raised); color: var(--cs-text); animation: csSess var(--cs-t) linear infinite; }

.cs-main {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 14px 16px;
}

/* Welcome: a title and four starters */
.cs-welcome {
    position: absolute;
    inset: 0 0 72px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 0 20px;
    animation: csWelcome var(--cs-t) ease infinite;
}

.cs-welcome__title { font-size: 18px; font-weight: 600; color: #fff; }

.cs-starters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: min(100%, 22rem);
}

.cs-starters > span {
    padding: 9px 11px;
    border: 1px solid var(--cs-border);
    border-radius: 10px;
    background: var(--cs-surface);
    font-size: 11.5px;
    color: var(--cs-muted);
}

/* The thread grows from the bottom as messages arrive. */
.cs-thread {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 10px;
    padding-bottom: 12px;
    overflow: hidden;
}

.cs-thread > *,
.cs-steps > li {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
}

.cs-user { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; animation: csUser var(--cs-t) ease infinite; }

.cs-user__asset {
    width: 48px;
    height: 48px;
    overflow: hidden;
    border: 1px solid var(--cs-border);
    border-radius: 8px;
}

.cs-user__asset img { display: block; width: 100%; height: 100%; object-fit: cover; }

.cs-bubble {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 14px 14px 4px 14px;
    background: var(--cs-raised);
    font-size: 12.5px;
}

.cs-agent {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    font-weight: 600;
}

.cs-agent img { width: 10px; height: auto; }

.cs-ask {
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 10px 12px;
    border: 1px solid var(--cs-border);
    border-radius: 12px;
    background: var(--cs-surface);
    animation: csAsk var(--cs-t) ease infinite;
}

.cs-ask__q { font-size: 12.5px; font-weight: 600; }
.cs-options { display: flex; gap: 6px; flex-wrap: wrap; }

.cs-opt {
    position: relative;
    padding: 4px 10px;
    border: 1px solid var(--cs-border);
    border-radius: 7px;
    font-size: 11.5px;
    color: var(--cs-text);
}

.cs-opt--a { animation: csOpt var(--cs-t) linear infinite; }

.cs-steps {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
    max-height: none;
    opacity: 1;
    overflow: visible;
}

.cs-step { display: flex; align-items: center; gap: 8px; font-size: 11.5px; }
.cs-step--1 { animation: csStep1 var(--cs-t) ease infinite; }
.cs-step--2 { animation: csStep2 var(--cs-t) ease infinite; }

/* A spinner that becomes a tick */
.cs-mark {
    position: relative;
    flex: none;
    width: 13px;
    height: 13px;
    border: 1.5px solid rgba(28, 145, 255, 0.25);
    border-top-color: #1c91ff;
    border-radius: 50%;
    animation: csSpin 0.9s linear infinite;
}

.cs-step--1 .cs-mark::after,
.cs-step--2 .cs-mark::after {
    content: '';
    position: absolute;
    inset: -1.5px;
    border-radius: 50%;
    background: var(--cs-ok) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.5l2.6 2.5L12 5.5' fill='none' stroke='%231b1c1d' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 9px no-repeat;
    opacity: 0;
}

.cs-step--1 .cs-mark::after { animation: csTick1 var(--cs-t) linear infinite; }
.cs-step--2 .cs-mark::after { animation: csTick2 var(--cs-t) linear infinite; }

/* The board, as an artifact card in the chat */
.cs-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border: 1px solid var(--cs-border);
    border-radius: 12px;
    background: var(--cs-surface);
    animation: csCard var(--cs-t) ease infinite;
}

.cs-card__grid { display: grid; grid-template-columns: repeat(3, 34px); gap: 3px; }

.cs-card__grid i {
    height: 34px;
    border-radius: 4px;
    background: #222 var(--img) center / cover no-repeat;
}

.cs-card__meta { display: flex; flex-direction: column; min-width: 0; font-size: 11px; color: var(--cs-muted); }
.cs-card__meta b { overflow: hidden; font-size: 12.5px; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; color: var(--cs-text); }

.cs-card__open {
    position: relative;
    padding: 6px 11px;
    border-radius: 8px;
    background: var(--cs-accent);
    font-size: 11.5px;
    font-weight: 600;
    color: #0b1215;
    white-space: nowrap;
    animation: csOpen var(--cs-t) linear infinite;
}

/* The composer: the request types in, then send lights up. */
.cs-composer {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 46px;
    padding: 8px 8px 8px 12px;
    border: 1px solid var(--cs-border);
    border-radius: 12px;
    background: var(--cs-surface);
}

.cs-composer__text,
.cs-composer__ph {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    font-size: 12.5px;
    white-space: nowrap;
    text-overflow: clip;
}

.cs-composer__text {
    color: var(--cs-text);
    animation: csType var(--cs-t) steps(48, end) infinite;
}

.cs-composer__ph {
    position: absolute;
    left: 12px;
    right: 90px;
    color: var(--cs-faint);
    animation: csPh var(--cs-t) linear infinite;
}

.cs-model {
    flex: none;
    padding: 3px 8px;
    border: 1px solid var(--cs-border);
    border-radius: 6px;
    font-size: 11px;
    color: var(--cs-muted);
}

.cs-send {
    position: relative;
    flex: none;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--cs-raised);
    animation: csSend var(--cs-t) linear infinite;
}

.cs-send::after {
    content: '';
    position: absolute;
    inset: 8px;
    background: currentColor;
    color: var(--cs-muted);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 13V3M3.5 7.5L8 3l4.5 4.5' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 13V3M3.5 7.5L8 3l4.5 4.5' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* The pointer, inside the thing it clicks */
.cs-cursor {
    position: absolute;
    left: 55%;
    top: 45%;
    width: 18px;
    height: 22px;
    pointer-events: none;
    opacity: 0;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 22'%3E%3Cpath d='M2 1.5v16.2l4.3-4.1 2.9 6.6 2.8-1.2-2.9-6.5H15z' fill='%23fff' stroke='%23111' stroke-width='1.3' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.cs-cursor--a { animation: csCursorA var(--cs-t) cubic-bezier(0.45, 0, 0.2, 1) infinite; }
.cs-cursor--b { animation: csCursorB var(--cs-t) cubic-bezier(0.45, 0, 0.2, 1) infinite; }

/* ── Timeline ──────────────────────────────────────────────────────────── */

@keyframes csWelcome { 0%, 33% { opacity: 1; transform: none; } 36%, 96% { opacity: 0; transform: translateY(-8px); } 100% { opacity: 1; transform: none; } }
@keyframes csType { 0%, 10% { clip-path: inset(0 100% 0 0); opacity: 1; } 30%, 34% { clip-path: inset(0 0 0 0); opacity: 1; } 34.5%, 100% { opacity: 0; } }
@keyframes csPh { 0%, 9.5% { opacity: 1; } 10%, 34% { opacity: 0; } 35%, 100% { opacity: 1; } }
@keyframes csSend { 0%, 30% { background: var(--cs-raised); transform: none; } 31%, 34% { background: var(--cs-accent); } 33% { transform: scale(0.9); } 35%, 100% { background: var(--cs-raised); transform: none; } }

@keyframes csUser { 0%, 34.5% { max-height: 0; opacity: 0; } 37%, 96% { max-height: 140px; opacity: 1; } 100% { max-height: 0; opacity: 0; } }
@keyframes csAsk { 0%, 39.5% { max-height: 0; opacity: 0; } 42%, 96% { max-height: 120px; opacity: 1; } 100% { max-height: 0; opacity: 0; } }
@keyframes csOpt { 0%, 49.5% { background: transparent; border-color: var(--cs-border); color: var(--cs-text); } 50%, 100% { background: var(--cs-accent); border-color: var(--cs-accent); color: #0b1215; } }
@keyframes csStep1 { 0%, 52.5% { max-height: 0; opacity: 0; } 54%, 96% { max-height: 24px; opacity: 1; } 100% { max-height: 0; opacity: 0; } }
@keyframes csStep2 { 0%, 57.5% { max-height: 0; opacity: 0; } 59%, 96% { max-height: 24px; opacity: 1; } 100% { max-height: 0; opacity: 0; } }
@keyframes csTick1 { 0%, 57.5% { opacity: 0; } 58%, 100% { opacity: 1; } }
@keyframes csTick2 { 0%, 69.5% { opacity: 0; } 70%, 100% { opacity: 1; } }
@keyframes csCard { 0%, 70.5% { max-height: 0; opacity: 0; } 73%, 96% { max-height: 80px; opacity: 1; } 100% { max-height: 0; opacity: 0; } }
@keyframes csOpen { 0%, 83.5% { transform: none; filter: none; } 84% { transform: scale(0.93); } 85%, 96% { transform: none; filter: brightness(1.15); } 100% { filter: none; } }
@keyframes csSess { 0%, 34% { opacity: 0.55; } 36%, 100% { opacity: 1; } }

@keyframes csCursorA {
    0%, 42% { opacity: 0; transform: translate(60px, 40px); }
    44% { opacity: 1; }
    48% { transform: translate(0, 0); }
    50% { transform: translate(0, 0) scale(0.9); }
    51% { transform: translate(0, 0); }
    55%, 100% { opacity: 0; transform: translate(0, 0); }
}

@keyframes csCursorB {
    0%, 75% { opacity: 0; transform: translate(-70px, 40px); }
    77% { opacity: 1; }
    82% { transform: translate(0, 0); }
    84% { transform: translate(0, 0) scale(0.9); }
    85% { transform: translate(0, 0); }
    90%, 100% { opacity: 0; transform: translate(0, 0); }
}

@keyframes csSpin { to { transform: rotate(360deg); } }

/* Plays only while on screen (js/home.js adds .is-playing). */
.chat-scene:not(.is-playing) *,
.chat-scene:not(.is-playing) *::before,
.chat-scene:not(.is-playing) *::after { animation-play-state: paused; }

/* ── Phone: no conversation list ───────────────────────────────────────── */

@media (max-width: 599.98px) {
    .chat-scene { grid-template-columns: minmax(0, 1fr); height: 28rem; }
    .cs-side { display: none; }
}

/* ── Reduced motion: the finished chat, nothing moves ──────────────────── */

@media (prefers-reduced-motion: reduce) {
    .chat-scene *,
    .chat-scene *::before,
    .chat-scene *::after { animation: none !important; }
    .cs-welcome, .cs-composer__text, .cs-cursor { opacity: 0; }
    .cs-thread > *, .cs-steps > li { max-height: none; opacity: 1; }
    .cs-mark { border-color: var(--cs-ok); }
    .cs-step--1 .cs-mark::after, .cs-step--2 .cs-mark::after { opacity: 1; }
    .cs-opt--a { background: var(--cs-accent); border-color: var(--cs-accent); color: #0b1215; }
}
