/* The live demo: three machines — a Telnet client, NetGet, the model — and what joins them.
 *
 * Desktop: Telnet (left half) and the model (right half) side by side and the same height,
 * NetGet below them at full width, and the step list and the notes as two columns under
 * NetGet. Narrow screens stack everything: steps, Telnet, NetGet, the model, notes. Nothing in
 * the demo scrolls inside itself: the dashboard has a fixed height that xterm.js fits, the
 * model panel grows with what it shows, and the Telnet terminal fills whatever height the
 * model panel gives the row (never less than its own floor). */

.hero-demo { padding-bottom: 0.5rem; }

.demo {
    margin: 0 auto;
    max-width: 1320px;
    padding-inline: 1rem;
}

.demo-banner {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.6rem 1rem;
    margin: 0.5rem 0 1rem;
    color: var(--muted);
    font-size: 0.9rem;
}
.demo-banner[hidden] { display: none; }

.muted { color: var(--text); opacity: 0.55; }
.spacer { flex: 1; }

/* ---- the three marks, shared by the diagram and the machines ---------------------- */

.section-how { max-width: 780px; margin: 0 auto; padding: 0.5rem 1.25rem 1rem; }

.dg .box.client { stroke: var(--cyan); stroke-width: 2; }
.dg .client-t { fill: var(--cyan); }
.dg .box.model { stroke: var(--yellow); stroke-width: 2; }
.dg .model-t { fill: var(--yellow); }

.mark {
    font-family: var(--mono);
    font-size: 0.85em;
    padding: 0.05em 0.45em;
    border-radius: 6px;
    border: 1.5px solid currentColor;
    white-space: nowrap;
}
.mark-client { color: var(--cyan); border-style: dashed; }
.mark-netget { color: var(--green); }
.mark-model { color: var(--yellow); }

/* ---- layout --------------------------------------------------------------------------- */

.demo-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
        "telnet model"
        "cable1 cable2"
        "netget netget"
        "steps  notes";
    column-gap: 1.25rem;
    align-items: start;
}

/* The top row is even: both machines stretch to the taller one. */
.machine-client, .machine-model { align-self: stretch; display: flex; flex-direction: column; }

.machine-client { grid-area: telnet; }
.demo-steps { grid-area: steps; }
.cable-client { grid-area: cable1; }
.machine-netget { grid-area: netget; }
.cable-model { grid-area: cable2; }
.demo-notes { grid-area: notes; }
.machine-model { grid-area: model; }

@media (max-width: 900px) {
    .demo-grid {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "steps" "telnet" "cable1" "netget" "cable2" "model" "notes";
    }
}

/* ---- machines ------------------------------------------------------------------------- */

.machine {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--panel);
    box-shadow: var(--shadow);
    overflow: hidden;
    min-width: 0;
}

.machine-netget { border-color: var(--green); border-width: 2px; }
.machine-client { border-color: var(--cyan); border-style: dashed; border-width: 2px; }
.machine-model { border-color: var(--yellow); border-width: 2px; }
.machine-netget .machine-label { color: var(--green); }
.machine-client .machine-label { color: var(--cyan); }
.machine-model .machine-label { color: var(--yellow); }
.machine-netget .machine-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.machine-client .machine-dot { background: var(--cyan); box-shadow: 0 0 6px var(--cyan); }
.machine-model .machine-dot { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }

.machine-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.9rem;
    font-family: var(--mono);
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--panel-2);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.machine-label .muted { font-weight: 400; }

.machine-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
}

.screen {
    background: var(--term-bg);
    padding: 0.5rem;
    margin: 0.6rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    overflow: hidden;
}

.term-host { background: var(--term-bg); }

/* Heights that xterm.js fits to (see makeTerm in js/demo.js). The dashboard's is fixed. The
   Telnet terminal has a floor and otherwise fills its machine, which the model beside it may
   stretch: the terminal is positioned out of the flow, so what it has drawn never holds the
   row open once the model panel shrinks again. */
#dash-term { height: clamp(360px, 66vh, 600px); }
.machine-client .screen { flex: 1 1 auto; display: flex; flex-direction: column; }
.machine-client .term-host { flex: 1 1 auto; position: relative; min-height: clamp(200px, 34vh, 300px); }
#telnet-term { position: absolute; inset: 0; }

@media (max-width: 900px) {
    #dash-term { height: clamp(320px, 56vh, 440px); }
    .machine-client .term-host { min-height: clamp(180px, 30vh, 260px); }
}

/* A terminal scrolls by wheel and keys, never by a bar. */
.demo .xterm .xterm-viewport { background: transparent !important; scrollbar-width: none; }
.demo .xterm .xterm-viewport::-webkit-scrollbar { display: none; }

.conn-badge {
    font-family: var(--mono);
    font-size: 0.72rem;
    font-weight: 500;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--muted);
    white-space: nowrap;
}
.conn-badge.is-up { border-color: var(--green); color: var(--green); }

.machine-base {
    padding: 0.4rem 0.9rem 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    font-size: 0.85rem;
}

.base-row {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.base-key {
    font-family: var(--mono);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    min-width: 6.5rem;
}

.base-row.keys { color: var(--muted); }

.demo kbd {
    font-family: var(--mono);
    font-size: 0.72rem;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 0 0.3rem;
    color: var(--text);
}

/* ---- what is happening, under NetGet (above everything on a narrow screen) ------------- */

.demo-steps {
    list-style: none;
    counter-reset: step;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    padding: 0.4rem 0.2rem;
    margin: 1.4rem 0 0;
    font-size: 0.92rem;
    color: var(--muted);
}

.demo-steps li {
    counter-increment: step;
    position: relative;
    padding-left: 1.9rem;
}

.demo-steps li::before {
    content: counter(step);
    position: absolute;
    left: 0;
    top: 0.15em;
    font-family: var(--mono);
    font-size: 0.75rem;
    width: 1.3rem;
    height: 1.3rem;
    line-height: 1.2rem;
    text-align: center;
    border-radius: 50%;
    border: 1px solid var(--border);
    color: var(--muted);
}

.demo-steps li.is-done { color: var(--text); }
.demo-steps li.is-done::before { content: "✓"; border-color: var(--green); color: var(--green); }
.demo-steps b { color: var(--yellow); font-weight: 600; }
.demo-steps code { font-family: var(--mono); font-size: 0.85em; }

@media (max-width: 900px) {
    .demo-steps { margin: 0 0 0.8rem; font-size: 0.88rem; }
}

/* ---- the cables: Telnet and the model, each down to NetGet (on a narrow screen, NetGet
   down to the model) ------------------------------------------------------------------- */

.cable {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    height: 2.6rem;
}

.cable-line {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    border-left: 2px dashed var(--muted);
}

.cable-tag {
    position: relative;
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--muted);
    background: var(--bg);
    padding: 0 0.4rem;
}

.cable-client .cable-line { border-color: var(--cyan); }
.cable-client .cable-tag { color: var(--cyan); }
.cable-model .cable-line { border-color: var(--yellow); }
.cable-model .cable-tag { color: var(--yellow); }

/* ---- controls ------------------------------------------------------------------------- */

.btn {
    font: inherit;
    font-size: 0.85rem;
    padding: 0.35rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    cursor: pointer;
}

.btn:hover { border-color: var(--cyan); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--cyan); color: #0b0e14; border-color: transparent; font-weight: 600; }
.btn[hidden] { display: none; }

.demo input[type="text"],
.demo input[type="number"],
.demo select,
.demo textarea {
    font: inherit;
    font-family: var(--mono);
    font-size: 0.85rem;
    background: var(--term-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.35rem 0.55rem;
    min-width: 0;
    max-width: 100%;
}

.demo select[hidden] { display: none; }
.demo textarea { width: 100%; box-sizing: border-box; resize: vertical; }
.demo label { font-size: 0.85rem; color: var(--muted); display: inline-flex; gap: 0.35rem; align-items: center; }

.server-list { display: flex; flex-wrap: wrap; gap: 0.4rem; font-size: 0.8rem; align-items: center; }

.server-chip {
    font-family: var(--mono);
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--muted);
}

.server-chip.is-up { border-color: var(--green); color: var(--text); }
.server-chip small { color: var(--muted); }

/* ---- the model ------------------------------------------------------------------------ */

/* The header carries the model control: the title, the model select, and the one button a
   download needs. The select takes the rest of the row and shrinks before anything wraps. */
.llm-header select { flex: 1 1 12rem; width: 0; font-size: 0.78rem; font-weight: 400; padding: 0.2rem 0.45rem; margin-left: 0.3rem; }
.llm-header .btn { font-size: 0.76rem; padding: 0.22rem 0.6rem; white-space: nowrap; }
.llm-source { display: flex; flex-direction: column; gap: 0.4rem; padding: 0.55rem 0.9rem 0.1rem; font-size: 0.85rem; }
.llm-status { font-size: 0.78rem; color: var(--muted); }
.llm-status:empty { display: none; }
.llm-status b { color: var(--yellow); font-weight: 600; }

.llm-progress { height: 6px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); overflow: hidden; }
.llm-progress[hidden] { display: none; }
.llm-progress span { display: block; height: 100%; width: 0; background: var(--yellow); transition: width 0.2s; }

.screen-model { flex: 1 1 auto; padding: 0.6rem 0.2rem 0.2rem; font-size: 0.82rem; }

.llm-idle { padding: 0.2rem 0.6rem 0.5rem; color: var(--muted); font-size: 0.85rem; }

.llm-head { display: flex; gap: 0.6rem; align-items: baseline; padding: 0 0.6rem 0.4rem; font-family: var(--mono); font-size: 0.75rem; flex-wrap: wrap; }
.llm-id { color: var(--text); font-weight: 700; }
.llm-kind { color: var(--cyan); }
.llm-meta { color: var(--muted); overflow-wrap: anywhere; }
.llm-state { margin-left: auto; color: var(--yellow); }
.llm-queue { color: var(--muted); }

.llm-working { display: flex; gap: 0.55rem; align-items: baseline; padding: 0 0.6rem 0.5rem; color: var(--text); overflow-wrap: anywhere; }
.llm-working::before { content: ""; flex: none; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--green); animation: dotpulse 1.2s ease-out infinite; align-self: center; }
.llm-working code { font-family: var(--mono); font-size: 0.78rem; color: var(--cyan); }
.llm-note { padding: 0 0.6rem 0.5rem; color: var(--yellow); font-size: 0.78rem; }

/* What the model writes while it answers (liveView in js/demo.js): its reasoning, then the
   answer. Both blocks have a fixed height and follow the newest line, so the panel does not
   grow with the text; they scroll (wheel, touch) without showing a scrollbar. */
.llm-think, .llm-answer { margin: 0 0.6rem 0.5rem; border: 1px solid var(--border); border-radius: 8px; min-width: 0; }
.llm-think[hidden], .llm-answer[hidden] { display: none; }
.llm-think-head {
    display: flex; gap: 0.4rem; align-items: baseline; width: 100%;
    font: inherit; font-size: 0.78rem; text-align: left; color: var(--muted);
    background: none; border: 0; padding: 0.3rem 0.6rem; cursor: pointer;
}
.llm-think-head:focus-visible { outline: 2px solid var(--cyan); outline-offset: -2px; border-radius: 8px; }
.llm-think:not(.is-done) .llm-think-label { color: var(--text); animation: thinkpulse 1.6s ease-in-out infinite; }
.llm-think-caret { margin-left: auto; }
/* Heights are whole lines (line-height 1.3): four of thinking, three of answer. */
.llm-think-body, .llm-answer-body {
    box-sizing: content-box;
    margin: 0;
    padding: 0.35rem 0.6rem 0.4rem;
    height: 5.2em;
    overflow-y: auto;
    scrollbar-width: none;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.3;
    border-top: 1px dashed var(--border);
}
.llm-think-body::-webkit-scrollbar, .llm-answer-body::-webkit-scrollbar { display: none; }
.llm-think-body { color: var(--muted); font-size: 0.78rem; font-style: italic; }
.llm-think.is-collapsed .llm-think-body { display: none; }
.llm-answer-label { padding: 0.3rem 0.6rem; color: var(--muted); font-size: 0.78rem; }
.llm-answer-body { height: 3.9em; font-family: var(--mono); font-size: 0.72rem; color: var(--text); }

@keyframes thinkpulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .llm-think:not(.is-done) .llm-think-label { animation: none; } }

.llm-prompt { margin: 0 0.6rem 0.5rem; border: 1px solid var(--border); border-radius: 8px; }
.llm-prompt summary { cursor: pointer; padding: 0.3rem 0.6rem; color: var(--muted); font-size: 0.78rem; }
.llm-prompt pre {
    margin: 0;
    padding: 0.45rem 0.6rem;
    font-family: var(--mono);
    font-size: 0.72rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    border-top: 1px dashed var(--border);
}
.llm-role { display: block; padding: 0.2rem 0.6rem 0; font-family: var(--mono); font-size: 0.7rem; text-transform: uppercase; color: var(--muted); }

.llm-reply-label { padding: 0.35rem 0.6rem 0.2rem; font-size: 0.78rem; color: var(--muted); }
.llm-hint { margin: 0; padding: 0 0.6rem 0.4rem; color: var(--muted); font-size: 0.78rem; }
.llm-hint code { font-family: var(--mono); }
.llm-input { margin: 0 0.6rem 0.4rem; width: calc(100% - 1.2rem); }
.llm-actions { display: flex; gap: 0.4rem; padding: 0 0.6rem 0.6rem; }

/* ---- the "you are the model" composer (js/composer.js) ------------------------------- */

.cmp-tabs { display: flex; gap: 0.25rem; padding: 0 0.6rem 0.4rem; }
.cmp-tabs button {
    font: inherit; font-size: 0.78rem; padding: 0.2rem 0.6rem; border-radius: 6px; cursor: pointer;
    border: 1px solid var(--border); background: transparent; color: var(--muted);
}
.cmp-tabs button.is-active { background: var(--panel); color: var(--text); border-color: var(--yellow); }
.cmp-tabs button:focus-visible, .cmp-entry :focus-visible, .llm-actions .btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 1px; }

.cmp-form { display: flex; flex-direction: column; gap: 0.5rem; padding: 0 0.6rem 0.5rem; }
.cmp-form[hidden], .cmp-raw[hidden] { display: none; }
.cmp-entry { margin: 0; padding: 0.45rem 0.55rem 0.5rem; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); min-width: 0; }
.cmp-entry legend { padding: 0 0.3rem; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.cmp-pick { display: flex; gap: 0.4rem; align-items: center; }
.cmp-pick select { flex: 1 1 auto; width: 100%; }
.cmp-about { margin: 0.35rem 0 0.2rem; color: var(--muted); font-size: 0.78rem; }
.cmp-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.cmp-field { display: grid; grid-template-columns: minmax(7rem, max-content) minmax(0, 1fr); gap: 0.1rem 0.6rem; align-items: start; padding: 0.3rem 0; border-top: 1px dashed var(--border); }
.cmp-field > label { display: block; padding-top: 0.3rem; color: var(--text); font-size: 0.8rem; }
.cmp-field > label code { font-family: var(--mono); }
.cmp-control { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; min-width: 0; }
.cmp-control input[type="text"], .cmp-control input[type="number"], .cmp-control select, .cmp-control textarea { width: 100%; box-sizing: border-box; }
.cmp-kind-bool .cmp-control { padding-top: 0.3rem; }
.cmp-desc { grid-column: 2; color: var(--muted); font-size: 0.74rem; }
.cmp-field-error { color: var(--red); }
.cmp-req { color: var(--yellow); margin-left: 0.1rem; }
.cmp-type { font-family: var(--mono); font-size: 0.7rem; color: var(--cyan); display: block; }
.cmp-dim { color: var(--muted); font-size: 0.76rem; margin: 0.3rem 0 0; }
.cmp-crlf { font-size: 0.72rem !important; }
.cmp-unset { font: inherit; font-size: 0.72rem; background: none; border: none; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 0; }
.demo .cmp-control [aria-invalid="true"] { border-color: var(--red); }
.cmp-schema { margin-top: 0.4rem; }
.cmp-schema summary { cursor: pointer; color: var(--muted); font-size: 0.74rem; }
.cmp-schema pre { margin: 0.3rem 0 0; padding: 0.45rem 0.6rem; font-family: var(--mono); font-size: 0.72rem; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--term-bg); }
.cmp-add { align-self: flex-start; }

.cmp-raw { padding: 0; }
.cmp-raw-input[aria-invalid="true"] { border-color: var(--red); }
.cmp-raw-status { padding: 0 0.6rem 0.4rem; font-size: 0.74rem; color: var(--muted); }
.cmp-raw-status.is-bad { color: var(--red); }
.cmp-raw-status.is-ok { color: var(--green); }
.cmp-error { padding: 0 0.6rem; color: var(--red); font-size: 0.78rem; }
.cmp-error:empty { display: none; }
.llm-actions { flex-wrap: wrap; }

@media (max-width: 600px) {
    .cmp-field { grid-template-columns: minmax(0, 1fr); }
    .cmp-desc { grid-column: 1; }
}

/* ---- notes ---------------------------------------------------------------------------- */

.demo-notes {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    margin-top: 1.4rem;
    padding: 0.4rem 0.2rem;
    font-size: 0.88rem;
    color: var(--muted);
}

.demo-notes strong { color: var(--text); display: block; margin-bottom: 0.2rem; }
.demo-notes code { font-family: var(--mono); font-size: 0.8rem; }

@media (max-width: 900px) {
    .demo-notes { margin-top: 1.2rem; }
}
