/* Widget-layer styling (DESIGN.md §6). Deliberately token-driven so the page
   stages can restyle without touching component internals. */

:root {
  --bg: #14161a;
  --panel: #1e2127;
  --panel-2: #262a32;
  --text: #e7e9ee;
  --muted: #9aa2b1;
  --line: #363b45;
  --accent: #6ea8fe;
  --warn: #ffcc55;
  --ok: #7ddb8f;
  --radius: 8px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f8fa;
    --panel: #ffffff;
    --panel-2: #eef1f6;
    --text: #171a1f;
    --muted: #5b6472;
    --line: #d5dae2;
    color-scheme: light;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* --- PanZoom ------------------------------------------------------------ */

.panzoom {
  width: 100%;
  height: 100%;
  cursor: grab;
  background: var(--panel);
  border-radius: var(--radius);
}
.panzoom.is-panning {
  cursor: grabbing;
}
.panzoom-controls {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: flex;
  gap: 4px;
}
.panzoom-controls button {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
}

/* --- TileView ----------------------------------------------------------- */

.tile-view {
  display: block;
  overflow: visible;
  touch-action: none;
}
.tile-view.is-dimmed {
  opacity: 0.35;
}

.tile-view .edge-visual {
  opacity: 0;
  transition: opacity 120ms ease, stroke-width 120ms ease;
}
.tile-view .meta-edge.is-hovered .edge-visual,
.tile-view .meta-edge.is-highlighted .edge-visual {
  opacity: 1;
}
/* Plain :focus, not just :focus-visible: Chromium paints its default
   `outline: auto` focus ring on SVG elements scaled by the viewBox transform,
   so a pointer-down on a seam grew a giant two-tone disc over the tile.
   Keyboard users keep the dashed seam cue below. */
.tile-view .meta-edge:focus {
  outline: none;
}
.tile-view .meta-edge:focus-visible .edge-visual {
  opacity: 1;
  stroke-dasharray: 0.2 0.12;
}
.tile-view .edge-dot {
  transition: r 120ms ease;
}
.tile-view .meta-edge.is-hovered .edge-dot {
  /* px here means SVG user units (pre-transform), and CSS requires the unit —
     a bare number is an invalid length and the grow-on-hover never fired. */
  r: 0.21px;
}
.tile-view .landing-spot {
  animation: spectre-pulse 1.1s ease-in-out infinite;
}
.tile-view .landing-spot.is-snapped {
  animation: none;
  stroke-width: 0.08;
}
.tile-view .tile-shape.is-odd {
  animation: spectre-odd 1.6s ease-in-out infinite;
}

@keyframes spectre-pulse {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}
@keyframes spectre-odd {
  0%,
  100% {
    stroke: rgba(0, 0, 0, 0.55);
  }
  50% {
    stroke: #ff3b30;
  }
}

/* --- TilePalette -------------------------------------------------------- */

.tile-palette {
  display: grid;
  gap: 10px;
}
.tile-palette-cell {
  margin: 0;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tile-palette-label {
  font-size: 12px;
  color: var(--muted);
}

/* --- Tiling renderers --------------------------------------------------- */

.tiling-view,
.tiling-canvas {
  display: block;
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
}
/* The bitmap lives OUT of flow: an in-flow (inline) canvas adds a baseline
   gap that re-triggers the host's ResizeObserver — a slow, unbounded
   grow-remeasure-redraw loop at the heavy levels. */
.tiling-canvas canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.tiling-view .tile-instance.is-odd {
  filter: drop-shadow(0 0 0.12px #ff3b30);
}

/* --- Seam view ---------------------------------------------------------- */

.seam-view {
  display: block;
  background: var(--panel);
  border-radius: var(--radius);
}
.seam-view.is-empty {
  padding: 12px;
  color: var(--muted);
}

/* --- Controls ----------------------------------------------------------- */

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin: 0 0 10px;
}
legend {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 6px 0;
}
/* A checkbox row reads as one phrase — box then label — so it stays left.
   Only label/control rows want the two ends pushed apart. */
.control-row:has(> input[type='checkbox']:first-child) {
  justify-content: flex-start;
}
.control-row > span {
  color: var(--muted);
}
/* Keep a label and its ⓘ on one line rather than letting the icon wrap. */
.control-row > span:has(.info-tip) {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}
select,
input[type='number'],
input[type='text'] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  max-width: 100%;
}
button {
  font: inherit;
}

.edge-legend-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.edge-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
}
.edge-chip.is-on {
  color: var(--text);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, var(--panel-2));
}
.edge-chip.is-highlighted {
  outline: 2px solid var(--accent);
}
.edge-chip-swatch {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.5);
}

.warning-badge {
  color: var(--warn);
  font-size: 12px;
  margin: 6px 0 0;
}
.ok-badge {
  color: var(--ok);
  font-size: 12px;
  margin: 6px 0 0;
}

.matching-slider {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.matching-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
}
.matching-controls input[type='range'] {
  flex: 1;
  min-width: 40px;
}
.matching-controls button {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  line-height: 1;
}
.matching-badge,
.matching-filter,
.matching-odd-note {
  font-size: 11px;
  color: var(--muted);
}
.matching-odd-note {
  text-align: center;
  margin: 0;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.color-wells {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 4px;
}
.color-well {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
}

.stats-figures {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 6px;
  margin: 0 0 8px;
}
.stats-figures div {
  background: var(--panel-2);
  border-radius: 6px;
  padding: 5px 7px;
}
.stats-figures dt {
  font-size: 11px;
  color: var(--muted);
}
.stats-figures dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.stats-summary h4 {
  margin: 8px 0 4px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.length-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.length-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}
.length-chip.is-active {
  outline: 2px solid var(--accent);
}
.length-chip-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.share-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.share-panel button {
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}
.share-url,
.share-combo {
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
}
.muted {
  color: var(--muted);
}
.error {
  color: #ff6b6b;
}

/* Seam-contract slider: track spans the whole seam, notches mark the vertices
   between physical edges. Inactive classes grey out; class 0 is pinned. */
.contract-slider {
  --csl-thumb-r: 8px;
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 1 1 140px;
  min-width: 120px;
}
.contract-slider input[type='range'] {
  width: 100%;
  position: relative;
  z-index: 1;
  background: transparent;
}
.contract-slider-track {
  position: absolute;
  left: var(--csl-thumb-r);
  right: var(--csl-thumb-r);
  top: 50%;
  height: 14px;
  transform: translateY(-50%);
  pointer-events: none;
}
.contract-notch {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  transform: translateX(-1px);
  border-radius: 1px;
  background: currentColor;
  opacity: 0.55;
}
.contract-slider.is-inactive {
  opacity: 0.35;
  filter: grayscale(1);
}
.contract-slider.is-pinned input {
  cursor: not-allowed;
}
.contract-slider.is-pinned .contract-notch {
  opacity: 0.35;
}

/* --- InfoTip ------------------------------------------------------------ */
/* The ⓘ that holds what used to be a paragraph of sidebar prose. */

.info-tip {
  display: inline-block;
  flex: 0 0 auto;
  margin-left: 4px;
  vertical-align: middle;
}
/* The popover spans the ROW, not the icon: the sidebar is narrow enough that
   anything anchored to a 16px button ends up hanging off one edge of it. */
.control-row:has(.info-tip) {
  position: relative;
}
.info-tip > summary {
  list-style: none;
  cursor: help;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--panel-2);
  font-size: 11px;
  font-style: italic;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  user-select: none;
}
.info-tip > summary::-webkit-details-marker {
  display: none;
}
.info-tip > summary:hover,
.info-tip[open] > summary {
  color: var(--text);
  border-color: var(--accent);
}
.info-tip > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
/* Floated over the panel so opening one does not shove the controls down. */
.info-tip-body {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.info-tip-body p {
  margin: 0 0 6px;
}
.info-tip-body p:last-child {
  margin-bottom: 0;
}
