@layer reset, tokens, syntax-highlight-element, layout;

@layer reset {
  *,
  :after,
  :before {
    box-sizing: border-box;
  }
  body {
    margin: 0;
  }
  [hidden] {
    display: none !important;
  }
}

@layer layout {
  :root {
    font-family: var(--fonts-sans);
    line-height: 1.5;
    font-weight: 400;

    color-scheme: light dark;
    color: light-dark(var(--light-canvas-text), var(--dark-canvas-text));
    background-color: light-dark(var(--light-canvas), var(--dark-canvas));

    font-synthesis: none;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  body {
    display: grid;
    gap: var(--base-size-64);
    min-height: 100vh;
  }

  :focus-visible {
    outline-color: light-dark(var(--light-accent), var(--dark-accent));
  }

  a {
    color: light-dark(var(--light-link-text), var(--dark-link-text));
    text-decoration: inherit;
  }
  a:hover {
    /* text-decoration: underline; */
    text-decoration-line: underline;
    text-decoration-style: wavy;
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
  }

  input {
    accent-color: light-dark(var(--light-accent), var(--dark-accent));
  }

  select {
    appearance: unset;
    background-color: unset;
    border: 1px solid transparent;
    color: inherit;
    font-family: inherit;
    padding: var(--spacing-1\.5) var(--spacing-3);
    border-radius: 4px;
    transition-duration: 0.25s;
    transition-property: border-color;
  }
  select:not([disabled]):hover {
    border-color: light-dark(var(--light-accent), var(--dark-accent));
  }

  syntax-highlight {
    color-scheme: inherit;
  }

  code {
    background-color: light-dark(var(--light-button-face), var(--dark-button-face));
    border-radius: 0.25rem;
    padding: var(--spacing-0\.5) var(--spacing-1);
  }

  h1 {
    margin-block: 0;
  }

  button,
  .button {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid transparent;
    padding: 0.6em 1.2em;
    font-weight: 500;
    font-family: inherit;
    background-color: light-dark(var(--light-button-face), var(--dark-button-face));
    cursor: pointer;
    user-select: none;
    transition-duration: 0.25s;
    transition-property: border-color, opacity, scale;
  }
  button:hover,
  .button:hover {
    border-color: light-dark(var(--light-accent), var(--dark-accent));
    color: light-dark(var(--light-accent), var(--dark-accent));
    scale: 1.1;
  }

  .alert {
    background-color: light-dark(var(--light-canvas), var(--dark-canvas));
    position: sticky;
    top: env(safe-area-inset-top, 0);
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    text-wrap: balance;
    gap: var(--spacing-2);
    padding: var(--spacing-6) var(--spacing-4);
    border-block-end: 3px solid light-dark(var(--light-accent), var(--dark-accent));

    p {
      margin: 0;
    }
  }

  header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: var(--spacing-5);
    background-color: light-dark(var(--light-button-face-muted), var(--dark-button-face-muted));
    border-block-end: 1px solid light-dark(var(--light-button-face), var(--dark-button-face));
    padding: var(--spacing-6) var(--spacing-4);

    color-scheme-switch.button {
      padding: var(--spacing-2);
      aspect-ratio: 1;
      align-self: flex-start;
    }
  }

  .header-links {
    font-size: 0.9rem;
    display: flex;
    flex-wrap: wrap;
    flex: 1;
    gap: var(--spacing-5);
    container-type: inline-size;

    a {
      color: inherit;
      display: inline-flex;
      align-items: center;
      gap: var(--spacing-2);
      text-wrap: nowrap;
      width: 100%;
    }

    a:first-of-type {
      margin-inline-end: auto;
    }

    svg {
      display: none;
    }
  }

  @container (min-width: 400px) {
    .header-links a {
      width: auto;
    }

    .header-links svg {
      display: initial;
    }
  }

  main {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-10);
    margin-inline: auto;
    max-inline-size: var(--sizes-5xl);
    inline-size: var(--sizes-full);
    padding-inline: var(--spacing-4);
    padding-block: var(--spacing-24);
  }

  footer {
    border-block-start: 1px solid light-dark(var(--light-button-face), var(--dark-button-face));
    text-align: center;
    margin-inline: auto;
    margin-block-start: auto;
    inline-size: var(--sizes-full);
    padding: var(--spacing-8) var(--spacing-4);

    p {
      margin: 0;
    }
  }

  .copy-code {
    display: flex;
    position: relative;
    inline-size: 0;
    min-inline-size: 100%;

    syntax-highlight {
      flex: 1;
      border-radius: 0.6rem;
      padding: var(--spacing-4);
      line-height: 1.6; /* fixed line-height no matter which theme is loaded */
    }

    .button {
      opacity: 0;
      position: absolute;
      inset-inline-end: var(--spacing-2);
      inset-block-start: var(--spacing-2);
      padding: var(--spacing-2);
      aspect-ratio: 1;
    }
  }

  .copy-code:hover .button,
  .copy-code:focus-within .button {
    opacity: 1;
  }

  /* Intro */
  [data-section="intro"] {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-4);
    text-align: center;
    text-wrap: balance;
    padding-block-end: var(--spacing-24);

    .emoji {
      font-size: clamp(2rem, 2vw + 2rem, 5rem);
      line-height: 1;
    }

    .heading {
      color: light-dark(var(--light-accent), var(--dark-accent));
      font-size: clamp(1.5rem, 2vw + 1.5rem, 3rem);
      font-weight: bold;
      line-height: 1.1;
      display: flex;
      flex-direction: column;
      margin: 0;
    }

    .tagline {
      font-size: clamp(1rem, 2vw, 1.25rem);
      font-weight: normal;
      margin: 0;
    }

    .badges {
      display: flex;
      justify-content: center;
      flex-wrap: wrap;
      gap: 0.5rem;
      font-size: 0;
      padding-block-start: var(--spacing-6);
    }

    .copy-code-container {
      text-align: initial;
      max-inline-size: var(--sizes-md);
      inline-size: var(--sizes-full);
      padding-block-start: var(--spacing-6);
    }
  }

  /* Demo playground */
  [data-section="playground"] {
    display: grid;
    padding: var(--spacing-3);
    border: 1px solid light-dark(var(--light-button-face), var(--dark-button-face));
    border-radius: 0.6rem;
    box-shadow:
      0 1px 3px 0 rgba(0, 0, 0, 0.1),
      0 1px 2px -1px rgba(0, 0, 0, 0.1);

    .playground-title {
      background-color: light-dark(var(--light-button-face), var(--dark-button-face));
      border-radius: 0.4rem;
      font-size: 85%;
      font-weight: 400;
      line-height: 1;
      text-align: center;
      margin: 0;
      padding: var(--spacing-2);
    }

    .menubar {
      display: flex;
      gap: var(--spacing-4);
      padding: var(--spacing-4);
      overflow: auto;
    }
    .menubar:has([disabled]) {
      opacity: 0.4;
    }
    .menubar__item {
      display: flex;
      gap: var(--spacing-2);
      align-items: center;
      min-width: 12ch;
    }
    .menubar__item select {
      font-size: 1rem;
      flex: 1;
    }

    .playground-code {
      inline-size: 0;
      min-inline-size: 100%;
      border-radius: 0.4rem;
      position: relative;
    }

    .playground-code .loader {
      mix-blend-mode: exclusion;
      width: fit-content;
      font-family: monospace;
      font-size: 1rem;
      clip-path: inset(0 3ch 0 0);
      opacity: 0;
      pointer-events: none;
      position: absolute;
      inset-inline-end: var(--spacing-4);
      inset-block-start: var(--spacing-4);
      transition: opacity 0.25s;
    }
    .playground-code .loader:before {
      content: "Loading...";
    }

    .playground-code[data-loading] .loader {
      opacity: 1;
      animation: loader 1s steps(4) infinite;
    }
    .playground-code[data-loading] syntax-highlight {
      opacity: 0.4;
    }

    syntax-highlight {
      display: block;
      padding: var(--spacing-4);
      border-radius: inherit;
      overflow: auto;
      overscroll-behavior: contain;
      block-size: 60dvh;
      max-block-size: var(--sizes-xl);
      transition: opacity 0.25s;
    }
  }

  /* Content */
  [data-section="content"] {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-4);

    h1 {
      font-size: clamp(1.5rem, 2vw + 1rem, 2rem);
      line-height: 1.1;
    }

    h2 {
      font-size: clamp(1rem, 2vw + 0.75rem, 1.5rem);
      margin-block-start: var(--spacing-6);
      margin-block-end: var(--spacing-4);
    }

    p,
    li {
      text-wrap: balance;
    }

    li + li {
      margin-block-start: var(--spacing-2);
    }

    p,
    ul,
    .copy-code {
      margin-block-start: 0;
      margin-block-end: var(--spacing-4);
    }
  }

  .toast {
    background-color: light-dark(var(--light-button-face), var(--dark-button-face));
    border: 1px solid light-dark(var(--light-button-face), var(--dark-button-face));
    border-radius: 0.4rem;
    font-size: 85%;
    box-shadow:
      0 1px 3px 0 rgba(0, 0, 0, 0.1),
      0 1px 2px -1px rgba(0, 0, 0, 0.1);
    padding: var(--spacing-4) var(--spacing-4);
    width: var(--sizes-xs);
    margin: unset;
    inset: unset;
    inset-inline-end: var(--spacing-8);
    inset-block-end: var(--spacing-8);
    opacity: 0;
    transform: translateY(100%);
    transition:
      opacity 0.25s,
      transform 0.25s;
  }

  .toast:popover-open {
    transform: translateY(0);
    opacity: 1;

    @starting-style {
      /* biome-ignore lint/suspicious/noDuplicateProperties: reason */
      opacity: 0;
      transform: translateY(100%);
    }
  }

  @keyframes loader {
    to {
      clip-path: inset(0 -1ch 0 0);
    }
  }
}

@layer tokens {
  :where(:root) {
    --spacing-0: 0rem;
    --spacing-0\.5: 0.125rem;
    --spacing-1: 0.25rem;
    --spacing-1\.5: 0.375rem;
    --spacing-2: 0.5rem;
    --spacing-2\.5: 0.625rem;
    --spacing-3: 0.75rem;
    --spacing-3\.5: 0.875rem;
    --spacing-4: 1rem;
    --spacing-5: 1.25rem;
    --spacing-6: 1.5rem;
    --spacing-7: 1.75rem;
    --spacing-8: 2rem;
    --spacing-9: 2.25rem;
    --spacing-10: 2.5rem;
    --spacing-11: 2.75rem;
    --spacing-12: 3rem;
    --spacing-14: 3.5rem;
    --spacing-16: 4rem;
    --spacing-20: 5rem;
    --spacing-24: 6rem;
    --spacing-28: 7rem;
    --spacing-32: 8rem;

    --sizes-xs: 20rem;
    --sizes-sm: 24rem;
    --sizes-md: 28rem;
    --sizes-lg: 32rem;
    --sizes-xl: 36rem;
    --sizes-2xl: 42rem;
    --sizes-3xl: 48rem;
    --sizes-4xl: 56rem;
    --sizes-5xl: 64rem;
    --sizes-6xl: 72rem;
    --sizes-7xl: 80rem;
    --sizes-8xl: 90rem;
    --sizes-full: 100%;

    --fonts-sans:
      ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
    --fonts-mono:
      ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
      monospace;

    --dark-accent: #8cccd5;
    --dark-canvas: #0d1117;
    --dark-canvas-text: rgba(255, 255, 245, 0.86);
    --dark-link-text: var(--dark-accent);
    --dark-button-face: #151b23;

    --light-accent: #5086a1;
    --light-canvas: #ffffff;
    --light-canvas-text: #3c3c43;
    --light-link-text: var(--light-accent);
    --light-button-face: #f6f8fa;
  }
}
