@layer typography {
  .typography-stage {
    display: block;
    min-width: 0;
  }

  .typography-article,
  .typography-samples {
    width: 100%;
    max-width: 42rem;
    margin-inline: auto;
  }

  .typography-article {
    font-size: 1rem;
    line-height: 1.75;
  }

  .typography-h1,
  .typography-h2,
  .typography-h3,
  .typography-h4 {
    color: var(--foreground);
    text-wrap: balance;
  }

  .typography-h1 {
    scroll-margin-top: 5rem;
    font-size: 2.25rem;
    line-height: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.025em;
  }

  .typography-h2 {
    margin-top: 2.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
    scroll-margin-top: 5rem;
    font-size: 1.875rem;
    line-height: 2.25rem;
    font-weight: 600;
    letter-spacing: -0.025em;
  }

  .typography-h3 {
    margin-top: 2rem;
    scroll-margin-top: 5rem;
    font-size: 1.5rem;
    line-height: 2rem;
    font-weight: 600;
    letter-spacing: -0.025em;
  }

  .typography-h4 {
    scroll-margin-top: 5rem;
    font-size: 1.25rem;
    line-height: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.025em;
  }

  .typography-lead {
    margin-top: 1.5rem;
    color: var(--muted-foreground);
    font-size: 1.25rem;
    line-height: 1.75rem;
  }

  .typography-p {
    margin-top: 1.5rem;
    font-size: 1rem;
    line-height: 1.75rem;
  }

  .typography-link {
    color: var(--foreground);
    font-weight: 500;
    text-decoration-line: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
  }

  .typography-link:hover {
    text-decoration-thickness: 2px;
  }

  .typography-blockquote {
    margin: 1.5rem 0 0;
    padding-inline-start: 1.5rem;
    border-inline-start: 2px solid var(--border);
    font-style: italic;
  }

  .typography-list {
    margin: 1.5rem 0 1.5rem 1.5rem;
    padding: 0;
    list-style: disc outside;
  }

  .typography-list > li {
    margin-top: 0.5rem;
    padding-inline-start: 0.125rem;
  }

  .typography-table-wrap {
    width: 100%;
    margin-block: 1.5rem;
    overflow-x: auto;
    border-radius: 2px;
  }

  .typography-table-wrap:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
  }

  .typography-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 1rem;
    line-height: 1.5rem;
  }

  .typography-table th,
  .typography-table td {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    text-align: left;
  }

  .typography-table th {
    font-weight: 700;
  }

  .typography-table tbody tr:nth-child(even) {
    background: var(--muted);
  }

  .typography-samples {
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
  }

  .typography-samples-title {
    margin-bottom: 1rem;
    font-size: 0.75rem;
    line-height: 1rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted-foreground);
  }

  .typography-sample-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--border);
  }

  .typography-sample {
    min-width: 0;
    min-height: 7.25rem;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.875rem;
    background: var(--background);
  }

  .typography-sample-wide {
    grid-column: 1 / -1;
  }

  .typography-label {
    color: var(--muted-foreground);
    font-size: 0.75rem;
    line-height: 1rem;
    font-weight: 500;
  }

  .typography-code {
    align-self: flex-start;
    max-width: 100%;
    overflow-wrap: anywhere;
    border-radius: calc(var(--radius) - 4px);
    background: var(--muted);
    padding: 0.2rem 0.3rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 600;
  }

  .typography-large {
    font-size: 1.125rem;
    line-height: 1.75rem;
    font-weight: 600;
  }

  .typography-small {
    font-size: 0.875rem;
    line-height: 1;
    font-weight: 500;
  }

  .typography-muted {
    color: var(--muted-foreground);
    font-size: 0.875rem;
    line-height: 1.25rem;
  }

  .typography-rtl {
    margin-top: 0;
    text-align: start;
  }

  @media (max-width: 540px) {
    .typography-sample-grid {
      grid-template-columns: 1fr;
    }

    .typography-sample-wide {
      grid-column: auto;
    }
  }
}
