* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg, #fff);
}

#glcanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  /* The LARGE viewport on purpose: the picture runs full bleed behind the
     browser's toolbars rather than stopping in a cropped white band. The
     drawing buffer is measured from this box (see resize in main.js), so
     whatever it resolves to, the aspect stays honest - and body already
     has overflow:hidden, so a canvas taller than what's visible scrolls
     nothing. The interface uses dvh instead, further down, so it stays
     above the toolbar rather than sliding under it with the picture. */
  height: 100vh;
  height: 100lvh;
  display: block;
  /* shaders that bind the pointer need the raw moves; without this the
     browser eats them to pan and pinch-zoom the page */
  touch-action: none;
}

.controls {
  position: fixed;
  display: flex;
  flex-direction: column;
  /* pinned to the bottom of what is actually visible, clear of the home
     indicator */
  bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  left: calc(10px + env(safe-area-inset-left, 0px));
  display: flex;
  z-index: 10;

  button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #80808001;
    color: contrast-color(var(--bg, #fff));
    mix-blend-mode: difference;
    opacity: 0.35;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);

    &:hover {
      background: rgba(255, 255, 255, 0.22);
      opacity: 1;
    }

    &:active {
      background: rgba(255, 255, 255, 0.3);
    }

    /* Until the settings have been opened once (see settingsSeen in
       main.js), the button has an onboarding outline */
    &.hint {
      opacity: .75;
      outline: 2px solid #6cf9b0;
    }
  }
}


#fileInput {
  display: none;
}

.pcr-color-chooser {
  grid-area: 2/1/2/3 !important;
}

.pcr-palette {
  border-bottom-right-radius: none !important;
  border-bottom-left-radius: none !important;
}

.settings {
  position: fixed;
  bottom: calc(32px + env(safe-area-inset-bottom, 0px));
  left: calc(48px + env(safe-area-inset-left, 0px));
  background: rgba(20, 20, 20, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 12px;
  border-bottom-left-radius: 0;
  padding: 14px 18px;
  display: none;
  flex-direction: column;
  min-width: min(calc(100vw - 72px), 400px);
  /* the panel grows upward from its bottom edge; this keeps it inside the
     visible viewport even when it is 30 controls long */
  max-height: min(90dvh, calc(100dvh - 72px));
  overflow-y: auto;
  color: #fff;
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 12px;
  z-index: 10;
  /* Rows sit flush; the dividers and the modules' own spacers do the
     grouping. The shader controls live inside a plain #shaderControls
     div, so they never got this container's gap - which is why they used
     to sit tighter than Zoom / Rotate / Frame rate right below them. */
  gap: 0;

  &.open {
    display: flex;
  }

  .row {
    display: flex;
    align-items: center;
    gap: 10px;

    label {
      flex: 0 0 130px;
      opacity: 0.8;
      user-select: none;   /* double-click resets the param, not selects it */
    }

    input[type="range"] {
      width: 140px;
    }

    select {
      flex: 1;
      background: rgba(255, 255, 255, 0.08);
      color: #fff;
      border: none;
      border-radius: 6px;
      padding: 6px 8px;
      font-size: 12px;
    }

    input[type="color"] {
      flex: 1;
      height: 28px;
      border: none;
      border-radius: 3px;
      background: none;
      cursor: pointer;
      padding: 0;
    }

    input[type="text"].txt {
      flex: 1;
      min-width: 0;
      background: rgba(255, 255, 255, 0.08);
      color: #fff;
      border: none;
      border-radius: 6px;
      padding: 6px 8px;
      font-size: 12px;
      font-family: ui-monospace, SFMono-Regular, Menlo, monospace;

      &::placeholder {
        color: rgba(255, 255, 255, 0.35);
      }
    }

    .val {
      max-width: 6em;
      field-sizing: content;
      background: transparent;
      color: #fff;
      border: none;
      font-size: 12px;
      font-variant-numeric: tabular-nums;
      padding: 3px 4px;
    }
  }

  .row.disabled {
    opacity: 0.3;
    pointer-events: none;
  }

  .divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.12);
    margin: 10px 0;
  }

  .spacer {
    height: 1em;
  }

  .text-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.65);
    font-size: 11px;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    text-align: left;

    &:hover {
      color: #fff;
    }
  }
}
/* Narrow screens: the panel's natural width is label + slider + value,
   which is wider than a phone. Let it span the screen instead of running
   off the right edge, and let the slider take whatever is left. Desktop
   keeps the fixed widths above. */
@media (max-width: 520px) {
  .settings {
    left: calc(10px + env(safe-area-inset-left, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    min-width: 0;

    .row {
      label {
        flex: 0 0 clamp(84px, 34vw, 130px);
      }

      input[type="range"] {
        width: auto;
        flex: 1;
        min-width: 0;
      }

      .val {
        max-width: 4.5em;
      }
    }
  }
}
