@import 'tailwindcss';
@import 'tw-animate-css';

@custom-variant dark (&:is(.dark *));

@theme inline {
  --breakpoint-3xl: 1600px;
  --breakpoint-4xl: 2000px;
  --font-sans: var(--font-sans);
  --font-mono: var(--font-mono);
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-card: var(--card);
  --color-card-foreground: var(--card-foreground);
  --color-popover: var(--popover);
  --color-popover-foreground: var(--popover-foreground);
  --color-primary: var(--primary);
  --color-primary-foreground: var(--primary-foreground);
  --color-secondary: var(--secondary);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-muted: var(--muted);
  --color-muted-foreground: var(--muted-foreground);
  --color-accent: var(--accent);
  --color-accent-foreground: var(--accent-foreground);
  --color-destructive: var(--destructive);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-ring: var(--ring);
  --color-surface: var(--surface);
  --color-surface-foreground: var(--surface-foreground);
  --color-code: var(--code);
  --color-code-foreground: var(--code-foreground);
  --color-code-highlight: var(--code-highlight);
  --color-code-number: var(--code-number);
  --color-selection: var(--selection);
  --color-selection-foreground: var(--selection-foreground);
  --color-brand-facebook: var(--brand-facebook);
  --color-brand-line: var(--brand-line);
  --color-brand-pinterest: var(--brand-pinterest);
  --color-brand-x: var(--brand-x);
}

:root {
  --radius: 0.5rem;
  --background: oklch(1 0 0);
  --foreground: oklch(0.321 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.321 0 0);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.321 0 0);
  --primary: oklch(0.205 0 0);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.97 0 0);
  --secondary-foreground: oklch(0.205 0 0);
  --muted: oklch(0.97 0 0);
  --muted-foreground: oklch(0.556 0 0);
  --accent: oklch(0.97 0 0);
  --accent-foreground: oklch(0.205 0 0);
  --destructive: oklch(0.379 0.155 28.7);
  --border: oklch(0.922 0 0);
  --input: oklch(0.922 0 0);
  --ring: oklch(0.708 0 0);
  --surface: oklch(0.98 0 0);
  --surface-foreground: var(--foreground);
  --code: var(--surface);
  --code-foreground: var(--surface-foreground);
  --code-highlight: oklch(0.96 0 0);
  --code-number: oklch(0.56 0 0);
  --selection: oklch(0.321 0 0);
  --selection-foreground: oklch(1 0 0);
  --brand-facebook: oklch(0.564 0.24 261.2);
  --brand-line: oklch(0.708 0.241 142.5);
  --brand-pinterest: oklch(0.505 0.202 25.8);
  --brand-x: oklch(0 0 0);
}

.dark {
  --background: oklch(0.145 0 0);
  --foreground: oklch(0.985 0 0);
  --card: oklch(0.205 0 0);
  --card-foreground: oklch(0.985 0 0);
  --popover: oklch(0.269 0 0);
  --popover-foreground: oklch(0.985 0 0);
  --primary: oklch(0.922 0 0);
  --primary-foreground: oklch(0.205 0 0);
  --secondary: oklch(0.269 0 0);
  --secondary-foreground: oklch(0.985 0 0);
  --muted: oklch(0.269 0 0);
  --muted-foreground: oklch(0.708 0 0);
  --accent: oklch(0.371 0 0);
  --accent-foreground: oklch(0.985 0 0);
  --destructive: oklch(0.704 0.191 22.216);
  --border: oklch(1 0 0 / 10%);
  --input: oklch(1 0 0 / 15%);
  --ring: oklch(0.556 0 0);
  --surface: oklch(0.2 0 0);
  --surface-foreground: oklch(0.708 0 0);
  --code: var(--surface);
  --code-foreground: var(--surface-foreground);
  --code-highlight: oklch(0.27 0 0);
  --code-number: oklch(0.72 0 0);
  --selection: oklch(0.922 0 0);
  --selection-foreground: oklch(0.205 0 0);
  --brand-facebook: oklch(0.564 0.24 261.2);
  --brand-line: oklch(0.708 0.241 142.5);
  --brand-pinterest: oklch(0.505 0.202 25.8);
  --brand-x: oklch(0 0 0);
}

@layer base {
  * {
    @apply border-border outline-ring/50;
  }
  body {
    @apply bg-background text-foreground;
  }
  ::selection {
    @apply bg-selection text-selection-foreground;
  }
  html {
    @apply scroll-smooth;
  }
  body {
    font-synthesis-weight: none;
    text-rendering: optimizeLegibility;
  }
  a:active,
  button:active {
    @apply opacity-60 md:opacity-100;
  }
}

@utility border-grid {
  @apply border-border/50 dark:border-border;
}

@utility section-soft {
  @apply from-background to-surface/40 dark:bg-background bg-gradient-to-b;
}

@utility container-wrapper {
  @apply mx-auto w-full px-4;

  .fixed-width & {
    @apply max-w-screen-lg;
  }
}

@utility container {
  @apply mx-auto max-w-screen-lg px-4 lg:px-8;
}

@utility no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;

  &::-webkit-scrollbar {
    display: none;
  }
}

@utility border-ghost {
  @apply after:border-border relative after:absolute after:inset-0 after:border after:mix-blend-darken dark:after:mix-blend-lighten;
}

@utility extend-touch-target {
  @media (pointer: coarse) {
    @apply relative touch-manipulation after:absolute after:-inset-2;
  }
}

@layer components {
  .steps {
    &:first-child {
      @apply !mt-0;
    }

    &:first-child > h3:first-child {
      @apply !mt-0;
    }

    > h3 {
      @apply !mt-16;
    }

    > h3 + p {
      @apply !mt-2;
    }
  }

  [data-rehype-pretty-code-figure] {
    background-color: var(--color-code);
    color: var(--color-code-foreground);
    border-radius: var(--radius-lg);
    border-width: 0px;
    border-color: var(--border);
    margin-top: calc(var(--spacing) * 6);
    overflow: hidden;
    font-size: var(--text-sm);
    outline: none;
    position: relative;
    @apply md:-mx-4;

    &:has([data-rehype-pretty-code-title]) [data-slot='copy-button'] {
      top: calc(var(--spacing) * 1.5) !important;
    }
  }

  [data-rehype-pretty-code-title] {
    border-bottom: color-mix(in oklab, var(--border) 30%, transparent);
    border-bottom-width: 1px;
    border-bottom-style: solid;
    padding-block: calc(var(--spacing) * 2.5);
    padding-inline: calc(var(--spacing) * 4);
    font-size: var(--text-sm);
    font-family: var(--font-mono);
    color: var(--color-code-foreground);
  }

  [data-line-numbers] {
    display: grid;
    min-width: 100%;
    white-space: pre;
    border: 0;
    background: transparent;
    padding: 0;
    counter-reset: line;
    box-decoration-break: clone;
  }

  [data-line-numbers] [data-line]::before {
    font-size: var(--text-sm);
    counter-increment: line;
    content: counter(line);
    display: inline-block;
    width: calc(var(--spacing) * 16);
    padding-right: calc(var(--spacing) * 6);
    text-align: right;
    color: var(--color-code-number);
    background-color: var(--color-code);
    position: sticky;
    left: 0;
  }

  [data-line-numbers] [data-highlighted-line][data-line]::before {
    background-color: var(--color-code-highlight);
  }

  [data-line] {
    padding-top: calc(var(--spacing) * 0.5);
    padding-bottom: calc(var(--spacing) * 0.5);
    min-height: calc(var(--spacing) * 1);
    width: 100%;
    display: inline-block;
  }

  [data-line] span {
    color: var(--shiki-light);

    @variant dark {
      color: var(--shiki-dark) !important;
    }
  }

  [data-highlighted-line],
  [data-highlighted-chars] {
    position: relative;
    background-color: var(--color-code-highlight);
  }

  [data-highlighted-line] {
    &:after {
      position: absolute;
      top: 0;
      left: 0;
      width: 2px;
      height: 100%;
      content: '';
      background-color: color-mix(
        in oklab,
        var(--muted-foreground) 50%,
        transparent
      );
    }
  }

  [data-highlighted-chars] {
    border-radius: var(--radius-sm);
    padding-inline: 0.3rem;
    padding-block: 0.1rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
  }
}
