@layer reset, tokens, base, layout, components, utilities, overrides;

@layer tokens {
  :root {
    color-scheme: dark;
    --color-bg: #0b0d10;
    --color-surface: #151922;
    --color-surface-2: #1c212c;
    --color-text: #f1f3f5;
    --color-muted: #9aa4b2;
    --color-border: #303846;
    --color-accent: #34d399;
    --stage-bg: #0f1218;
    --stage-border: #3a4352;
    --shadow-color: rgb(0 0 0 / 13%);

    /* Numbered rather than t-shirt sized: this lab's 11 hand-tuned demos
       land on 12 distinct rem steps between .25rem and 3rem, closer
       together than a small/medium/large naming scheme reads cleanly. */
    --space-1: .25rem;
    --space-2: .35rem;
    --space-3: .4rem;
    --space-4: .5rem;
    --space-5: .6rem;
    --space-6: .75rem;
    --space-7: 1rem;
    --space-8: 1.25rem;
    --space-9: 1.5rem;
    --space-10: 1.75rem;
    --space-11: 2rem;
    --space-12: 3rem;

    --radius-s: .5rem;
    --radius-m: .75rem;
    --radius-l: 1rem;
    --radius-full: 999px;

    /* Content-width caps: same concept (a block's max-inline-size before
       centering with margin-inline: auto) reused across demo cards. */
    --measure-m: 700px;
    --measure-l: 900px;
    --measure-xl: 1100px;

    /* Preview-box block-size: identical 16rem reused verbatim by the
       photo, blob-morph, and tilt-scene demos. */
    --preview-block: 16rem;
    /* Compact color-preview square: reused by the channel-mixer swatch and
       the contrast-picker preview. */
    --size-swatch: 8rem;
  }
}

@layer reset {
  * {
    box-sizing: border-box;
  }

  body {
    margin: 0;
    font: 16px system-ui, sans-serif;
  }
}

@layer base {
  html,
  body {
    background: var(--color-bg);
    color: var(--color-text);
  }

  header {
    max-inline-size: var(--measure-l);
    margin-block: var(--space-11) 0;
    margin-inline: auto;
    padding-inline: var(--space-7);

    h1 {
      margin-block-end: var(--space-1);
    }

    p {
      max-inline-size: 70ch;
      color: var(--color-muted);
      margin-block-start: 0;
    }
  }

  :is(h1, h2, h3) {
    text-wrap: balance;
  }

  p {
    text-wrap: pretty;
  }

  button {
    background: var(--color-surface-2);
    color: var(--color-text);
    border-color: var(--color-border);
  }

  :where(a, button, [tabindex]):focus-visible {
    outline: 2px solid var(--color-text);
    outline-offset: 2px;
  }
}

@layer layout {
  .stage {
    inline-size: min(90vw, var(--measure-m));
    margin-block: var(--space-12);
    margin-inline: auto;
    padding: var(--space-11) var(--space-9);
    border: 2px dashed var(--stage-border);
    background: var(--stage-bg);
  }

  .stage-controls {
    display: grid;
    gap: var(--space-8);
    margin-block-end: var(--space-11);
  }

  .stage-control {
    label {
      display: flex;
      justify-content: space-between;
      font-size: .8rem;
      color: var(--color-muted);
      margin-block-end: var(--space-2);
    }
  }
}

@layer components {
  /* Shared cosmetic reset for every range input in this lab. The scroll-driven
     view-timeline wiring that makes the slider live-update a CSS variable is
     registered per demo (each needs its own property name/count) — this only
     makes the native control look intentional instead of browser-default. */
  input[type="range"].range-slider {
    /* Thumb is centered on the track by construction: margin-block-start is
       always half the size difference, not a value re-tuned by eye. */
    --track-size: 4px;
    --thumb-size: 16px;

    -webkit-appearance: none;
    appearance: none;
    inline-size: 100%;
    block-size: 1.5rem;
    background: transparent;
    margin: 0;

    &::-webkit-slider-runnable-track {
      block-size: var(--track-size);
      background: var(--color-border);
      border-radius: 2px;
    }

    &::-moz-range-track {
      block-size: var(--track-size);
      background: var(--color-border);
      border-radius: 2px;
    }

    &::-webkit-slider-thumb {
      -webkit-appearance: none;
      appearance: none;
      inline-size: var(--thumb-size);
      block-size: var(--thumb-size);
      margin-block-start: calc((var(--track-size) - var(--thumb-size)) / 2);
      border-radius: 50%;
      background: var(--color-accent);
      border: 2px solid var(--color-bg);
      box-shadow: 0 0 0 1px var(--color-accent);
      cursor: pointer;
    }

    &::-moz-range-thumb {
      inline-size: var(--thumb-size);
      block-size: var(--thumb-size);
      border-radius: 50%;
      background: var(--color-accent);
      border: 2px solid var(--color-bg);
      box-shadow: 0 0 0 1px var(--color-accent);
      cursor: pointer;
    }

    &:focus-visible::-webkit-slider-thumb {
      outline: 2px solid var(--color-text);
      outline-offset: 2px;
    }

    &:focus-visible::-moz-range-thumb {
      outline: 2px solid var(--color-text);
      outline-offset: 2px;
    }
  }
}

@layer utilities {
  .visually-hidden {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }
}
