/*
  CGL visualiser styles (originally a standalone widget; now maintained as part of this site). The custom properties on .cgl are the design hooks:
  override them from the site's stylesheet. Curve and spot colours are read by the
  canvas when it mounts; call refreshTheme() if they change afterwards.
*/
.cgl {
  --cgl-curve-1: #35e0d0;
  --cgl-curve-2: #8a6bff;
  --cgl-curve-3: #ff5fa2;
  --cgl-spot: #ffe9b8;

  --cgl-stage-bg: radial-gradient(circle at 50% 45%, #161631 0%, #0b0b1a 55%, #060610 100%);
  --cgl-panel-bg: #101022;
  --cgl-text: #ecebf7;
  --cgl-text-muted: #9c9ab8;
  --cgl-track: #2a2a48;
  --cgl-accent: #35e0d0;
  --cgl-accent-2: #8a6bff;
  --cgl-radius: 16px;
  --cgl-gap: 12px;
  --cgl-sticky-top: 0px; /* clear any fixed site header on phones */

  container-type: inline-size;
  color: var(--cgl-text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.3;
}

.cgl *,
.cgl *::before,
.cgl *::after {
  box-sizing: border-box;
}

.cgl__layout {
  display: flex;
  flex-direction: column;
  gap: var(--cgl-gap);
}

/* On narrow layouts the stage sticks, so the curve stays in view while the sliders scroll under it */
.cgl__stage {
  position: sticky;
  top: var(--cgl-sticky-top);
  z-index: 1;
  width: 100%;
  height: var(--cgl-stage-h, min(100cqw, 46svh));
  min-height: var(--cgl-stage-min, 240px);
  overflow: hidden;
  border-radius: var(--cgl-radius) var(--cgl-radius) 0 0;
  background: var(--cgl-stage-bg);
}

/* Stacked, reset rides along under the sticky curve as one unit, so it's always to hand */
.cgl__layout > .cgl__reset {
  order: 1;
  position: sticky;
  top: calc(var(--cgl-sticky-top) + max(var(--cgl-stage-min, 240px), var(--cgl-stage-h, min(100cqw, 46svh))));
  z-index: 1;
  margin-top: calc(-1 * var(--cgl-gap));
  border-radius: 0 0 var(--cgl-radius) var(--cgl-radius);
}
.cgl__layout > .cgl__panel {
  order: 2;
}

.cgl__canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.cgl__panel {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 14px 16px;
  border-radius: var(--cgl-radius);
  background: var(--cgl-panel-bg);
}

/* Stacked: --cgl-crop > 1 lets the curve grow past a short, wide stage's height (it's cropped top and bottom) */
@container (max-width: 719px) {
  .cgl__stage { --cgl-crop: var(--cgl-stacked-crop, 1); }
}

/* Two columns: reset sits under the curve, and the controls tighten to fit one laptop screen */
@container (min-width: 720px) {
  .cgl__layout {
    display: grid;
    grid-template-columns: var(--cgl-stage-w, 23em) minmax(280px, 1fr);   /* stage roughly square beside the panel */
    grid-template-rows: 1fr auto;
    grid-template-areas:
      "stage panel"
      "reset panel";
  }
  .cgl__stage {
    grid-area: stage;
    position: relative;
    top: 0;
    height: auto;
    min-height: 0;
    border-radius: var(--cgl-radius);
  }
  .cgl__panel {
    grid-area: panel;
    gap: 10px;
    padding: 14px 16px;
  }
  .cgl__layout > .cgl__reset {
    grid-area: reset;
    position: relative;
    top: 0;
    margin-top: 0;
    border-radius: 12px;
  }
  .cgl__group {
    gap: 4px;
  }
  .cgl__slider {
    height: 22px;
  }
  .cgl__option span {
    padding: 5px 0;
  }
}

.cgl__group {
  display: grid;
  gap: 4px;
}

.cgl__group-title {
  margin: 0;
  text-align: center;
  color: var(--cgl-text-muted);
  font-size: 0.75em;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* One row per control: name | slider | value */
.cgl__control {
  display: grid;
  grid-template-columns: var(--cgl-label-w, 6.6em) minmax(0, 1fr) var(--cgl-value-w, 3.4em);
  gap: 0 10px;
  align-items: center;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
  transition: opacity 0.2s ease;
}

.cgl__control--off {
  opacity: 0.35;
}

.cgl__label {
  padding: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cgl__symbol {
  font-weight: 600;
}

.cgl__name {
  color: var(--cgl-text-muted);
  font-size: 0.87em;
}

.cgl__value {
  grid-column: 3;
  text-align: right;
  white-space: nowrap;
  color: var(--cgl-text-muted);
  font-size: 0.87em;
  font-variant-numeric: tabular-nums;
}

/* Sliders. --cgl-fill-from and --cgl-fill-to are set per slider from JS. */
.cgl__slider {
  grid-column: 2;
  grid-row: 1;
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  touch-action: pan-y;
}

.cgl__slider:disabled {
  cursor: default;
}

.cgl__slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(
    to right,
    var(--cgl-track) var(--cgl-fill-from, 0%),
    var(--cgl-accent) var(--cgl-fill-from, 0%),
    var(--cgl-accent-2) var(--cgl-fill-to, 0%),
    var(--cgl-track) var(--cgl-fill-to, 0%)
  );
}

.cgl__slider::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(
    to right,
    var(--cgl-track) var(--cgl-fill-from, 0%),
    var(--cgl-accent) var(--cgl-fill-from, 0%),
    var(--cgl-accent-2) var(--cgl-fill-to, 0%),
    var(--cgl-track) var(--cgl-fill-to, 0%)
  );
}

.cgl__slider::-webkit-slider-thumb {
  width: 20px;
  height: 20px;
  margin-top: -7px;
  border: 0;
  border-radius: 50%;
  background: var(--cgl-text);
  box-shadow: 0 0 10px color-mix(in srgb, var(--cgl-accent) 60%, transparent);
  -webkit-appearance: none;
  appearance: none;
}

.cgl__slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: var(--cgl-text);
  box-shadow: 0 0 10px color-mix(in srgb, var(--cgl-accent) 60%, transparent);
}

/* Whole-number ωr picker: its buttons take the slider and value columns */
.cgl__control--whole .cgl__options {
  grid-column: 2 / -1;
}

.cgl__options {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
}

.cgl__option {
  position: relative;
  cursor: pointer;
}

.cgl__option input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: inherit;
}

.cgl__option span {
  display: block;
  padding: 5px 0;
  border-radius: 10px;
  background: var(--cgl-track);
  text-align: center;
  font-variant-numeric: tabular-nums;
  transition: background 0.15s ease, color 0.15s ease;
}

.cgl__option input:checked + span {
  background: var(--cgl-accent);
  color: #06121a;
  font-weight: 600;
}

.cgl__control--off .cgl__option {
  cursor: default;
}

.cgl__reset {
  width: 100%;
  padding: 13px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(90deg, var(--cgl-accent), var(--cgl-accent-2));
  color: #06121a;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.cgl__reset:hover {
  filter: brightness(1.1);
}

.cgl__reset:active {
  transform: scale(0.985);
}

.cgl__slider:focus-visible,
.cgl__reset:focus-visible,
.cgl__option input:focus-visible + span {
  outline: 2px solid var(--cgl-text);
  outline-offset: 2px;
}
