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

@layer tokens {
  :root {
    color-scheme: dark;
    --color-bg: oklch(15% 0.02 250);
    --color-surface: oklch(21% 0.02 250);
    --color-surface-2: oklch(26% 0.02 250);
    --color-text: oklch(96% 0.01 240);
    --color-muted: oklch(70% 0.02 240);
    --color-border: oklch(33% 0.02 245);
    --color-accent: oklch(75% 0.14 225);
    --stage-bg: oklch(11% 0.02 250);
    --stage-border: oklch(35% 0.02 245);
    --shadow-color: oklch(0% 0 0 / 25%);

    --space-3xs: .25rem;
    --space-2xs: .4rem;
    --space-xs: .5rem;
    --space-s: .65rem;
    --space-m: .75rem;
    --space-l: 1rem;
    --space-xl: 1.25rem;
    --space-2xl: 1.5rem;
    --space-3xl: 2rem;
    --space-4xl: 3rem;

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

    --measure-m: 700px;
    --measure-l: 900px;
    --measure-xl: 1100px;

    /* default draggable range for .stage; individual demos may override */
    --stage-max: 1100px;
    --stage-min: 220px;
  }

  /* Registered as a real <number> (not just a token string) so it can be
     transitioned: every demo sets this from a @container width query, and
     because the type is registered, the browser eases the number itself
     across a threshold instead of snapping. Anything computed from
     var(--state) inherits that easing for free, no per-property
     transitions needed. See css-lab5/README.md. */
  @property --state {
    syntax: '<number>';
    inherits: true;
    initial-value: 0;
  }
}

@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);
  }

  body {
    padding-block-end: var(--space-4xl);
  }

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

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

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

      a {
        color: var(--color-accent);
      }
    }
  }

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

  p {
    text-wrap: pretty;
  }

  button {
    background: var(--color-surface-2);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-s);
    font: inherit;
  }

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

@layer layout {
  .stage {
    container-type: inline-size;
    /* physical: the drag handle a browser paints for `resize` always sits at the
       physical bottom-right corner regardless of writing mode */
    resize: horizontal;
    overflow: auto;
    inline-size: min(90vw, var(--stage-max));
    min-inline-size: var(--stage-min);
    margin-block: var(--space-4xl);
    margin-inline: auto;
    padding: var(--space-3xl) var(--space-2xl);
    border: 2px dashed var(--stage-border);
    background: var(--stage-bg);
  }
}

@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;
  }

  .state-pill {
    display: flex;
    gap: var(--space-3xs);
    margin-block-end: var(--space-l);
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--color-muted);

    span {
      display: none;
      padding-block: var(--space-3xs);
      padding-inline: var(--space-s);
      border-radius: var(--radius-full);
      background: var(--color-surface-2);
      color: var(--color-accent);
    }
  }
}
