/* ============================================================================
   TWEAKS PANEL — reusable primitive for exercise/wallpaper pages
   ----------------------------------------------------------------------------
   Mount via TweaksPanel.mount(...) from tweaks.js.
   Always console-flavoured (dark terminal chrome) regardless of page surface —
   it's a control overlay, not part of the document. Keeps it recognisable
   across exercises.
   ============================================================================ */

/* ----- toggle button ----- */
.tweaks-toggle {
  position: fixed; bottom: 18px; right: 130px;
  z-index: 60;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--whisper);
  background: rgba(12, 12, 13, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid #2e2e36;
  padding: 5px 10px;
  border-radius: 2px;
  cursor: pointer;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color 120ms, border-color 120ms;
}
.tweaks-toggle.side-left {
  left: 18px;
  right: auto;
}
.tweaks-toggle:hover,
.tweaks-toggle.open {
  color: #ffd23f;
  border-color: #ffd23f;
}

/* ----- the panel itself ----- */
.tweaks-panel {
  position: fixed;
  top: 60px; right: 18px; bottom: 60px;
  width: 340px;
  z-index: 60;
  background: rgba(12, 12, 13, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid #2e2e36;
  border-radius: 3px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  overflow-y: auto;
  overflow-x: hidden;
  display: none;
  font-family: var(--font-mono);
  font-size: 11px;
  color: #f1ebdb;
  flex-direction: column;
}
.tweaks-panel.open {
  display: flex;
}
.tweaks-panel.side-left {
  left: 18px;
  right: auto;
}
.tweaks-panel::-webkit-scrollbar { width: 6px; }
.tweaks-panel::-webkit-scrollbar-track { background: transparent; }
.tweaks-panel::-webkit-scrollbar-thumb { background: #2e2e36; border-radius: 3px; }

/* ----- head ----- */
.tweaks-head {
  padding: 14px 16px 10px;
  border-bottom: 1px solid #2e2e36;
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 8px;
  position: sticky; top: 0;
  background: rgba(12, 12, 13, 0.96);
  z-index: 1;
}
.tweaks-head-title {
  color: #ffd23f;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 500;
}
.tweaks-head-sub {
  color: #5b5648;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color 240ms;
}
.tweaks-head-sub.saved {
  color: #3fa66b; /* sage — confirms the auto-save just happened */
}

/* ----- sections ----- */
.tweaks-body { flex: 1; }
.tweaks-section {
  padding: 14px 16px 4px;
  border-bottom: 1px solid #2e2e36;
}
.tweaks-section:last-child { border-bottom: none; }
.tweaks-section-title {
  color: #3fb6c8;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 10px;
  margin-bottom: 12px;
}

/* ----- collapsible section ----- */
.tweaks-section-collapsible .tweaks-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: color 120ms;
}
.tweaks-section-collapsible .tweaks-section-title:hover {
  color: #ffd23f;
}
.tweaks-section-chev {
  font-size: 9px;
  line-height: 1;
  color: #5b5648;
  transition: transform 160ms, color 120ms;
}
.tweaks-section-collapsible .tweaks-section-title:hover .tweaks-section-chev {
  color: #ffd23f;
}
.tweaks-section.collapsed .tweaks-section-chev {
  transform: rotate(-90deg);
}
.tweaks-section.collapsed {
  padding-bottom: 14px;
}
.tweaks-section.collapsed .tweaks-section-title {
  margin-bottom: 0;
}
.tweaks-section.collapsed .tweaks-section-controls {
  display: none;
}

/* ----- inline section (row of compact controls, e.g. preview buttons) ----- */
.tweaks-section-inline .tweaks-section-controls {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.tweaks-section-inline .tweaks-row {
  flex: 1;
  margin-bottom: 4px;
  min-width: 0;
}
.tweaks-section-inline .tweaks-row-button .tweaks-row-button-action {
  padding: 7px 6px;
  font-size: 10px;
  letter-spacing: 0.04em;
}
.tweaks-section-inline .tweaks-hint {
  font-size: 10px;
  margin-top: 4px;
}

/* ----- a row ----- */
.tweaks-row {
  margin-bottom: 14px;
}
.tweaks-row:last-child { margin-bottom: 8px; }

.tweaks-row-head {
  display: flex; align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.tweaks-row-label {
  appearance: none;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  color: #f1ebdb;
  font-family: inherit;
  font-size: 11px;
  text-align: left;
  flex: 1;
  cursor: pointer;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.3;
}
.tweaks-row-label:hover { color: #ffd23f; }

/* numeric readout (sliders only) */
.tweaks-num {
  color: #ffd23f;
  font-size: 10px;
  min-width: 44px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ? button — toggles explainer */
.tweaks-q {
  appearance: none;
  background: transparent;
  border: 1px solid #2e2e36;
  color: #5b5648;
  width: 16px; height: 16px;
  border-radius: 50%;
  padding: 0;
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
  transition: color 120ms, border-color 120ms;
}
.tweaks-q:hover { color: #ffd23f; border-color: #ffd23f; }
.tweaks-row.expanded .tweaks-q {
  color: #ffd23f;
  border-color: #ffd23f;
  background: rgba(255, 210, 63, 0.08);
}

/* ----- slider ----- */
.tweaks-row input[type=range] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 2px;
  background: #2e2e36;
  outline: none;
  margin: 4px 0 0;
  padding: 0;
  cursor: pointer;
}
.tweaks-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #3fb6c8;
  cursor: pointer;
  border: 2px solid #0c0c0d;
}
.tweaks-row input[type=range]::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #3fb6c8;
  cursor: pointer;
  border: 2px solid #0c0c0d;
}

/* ----- segmented radio ----- */
.tweaks-segments {
  display: flex;
  border: 1px solid #2e2e36;
  border-radius: 2px;
  overflow: hidden;
}
.tweaks-seg {
  appearance: none;
  flex: 1;
  background: transparent;
  border: none;
  border-right: 1px solid #2e2e36;
  color: #8a8472;
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 0.04em;
  padding: 6px 4px;
  cursor: pointer;
  text-transform: uppercase;
  transition: color 120ms, background 120ms;
}
.tweaks-seg:last-child { border-right: none; }
.tweaks-seg:hover { color: #f1ebdb; }
.tweaks-seg.on {
  background: rgba(63, 182, 200, 0.12);
  color: #3fb6c8;
}

/* ----- text input ----- */
.tweaks-row input[type=text] {
  appearance: none;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid #2e2e36;
  color: #f1ebdb;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 6px 8px;
  border-radius: 2px;
  width: 100%;
  outline: none;
  box-sizing: border-box;
  margin-top: 2px;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.4;
}
.tweaks-row input[type=text]:focus {
  border-color: #ffd23f;
}
.tweaks-row input[type=text]::selection {
  background: rgba(255, 210, 63, 0.35);
}

/* ----- textarea ----- */
.tweaks-row textarea {
  appearance: none;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid #2e2e36;
  color: #f1ebdb;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 6px 8px;
  border-radius: 2px;
  width: 100%;
  outline: none;
  box-sizing: border-box;
  margin-top: 2px;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.5;
  resize: vertical;
  min-height: 48px;
}
.tweaks-row textarea:focus {
  border-color: #ffd23f;
}
.tweaks-row textarea::selection {
  background: rgba(255, 210, 63, 0.35);
}

/* ----- range slider (two handles: start + end of journey) ----- */
.tweaks-row-range .tweaks-range-pair {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.tweaks-range-letter {
  font-size: 9px;
  color: #5b5648;
  width: 12px;
  text-align: center;
  font-family: var(--font-mono);
  letter-spacing: 0;
  text-transform: none;
}
.tweaks-row-range input[type=range] {
  flex: 1;
  margin: 0;
}
/* Subtle visual differentiation: start handle in cyan, end handle in marker
   yellow, so it's instantly clear which is which. */
.tweaks-row-range .tweaks-range-pair:nth-child(2) input[type=range]::-webkit-slider-thumb {
  background: #3fb6c8;
}
.tweaks-row-range .tweaks-range-pair:nth-child(2) input[type=range]::-moz-range-thumb {
  background: #3fb6c8;
}
.tweaks-row-range .tweaks-range-pair:nth-child(3) input[type=range]::-webkit-slider-thumb {
  background: #ffd23f;
}
.tweaks-row-range .tweaks-range-pair:nth-child(3) input[type=range]::-moz-range-thumb {
  background: #ffd23f;
}
.tweaks-row-range .tweaks-range-pair:nth-child(2) .tweaks-range-letter { color: #3fb6c8; }
.tweaks-row-range .tweaks-range-pair:nth-child(3) .tweaks-range-letter { color: #ffd23f; }

/* ----- action button row ----- */
.tweaks-row-button .tweaks-row-button-action {
  appearance: none;
  background: transparent;
  border: 1px solid #2e2e36;
  color: #f1ebdb;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 8px 12px;
  border-radius: 2px;
  cursor: pointer;
  width: 100%;
  text-align: center;
  transition: color 120ms, border-color 120ms, background 120ms;
}
.tweaks-row-button .tweaks-row-button-action:hover {
  color: #ffd23f;
  border-color: #ffd23f;
}
.tweaks-row-button .tweaks-row-button-action.active {
  color: #3fb6c8;
  border-color: #3fb6c8;
  background: rgba(63, 182, 200, 0.12);
}
.tweaks-row-button .preview-btn-end.active {
  color: #ffd23f;
  border-color: #ffd23f;
  background: rgba(255, 210, 63, 0.12);
}
.tweaks-row-head-button { display: flex; gap: 8px; align-items: center; }
.tweaks-row-head-button .tweaks-row-button-action { flex: 1; }

/* ----- toggle switch ----- */
.tweaks-switch {
  appearance: none;
  background: #18181b;
  border: 1px solid #2e2e36;
  width: 28px; height: 16px;
  border-radius: 999px;
  padding: 0;
  cursor: pointer;
  position: relative;
  transition: background 120ms, border-color 120ms;
  flex-shrink: 0;
}
.tweaks-switch-knob {
  position: absolute;
  top: 1px; left: 1px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #5b5648;
  transition: left 140ms, background 140ms;
}
.tweaks-switch.on {
  background: rgba(63, 182, 200, 0.18);
  border-color: #3fb6c8;
}
.tweaks-switch.on .tweaks-switch-knob {
  left: 13px;
  background: #3fb6c8;
}

/* ----- hint (short, always visible) ----- */
.tweaks-hint {
  font-size: 11px;
  color: #b8a888;
  line-height: 1.5;
  margin-top: 6px;
  font-family: var(--font-sans);
  letter-spacing: 0;
  text-transform: none;
}

/* ----- explainer (long, expand on click) -----
   Snap height, fade opacity. A max-height transition would be smoother in
   theory but reliably wedges at 0 on this page (continuous rAF + canvas
   mutations confuse the transition start), so we keep it simple. */
.tweaks-explainer {
  display: none;
  opacity: 0;
  transition: opacity 180ms;
  font-size: 10px;
  color: #c7c1ad;
  line-height: 1.55;
  font-family: var(--font-sans);
  letter-spacing: 0;
  text-transform: none;
  border-left: 2px solid #ffd23f;
  padding: 6px 10px 6px 12px;
  margin-top: 8px;
}
.tweaks-row.expanded .tweaks-explainer {
  display: block;
  opacity: 1;
}

/* ----- actions row ----- */
.tweaks-actions {
  padding: 12px 16px 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  border-top: 1px solid #2e2e36;
  position: sticky; bottom: 0;
  background: rgba(12, 12, 13, 0.96);
}
.tweaks-action {
  appearance: none;
  background: transparent;
  border: 1px solid #2e2e36;
  color: #f1ebdb;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 7px 8px;
  border-radius: 2px;
  cursor: pointer;
  transition: color 120ms, border-color 120ms;
}
.tweaks-action:hover {
  color: #ffd23f;
  border-color: #ffd23f;
}
.tweaks-action.flash {
  color: #3fa66b;
  border-color: #3fa66b;
}

/* drag-drop file load affordance — when dragging a .json over the panel */
.tweaks-panel.drag-over {
  border-color: #ffd23f;
  box-shadow: inset 0 0 0 1px #ffd23f, 0 8px 32px rgba(0,0,0,0.5);
}

/* ----- list (editable array of textareas with add/delete) ----- */
.tweaks-list-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}
.tweaks-list-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.tweaks-list-item-head-right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.tweaks-list-item-extra {
  display: flex;
  align-items: center;
  gap: 3px;
}
.tweaks-list-item-extra input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
  width: 44px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid #2e2e36;
  color: #f1ebdb;
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 3px 6px;
  border-radius: 2px;
  outline: none;
  text-align: right;
  letter-spacing: 0;
  text-transform: none;
}
.tweaks-list-item-extra input[type="number"]:focus {
  border-color: #ffd23f;
}
.tweaks-list-item-extra input[type="number"]::-webkit-outer-spin-button,
.tweaks-list-item-extra input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.tweaks-list-item-extra-suffix {
  font-size: 9px;
  color: #5b5648;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.tweaks-list-item-label {
  font-size: 9px;
  color: #8a8472;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.tweaks-list-item-head-left {
  display: flex;
  align-items: center;
  gap: 6px;
}
.tweaks-list-item-grip {
  appearance: none;
  background: transparent;
  border: none;
  color: #5b5648;
  font-size: 12px;
  line-height: 1;
  padding: 2px 4px;
  cursor: grab;
  font-family: var(--font-mono, monospace);
  transition: color 120ms;
}
.tweaks-list-item-grip:hover {
  color: #ffd23f;
}
.tweaks-list-item-grip:active {
  cursor: grabbing;
}
.tweaks-list-item.dragging {
  opacity: 0.45;
}
.tweaks-list-item.drag-over-top {
  box-shadow: inset 0 2px 0 0 #ffd23f;
}
.tweaks-list-item.drag-over-bottom {
  box-shadow: inset 0 -2px 0 0 #ffd23f;
}
.tweaks-list-item-del {
  appearance: none;
  background: transparent;
  border: 1px solid #2e2e36;
  color: #5b5648;
  width: 18px;
  height: 18px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  font-family: inherit;
  flex-shrink: 0;
  transition: color 120ms, border-color 120ms, background 120ms;
}
.tweaks-list-item-del:hover {
  color: #e94b35;
  border-color: #e94b35;
  background: rgba(233, 75, 53, 0.08);
}
.tweaks-list-add {
  appearance: none;
  background: transparent;
  border: 1px dashed #2e2e36;
  color: #8a8472;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 7px 8px;
  border-radius: 2px;
  cursor: pointer;
  width: 100%;
  margin-top: 10px;
  transition: color 120ms, border-color 120ms;
}
.tweaks-list-add:hover {
  color: #ffd23f;
  border-color: #ffd23f;
}

/* ----- pins (per-side range snapshots) ----- */
.tweaks-pins-side { margin-bottom: 14px; }
.tweaks-pins-side:last-child { margin-bottom: 0; }
.tweaks-pins-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.tweaks-pins-side-label {
  font-family: var(--font-mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.08em; color: #f1ebdb;
}
.tweaks-pins-add {
  appearance: none; background: transparent;
  border: 1px solid #2e2e36; color: #8a8578;
  font-family: var(--font-mono); font-size: 9px;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 4px 8px; border-radius: 2px; cursor: pointer;
  transition: color 120ms, border-color 120ms;
}
.tweaks-pins-add:hover { color: #3fb6c8; border-color: #3fb6c8; }
.tweaks-pins-list { display: flex; flex-wrap: wrap; gap: 5px; }
.tweaks-pins-empty {
  font-family: var(--font-mono); font-size: 9px;
  color: #5b5648; font-style: italic;
}
.tweaks-pin {
  display: flex; align-items: stretch;
  border: 1px solid #2e2e36; border-radius: 2px; overflow: hidden;
  transition: border-color 200ms;
}
.tweaks-pin.applied { border-color: #3fa66b; }
.tweaks-pin-name {
  appearance: none; background: transparent; border: none;
  color: #f1ebdb; font-family: var(--font-mono); font-size: 10px;
  padding: 4px 8px; cursor: pointer;
  transition: color 120ms;
}
.tweaks-pin-name:hover { color: #ffd23f; }
.tweaks-pin-del {
  appearance: none; background: transparent;
  border: none; border-left: 1px solid #2e2e36;
  color: #5b5648; font-size: 12px; line-height: 1;
  padding: 0 7px; cursor: pointer;
  transition: color 120ms;
}
.tweaks-pin-del:hover { color: #e94b35; }
