@tailwind base;
@tailwind components;
@tailwind utilities;

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 10px;
}

*::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: 20px;
  border: 2px solid var(--scrollbar-track);
  transition: background-color 0.2s ease;
}

*::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-thumb-hover);
}

@layer base {
  :root {
    --background: 0 0% 100%;
    --foreground: 0 0% 15%;
    --card: 0 0% 100%;
    --card-foreground: 0 0% 15%;
    --popover: 0 0% 100%;
    --popover-foreground: 0 0% 15%;
    --primary: 0 0% 25%;
    --primary-foreground: 0 0% 98%;
    --secondary: 0 0% 96%;
    --secondary-foreground: 0 0% 25%;
    --muted: 0 0% 96%;
    --muted-foreground: 0 0% 45%;
    --accent: 0 0% 96%;
    --accent-foreground: 0 0% 25%;
    --destructive: 0 50% 50%;
    --destructive-foreground: 0 0% 98%;
    --border: 0 0% 90%;
    --input: 0 0% 90%;
    --ring: 0 0% 25%;
    --radius: 0.5rem;

    --scrollbar-thumb: rgba(0, 0, 0, 0.15);
    --scrollbar-thumb-hover: rgba(0, 0, 0, 0.25);
    --scrollbar-track: rgba(0, 0, 0, 0.03);
    --chart-1: 0 0% 30%;
    --chart-2: 0 0% 40%;
    --chart-3: 0 0% 50%;
    --chart-4: 0 0% 60%;
    --chart-5: 0 0% 70%;

    --code-bg: 0 0% 98%;
    --code-fg: 0 0% 15%;
  }

  .dark {
    --background: 0 0% 8%;
    --foreground: 0 0% 90%;
    --card: 0 0% 8%;
    --card-foreground: 0 0% 90%;
    --popover: 0 0% 8%;
    --popover-foreground: 0 0% 90%;
    --primary: 0 0% 85%;
    --primary-foreground: 0 0% 10%;
    --secondary: 0 0% 12%;
    --secondary-foreground: 0 0% 85%;
    --muted: 0 0% 12%;
    --muted-foreground: 0 0% 60%;
    --accent: 0 0% 12%;
    --accent-foreground: 0 0% 85%;
    --destructive: 0 50% 50%;
    --destructive-foreground: 0 0% 90%;
    --border: 0 0% 15%;
    --input: 0 0% 15%;
    --ring: 0 0% 85%;

    --scrollbar-thumb: rgba(255, 255, 255, 0.15);
    --scrollbar-thumb-hover: rgba(255, 255, 255, 0.25);
    --scrollbar-track: rgba(0, 0, 0, 0.2);

    --chart-1: 0 0% 70%;
    --chart-2: 0 0% 60%;
    --chart-3: 0 0% 50%;
    --chart-4: 0 0% 40%;
    --chart-5: 0 0% 30%;

    --code-bg: 0 0% 6%;
    --code-fg: 0 0% 85%;
  }
}

@layer base {
  * {
    @apply border-border;
  }

  html {
    scroll-behavior: smooth;
  }

  body {
    @apply bg-background text-foreground;
    font-feature-settings: "ss01", "ss02", "cv01", "cv02";
  }
}

.prose {
  margin: 0 !important;
}

/* Enhanced pre styling - Mobile optimized */
pre {
  padding: 0 !important;
  width: 100% !important;
  overflow-x: auto;
  @apply bg-[hsl(var(--code-bg))] text-[hsl(var(--code-fg))];
  @apply rounded-lg sm:rounded-xl;
  transition: all 0.2s ease;
  font-size: 13px;
}

@media (min-width: 640px) {
  pre {
    font-size: 14px;
  }
}

pre>code {
  display: grid;
  width: 100%;
  padding: 12px 0 !important;
  @apply text-xs sm:text-sm leading-relaxed;
}

@media (min-width: 640px) {
  pre>code {
    padding: 16px 0 !important;
  }
}

.code-line {
  padding: 0 12px;
  transition: background-color 0.2s ease;
}

@media (min-width: 640px) {
  .code-line {
    padding: 0 16px;
  }
}

.line-number::before {
  display: inline-block;
  width: 1rem;
  margin-right: 16px;
  color: hsl(var(--muted-foreground));
  content: attr(line);
  font-size: 12px;
  text-align: right;
  user-select: none;
  opacity: 0.5;
}

.highlight-line {
  background-color: hsl(var(--muted) / 0.15);
  border-left: 2px solid hsl(var(--primary));
}

.punctuation {
  color: hsl(220 14% 71%);
  font-weight: 400;
}

.dark .punctuation {
  color: hsl(220 14% 45%);
}

.comment {
  color: hsl(220 10% 50%);
  font-style: italic;
  opacity: 0.8;
}

.dark .comment {
  color: hsl(220 10% 60%);
}

.keyword {
  color: hsl(221 87% 60%);
  font-weight: 600;
}

.dark .keyword {
  color: hsl(221 87% 70%);
}

.function {
  color: hsl(266 85% 58%);
  font-weight: 500;
}

.dark .function {
  color: hsl(266 85% 68%);
}

.string {
  color: hsl(142 76% 36%);
  font-weight: 400;
}

.dark .string {
  color: hsl(142 76% 46%);
}

.constant {
  color: hsl(35 99% 36%);
  font-weight: 500;
}

.dark .constant {
  color: hsl(35 99% 46%);
}

.annotation {
  color: hsl(204 70% 53%);
  font-weight: 500;
}

.dark .annotation {
  color: hsl(204 70% 63%);
}

.boolean {
  color: hsl(5 74% 59%);
  font-weight: 600;
}

.dark .boolean {
  color: hsl(5 74% 69%);
}

.number {
  color: hsl(35 99% 36%);
  font-weight: 500;
}

.dark .number {
  color: hsl(35 99% 46%);
}

.attr-value {
  color: hsl(142 76% 36%);
  font-weight: 400;
}

.dark .attr-value {
  color: hsl(142 76% 46%);
}

.tag {
  color: hsl(5 74% 59%);
  font-weight: 600;
}

.dark .tag {
  color: hsl(5 74% 69%);
}

.attr-name {
  color: hsl(204 70% 53%);
  font-weight: 500;
}

.dark .attr-name {
  color: hsl(204 70% 63%);
}

.variable {
  color: hsl(266 85% 58%);
  font-weight: 400;
}

.dark .variable {
  color: hsl(266 85% 68%);
}

.operator {
  color: hsl(221 87% 60%);
  font-weight: 500;
}

.dark .operator {
  color: hsl(221 87% 70%);
}

.class-name {
  color: hsl(35 99% 36%);
  font-weight: 600;
}

.dark .class-name {
  color: hsl(35 99% 46%);
}

.property {
  color: hsl(204 70% 53%);
  font-weight: 400;
}

.dark .property {
  color: hsl(204 70% 63%);
}

.regex {
  color: hsl(142 76% 36%);
  font-weight: 400;
  background-color: hsl(142 76% 36% / 0.1);
  padding: 1px 2px;
  border-radius: 2px;
}

.dark .regex {
  color: hsl(142 76% 46%);
  background-color: hsl(142 76% 46% / 0.1);
}

.url {
  color: hsl(204 70% 53%);
  text-decoration: underline;
  text-decoration-color: hsl(204 70% 53% / 0.5);
}

.dark .url {
  color: hsl(204 70% 63%);
  text-decoration-color: hsl(204 70% 63% / 0.5);
}

.important {
  color: hsl(5 74% 59%);
  font-weight: 700;
}

.dark .important {
  color: hsl(5 74% 69%);
}

.deleted {
  color: hsl(5 74% 59%);
  background-color: hsl(5 74% 59% / 0.1);
}

.dark .deleted {
  color: hsl(5 74% 69%);
  background-color: hsl(5 74% 69% / 0.1);
}

.inserted {
  color: hsl(142 76% 36%);
  background-color: hsl(142 76% 36% / 0.1);
}

.dark .inserted {
  color: hsl(142 76% 46%);
  background-color: hsl(142 76% 46% / 0.1);
}

/* Enhanced code title */
.rehype-code-title {
  @apply px-4 py-3 text-sm font-medium tracking-wide rounded-t-xl bg-muted text-muted-foreground;
  font-family: var(--font-code) !important;
  border-bottom: 1px solid hsl(var(--border));
}

.highlight-comp>code {
  background-color: transparent !important;
}

* {
  transition-property: background-color, border-color, color, fill, stroke;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  transition-duration: 150ms;
}

/* Enhanced focus styles */
*:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

::selection {
  background-color: hsl(var(--primary) / 0.2);
}

/* Hide scrollbar utility */
.scrollbar-hide {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.scrollbar-hide::-webkit-scrollbar {
  display: none;
}

/* Mobile-specific optimizations */
@media (max-width: 1023px) {

  /* Improve touch targets */
  button,
  a,
  [role="button"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Better spacing for mobile */
  .prose {
    font-size: 15px;
    line-height: 1.6;
    padding: 0 0.5rem;
    overflow-x: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  /* Prevent horizontal overflow */
  .prose * {
    max-width: 100%;
    box-sizing: border-box;
  }

  .prose h1,
  .prose h2,
  .prose h3,
  .prose h4 {
    margin-top: 1.5em;
    margin-bottom: 0.75em;
    line-height: 1.3;
  }

  .prose h1 {
    font-size: 1.75rem;
  }

  .prose h2 {
    font-size: 1.5rem;
  }

  .prose h3 {
    font-size: 1.25rem;
  }

  .prose p {
    margin-top: 1em;
    margin-bottom: 1em;
  }

  /* Mobile code blocks */
  .prose pre {
    margin: 1.5em -0.5rem;
    border-radius: 0.5rem;
    font-size: 13px;
    overflow-x: auto;
    max-width: calc(100vw - 2rem);
    white-space: pre;
    word-wrap: normal;
  }

  .prose code {
    word-break: break-word;
    overflow-wrap: break-word;
  }

  /* Inline code should break */
  .prose :not(pre)>code {
    white-space: pre-wrap;
    word-break: break-word;
  }

  /* Mobile tables */
  .prose table {
    font-size: 14px;
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .prose td,
  .prose th {
    padding: 8px;
  }

  /* Better mobile images */
  .prose img {
    margin: 1rem -0.5rem;
    width: calc(100% + 1rem);
    max-width: calc(100% + 1rem);
  }
}

/* Tablet optimizations */
@media (min-width: 768px) and (max-width: 1023px) {
  .prose {
    font-size: 16px;
  }

  .prose pre {
    margin: 2em 0;
  }
}

/* Mobile navigation improvements */
@media (max-width: 1023px) {

  /* Ensure mobile nav is accessible */
  [data-radix-scroll-area-viewport] {
    scrollbar-width: thin;
  }

  /* Better mobile sheet content */
  [data-radix-dialog-content] {
    max-height: 90vh;
    overflow-y: auto;
  }

  /* Mobile container improvements */
  .container {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  /* Better mobile button spacing */
  .prose button {
    margin: 0.5rem 0;
  }

  /* Mobile-friendly links */
  .prose a {
    word-break: break-word;
  }

  /* Better mobile list spacing */
  .prose ul,
  .prose ol {
    padding-left: 1.5rem;
  }

  .prose li {
    margin: 0.5rem 0;
  }
}

/* Additional overflow prevention for docs */
.docs-content {
  overflow-x: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.docs-content * {
  max-width: 100%;
  box-sizing: border-box;
}

/* Ensure Preview components don't overflow */
.not-prose {
  overflow-x: auto;
  max-width: 100%;
}

/* Mobile-specific Preview fixes */
@media (max-width: 640px) {
  .not-prose {
    margin-left: -1rem;
    margin-right: -1rem;
    padding-left: 1rem;
    padding-right: 1rem;
  }
}

/* Ensure all content respects viewport bounds */
@media (max-width: 1023px) {
  body {
    overflow-x: hidden;
  }

  main {
    overflow-x: hidden;
    min-width: 0;
  }

  /* Fix for very wide content */
  * {
    max-width: 100vw;
  }

  /* Exception for elements that should be able to scroll */
  pre,
  code,
  .overflow-x-auto,
  [data-radix-scroll-area-viewport] {
    max-width: none;
  }
}