/* The Studio's primitives (T0, src/studio/ui/*): Button, IconButton,
   SegmentedControl, Switch, Knob, Slider, Kbd, Tag and Tooltip. Every area
   builds its controls from these, so they look and behave the same
   everywhere. Sizes are the design's. */

.st-icon { width: 16px; height: 16px; flex: none; }

/* ---- Button --------------------------------------------------------------- */

.st-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  outline: 1px solid transparent;
  outline-offset: -0.5px;
  background: none;
  color: var(--st-text);
  font: 500 13px/1 var(--st-font);
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, outline-color 0.15s, box-shadow 0.15s;
}
.st-btn .st-icon { width: 14px; height: 14px; }
.st-btn--sm { height: 28px; padding: 0 10px; border-radius: 7px; font-size: 12px; }
.st-btn--lg { height: 40px; padding: 0 18px; border-radius: 10px; gap: 8px; font-size: 15px; font-weight: 600; }

.st-btn--primary {
  outline-color: var(--st-accent-edge);
  /* White text is 4.70:1 on the top stop and 6.2:1 on the foot (T10 found
     3.34:1 on the former #ff4468). */
  background: linear-gradient(180deg, var(--st-accent-strong) 0%, var(--st-accent-deep) 100%);
  color: var(--st-on-accent);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--st-accent) 25%, transparent);
}
.st-btn--primary:hover { box-shadow: 0 8px 24px color-mix(in srgb, var(--st-accent) 40%, transparent); }

.st-btn--secondary { outline-color: var(--st-line); background: var(--st-surface-2); }
.st-btn--secondary:hover { outline-color: var(--st-line-strong); }

.st-btn--ghost { color: var(--st-text-dim); }
.st-btn--ghost:hover { background: var(--st-surface-2); color: var(--st-text); }

.st-btn--light { background: var(--st-text); color: var(--st-bg); font-weight: 600; }
.st-btn--light:hover { background: var(--st-text-strong); }

.st-btn:disabled { opacity: 0.45; cursor: default; box-shadow: none; }

/* ---- IconButton ------------------------------------------------------------ */

.st-icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--st-text-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.st-icon-btn--sm { width: 28px; height: 28px; border-radius: 7px; }
.st-icon-btn--lg { width: 40px; height: 40px; border-radius: 10px; }
.st-icon-btn--sm .st-icon { width: 14px; height: 14px; }
.st-icon-btn--lg .st-icon { width: 18px; height: 18px; }
.st-icon-btn--outlined { outline: 1px solid var(--st-line); outline-offset: -0.5px; background: var(--st-surface); }
.st-icon-btn:hover { background: var(--st-surface-2); color: var(--st-text); }
.st-icon-btn[aria-pressed='true'] { background: var(--st-accent-soft); color: var(--st-accent); }
.st-icon-btn:disabled { opacity: 0.45; cursor: default; }

/* ---- SegmentedControl ------------------------------------------------------ */

.st-seg {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  outline: 1px solid var(--st-line);
  outline-offset: -0.5px;
  background: var(--st-panel);
}
.st-seg__item {
  padding: 4px 9px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--st-text-faint);
  font: 500 11.5px/normal var(--st-font);
  white-space: nowrap;
  cursor: pointer;
}
.st-seg--md .st-seg__item { padding: 5px 12px; font-size: 12.5px; }
.st-seg__item:hover { color: var(--st-text); }
.st-seg__item[aria-checked='true'] {
  outline: 1px solid var(--st-line-strong);
  outline-offset: -0.5px;
  background: var(--st-surface-2);
  color: var(--st-text);
}

/* ---- Switch ------------------------------------------------------------------ */

.st-switch {
  display: inline-flex;
  align-items: center;
  flex: none;
  width: 30px;
  height: 18px;
  padding: 2px;
  border: 0;
  border-radius: 9px;
  background: var(--st-switch-off);
  cursor: pointer;
  transition: background 0.15s;
}
.st-switch__thumb {
  width: 14px;
  height: 14px;
  border-radius: 7px;
  background: var(--st-on-accent);
  transition: transform 0.15s var(--ease);
}
.st-switch[aria-checked='true'] { background: var(--st-accent); }
.st-switch[aria-checked='true'] .st-switch__thumb { transform: translateX(12px); }
.st-switch:disabled { opacity: 0.45; cursor: default; }

/* ---- Knob -------------------------------------------------------------------- */

.st-knob {
  --knob-color: var(--st-text);
  --knob-angle: 0deg;
  position: relative;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: ns-resize;
  touch-action: none;
}
.st-knob__dial {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  outline: 1px solid var(--st-line-strong);
  outline-offset: -0.5px;
  background: radial-gradient(ellipse 65% 65% at 35% 30%, var(--st-knob-hi) 0%, var(--st-knob-lo) 100%);
  box-shadow: 0 2px 6px color-mix(in srgb, var(--st-shadow) 60%, transparent);
  transform: rotate(var(--knob-angle));
}
.st-knob__pointer {
  position: absolute;
  top: 5px;
  left: calc(50% - 1.25px);
  width: 2.5px;
  height: 11px;
  border-radius: 2px;
  background: var(--knob-color);
}

/* ---- Slider -------------------------------------------------------------------- */

.st-slider {
  --slider-color: var(--st-text);
  --slider-ratio: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.st-slider__track {
  position: relative;
  flex: 1;
  min-width: 40px;
  height: 16px;
  cursor: pointer;
  touch-action: none;
}
.st-slider__track::before {
  content: '';
  position: absolute;
  top: 6px;
  right: 0;
  left: 0;
  height: 4px;
  border-radius: 2px;
  background: var(--st-line-strong);
}
.st-slider__fill {
  position: absolute;
  top: 6px;
  left: 0;
  width: calc(var(--slider-ratio) * 100%);
  height: 4px;
  border-radius: 2px;
  background: var(--slider-color);
}
.st-slider__thumb {
  position: absolute;
  top: 2px;
  left: calc(var(--slider-ratio) * 100% - 6px);
  width: 12px;
  height: 12px;
  border-radius: 6px;
  outline: 2px solid var(--st-panel);
  outline-offset: -1px;
  background: var(--slider-color);
}
.st-slider__track:focus-visible { border-radius: 4px; }
.st-slider__readout,
.st-slider__input {
  flex: none;
  width: 34px;
  color: var(--st-text-dim);
  font: 400 10.5px/normal var(--st-font-mono);
  text-align: right;
}
.st-slider__readout { padding: 0; border: 0; border-radius: 4px; background: none; cursor: text; }
.st-slider__readout:hover { color: var(--st-text); }
.st-slider__input {
  height: 18px;
  padding: 0 3px;
  border: 1px solid var(--st-line-control);
  border-radius: 4px;
  background: var(--st-surface-2);
  color: var(--st-text);
}

/* ---- Kbd ------------------------------------------------------------------------ */

.st-kbd {
  display: inline-block;
  padding: 3px 6px;
  border-radius: 5px;
  outline: 1px solid var(--st-line-strong);
  outline-offset: -0.5px;
  color: var(--st-text-faint);
  font: 400 10px/normal var(--st-font-mono);
  white-space: nowrap;
}

/* ---- Tag ------------------------------------------------------------------------ */

.st-tag {
  --tag-color: var(--st-text-faint);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 5px;
  outline: 1px solid color-mix(in srgb, var(--tag-color) 25%, transparent);
  outline-offset: -0.5px;
  background: color-mix(in srgb, var(--tag-color) 7%, transparent);
  color: color-mix(in srgb, var(--tag-color) 67%, transparent);
  font: 700 10px/normal var(--st-font-mono);
  letter-spacing: 1px;
  text-transform: uppercase;
  white-space: nowrap;
}
.st-tag--strong {
  outline-color: var(--tag-color);
  background: color-mix(in srgb, var(--tag-color) 16%, transparent);
  color: var(--tag-color);
}

/* ---- Tooltip -------------------------------------------------------------------- */

.st-has-tip { position: relative; }
/* Placed by ui/tooltip.ts in window coordinates (left, top), in the top layer
   as a manual popover: no panel's overflow or stacking can hide it. The
   margin, inset, border and colours reset the browser's popover defaults. */
.st-tip {
  position: fixed;
  inset: auto;
  z-index: 50;
  margin: 0;
  padding: 4px 7px;
  border: 0;
  border-radius: 6px;
  outline: 1px solid var(--st-line-strong);
  outline-offset: -0.5px;
  overflow: visible;
  background: var(--st-surface-2);
  box-shadow: 0 6px 16px color-mix(in srgb, var(--st-shadow) 50%, transparent);
  color: var(--st-text);
  font: 500 10.5px/normal var(--st-font-mono);
  white-space: nowrap;
  pointer-events: none;
}
.st-tip[hidden] { display: none; }

/* ---- Keyboard focus: one ring for the whole Studio ------------------------------

   Every focusable thing in the Studio shows the same ring when it is reached
   from the keyboard: 2px of accent. Many controls draw their border with
   `outline`, and some areas colour it with long selectors, so the ring's
   style, width and colour are !important: a focused control always shows
   this ring.

   Where the ring sits is the area's call. It is 2px outside by default, at a
   specificity (0,2,0) that beats a control's resting `outline-offset` from
   controls.css, but loses to any area rule that comes later: a plain
   `.thing:focus-visible { outline-offset: -2px }`, or --st-focus-offset on
   the control or a parent. A control inside a clipping box (overflow hidden,
   auto or scroll) must draw its ring inside, for example -2px.

   One opt-out: a text input inside a box that draws the ring for it (the
   link field, the Library search) sets --st-focus-ring-style: none on the
   input itself, so only the box shows a ring. The property doesn't inherit,
   so it can't switch off the ring of anything else in the box. */

@property --st-focus-ring-style {
  syntax: '*';
  inherits: false;
}
html[data-app='studio'] body :focus-visible {
  outline-style: var(--st-focus-ring-style, solid) !important;
  outline-width: 2px !important;
  outline-color: var(--st-focus-ring) !important;
}
[data-app='studio'] :focus-visible {
  outline-offset: var(--st-focus-offset, 2px);
}
