/* ==========================================================================
   Two-axis picker (notes/input-controls-for-refinement.html, Prototype 3)

   A color picker cut down to a 3, 5 or 8 step grid of one color, or a
   gradient of it, used as a metaphor for setting two qualities by degree. Each example has its own
   color, set by js/tone-picker.js. Cards, buttons, tabs and badges come from
   proto-ui.css.
   ========================================================================== */

.tone-picker .tp-picker {
  display: grid;
  grid-template-columns: auto minmax(0, 280px);
  column-gap: 10px;
  row-gap: 6px;
  justify-content: center;
  font-size: 11px;
  color: var(--bd-muted-foreground);
}

/* Labels for the ends of each axis */
.tone-picker .tp-ylabels {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: right;
}

.tone-picker .tp-xlabels {
  grid-column: 2;
  display: flex;
  justify-content: space-between;
}

/* The grid: flat blocks with a hairline between them. js/tone-picker.js
   sets --n (blocks a side) and --gap. */
.tone-picker .tp-grid {
  --n: 3;
  --gap: 4px;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  gap: var(--gap);
  aspect-ratio: 1;
  cursor: pointer;
  touch-action: none;
  outline: none;
}

.tone-picker .tp-cell {
  border-radius: 3px;
  transition: background-color 200ms ease-out;
}

.tone-picker .tp-grid:focus-visible {
  border-radius: 4px;
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--bd-ring) 50%, transparent);
}

/* The handle is the picked block; the dashed one is where it started. Both
   are one block in size and move by whole blocks. */
.tone-picker .tp-handle,
.tone-picker .tp-ghost {
  position: absolute;
  top: 0;
  left: 0;
  width: calc((100% - (var(--n) - 1) * var(--gap)) / var(--n));
  height: calc((100% - (var(--n) - 1) * var(--gap)) / var(--n));
  border-radius: 4px;
  pointer-events: none;
}

.tone-picker .tp-handle {
  border: 2px solid #fff;
  box-shadow: 0 0 0 1.5px var(--bd-foreground), 0 2px 6px rgb(0 0 0 / 0.25);
  transition: transform 120ms ease-out;
}

.tone-picker .tp-ghost {
  border: 1.5px dashed var(--bd-foreground);
  opacity: 0.6;
}

/* Gradient: one smooth field, with a round handle that moves freely and a
   dashed ring where it started. */
.tone-picker .tp-grid.is-gradient {
  display: block;
}

.tone-picker .tp-ramp {
  --rows: 96;
  position: absolute;
  inset: 0;
  border-radius: 4px;
  overflow: hidden;
}

/* Each row reaches 1px into the next, so no seam shows between them where
   a row falls on a fraction of a pixel. js/tone-picker.js sets --i. */
.tone-picker .tp-ramp > div {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--i) / var(--rows) * 100%);
  height: calc(100% / var(--rows) + 1px);
}

.tone-picker .tp-grid.is-gradient .tp-handle,
.tone-picker .tp-grid.is-gradient .tp-ghost {
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  transition: none;
}

/* The header holds two toggles and Reset, so it wraps on a phone. */
.tone-picker .bd-card-header {
  flex-wrap: wrap;
  row-gap: 10px;
}

.tone-picker .bd-actions {
  margin-left: auto;
}

@media (prefers-reduced-motion: reduce) {
  .tone-picker .tp-handle,
  .tone-picker .tp-cell {
    transition: none;
  }
}
