/* Interactive figures in posts (see WIDGETS.md): the components every widget
   is built from.  A widget's own stylesheet (widgets/NAME.css) only arranges
   these and styles what is truly its own (the ribbons of a sankey); anything
   two widgets need goes here.

   Colours: the palette below, by name.  A component that takes a colour reads
   it from --tone (ctx.ui.tone("red") → "--tone: var(--chart-red)"). */

:root {
  --chart-blue: var(--primary-color);
  --chart-red: var(--secondary-color);
  --chart-navy: var(--header-color);
  --chart-orange: light-dark(#c4700c, #ee9a3a);
  --chart-purple: light-dark(#7d4cc4, #c07bff);
  --chart-yellow: light-dark(#b08a00, #f5c542);
  --chart-green: light-dark(#2f8a4c, #6fcf8f);
  --chart-grey: light-dark(#93a1ad, #6f87a0);
  --chart-grid: var(--border-color);
  --chart-text: var(--text-color);
  --chart-faded: var(--faded-color);

  --widget-font-mono: 'Ubuntu Mono', 'Consolas', monospace;
}

/* ---- the figure ----------------------------------------------------------- */

/* in the text column like an image, title and caption centred: no box, no
   background of its own */
figure.widget {
  margin: 34px 0;
  padding: 0;
  font-size: 15px;
  line-height: 1.5;
  text-align: center;
}
figure.widget * { box-sizing: border-box; }

/* the body keeps its room while the module loads, so the page doesn't jump */
.widget-body { min-height: var(--widget-height, 0); text-align: initial; }

/* the title above, in small caps; .widget-label is the same for fields */
.widget-title,
.widget-label {
  display: block;
  margin: 0 0 12px;
  color: var(--faded-color);
  font: 700 12px/1.35 var(--widget-font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.widget-label { margin: 0 0 5px; font-size: 11px; }

figure.widget figcaption {
  margin: 12px 0 0;
  color: var(--faded-color);
  font-size: 14px;
  line-height: 21px;
}
figure.widget figcaption p { margin: 0; }
figure.widget figcaption p + p { margin-top: 6px; }

.widget-fallback {
  margin: 0;
  padding: 18px;
  color: var(--faded-color);
  font-style: italic;
  text-align: center;
}
.widget-feed { font-style: italic; }

/* ---- text --------------------------------------------------------------- */

.widget-muted { color: var(--faded-color); font-size: 14px; }
.widget-mono { font-family: var(--widget-font-mono); }
.widget-num { font-variant-numeric: tabular-nums; }
/* a paragraph beside controls (ui.note) */
.widget-note { margin: 0; color: var(--faded-color); font-size: 14px; }
/* what is shown now (ui.status) */
.widget-status { margin: 8px 0; font-size: 14px; }

/* ---- layout ------------------------------------------------------------- */

.widget-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin: 8px 0;
}
.widget-row > .widget-grow,
.widget-row > .widget-muted { flex: 1 1 12em; min-width: 0; }
.widget-grow { flex: 1; min-width: 0; }

/* a field and a note beside it (ui.controls) */
.widget-controls {
  display: grid;
  grid-template-columns: minmax(200px, 290px) 1fr;
  gap: 18px;
  align-items: end;
  margin: 0 0 12px;
}
.widget-controls .widget-select { width: 100%; }

/* main content with a narrow column beside it (ui.split) */
.widget-split { display: flex; gap: 10px; align-items: stretch; }
.widget-side { width: 128px; flex: none; align-self: flex-end; }

/* an item: a head line, its content below (ui.entry) */
.widget-entry { margin: 0 0 12px; }
.widget-entry:last-child { margin-bottom: 0; }
.widget-entry-head { margin: 0 0 5px; gap: 4px 10px; }
.widget-entry-name { flex: none; }

/* a box inside a widget: a chart's plot, a number */
.widget-panel {
  border: 1px solid var(--border-color);
  border-radius: 3px;
}

/* a chart with a minimum width scrolls; on phones to the edges of the screen */
.widget-scroll { overflow-x: auto; overscroll-behavior-x: contain; }

@media only screen and (max-width: 800px) {
  figure.widget .widget-scroll { margin: 0 -12px; padding: 0 12px; }
}
@media only screen and (max-width: 600px) {
  .widget-controls { grid-template-columns: 1fr; gap: 8px; }
  .widget-side { width: 84px; }
}

/* ---- controls ------------------------------------------------------------ */

.widget-field { min-width: 0; }

.widget-button,
.widget-select {
  font: inherit;
  font-size: 14px;
  line-height: 20px;
  padding: 3px 10px;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  background: var(--background-color);
  color: var(--text-color);
}
.widget-button { cursor: pointer; }
.widget-button:hover:not(:disabled) { border-color: var(--primary-color); }
.widget-button:disabled { opacity: 0.35; cursor: default; }
.widget-button.is-on {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: var(--background-color);
}
.widget-select { max-width: 100%; padding-right: 26px; }

/* play/pause (ui.play) */
.widget-play {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 28px;
  padding: 0;
}
.widget-play svg { display: block; width: 12px; height: 12px; }

/* buttons of which one is on, with a label in front (ui.toggles) */
.widget-toggles > .widget-label { min-width: 92px; margin: 0; }
@media only screen and (max-width: 600px) {
  .widget-toggles > .widget-label { min-width: 0; flex-basis: 100%; }
}

/* a slider between two named ends (ui.range) */
.widget-slider { flex: 1; min-width: 120px; accent-color: var(--primary-color); }
.widget-range-end { font-weight: 600; min-width: 52px; }
.widget-range-end:last-child { text-align: right; }

/* ---- small charts in HTML ------------------------------------------------ */

/* numbers: label above, value below (ui.stats) */
.widget-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin: 0 0 12px;
}
.widget-stat {
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--border-color);
  border-radius: 3px;
}
.widget-stat .widget-label { margin-bottom: 3px; }
.widget-stat-value {
  display: block;
  color: var(--header-color);
  font: 500 clamp(22px, 3.4vw, 30px)/1.1 'Lora', serif;
}
.widget-stat-value.is-accent { color: var(--secondary-color); }
@media only screen and (max-width: 600px) {
  .widget-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* bars: label, track, value (ui.bars) */
.widget-bars { margin: 8px 0; }
.widget-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 3px 0;
  font-size: 14px;
}
.widget-bar-label { width: 170px; flex: none; color: var(--faded-color); }
.widget-bar-track {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: var(--code-background-color);
  overflow: hidden;
}
.widget-bar-fill {
  display: block;
  height: 100%;
  background: var(--tone, var(--chart-blue));
  transition: width 0.25s;
}
.widget-bar-value { width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
@media only screen and (max-width: 600px) {
  .widget-bar-label { width: 120px; }
}

/* swatches and labels (ui.legend) */
.widget-legend { gap: 6px 16px; margin: 0 0 10px; font-size: 14px; }
.widget-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.widget-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--tone, var(--chart-grey));
}

/* a row of tokens, as code (ui.tokens) */
.widget-tokens {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 12px 0 4px;
  font: 12px/1.4 var(--widget-font-mono);
}
.widget-token { padding: 2px 7px; border-radius: 3px; background: var(--code-background-color); }
.widget-token.is-toned { background: color-mix(in srgb, var(--tone) 22%, transparent); }
.widget-token.is-strong { font-weight: 700; }
.widget-token.is-off { opacity: 0.6; text-decoration: line-through; }

/* ---- charts in SVG and canvas -------------------------------------------- */

.widget-svg { display: block; overflow: visible; }
.widget-svg text {
  fill: var(--chart-faded);
  font: 12px var(--widget-font-mono);
}
.widget-svg text.is-strong { fill: var(--chart-text); }
.widget-svg text.is-toned { fill: var(--tone); }
/* a label over lines and areas: a halo in the page colour */
.widget-svg text.halo {
  paint-order: stroke;
  stroke: var(--background-color);
  stroke-width: 4px;
  stroke-linejoin: round;
}
.widget-svg .grid { stroke: var(--chart-grid); stroke-width: 1; opacity: 0.45; }
.widget-svg .axis { stroke: var(--chart-grid); stroke-width: 1.2; }
/* an axis break: two slashes */
.widget-svg .break { stroke: var(--chart-faded); stroke-width: 1.5; fill: none; }
/* a data line and its points */
.widget-svg .series {
  fill: none;
  stroke: var(--tone, var(--chart-blue));
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.widget-svg .point { fill: var(--tone, var(--chart-blue)); stroke: var(--background-color); stroke-width: 2; }
/* a reference line: a mean, a threshold */
.widget-svg .ref { stroke: var(--tone, var(--chart-faded)); stroke-width: 1.5; stroke-dasharray: 6 5; }
.widget-svg .is-dotted { stroke-dasharray: 3 5; }
.widget-svg .is-dashed { stroke-dasharray: 4 5; }
.widget-svg .is-faint { opacity: 0.6; }

.widget-canvas { display: block; width: 100%; border-radius: 3px; }
