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

@layer tokens {
  :root {
    color-scheme: dark;
    --color-page: oklch(20% 0.03 250);
    --color-card: oklch(26% 0.035 245);
    --color-ink: oklch(94% 0.03 88);
    --color-muted: oklch(78% 0.025 88);
    --color-line: oklch(46% 0.04 230);
    --color-shadow: oklch(12% 0.02 250);
    --color-teal: oklch(78% 0.11 195);
    --color-tangerine: oklch(72% 0.18 50);
    --color-cherry: oklch(70% 0.17 27);
    --color-mustard: oklch(82% 0.15 85);
    --color-title-shadow: oklch(55% 0.2 27);

    --space-xs: 0.25rem;
    --space-s: 0.5rem;
    --space-m: 1rem;
    --space-l: 1.25rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    --text-xs: 0.75rem;
    --text-s: 0.875rem;
    --text-m: 1rem;
    --text-l: 1.15rem;
    --text-xl: clamp(2rem, 1.5rem + 2.5vi, 3.25rem);
    --leading-tight: 1.15;
    --leading-body: 1.5;

    --radius-m: 1rem;
    --radius-pill: 999px;
    --measure-xl: 1200px;
    --card-min: 18rem;
    --focus-width: 3px;
    --shadow-offset: 6px;
    --badge-size: 3rem;
    --duration-fast: 0.15s;

    --font-sign: "Futura", "Century Gothic", "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  }
}

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

  body {
    margin: 0;
  }

  :where(ul) {
    margin: 0;
    padding: 0;
    list-style: none;
  }
}

@layer base {
  body {
    background: var(--color-page);
    color: var(--color-ink);
    font: var(--text-m) / var(--leading-body) var(--font-sign);
  }

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

  p {
    text-wrap: pretty;
  }

  a {
    color: var(--color-teal);
    text-decoration-thickness: 2px;
    text-underline-offset: 0.15em;
  }

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

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

    & h1 {
      margin-block: var(--space-xs);
      font-size: var(--text-xl);
      font-style: italic;
      font-weight: 900;
      line-height: var(--leading-tight);
      text-shadow: 3px 3px 0 var(--color-title-shadow);
    }

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

  .lab-kicker {
    color: var(--color-cherry);
    font-size: var(--text-s);
    font-weight: 700;
    letter-spacing: 0.25em;
    text-transform: uppercase;
  }
}

@layer layout {
  .index-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--card-min)), 1fr));
    gap: var(--space-xl) var(--space-l);
    max-inline-size: var(--measure-xl);
    margin-inline: auto;
    margin-block: var(--space-xl) var(--space-2xl);
    padding-inline: var(--space-m);
  }
}

@layer components {
  .piece {
    position: relative;
    display: grid;
    align-content: start;
    gap: var(--space-s);
    padding: var(--space-m) var(--space-m) var(--space-l);
    border: 2px solid var(--color-line);
    border-radius: var(--radius-m);
    background: var(--color-card);
    box-shadow: var(--shadow-offset) var(--shadow-offset) 0 var(--color-shadow);
    transition: translate var(--duration-fast) ease, box-shadow var(--duration-fast) ease;

    & iframe {
      display: block;
      inline-size: 100%;
      max-inline-size: 100%;
      aspect-ratio: 4 / 3;
      margin-block-end: var(--space-xs);
      border: 2px solid var(--color-line);
      border-radius: calc(var(--radius-m) - var(--space-s));
      background: var(--color-page);
      pointer-events: none;
    }

    & h2 {
      margin: 0;
      font-size: var(--text-l);
      font-style: italic;
      line-height: var(--leading-tight);
    }

    & h2 a {
      color: var(--color-ink);
      text-decoration: none;

      &::after {
        content: "";
        position: absolute;
        inset: 0;
        border-radius: inherit;
      }

      &:focus-visible {
        outline: none;
      }
    }

    &:has(a:focus-visible) {
      outline: var(--focus-width) solid var(--color-tangerine);
      outline-offset: var(--focus-width);
    }

    @media (hover: hover) {
      &:hover {
        translate: -2px -2px;
        border-color: var(--color-mustard);
        box-shadow: calc(var(--shadow-offset) + 2px) calc(var(--shadow-offset) + 2px) 0 var(--color-shadow);
      }
    }
  }

  .demo-num {
    position: absolute;
    inset-block-start: calc(var(--badge-size) / -3);
    inset-inline-end: calc(var(--badge-size) / -3);
    display: grid;
    place-items: center;
    inline-size: var(--badge-size);
    aspect-ratio: 1;
    background: var(--color-mustard);
    clip-path: polygon(50% 0%, 59% 22%, 82% 13%, 76% 36%, 100% 42%, 80% 57%, 94% 77%, 70% 76%, 64% 100%, 50% 83%, 36% 100%, 30% 76%, 6% 77%, 20% 57%, 0% 42%, 24% 36%, 18% 13%, 41% 22%);
    color: var(--color-shadow);
    font-size: var(--text-s);
    font-variant-numeric: tabular-nums;
    font-weight: 900;
  }

  .demo-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);

    & li {
      padding: 0.1rem var(--space-s);
      border: 1.5px solid var(--color-line);
      border-radius: var(--radius-pill);
      background: var(--color-page);
      font-size: var(--text-xs);
      font-weight: 700;
      letter-spacing: 0.05em;
      text-transform: uppercase;
    }
  }

  .demo-desc {
    margin: 0;
    color: var(--color-muted);
    font-size: var(--text-s);
  }
}

@layer overrides {
  @media (prefers-reduced-motion: reduce) {
    .piece {
      transition: none;
    }
  }

  @media (forced-colors: active) {
    .piece:has(a:focus-visible) {
      outline-color: Highlight;
    }
  }
}
