/* ─────────────────────────────────────────────────────────────────────────────
   UI Lab shell styles.

   Everything about how the library looks lives here: the grid, the cards, the
   expanded view and the settings panel. Components never style any of this,
   and nothing here reaches into a component. Change the frame freely.
   ───────────────────────────────────────────────────────────────────────────── */

:root {
  --lab-bg: #0f0f0f;
  --lab-card: #19191b;
  --lab-stage: #161618;
  --lab-stage-light: #f4f4f2;
  --lab-well: #232326;
  --lab-well-on: #36363a;
  --lab-fill: #444448;
  --lab-line: rgba(255, 255, 255, 0.07);
  --lab-text: #ededed;
  --lab-muted: #8b8b90;
  --lab-faint: #5e5e63;
  --lab-accent: #8f86ff;

  --lab-ease: cubic-bezier(0.32, 0.72, 0, 1);
  --lab-radius: 28px;
  --lab-gap: 12px;
  --lab-panel-w: 380px;
  /* The expanded view floats in the page rather than filling it, so there is
     always backdrop to click to close. */
  --lab-overlay-max-h: 860px;
  --lab-overlay-margin: 56px;
  --lab-preview-ratio: 1.1;  /* preview width / height, when there is room */

  /* Expand / collapse choreography. */
  --lab-expand-ms: 560ms;
  --lab-panel-delay-ms: 90ms;
}

/* Scoped to the library, so it can live inside another page. :where() keeps
   these at element-level specificity, so component styles still win. */
:where(.lab-grid, .lab-overlay) {
  color: var(--lab-text);
  font: 15px/1.4 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
:where(.lab-grid, .lab-overlay), :where(.lab-grid, .lab-overlay) *, :where(.lab-grid, .lab-overlay) *::before, :where(.lab-grid, .lab-overlay) *::after { box-sizing: border-box; }
:where(.lab-grid, .lab-overlay) button { font: inherit; color: inherit; }
:where(.lab-grid, .lab-overlay) [hidden] { display: none !important; }
body.lab-locked { overflow: hidden; }

:where(.lab-icon-btn, .lab-seg button, .lab-slider, .lab-btn, .lab-tracks):focus-visible {
  outline: 2px solid var(--lab-accent);
  outline-offset: 2px;
}


/* Masonry by columns: cards keep their own heights and flow top to bottom. */
/* Row by row: the shell deals cards into these columns in reading order. */
.lab-grid { display: flex; gap: var(--lab-gap); align-items: flex-start; transition: opacity 300ms ease; }
/* Hidden until start() has everything loaded and measured. */
.lab-grid:not([data-ready]) { opacity: 0; }
.lab-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--lab-gap); }

/* ── Card ───────────────────────────────────────────────────────────────── */
.lab-card {
  position: relative;
  /* Set by the shell: content height + the same padding above and below. */
  height: var(--card-h, 320px);
  border-radius: var(--lab-radius);
  background: var(--lab-stage);
  overflow: hidden;
  cursor: pointer;
  /* No opacity transition: the card must reappear in the same frame the
     preview lands on it, or the collapse flashes the page through. */
  transition: background 440ms var(--lab-ease);
}
.lab-card[data-ground="light"] { background: var(--lab-stage-light); }
.lab-card.is-lifted { visibility: hidden; }

.lab-stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  container-type: size; /* components can size against the stage with cq units */
}

.lab-card-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 14px 22px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 240ms var(--lab-ease), transform 240ms var(--lab-ease);
  pointer-events: none;
}
.lab-card:hover .lab-card-foot,
.lab-card:has(:focus-visible) .lab-card-foot {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.lab-card-name { flex: 1; font-size: 14px; font-weight: 500; }
.lab-card[data-ground="light"] .lab-card-name { color: #1c1c1e; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.lab-icon-btn {
  appearance: none;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--lab-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}
.lab-icon-btn:hover { background: rgba(255,255,255,0.07); color: var(--lab-text); }
.lab-icon-btn.solid { background: rgba(255,255,255,0.09); color: var(--lab-text); }
.lab-icon-btn.solid:hover { background: rgba(255,255,255,0.15); }
.lab-icon-btn[aria-pressed="true"] { background: rgba(143,134,255,0.16); color: #b9b3ff; }
[data-ground="light"] .lab-icon-btn { color: #7c7c78; }
[data-ground="light"] .lab-icon-btn:hover { background: rgba(0,0,0,0.06); color: #1c1c1e; }
[data-ground="light"] .lab-icon-btn.solid { background: rgba(0,0,0,0.07); color: #1c1c1e; }

.lab-btn {
  appearance: none;
  height: 52px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.14);
  background: transparent;
  color: var(--lab-text);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  cursor: pointer;
  transition: background 160ms ease, transform 120ms ease;
}
.lab-btn:hover { background: rgba(255,255,255,0.05); }
.lab-btn:active { transform: scale(0.985); }
.lab-btn.primary { background: #ecebe8; color: #111; border-color: transparent; }
.lab-btn.primary:hover { background: #fff; }
.lab-btn.small { height: 36px; padding: 0 16px; font-size: 13.5px; }
.lab-swap { display: inline-block; animation: lab-swap 300ms var(--lab-ease) both; }
@keyframes lab-swap { from { opacity: 0; transform: translateY(-4px); filter: blur(2px); } }

/* ── Expanded view ──────────────────────────────────────────────────────── */
.lab-overlay { position: fixed; inset: 0; z-index: 100; }
.lab-backdrop {
  position: absolute;
  inset: 0;
  cursor: zoom-out;
  background: rgba(8, 8, 9, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.lab-preview {
  position: absolute;
  border-radius: var(--lab-radius);
  background: var(--lab-stage);
  overflow: hidden;
  transition: background 440ms var(--lab-ease);
}
.lab-preview[data-ground="light"] { background: var(--lab-stage-light); }
.lab-preview .lab-stage { bottom: var(--transport-h, 0px); transition: bottom var(--lab-expand-ms) var(--lab-ease); }

/* The main interaction, placed under the component in the expanded preview. */
/* The same size in the card and the preview, so nothing jumps between them. */
.lab-stage-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: var(--lab-stage-gap, 32px);
  max-height: 60px;
  transition:
    max-height var(--lab-expand-ms) var(--lab-ease),
    margin-top var(--lab-expand-ms) var(--lab-ease),
    opacity 300ms ease;
}
/* Controls that only belong in the expanded view fold away in the card. */
.lab-stage[data-mode="card"] .lab-stage-controls[data-miniature="hidden"] {
  max-height: 0;
  margin-top: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}
.lab-seg.stage { padding: 4px; background: rgba(255,255,255,0.06); }
.lab-seg.stage button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 15px;
  font-size: 13px;
}
.lab-seg.stage button[aria-pressed="true"] { background: #0c0c0d; color: #fff; }
[data-ground="light"] .lab-seg.stage { background: rgba(0,0,0,0.06); }
[data-ground="light"] .lab-seg.stage button { color: #77777a; }
[data-ground="light"] .lab-seg.stage button:hover { color: #1c1c1e; }
[data-ground="light"] .lab-seg.stage button[aria-pressed="true"] { background: #fff; color: #1c1c1e; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

/* Play / pause for items without a timeline. */
.lab-preview-tools { position: absolute; right: 16px; bottom: 16px; }

.lab-panel {
  position: absolute;
  outline: none;
  border-radius: var(--lab-radius);
  background: var(--lab-card);
  border: 1px solid var(--lab-line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}


/* ── Panel ──────────────────────────────────────────────────────────────── */
.lab-p-head {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 22px 18px 0 24px;
}
.lab-p-title { flex: 1; min-width: 0; }
.lab-p-title h2 { margin: 0; font-size: 21px; font-weight: 600; letter-spacing: -0.01em; }
.lab-p-title div {
  margin-top: 6px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--lab-muted);
}
.lab-p-head .lab-icon-btn.close { border: 1px solid var(--lab-line); }

.lab-tabs { margin: 20px 24px 4px; }
.lab-p-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 24px 16px;
  scrollbar-width: none;
}
.lab-p-body::-webkit-scrollbar { display: none; }
.lab-p-foot { padding: 16px 24px 22px; border-top: 1px solid var(--lab-line); display: grid; }

.lab-group {
  margin: 20px 0 8px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--lab-faint);
}
.lab-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
}
.lab-row-label { color: #cfcfd3; }
.lab-note { margin: 10px 2px 12px; font-size: 12.5px; line-height: 1.45; color: var(--lab-muted); }

.lab-seg {
  display: flex;
  padding: 4px;
  border-radius: 999px;
  background: var(--lab-well);
}
.lab-seg button {
  appearance: none;
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--lab-muted);
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 240ms var(--lab-ease), color 240ms var(--lab-ease);
}
.lab-seg button:hover { color: var(--lab-text); }
.lab-seg button[aria-pressed="true"] { background: var(--lab-well-on); color: var(--lab-text); }
.lab-seg.wide { width: 100%; margin: 6px 0; }
.lab-tabs.lab-seg button { padding: 10px; display: grid; place-items: center; }

.lab-slider {
  position: relative;
  height: 52px;
  margin: 8px 0;
  border-radius: 14px;
  background: var(--lab-well);
  overflow: hidden;
  cursor: ew-resize;
  touch-action: none;
  user-select: none;
}
.lab-slider .fill { position: absolute; inset: 0 auto 0 0; background: var(--lab-fill); transition: background 160ms ease; }
.lab-slider:hover .fill, .lab-slider.dragging .fill { background: #4f4f54; }
.lab-slider .s-label, .lab-slider .s-val { position: absolute; top: 50%; transform: translateY(-50%); pointer-events: none; }
.lab-slider .s-label { left: 18px; color: #c9c9cd; }
.lab-slider .s-val { right: 18px; font-variant-numeric: tabular-nums; font-weight: 500; }

.lab-swatches { display: flex; gap: 10px; padding: 4px; }
.lab-swatch {
  appearance: none;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14);
  cursor: pointer;
  transition: box-shadow 200ms var(--lab-ease), transform 200ms var(--lab-ease);
}
.lab-swatch:hover { transform: scale(1.08); }
.lab-swatch[aria-pressed="true"] { box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14), 0 0 0 2px var(--lab-card), 0 0 0 4px #ededed; }
.lab-swatch:focus-visible { outline: 2px solid var(--lab-accent); outline-offset: 4px; }

.lab-image { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.lab-image img { width: 52px; height: 38px; border-radius: 8px; object-fit: cover; background: var(--lab-well); }
.lab-image .lab-btn { flex: 1; }

/* The code view fills the panel; only the code block itself scrolls, so its
   padding and rounded corners stay put. */
.lab-p-body[data-view="code"] { display: flex; flex-direction: column; overflow: hidden; }
.lab-code {
  flex: 1;
  min-height: 0;
  overflow: auto;
  margin: 8px 0 0;
  padding: 16px;
  border-radius: 14px;
  background: #111113;
  border: 1px solid var(--lab-line);
  font: 12px/1.6 "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  color: #c4c4c9;
  white-space: pre;
  tab-size: 2;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.18) transparent;
}

/* ── Demo cursor ───────────────────────────────────────────────────────── */
.lab-cursor {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 50;
  width: 22px;
  height: 22px;
  margin: -3px 0 0 -4px; /* the arrow's tip sits on the point */
  pointer-events: none;
  opacity: 0;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
  transition: opacity 240ms ease;
}
.lab-cursor.is-shown { opacity: 1; }
.lab-cursor-arrow { position: relative; display: block; transform-origin: 4px 3px; }
.lab-cursor svg { display: block; }
/* Click rings spread from the arrow's tip. */
.lab-cursor-ring {
  position: absolute;
  left: -14px;
  top: -15px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.7);
  opacity: 0;
}
.lab-cursor-ring.is-second { background: transparent; }

/* ── Transport: shown in the expanded preview for items with a timeline ── */
.lab-transport {
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 20px;
  padding: 14px 16px 12px 12px;
  border-radius: 18px;
  background: rgba(255,255,255,0.035);
  border: 1px solid var(--lab-line);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  align-items: center;
}
.lab-transport-btns { display: flex; flex-direction: column; gap: 4px; }
.lab-tracks {
  --label-w: 52px;
  position: relative;
  display: grid;
  grid-template-columns: var(--label-w) 1fr;
  row-gap: 9px;
  align-items: center;
  padding: 20px 0 2px;
  cursor: ew-resize;
  touch-action: none;
  user-select: none;
}
.lab-lane-label { font-size: 11px; letter-spacing: 0.04em; color: var(--lab-muted); }
.lab-lane { position: relative; height: 10px; border-radius: 5px; background: rgba(255,255,255,0.05); }
.lab-lane-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 5px;
  background: color-mix(in srgb, var(--c) 28%, transparent);
  overflow: hidden;
  transition: left 200ms var(--lab-ease), width 200ms var(--lab-ease);
}
.lab-lane-bar > b { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--c); border-radius: 5px; }
.lab-ruler {
  position: absolute;
  top: 0;
  left: var(--label-w);
  right: 0;
  height: 14px;
  font-size: 10px;
  color: var(--lab-faint);
  font-variant-numeric: tabular-nums;
}
.lab-ruler span { position: absolute; transform: translateX(-50%); }
.lab-ruler span:first-child { transform: none; }
.lab-playhead {
  position: absolute;
  top: 14px;
  bottom: -4px;
  width: 2px;
  margin-left: -1px;
  background: #fff;
  border-radius: 1px;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35);
}
.lab-playhead::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 50%;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  border-radius: 3px 3px 6px 6px;
  background: #fff;
  transition: transform 160ms var(--lab-ease);
}
.lab-tracks:hover .lab-playhead::before, .lab-tracks.dragging .lab-playhead::before { transform: scale(1.25); }
.lab-tip {
  position: absolute;
  top: -16px;
  padding: 2px 6px;
  border-radius: 6px;
  background: #fff;
  color: #111;
  font-size: 10.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 160ms ease;
}
.lab-tracks:hover .lab-tip, .lab-tracks.dragging .lab-tip { opacity: 1; }
.lab-transport-meta {
  grid-column: 2;
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--lab-faint);
  padding-left: 52px;
}
.lab-transport-meta b { color: var(--lab-muted); font-weight: 500; font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  :root { --lab-expand-ms: 1ms; --lab-panel-delay-ms: 0ms; }
}
