/* =========================================================================
   CAPACITY CHAIN DEMO (#capacityChainDemo).
   See src/components/CapacityChainDemo.astro for the storyboard.
   Timeline: public/js/capacity-chain-demo.js toggles `is-*` classes and
   positions `.ccd__cursor` at runtime.

   A single steady scene (no crossfade — same pattern as
   BudgetMultiplayerDemo/BudgetVarianceDemo): a literal calculation chain,
   not a table. New visual language for this page, but the same --xxx-*
   palette (product likeness) as every other demo on the site.
   ========================================================================= */

.ccd {
  --ccd-canvas: #FAF9F5;
  --ccd-card: #FFFFFF;
  --ccd-border: #DBDBDE;
  --ccd-line: #EAEAEA;
  --ccd-head: #F6F6F7;
  --ccd-ink: #2B2B2B;
  --ccd-ink2: #777777;
  --ccd-accent: #6A5BC6;
  --ccd-accent-soft: #ECECFF;
}

/* standard product-demo dimensions (matches every other demo's stage —
   width:100% keeps aspect-ratio from computing width off the min-height
   floor in a narrow container, the bug this pattern has hit before). */
.ccd__stage {
  position: relative; overflow: hidden; width: 100%;
  aspect-ratio: 3 / 2; min-height: 380px; max-width: 640px; margin: 0 auto;
  background: var(--ccd-canvas);
  display: flex; flex-direction: column;
  transition: opacity .5s ease;
}
.ccd.is-out .ccd__stage { opacity: 0; }

.ccd__topBar {
  flex: none; font-size: 11px; font-weight: 600; color: var(--ccd-ink);
  padding: 12px 14px 9px; border-bottom: 1px solid var(--ccd-line);
  white-space: nowrap;
}

.ccd__pane {
  flex: 1; min-height: 0; min-width: 0; padding: 12px 14px;
  display: flex; flex-direction: column; justify-content: center;
}

.ccdHead { margin: 0 0 18px; font-size: 12px; font-weight: 600; color: var(--ccd-ink); text-align: center; }

/* ---------- the chain — nodes connected by operator glyphs, laid out to
   wrap gracefully on narrow widths rather than overflow. ---------- */
.ccd__chain {
  display: flex; align-items: center; justify-content: center;
  flex-wrap: wrap; gap: 10px 8px;
}
.ccdNode {
  flex: 1 1 130px; max-width: 150px; min-width: 110px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  text-align: center; padding: 14px 10px;
  background: var(--ccd-card); border: 1px solid var(--ccd-border); border-radius: 10px;
  transition: background .3s ease, outline-color .3s ease;
}
.ccdNode--output { background: var(--ccd-accent-soft); border-color: #CFC7EF; }
.ccdNode__label { font-size: 8.5px; font-weight: 600; color: var(--ccd-ink2); text-transform: uppercase; letter-spacing: .04em; }
.ccdNode__val { font-size: 18px; font-weight: 700; color: var(--ccd-ink); font-variant-numeric: tabular-nums; position: relative; }
.ccdNode--output .ccdNode__val { color: var(--ccd-accent); }
.ccdNode__sub { font-size: 8.5px; color: var(--ccd-ink2); }
.ccdOp { flex: none; font-size: 16px; font-weight: 600; color: var(--ccd-ink2); }

/* editable input node, mid-edit — outline + pulse (same "being edited"
   language used across the other demos' editable cells). */
.ccdNode.is-editing {
  outline: 1.5px solid var(--ccd-accent); outline-offset: -1.5px;
  animation: ccdNodePulse .8s ease-out;
}
@keyframes ccdNodePulse {
  0% { box-shadow: 0 0 0 0 rgba(106, 91, 198, .45); }
  70% { box-shadow: 0 0 0 8px rgba(106, 91, 198, 0); }
  100% { box-shadow: 0 0 0 0 rgba(106, 91, 198, 0); }
}

/* the result node, the moment it recalculates. */
.ccdNode--output.is-flash { outline: 1.5px solid var(--ccd-accent); outline-offset: -1.5px; }

/* ---------- cursor — positioned at runtime (JS sets left/top in px via
   getBoundingClientRect against .ccd__stage). ---------- */
.ccd__cursor {
  position: absolute; opacity: 0; pointer-events: none; z-index: 9;
  transition: left .6s cubic-bezier(.5, .05, .3, 1), top .6s cubic-bezier(.5, .05, .3, 1), opacity .3s ease;
}
.ccd.is-cursor-visible .ccd__cursor { opacity: 1; }

/* ---------- responsive — below the point the row gets too cramped, read
   top-to-bottom instead: node, operator, node, operator, result — same
   equation, stacked like it's written out. ---------- */
@media (max-width: 420px) {
  .ccd__stage { aspect-ratio: auto; min-height: 470px; }
  .ccd__chain { flex-direction: column; }
  .ccdNode { width: 100%; max-width: 220px; }
}
