/* Fractal Lab */

.lab {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #000;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

.lab-view, .lab-trace {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}
.lab-view {
  touch-action: none;
  cursor: grab;
}
.lab-view.is-dragging { cursor: grabbing; }
.lab-view.is-tracing { cursor: crosshair; }
.lab-trace { pointer-events: none; }

.lab.ui-hidden .ui { opacity: 0; pointer-events: none; }
.ui { transition: opacity 0.3s; }

.lab-nogl {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
  background: var(--bg);
}
.lab-nogl h1 { font-size: clamp(2.6rem, 7vw, 4.5rem); }
.lab-nogl p { color: var(--text-dim); max-width: 34em; margin: 0 auto; }
.lab-nogl .btn { justify-self: center; }

/* Glass surfaces */
.lab-bar, .floating, .hud, .toast, .sheet {
  background: rgba(8, 10, 15, 0.72);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid rgba(255, 255, 255, 0.09);
  color: var(--text);
}

/* Top bar */
.lab-bar {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 52px;
  padding: 0 8px 0 14px;
  border-radius: 14px;
}
.lab-bar .brand { font-size: 0.82rem; }
.lab-bar .brand-mark { width: 22px; height: 22px; }
.lab-title {
  font-family: var(--serif);
  font-size: 1.35rem;
  line-height: 1;
  padding-left: 14px;
  border-left: 1px solid var(--line-strong);
}
.lab-bar .seg { margin-left: auto; }
.bar-actions { display: flex; gap: 2px; }

.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: 500 0.8rem/1 var(--sans);
  padding: 8px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed='true'] {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.icon-btn {
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.icon-btn svg { width: 19px; height: 19px; fill: currentColor; }
.icon-btn svg[fill='none'] { fill: none; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.icon-btn[aria-pressed='true'] { color: var(--accent); background: rgba(127, 216, 255, 0.1); }
#btn-autopilot .i-pause { display: none; }
#btn-autopilot[aria-pressed='true'] .i-play { display: none; }
#btn-autopilot[aria-pressed='true'] .i-pause { display: inline; }
.panel-toggle-btn { display: none; }
.mobile-only { display: none; }
.panel-actions { display: flex; gap: 8px; }
.panel-actions .btn { flex: 1; justify-content: center; padding: 0.7em 0.6em; font-size: 0.85rem; }

/* Floating panels */
.floating {
  position: fixed;
  z-index: 15;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}
.panel {
  top: calc(76px + env(safe-area-inset-top, 0px));
  right: 12px;
  width: 280px;
  max-height: calc(100vh - 88px - 320px);
  max-height: calc(100dvh - 88px - 320px);
  display: flex;
  flex-direction: column;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 10px 16px;
  cursor: grab;
  touch-action: none;
}
.panel-head:active { cursor: grabbing; }
.panel-head h2 {
  margin: 0;
  font: 500 0.7rem/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.collapse-btn {
  appearance: none;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.collapse-btn svg { width: 12px; height: 12px; transition: transform 0.2s; }
.collapse-btn[aria-expanded='false'] svg { transform: rotate(180deg); }
.collapse-btn:hover { color: var(--text); border-color: var(--line-strong); }

.panel-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 16px 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}
.group { padding: 14px 0; border-top: 1px solid var(--line); }
.group h3 {
  margin: 0 0 12px;
  font: 500 0.68rem/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field > span {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.field output { font-family: var(--mono); color: var(--text); font-size: 0.75rem; }
.field[hidden] { display: none; }

.lab select, .export-form select {
  appearance: none;
  width: 100%;
  padding: 8px 30px 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23a3abbd'/%3E%3C/svg%3E") no-repeat right 10px center / 10px 6px,
    rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: 0.82rem var(--sans);
  cursor: pointer;
}
.lab select option { background: #10131b; color: var(--text); }

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}
input[type='range']::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.14); }
input[type='range']::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.14); }
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; margin-top: -6px;
  border-radius: 50%; background: var(--text); border: 0;
  box-shadow: 0 0 0 4px rgba(127, 216, 255, 0);
  transition: box-shadow 0.2s;
}
input[type='range']::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--text); border: 0; }
input[type='range']:focus-visible { outline: none; }
input[type='range']:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(127, 216, 255, 0.45); }
input[type='range']:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px rgba(127, 216, 255, 0.45); }

.check, .radio {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin: 8px 0;
  cursor: pointer;
}
.check input, .radio input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }

.swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.swatch {
  appearance: none;
  height: 30px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  padding: 0;
  position: relative;
}
.swatch[aria-pressed='true'] { outline: 2px solid var(--text); outline-offset: 2px; }
.seg-small { display: flex; margin-bottom: 14px; }
.seg-small button { flex: 1; padding: 7px 4px; font-size: 0.74rem; }

.places { display: grid; gap: 4px; }
.place {
  appearance: none;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font: 0.82rem var(--sans);
  text-align: left;
  cursor: pointer;
}
.place:hover { border-color: var(--line-strong); background: rgba(255, 255, 255, 0.06); }
.place small { font-family: var(--mono); font-size: 0.66rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.08em; }

/* HUD */
.hud {
  position: fixed;
  left: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 10;
  min-width: 230px;
  padding: 12px 14px;
  border-radius: 12px;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.75;
  pointer-events: none;
}
.hud-row { display: flex; justify-content: space-between; gap: 18px; }
.hud-row span, .hud-meter span { color: var(--text-faint); }
.hud-row b { font-weight: 400; color: var(--text); white-space: nowrap; }
.hud-row[hidden] { display: none; }
.hud-meter { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.hud-meter i { flex: 1; height: 3px; background: rgba(255, 255, 255, 0.12); border-radius: 2px; overflow: hidden; }
.hud-meter em { display: block; height: 100%; width: 0; background: var(--ok); transition: width 0.3s, background 0.3s; }
.hud-meter em.warn { background: var(--warm); }
.hud-meter em.max { background: #ff6b6b; }
.hud-status { margin-top: 4px; color: var(--text-faint); }

/* Mini-map */
.minimap {
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  width: 228px;
}
.mm-body { padding: 0 10px 10px; }
.mm-stage { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: #000; }
.mm-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#mm-overlay { touch-action: none; cursor: crosshair; }
.mm-caption {
  margin: 8px 0 0;
  font: 0.68rem var(--mono);
  color: var(--text-faint);
  text-align: center;
}
[data-collapsed='true'] .panel-body,
[data-collapsed='true'] .mm-body { display: none; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  top: calc(76px + env(safe-area-inset-top, 0px));
  z-index: 40;
  transform: translate(-50%, -8px);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* Dialogs */
.sheet {
  width: min(860px, calc(100vw - 24px));
  max-height: calc(100dvh - 40px);
  padding: 26px 28px 30px;
  border-radius: 18px;
  overflow-y: auto;
  color: var(--text);
}
.sheet-narrow { width: min(420px, calc(100vw - 24px)); }
.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.sheet-head h2 { font-size: 2.4rem; }
.sheet-cols { display: grid; gap: 30px; }
@media (min-width: 760px) { .sheet-cols { grid-template-columns: 0.9fr 1.1fr; } }
.sheet h3 { margin: 0 0 12px; font: 500 0.7rem/1 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-faint); }
.keys { margin: 0; display: grid; gap: 2px; }
.keys div { display: flex; justify-content: space-between; gap: 16px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 0.86rem; }
.keys dt { font-family: var(--mono); font-size: 0.78rem; color: var(--accent); }
.keys dd { margin: 0; color: var(--text-dim); text-align: right; }
.notes p { color: var(--text-dim); font-size: 0.92rem; margin: 0 0 1em; -webkit-user-select: text; user-select: text; }
.notes b { color: var(--text); font-weight: 500; }

.export-form { display: grid; gap: 16px; }
.export-form fieldset { border: 0; margin: 0; padding: 0; }
.export-form legend { font: 500 0.7rem/1 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 8px; }
.radio span { display: flex; justify-content: space-between; flex: 1; color: var(--text); }
.radio em { font-style: normal; font-family: var(--mono); font-size: 0.75rem; color: var(--text-faint); }
.progress { display: flex; align-items: center; gap: 12px; font: 0.75rem var(--mono); color: var(--text-dim); }
.progress i { flex: 1; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.progress em { display: block; height: 100%; width: 0; background: var(--accent); }
.export-form .btn { justify-content: center; }
.export-form .btn:disabled { opacity: 0.6; cursor: progress; }

/* Small screens: controls become a bottom sheet */
@media (max-width: 760px) {
  .lab-bar { gap: 8px; padding: 0 4px 0 10px; height: 48px; top: calc(8px + env(safe-area-inset-top, 0px)); left: 8px; right: 8px; }
  .brand-text, .lab-title, #btn-hide, #btn-share, #btn-export, #btn-help { display: none; }
  .mobile-only { display: block; }
  .lab-bar .seg { margin-left: 0; }
  .seg button { padding: 7px 9px; }
  .icon-btn { width: 34px; height: 34px; }
  .panel-toggle-btn { display: inline-grid; }
  .bar-actions { margin-left: auto; }

  .panel {
    top: auto !important;
    left: 8px !important;
    right: 8px !important;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
    width: auto;
    max-height: 62dvh;
    z-index: 25;
  }
  .panel:not(.is-open) { display: none; }
  .panel .panel-head { cursor: default; }
  .panel .collapse-btn { display: none; }

  .minimap {
    top: calc(64px + env(safe-area-inset-top, 0px)) !important;
    right: 8px !important;
    left: auto !important;
    bottom: auto !important;
    width: 150px;
  }
  .minimap .panel-head { padding: 7px 7px 7px 10px; cursor: default; }
  .minimap .panel-head h2 { font-size: 0.6rem; }
  .mm-caption { display: none; }
  .mm-body { padding: 0 6px 6px; }

  .hud { left: 8px; bottom: calc(8px + env(safe-area-inset-bottom, 0px)); min-width: 0; padding: 9px 12px; font-size: 0.66rem; }
  .hud-extra, .hud-status { display: none; }
}
@media (max-width: 380px) {
  .seg button { padding: 7px 7px; font-size: 0.74rem; }
}
