/* Import fonts first */
@import url("https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap");
@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap");

/* Then import Tailwind */
@import "tailwindcss";
@plugin "@tailwindcss/typography";

/* Global font smoothing */
* {
  -webkit-font-smoothing: antialiased;
}

/* Hide scrollbar but keep scrolling functionality */
.scrollbar-hide {
  -ms-overflow-style: none; /* Internet Explorer 10+ */
  scrollbar-width: none; /* Firefox */
}

.scrollbar-hide::-webkit-scrollbar {
  display: none; /* Safari and Chrome */
}

/* Add scroll offset for anchor links */
.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
  scroll-margin-top: 2rem; /* 32px offset from top */
}

/* Fix cramped middle section */
@media (min-width: 1024px) and (max-width: 1280px) {
  /* Ensure content doesn't get too cramped */
  article {
    min-width: 0;
    flex: 1;
  }
}

/* Better content wrapping on mobile */
@media (max-width: 1024px) {
  /* Ensure code blocks don't overflow */
  pre {
    overflow-x: auto;
    white-space: pre;
  }

  /* Better table handling */
  .prose table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* Tablet-specific adjustments */
@media (min-width: 641px) and (max-width: 1024px) {
  .prose {
    font-size: 0.9375rem; /* 15px */
  }
}

/* Mobile navigation improvements */
@media (max-width: 1024px) {
  /* Ensure mobile menu is properly positioned */
  #sidebar {
    top: 0;
    left: 0;
    height: 100vh;
    width: 100vw;
    max-width: 19rem;
  }

  /* Improve mobile overlay */
  #mobile-overlay {
    backdrop-filter: blur(4px);
  }
}

/* Shiki dual theme support for data-theme attribute - Fixed selector */
[data-theme="dark"] .astro-code,
[data-theme="dark"] .astro-code span {
  color: var(--shiki-dark) !important;
  /* Optional, if you also want font styles */
  font-style: var(--shiki-dark-font-style) !important;
  font-weight: var(--shiki-dark-font-weight) !important;
  text-decoration: var(--shiki-dark-text-decoration) !important;
}

/* Override Shiki background colors with our --background variable */
.astro-code {
  background-color: var(--secondary) !important;
}

[data-theme="dark"] .astro-code {
  background-color: var(--secondary) !important;
}

/* Pre component styling */
pre {
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
}

[data-theme="dark"] pre {
  border-color: transparent;
}

/* Fix first line spacing in code blocks */
pre .astro-code {
  margin-top: -0.25rem;
}

/* Target the first line specifically */
pre .astro-code > *:first-child {
  margin-top: 0 !important;
  padding-top: 0 !important;
}

/* Remove any top spacing from the first text node */
pre .astro-code > *:first-child > *:first-child {
  margin-top: 0 !important;
  padding-top: 0 !important;
}

/* Target all spans in the first line */
pre .astro-code span:first-child {
  margin-top: 0 !important;
  padding-top: 0 !important;
}

/* Remove any line-height issues */
pre .astro-code {
  line-height: 1.5 !important;
}

/* Try text-indent approach */
pre .astro-code {
  text-indent: -0.5rem;
  padding-left: 0.5rem;
}

/* Alternative: use ::before to remove first line spacing */
pre .astro-code::before {
  content: "";
  display: block;
  height: 0;
  margin-top: -0.25rem;
}

/* Last resort: target the actual text nodes */
pre .astro-code > *:first-child {
  margin-top: -0.5rem !important;
}

/* Fix prose table margins */
.prose table {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

/* Remove border from last table row */
.prose table tr:last-child {
  border-bottom: none !important;
}

/* Fix prose paragraph margins in cards */
.prose p {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

/* Remove margins from images in prose */
.prose img {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

/* Preserve whitespace between paragraphs in prose */
.prose p + p {
  margin-top: 1rem !important;
}

/* Fix accordion spacing when multiple */
.prose .accordion + .accordion {
  margin-top: 0.5rem !important;
}

/* Accordion group styling */
.accordion-group .accordion {
  margin: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  border-bottom: 1px solid var(--border) !important;
}

.accordion-group .accordion:last-child {
  border-bottom: none !important;
}

/* Component spacing - using Tailwind classes instead */

[data-theme="dark"] pre {
  border-color: transparent;
}

/* Remove backticks from inline code */
.prose code::before {
  content: "";
}

.prose code::after {
  content: "";
}

/* Custom Scrollbar Styles */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
  transition: background-color 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted-foreground);
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Custom Text Selection */
::selection {
  background: var(--primary);
  color: var(--primary-foreground);
}

::-moz-selection {
  background: var(--primary);
  color: var(--primary-foreground);
}

/* Dark mode scrollbar adjustments */
[data-theme="dark"] ::-webkit-scrollbar-track {
  background: transparent;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: var(--border);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: var(--muted-foreground);
}

[data-theme="dark"] ::-webkit-scrollbar-corner {
  background: transparent;
}

[data-theme="dark"] * {
  scrollbar-color: var(--border) transparent;
}

@theme {
  --font-sans: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;

  /* Color tokens for Tailwind */
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-app-background: var(--app-background);
  --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-destructive-foreground: var(--destructive-foreground);
  --color-success: var(--success);
  --color-success-foreground: var(--success-foreground);
  --color-warning: var(--warning);
  --color-warning-foreground: var(--warning-foreground);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-ring: var(--ring);

  /* Sidebar colors */
  --color-sidebar: var(--sidebar);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-ring: var(--sidebar-ring);

  /* Chart colors */
  --color-chart-1: var(--chart-1);
  --color-chart-2: var(--chart-2);
  --color-chart-3: var(--chart-3);
  --color-chart-4: var(--chart-4);
  --color-chart-5: var(--chart-5);
  --color-star: var(--star);

  /* Light Mode Colors */
  --background: oklch(1 0 0);
  --app-background: oklch(0.9848 0.0013 106.42);
  --foreground: oklch(26.8% 0.007 34.298);
  --card: oklch(1 0 0);
  --card-foreground: oklch(26.8% 0.007 34.298);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(26.8% 0.007 34.298);
  --primary: oklch(0.6252 0.146802 118.8993);
  --primary-foreground: oklch(1 0.146802 118.8993);
  --secondary: oklch(97% 0.001 106.424);
  --secondary-foreground: oklch(26.8% 0.007 34.298);
  --muted: oklch(97% 0.001 106.424);
  --muted-foreground: oklch(55.3% 0.013 58.071);
  --accent: oklch(97% 0.001 106.424);
  --accent-foreground: oklch(26.8% 0.007 34.298);
  --destructive: oklch(0.577 0.245 27.325);
  --destructive-foreground: oklch(1 0 0);
  --success: oklch(0.654 0.184 142);
  --success-foreground: oklch(0.963 0.025 137);
  --warning: oklch(0.877 0.184 99);
  --warning-foreground: oklch(0.293 0.071 70);
  --border: oklch(92.3% 0.003 48.717);
  --input: oklch(92.3% 0.003 48.717);
  --ring: oklch(0.709 0.01 56.259);
  --star: oklch(68.1% 0.162 75.834);

  /* Callout Colors - Light Mode (from Figma) */
  --callout-info-bg: #f5f5f4; /* stone-100 */
  --callout-info-border: #e7e5e4; /* stone-200 */
  --callout-info-text: #292524; /* stone-800 */
  --callout-warning-bg: #fffbeb; /* amber-50 */
  --callout-warning-border: #fde68a; /* amber-200 */
  --callout-warning-text: #78350f; /* amber-900 */
  --callout-error-bg: #fef2f2; /* red-50 */
  --callout-error-border: #fca5a5; /* red-300 */
  --callout-error-text: #7f1d1d; /* red-900 */
  --callout-success-bg: #f7fee7; /* lime-50 */
  --callout-success-border: #bef264; /* lime-300 */
  --callout-success-text: #365314; /* lime-900 */
  --callout-tip-bg: #f7fee7; /* lime-50 */
  --callout-tip-border: #bef264; /* lime-300 */
  --callout-tip-text: #365314; /* lime-900 */
  --callout-note-bg: #f0f9ff; /* sky-50 */
  --callout-note-border: #bae6fd; /* sky-200 */
  --callout-note-text: #0c4a6e; /* sky-900 */

  /* Chart Colors */
  --chart-1: oklch(0.646 0.222 41.116);
  --chart-2: oklch(0.6 0.118 184.704);
  --chart-3: oklch(0.398 0.07 227.392);
  --chart-4: oklch(0.828 0.189 84.429);
  --chart-5: oklch(0.769 0.188 70.08);

  /* Sidebar Specific Tokens */
  --sidebar: oklch(0.985 0.001 106.423);
  --sidebar-foreground: oklch(0.147 0.004 49.25);
  --sidebar-primary: oklch(0.216 0.006 56.043);
  --sidebar-primary-foreground: oklch(0.985 0.001 106.423);
  --sidebar-accent: oklch(0.97 0.001 106.424);
  --sidebar-accent-foreground: oklch(0.216 0.006 56.043);
  --sidebar-border: oklch(0.923 0.003 48.717);
  --sidebar-ring: oklch(0.709 0.01 56.259);
}

/* Custom Typography Styles - Direct CSS Override */
.prose {
  /* Light mode colors */
  --tw-prose-body: var(--color-muted-foreground);
  --tw-prose-headings: var(--color-foreground);
  --tw-prose-lead: var(--color-muted-foreground);
  --tw-prose-links: var(--color-primary);
  --tw-prose-bold: var(--color-foreground);
  --tw-prose-counters: var(--color-muted-foreground);
  --tw-prose-bullets: var(--color-muted-foreground);
  --tw-prose-hr: var(--color-border);
  --tw-prose-quotes: var(--color-foreground);
  --tw-prose-quote-borders: var(--color-border);
  --tw-prose-captions: var(--color-muted-foreground);
  --tw-prose-th-borders: var(--color-border);
  --tw-prose-td-borders: var(--color-border);
}

.prose.prose-invert {
  /* Dark mode colors */
  --tw-prose-body: var(--color-muted-foreground);
  --tw-prose-headings: var(--color-foreground);
  --tw-prose-lead: var(--color-muted-foreground);
  --tw-prose-links: var(--color-primary);
  --tw-prose-bold: var(--color-foreground);
  --tw-prose-counters: var(--color-muted-foreground);
  --tw-prose-bullets: var(--color-muted-foreground);
  --tw-prose-hr: var(--color-border);
  --tw-prose-quotes: var(--color-foreground);
  --tw-prose-quote-borders: var(--color-border);
  --tw-prose-captions: var(--color-muted-foreground);
  --tw-prose-code: var(--color-primary);
  --tw-prose-pre-code: var(--color-primary-foreground);
  --tw-prose-pre-bg: var(--color-card);
  --tw-prose-th-borders: var(--color-border);
  --tw-prose-td-borders: var(--color-border);
}

/* Dark Mode Colors - Using Starlight's [data-theme="dark"] approach */
[data-theme="dark"] {
  --background: oklch(21.6% 0.006 56.043);
  --app-background: oklch(0.1838 0.0052 67.5);
  --foreground: oklch(98.5% 0.001 106.423);
  --card: oklch(26.8% 0.007 34.298);
  --card-foreground: oklch(98.5% 0.001 106.423);
  --popover: oklch(26.8% 0.007 34.298);
  --popover-foreground: oklch(98.5% 0.001 106.423);
  --primary: oklch(0.8916 0.2037 118.17);
  --primary-foreground: oklch(0.3266 0.0858 149.2);
  --secondary: oklch(26.8% 0.007 34.298);
  --secondary-foreground: oklch(98.5% 0.001 106.423);
  --muted: oklch(37.4% 0.01 67.558);
  --muted-foreground: oklch(70.9% 0.01 56.259);
  --accent: oklch(37.4% 0.01 67.558);
  --accent-foreground: oklch(98.5% 0.001 106.423);
  --destructive: oklch(0.704 0.191 22.216);
  --destructive-foreground: oklch(98.5% 0.001 106.423);
  --success: oklch(0.696 0.17 162.48);
  --success-foreground: oklch(98.5% 0.001 106.423);
  --warning: oklch(0.769 0.188 70.08);
  --warning-foreground: oklch(98.5% 0.001 106.423);
  --border: oklch(0.444 0.011 73.64 / 40%);
  --input: oklch(44.4% 0.011 73.639);
  --ring: oklch(0.553 0.013 58.071);
  --star: oklch(0.9 0.15 85);

  /* Callout Colors - Dark Mode (from Figma) */
  --callout-info-bg: oklch(21.6% 0.006 56.043); /* stone-900 */
  --callout-info-border: oklch(37.4% 0.01 67.558 / 60%); /* stone-700 */
  --callout-info-text: oklch(97% 0.001 106.424); /* stone-50 */
  --callout-warning-bg: oklch(76.9% 0.188 70.08 / 10%); /* amber-950 */
  --callout-warning-border: oklch(76.9% 0.188 70.08 / 50%); /* amber-800 */
  --callout-warning-text: oklch(96.2% 0.059 95.617); /* amber-100 */
  --callout-error-bg: oklch(63.7% 0.237 25.331 / 10%); /* red-950 */
  --callout-error-border: oklch(63.7% 0.237 25.331 / 50%); /* red-800 */
  --callout-error-text: oklch(88.5% 0.062 18.334); /* red-200 */
  --callout-success-bg: oklch(76.8% 0.233 130.85 / 10%); /* lime-950 */
  --callout-success-border: oklch(76.8% 0.233 130.85 / 50%); /* lime-800 */
  --callout-success-text: oklch(96.7% 0.067 122.328); /* lime-100 */
  --callout-tip-bg: oklch(76.8% 0.233 130.85 / 10%); /* lime-950 */
  --callout-tip-border: oklch(76.8% 0.233 130.85 / 50%); /* lime-800 */
  --callout-tip-text: oklch(96.7% 0.067 122.328); /* lime-100 */
  --callout-note-bg: oklch(68.5% 0.169 237.323 / 10%); /* sky-900 */
  --callout-note-border: oklch(68.5% 0.169 237.323 / 50%); /* sky-700 */
  --callout-note-text: oklch(95.1% 0.026 236.824); /* sky-100 */

  /* Dark Chart Colors */
  --chart-1: oklch(0.488 0.243 264.376);
  --chart-2: oklch(0.696 0.17 162.48);
  --chart-3: oklch(0.769 0.188 70.08);
  --chart-4: oklch(0.627 0.265 303.9);
  --chart-5: oklch(0.645 0.246 16.439);

  /* Dark Sidebar Tokens */
  --sidebar: oklch(0.216 0.006 56.043);
  --sidebar-foreground: oklch(0.985 0.001 106.423);
  --sidebar-primary: oklch(0.488 0.243 264.376);
  --sidebar-primary-foreground: oklch(0.985 0.001 106.423);
  --sidebar-accent: oklch(0.268 0.007 34.298);
  --sidebar-accent-foreground: oklch(0.985 0.001 106.423);
  --sidebar-border: oklch(0.444 0.011 73.639);
  --sidebar-ring: oklch(0.553 0.013 58.071);
}
