/*
 * Illustrative backtest sequence (website component, markup: [data-backtest]).
 * Colours only via tokens.css, so dark and light follow the theme automatically.
 * Motion: opacity/transform on a few groups; one stroke-dashoffset sheen on the target line.
 */

.bt {
  container-type: inline-size;
  display: grid; gap: var(--s-4);
  margin: 0;
  padding: clamp(16px, .75rem + 1.2vw, 28px);
  border-radius: var(--r-lg);
  background: var(--surface-1);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-2);
}

/* Status + controls */
.bt-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3) var(--s-4); }
.bt-status {
  display: inline-flex; align-items: center; gap: 10px; margin: 0;
  min-height: 24px; font-size: var(--fs-small); font-weight: 600; color: var(--text-1);
  font-variant-numeric: tabular-nums lining-nums;
}
.bt-status::before {
  content: ""; width: 8px; height: 8px; flex: none; border-radius: 50%;
  background: var(--gold); transition: background-color var(--dur-2) ease-out;
}
.bt[data-phase="target"] .bt-status::before { background: var(--pos); }

.bt-controls { display: flex; gap: 8px; }
.bt-controls[hidden] { display: none; }
.bt-btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: var(--r-pill);
  border: 1px solid var(--line-ui); background: transparent; color: var(--text-1);
  font: 600 var(--fs-small)/1.2 var(--sans); cursor: pointer;
  transition: background-color var(--dur-1) ease-out, border-color var(--dur-1) ease-out, transform var(--dur-1) ease-out;
}
.bt-btn:active { transform: scale(.97); background: var(--pressed); }
.bt-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.bt-btn[aria-pressed="true"] { background: var(--selected); border-color: var(--gold-line); }
.bt-btn svg { width: 14px; height: 14px; flex: none; fill: currentColor; }
.bt-btn .i-play { display: none; }
.bt-btn[aria-pressed="true"] .i-play { display: block; }
.bt-btn[aria-pressed="true"] .i-pause { display: none; }
.bt-btn .i-restart { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: hover) and (pointer: fine) {
  .bt-btn:hover { border-color: var(--gold); background: var(--hover); }
}

/* Stage: fixed proportions → no layout shift when JS takes over */
.bt-stage { position: relative; aspect-ratio: 16 / 9; min-width: 0; }
.bt-svg { display: block; width: 100%; height: 100%; overflow: hidden; }
.bt-poster--compact { display: none; }
@container (max-width: 559px) {
  .bt-stage { aspect-ratio: 4 / 3; }
  .bt-poster--wide { display: none; }
  .bt-poster--compact { display: block; }
}

.bt-caption { margin: 0; }

/* ---------- Chart ---------- */
.bt-svg text { font-family: var(--sans); font-size: 13px; font-variant-numeric: tabular-nums lining-nums; }
.bt-svg.is-compact text, .bt-poster--compact text { font-size: 12px; }

.bt-grid line { stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
.bt-grid .bt-axis { stroke: var(--line-strong); }
.bt-tick { fill: var(--text-3); transition: opacity 380ms var(--ease-out); }
.bt-svg:has(.bt-setup.is-on) .bt-tick--under { opacity: 0; }

.bt-c line { stroke-width: 1.25; }
.bt-c.is-up line { stroke: var(--pos); }
.bt-c.is-up rect { fill: var(--pos); }
.bt-c.is-down line { stroke: var(--neg); }
.bt-c.is-down rect { fill: var(--neg); }

.bt-zone-tp { fill: var(--pos-tint); }
.bt-zone-sl { fill: var(--neg-tint); }
.bt-line-tp { stroke: var(--pos); stroke-width: 1.25; }
.bt-line-sl { stroke: var(--neg); stroke-width: 1.25; }
.bt-line-entry { stroke: var(--gold); stroke-width: 1.25; stroke-dasharray: 5 4; }

.bt-label { font-weight: 600; }
.bt-label-tp { fill: var(--pos); }
.bt-label-sl { fill: var(--neg); }
.bt-label-ratio { fill: var(--text-2); }

.bt-tag text { fill: var(--on-gold); font-weight: 600; }
.bt-tag--tp rect { fill: var(--pos); }
.bt-tag--stop rect { fill: var(--neg); }
.bt-tag--entry rect { fill: var(--gold-fill); }

.bt-marker { fill: var(--surface-1); stroke: var(--pos); stroke-width: 2; }
.bt-chip rect { fill: var(--surface-1); stroke: var(--pos); stroke-width: 1.25; }
.bt-chip path { fill: none; stroke: var(--pos); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bt-chip text { fill: var(--text-1); font-weight: 600; }
.bt-sheen { stroke: var(--pos); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 14 200; stroke-dashoffset: 14; opacity: 0; }

/* ---------- States (classes toggled by /js/backtest-sequence.mjs) ---------- */
.bt-setup, .bt-hit { opacity: 0; transition: opacity 380ms var(--ease-out); }
.bt-setup.is-on, .bt-hit.is-on { opacity: 1; }
.bt-setup-front { transform: translateY(3px); transition: opacity 380ms var(--ease-out), transform 420ms var(--ease-out); }
.bt-setup-front.is-on { transform: none; }

.bt-chip { transform-box: fill-box; transform-origin: 0 50%; transform: translateY(4px) scale(.96); transition: transform 360ms var(--ease-out); }
.bt-hit.is-on .bt-chip { transform: none; }
.bt-hit.is-on .bt-sheen { animation: bt-sheen 900ms var(--ease-in-out) 80ms 1 both; }
.bt-hit.is-on .bt-marker { animation: bt-pop 320ms var(--ease-out) both; }

.bt-future { transition: opacity 460ms var(--ease-out); }
.bt-future.is-out { opacity: 0; }
.bt-new { transform-box: fill-box; transform-origin: 50% 50%; animation: bt-in 280ms var(--ease-out) both; }

@keyframes bt-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes bt-pop { from { opacity: 0; transform: scale(.6); } }
@keyframes bt-sheen {
  0% { stroke-dashoffset: 14; opacity: 0; }
  15% { opacity: .9; }
  85% { opacity: .9; }
  100% { stroke-dashoffset: -100; opacity: 0; }
}
.bt-marker { transform-box: fill-box; transform-origin: 50% 50%; }

/* Static poster (no JS, or animations paused): end state without motion */
:root[data-motion="off"] .bt-new,
.bt-poster .bt-new { animation: none; }
:root[data-motion="off"] .bt-hit.is-on .bt-sheen,
.bt-poster .bt-sheen { animation: none; opacity: 0; }
