/* Interactive article charts.
   Progressive enhancement: every number and label lives in the HTML as text,
   so crawlers, AI answer engines and no-JS readers get the full content.
   js/article-charts.js only adds the reveal animation and the metric toggle. */

.article-layout > .article-content { min-width: 0; }
@media (max-width: 768px) {
  .article-layout { grid-template-columns: minmax(0, 1fr); }
}

/* lists inside charts must not inherit the article's list styling */
.article-content .eh-chart ol {
  margin: 0;
  padding: 0;
  list-style: none;
  gap: 0;
}
.article-content .eh-chart li { opacity: 1; line-height: 1.4; }
.article-content .eh-chart ol.fb-bars,
.article-content .eh-chart ol.fb-labels { display: grid; gap: 14px; }
.article-content .eh-chart ol.ss-rows { display: block; }

.eh-chart {
  margin: 36px 0 12px;
  padding: 28px 28px 24px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
}

.eh-chart figcaption {
  margin-bottom: 22px;
}

.eh-chart figcaption strong {
  display: block;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text);
}

.eh-chart figcaption span {
  display: block;
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-muted);
}

.eh-chart .eh-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.eh-legend i {
  display: inline-block;
  vertical-align: middle;
  margin-right: 8px;
}

.eh-legend .lg-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--amber); }
.eh-legend .lg-band { width: 22px; height: 10px; border-radius: 5px; background: var(--green); }

/* ---------- Sweet-spot timeline ---------- */
.ss-rows {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ss-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  column-gap: 16px;
  align-items: center;
  padding: 10px 8px;
  margin: 0 -8px;
  border-radius: 8px;
  cursor: default;
  outline: none;
  transition: background 0.2s;
}

.ss-row:hover,
.ss-row:focus-visible,
.ss-row.is-open {
  background: rgba(255, 255, 255, 0.04);
}

.ss-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.ss-track {
  position: relative;
  height: 14px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
}

.ss-band {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--from) / 75 * 100%);
  width: calc((var(--to) - var(--from)) / 75 * 100%);
  border-radius: 7px;
  background: linear-gradient(90deg, var(--teal), var(--green));
  box-shadow: 0 0 14px rgba(84, 228, 43, 0.35);
  transform-origin: left center;
  transition: transform 0.9s cubic-bezier(.2, .8, .2, 1), opacity 0.6s;
}

.ss-row.is-open-ended .ss-band {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  -webkit-mask-image: linear-gradient(90deg, #000 75%, transparent);
  mask-image: linear-gradient(90deg, #000 75%, transparent);
}

.ss-dot {
  position: absolute;
  top: 50%;
  left: calc(var(--med) / 75 * 100%);
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: var(--amber);
  border: 2px solid var(--bg);
  z-index: 1;
  transition: left 0.9s cubic-bezier(.2, .8, .2, 1), opacity 0.4s;
}

.ss-text {
  grid-column: 2;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.3s, opacity 0.3s, margin 0.3s;
}

.ss-row:hover .ss-text,
.ss-row:focus-visible .ss-text,
.ss-row.is-open .ss-text {
  max-height: 80px;
  opacity: 1;
  margin-top: 8px;
}

.ss-axis {
  display: grid;
  grid-template-columns: 130px 1fr;
  column-gap: 16px;
  margin-top: 8px;
}

.ss-axis-scale {
  position: relative;
  height: 18px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
}

.ss-axis-scale span {
  position: absolute;
  left: calc(var(--at) / 75 * 100%);
  transform: translateX(-50%);
}

/* reveal animation (only once JS has marked the chart) */
.eh-chart.eh-anim .ss-band { transform: scaleX(0); opacity: 0; }
.eh-chart.eh-anim .ss-dot { left: 0; opacity: 0; }
.eh-chart.eh-anim.eh-in .ss-band { transform: scaleX(1); opacity: 1; }
.eh-chart.eh-anim.eh-in .ss-dot { left: calc(var(--med) / 75 * 100%); opacity: 1; }
.eh-chart.eh-anim.eh-in .ss-row:nth-child(2) .ss-band,
.eh-chart.eh-anim.eh-in .ss-row:nth-child(2) .ss-dot { transition-delay: 0.08s; }
.eh-chart.eh-anim.eh-in .ss-row:nth-child(3) .ss-band,
.eh-chart.eh-anim.eh-in .ss-row:nth-child(3) .ss-dot { transition-delay: 0.16s; }
.eh-chart.eh-anim.eh-in .ss-row:nth-child(4) .ss-band,
.eh-chart.eh-anim.eh-in .ss-row:nth-child(4) .ss-dot { transition-delay: 0.24s; }
.eh-chart.eh-anim.eh-in .ss-row:nth-child(5) .ss-band,
.eh-chart.eh-anim.eh-in .ss-row:nth-child(5) .ss-dot { transition-delay: 0.32s; }
.eh-chart.eh-anim.eh-in .ss-row:nth-child(6) .ss-band,
.eh-chart.eh-anim.eh-in .ss-row:nth-child(6) .ss-dot { transition-delay: 0.40s; }
.eh-chart.eh-anim.eh-in .ss-row:nth-child(7) .ss-band,
.eh-chart.eh-anim.eh-in .ss-row:nth-child(7) .ss-dot { transition-delay: 0.48s; }

/* ---------- Bucket bar chart with metric toggle ---------- */
.fb-toggle {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 20px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.fb-toggle button {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.fb-toggle button[aria-pressed="true"] {
  background: var(--blue);
  color: #fff;
}

.fb-bars {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  align-items: end;
  height: 220px;
  border-bottom: 1px solid var(--glass-border);
}

.fb-bar {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}

.fb-fill {
  width: 100%;
  max-width: 72px;
  height: var(--h);
  border-radius: 8px 8px 0 0;
  background: rgba(138, 154, 181, 0.35);
  transform-origin: bottom center;
  transition: height 0.7s cubic-bezier(.2, .8, .2, 1), transform 0.9s cubic-bezier(.2, .8, .2, 1);
}

.fb-bar.is-best .fb-fill {
  background: linear-gradient(180deg, var(--green), var(--teal));
  box-shadow: 0 0 18px rgba(84, 228, 43, 0.3);
}

.fb-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.fb-bar.is-best .fb-val { color: var(--green); }

.fb-labels {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.fb-labels strong {
  display: block;
  font-size: 14px;
  color: var(--text);
}

/* metric switching: both values are in the HTML, CSS shows one */
.eh-chart[data-metric="b"] .fb-bar .fb-fill { height: var(--hb); }
.eh-chart .fb-val[data-m="b"] { display: none; }
.eh-chart[data-metric="b"] .fb-val[data-m="a"] { display: none; }
.eh-chart[data-metric="b"] .fb-val[data-m="b"] { display: inline; }

.eh-chart.eh-anim .fb-fill { transform: scaleY(0); }
.eh-chart.eh-anim.eh-in .fb-fill { transform: scaleY(1); }
.eh-chart.eh-anim.eh-in .fb-bar:nth-child(2) .fb-fill { transition-delay: 0.1s; }
.eh-chart.eh-anim.eh-in .fb-bar:nth-child(3) .fb-fill { transition-delay: 0.2s; }
.eh-chart.eh-anim.eh-in .fb-bar:nth-child(4) .fb-fill { transition-delay: 0.3s; }

.eh-chart-note {
  margin-top: 16px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
}

@media (max-width: 600px) {
  .eh-chart { padding: 22px 16px 18px; }
  .ss-row, .ss-axis { grid-template-columns: 92px 1fr; column-gap: 10px; }
  .ss-label { font-size: 13px; }
  .fb-bars { height: 180px; }
  .article-content .eh-chart ol.fb-bars,
  .article-content .eh-chart ol.fb-labels { gap: 8px; }
  .fb-labels { font-size: 12px; }
  .fb-val { font-size: 13px; }
}

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