/* ── Shared experiment chrome ─────────────────────────────────────────
   Control panel used by every experiment page. On desktop it floats in
   the top-right corner of the demo area; at 800px and below it becomes a
   bottom sheet that starts collapsed, so the demo itself is never hidden
   behind it. experiment.js injects the sheet header and moves the panel
   contents into .ctrl-body — the markup in each page stays flat.       */

.ctrl-panel {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 40;
  width: auto;
  min-width: 280px;
  max-height: calc(100% - 2rem);
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}
.ctrl-body {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 1rem 1.25rem;
  overflow-y: auto;
  /* Without this the flex item refuses to shrink under its content and
     scrolls out of the panel instead of inside it. */
  min-height: 0;
}
.ctrl-sheet-toggle { display: none; }

.ctrl-label {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-ghost);
  margin-top: 0.75rem;
}
.ctrl-label:first-child { margin-top: 0; }

.ctrl-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.25rem 0; }
.ctrl-row input[type="range"] {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  min-width: 100px;
}
.ctrl-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--brand);
  border: none;
  cursor: pointer;
}
.ctrl-row input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--brand);
  border: none;
  cursor: pointer;
}
.ctrl-val {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--ink-mute);
  min-width: 3.5rem;
  text-align: right;
}
.ctrl-name { font-size: 0.75rem; color: var(--ink-soft); min-width: 7.5rem; }

.ctrl-toggle { display: flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0; cursor: pointer; }
.ctrl-toggle input { display: none; }
.ctrl-toggle-track {
  width: 32px; height: 18px;
  border-radius: 9px;
  background: var(--border);
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.ctrl-toggle input:checked + .ctrl-toggle-track { background: var(--brand); }
.ctrl-toggle-dot {
  position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 0.2s;
}
.ctrl-toggle input:checked + .ctrl-toggle-track .ctrl-toggle-dot { transform: translateX(14px); }
.ctrl-toggle-label { font-size: 0.75rem; color: var(--ink-soft); }

.ctrl-actions { display: flex; gap: 0.5rem; }
.reset-btn {
  margin-top: 0.75rem;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink-mute);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
  width: fit-content;
}
.reset-btn:hover { background: var(--surface-3); color: var(--ink); }

.stat-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  color: var(--ink-ghost);
  padding: 0.25rem 0;
}

/* ── Mobile: collapsible bottom sheet ─────────────────────────────────
   Two columns of stacked rows roughly halve the height of the open
   sheet, which matters when it can only take up ~45vh.                */
@media (max-width: 800px) {
  .ctrl-panel {
    position: fixed;
    top: auto; right: 0; bottom: 0; left: 0;
    width: auto;
    min-width: 0;
    max-height: none;
    border-radius: 1rem 1rem 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.22);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .ctrl-sheet-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    padding: 0.9rem 1.25rem;
    border: none;
    background: transparent;
    color: var(--ink-soft);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    touch-action: manipulation;
  }
  .ctrl-sheet-chevron { flex-shrink: 0; transition: transform 0.25s ease; }
  .ctrl-panel.is-open .ctrl-sheet-chevron { transform: rotate(180deg); }

  .ctrl-body {
    display: none;
    grid-template-columns: 1fr 1fr;
    align-content: start;
    gap: 0.4rem 1rem;
    padding: 0 1.25rem 1.25rem;
    max-height: 45vh;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .ctrl-panel.is-open .ctrl-body { display: grid; }

  .ctrl-label { grid-column: 1 / -1; margin-top: 0.5rem; }
  .ctrl-label:first-child { margin-top: 0; }

  /* Name and value share the top line; the slider spans the full width
     underneath, so it stays wide enough to aim at with a thumb. */
  .ctrl-row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "name val" "slider slider";
    align-items: center;
    gap: 0 0.5rem;
    padding: 0;
  }
  .ctrl-name { grid-area: name; min-width: 0; }
  .ctrl-val { grid-area: val; min-width: 0; }
  .ctrl-row input[type="range"] {
    grid-area: slider;
    width: 100%;
    min-width: 0;
    height: 24px;
    background: transparent;
  }
  .ctrl-row input[type="range"]::-webkit-slider-runnable-track {
    height: 4px; border-radius: 2px; background: var(--border);
  }
  .ctrl-row input[type="range"]::-webkit-slider-thumb {
    width: 18px; height: 18px; margin-top: -7px;
  }
  .ctrl-row input[type="range"]::-moz-range-track {
    height: 4px; border-radius: 2px; background: var(--border);
  }
  .ctrl-row input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; }

  .ctrl-toggle { align-self: center; padding: 0.35rem 0; }
  .stat-row, .ctrl-actions { grid-column: 1 / -1; }
  .reset-btn { grid-column: 1 / -1; padding: 0.5rem 0.9rem; width: auto; }
  .ctrl-actions .reset-btn { flex: 1; margin-top: 0; }
  .ctrl-actions { margin-top: 0.75rem; }
}
