/* ==========================================================================
   Components
   ========================================================================== */

/* -- Card ------------------------------------------------------------------ */

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--pad);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  min-width: 0;
}

/* Wraps rather than crushing its controls: on a narrow phone the timeframe
   tabs drop below the title instead of squeezing it onto two lines. */
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.card__title {
  white-space: nowrap;
  font-size: var(--fs-2xs);
  font-weight: 650;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--text-mute);
}

/* -- Connection status ----------------------------------------------------- */

.status {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0.35em 0.75em;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
  white-space: nowrap;
}

.status__dot {
  width: 7px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--text-mute);
  flex: none;
}

.status[data-state="live"]         { color: var(--buy); border-color: var(--buy-soft); }
.status[data-state="live"] .status__dot {
  background: var(--buy);
  box-shadow: 0 0 0 0 var(--buy);
  animation: pulse 2s var(--ease) infinite;
}
.status[data-state="connecting"]   { color: var(--accent); }
.status[data-state="connecting"] .status__dot { background: var(--accent); animation: blink 1s steps(2) infinite; }
.status[data-state="offline"]      { color: var(--sell); }
.status[data-state="offline"] .status__dot { background: var(--sell); }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(0, 214, 143, 0.55); }
  70%  { box-shadow: 0 0 0 7px rgba(0, 214, 143, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 214, 143, 0); }
}
@keyframes blink { 50% { opacity: 0.25; } }

/* -- Icon button ----------------------------------------------------------- */

.iconbtn {
  display: grid;
  place-items: center;
  width: 2.25rem;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  transition: background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}

.iconbtn:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

.iconbtn svg { width: 1.05rem; height: 1.05rem; }

/* -- Price ----------------------------------------------------------------- */

.price {
  display: flex;
  align-items: baseline;
  gap: 0.12em;
  font-size: var(--fs-price);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1;
  transition: color var(--dur) var(--ease);
}

.price__cur { font-size: 0.42em; color: var(--text-mute); font-weight: 600; }
.price__frac { font-size: 0.46em; color: var(--text-dim); font-weight: 650; }

.hero__label {
  font-size: var(--fs-2xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-mute);
  margin-bottom: var(--sp-3);
}

/* space-between rather than center: the price anchors the top of the card and
   the range bar the bottom, so the card stays balanced as the signal card
   beside it grows. */
.hero__price-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--sp-5);
}

/* Before the first tick arrives the price is a placeholder, not a value. */
.price.is-loading { color: var(--text-mute); opacity: 0.5; }

/* Tick direction. The colour is applied on the next frame and removed shortly
   after, so a run of ticks reads as a pulse rather than a solid colour. */
.price[data-tick="up"]   { color: var(--buy); }
.price[data-tick="down"] { color: var(--sell); }

/* -- 24h delta ------------------------------------------------------------- */

.delta {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
  font-size: var(--fs-lg);
  font-weight: 650;
  color: var(--neutral);
  transition: color var(--dur) var(--ease);
}

.delta[data-dir="up"]   { color: var(--buy); }
.delta[data-dir="down"] { color: var(--sell); }

/* A CSS triangle keeps the direction glyph aligned to the text baseline in a
   way an emoji or arrow character will not. */
.delta__arrow {
  width: 0; height: 0;
  border-inline: 0.36em solid transparent;
  align-self: center;
  transition: transform var(--dur) var(--ease);
}
.delta[data-dir="up"] .delta__arrow   { border-bottom: 0.5em solid currentColor; }
.delta[data-dir="down"] .delta__arrow { border-top: 0.5em solid currentColor; }
.delta[data-dir="flat"] .delta__arrow { display: none; }

.delta__abs { color: var(--text-dim); font-weight: 550; font-size: 0.82em; }
.delta__note {
  color: var(--text-mute);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* -- 24h range ------------------------------------------------------------- */

.range { margin-top: var(--sp-5); }

.range__track {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg,
    var(--sell-soft) 0%,
    var(--surface-hover) 50%,
    var(--buy-soft) 100%);
  border: 1px solid var(--border);
}

.range__marker {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: 16px;
  border-radius: 999px;
  background: var(--text);
  box-shadow: 0 0 0 3px var(--bg), 0 0 14px 1px currentColor;
  transform: translate(-50%, -50%);
  /* Eased so the marker glides between ticks instead of snapping. */
  transition: left var(--dur-slow) var(--ease);
}

.range__ends {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
  font-size: var(--fs-xs);
  color: var(--text-dim);
}

.range__cap {
  color: var(--text-mute);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  font-size: 0.86em;
}

/* -- Stats strip -----------------------------------------------------------
   auto-fit lets the strip go from four across on a desktop down to two, then
   one, without a single media query. */

.statstrip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(clamp(7rem, 18vw, 11rem), 1fr));
  gap: var(--gap);
}

/* Block, not a column flex, so the value and its unit share one baseline. */
.stat { min-width: 0; }

.stat__key {
  display: block;
  margin-bottom: 0.2em;
  font-size: var(--fs-2xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-mute);
}

.stat__val {
  font-size: var(--fs-lg);
  font-weight: 650;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat__unit {
  margin-left: 0.3em;
  font-size: var(--fs-2xs);
  color: var(--text-mute);
}

/* -- Signal card ----------------------------------------------------------- */

/* One band colour per card drives the gauge, the verdict and the glow, so a
   single data attribute recolours the whole component. */
.signal[data-band="strong-buy"]  { --band: var(--buy); }
.signal[data-band="buy"]         { --band: var(--buy); }
.signal[data-band="neutral"]     { --band: var(--neutral); }
.signal[data-band="sell"]        { --band: var(--sell); }
.signal[data-band="strong-sell"] { --band: var(--sell); }

.signal {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  overflow: hidden;
}

/* A soft wash of the current band colour bleeding in from the top edge. */
.signal::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 45%;
  pointer-events: none;
  background: radial-gradient(70% 100% at 50% 0%,
    color-mix(in oklab, var(--band) 16%, transparent), transparent 70%);
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease);
}
.signal[data-ready="true"]::after { opacity: 1; }

.signal__window {
  font-size: var(--fs-2xs);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-mute);
}

/* -- Gauge ----------------------------------------------------------------- */

.gauge {
  position: relative;
  width: min(100%, var(--gauge-w));
  margin-inline: auto;
}

.gauge__svg { display: block; width: 100%; height: auto; overflow: visible; }

/* CSS-set stops, because a presentation attribute cannot read a custom
   property and the palette must follow the theme. */
.g-sell { stop-color: var(--sell); }
.g-mid  { stop-color: var(--neutral); }
.g-buy  { stop-color: var(--buy); }

.gauge__track {
  fill: none;
  stroke: var(--track);
  stroke-width: 13;
  stroke-linecap: round;
}

.gauge__value {
  fill: none;
  stroke: url(#gaugeTrack);
  stroke-width: 13;
  stroke-linecap: round;
  /* Hidden until the first reading; a dash of zero length draws nothing. */
  stroke-dasharray: 0 9999;
  transition: stroke-dasharray var(--dur-slow) var(--ease),
              stroke-dashoffset var(--dur-slow) var(--ease);
}

.gauge__knob {
  fill: var(--text);
  stroke: var(--bg);
  stroke-width: 3;
  transform-origin: 100px 100px;
  transition: transform var(--dur-slow) var(--ease);
  filter: drop-shadow(0 0 6px var(--band));
}

.gauge__center {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  text-align: center;
  line-height: 1.1;
}

.gauge__score {
  font-size: clamp(1.75rem, 1.3rem + 1.7vw, 2.75rem);
  font-weight: 750;
  letter-spacing: -0.03em;
  color: var(--band);
  transition: color var(--dur) var(--ease);
}

.gauge__caption {
  font-size: var(--fs-2xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-mute);
}

.gauge__ends {
  display: flex;
  justify-content: space-between;
  margin-top: calc(var(--sp-4) * -1);
  font-size: var(--fs-2xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-mute);
}

/* -- Verdict --------------------------------------------------------------- */

.verdict { text-align: center; }

.verdict__label {
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--band);
  transition: color var(--dur) var(--ease);
}

.verdict__blurb {
  margin-top: 0.15em;
  font-size: var(--fs-sm);
  color: var(--text-dim);
  text-wrap: balance;
}

/* -- Buy/sell split -------------------------------------------------------- */

.split__bar {
  display: flex;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--track);
  gap: 2px;
}

.split__seg {
  transition: width var(--dur-slow) var(--ease);
  width: 50%;
}
.split__seg--buy  { background: var(--buy); }
.split__seg--sell { background: var(--sell); }

.split__legend {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

.split__item { display: inline-flex; align-items: center; gap: 0.45em; }
.split__item b { color: var(--text); font-weight: 650; }

.dot {
  width: 0.55em; aspect-ratio: 1;
  border-radius: 50%;
  flex: none;
}
.dot--buy  { background: var(--buy); }
.dot--sell { background: var(--sell); }

.signal__foot {
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--text-mute);
}

/* -- Timeframe tabs -------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.tab {
  padding: 0.4em 0.95em;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-mute);
  transition: color var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease);
}

.tab:hover { color: var(--text); }

.tab.is-active {
  background: var(--surface-hover);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}

/* -- Chart ----------------------------------------------------------------- */

/* The chart's own accent follows the period's direction, and every stroke in
   the canvas derives from it. */
.chart__canvas[data-dir="up"]   { --line: var(--buy); }
.chart__canvas[data-dir="down"] { --line: var(--sell); }

.chart__canvas {
  position: relative;
  width: 100%;
  /* Shorter on phones, taller on desks and TVs, without a media query. */
  height: var(--panel-h);
  touch-action: pan-y;
}

.chart__svg { display: block; }

.c-top { stop-color: var(--line); stop-opacity: 0.30; }
.c-bot { stop-color: var(--line); stop-opacity: 0; }

.chart__area { fill: url(#chartFill); stroke: none; }

.chart__line {
  fill: none;
  stroke: var(--line);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart__baseline {
  stroke: var(--border-strong);
  stroke-width: 1;
  stroke-dasharray: 3 5;
}

/* The user-agent [hidden] rule does not reach SVG elements - a <g hidden>
   still computes to display:inline - so the crosshair must be hidden
   explicitly, or its dot paints at the SVG origin. */
.chart__cross[hidden] { display: none; }

.chart__cross line {
  stroke: var(--text-dim);
  stroke-width: 1;
  stroke-dasharray: 3 4;
}

.chart__cross circle {
  fill: var(--line);
  stroke: var(--bg);
  stroke-width: 3;
}

.chart__tip {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 0.1em;
  padding: 0.45em 0.7em;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface-solid);
  box-shadow: var(--shadow);
  font-size: var(--fs-xs);
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
}

/* An author `display` beats the user-agent rule for [hidden], so the attribute
   has to be honoured explicitly or the empty tooltip stays on screen. */
.chart__tip[hidden] { display: none; }

.chart__tip b { font-size: var(--fs-sm); font-weight: 650; }
.chart__tip span { color: var(--text-mute); }

.chart__edge {
  position: absolute;
  right: 0;
  padding: 0.1em 0.4em;
  border-radius: 5px;
  background: var(--surface);
  font-size: var(--fs-2xs);
  color: var(--text-mute);
  pointer-events: none;
}

.chart__edge--hi { top: 0; }
.chart__edge--lo { bottom: 0; }

/* -- Trade tape ------------------------------------------------------------ */

.tape { display: flex; flex-direction: column; }

.tape__legend {
  font-size: var(--fs-2xs);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-mute);
}

.tape__list {
  position: relative;
  list-style: none;
  height: var(--panel-h);
  overflow: hidden;
  /* Rows dissolve as they age out rather than being cut off mid-glyph. */
  mask-image: linear-gradient(to bottom, #000 62%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 62%, transparent 100%);
}

.tape__row {
  display: grid;
  grid-template-columns: 3.2rem minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--sp-2);
  padding: 0.42em 0.5em;
  border-radius: 7px;
  font-size: var(--fs-sm);
  animation: tape-in var(--dur) var(--ease);
}

/* Each row enters from above with the fill tint at full strength, then settles
   - so the eye is drawn to what is new without the list ever jumping. */
@keyframes tape-in {
  from { opacity: 0; transform: translateY(-70%); }
  to   { opacity: 1; transform: none; }
}

.tape__row[data-side="buy"]  { --fill: var(--buy); }
.tape__row[data-side="sell"] { --fill: var(--sell); }

.tape__side {
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--fill);
}

.tape__price { font-weight: 600; }
.tape__size  { color: var(--text-dim); text-align: right; }

.tape__time {
  color: var(--text-mute);
  font-size: var(--fs-xs);
  text-align: right;
}

/* Size alone is easy to miss in a fast tape, so a notable fill is given the
   band colour as a background and a marker rail. */
.tape__row.is-notable {
  background: color-mix(in oklab, var(--fill) 14%, transparent);
  box-shadow: inset 2px 0 0 var(--fill);
}
.tape__row.is-notable .tape__size { color: var(--text); font-weight: 650; }

/* On the narrowest phones the timestamp is the first thing to go: a live tape
   is self-evidently "now", and the space is better spent on price and size. */
@media (max-width: 26rem) {
  .tape__row { grid-template-columns: 2.8rem minmax(0, 1fr) auto; }
  .tape__time { display: none; }
}

.tape__empty {
  padding-top: var(--sp-3);
  font-size: var(--fs-xs);
  color: var(--text-mute);
  text-align: center;
}
.tape__empty[hidden] { display: none; }

/* Show the icon for the theme the button switches *to*, not the current one:
   a dark page offers the sun, a light page offers the moon. */
:root[data-theme="dark"]  .icon-moon { display: none; }
:root[data-theme="light"] .icon-sun  { display: none; }

/* -- Boot notice -----------------------------------------------------------
   Shown only when the application failed to start, so it must not depend on
   anything the application does. */

.notice {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--pad);
  border: 1px solid color-mix(in oklab, var(--sell) 45%, transparent);
  border-radius: var(--r-md);
  background: var(--sell-soft);
}

.notice[hidden] { display: none; }

.notice__mark {
  display: grid;
  place-items: center;
  width: 1.5rem;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--sell);
  color: var(--bg);
  font-weight: 800;
  font-size: var(--fs-sm);
  flex: none;
}

.notice__title {
  font-size: var(--fs-md);
  font-weight: 650;
  margin-bottom: 0.2em;
}

.notice__body { font-size: var(--fs-sm); color: var(--text-dim); }
.notice__body [hidden] { display: none; }

.notice code {
  padding: 0.1em 0.4em;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-hover);
  color: var(--text);
  font-size: 0.92em;
  white-space: nowrap;
}

/* -- How it works ----------------------------------------------------------
   The only prose on the page. It exists so a first-time visitor has a reason
   to trust the number, and so the page has something to say to a search
   engine - a live gauge is invisible to both. */

.explain { display: flex; flex-direction: column; gap: var(--sp-5); }

.explain__title {
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.025em;
}

.explain__lede {
  font-size: var(--fs-lg);
  line-height: 1.45;
  color: var(--text-dim);
  max-width: 62ch;
  text-wrap: pretty;
}

/* Three across on a wide screen, one on a phone, with no breakpoint of its
   own - auto-fit collapses the track count when the columns get too narrow. */
.explain__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
  gap: var(--gap);
}

.explain__item { min-width: 0; }

.explain__num {
  display: grid;
  place-items: center;
  width: 1.9em;
  aspect-ratio: 1;
  margin-bottom: var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  color: var(--accent);
  font-size: var(--fs-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.explain__item h3,
.explain__proof h3,
.explain__limits h3 {
  margin-bottom: var(--sp-2);
  font-size: var(--fs-md);
  font-weight: 650;
}

.explain__item p,
.explain__proof p,
.explain__limits li {
  font-size: var(--fs-sm);
  line-height: 1.6;
  color: var(--text-dim);
  text-wrap: pretty;
}

.explain__item p + p,
.explain__proof p + p { margin-top: var(--sp-3); }

.explain strong { color: var(--text); font-weight: 650; }
.explain em { color: var(--text); font-style: normal; font-weight: 600; }

.explain code {
  padding: 0.08em 0.35em;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-hover);
  color: var(--text);
  font-size: 0.9em;
}

/* The evidence block: the one place the page shows its working. */
.explain__proof {
  padding: var(--pad);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: var(--r-md);
  background: var(--surface);
}

.explain__data {
  margin: var(--sp-3) 0;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--fs-xs);
  line-height: 1.7;
  /* Narrow screens scroll the block rather than the page. */
  overflow-x: auto;
}

.explain__data code {
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
}

.explain__limits ul {
  display: grid;
  gap: var(--sp-3);
  padding-left: 1.1em;
  max-width: 68ch;
}

.explain__limits li::marker { color: var(--text-mute); }
