:root {
    --field: #0b2fc7;
    --ink: #0a1035;
    --ink-soft: #515a82;
    --paper: #ffffff;
    --mist: #eef1fd;
    --line: #d6dcf4;
    --live: #6ff0c0;
    --alert: #ffcf6b;
    --danger: #b3261e;

    --on-field: #ffffff;
    --on-field-soft: rgba(255, 255, 255, .82);
    --glass: rgba(255, 255, 255, .13);
    --glass-strong: rgba(255, 255, 255, .24);

    --font-ui: 'Geist', 'Helvetica Neue', 'Segoe UI', system-ui, sans-serif;
    --font-code: 'Fragment Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    --ease: cubic-bezier(.2, .8, .2, 1);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
    background: var(--field);
    color: var(--on-field);
    font: 400 15px/1.5 var(--font-ui);
    -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

h1,
h2,
h3,
p {
    margin: 0;
}

[hidden] {
    display: none !important;
}

:focus-visible {
    outline: 2px solid var(--on-field);
    outline-offset: 2px;
}

.surface :focus-visible {
    outline-color: var(--field);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Top bar */

.bar {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 10px 14px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    margin-right: 6px;
    color: inherit;
    font-size: 16px;
    font-weight: 650;
    letter-spacing: -.02em;
    text-decoration: none;
    white-space: nowrap;
}

.brand svg {
    width: 22px;
    height: 22px;
    flex: none;
}

.session-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    height: 34px;
    padding: 0 4px 0 12px;
    border-radius: 999px;
    background: var(--glass);
    font-size: 13.5px;
    font-weight: 500;
    white-space: nowrap;
}

#status-text {
    padding-right: 8px;
}

.dot {
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--on-field);
    opacity: .55;
}

body[data-status="starting"] .dot {
    opacity: 1;
    animation: blink 1s ease-in-out infinite alternate;
}

body[data-status="live"] .dot {
    opacity: 1;
    background: var(--live);
    box-shadow: 0 0 0 3px rgba(111, 240, 192, .25);
}

body[data-status="error"] .dot {
    opacity: 1;
    background: var(--alert);
}

.sid {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    height: 26px;
    padding: 0 9px 0 10px;
    border: 0;
    border-radius: 999px;
    background: var(--glass);
    font-family: var(--font-code);
    font-size: 12.5px;
    transition: background-color .15s;
}

.sid:hover {
    background: var(--glass-strong);
}

.sid-value {
    overflow: hidden;
    text-overflow: ellipsis;
}

.sid svg {
    flex: none;
    width: 13px;
    height: 13px;
    opacity: .8;
}

.bar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.bar-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 36px;
    padding: 0 13px;
    border: 0;
    border-radius: 10px;
    background: var(--glass);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    transition: background-color .15s, box-shadow .15s;
}

.bar-btn:hover {
    background: var(--glass-strong);
}

.bar-btn svg {
    width: 15px;
    height: 15px;
    flex: none;
}

.bar-btn.icon-only {
    width: 36px;
    padding: 0;
    justify-content: center;
}

body:not([data-status="live"]) .needs-live {
    display: none;
}

/* Stage */

.stage {
    position: relative;
    min-height: 0;
    margin: 0 12px 12px;
}

.frame-slot {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: 16px;
    background: var(--paper);
    box-shadow: 0 24px 60px -24px rgba(2, 8, 60, .7);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px) scale(.99);
    transition: opacity .45s ease-out, transform .6s var(--ease), visibility 0s .45s;
}

body[data-status="live"] .frame-slot {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition-delay: 0s;
}

.frame-slot iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}

.state {
    position: absolute;
    inset: 0;
    display: none;
    overflow: auto;
    padding: clamp(20px, 5vw, 72px);
}

body[data-status="starting"] .state-starting,
body[data-status="ended"] .state-ended,
body[data-status="error"] .state-error {
    display: grid;
    align-content: end;
}

.state-copy {
    max-width: 21ch;
    font-size: clamp(46px, 8.2vw, 116px);
}

.display {
    font-size: 1em;
    font-weight: 700;
    line-height: .96;
    letter-spacing: -.05em;
    text-wrap: balance;
}

.lead {
    max-width: 46ch;
    margin-top: 22px;
    color: var(--on-field-soft);
    font-size: 17px;
    line-height: 1.5;
}

.state-copy .actions {
    margin-top: 26px;
}

.progress {
    position: relative;
    width: min(360px, 60vw);
    height: 3px;
    margin-top: 30px;
    overflow: hidden;
    border-radius: 3px;
    background: var(--glass);
}

.progress::after {
    content: '';
    position: absolute;
    inset: 0;
    width: 38%;
    border-radius: inherit;
    background: var(--on-field);
    animation: slide 1.3s var(--ease) infinite;
}

/* Shared controls */

.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 18px;
    border: 0;
    border-radius: 11px;
    background: var(--mist);
    color: var(--ink);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color .15s, box-shadow .15s, opacity .15s;
}

.btn:hover {
    background: #e2e7fb;
}

.btn svg {
    width: 16px;
    height: 16px;
    flex: none;
}

.btn-primary {
    background: var(--field);
    color: var(--on-field);
}

.btn-primary:hover {
    background: #1a3fdc;
}

.btn-on-field {
    background: var(--paper);
    color: var(--field);
}

.btn-on-field:hover {
    background: var(--paper);
    box-shadow: 0 0 0 4px rgba(255, 255, 255, .28);
}

.btn-ghost-field {
    background: var(--glass);
    color: var(--on-field);
}

.btn-ghost-field:hover {
    background: var(--glass-strong);
}

.btn[aria-disabled="true"],
.btn:disabled {
    opacity: .45;
    cursor: not-allowed;
}

.field {
    display: grid;
    gap: 6px;
}

.field-label {
    font-size: 14px;
    font-weight: 600;
}

.field input {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1.5px solid var(--line);
    border-radius: 10px;
    background: var(--paper);
    font-family: var(--font-code);
    font-size: 14px;
    transition: border-color .15s, box-shadow .15s;
}

.field input::placeholder,
.composer textarea::placeholder {
    color: #9aa1c2;
}

.field input:focus {
    border-color: var(--field);
    box-shadow: 0 0 0 3px rgba(11, 47, 199, .14);
    outline: 0;
}

.field input[aria-invalid="true"] {
    border-color: var(--danger);
}

.hint {
    color: var(--ink-soft);
    font-size: 13.5px;
    line-height: 1.45;
}

.hint code {
    font-family: var(--font-code);
    font-size: .93em;
}

.hint.is-warning {
    color: var(--danger);
}

/* Agent panel */

.panel-scrim {
    position: fixed;
    inset: 0;
    z-index: 4;
    background: rgba(4, 12, 64, .3);
    opacity: 0;
    visibility: hidden;
    transition: opacity .25s ease, visibility 0s .25s;
}

body[data-status="live"][data-panel="open"] .panel-scrim {
    opacity: 1;
    visibility: visible;
    transition: opacity .25s ease;
}


.agent-panel {
    position: absolute;
    top: 18px;
    right: 18px;
    bottom: 18px;
    z-index: 5;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-end;
    width: min(390px, calc(100% - 36px));
    pointer-events: none;
}

body:not([data-status="live"]) .agent-panel {
    display: none;
}

.agent-panel > * {
    pointer-events: auto;
}

.agent-panel[data-open="false"] .panel-card,
.agent-panel[data-open="true"] .panel-pill {
    display: none;
}

.panel-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    width: 100%;
    max-height: 100%;
    overflow: auto;
    padding: 18px;
    border-radius: 18px;
    background: var(--paper);
    color: var(--ink);
    box-shadow: 0 30px 80px -24px rgba(2, 8, 60, .6), 0 0 0 1px rgba(10, 16, 53, .06);
    animation: panel-in .28s var(--ease);
    overscroll-behavior: contain;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel-title {
    font-size: 21px;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -.035em;
}

.panel-min {
    display: grid;
    place-items: center;
    flex: none;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 50%;
    background: var(--mist);
    color: var(--ink-soft);
    transition: background-color .15s, color .15s;
}

.panel-min:hover {
    background: #e2e7fb;
    color: var(--ink);
}

.panel-min svg {
    width: 15px;
    height: 15px;
}

.panel-lead {
    margin-top: -6px;
    color: var(--ink-soft);
    font-size: 14px;
    line-height: 1.45;
}

.agents {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.agent-btn {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 10px;
    align-items: center;
    min-height: 58px;
    padding: 9px 12px;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    background: var(--paper);
    color: var(--ink);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: border-color .15s, background-color .15s, box-shadow .15s;
}

.agent-btn svg {
    grid-row: span 2;
    width: 20px;
    height: 20px;
    color: var(--field);
}

.agent-btn svg.agent-logo {
    width: 22px;
    height: 22px;
}

.agent-name {
    font-size: 14.5px;
    font-weight: 650;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agent-note {
    color: var(--ink-soft);
    font-size: 12.5px;
    line-height: 1.3;
}

.agent-btn:hover {
    border-color: var(--field);
    background: var(--mist);
}

.agent-btn:active {
    box-shadow: inset 0 0 0 1px var(--field);
}

.agent-btn[aria-disabled="true"],
.agent-btn:disabled {
    opacity: .45;
    cursor: not-allowed;
}

.agent-btn[aria-disabled="true"]:hover,
.agent-btn:disabled:hover {
    border-color: var(--line);
    background: var(--paper);
}

.agent-btn.is-done {
    border-color: var(--field);
    background: var(--mist);
}

.panel-pill {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    height: 44px;
    padding: 0 14px 0 16px;
    border: 0;
    border-radius: 999px;
    background: var(--paper);
    color: var(--field);
    font-size: 14.5px;
    font-weight: 650;
    box-shadow: 0 16px 40px -12px rgba(2, 8, 60, .6), 0 0 0 1px rgba(10, 16, 53, .06);
    animation: panel-in .28s var(--ease);
    transition: box-shadow .15s;
}

.panel-pill:hover {
    box-shadow: 0 16px 40px -12px rgba(2, 8, 60, .6), 0 0 0 4px rgba(255, 255, 255, .35);
}

.panel-pill svg {
    width: 15px;
    height: 15px;
}

.panel-pill .dot {
    background: var(--field);
    opacity: 1;
}

.agent-panel[data-agent="connected"] .panel-pill .dot {
    background: #12b886;
    box-shadow: 0 0 0 3px rgba(18, 184, 134, .2);
}

.composer {
    border: 1.5px solid var(--line);
    border-radius: 14px;
    background: var(--paper);
    transition: border-color .15s, box-shadow .15s;
}

.composer:focus-within {
    border-color: var(--field);
    box-shadow: 0 0 0 3px rgba(11, 47, 199, .14);
}

.composer textarea {
    display: block;
    width: 100%;
    min-height: 74px;
    padding: 13px 14px 10px;
    border: 0;
    border-radius: 13px 13px 0 0;
    background: none;
    outline: 0;
    resize: vertical;
    font-size: 15px;
    line-height: 1.5;
}

.included {
    border-top: 1px solid var(--line);
}

.included summary {
    display: flex;
    align-items: center;
    gap: 8px;
    width: fit-content;
    padding: 10px 14px;
    color: var(--ink-soft);
    font-size: 13.5px;
    cursor: pointer;
    list-style: none;
}

.included summary::-webkit-details-marker {
    display: none;
}

.included summary::before {
    content: '';
    width: 6px;
    height: 6px;
    border-right: 1.6px solid currentColor;
    border-bottom: 1.6px solid currentColor;
    transform: rotate(-45deg);
    transition: transform .15s;
}

.included[open] summary::before {
    transform: rotate(45deg);
}

.included summary:hover {
    color: var(--ink);
}

.included-text {
    max-height: 190px;
    margin: 0;
    padding: 0 14px 14px;
    overflow: auto;
    color: var(--ink-soft);
    font-family: var(--font-code);
    font-size: 12.5px;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.included-text mark {
    padding: 0 4px;
    border-radius: 4px;
    background: #d5ddff;
    color: var(--ink);
}

.included-text .key {
    color: var(--ink);
    font-weight: 600;
}

/* Motion */

@keyframes blink {
    to {
        opacity: .3;
    }
}

@keyframes slide {
    from {
        transform: translateX(-110%);
    }

    to {
        transform: translateX(275%);
    }
}

@keyframes panel-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
}

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

/* Small screens */

@media (max-width: 720px) {
    .brand-name,
    .bar-btn-label {
        display: none;
    }

    .bar-btn {
        width: 36px;
        padding: 0;
        justify-content: center;
    }

    .sid-value {
        max-width: 11ch;
    }
}

@media (max-width: 640px) {
    .bar {
        gap: 8px;
        padding: 8px 10px;
    }

    .stage {
        margin: 0 6px 6px;
    }

    .agent-panel {
        top: 8px;
        right: 8px;
        bottom: 8px;
        width: calc(100% - 16px);
    }

    .panel-card {
        max-height: 78%;
        padding: 16px 14px 14px;
    }

    .agent-btn {
        min-height: 52px;
        padding: 8px 10px;
        column-gap: 8px;
    }

    .agent-btn svg {
        width: 18px;
        height: 18px;
    }

    .agent-name {
        font-size: 14px;
        white-space: normal;
    }

    .agent-note {
        font-size: 12px;
    }
}
