/* CandleChart, miniChart and candleSVG (js/core/chart.js). Everything is coloured through the
   design tokens in css/tokens.css, so light and dark themes follow automatically. */

.tc-chart {
  position: relative;
  width: 100%;
  min-width: 0;
  background: var(--surface);
  border-radius: var(--radius-sm, 6px);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.tc-chart.is-interactive:focus-visible {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--focus);
}

.tc-svg {
  display: block;
  width: 100%;
  overflow: hidden;
  touch-action: pan-y;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  -webkit-touch-callout: none;
}

.tc-chart.is-interactive .tc-svg { cursor: crosshair; }
.tc-chart.is-pannable.is-panning .tc-svg { cursor: grabbing; }
.tc-chart.is-drawing .tc-svg,
.tc-chart.is-dragging .tc-svg { touch-action: none; }
.tc-chart.is-dragging .tc-svg { cursor: grabbing; }

.tc-bg { fill: var(--surface); }

/* Grid and axes */
.tc-grid { fill: none; stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.tc-axis-line,
.tc-pane-div { fill: none; stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
.tc-axis-text {
  fill: var(--text-2);
  font: 500 11px/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Candles — strong bull/bear contrast so game answers stay readable */
.tc-bull { fill: var(--bull); stroke: var(--bull-strong, var(--bull)); }
.tc-bear { fill: var(--bear); stroke: var(--bear-strong, var(--bear)); }
.tc-wick { fill: none; shape-rendering: crispEdges; }
.tc-body { stroke: none; shape-rendering: crispEdges; }
.tc-body.tc-bull { fill: var(--bull); }
.tc-body.tc-bear { fill: var(--bear); }
.tc-vol { stroke: none; opacity: 0.26; shape-rendering: crispEdges; }
.tc-bar { fill: none; stroke-linecap: butt; shape-rendering: crispEdges; }

/* Line chart: close line with a subtle area */
.tc-line { fill: none; stroke: var(--info); stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.tc-area { stroke: none; }
.tc-area-stop0 { stop-color: var(--info); stop-opacity: 0.2; }
.tc-area-stop1 { stop-color: var(--info); stop-opacity: 0; }

/* Focus (ChartStory): candles outside the focus range are dimmed */
.tc-dimmed { transition: opacity 0.2s; }

/* Overlays that appear with a one-off pulse (spec.pulse) */
.tc-pulse { animation: tc-pulse 1.3s var(--ease-out, ease-out) both; }
@keyframes tc-pulse {
  0% { opacity: 0; }
  22% { opacity: 1; }
  45% { opacity: 0.35; }
  70% { opacity: 1; }
  100% { opacity: 1; }
}

/* Overlays */
.tc-series,
.tc-path,
.tc-seg,
.tc-hline,
.tc-fib-line,
.tc-draw-line { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.tc-hline,
.tc-fib-line { stroke-linecap: butt; shape-rendering: crispEdges; }
.tc-fib-line { opacity: 0.85; }
.tc-fib-line.is-key { opacity: 1; }
.tc-fib-trend { fill: none; stroke-width: 1; stroke-dasharray: 3 4; opacity: 0.7; }
.tc-fib-zone { fill-opacity: 0.13; stroke: none; }
.tc-band { stroke: none; }
.tc-band-edge { fill: none; stroke-width: 1; stroke-opacity: 0.55; }
.tc-zone { stroke: none; }
.tc-zone-edge { fill: none; stroke-width: 1; stroke-opacity: 0.55; stroke-dasharray: 4 3; shape-rendering: crispEdges; }
.tc-box { fill-opacity: 0.08; stroke-width: 1.25; stroke-dasharray: 5 3; }
.tc-level { fill: none; stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.8; shape-rendering: crispEdges; }
.tc-zero { fill: none; stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
.tc-hist { stroke: none; opacity: 0.75; shape-rendering: crispEdges; }
.tc-dot { fill: var(--surface); stroke-width: 2; }
.tc-ring { fill: none; stroke-width: 2; }
.tc-marker { stroke: var(--surface); stroke-width: 1; paint-order: stroke; }
.tc-lastline { fill: none; stroke-width: 1; stroke-dasharray: 1 3; opacity: 0.7; shape-rendering: crispEdges; }

/* Text: a halo in the surface colour keeps labels readable over candles */
.tc-label,
.tc-legend,
.tc-pane-title {
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.tc-label {
  font: 600 11px/1 var(--font-body);
  letter-spacing: 0.01em;
}
.tc-label--strong { font-weight: 700; }
.tc-legend,
.tc-pane-title {
  font: 500 11.5px/1 var(--font-mono);
  fill: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.tc-legend-k { fill: var(--text-3); }
.tc-legend-note { fill: var(--warn); font-family: var(--font-body); font-size: 11px; font-weight: 600; }
.tc-up { fill: var(--bull); }
.tc-down { fill: var(--bear); }
.tc-pane-title { fill: var(--text-2); font-family: var(--font-body); font-weight: 600; }
.tc-pane-title tspan { font-family: var(--font-mono); font-weight: 500; }

/* Pills: solid ones sit on the price axis, outlined ones inside the plot */
.tc-pill text {
  fill: var(--surface);
  font: 600 11px/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.tc-ipill rect,
.tc-lpill rect {
  fill: var(--surface);
  fill-opacity: 0.92;
  stroke-width: 1;
}
.tc-ipill text,
.tc-lpill text {
  font: 600 11px/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.tc-lpill text { font-family: var(--font-body); }

/* Crosshair */
.tc-l-cross { pointer-events: none; }
.tc-cross-line { fill: none; stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 4 4; shape-rendering: crispEdges; }
.tc-cross-y rect,
.tc-cross-x rect { fill: var(--text); }
.tc-cross-y text,
.tc-cross-x text {
  fill: var(--surface);
  font: 600 11px/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Drawing + handles */
.tc-l-draw { pointer-events: none; }
.tc-draw-line { stroke-width: 2; stroke-dasharray: 6 4; }
.tc-draw-zone { fill-opacity: 0.14; stroke-width: 1; stroke-dasharray: 4 3; }
.tc-draw-dot { fill: var(--surface); stroke-width: 2.5; }
.tc-handle { fill: var(--surface); stroke-width: 2.5; pointer-events: none; }
.tc-hit {
  fill: transparent;
  stroke: transparent;
  cursor: grab;
  touch-action: none;
  pointer-events: all;
}
.tc-hit-line { fill: none; stroke-width: 24; cursor: ns-resize; }
.tc-handle-g:hover .tc-handle { stroke-width: 3.5; }

/* Reveal + flash */
.tc-flash {
  pointer-events: none;
  opacity: 0;
  animation: tc-flash 0.9s var(--ease-out, ease-out);
}
@keyframes tc-flash {
  0% { opacity: 0.38; }
  100% { opacity: 0; }
}

.tc-arrowhead { stroke: none; }

/* Screen-reader live region */
.tc-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* miniChart */
.tc-mini {
  display: block;
  max-width: 100%;
  height: auto;
  overflow: hidden;
  font-family: var(--font-mono);
  border-radius: 8px;
}
.tc-mini--axis {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.tc-mini-hl { fill: var(--accent-soft); }
.tc-mini .tc-axis-text { font-size: 11px; fill: var(--text-2); }
.tc-mini .tc-pill text {
  fill: var(--surface);
  font: 600 11px/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* candleSVG */
.tc-candle-svg {
  display: block;
  max-width: 100%;
  height: auto;
  overflow: visible;
}
.tc-candle-svg .tc-wick { shape-rendering: auto; stroke-linecap: round; }
.tc-callout,
.tc-bracket { fill: none; stroke: var(--text-3); stroke-width: 1; }
.tc-callout-text { fill: var(--text-2); font: 600 12px/1 var(--font-body); }

@media (prefers-reduced-motion: reduce) {
  .tc-flash { animation: none; opacity: 0.22; }
  .tc-pulse { animation: none; }
}

/* ChartStory (js/core/story.js): chart, caption bar, transport with numbered frame dots */
.cs {
  margin: 0;
  display: grid;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius, 10px);
  overflow: hidden;
  outline: none;
}
.cs:focus-visible { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--focus); }
.cs__stage { padding: 8px 6px 2px; min-width: 0; }
.cs__caption {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin: 0;
  padding: 12px 14px;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  box-shadow: inset 3px 0 0 var(--accent);
}
.cs__num {
  flex: none;
  min-width: 2.6em;
  padding-top: 1px;
  font: 800 20px/1.1 var(--font-display);
  color: var(--accent-strong, var(--accent));
  font-variant-numeric: tabular-nums;
}
.cs__num span { margin-left: 1px; font: 600 12px/1 var(--font-mono); color: var(--text-3); }
.cs__text {
  margin: 0;
  min-height: 3em;
  font: 400 15px/1.5 var(--font-body);
  color: var(--text);
  text-wrap: pretty;
}
.cs__text strong { font-weight: 700; }
.cs__text.is-new { animation: cs-caption 0.35s var(--ease-out, ease-out); }
@keyframes cs-caption {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
.cs__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
}
.cs__btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.cs__btn svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.cs__btn svg .cs-fill { fill: currentColor; stroke: none; }
.cs__btn:hover:not(:disabled) { border-color: var(--text-3); }
.cs__btn:disabled { opacity: 0.4; cursor: default; }
.cs__btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.cs__btn--play {
  width: 42px;
  height: 42px;
  border-color: transparent;
  background: var(--btn-primary, var(--accent));
  color: var(--accent-ink);
}
.cs__btn--play:hover:not(:disabled) { background: var(--btn-primary-hover, var(--accent)); border-color: transparent; }
.cs__scrub {
  position: relative;
  flex: 1 1 200px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 2px;
  cursor: pointer;
  touch-action: none;
  outline: none;
  border-radius: 22px;
  -webkit-user-select: none;
  user-select: none;
}
.cs__scrub:focus-visible { box-shadow: 0 0 0 2px var(--focus); }
.cs__track {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 50%;
  height: 3px;
  margin-top: -1.5px;
  border-radius: 2px;
  background: var(--line);
}
.cs__fill { width: 0; height: 100%; border-radius: 2px; background: var(--accent); transition: width 0.3s var(--ease-out, ease-out); }
.cs__dot {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--text-3);
  font: 600 11px/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
  transition: transform 0.2s var(--ease-out, ease-out), background-color 0.2s, border-color 0.2s;
}
.cs__dot.is-done { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong, var(--text)); }
.cs__dot.is-current {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  transform: scale(1.15);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.cs--single .cs__controls { display: none; }
@media (pointer: coarse) {
  .cs__btn { width: 44px; height: 44px; }
}
@media (max-width: 480px) {
  .cs__caption { padding: 10px 12px; gap: 10px; }
  .cs__text { font-size: 14px; }
  .cs__num { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .cs__text.is-new { animation: none; }
  .cs__fill, .cs__dot { transition: none; }
}
