/* Think it, see it: the live agent lab on the home page. */

/* Step colors for chart marks, validated for the dark surface (dataviz validator: all checks pass). */
.s-plan { --mk: #4a8ae6; }
.s-make { --mk: #d9673f; }
.s-check { --mk: #1fa094; }
.s-ship { --mk: #bf8420; }

[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Lab panel: header line, agent bar, composer, machine, run results */
.think { border-top: 1px solid var(--divider); border-bottom: 1px solid var(--divider); background: #0f100e; padding-block: clamp(40px, 6vw, 72px); }
.lab { display: grid; gap: 16px; }
.lab-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 20px; }
.think h2 { font-weight: 800; font-size: clamp(1.8rem, 4vw, 2.6rem); line-height: 1.05; letter-spacing: -0.02em; }
.lab-meta { display: inline-flex; align-items: center; gap: 14px; font-size: 14px; color: var(--muted); max-width: none; }
.lab-live { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.lab-meta.offline .live-dot { background: var(--muted); animation: none; }

.lab-panel { background: var(--surface); border: 1px solid var(--divider); border-radius: 14px; display: grid; min-width: 0; }
.lab-panel > * { padding-inline: clamp(14px, 2.4vw, 20px); }
.agent-bar { display: flex; align-items: center; gap: 12px; padding-block: 14px; border-bottom: 1px solid var(--divider); }
.agent-mark { width: 40px; height: 40px; flex: none; fill: none; stroke: var(--primary); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.agent-mark rect { fill: var(--field); stroke: var(--border); stroke-width: 1; }
.agent-mark circle { fill: var(--primary); stroke: none; }
.agent-id { flex: 1; min-width: 0; }
.agent-name { font: 700 15px/1.3 var(--heading); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.agent-status { font-size: 14px; color: var(--muted); max-width: none; }
.agent-stats { display: flex; gap: 18px; margin: 0; }
.agent-stats div { display: grid; text-align: right; }
.agent-stats dt { font-size: 11px; color: var(--muted); order: 2; }
.agent-stats dd { margin: 0; font: 600 15px/1.2 var(--heading); order: 1; }
.mode-chip { --fx: var(--muted); }

.prompt { display: flex; align-items: center; gap: 8px; padding-block: 12px 8px; }
.prompt textarea {
  flex: 1; min-width: 0; resize: none; border: 1px solid var(--border); border-radius: 10px; outline: 0;
  background: var(--field); color: var(--text); font: 400 16px/1.5 var(--body);
  padding: 9px 12px; min-height: 42px; max-height: 120px; field-sizing: content;
}
.prompt textarea:focus-visible { border-color: var(--muted); }
.prompt textarea::placeholder { color: var(--muted); }
.prompt .count { font-size: 12px; color: var(--muted); }
.ghost {
  min-height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border);
  background: none; color: var(--text); font: 500 13px/1 var(--body); cursor: pointer; white-space: nowrap;
}
.ghost:hover { border-color: var(--muted); }
.send {
  width: 42px; height: 42px; flex: none; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--primary); color: var(--on-primary); display: grid; place-items: center;
}
.send:hover { background: var(--primary-hover); }
.send:disabled { background: var(--soft); color: var(--muted); cursor: not-allowed; }
.send svg { width: 18px; height: 18px; }
.ghost:focus-visible, .send:focus-visible, .preset:focus-visible, .link-btn:focus-visible, .timing summary:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.presets { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 12px; }
.preset {
  min-height: 32px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--divider); background: var(--field); color: var(--muted);
  font: 500 12px/1 var(--body); cursor: pointer;
}
.preset:hover { border-color: var(--border); color: var(--text); }

/* Human check: only shown when Turnstile needs an interaction */
.human-check { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin: 0 clamp(14px, 2.4vw, 20px) 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--field); }
.human-check p { font-size: 14px; color: var(--muted); max-width: 44ch; }
.human-check b { color: var(--text); font-weight: 600; }

/* The machine: Plan, Make, Check, Ship on one conveyor. State lives on data attributes and station classes. */
/* Stage: the 2x2 machine on the left, the concept it is building on the right */
.stage { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(16px, 3vw, 28px); align-items: start; padding-block: 16px; border-top: 1px solid var(--divider); }
.machine { display: block; width: 100%; max-width: 460px; height: auto; margin-inline: auto; overflow: visible; }
.machine .housing, .machine .leg, .machine .sheet, .machine .lens { fill: var(--field); stroke: var(--border); stroke-width: 1.5; transition: stroke 0.3s, fill 0.3s; }
.machine .sheet { fill: #20221f; }
.machine .ink { fill: none; stroke: var(--mk); stroke-width: 2; stroke-linecap: round; stroke-dasharray: 50; stroke-dashoffset: 50; }
.machine .arm { stroke: var(--border); stroke-width: 3; stroke-linecap: round; }
.machine .joint, .machine .nib { fill: var(--border); }
.machine .bulb circle { fill: none; stroke: var(--border); stroke-width: 1.5; transition: fill 0.3s, stroke 0.3s; }
.machine .bulb path { stroke: var(--border); stroke-width: 1.5; stroke-linecap: round; }
.machine .nozzle { fill: var(--raised); stroke: var(--border); stroke-width: 1.5; }
.machine .spark { stroke: var(--mk); stroke-width: 2; stroke-linecap: round; opacity: 0; }
.machine .arch { fill: none; }
.machine .lens-in { fill: var(--border); transition: fill 0.3s; }
.machine .beam { fill: var(--mk); opacity: 0; transform-box: fill-box; transform-origin: 50% 0; }
.machine .lamp { fill: var(--raised); stroke: var(--border); stroke-width: 1.5; transition: fill 0.3s; }
.machine .lamp.pass { fill: #1fa094; }
.machine .lamp.fail { fill: #ff8a7a; }
.machine .face { fill: var(--raised); stroke: var(--border); stroke-width: 1.5; }
.machine .dial { fill: none; stroke: var(--divider); stroke-width: 3; stroke-linecap: round; }
.machine .hub { fill: var(--text); }
.machine .mast { stroke: var(--border); stroke-width: 2; }
.machine .pass-tick { stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.machine .needle { stroke: var(--text); stroke-width: 2; stroke-linecap: round; transform-box: fill-box; transform-origin: 50% 100%; transform: rotate(var(--needle, -90deg)); transition: transform 0.8s cubic-bezier(0.3, 1.4, 0.5, 1); }
.machine .slats, .machine .lid { fill: none; stroke: var(--border); stroke-width: 1.5; }
.machine .lid { stroke-width: 3; stroke-linecap: round; }
.machine .shipmark { fill: none; stroke: var(--mk); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 60; stroke-dashoffset: 60; }
.machine .belt-edge { fill: none; stroke: var(--border); stroke-width: 16; stroke-linecap: round; stroke-linejoin: round; }
.machine .belt { fill: none; stroke: #1b1c1a; stroke-width: 12; stroke-linecap: round; stroke-linejoin: round; }
.machine .belt-return { fill: none; stroke: var(--divider); stroke-width: 2; stroke-dasharray: 3 6; }
.machine .roller circle { fill: var(--raised); stroke: var(--border); stroke-width: 1.5; }
.machine .roller path { stroke: var(--muted); stroke-width: 1.5; }
.machine .loop { fill: none; stroke: var(--border); stroke-width: 1.5; stroke-dasharray: 4 5; transition: stroke 0.3s; }
.machine .loop-label { fill: var(--muted); font: 500 11px var(--body); text-anchor: middle; }
.machine .retry-dot { fill: var(--primary); opacity: 0; transition: opacity 0.2s; }
.machine .part { transition: opacity 0.4s; }
.machine .part-shell { fill: var(--raised); stroke: var(--muted); stroke-width: 1.5; }
.machine .part-fill { fill: #d9673f; transform-box: fill-box; transform-origin: 50% 100%; transform: scaleY(var(--fill, 0)); transition: transform 0.4s; }
.machine[data-state="idle"] .part { opacity: 0; }
.machine.shipped .part { opacity: 0; }
.machine .labels text { fill: var(--muted); font: 600 13px var(--body); text-anchor: middle; }
.machine .labels .sub { font: 400 11px var(--body); }

/* Station states */
.machine .st.active .housing, .machine .st.done .housing { stroke: var(--mk); }
.machine .st.done .housing { fill: color-mix(in srgb, var(--mk) 14%, var(--field)); }
.machine .st.fail .housing { stroke: #ff8a7a; }
.machine .s-plan.active .bulb circle, .machine .s-plan.done .bulb circle { fill: rgba(244, 226, 122, 0.55); stroke: #f4e27a; }
.machine .s-plan.done .ink { stroke-dashoffset: 0; }
.machine .s-plan.active .ink { animation: ink 1.6s ease-out forwards; }
.machine .pen { transform-box: fill-box; transform-origin: 100% 0; }
.machine .s-plan.active .pen { animation: pen 0.5s ease-in-out infinite alternate; }
.machine .s-make.active .nozzle { animation: nozzle 0.9s ease-in-out infinite alternate; }
.machine .s-make.active .spark { animation: spark 0.45s steps(2) infinite; }
.machine .part.filling .part-fill { transition: transform var(--fill-ms, 9000ms) cubic-bezier(0.2, 0.6, 0.4, 1); }
.machine .s-check.active .beam { animation: beam 1.1s ease-in-out infinite alternate; }
.machine .s-check.active .lens-in { fill: var(--mk); }
.machine .s-ship.done .shipmark { stroke-dashoffset: 0; transition: stroke-dashoffset 0.6s ease-out 0.2s; }
.machine.retrying .loop { stroke: var(--primary); }
.machine.retrying .retry-dot { opacity: 1; }

@keyframes ink { to { stroke-dashoffset: 0; } }
@keyframes pen { from { transform: rotate(-7deg); } to { transform: rotate(9deg); } }
@keyframes nozzle { from { transform: translateX(-30px); } to { transform: translateX(30px); } }
@keyframes spark { 50% { opacity: 1; } }
@keyframes beam { from { opacity: 0.14; transform: rotate(-12deg); } to { opacity: 0.32; transform: rotate(12deg); } }

/* Run results inside the panel */
.frame.idle { display: grid; place-items: center; border-style: dashed; }
.frame-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 16px; }
.lab-panel > .log { padding: 12px clamp(14px, 2.4vw, 20px); border-top: 1px solid var(--divider); max-height: 320px; }
.lab-foot { display: grid; gap: 10px; padding-block: 12px 14px; border-top: 1px solid var(--divider); }
.stage-links { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; color: var(--muted); max-width: none; }
.link-btn { background: none; border: 0; padding: 4px 0; color: var(--text); font: 500 14px/1.4 var(--body); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.mode-note { font-size: 13px; color: var(--muted); max-width: 70ch; }
.mode-note:empty { display: none; }
.timing summary { cursor: pointer; font-size: 13px; color: var(--muted); width: fit-content; }
.timing[open] { display: grid; gap: 12px; }

/* Step log */
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; max-height: 440px; overflow: auto; font-size: 13px; }
.log li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 4px 10px; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--divider); }
.log li:first-child { border-top: 0; }
.log .sw-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--mk); align-self: center; }
.log .what { min-width: 0; }
.log .what b { font-weight: 600; }
.log .what span { color: var(--muted); display: block; overflow-wrap: anywhere; }
.log .t { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Concept card */
.concept { display: grid; gap: 12px; }
.concept .frame { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--field); border: 1px solid var(--divider); }
.concept .frame img { width: 100%; height: 100%; object-fit: cover; display: block; transition: filter 0.4s; }
.concept .frame img.draft { filter: blur(6px) saturate(0.7); }
.concept .frame .attempt { position: absolute; left: 10px; top: 10px; }
.concept .frame.loading::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.06) 50%, transparent 70%) var(--field);
  background-size: 200% 100%; animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.concept .name { margin: 0; font: 700 1.3rem/1.2 var(--heading); }
.concept .tagline { color: var(--text); }
.concept .brief { color: var(--muted); font-size: 14px; }
.concept .verdict { font-size: 14px; color: var(--muted); }
.score { display: inline-flex; align-items: center; gap: 6px; font: 600 12px/1 var(--body); padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--text); background: var(--raised); }
.concept .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Waterfall */
.waterfall { display: grid; gap: 10px; }
.wf-axis, .wf-row { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 10px; align-items: center; }
.wf-axis .ticks { position: relative; height: 16px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.wf-axis .ticks span { position: absolute; top: 0; transform: translateX(-50%); }
.wf-axis .ticks span:first-child { transform: none; }
.wf-axis .ticks span:last-child { transform: translateX(-100%); }
.wf-row .label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.wf-row .track { position: relative; height: 18px; background-image: linear-gradient(to right, var(--divider) 1px, transparent 1px); background-size: 25% 100%; }
.wf-row .bar { position: absolute; top: 4px; height: 10px; min-width: 4px; border-radius: 4px; background: var(--mk); cursor: default; }
.wf-row .bar::after { content: ""; position: absolute; inset: -6px -2px; }
.wf-row .bar.running { animation: grow-pulse 1s ease-in-out infinite; }
@keyframes grow-pulse { 50% { opacity: 0.55; } }
.wf-row .ms { position: absolute; top: 0; font-size: 11px; line-height: 18px; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--mk); }
.tip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 260px;
  background: var(--raised); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; color: var(--text); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.tip b { display: block; font-size: 13px; }
.tip span { color: var(--muted); display: block; }
.table-view { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { text-align: left; padding: 6px 8px; border-top: 1px solid var(--divider); }
.table-view th { color: var(--muted); font-weight: 600; }
.run-note { font-size: 12px; color: var(--muted); }

/* Dialogs */
dialog.lab-dialog {
  width: min(960px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  background: var(--canvas); color: var(--text); border: 1px solid var(--border); border-radius: 12px;
}
dialog.lab-dialog::backdrop { background: rgba(8, 9, 8, 0.75); backdrop-filter: blur(4px); }
.dialog-head { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; background: var(--header); border-bottom: 1px solid var(--divider); }
.dialog-head h3 { font-size: 16px; }
.dialog-body { padding: 16px; display: grid; gap: 16px; }
.card-detail { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 16px; align-items: start; }
.card-detail img { width: 100%; aspect-ratio: 1; object-fit: cover; height: auto; border-radius: 8px; display: block; border: 1px solid var(--divider); }
.dialog-body .ghost { border-color: var(--border); }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gallery-grid button { padding: 0; border: 1px solid var(--divider); border-radius: 10px; overflow: hidden; background: var(--surface); color: var(--text); cursor: pointer; text-align: left; display: grid; }
.gallery-grid button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.gallery-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.gallery-grid span { padding: 8px 10px; font: 600 13px/1.3 var(--body); }
.gallery-status { min-height: 1.5em; font-size: 13px; color: var(--muted); text-align: center; }

@media (max-width: 860px) {
  .stage, .card-detail { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .agent-bar { flex-wrap: wrap; }
  .agent-stats { width: 100%; }
  .agent-stats div { text-align: left; }
  .prompt { flex-wrap: wrap; }
  .prompt textarea { flex-basis: 100%; }
  .prompt .count { margin-right: auto; }
}
@media (max-width: 520px) {
  .wf-axis, .wf-row { grid-template-columns: 56px minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .wf-row .bar.running, .concept .frame.loading::before,
  .machine .st.active * { animation: none !important; }
  .machine .part, .machine .needle, .machine .part-fill { transition: none !important; }
  .machine .s-plan.active .ink { stroke-dashoffset: 0; }
  .machine .s-check.active .beam { opacity: 0.22; }
}

/* Card dialog sections */
.panel-card { background: var(--surface); border: 1px solid var(--divider); border-radius: 10px; padding: 16px; display: grid; gap: 12px; min-width: 0; }
.panel-card > h4 { margin: 0; font: 600 12px/1.4 var(--body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
