/* widgets.css — artifact-specific interactive widget styles (potf paper).
   Colors are BRAIID tokens (the widgets are inlined into the document, so they
   inherit the token set), which keeps them on-palette in light mode and lets
   them invert with the rest of the document under .dark-theme. Structural colors
   (surfaces, borders, grays, the primary blue) use semantic tokens that flip;
   the math-semantic accents (lower-bound green, upper-bound red, selection gold)
   use the stable primitive ramps so they read the same in both themes. */

.spectral-workbench, .turan-workbench {
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  padding: 1rem 1.25rem 1rem;
  margin: 0.4rem 0;
  background: var(--surface-page);
  position: relative;
  font-family: var(--font-body);
}

.sw-controls {
  display: flex; flex-direction: column;
  font-size: 0.85rem; margin-bottom: 0.85rem;
  background: var(--surface-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 0.15rem 0.85rem;
}
.sw-controls-row {
  display: flex; align-items: center; gap: 0.55rem; flex-wrap: wrap;
  padding: 0.6rem 0;
}
/* Hairline divider between the two control rows for structure. */
.sw-row-config { border-top: 1px solid var(--border-primary); }

/* Left rail: a fixed-width label column so the two rows align cleanly. */
.sw-rowlabel {
  flex: 0 0 3.4rem;
  /* --dark (gray-700), not a lighter gray: keeps the uppercase label above the
     WCAG 1.4.3 AA floor against the control band. */
  color: var(--dark); font-size: 0.68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
}

.sw-presets { display: inline-flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.sw-preset {
  padding: 0.28rem 0.66rem; border: 1px solid var(--border-primary); border-radius: var(--radius-md);
  background: var(--surface-page); color: var(--primary-700); cursor: pointer; font-size: 0.82rem; font-weight: 600;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.sw-preset:hover { background: var(--surface-hover); border-color: var(--primary-300); }
.sw-preset:active { background: var(--gray-100); }

/* Segmented stepper: one unified control rather than three loose pills. */
.sw-r {
  display: inline-flex; align-items: stretch; color: var(--dark);
  border: 1px solid var(--border-primary); border-radius: var(--radius-md); overflow: hidden; background: var(--surface-page);
}
.sw-r b {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.5rem; padding: 0 0.2rem;
  font-weight: 600; color: var(--text-body);
  border-left: 1px solid var(--border-primary); border-right: 1px solid var(--border-primary);
  font-variant-numeric: tabular-nums;
}
.sw-r button {
  width: 1.7rem; padding: 0.26rem 0; border: 0; background: var(--surface-page);
  color: var(--dark); cursor: pointer; font-size: 1rem; line-height: 1;
  transition: background 0.12s ease, color 0.12s ease;
}
.sw-r button:hover { background: var(--surface-hover); color: var(--primary-700); }
.sw-r button:active { background: var(--gray-100); }

/* Clear sits by itself at the far right of the GRAPH row. */
.sw-clear { margin-left: auto; }

/* Interaction instructions in a band below the graph (inside the SVG). */
.sw-graph-hint { fill: var(--dark); font-size: 11px; pointer-events: none; }
.sw-graph-hint-verb { fill: var(--text-body); font-weight: 700; }

/* Graph (left) and spectrum (right) sit side by side; the graph no longer
   wastes horizontal room and the widget's vertical footprint shrinks. */
.sw-stage {
  display: flex; align-items: center; justify-content: center; gap: 1.5rem;
  margin: 0.2rem 0 0.3rem;
}
.sw-graph {
  display: block; flex: 0 1 230px; width: 230px; max-width: 48%;
  height: auto; align-self: center;
}
.sw-edge { stroke: var(--primary-700); stroke-width: 2; opacity: 0.55; pointer-events: none; }
.sw-edge-hit { stroke: transparent; stroke-width: 14; cursor: pointer; }
.sw-node { fill: var(--text-body); cursor: pointer; stroke: var(--surface-page); stroke-width: 2.5; }
.sw-node:hover { fill: var(--primary-700); }
.sw-node.sw-sel { fill: var(--yellow-700); stroke: var(--yellow-700); stroke-opacity: 0.35; stroke-width: 7; }

.sw-spectrum {
  display: block; flex: 0 0 46%; max-width: 250px;
  width: auto; height: auto; align-self: stretch;
}
.sw-axis { stroke: var(--medium); stroke-width: 1.3; }
.sw-tick { stroke: var(--light); stroke-width: 1; }
.sw-ticklbl { fill: var(--gray-600); font-size: 10px; text-anchor: end; dominant-baseline: middle; }
.sw-axislabel { fill: var(--dark); font-size: 11px; text-anchor: middle; font-style: italic; }
.sw-eig { fill: var(--dark); }
.sw-eig1 { fill: var(--primary-700); }
.sw-bound-hi { stroke: var(--error-600); stroke-width: 1.4; stroke-dasharray: 4 3; }
.sw-bound-lo { stroke: var(--success-600); stroke-width: 1.2; stroke-dasharray: 2 3; }
.sw-blabel-hi { font-size: 10.5px; text-anchor: start; dominant-baseline: middle; fill: var(--error-600); font-weight: 700; }
.sw-blabel-lo { font-size: 10.5px; text-anchor: start; dominant-baseline: middle; fill: var(--success-600); font-weight: 700; }
.sw-eiglabel { font-size: 11px; text-anchor: end; dominant-baseline: middle; fill: var(--primary-700); font-weight: 700; }

.sw-bhit { stroke: transparent; stroke-width: 12; cursor: help; }
.sw-bound-hi, .sw-bound-lo, .sw-blabel-hi, .sw-blabel-lo,
.sw-ticklbl, .sw-eiglabel, .sw-axis, .sw-tick, .sw-axislabel { pointer-events: none; }
.sw-eig, .sw-eig1 { cursor: help; }

.sw-legend {
  display: flex; flex-wrap: wrap; gap: 0.9rem;
  font-size: 0.76rem; color: var(--dark); margin: 0.1rem 0 0.2rem;
}
.sw-leg { display: inline-flex; align-items: center; gap: 0.35rem; }
.sw-sw-eig { width: 9px; height: 9px; border-radius: var(--radius-full); background: var(--dark); }
.sw-sw-eig1 { width: 9px; height: 9px; border-radius: var(--radius-full); background: var(--primary-700); }
.sw-sw-lo { width: 14px; border-top: 2px dashed var(--success-600); }
.sw-sw-hi { width: 14px; border-top: 2px dashed var(--error-600); }

.sw-tip {
  position: absolute; z-index: 10; pointer-events: none;
  /* Inverts with the theme: dark chip + light text in light mode, and the
     reverse in dark mode (both via flipping tokens), so it always reads. */
  background: var(--text-body); color: var(--surface-page); font-size: 0.76rem; line-height: 1.35;
  padding: 0.35rem 0.55rem; border-radius: var(--radius-md); max-width: 250px;
  box-shadow: var(--shadow-soft, 0 2px 10px rgba(20, 30, 50, 0.28));
}

.sw-caption {
  border-top: 1px solid var(--border-primary); padding-top: 0.6rem; margin-top: 0.3rem;
  font-size: 0.92rem; color: var(--text-body);
}
.sw-caption b { color: var(--text-body); font-variant-numeric: tabular-nums; }
.sw-ok { color: var(--success-700); font-weight: 600; }
.sw-bad { color: var(--error-700); font-weight: 600; }
.sw-mut { color: var(--text-subtle); }

/* --- Turán workbench (section 2) -------------------------------------- */
.tw-rowlabel {
  /* --dark for the same WCAG 1.4.3 AA reason as .sw-rowlabel. */
  color: var(--dark); font-size: 0.68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
}
.tw-rebalance { margin-left: auto; }

.tw-stage { display: flex; justify-content: center; margin: 0.3rem 0 0.1rem; }
.tw-graph { display: block; width: 320px; max-width: 100%; height: auto; }

/* Each part is a soft bag; clicking one moves the selected vertex into it.
   --pc is the per-part color, set inline by turan-workbench.js from BRAIID
   accent tokens. */
.tw-bag {
  fill: var(--pc); fill-opacity: 0.07;
  stroke: var(--pc); stroke-opacity: 0.35; stroke-width: 1.2;
  cursor: pointer; transition: fill-opacity 0.12s ease;
}
.tw-bag:hover { fill-opacity: 0.14; }
.tw-edge { stroke: var(--medium); stroke-width: 1.3; opacity: 0.22; pointer-events: none; }
.tw-node { fill: var(--pc); stroke: var(--surface-page); stroke-width: 2.5; cursor: pointer; }
.tw-node:hover { stroke: var(--pc); stroke-opacity: 0.4; stroke-width: 6; }
.tw-halo { fill: none; stroke: var(--yellow-700); stroke-width: 3; pointer-events: none; }
.tw-hint { fill: var(--dark); font-size: 11px; pointer-events: none; }
.tw-hint-verb { fill: var(--text-body); font-weight: 700; }

/* On phones the base font shrinks (12px) and the graph SVGs scale down, so the
   widget text reads too small. Bump the HTML chrome (rem) and the in-graph SVG
   text (px). The SVG text still scales with the graph, so there is a ceiling on
   how large it can get without enlarging the graph itself. */
@media (max-width: 640px) {
  /* Two rows, each on a single line that does not wrap: the Graph row (label +
     presets + Clear) and, below it, the Forbid row (label + stepper). */
  .sw-controls-row { flex-wrap: nowrap; gap: 0.3rem; }
  .sw-rowlabel { flex: 0 0 auto; font-size: 0.6rem; letter-spacing: 0.03em; }
  .sw-presets { gap: 0.22rem; flex-wrap: nowrap; }
  .sw-preset { padding: 0.2rem 0.4rem; font-size: 0.73rem; }
  .sw-r button { width: 1.45rem; }

  /* Legibility bumps for the content text (not the controls). */
  .sw-legend { font-size: 0.9rem; }
  .sw-caption { font-size: 1.02rem; }
  .sw-tip { font-size: 0.9rem; }

  .sw-graph-hint, .tw-hint { font-size: 13px; }
  .sw-ticklbl, .sw-blabel-hi, .sw-blabel-lo { font-size: 11px; }
  .sw-axislabel, .sw-eiglabel { font-size: 12px; }

  /* Stack the spectral graph above the spectrum so each gets full width; the
     SVGs stop scaling down to ~half, so the in-graph text reads at its native
     size instead of shrinking with the graph. */
  .sw-stage { flex-direction: column; gap: 0.75rem; }
  .sw-graph { width: 100%; max-width: 280px; flex: none; align-self: center; }
  .sw-spectrum { width: 100%; max-width: 320px; flex: none; align-self: center; }
}

/* Bounds workbench: the spectral climax (section 4). Built on D3; the plot
   shows the two bounds squeezing the edge count m, closing at the Turan bound
   m*. A range slider drives n and a segmented control drives omega. Every mark
   is coloured through a BRAIID token (Nikiforov ceiling red, Rayleigh floor
   green, lambda_1 / Turan graph primary) so the plot flips with .dark-theme. */
.bounds-workbench {
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  padding: 1rem 1.25rem 1rem;
  margin: 0.4rem 0;
  background: var(--surface-page);
  position: relative;
  font-family: var(--font-body);
}
.bw-stage { display: flex; justify-content: center; padding: 0.5rem 0 0.25rem; }
.bw-plot { width: 100%; max-width: 480px; height: auto; font-family: var(--font-body); }
.bw-plot text { pointer-events: none; }

/* Segmented control for the forbidden clique (replaces the +/- stepper). */
.bw-seg {
  display: inline-flex; align-items: stretch; overflow: hidden;
  border: 1px solid var(--border-primary); border-radius: var(--radius-md);
  background: var(--surface-page);
}
.bw-seg-btn {
  padding: 0.26rem 0.62rem; border: 0; border-left: 1px solid var(--border-primary);
  background: var(--surface-page); color: var(--dark);
  cursor: pointer; font-size: 0.82rem; font-weight: 600; line-height: 1.2;
  font-variant-numeric: tabular-nums;
  transition: background 0.12s ease, color 0.12s ease;
}
.bw-seg-btn:first-child { border-left: 0; }
.bw-seg-btn:hover { background: var(--surface-hover); color: var(--primary-700); }
.bw-seg-btn.is-active { background: var(--primary-700); color: var(--surface-page); }

/* Range slider for the vertex count, themed off BRAIID tokens. */
.bw-slider {
  -webkit-appearance: none; appearance: none;
  flex: 1 1 auto; min-width: 6rem; max-width: 14rem; height: 4px; margin: 0;
  background: var(--border-primary); border-radius: 999px; cursor: pointer;
}
.bw-slider:focus-visible { outline: 2px solid var(--primary-700); outline-offset: 4px; }
.bw-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary-700); border: 2px solid var(--surface-page);
  box-shadow: 0 0 0 1px var(--border-primary); cursor: pointer;
}
.bw-slider::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary-700); border: 2px solid var(--surface-page);
  box-shadow: 0 0 0 1px var(--border-primary); cursor: pointer;
}
.bw-slider::-moz-range-track { background: var(--border-primary); height: 4px; border-radius: 999px; }
.bw-nv {
  min-width: 1.6rem; text-align: center; font-weight: 700;
  color: var(--text-body); font-variant-numeric: tabular-nums;
}

/* D3 axes: thin domain line and ticks in the muted border/medium grays, with a
   faint gridline lattice behind the data. */
.bw-axis .domain { stroke: var(--medium); stroke-width: 1.3; }
.bw-axis .tick line { stroke: var(--medium); stroke-width: 1; }
.bw-axis .tick text { fill: var(--text-subtle); font-size: 10px; font-family: var(--font-body); }
.bw-grid line { stroke: var(--border-primary); stroke-width: 1; opacity: 0.5; }
.bw-axislabel { fill: var(--dark); font-size: 11px; font-style: italic; }

/* Data marks. */
.bw-band { fill: var(--primary-700); fill-opacity: 0.12; stroke: none; }
.bw-infeasible { fill: var(--error-600); fill-opacity: 0.10; stroke: none; }
.bw-nik { fill: none; stroke: var(--error-600); stroke-width: 2.4; }
.bw-ray { stroke: var(--success-600); stroke-width: 2.4; }
.bw-drop { stroke: var(--medium); stroke-width: 1.1; stroke-dasharray: 3 3; }
.bw-mstar-tick { stroke: var(--dark); stroke-width: 1.3; }
.bw-turan { fill: var(--primary-700); stroke: var(--surface-page); stroke-width: 1.5; }
.bw-tlabel { fill: var(--primary-700); font-size: 12px; font-weight: 700; }
.bw-mstar { fill: var(--dark); font-size: 11px; font-weight: 600; }

/* Legend (a key) below the plot. */
.bw-legend {
  display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; justify-content: center;
  padding: 0.35rem 0.5rem 0.1rem; font-size: 0.8rem;
}
.bw-key { display: inline-flex; align-items: center; gap: 0.4rem; }
.bw-key-label { color: var(--text-body); }
.bw-swatch { flex: 0 0 auto; width: 16px; height: 12px; border-radius: 2px; }
.bw-swatch.bw-key-nik {
  height: 0; width: 18px; border-top: 2.4px solid var(--error-600); border-radius: 0;
}
.bw-swatch.bw-key-ray {
  height: 0; width: 18px; border-top: 2.4px solid var(--success-600); border-radius: 0;
}
.bw-swatch.bw-key-band { background: var(--primary-700); opacity: 0.18; }
.bw-swatch.bw-key-turan {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--primary-700); border: 1.5px solid var(--surface-page);
  box-shadow: 0 0 0 1px var(--border-primary);
}
.bw-swatch.bw-key-infeasible { background: var(--error-600); opacity: 0.18; }
