:root {
    color-scheme: dark;
    font-family: "Titillium Web", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 200;
    --grad-blue: #3da1ff;
    --grad-pink: #f249d9;
    --grad-purple: #9f39ff;
    --ease-flow: cubic-bezier(.22, 1, .36, 1);

    --orb-c1: #4285f4;
    --orb-c2: #9b51e0;
    --orb-c3: #e91e63;
    --orb-c4: #2196f3;
    --orb-c5: #00f2ff;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-width: 320px;
    min-height: 100vh;
    overflow: hidden;
    background: #090727;
    color: #f8fafb;
}

button {
    font: inherit;
    cursor: pointer;
}

.stage {
    position: relative;
    isolation: isolate;
    height: 100svh;
    overflow: hidden;
    background:
        radial-gradient(ellipse at 57% 38%, #6346c9 0, transparent 44%),
        radial-gradient(ellipse at 88% 74%, #c624b5 0, transparent 43%),
        radial-gradient(ellipse at 14% 72%, #176cdb 0, transparent 35%),
        linear-gradient(145deg, #430e60 0%, #171153 45%, #050b31 100%);
}

#persona-video {
    position: absolute;
    z-index: -2;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 25%;
    opacity: 0;
    transition: opacity .7s ease;
}

.stage.connected #persona-video {
    opacity: 1;
}

.backdrop {
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(ellipse at 20% 57%, rgba(61,161,255,.48) 0, transparent 23%),
        radial-gradient(ellipse at 76% 60%, rgba(242,73,217,.5) 0, transparent 30%),
        radial-gradient(ellipse at 52% 94%, rgba(159,57,255,.65) 0, transparent 42%),
        linear-gradient(180deg, rgba(4,7,39,.44) 0%, rgba(20,8,64,.02) 35%, rgba(17,3,43,.52) 100%);
    transition: background .5s ease;
}

.stage.connected .backdrop {
    background: linear-gradient(180deg, rgba(4,7,23,.55) 0%, transparent 25%, transparent 60%, rgba(4,7,23,.76) 100%);
}

/* --- Topbar --- */
.topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 28px clamp(20px, 4vw, 58px);
}

.brand {
    font-size: 16px;
    font-weight: 720;
    letter-spacing: -.02em;
    display: flex;
    gap: 7px;
    align-items: center;
}

.brand span:last-child {
    color: #d8cef3;
    font-weight: 450;
}

.brand-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* --- Status chip --- */
.status {
    display: none;
    gap: 9px;
    align-items: center;
    padding: 8px 12px;
    border: 1px solid rgba(213,190,255,.2);
    border-radius: 999px;
    background: rgba(19,10,64,.4);
    backdrop-filter: blur(12px);
    font-size: 13px;
}

.status[data-state="connecting"],
.status[data-state="connected"],
.status[data-state="error"] {
    display: flex;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #a8a5c3;
    flex: 0 0 auto;
}

.status-loader {
    display: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex: 0 0 auto;
    background: conic-gradient(from 0deg, var(--grad-blue), var(--grad-purple), var(--grad-pink), var(--grad-blue));
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.4px), #000 calc(100% - 2.4px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 2.4px), #000 calc(100% - 2.4px));
    animation: spin .85s linear infinite;
}

.status[data-state="connecting"] .status-dot {
    display: none;
}

.status[data-state="connecting"] .status-loader {
    display: block;
}

.status[data-state="connected"] .status-dot {
    background: #74e1ff;
    box-shadow: 0 0 10px #74e1ff;
}

.status[data-state="error"] .status-dot {
    background: #ff6e9f;
}

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

/* --- Hero panel --- */
.hero {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 100px 24px 130px;
}

.hero-panel {
    width: min(980px, 100%);
    text-align: center;
    display: grid;
    justify-items: center;
    gap: 0;
    transition: opacity .4s, transform .4s;
}

.stage.connected .hero-panel {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-16px);
}

.stage.connected .transcript-panel {
    bottom: 30px;
}

/* --- Message rotator --- */
.message-rotator {
    margin-top: 8px;
    width: min(860px, 100%);
    height: 340px;
    position: relative;
}

.message-slide {
    position: absolute;
    inset: 0;
    padding: 28px 28px 30px;
    display: grid;
    grid-template-rows: auto auto 1fr;
    justify-items: center;
    align-content: center;
    text-align: center;
    gap: 0;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 1s cubic-bezier(.4,0,.2,1), transform 1s cubic-bezier(.4,0,.2,1);
    pointer-events: none;
    will-change: opacity, transform;
}

.message-slide.is-active {
    opacity: 1;
    transform: translateY(0);
}

.message-slide.is-leaving {
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity .8s cubic-bezier(.4,0,.2,1), transform .8s cubic-bezier(.4,0,.2,1);
}

.message-kicker {
    margin: 0 0 10px;
    color: #8fdcff;
    font-size: 11px;
    font-weight: 200;
    letter-spacing: .16em;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.message-kicker::before {
    content: "";
    width: 14px;
    height: 1px;
    background: linear-gradient(90deg, transparent, #8fdcff);
}

.message-kicker::after {
    content: "";
    width: 14px;
    height: 1px;
    background: linear-gradient(90deg, #8fdcff, transparent);
}

.message-slide h2 {
    margin: 0 0 12px;
    max-width: 760px;
    font-size: clamp(40px, 6.2vw, 84px);
    line-height: .98;
    letter-spacing: -.06em;
    text-shadow: 0 8px 36px rgba(53,15,121,.5);
}

.message-slide p {
    margin: 0;
    max-width: 680px;
    color: #ddd4f1;
    font-size: clamp(16px, 2vw, 20px);
    line-height: 1.6;
}

.rotator-dots {
    position: absolute;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 3;
}

.rotator-dot {
    width: 8px;
    height: 8px;
    border: 0;
    border-radius: 50%;
    padding: 0;
    background: rgba(255,255,255,.22);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
    transition: background .3s, box-shadow .3s, transform .3s var(--ease-flow);
}

.rotator-dot.is-active {
    background: #8fdcff;
    box-shadow: 0 0 10px rgba(116,225,255,.65);
    transform: scale(1.2);
}

/* --- Buttons --- */
.primary-button {
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 999px;
    color: white;
    background: linear-gradient(105deg, #6d64ff, #d343d6);
    font-weight: 700;
    padding: 14px 21px;
    box-shadow: 0 12px 32px rgba(165,54,218,.38);
    transition: transform .15s, filter .15s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

#start-button.primary-button {
    margin-top: 28px;
}

.primary-button:hover {
    transform: translateY(-2px);
    filter: brightness(1.13);
}

.primary-button:disabled {
    opacity: .85;
    cursor: wait;
}

.button-loader {
    display: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    animation: spin .7s linear infinite;
}

.primary-button[data-loading="true"] .button-loader {
    display: inline-block;
}

.primary-button[data-loading="true"] .button-icon {
    display: none;
}

.button-icon {
    font-size: 12px;
}

/* --- Transcript --- */
.transcript-panel {
    position: absolute;
    left: 50%;
    bottom: 110px;
    transform: translateX(-50%);
    width: min(530px, calc(100vw - 40px));
    padding: 16px 18px;
    border-radius: 14px;
    background: rgba(0,0,0,.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,.04);
    box-shadow: 0 4px 24px rgba(0,0,0,.5);
    z-index: 20;
}

.transcript-label {
    margin: 0 0 7px;
    color: #9edaff;
    font-size: 10px;
    letter-spacing: .16em;
    font-weight: 800;
}

.transcript-text {
    margin: 0;
    font-size: 16px;
    line-height: 1.45;
    text-wrap: balance;
}

.transcript-close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: none;
    border: none;
    color: rgba(255,255,255,.45);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 6px;
    line-height: 1;
    border-radius: 6px;
    transition: color .2s, background .2s;
}

.transcript-close:hover {
    color: #fff;
    background: rgba(255,255,255,.1);
}

.transcript-show-btn {
    position: absolute;
    left: 50%;
    bottom: 30px;
    transform: translateX(-50%);
    z-index: 20;
    background: rgba(0,0,0,.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 50%;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,.6);
    cursor: pointer;
    transition: color .2s, background .2s, transform .2s;
}

.transcript-show-btn:hover {
    color: #fff;
    background: rgba(0,0,0,.8);
    transform: translateX(-50%) scale(1.1);
}

.transcript-show-btn[hidden] {
    display: none;
}

/* --- Footer --- */
.page-footer {
    position: absolute;
    right: clamp(20px, 4vw, 58px);
    bottom: 5px;
    left: clamp(20px, 4vw, 58px);
    z-index: 20;
    text-align: center;
}

.footer-copyright {
    font-size: 13px;
    font-weight: 300;
    letter-spacing: .04em;
    color: rgba(223,226,255,.6);
    text-decoration: none;
}

.footer-copyright:hover {
    color: rgba(223,226,255,.9);
}

.stage.connected .page-footer {
    opacity: 0;
    pointer-events: none;
}

/* --- Orb Animation --- */
#canvas-container {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: transparent;
    z-index: -3;
    pointer-events: none;
}

#canvas-container canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    filter: saturate(1.18) contrast(1.04);
    display: block;
    background: transparent;
}

/* --- Controls --- */
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.end-button {
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 999px;
    color: white;
    background: #c94134;
    font-weight: 700;
    padding: 8px 16px;
    font-size: 13px;
    box-shadow: 0 8px 22px rgba(176,45,35,.3);
    transition: background .15s;
}

.end-button:not(:disabled):hover {
    background: #df5547;
}

.end-button:disabled {
    opacity: 0;
    pointer-events: none;
}

.end-button[hidden] {
    display: none;
}

/* --- Toast --- */
.toast {
    position: absolute;
    left: 50%;
    bottom: 105px;
    transform: translateX(-50%);
    width: min(420px, calc(100vw - 40px));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    padding: 14px 16px;
    border-radius: 12px;
    color: #ffe9eb;
    background: rgba(91,25,35,.92);
    border: 1px solid rgba(255,144,154,.33);
    z-index: 30;
}

.toast button {
    flex: 0 0 auto;
    background: transparent;
    border: 1px solid rgba(255,255,255,.3);
    border-radius: 8px;
    color: white;
    padding: 6px 9px;
}

.transcript-panel[hidden],
.toast[hidden] {
    display: none;
}

/* --- Responsive --- */
@media (max-width: 560px) {
    .topbar { padding: 20px; }
    .brand { font-size: 14px; }
    .status { font-size: 11px; }

    .status #status-label {
        max-width: 115px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .hero {
        padding: 90px 16px 126px;
    }

    .message-slide--hero h2,
    .message-slide h2 {
        font-size: clamp(34px, 10vw, 54px);
    }

    .message-slide--hero p,
    .message-slide p {
        max-width: 340px;
        width: 100%;
        font-size: 15px;
        line-height: 1.55;
    }

    .message-rotator {
        height: 300px;
        margin-top: 20px;
    }

    .message-slide {
        padding: 24px 18px 32px;
    }

    .transcript-panel { bottom: 112px; }
    .transcript-text { font-size: 14px; }
    .page-footer { bottom: 20px; }
}

@media (prefers-reduced-motion: reduce) {
    .message-slide,
    .message-slide.is-leaving,
    #persona-video,
    .hero-panel,
    .backdrop,
    .status-loader,
    .button-loader {
        transition: none;
        animation: none;
    }
}
