:root {
  --bg: #ffffff;
  --ink: #2b2a30;
  --ink-soft: #6f6a62;
  --card: rgba(255, 255, 255, 0.86);
  --line: rgba(43, 42, 48, 0.35);
  --accent: #c0392b;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.55 "IBM Plex Mono", ui-monospace, monospace;
}

.nsc-lighting-lab {
  position: fixed;
  inset: 0;

  .stage {
    position: absolute;
    inset: 0;

    canvas { display: block; }
  }

  .panel {
    position: absolute;
    /* Where it starts (the reference layout); drag the title to move it. */
    top: clamp(16px, 10.5vh, 84px);
    left: clamp(16px, 4vw, 60px);
    width: min(360px, calc(100vw - 32px));
    padding: 16px 18px;
    background: var(--card);
    border: var(--panel-border) solid #000;
    border-radius: 2px;
    backdrop-filter: blur(10px);

    /* A hatched drop shadow, as on web-portfolio's .entry-thumb: the box
       offset down and right, filled with diagonal pencil lines. Clipped to
       the L that clears the panel, so the translucent card never shows
       hatching through its face. */
    --hatch-offset: 10px;
    --panel-border: 2px;

    &::before {
      content: '';
      position: absolute;
      /* The border box, shifted by the offset (insets count from inside the border). */
      inset:
        calc(var(--hatch-offset) - var(--panel-border)) calc(var(--hatch-offset) * -1 - var(--panel-border))
        calc(var(--hatch-offset) * -1 - var(--panel-border)) calc(var(--hatch-offset) - var(--panel-border));
      background-image: url('../background-experiments/patterns/diagonal-lines.svg');
      background-size: 4px 4px;
      clip-path: polygon(
        calc(100% - var(--hatch-offset)) 0, 100% 0, 100% 100%, 0 100%,
        0 calc(100% - var(--hatch-offset)), calc(100% - var(--hatch-offset)) calc(100% - var(--hatch-offset))
      );
      pointer-events: none;
    }
  }

  .panel-title {
    margin: 0 0 12px;
    font-size: 19px;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: move;
    user-select: none;
    touch-action: none;
  }

  .steps {
    margin: 0 0 14px;
    padding: 0;
    list-style: none;
    counter-reset: step;
    color: #000;

    li {
      position: relative;
      padding-left: 32px;
      counter-increment: step;

      & + li { margin-top: 8px; }

      &::before {
        content: counter(step);
        position: absolute;
        top: -1px;
        left: 0;
        width: 22px;
        height: 22px;
        font-size: 13px;
        font-weight: 600;
        line-height: 22px;
        text-align: center;
        color: var(--bg);
        background: var(--ink);
      }
    }
  }

  .cam-button {
    width: 100%;
    padding: 9px 12px;
    font: inherit;
    font-weight: 600;
    color: var(--bg);
    background: var(--ink);
    border: 0;
    border-radius: 2px;
    cursor: pointer;
    transition: transform 0.12s ease, filter 0.12s ease;

    &:hover { filter: brightness(1.08); }
    &:active { transform: scale(0.98); }
    &.is-active {
      color: var(--ink);
      background: transparent;
      box-shadow: inset 0 0 0 1px var(--ink);
    }
  }

  .cam-select,
  .calibrate-button {
    width: 100%;
    margin-top: 8px;
    padding: 7px 10px;
    font: inherit;
    color: var(--ink);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 2px;
  }

  .calibrate-button {
    cursor: pointer;

    &:hover { border-color: var(--ink); }
  }

  .cam-status {
    margin: 10px 0 0;
    color: var(--accent);
  }

  [hidden] { display: none !important; }


  .cam-preview {
    position: absolute;
    right: 16px;
    bottom: 16px;
    width: 200px;
    aspect-ratio: 4 / 3;
    margin: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 2px;
    background: #000;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.25s ease, transform 0.25s ease;

    &.is-visible {
      opacity: 1;
      transform: none;
    }

    video,
    canvas {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    video { transform: scaleX(-1); filter: grayscale(1); }
    &.is-unmirrored video { transform: none; }
  }
}

@media (max-width: 600px) {
  .nsc-lighting-lab .cam-preview { width: 120px; }
}

/* lil-gui in paper and graphite */
body .lil-gui {
  --background-color: #ffffff;
  --text-color: #2b2a30;
  --title-background-color: #f1f1f1;
  --title-text-color: #2b2a30;
  --widget-color: #ececec;
  --hover-color: #e0e0e0;
  --focus-color: #d4d4d4;
  --number-color: #c0392b;
  --string-color: #2b2a30;
  --font-family: "IBM Plex Mono", ui-monospace, monospace;

  &.root { border: 1px solid rgba(43, 42, 48, 0.35); }
}

.nsc-lighting-lab .stage { cursor: crosshair; }
.nsc-lighting-lab.is-cam-on .stage { cursor: grab; }

/* "Scene properties", folded into the bottom of the instructions card. No
   background of its own (nor in its subsections), so it reads as part of
   the card. */
body .nsc-lighting-lab .panel .lil-gui {
  --background-color: transparent;
  --title-background-color: transparent;
  --name-width: 48%;
  --font-size: 12px;
  --input-font-size: 12px;
  background: transparent;

  .title { font-weight: 600; }
}

body .nsc-lighting-lab .panel .lil-gui.root {
  --width: 100%;
  width: 100%;
  margin-top: 34px;
  border: 0;

  > .title { padding-left: 0; }
  > .children { padding-bottom: 4px; }
}

/* The small paper-colour swatch at the end of each solid's pattern row. The
   dropdown's invisible <select> is narrowed so it doesn't cover the swatch,
   and the colour <input> fills the swatch, invisible, to catch the click. */
body .nsc-lighting-lab .panel .lil-gui .controller .widget:has(.swatch) {
  select { width: calc(100% - var(--widget-height) - 6px); }
  > .display:not(.swatch) { flex: 1; min-width: 0; }

  .swatch {
    padding: 0;
    /* lil-gui turns pointer events off on a dropdown's .display; the swatch
       needs them back so its colour input can be clicked. */
    pointer-events: auto;

    &::after { content: none; }

    position: relative;
    flex: 0 0 var(--widget-height);
    width: var(--widget-height);
    min-width: 0;
    height: var(--widget-height);
    margin-left: 6px;
    border: 1px solid var(--line);
    border-radius: 2px;
    cursor: pointer;

    input {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      padding: 0;
      border: 0;
      opacity: 0;
      cursor: pointer;
    }
  }
}

/* A darker rule above each solid's subsection (Cube, Cylinder, Cone, Sphere). */
body .nsc-lighting-lab .panel .lil-gui.root > .children > .lil-gui {
  > .title {
    border: 0;
    border-top: 1px solid rgba(22, 22, 26, 0.55);
  }

  &:first-of-type > .title { margin-top: 6px; }
}

/* The "add color" picker: the trigger in the row, and the menu, which lives
   on the page root (fixed) so the panel's scrolling can't clip it. */
body .nsc-lighting-lab {
  .palette-trigger,
  .palette-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 0 6px;
    font: inherit;
    font-size: 12px;
    color: var(--ink);
    text-align: left;
    background: none;
    border: 0;
    cursor: pointer;
  }

  .palette-trigger {
    height: var(--widget-height, 20px);
    background: #ececec;
    border-radius: 2px;

    &::after {
      content: '\2195';
      margin-left: auto;
      opacity: 0.6;
    }

    &:hover { background: #e0e0e0; }
    &.is-open { box-shadow: inset 0 0 0 1px var(--ink); }
  }

  .strip {
    display: flex;
    flex: 0 0 56px;
    height: 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 2px;

    span { flex: 1; }

    &.is-empty { background: #fff; }
  }

  .palette-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .palette-menu {
    position: fixed;
    z-index: 10;
    margin: 0;
    padding: 4px 0;
    overflow-y: auto;
    list-style: none;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 2px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  }

  .palette-option {
    height: 28px;
    padding: 0 10px;

    &:hover,
    &:focus-visible { background: #f1f1f1; outline: none; }
    &.is-selected { font-weight: 600; }
  }
}

/* Scene properties inputs: darker fields with a thin ink outline, so each
   control reads clearly on the white card. */
body .nsc-lighting-lab .panel .lil-gui {
  --text-color: #16161a;
  --widget-color: #e6e6e6;
  --hover-color: #dcdcdc;
  --focus-color: #d0d0d0;

  .controller {
    .slider,
    input[type='checkbox'],
    &.option .display:not(.swatch),
    &.color .display {
      box-shadow: inset 0 0 0 1px rgba(22, 22, 26, 0.28);
    }

    /* The filled part of a slider, in light ink, up to its red marker. */
    .slider .fill { background: rgba(22, 22, 26, 0.14); }

    &:hover {
      .slider,
      input[type='checkbox'],
      &.option .display:not(.swatch) { box-shadow: inset 0 0 0 1px rgba(22, 22, 26, 0.5); }
    }
  }

  .palette-trigger {
    background: var(--widget-color);
    box-shadow: inset 0 0 0 1px rgba(22, 22, 26, 0.28);

    &:hover { background: var(--hover-color); box-shadow: inset 0 0 0 1px rgba(22, 22, 26, 0.5); }
  }

  .swatch { border-color: rgba(22, 22, 26, 0.35); }
}

/* The value read-outs after sliders and the ink colour: plain text, no field. */
body .nsc-lighting-lab .panel .lil-gui .controller {
  input[type='text'],
  input[type='number'] {
    background: transparent;
    box-shadow: none;
  }
}

/* In the "add color" row the preview strip fills the trigger. */
body .nsc-lighting-lab .palette-trigger .strip { flex: 1; }
body .nsc-lighting-lab .palette-trigger { max-width: 80px; }
