/* Interactive explainer: receipts and CEL. Loaded only by its post. */

.ix {
  --ok: #2c6b4d;
  --ok-soft: #e6f0ea;
  --bad: #a3392b;
  --bad-soft: #f6e6e2;
  --amber: #8a5d0d;
  --amber-soft: #f5ecd9;
  --card: #fffefb;
  margin-block: 1.6em;
  margin-inline: calc(50% - min(430px, 50vw - 20px));
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font-size: .95rem;
  line-height: 1.55;
}
.ix:not(.is-live) { color: var(--text); font-style: italic; }
/* .is-live raises specificity so components that reset their own margin still get the gap */
.ix.is-live > * + * { margin-top: 12px; }
.ix ul, .ix ol { padding-left: 0; }
.ix li + li { margin-top: 0; }
.prose h2 { scroll-margin-top: var(--ix-offset, 150px); }

.ix code, .ix pre { font-family: var(--mono); }
.ix-label { margin: 0; color: var(--muted); font: 600 .7rem/1.5 var(--mono); letter-spacing: .09em; text-transform: uppercase; }
.ix-label-ok { color: var(--ok); }
.ix-label-bad { color: var(--bad); }
.ix-note { margin: 8px 0 0; color: var(--muted); font-size: .85rem; }
.ix-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 12px; }
.ix-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 22px; }
.ix-split > div > * + * { margin-top: 10px; }
.ix-plan .ix-split { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }

.ix-button {
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font: 650 .82rem/1.2 var(--sans);
  cursor: pointer;
  transition: background .2s, transform .15s;
}
.ix-button:hover { background: var(--blue-dark); }
.ix-button:active { transform: scale(.97); }
.ix-button:disabled { opacity: .55; cursor: progress; }
.ix-button-quiet { border: 1px solid var(--line); background: transparent; color: var(--ink); }
.ix-button-quiet:hover { background: #eeede7; }
.ix button:focus-visible, .ix-input:focus-visible, .ix a:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.ix-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--text);
  font-size: .8rem;
}
.ix-chip code { color: var(--ink); font-size: .78rem; white-space: nowrap; }
.ix-chip-bad { border-color: #e2bdb5; background: var(--bad-soft); color: var(--bad); font-family: var(--mono); }
.ix-chip-button { font: inherit; font-size: .8rem; text-align: left; cursor: pointer; transition: border-color .2s, background .2s; }
.ix-chip-button:hover { border-color: var(--blue); background: #fff; }
.ix-presets, .ix-names, .ix-history { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ix-names { flex-direction: column; align-items: flex-start; }

.ix-bubble { max-width: 46ch; margin: 0; padding: 10px 14px; border-radius: 14px; font-size: .95rem; }
.ix-bubble-user { margin-left: auto; border-bottom-right-radius: 4px; background: var(--ink); color: var(--paper); }
.ix-bubble-model { min-height: 2.6em; border: 1px solid var(--line); border-bottom-left-radius: 4px; background: var(--paper); }
.ix-answer { max-width: none; font-size: 1.02rem; }
.ix-answer.is-blocked { border-style: dashed; color: var(--muted); font-style: italic; }
.ix-wrong { padding: 0 3px; border-radius: 3px; background: var(--bad-soft); color: var(--bad); font-weight: 650; }

.ix .ix-code code { font-size: inherit; }
.ix-code { margin: 0; padding: 12px 14px; overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: #f3f2ec; font-size: .8rem; line-height: 1.55; white-space: pre; }

/* Pipeline stepper: sticks under the site header while the stages scroll by */
.ix-pipeline {
  position: sticky;
  z-index: 1;
  top: var(--top, 72px);
  padding: 10px 14px;
  background: var(--paper);
  box-shadow: 0 8px 20px -14px #20242a40;
}
.ix-pipeline nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.ix-step {
  position: relative;
  display: inline-flex;
  flex: 1 0 auto;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--muted);
  font: 600 .74rem/1.3 var(--mono);
  letter-spacing: .04em;
  text-decoration: none;
  text-transform: uppercase;
  transition: color .3s, background .3s;
}
.ix-step-dot { width: 9px; height: 9px; border: 1.5px solid currentColor; border-radius: 50%; transition: background .3s, transform .3s; }
.ix-step:hover { color: var(--ink); }
.ix-step.is-done { color: var(--ink); }
.ix-step.is-done .ix-step-dot { background: currentColor; }
.ix-step[aria-current] { background: var(--ink); color: var(--paper); }
.ix-step[aria-current] .ix-step-dot { background: var(--paper); border-color: var(--paper); transform: scale(1.15); }

/* Receipts */
.ix-slot { min-height: 120px; }
.ix-receipt {
  position: relative;
  padding: 16px 16px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff radial-gradient(circle at 6px 0, var(--card) 3px, transparent 3.5px) 0 0 / 12px 6px repeat-x;
  font-size: .82rem;
  box-shadow: 0 6px 18px #20242a12;
}
.ix-receipt header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding-bottom: 8px; border-bottom: 1px dashed var(--line); font-family: var(--mono); }
.ix-receipt header strong { font-size: 1rem; }
.ix-receipt header span { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; }
.ix-receipt .ix-trust { margin-left: auto; padding: 1px 8px; border-radius: 999px; background: #e8edf5; color: var(--blue) !important; }
.trust-calculated .ix-trust { background: var(--ok-soft); color: var(--ok) !important; }
.trust-illustration .ix-trust, .trust-yours .ix-trust { background: var(--amber-soft); color: var(--amber) !important; }
.ix-receipt dl { display: grid; gap: 6px; margin: 10px 0 0; }
.ix-receipt dl > div { display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 10px; align-items: baseline; }
.ix-receipt dt { color: var(--muted); font: 500 .72rem/1.5 var(--mono); }
.ix-receipt dd { margin: 0; overflow-wrap: anywhere; }
.ix-receipt dd code { font-size: .78rem; }
.ix-line { display: block; }
.ix-receipt footer { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); color: var(--muted); font: 500 .72rem/1.5 var(--mono); }
.ix-ok { color: var(--ok); font-weight: 650; }
.ix-bad { color: var(--bad); font-weight: 650; }
.ix-ok::before { content: "✓ "; }
.ix-bad::before { content: "✗ "; }
.ix-receipt.is-printing { animation: ix-print .9s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes ix-print {
  from { clip-path: inset(0 0 100% 0); transform: translateY(-10px); }
  to { clip-path: inset(0 0 -20px 0); transform: none; }
}

.ix-bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; align-items: end; height: 64px; }
.ix-bar { display: grid; grid-template-rows: 1fr auto; height: 100%; }
.ix-bar-fill { align-self: end; height: max(2px, var(--h)); border-radius: 2px 2px 0 0; background: var(--blue); opacity: .8; transition: height .5s cubic-bezier(.2, .8, .2, 1), background .3s; }
.ix-bar.is-changed .ix-bar-fill { background: var(--bad); opacity: 1; }
.ix-bar-label { margin-top: 2px; color: var(--muted); font: 500 .6rem/1 var(--mono); text-align: center; }

/* Check */
.ix-input {
  display: block;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: 500 .95rem/1.4 var(--mono);
}
.ix-textarea { resize: vertical; font-family: var(--sans); }
.ix-status { margin: 0; padding: 9px 12px; border-radius: 8px; font-size: .88rem; font-weight: 550; }
.ix-status.is-ok { background: var(--ok-soft); color: var(--ok); }
.ix-status.is-bad { background: var(--bad-soft); color: var(--bad); }
.ix-status.is-ok::before { content: "✓ "; }
.ix-status.is-bad::before { content: "✗ "; }

.ix-tree, .ix-tree ul { margin: 0; padding: 0; list-style: none; }
.ix-tree ul { margin-left: 11px; padding-left: 14px; border-left: 1px solid var(--line); }
.ix-tree li { position: relative; padding-top: 6px; }
.ix-tree ul > li::before { content: ""; position: absolute; top: 19px; left: -14px; width: 11px; border-top: 1px solid var(--line); }
.ix-node { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 6px; padding: 4px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; animation: ix-pop .35s cubic-bezier(.2, .8, .2, 1) both; }
.ix-node code { font-size: .82rem; font-weight: 650; }
.ix-unit { color: var(--ok); font: 500 .7rem/1.4 var(--mono); }
.ix-from { color: var(--muted); font: 500 .7rem/1.4 var(--mono); }
.ix-tree .is-bad > .ix-node { border-color: var(--bad); background: var(--bad-soft); }
.ix-tree .is-bad > .ix-node code { color: var(--bad); }
@keyframes ix-pop { from { opacity: 0; transform: translateY(4px); } }

/* Run */
.ix .ix-steps { margin: 12px 0 0; padding-left: 22px; font-size: .82rem; }
.ix-steps li { padding: 3px 0; animation: ix-pop .35s cubic-bezier(.2, .8, .2, 1) both; }
.ix-steps li:last-child code { color: var(--ok); font-weight: 700; }
.ix-steps li code { overflow-wrap: anywhere; }
.ix-steps li.is-bad { color: var(--bad); }

/* Write */
.ix-figure strong { padding: 0 3px; border-radius: 3px; background: #e8edf5; color: var(--blue); }
.ix-figure.trust-calculated strong { background: var(--ok-soft); color: var(--ok); }
.ix-figure.trust-illustration strong, .ix-figure.trust-yours strong { background: var(--amber-soft); color: var(--amber); }
.ix-figure-label { color: var(--muted); font-size: .9em; }

/* Replay */
.ix .ix-results { display: grid; gap: 6px; margin: 4px 0 0; padding: 0; list-style: none; }
.ix-results li { padding: 8px 12px; border-radius: 8px; font-size: .88rem; animation: ix-pop .35s cubic-bezier(.2, .8, .2, 1) both; }
.ix-results li.is-ok { background: var(--ok-soft); color: var(--ok); }
.ix-results li.is-bad { background: var(--bad-soft); color: var(--bad); }
.ix-results li.is-ok::before { content: "✓ "; font-weight: 700; }
.ix-results li.is-bad::before { content: "✗ "; font-weight: 700; }
.ix-chain { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.ix-arrow { justify-self: center; color: var(--muted); font: 600 .7rem/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.ix-arrow::before { content: "↓ "; }

@media (max-width: 700px) {
  .ix { padding: 16px; }
  .ix-split, .ix-plan .ix-split { grid-template-columns: minmax(0, 1fr); }
  .ix-receipt dl > div { grid-template-columns: 70px minmax(0, 1fr); }
  /* Six labels don't fit a phone: show the current stage's name and a dot for the rest. */
  .ix-pipeline nav { justify-content: space-between; }
  .ix-step { flex: 0 0 auto; padding: 6px 9px; font-size: .7rem; }
  .ix-step:not([aria-current]) .ix-step-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .ix .ix-code { font-size: .74rem; }
  .ix-plan .ix-code { font-size: .7rem; white-space: pre; }
}

@media (prefers-reduced-motion: reduce) {
  .ix *, .ix *::before { animation: none !important; transition: none !important; }
}
