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

@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: inherit;
    text-decoration-color: light-dark(var(--light-accent), var(--dark-accent));
    text-decoration-line: underline;
    text-underline-offset: var(--spacing-1);
  }

  a:not(:is(:hover, :focus)) {
    text-decoration-color: color-mix(in srgb, currentColor, transparent 75%);
  }

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

  select {
    appearance: unset;
    background-color: unset;
    border: 1px solid transparent;
    color: inherit;
    border-radius: 0.6em;
    padding: 0.4em 1em;
  }
  select:not([disabled]):hover {
    border-color: light-dark(var(--light-accent), var(--dark-accent));
  }

  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: 0.6em;
    border: 1px solid transparent;
    padding: 0.4em 1em;
    font-weight: 500;
    font-family: inherit;
    color: inherit;
    background-color: light-dark(
      var(--light-button-face),
      var(--dark-button-face)
    );
    cursor: pointer;
    transition: border-color 0.25s;
  }
  button:hover,
  .button:hover {
    border-color: light-dark(var(--light-accent), var(--dark-accent));
  }

  .alert {
    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;
      user-select: none;
    }
  }

  .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 {
    background-color: light-dark(
      var(--light-button-face-muted),
      var(--dark-button-face-muted)
    );
    border-block-start: 1px solid
      light-dark(var(--light-button-face), var(--dark-button-face));
    text-align: center;
    font-size: 0.85rem;
    margin-inline: auto;
    margin-block-start: auto;
    inline-size: var(--sizes-full);
    padding: var(--spacing-8) var(--spacing-4);

    p {
      margin: 0;
      margin-block-end: var(--spacing-2);
    }
  }

  .copy-code {
    display: flex;
    justify-content: space-between;
    inline-size: 0;
    min-inline-size: 100%;
    border-radius: 0.6rem;
    background-color: light-dark(
      var(--light-button-face),
      var(--dark-button-face)
    );

    syntax-highlight {
      border-radius: inherit;
      padding: var(--spacing-4);
    }

    .button {
      align-self: flex-start;
      margin: var(--spacing-2);
      font-size: 85%;
    }
  }

  /* 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 {
      max-inline-size: var(--sizes-md);
      inline-size: var(--sizes-full);
      padding-block-start: var(--spacing-6);
    }
  }

  /* Demo playground */
  [data-section="playground"] {
    display: grid;
    gap: var(--spacing-4);
    padding: var(--spacing-4);
    border-radius: 1rem;
    border: 1px solid
      light-dark(var(--light-button-face), var(--dark-button-face));

    .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-inline: var(--spacing-4);
      overflow: auto;
    }

    .menubar__item {
      display: flex;
      gap: var(--spacing-2);
      align-items: center;
      min-inline-size: 14ch;
    }

    .menubar__item select {
      font-size: 1rem;
      max-width: 20ch;
      text-overflow: ellipsis;
    }

    .menubar__item svg {
      flex-shrink: 0;
    }

    .playground {
      display: grid;
      grid-template-columns: auto;
      gap: var(--spacing-4);

      @media (min-width: 960px) {
        grid-template-columns: minmax(0, 4fr) minmax(0, 5fr);
      }
    }

    /* Playground preview */
    [data-playground="preview"] {
      display: grid;
      grid-template-rows: auto;
      align-items: center;
      justify-items: center;
      align-self: stretch;
      gap: 1rem;
      min-block-size: 300px;
      background-color: light-dark(
        var(--light-button-face-muted),
        var(--dark-button-face-muted)
      );
      border: 1px solid
        light-dark(var(--light-button-face), var(--dark-button-face));
      border-radius: 1rem;
      padding: var(--spacing-4);
    }

    /* Playground code */
    [data-playground="code"] {
      display: grid;
      grid-template-rows: auto 1fr;
      gap: 1rem;
    }
    [data-playground="code"] syntax-highlight {
      display: block;
      border-radius: 1rem;
      padding: var(--spacing-4);
    }
    [data-playground="code"] syntax-highlight:has(style) {
      padding: 0;
      min-inline-size: 100%;
      inline-size: 0;
      display: grid;
      margin: 0;
      position: relative;
    }
    [data-playground="code"] syntax-highlight:has(style:focus-visible) {
      outline: light-dark(var(--light-accent), var(--dark-accent)) auto 1px;
    }
    [data-playground="code"] syntax-highlight:has(style:focus-visible) .hint {
      display: none;
    }
    [data-playground="code"] syntax-highlight:has(style) .hint {
      background-color: light-dark(
        var(--light-button-face-muted),
        var(--dark-button-face-muted)
      );
      color: light-dark(var(--light-accent), var(--dark-accent));
      font-size: 85%;
      position: absolute;
      margin: auto;
      inset-inline-end: var(--spacing-2);
      inset-block-start: var(--spacing-2);
      padding: var(--spacing-2);
      border-radius: calc(1rem - var(--spacing-2));
      display: flex;
      align-items: center;
      gap: var(--spacing-2);
    }
    [data-playground="code"] syntax-highlight style {
      display: block;
      padding: 1rem;
      border-radius: inherit;
      overflow: auto;
      block-size: 400px;
      outline: 0;

      /* prevent iOS zoom on focus */
      @media (hover: none) {
        font-size: 16px;
      }
    }
  }

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

    h1,
    h2,
    h3,
    p {
      text-wrap: balance;
    }

    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,
    .copy-code {
      margin-block-start: 0;
      margin-block-end: var(--spacing-4);
    }
  }
}

@layer reset {
  *,
  :after,
  :before {
    box-sizing: border-box;
  }
  body {
    margin: 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;

    /* #c1c4ff */
    --dark-accent: #a1a2ff;
    --dark-canvas: #242424;
    --dark-canvas-text: rgba(255, 255, 255, 0.871);
    --dark-button-face: #1a1a1a;
    --dark-button-face-muted: #212121;

    /* #6261ff */
    --light-accent: #4a46e0;
    --light-canvas: #ffffff;
    --light-canvas-text: #414141;
    --light-button-face: #f9f9f9;
    --light-button-face-muted: #fdfdfd;
  }
}

@layer syntax-highlight-element {
  :root {
    /* --she-color-text: #414141; */
    /* --she-color-background: transparent; */
    --she-token-constant: #e90;
    --she-token-string: #bea5ff;
    --she-token-comment: #aaa;
    --she-token-keyword: #d19a66;
    --she-token-parameter: #1a1a1a;
    --she-token-function: #c678dd;
    --she-token-string-expression: deeppink;
    --she-token-punctuation: #b3b3b3;
    --she-token-link: #c1cff1;
    --she-token-deleted: crimson;
    --she-token-inserted: #00d061;
  }

  syntax-highlight {
    display: inline-block;
    font-family: var(--fonts-mono);
    white-space: pre;
    tab-size: 2;
    hyphens: none;
    line-height: 1.6;
    overflow: auto;
    background-color: light-dark(
      var(--light-button-face),
      var(--dark-button-face)
    );
  }

  ::highlight(parameter) {
    color: var(--she-token-parameter);
  }

  ::highlight(comment),
  ::highlight(prolog),
  ::highlight(doctype),
  ::highlight(cdata) {
    color: var(--she-token-comment);
  }

  ::highlight(punctuation) {
    color: var(--she-token-punctuation);
  }

  ::highlight(property),
  ::highlight(tag),
  ::highlight(boolean),
  ::highlight(number),
  ::highlight(constant),
  ::highlight(symbol),
  ::highlight(class-name) {
    color: var(--she-token-constant);
  }

  ::highlight(selector),
  ::highlight(attr-name),
  ::highlight(string),
  ::highlight(char),
  ::highlight(builtin) {
    color: var(--she-token-string);
  }

  ::highlight(deleted) {
    color: var(--she-token-deleted);
  }

  ::highlight(inserted) {
    color: var(--she-token-inserted);
  }

  ::highlight(operator),
  ::highlight(entity),
  ::highlight(url) {
    color: var(--she-token-link);
    background: hsla(0, 0%, 100%, 0.5);
  }

  ::highlight(atrule),
  ::highlight(attr-value),
  ::highlight(keyword) {
    color: var(--she-token-keyword);
  }

  ::highlight(function) {
    color: var(--she-token-function);
  }

  ::highlight(regex),
  ::highlight(important),
  ::highlight(variable) {
    color: var(--she-token-string-expression);
  }
}
