:root {
    --ink: #111111;
    --paper: #ffffff;
    --canvas: #f7f7f7;
    --purple: #5e17eb;
    --purple-dark: #4310ad;
    --yellow: #ffde59;
    --pink: #ff5252;
    --teal: #4ecdc4;
    --blue: #6ab7ff;
    --mint: #a8e6cf;
    --muted: #5d5a54;
    --line: 4px solid var(--ink);
    --hard-shadow: 8px 8px 0 var(--ink);
    --small-shadow: 4px 4px 0 var(--ink);
    --display: ui-monospace, "SFMono-Regular", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;
    --body: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

html, body {
    margin: 0;
    min-height: 100%;
}

html {
    visibility: hidden;
    background: var(--canvas);
}

html[data-top-level="true"] {
    visibility: visible;
}

body {
    min-height: 100vh;
    min-height: 100svh;
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--body);
    line-height: 1.45;
}

button, input, textarea {
    font: inherit;
}

button, label, input[type="radio"] {
    -webkit-tap-highlight-color: transparent;
}

[hidden] {
    display: none !important;
}

.app-frame {
    width: min(1560px, 100%);
    min-height: 100vh;
    min-height: 100svh;
    margin: 0 auto;
    padding: clamp(0.75rem, 2vw, 1.75rem);
}

.hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    padding: clamp(1.25rem, 2.5vw, 2.25rem);
    background: var(--paper);
    border: var(--line);
    box-shadow: var(--hard-shadow);
}

.eyebrow,
.panel-kicker,
.provider-meta,
.empty-kicker {
    margin: 0 0 0.45rem;
    color: var(--purple);
    font-family: var(--display);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.hero h1,
.panel-header h2,
.empty-state h3 {
    margin: 0;
    font-family: var(--display);
    font-weight: 900;
    letter-spacing: -0.045em;
    line-height: 0.98;
    text-transform: uppercase;
}

.hero h1 {
    font-size: clamp(2rem, 5vw, 4.8rem);
}

.hero h1 span {
    color: var(--purple);
}

.hero-description {
    max-width: 760px;
    margin: 0.9rem 0 0;
    font-family: var(--display);
    font-size: clamp(0.86rem, 1.4vw, 1.05rem);
    font-weight: 650;
}

.hero-mark {
    display: grid;
    flex: 0 0 clamp(72px, 8vw, 108px);
    aspect-ratio: 1;
    place-items: center;
    background: var(--paper);
    border: var(--line);
}

.chat-glyph {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 68%;
    height: 58%;
    background: var(--purple);
    border: 3px solid var(--ink);
}

.chat-glyph::after {
    position: absolute;
    right: 7px;
    bottom: -11px;
    width: 14px;
    height: 14px;
    background: var(--purple);
    border-right: 3px solid var(--ink);
    border-bottom: 3px solid var(--ink);
    content: "";
    transform: skewY(35deg);
}

.chat-glyph span {
    z-index: 1;
    width: 4px;
    background: var(--ink);
}

.chat-glyph span:nth-child(1),
.chat-glyph span:nth-child(5) { height: 28%; }
.chat-glyph span:nth-child(2),
.chat-glyph span:nth-child(4) { height: 55%; }
.chat-glyph span:nth-child(3) { height: 82%; }

.status-rail {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    margin: 1.25rem 0;
    border: 3px solid var(--ink);
    background: var(--ink);
}

.status-rail span {
    flex: 1 1 160px;
    padding: 0.55rem 0.8rem;
    background: var(--yellow);
    border-right: 3px solid var(--ink);
    font-family: var(--display);
    font-size: 0.7rem;
    font-weight: 850;
    letter-spacing: 0.08em;
    text-align: center;
    text-transform: uppercase;
}

.status-rail span:nth-child(even) {
    background: var(--paper);
}

.status-rail span:last-child {
    border-right: 0;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(330px, 0.72fr) minmax(0, 1.6fr);
    gap: clamp(1rem, 2vw, 1.5rem);
    align-items: stretch;
}

.panel {
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: var(--paper);
    border: var(--line);
    box-shadow: var(--hard-shadow);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 92px;
    padding: 1rem 1.2rem;
    border-bottom: var(--line);
}

.panel-header h2 {
    font-size: clamp(1.35rem, 2.4vw, 2.1rem);
}

.panel-kicker {
    margin-bottom: 0.25rem;
}

.step-badge {
    display: grid;
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    place-items: center;
    background: var(--yellow);
    border: 3px solid var(--ink);
    font-family: var(--display);
    font-size: 1rem;
    font-weight: 900;
    box-shadow: 3px 3px 0 var(--ink);
}

.panel-body,
.conversation-body {
    min-height: 0;
}

.controls-body {
    padding: 1rem;
}

.form-section,
.characters-section {
    margin: 0 0 1rem;
    padding: 1rem;
    border: 3px solid var(--ink);
    background: var(--paper);
}

.form-section > legend,
.section-heading-row h3 {
    margin: 0;
    padding: 0;
    font-family: var(--display);
    font-size: 0.92rem;
    font-weight: 900;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.form-section > legend {
    padding: 0 0.4rem;
}

.provider-section {
    background: #f6f1ff;
}

.provider-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.7rem;
    margin-top: 0.35rem;
}

.provider-option {
    position: relative;
    cursor: pointer;
}

.provider-option input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.provider-copy {
    display: flex;
    min-height: 102px;
    flex-direction: column;
    justify-content: flex-end;
    padding: 0.75rem;
    background: var(--paper);
    border: 3px solid var(--ink);
    transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

.provider-copy strong {
    font-family: var(--display);
    font-size: 1rem;
    text-transform: uppercase;
}

.provider-copy small {
    color: var(--muted);
    font-family: var(--display);
    font-size: 0.7rem;
}

.provider-meta {
    margin-bottom: auto;
    color: var(--muted);
    font-size: 0.62rem;
}

.provider-option input:checked + .provider-copy {
    background: var(--yellow);
    box-shadow: var(--small-shadow);
    transform: translate(-2px, -2px);
}

.provider-option input:focus-visible + .provider-copy {
    outline: 4px solid var(--purple);
    outline-offset: 3px;
}

.provider-option:hover .provider-copy {
    box-shadow: 3px 3px 0 var(--ink);
    transform: translate(-1px, -1px);
}

.provider-details,
.security-note,
.call-estimate,
.run-status {
    font-size: 0.76rem;
    line-height: 1.5;
}

.provider-details {
    margin: 0.9rem 0 0;
    color: var(--muted);
}

.key-section {
    background: #fff9d9;
}

.section-heading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.8rem;
}

.section-heading-row > span {
    font-family: var(--display);
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.form-label {
    display: block;
    margin: 0 0 0.38rem;
    font-family: var(--display);
    font-size: 0.7rem;
    font-weight: 850;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.form-control {
    display: block;
    width: 100%;
    min-height: 46px;
    padding: 0.68rem 0.75rem;
    border: 3px solid var(--ink);
    border-radius: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--display);
    font-size: 0.82rem;
    outline: 0;
    transition: box-shadow 120ms ease, transform 120ms ease, background-color 120ms ease;
}

.form-control::placeholder {
    color: #77736b;
    opacity: 1;
}

.form-control:focus-visible {
    background: #fbf9ff;
    box-shadow: 4px 4px 0 var(--purple);
    transform: translate(-2px, -2px);
}

.form-control:disabled {
    background: #dedbd4;
    color: #65615b;
    cursor: not-allowed;
}

.security-note {
    margin: 0.8rem 0 0;
    padding: 0.75rem;
    background: var(--yellow);
    border: 2px solid var(--ink);
}

.security-note strong {
    font-family: var(--display);
    text-transform: uppercase;
}

.number-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.number-grid .form-control {
    text-align: center;
}

.call-estimate {
    margin: 0.75rem 0 0;
    padding: 0.55rem 0.65rem;
    background: var(--ink);
    color: var(--paper);
    font-family: var(--display);
    font-weight: 700;
}

.characters-section {
    padding: 0;
    border: 0;
}

.cast-heading {
    padding: 0.9rem 1rem;
    margin: 0;
    background: var(--ink);
    color: var(--paper);
}

#promptsContainer {
    display: grid;
    gap: 0.8rem;
    padding-top: 0.8rem;
}

.character-config {
    padding: 0.9rem;
    border: 3px solid var(--ink);
    background: #f5f5f2;
}

.character-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.55rem;
    border-bottom: 3px solid var(--ink);
}

.character-heading h4 {
    margin: 0;
    font-family: var(--display);
    font-size: 0.85rem;
    font-weight: 900;
    text-transform: uppercase;
}

.character-index {
    display: grid;
    width: 28px;
    height: 28px;
    place-items: center;
    background: var(--purple);
    border: 2px solid var(--ink);
    color: var(--paper);
    font-family: var(--display);
    font-size: 0.68rem;
    font-weight: 900;
}

.field-group + .field-group {
    margin-top: 0.7rem;
}

.character-config textarea {
    min-height: 98px;
    resize: vertical;
}

.controls-footer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    padding: 0.8rem;
    background: var(--paper);
    border: 3px solid var(--ink);
    box-shadow: 0 -5px 0 var(--yellow);
}

.button-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.65rem;
}

.btn {
    min-height: 48px;
    padding: 0.7rem 1rem;
    border: 3px solid var(--ink);
    border-radius: 0;
    cursor: pointer;
    font-family: var(--display);
    font-size: 0.75rem;
    font-weight: 900;
    letter-spacing: 0.035em;
    text-transform: uppercase;
    transition: transform 100ms ease, box-shadow 100ms ease, background-color 100ms ease;
}

.btn-primary {
    background: var(--purple);
    color: var(--paper);
    box-shadow: var(--small-shadow);
}

.btn-danger {
    background: var(--pink);
    color: var(--ink);
}

.btn:hover:not(:disabled) {
    box-shadow: 2px 2px 0 var(--ink);
    transform: translate(2px, 2px);
}

.btn:active:not(:disabled) {
    box-shadow: none;
    transform: translate(4px, 4px);
}

.btn:focus-visible {
    outline: 4px solid var(--purple);
    outline-offset: 3px;
}

.btn:disabled {
    cursor: not-allowed;
    filter: grayscale(1);
    opacity: 0.52;
}

.run-status {
    min-height: 1.15rem;
    margin: 0.65rem 0 0;
    font-family: var(--display);
    font-weight: 700;
}

.run-status[data-tone="success"] { color: #08735f; }
.run-status[data-tone="warning"] { color: #8b5000; }
.run-status[data-tone="danger"] { color: #b00020; }

.conversation-panel {
    display: flex;
    flex-direction: column;
}

.conversation-header {
    background: var(--yellow);
}

.room-state {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 0.65rem;
    background: var(--paper);
    border: 2px solid var(--ink);
    font-family: var(--display);
    font-size: 0.65rem;
    font-weight: 900;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.room-state span {
    width: 10px;
    height: 10px;
    background: #21b75b;
    border: 2px solid var(--ink);
}

.room-state > span:last-child {
    width: auto;
    height: auto;
    background: transparent;
    border: 0;
}

.room-state[data-state="idle"] > span:first-child { background: #99948b; }
.room-state[data-state="running"] > span:first-child { background: #21b75b; }
.room-state[data-state="success"] > span:first-child { background: var(--teal); }
.room-state[data-state="warning"] > span:first-child { background: var(--yellow); }
.room-state[data-state="danger"] > span:first-child { background: var(--pink); }

.conversation-body {
    display: flex;
    flex: 1;
    padding: 1rem;
    background: #eeebe3;
}

.chat-window {
    display: flex;
    width: 100%;
    min-height: 420px;
    flex: 1;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
    padding: clamp(0.8rem, 2vw, 1.4rem);
    background: var(--paper);
    border: 3px solid var(--ink);
    scrollbar-color: var(--purple) var(--paper);
    scrollbar-width: thin;
}

.chat-window::-webkit-scrollbar {
    width: 10px;
}

.chat-window::-webkit-scrollbar-thumb {
    background: var(--purple);
    border: 2px solid var(--ink);
}

.chat-window::-webkit-scrollbar-track {
    background: var(--paper);
    border-left: 2px solid var(--ink);
}

.empty-state {
    display: grid;
    max-width: 560px;
    min-height: 100%;
    margin: auto;
    place-items: center;
    align-content: center;
    padding: clamp(1.5rem, 5vw, 4rem);
    text-align: center;
}

.empty-icon {
    display: grid;
    width: 72px;
    height: 72px;
    margin-bottom: 1.2rem;
    place-items: center;
    background: var(--purple);
    border: 4px solid var(--ink);
    box-shadow: 6px 6px 0 var(--ink);
    color: var(--paper);
    font-family: var(--display);
    font-size: 1.4rem;
    font-weight: 900;
}

.empty-kicker {
    margin-bottom: 0.6rem;
}

.empty-state h3 {
    font-size: clamp(1.45rem, 3vw, 2.5rem);
}

.empty-state > p:last-child {
    max-width: 390px;
    margin: 0.9rem 0 0;
    color: var(--muted);
    font-family: var(--display);
    font-size: 0.8rem;
}

.message {
    display: grid;
    grid-template-columns: minmax(88px, 118px) minmax(0, 1fr);
    gap: 0.85rem;
    align-items: start;
    width: 100%;
    animation: message-in 180ms ease-out;
}

.message-sender {
    padding-top: 0.65rem;
    font-family: var(--display);
    font-size: 0.72rem;
    font-weight: 900;
    line-height: 1.25;
    overflow-wrap: anywhere;
    text-align: right;
    text-transform: uppercase;
}

.message-wrapper {
    min-width: 0;
}

.message-bubble {
    padding: 0.9rem 1rem;
    border: 3px solid var(--ink);
    border-left-width: 10px;
    background: var(--paper);
    box-shadow: 3px 3px 0 var(--ink);
}

.message[data-agent="1"] .message-bubble { border-left-color: var(--pink); }
.message[data-agent="2"] .message-bubble { border-left-color: var(--teal); }
.message[data-agent="3"] .message-bubble { border-left-color: var(--blue); }
.message[data-agent="4"] .message-bubble { border-left-color: var(--mint); }
.message[data-agent="5"] .message-bubble { border-left-color: var(--yellow); }

.message-content {
    color: var(--ink);
    font-size: 0.95rem;
    line-height: 1.6;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.message-timestamp {
    margin: 0.45rem 0 0 0.2rem;
    color: var(--muted);
    font-family: var(--display);
    font-size: 0.63rem;
    font-weight: 700;
    text-transform: uppercase;
}

.alert {
    padding: 0.85rem 1rem;
    border: 3px solid var(--ink);
    font-family: var(--display);
    font-size: 0.78rem;
    font-weight: 750;
    box-shadow: var(--small-shadow);
}

.alert-danger { background: #ffb1bd; }
.alert-warning { background: var(--yellow); }
.noscript-alert { margin: 1rem; }

@keyframes message-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 900px) {
    .workspace {
        height: max(580px, calc(100svh - 240px));
    }

    .controls-panel {
        display: flex;
        flex-direction: column;
    }

    .controls-body,
    .chat-window {
        overflow-y: auto;
    }

    .controls-body {
        flex: 1;
    }
}

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

    .conversation-panel {
        min-height: 68vh;
    }

    .controls-footer {
        position: static;
    }

    body.is-running .controls-footer {
        position: fixed;
        right: 0.75rem;
        bottom: 0.75rem;
        left: 0.75rem;
        z-index: 20;
        max-width: 720px;
        margin: 0 auto;
        box-shadow: 6px 6px 0 var(--ink);
    }
}

@media (max-width: 620px) {
    .app-frame {
        padding: 0.65rem 0.65rem 1.25rem;
    }

    .hero {
        align-items: flex-start;
        padding: 1rem;
        box-shadow: 5px 5px 0 var(--ink);
    }

    .hero-mark {
        flex-basis: 58px;
    }

    .eyebrow {
        font-size: 0.6rem;
    }

    .hero-description {
        font-size: 0.76rem;
    }

    .status-rail span {
        flex-basis: 50%;
        border-bottom: 3px solid var(--ink);
    }

    .status-rail span:nth-child(2) {
        border-right: 0;
    }

    .status-rail span:nth-child(n+3) {
        border-bottom: 0;
    }

    .panel {
        box-shadow: 5px 5px 0 var(--ink);
    }

    .panel-header {
        min-height: 78px;
        padding: 0.85rem;
    }

    .step-badge {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
    }

    .controls-body,
    .conversation-body {
        padding: 0.7rem;
    }

    .provider-grid {
        grid-template-columns: 1fr;
    }

    .provider-copy {
        min-height: 84px;
    }

    .button-row {
        grid-template-columns: 1fr;
    }

    .message {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.35rem;
    }

    .message-sender {
        padding: 0;
        text-align: left;
    }

    .chat-window {
        min-height: 54vh;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
