/* Interactive skill composition demo.

   Laid out to fill its window: standalone it is the browser window, embedded
   it is the fixed box on the project page. The stage takes the golden major
   width; the panel keeps its tabs and footer fixed and scrolls its body, so
   switching modes never changes the demo's size. Tokens mirror the page's
   theme; demo.js syncs data-theme from the embedding page. */

:root {
    --bg: #F8FAF9;
    --text: #111;
    --muted: rgba(17, 17, 17, 0.6);
    --panel: #f2f4f3;
    --field: #fff;
    --border: #dde2df;
    --accent: #b25e17;
    --on-accent: #fff;
    --manual: #16847e;
    --font: et-book, Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Code", "Fira Mono", Menlo, monospace;
    --ui: system-ui, -apple-system, "Segoe UI", sans-serif;
    --stage: radial-gradient(130% 95% at 50% 30%, #fbfcfb 0%, #eef1ef 45%, #d7ddd9 78%, #c5ccc8 100%);
    color-scheme: light;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #161817;
    --text: #e2e2e0;
    --muted: rgba(226, 226, 224, 0.6);
    --panel: #1c1e1d;
    --field: #232625;
    --border: #2f3331;
    --accent: #e39a4f;
    --on-accent: #161817;
    --manual: #5cc8c2;
    --stage: radial-gradient(130% 95% at 50% 30%, #30322f 0%, #262826 45%, #1b1d1c 78%, #131514 100%);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #161817;
        --text: #e2e2e0;
        --muted: rgba(226, 226, 224, 0.6);
        --panel: #1c1e1d;
        --field: #232625;
        --border: #2f3331;
        --accent: #e39a4f;
        --on-accent: #161817;
        --manual: #5cc8c2;
        --stage: radial-gradient(130% 95% at 50% 30%, #30322f 0%, #262826 45%, #1b1d1c 78%, #131514 100%);
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.4;
}

button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

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

.demo {
    height: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1.618fr) minmax(19rem, 1fr);
}

/* ---------------------------------------------------------------- stage */

.demo-stage {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: var(--stage);
}

.demo-stage canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
}

.stage-top {
    position: absolute;
    z-index: 2;
    top: 0.7rem;
    left: 0.8rem;
    right: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.8rem;
    pointer-events: none;
}

.demo-status {
    padding: 0.28rem 0.7rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--bg) 72%, transparent);
    backdrop-filter: blur(6px);
    font-family: var(--mono);
    font-size: 0.72rem;
    letter-spacing: 0.02em;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
}

.demo-hud {
    display: grid;
    grid-template-columns: max-content max-content;
    column-gap: 0.6rem;
    row-gap: 0.05rem;
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    background: color-mix(in srgb, var(--bg) 72%, transparent);
    backdrop-filter: blur(6px);
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--muted);
}

.demo-hud b { color: var(--text); font-weight: 600; }

/* instruction bar at the foot of the stage; examples appear on hover/focus */
.demo-say {
    position: absolute;
    z-index: 2;
    left: 50%;
    bottom: 0.9rem;
    transform: translateX(-50%);
    width: min(92%, 32rem);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.say-examples { order: 1; }
.say-out { order: 2; }
.say-bar { order: 3; }

.say-bar {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: color-mix(in srgb, var(--panel) 86%, transparent);
    backdrop-filter: blur(8px);
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.12);
}

.say-bar input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.38rem 0.75rem;
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.98rem;
    outline: none;
}

.say-bar input::placeholder { color: var(--muted); }

.say-go {
    padding: 0.38rem 1rem;
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: var(--on-accent);
    font-size: 0.95rem;
    cursor: pointer;
}

.say-examples {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.3rem;
    opacity: 0;
    transform: translateY(4px);
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.demo-say:hover .say-examples,
.demo-say:focus-within .say-examples {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.phrase-eg {
    padding: 0.16rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: color-mix(in srgb, var(--panel) 90%, transparent);
    color: var(--muted);
    font-size: 0.82rem;
    cursor: pointer;
}

.phrase-eg:hover { color: var(--text); border-color: var(--accent); }

.say-out {
    min-height: 1em;
    text-align: center;
    font-family: var(--mono);
    font-size: 0.74rem;
    color: var(--manual);
}

/* loading / error overlay */
.demo-overlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    padding: 1rem;
    background: color-mix(in srgb, var(--bg) 84%, transparent);
    text-align: center;
    transition: opacity 0.3s ease;
}

.demo-overlay.is-hidden { opacity: 0; pointer-events: none; }
.demo-overlay.is-error { background: color-mix(in srgb, var(--bg) 92%, #c0392b); }

.demo-progress {
    width: min(60%, 24rem);
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    overflow: hidden;
}

.demo-progress-bar {
    width: 0%;
    height: 100%;
    background: var(--accent);
    transition: width 0.2s ease;
}

.demo-overlay-text {
    max-width: 34rem;
    font-size: 0.95rem;
    color: var(--muted);
}

/* ---------------------------------------------------------------- panel */

.demo-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    border-left: 1px solid var(--border);
    background: var(--panel);
}

.demo-modes {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.2rem;
    margin: 0.8rem 0.9rem 0.3rem;
    padding: 0.2rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
}

.mode-btn {
    padding: 0.36rem 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font-size: 0.98rem;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.mode-btn:hover { color: var(--text); }
.mode-btn.is-active { background: var(--accent); color: var(--on-accent); }

.panel-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 0.2rem 0.9rem 0.9rem;
    scrollbar-width: thin;
}

.panel-foot {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.6rem 0.9rem 0.75rem;
    border-top: 1px solid var(--border);
}

.panel-label {
    margin: 0.85rem 0 0.4rem;
    font-family: var(--mono);
    font-size: 0.66rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.panel-note {
    margin: 0.8rem 0 0;
    font-size: 0.82rem;
    line-height: 1.4;
    color: var(--muted);
}

/* base skill: filled pills; compositions of that base: outline chips */
.seg,
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.seg-btn,
.chip-btn,
.chip.is-button {
    padding: 0.3rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--field);
    color: var(--text);
    font-size: 0.93rem;
    line-height: 1.2;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.seg-btn:hover,
.chip-btn:hover,
.chip.is-button:hover { border-color: var(--accent); }

.seg-btn.is-active {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--on-accent);
}

.chip-btn {
    background: transparent;
    font-size: 0.9rem;
}

.chip-btn.is-active {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 15%, transparent);
}

.chip.is-button { font-size: 0.86rem; }

.row-blurb {
    margin: 0.65rem 0 0.1rem;
    font-size: 0.9rem;
    line-height: 1.4;
    color: var(--muted);
}

/* ---------------------------------------------------------------- spectral directions (steering sliders) */

.demo-knobs {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    margin: 0.8rem 0 0.4rem;
}

.demo-knobs-more { margin: 0.6rem 0 0.2rem; }

.knob { display: flex; flex-direction: column; gap: 0.2rem; }

.knob-head {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.knob-title { font-size: 1rem; }
.knob-hint { flex: 1 1 auto; font-size: 0.78rem; color: var(--muted); }

.knob-value {
    min-width: 3.4em;
    font-family: var(--mono);
    font-size: 0.95rem;
    text-align: right;
}

.knob-track {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr) max-content;
    align-items: center;
    gap: 0.5rem;
}

.knob-min,
.knob-max {
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--muted);
}

input[type="range"] {
    width: 100%;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.knob.is-manual input[type="range"] { accent-color: var(--manual); }
.knob.is-manual .knob-value { color: var(--manual); }

.knob-primary .knob-title { font-size: 1.2rem; font-weight: 600; }
.knob-primary .knob-value { font-size: 1.25rem; }
.knob-primary input[type="range"] { height: 2.2rem; }

.chk {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.88rem;
    color: var(--muted);
    cursor: pointer;
}

.chk-hint { opacity: 0.75; }

.demo-more { margin-top: 0.6rem; }

.demo-more summary {
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--muted);
}

/* ---------------------------------------------------------------- mix */

.mix-selects {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.35rem;
}

.pick {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    min-width: 0;
    padding: 0 0 0 0.6rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--field);
}

.pick:hover { border-color: var(--accent); }

.pick > span {
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--accent);
}

.pick select {
    width: 100%;
    min-width: 0;
    padding: 0.32rem 1.5rem 0.32rem 0.1rem;
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    outline: none;
}

.pick::after {
    content: "";
    position: absolute;
    right: 0.7rem;
    top: 50%;
    width: 0.42rem;
    height: 0.42rem;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: translateY(-70%) rotate(45deg);
    pointer-events: none;
}

#mix-pad {
    display: block;
    width: 100%;
    max-width: 300px;
    height: auto;
    margin: 0.6rem auto 0;
    cursor: crosshair;
    touch-action: none;
}

.mix-weights {
    min-height: 1.2em;
    font-family: var(--mono);
    font-size: 0.78rem;
    text-align: center;
}

/* ---------------------------------------------------------------- chain */

.skill-palette {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(6.2rem, 1fr));
    gap: 0.35rem;
}

.skill-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.05rem;
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--field);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.1s ease;
}

.skill-btn:hover { border-color: var(--accent); }
.skill-btn:active { transform: translateY(1px); }
.skill-btn.is-active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.skill-name { font-size: 0.95rem; font-weight: 600; }
.skill-len { font-family: var(--mono); font-size: 0.66rem; color: var(--muted); }

.chain-history {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    min-height: 1.8rem;
    font-size: 0.85rem;
}

.chip {
    padding: 0.15rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--field);
    color: var(--muted);
}

.chip.is-current { border-color: var(--accent); color: var(--text); font-weight: 600; }
.chip.is-incoming { border-color: var(--accent); border-style: dashed; color: var(--text); }
.chip.is-queued { border-style: dashed; }
.chip-arrow { color: var(--muted); font-size: 0.8rem; }

.chain-history + .knob { margin-top: 0.9rem; }

.chain-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.7rem;
    margin-top: 0.7rem;
}

/* ---------------------------------------------------------------- footer */

.btn {
    padding: 0.32rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--field);
    font-size: 0.92rem;
    cursor: pointer;
}

.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: default; }

.push-row {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.push-row .panel-label { margin: 0 0.35rem 0 0; }

.push-btn {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border-radius: 50%;
    font-family: var(--ui);
    font-size: 0.95rem;
    line-height: 1;
}

.push-row input[type="range"] { flex: 1 1 4rem; min-width: 3.5rem; margin-left: 0.3rem; }

.push-value {
    min-width: 4.6em;
    font-family: var(--mono);
    font-size: 0.78rem;
    text-align: right;
    color: var(--muted);
}

.demo-transport {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.8rem;
}

/* ---------------------------------------------------------------- phones */

@media (max-width: 760px) {
    .demo {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(0, 44%) minmax(0, 1fr);
    }

    .demo-panel { border-left: 0; border-top: 1px solid var(--border); }
    .demo-hud { display: none; }
    .demo-status { max-width: 100%; }
    .say-examples { display: none; }
    .demo-say { width: 94%; bottom: 0.6rem; }
    .demo-modes { margin: 0.6rem 0.8rem 0.2rem; }
}

@media (prefers-reduced-motion: reduce) {
    .say-examples, .mode-btn, .seg-btn, .chip-btn, .skill-btn, .demo-overlay { transition: none; }
}
