/* Duit website: the product demos (#product, part "demos", js/demos.js). SPEC 7.5.
   Needs site.css (tokens, .sec .sec-head .eyebrow, buttons, .g glyphs, .sr) and window.css (the .dw-* window).
   Every rule is scoped under .dm (the section) or a dm- class. Cream page, sky windows.

   DEMO A+B  .dm-ab > .dm-demo-head (h3, copy, .dm-ctl) + .dm-stage + .dm-caps.
             .dm-stage holds, in reading order: .dm-person label, Dana's .dw, .dm-wire, the lane's label,
             .dm-lane (the Omphalos log, sky surface), .dm-wire, Luis's label, Luis's .dw. Stacked under 1100px;
             from 1100px a 5-column grid: Dana | wire | lane | wire | Luis, labels on row 1.
   DEMO C    .dm-c: .dm-c-copy (text, rules, .dm-ctl) beside .dm-c-stage (one window). Stacked under 900px.
   STATE     The static HTML is the finished state (no JS, reduced motion). demos.js hides what has not
             happened yet with .dm-off (visibility only, so nothing reflows while it plays), adds .dw-rise as
             things arrive, toggles [hidden] on .dm-busy / .dm-done pairs (the ~ and * versions of a line),
             sets --u (0..1) on a .dm-wire while its pulse runs, --p (0..1) on a .dm-cap, .is-focus on the
             composer that has the caret, and --dm-lift on a composer while its typed prompt runs to two lines.
             .dm-js on the section means the script is running. */

.dm { --dm-fs: 14px; }
.dm h3 { font-size: clamp(20px, .8vw + 15px, 26px); line-height: 1.2; }
.dm .dw { --dw-fs: var(--dm-fs); }

/* ---------- state hooks (set by demos.js) ---------- */
.dm .dm-off { visibility: hidden; }
.dm .dm-w { transition: opacity .3s var(--ease), visibility 0s; }
.dm .dm-w.dm-off { opacity: 0; }
/* only the window being typed in shows its caret; it holds still while typing, like a real one */
.dm-js .dw-composer:not(.is-focus) .dw-caret { visibility: hidden; }
.dm .dw-composer.is-typing .dw-caret { animation: none; }
.dm .dw-send { transition: color .2s, border-color .2s, background-color .2s; }
.dm .dw-send.is-ready { color: var(--text); border-color: var(--soft); }
.dm .dw-send.is-hot { color: var(--on-accent); border-color: var(--accent-fill); background: var(--accent-fill); }
.dm-demo.is-paused *, .dm-demo.is-paused *::before, .dm-demo.is-paused *::after { animation-play-state: paused !important; }

/* ---------- the composers (overrides of window.css, for these three windows only) ---------- */
/* a typed prompt wraps cleanly: the caret takes no room on the line (its right margin cancels its width), so it
   rides down with the last word instead of wrapping alone; and the box grows upward (demos.js sets --dm-lift to
   the extra height: the negative margin keeps the window's height, the shift moves the box up over the still
   empty space above it), so nothing below it moves while it types */
.dm .dw-caret { margin-right: calc(-.5em - 1px); }
.dm .dw-composer[style*="--dm-lift"] { margin-bottom: calc(-1 * var(--dm-lift)); translate: 0 calc(-1 * var(--dm-lift)); }
/* the placeholder never ends in "…": the field is a size container and shows the longest of three that fits.
   long  "Ask Duit about a job, a customer or an invoice" (20.3em)  from a 22em field
   mid   "Ask Duit about a job or a customer"             (15.4em)  from 17em
   short "Ask Duit about a job"                           ( 9.0em)  below that, and without container queries
   Each phrase is a nowrap span with a plain space between: if a wider system font still overruns, the tail
   wraps to a clipped second line, so what shows is a whole phrase ("Ask Duit about a job, a customer").
   The left margin keeps the indent the caret's width used to give it. */
.dm .dw-field { container: dm-field / inline-size; }
.dm .dw-ph { height: 1.5em; margin-left: calc(.65em + 1px); white-space: normal; text-overflow: clip; overflow-wrap: normal; }
.dm .dm-ph > span { white-space: nowrap; }
.dm .dm-ph-l, .dm .dm-ph-m { display: none; }
@container dm-field (min-width: 17em) {
  .dm .dm-ph-m { display: inline; }
  .dm .dm-ph-s { display: none; }
}
@container dm-field (min-width: 22em) {
  .dm .dm-ph-l { display: inline; }
  .dm .dm-ph-m { display: none; }
}

/* ---------- the demo blocks ---------- */
.dm-demo { position: relative; }
.dm-demo + .dm-demo { margin-top: clamp(72px, 8vw, 120px); padding-top: clamp(56px, 6.5vw, 96px); border-top: 1px solid var(--faint); }
.dm-demo-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 40px; margin-bottom: clamp(24px, 2.6vw, 36px); }
.dm-demo-copy > p { max-width: 62ch; margin-top: 10px; font-size: 16px; line-height: 1.6; color: var(--soft); }

/* Pause / Play / Replay: one button, its icon follows data-state */
.dm-ctl { flex: none; min-width: 108px; }
.dm-ctl svg { display: none; width: 14px; height: 14px; }
.dm-ctl[data-state="pause"] .dm-i-pause,
.dm-ctl[data-state="play"] .dm-i-play,
.dm-ctl[data-state="replay"] .dm-i-replay { display: block; }

/* the labels over each panel: who is asking, and which AI answers them */
.dm-person {
  display: flex; align-items: center; gap: 4px 8px; min-height: 30px; margin: 0 2px 10px;
  font-size: 14px; line-height: 1.3; color: var(--soft);
}
.dm-person b { font-weight: 600; color: var(--text); }
.dm-person > span:not(.dm-agent)::before { content: "· "; content: "· " / ""; }
.dm-person .dm-mark { width: 14px; height: 14px; margin-right: 2px; color: var(--text); }
.dm-agent {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; margin-left: auto; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  font-family: var(--mono); font-size: 12px; line-height: 1; color: var(--text); white-space: nowrap;
}
.dm-agent::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }

/* ---------- Demo A+B stage: stacked by default ---------- */
.dm-stage { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); }
.dm-win { min-width: 0; }
.dm-win .dw-body > .dw-composer { margin-top: auto; }
/* before the first message: a quiet greeting in the middle of the window (only demos.js turns it on,
   and it goes as soon as the person asks, as in the desktop client) */
.dm-win .dw-body { position: relative; }
.dm-idle {
  position: absolute; inset: 0 0 4.6em; display: grid; place-content: center; justify-items: center; gap: .8em;
  color: var(--soft); font-size: 1.07em; pointer-events: none;
  opacity: 0; visibility: hidden; transition: opacity .45s var(--ease), visibility 0s .45s;
}
.dm-idle.is-on { opacity: 1; visibility: visible; transition: opacity .45s var(--ease); }
.dm-idle-mark { width: 2em; height: 2em; color: var(--line-strong); }
.dm .dw-status > span { display: inline-flex; align-items: baseline; gap: .55em; }

/* the wires between the panels, and the pulse that runs along them (--u from demos.js) */
.dm-wire { position: relative; height: 40px; overflow: hidden; }
.dm-wire::before { content: ""; position: absolute; top: 2px; bottom: 2px; left: 50%; margin-left: -1px; border-left: 2px dotted var(--line-strong); }
.dm-dot {
  position: absolute; left: 50%; top: calc(var(--u, 0) * 100%); width: 8px; height: 8px; margin: -4px 0 0 -4px;
  border-radius: 50%; background: var(--accent); opacity: 0;
  box-shadow:
    0 -9px 0 -1px color-mix(in oklch, var(--accent) 60%, transparent),
    0 -17px 0 -1.5px color-mix(in oklch, var(--accent) 38%, transparent),
    0 -24px 0 -2px color-mix(in oklch, var(--accent) 20%, transparent);
}
.dm-wire::before { transition: border-color .5s; }
.dm-wire.is-live::before { border-color: color-mix(in oklch, var(--accent) 60%, var(--line-strong)); transition-duration: .15s; }
.dm-wire.is-live .dm-dot { opacity: 1; }
.dm-wire + .dm-person { margin-top: 2px; }

/* the Omphalos lane: a plain log on the sky surface */
.dm-lane {
  display: flex; flex-direction: column; min-width: 0; overflow: hidden;
  background: var(--surface); border: 1px solid var(--faint); border-radius: 10px;
  font-family: var(--mono); font-size: 12px; line-height: 1.5; color: var(--text);
}
.dm-lane-bar {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  height: calc(2.43 * var(--dm-fs)); padding: 0 10px 0 14px; border-bottom: 1px solid var(--faint);
}
.dm-lane-title { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--soft); }
.dm-tag {
  padding: 2px 7px; border: 1px solid var(--faint); border-radius: 4px;
  font-size: 10px; line-height: 1.3; letter-spacing: .1em; text-transform: uppercase; color: var(--soft);
}
.dm-log { display: grid; align-content: start; margin: 0; padding: 4px 14px 12px; list-style: none; }
.dm-entry {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-content: start; column-gap: 10px;
  padding: 10px 0; border-bottom: 1px dashed var(--faint);
}
.dm-entry:last-child { border-bottom: 0; }
.dm-entry::before {
  content: ""; position: absolute; inset: 3px -8px; border-radius: 6px;
  background: color-mix(in oklch, var(--accent) 13%, var(--surface));
  opacity: 0; transition: opacity 1.4s ease;
}
.dm-entry.is-new::before { opacity: 1; transition-duration: .2s; }
.dm-entry > * { position: relative; min-width: 0; }
.dm-verb { color: var(--text); }
.dm-res { justify-self: end; color: var(--soft); white-space: nowrap; }
.dm-res .g { width: auto; }
.dm-det { grid-column: 1 / -1; color: var(--soft); overflow-wrap: anywhere; text-wrap: pretty; }

/* stacked and wide enough: the lane's log runs in two columns, Dana's half then Luis's half */
@media (min-width: 560px) and (max-width: 1099px) {
  .dm-log { grid-template-rows: repeat(4, auto); grid-auto-flow: column; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 28px; }
  .dm-entry:nth-child(4) { border-bottom: 0; }
}

/* step captions under the stage: a segmented progress line */
.dm-caps { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px 20px; margin: clamp(24px, 2.6vw, 32px) 0 0; padding: 0; list-style: none; }
.dm-cap { position: relative; padding-top: 14px; font-size: 14px; line-height: 1.45; color: var(--soft); text-wrap: pretty; transition: color .3s; }
.dm-cap::before, .dm-cap::after { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 2px; border-radius: 1px; }
.dm-cap::before { background: var(--faint); }
.dm-cap::after { background: var(--soft); transform: scaleX(var(--p, 1)); transform-origin: left center; }
.dm-cap.is-active { color: var(--text); }
.dm-cap.is-active::after { background: var(--accent); }
.dm-cap-n { margin-right: 8px; font-family: var(--mono); font-size: 12px; color: var(--text); }

/* ---------- wide: Dana | wire | lane | wire | Luis ---------- */
@media (min-width: 1100px) {
  .dm { --dm-fs: 13px; }
  /* the lane keeps 250px so a log line ("delivery Sat 08:00, Sam Ortiz") fits on one line; the windows give way */
  .dm-stage {
    grid-template-columns: minmax(0, 1.28fr) 40px 250px 40px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
  }
  .dm-p-dana { grid-area: 1 / 1; }
  .dm-dana { grid-area: 2 / 1; }
  .dm-w1 { grid-area: 2 / 2; }
  .dm-p-lane { grid-area: 1 / 3; }
  .dm-lane { grid-area: 2 / 3; }
  .dm-w2 { grid-area: 2 / 4; }
  .dm-p-luis { grid-area: 1 / 5; }
  .dm-luis { grid-area: 2 / 5; }
  .dm-person { align-self: end; font-size: 13px; }
  .dm-p-lane { white-space: nowrap; }
  .dm-wire + .dm-person { margin-top: 0; }

  .dm-wire { height: auto; }
  .dm-wire::before { top: 50%; bottom: auto; left: 2px; right: 2px; margin: -1px 0 0; border-left: 0; border-top: 2px dotted var(--line-strong); }
  .dm-dot {
    top: 50%; left: calc(var(--u, 0) * 100%);
    box-shadow:
      -9px 0 0 -1px color-mix(in oklch, var(--accent) 60%, transparent),
      -17px 0 0 -1.5px color-mix(in oklch, var(--accent) 38%, transparent),
      -24px 0 0 -2px color-mix(in oklch, var(--accent) 20%, transparent);
  }
}
@media (min-width: 1280px) {
  .dm-stage { grid-template-columns: minmax(0, 1.22fr) 44px minmax(0, 240px) 44px minmax(0, 1fr); }
  .dm-person { font-size: 14px; }
}

/* ---------- Demo C: the copy beside one window ---------- */
.dm-c { display: grid; grid-template-columns: minmax(0, 1fr); gap: 32px; }
.dm-c-copy > p:not(.eyebrow) { max-width: 46ch; margin-top: 14px; font-size: 16px; line-height: 1.6; color: var(--soft); }
.dm-c-copy .eyebrow { margin-bottom: 12px; }
.dm-rules { display: grid; gap: 8px; margin: 22px 0 28px; padding: 0; list-style: none; font-family: var(--mono); font-size: 13px; line-height: 1.5; color: var(--text); }
.dm-rules li { display: grid; grid-template-columns: 1.1ch minmax(0, 1fr); column-gap: 12px; align-items: baseline; }
.dm-rules .g { line-height: 1.5; }
.dm-c-stage { width: 100%; max-width: 560px; min-width: 0; margin-inline: auto; }
.dm-withheld { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .4em 1em; margin-top: -.35em; }
.dm-withheld .dw-status { min-width: 0; }
.dm-withheld .dw-link { font-size: .93em; }
@media (min-width: 900px) {
  .dm-c { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: center; column-gap: clamp(40px, 6vw, 96px); }
  .dm-c-stage { margin-inline: auto 0; }
}
@media (min-width: 1100px) {
  .dm-c-stage { --dm-fs: 14px; } /* the single window keeps the client's size */
}

/* ---------- small screens ---------- */
@media (max-width: 699px) {
  .dm-demo-head { flex-direction: column; align-items: flex-start; }
  .dm-caps { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .dm-cap { padding: 9px 0 9px 16px; }
  .dm-cap::before, .dm-cap::after { top: 0; bottom: 0; right: auto; width: 2px; height: auto; }
  .dm-cap::after { transform: scaleY(var(--p, 1)); transform-origin: center top; }
}
@media (max-width: 479px) {
  .dm { --dm-fs: 13px; }
  .dm-person { font-size: 13px; }
}
