:root {
  --bg: #000;
  --fg: #f7f7fb;
  --muted: rgba(255,255,255,.42);
  --hairline: rgba(255,255,255,.13);
  --panel: rgba(7,7,10,.90);
  --accent: #b864ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;

  background: var(--bg);
  color: var(--fg);

  font-family:
    ui-monospace,
    "SFMono-Regular",
    "Cascadia Code",
    "Roboto Mono",
    monospace;

  overscroll-behavior: none;
  touch-action: none;
}

body {
  min-height: 100dvh;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

#app {
  position: relative;
  width: 100%;
  height: 100dvh;
  background:
    radial-gradient(
      circle at 50% 48%,
      rgba(110, 40, 180, .045),
      transparent 40%
    ),
    #000;
}

.brand {
  position: fixed;
  z-index: 20;
  top: max(18px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));

  display: flex;
  align-items: baseline;
  gap: 12px;

  pointer-events: none;
}

.brand-name {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .22em;
}

.experiment {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: .14em;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
}

#fluidCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.boot-overlay {
  position: fixed;
  z-index: 50;
  inset: 0;

  display: grid;
  place-items: center;

  background: #000;

  transition:
    opacity .7s ease,
    visibility .7s ease;
}

.boot-overlay.hidden {
  opacity: 0;
  visibility: hidden;
}

.boot-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;

  text-align: center;
}

.boot-brand {
  font-size: clamp(21px, 5vw, 31px);
  font-weight: 900;
  letter-spacing: .30em;
  margin-right: -.30em;
}

.boot-id {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .25em;
}

.init-button {
  margin-top: 30px;

  border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px;

  padding: 13px 19px;

  background: transparent;
  color: #fff;

  font-size: 10px;
  letter-spacing: .16em;

  cursor: pointer;

  transition:
    background .2s ease,
    border .2s ease,
    box-shadow .2s ease;
}

.init-button:hover {
  border-color: rgba(184,100,255,.8);
  background: rgba(184,100,255,.08);
  box-shadow: 0 0 30px rgba(184,100,255,.12);
}

.boot-note {
  margin-top: 8px;
  color: rgba(255,255,255,.28);
  font-size: 8px;
  letter-spacing: .16em;
}

.instrument-readout {
  position: fixed;
  z-index: 15;

  bottom: max(22px, env(safe-area-inset-bottom));
  left: max(22px, env(safe-area-inset-left));

  color: rgba(255,255,255,.30);

  font-size: 8px;
  letter-spacing: .14em;

  pointer-events: none;
}

.separator {
  margin: 0 5px;
}

.menu-button {
  position: fixed;
  z-index: 30;

  right: max(20px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));

  width: 45px;
  height: 45px;

  border: 1px solid rgba(255,255,255,.17);
  border-radius: 50%;

  background: rgba(0,0,0,.42);
  backdrop-filter: blur(12px);

  font-size: 26px;
  line-height: 1;

  cursor: pointer;

  transition:
    transform .25s ease,
    border-color .25s ease,
    box-shadow .25s ease;
}

.menu-button:hover {
  transform: scale(1.06);
  border-color: rgba(184,100,255,.6);
  box-shadow: 0 0 25px rgba(184,100,255,.12);
}

.controls {
  position: fixed;
  z-index: 40;

  right: max(14px, env(safe-area-inset-right));
  bottom: max(72px, calc(env(safe-area-inset-bottom) + 58px));

  width: min(370px, calc(100vw - 28px));
  max-height: min(650px, calc(100dvh - 105px));

  padding: 20px;

  border: 1px solid rgba(255,255,255,.12);
  border-radius: 22px;

  background:
    linear-gradient(
      180deg,
      rgba(15,15,21,.95),
      rgba(4,4,6,.94)
    );

  box-shadow:
    0 26px 80px rgba(0,0,0,.8),
    0 0 60px rgba(120,45,220,.06);

  backdrop-filter: blur(22px);

  overflow-y: auto;

  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(.98);

  transition:
    opacity .22s ease,
    visibility .22s ease,
    transform .22s ease;
}

.controls.open {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.controls-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;

  margin-bottom: 24px;
}

.controls-title {
  font-weight: 900;
  font-size: 12px;
  letter-spacing: .16em;
}

.controls-subtitle {
  margin-top: 5px;
  color: var(--muted);
  font-size: 8px;
  letter-spacing: .16em;
}

.close-button {
  border: 0;
  background: transparent;
  color: rgba(255,255,255,.5);
  font-size: 22px;
  cursor: pointer;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 120px 53px;
  align-items: center;
  gap: 10px;

  padding: 12px 0;
  border-top: 1px solid rgba(255,255,255,.07);
}

.control-row strong {
  display: block;
  font-size: 9px;
  letter-spacing: .12em;
}

.control-row small {
  display: block;
  margin-top: 4px;

  color: rgba(255,255,255,.32);

  font-size: 7px;
  letter-spacing: .1em;
}

.control-row output {
  color: rgba(255,255,255,.52);
  text-align: right;
  font-size: 9px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.segmented-row {
  grid-template-columns: 1fr 173px;
}

.segments {
  display: flex;
  gap: 5px;
}

.segments button {
  flex: 1;

  border: 1px solid rgba(255,255,255,.10);
  border-radius: 8px;

  padding: 8px 7px;

  background: rgba(255,255,255,.03);

  color: rgba(255,255,255,.42);

  font-size: 7px;
  letter-spacing: .08em;

  cursor: pointer;
}

.segments button.active {
  color: #fff;
  border-color: rgba(184,100,255,.38);
  background: rgba(184,100,255,.10);
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;

  margin-top: 16px;
}

.toggle-grid label {
  display: flex;
  gap: 8px;
  align-items: center;

  padding: 9px;

  border: 1px solid rgba(255,255,255,.07);
  border-radius: 8px;

  font-size: 7px;
  letter-spacing: .07em;
}

.toggle-grid input {
  accent-color: var(--accent);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;

  margin-top: 20px;
}

.actions button {
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 9px;

  padding: 11px 8px;

  background: rgba(255,255,255,.035);

  font-size: 7px;
  letter-spacing: .1em;

  cursor: pointer;
}

.desktop-help {
  margin-top: 18px;

  color: rgba(255,255,255,.24);

  font-size: 7px;
  line-height: 1.7;
  letter-spacing: .1em;
}

@media (max-width: 600px) {
  .brand {
    top: max(15px, env(safe-area-inset-top));
    left: max(16px, env(safe-area-inset-left));
  }

  .brand-name {
    font-size: 10px;
  }

  .experiment {
    font-size: 8px;
  }

  .controls {
    left: 10px;
    right: 10px;
    width: auto;
    bottom: max(70px, calc(env(safe-area-inset-bottom) + 56px));
  }
}

/* GOOLAB tactile-input diagnostic */
html[data-touch-count]:not([data-touch-count="0"]) body::after {
  content: "TOUCH " attr(data-touch-count);
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 9999;
  pointer-events: none;
  font: 600 10px/1 monospace;
  letter-spacing: .16em;
  color: rgba(255,255,255,.55);
}

/* ---------------------------------------------------------
   GOOLAB / 001 — dedicated tactile vessel surface
   --------------------------------------------------------- */

#fluidTouchSurface {
  position: fixed;
  z-index: 20;

  border-radius: 50%;

  background: transparent;

  pointer-events: auto;
  touch-action: none;

  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;

  overscroll-behavior: none;
}

/*
 * Controls and startup UI must remain above the vessel's
 * tactile layer and receive their own taps normally.
 */
.controls,
.control-panel,
.menu,
.menu-panel,
.boot,
.boot-screen,
.overlay,
button,
input,
label {
  position: relative;
  z-index: 30;
}


/* =========================================================
   GOOLAB / 001
   MOBILE INSTRUMENT CONTROL SHEET
   ========================================================= */

@media (max-width: 600px) {

  /*
   * The desktop control panel is a floating card.
   * On phones it becomes a proper bottom instrument sheet.
   */

  .controls {
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));

    bottom:
      max(
        8px,
        env(safe-area-inset-bottom)
      );

    width: auto;

    /*
     * --goolab-vvh is updated from visualViewport below.
     * 100dvh remains the safe fallback.
     */
    max-height:
      calc(
        var(--goolab-vvh, 100dvh)
        - max(12px, env(safe-area-inset-top))
        - max(12px, env(safe-area-inset-bottom))
        - 12px
      );

    padding:
      16px
      16px
      max(16px, env(safe-area-inset-bottom));

    border-radius: 20px;

    overflow-x: hidden;
    overflow-y: auto;

    overscroll-behavior: contain;

    -webkit-overflow-scrolling: touch;

    transform:
      translateY(20px)
      scale(.985);
  }

  .controls.open {
    transform: none;
  }


  /* Header stays available while scrolling controls. */

  .controls-header {
    position: sticky;
    top: -16px;
    z-index: 2;

    margin:
      -16px
      -16px
      8px;

    padding:
      16px
      16px
      12px;

    background:
      linear-gradient(
        180deg,
        rgba(15,15,21,.99) 72%,
        rgba(15,15,21,.94) 88%,
        transparent
      );
  }


  /* Compact the laboratory controls vertically. */

  .control-row {
    grid-template-columns:
      minmax(92px, 1fr)
      minmax(90px, 1.15fr)
      48px;

    gap: 8px;

    padding: 10px 0;
  }

  .control-row strong {
    font-size: 8px;
  }

  .control-row small {
    font-size: 6px;
  }

  .control-row output {
    min-width: 0;
    text-align: right;
    font-size: 8px;
  }


  /* Colour selector must not force horizontal overflow. */

  .segments {
    min-width: 0;
  }

  .segments button {
    min-width: 0;
    padding-left: 7px;
    padding-right: 7px;
    font-size: 7px;
  }


  /* Two-column switches remain comfortably tappable. */

  .toggle-grid {
    gap: 7px;
    margin-top: 12px;
  }

  .toggle-grid label {
    min-height: 38px;
  }


  .actions {
    gap: 7px;
    margin-top: 14px;
  }


  /*
   * Desktop instructions waste scarce vertical space on
   * the actual phone instrument.
   */
  .desktop-help {
    display: none;
  }


  /*
   * Once the panel is open, the floating ○ is redundant.
   * Keeping it behind the sheet also prevents visual clutter.
   */
  .controls.open ~ .menu-button {
    visibility: hidden;
  }
}


/*
 * The dedicated vessel surface remains below controls.
 * Explicit values make this invariant obvious.
 */

#fluidTouchSurface {
  z-index: 20;
}

.menu-button {
  z-index: 30;
}

.controls {
  z-index: 40;
}


/* =========================================================
   GOOLAB MENU — v0.1 RESTORED INSTRUMENT GEOMETRY
   ========================================================= */
.menu-button {
  position: fixed;
  z-index: 30;

  right: max(20px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));

  width: 45px;
  height: 45px;

  border: 1px solid rgba(255,255,255,.17);
  border-radius: 50%;

  background: rgba(0,0,0,.42);
  backdrop-filter: blur(12px);

  font-size: 26px;
  line-height: 1;

  cursor: pointer;

  transition:
    transform .25s ease,
    border-color .25s ease,
    box-shadow .25s ease;
}

.menu-button:hover {
  transform: scale(1.06);
  border-color: rgba(184,100,255,.6);
  box-shadow: 0 0 25px rgba(184,100,255,.12);
}

.controls {
  position: fixed;
  z-index: 40;

  right: max(14px, env(safe-area-inset-right));
  bottom: max(72px, calc(env(safe-area-inset-bottom) + 58px));

  width: min(370px, calc(100vw - 28px));
  max-height: min(650px, calc(100dvh - 105px));

  padding: 20px;

  border: 1px solid rgba(255,255,255,.12);
  border-radius: 22px;

  background:
    linear-gradient(
      180deg,
      rgba(15,15,21,.95),
      rgba(4,4,6,.94)
    );

  box-shadow:
    0 26px 80px rgba(0,0,0,.8),
    0 0 60px rgba(120,45,220,.06);

  backdrop-filter: blur(22px);

  overflow-y: auto;

  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(.98);

  transition:
    opacity .22s ease,
    visibility .22s ease,
    transform .22s ease;
}

.controls.open {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.controls-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;

  margin-bottom: 24px;
}

.controls-title {
  font-weight: 900;
  font-size: 12px;
  letter-spacing: .16em;
}

.controls-subtitle {
  margin-top: 5px;
  color: var(--muted);
  font-size: 8px;
  letter-spacing: .16em;
}

.close-button {
  border: 0;
  background: transparent;
  color: rgba(255,255,255,.5);
  font-size: 22px;
  cursor: pointer;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 120px 53px;
  align-items: center;
  gap: 10px;

  padding: 12px 0;
  border-top: 1px solid rgba(255,255,255,.07);
}

.control-row strong {
  display: block;
  font-size: 9px;
  letter-spacing: .12em;
}

.control-row small {
  display: block;
  margin-top: 4px;

  color: rgba(255,255,255,.32);

  font-size: 7px;
  letter-spacing: .1em;
}

.control-row output {
  color: rgba(255,255,255,.52);
  text-align: right;
  font-size: 9px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.segmented-row {
  grid-template-columns: 1fr 173px;
}

.segments {
  display: flex;
  gap: 5px;
}

.segments button {
  flex: 1;

  border: 1px solid rgba(255,255,255,.10);
  border-radius: 8px;

  padding: 8px 7px;

  background: rgba(255,255,255,.03);

  color: rgba(255,255,255,.42);

  font-size: 7px;
  letter-spacing: .08em;

  cursor: pointer;
}

.segments button.active {
  color: #fff;
  border-color: rgba(184,100,255,.38);
  background: rgba(184,100,255,.10);
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;

  margin-top: 16px;
}

.toggle-grid label {
  display: flex;
  gap: 8px;
  align-items: center;

  padding: 9px;

  border: 1px solid rgba(255,255,255,.07);
  border-radius: 8px;

  font-size: 7px;
  letter-spacing: .07em;
}

.toggle-grid input {
  accent-color: var(--accent);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;

  margin-top: 20px;
}

.actions button {
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 9px;

  padding: 11px 8px;

  background: rgba(255,255,255,.035);

  font-size: 7px;
  letter-spacing: .1em;

  cursor: pointer;
}

.desktop-help {
  margin-top: 18px;

  color: rgba(255,255,255,.24);

  font-size: 7px;
  line-height: 1.7;
  letter-spacing: .1em;
}

@media (max-width: 600px) {
  .brand {
    top: max(15px, env(safe-area-inset-top));
    left: max(16px, env(safe-area-inset-left));
  }

  .brand-name {
    font-size: 10px;
  }

  .experiment {
    font-size: 8px;
  }

  .controls {
    left: 10px;
    right: 10px;
    width: auto;
    bottom: max(70px, calc(env(safe-area-inset-bottom) + 56px));
  }
}


/*
 * Current tactile layer remains underneath all controls.
 */
#fluidTouchSurface {
  z-index: 20 !important;
}

.menu-button {
  z-index: 30 !important;
}

.controls {
  z-index: 40 !important;
}
