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

/* Ensure all elements use border-box */
*, *::before, *::after {
  box-sizing: border-box;
}

/* Prevent horizontal overflow on mobile */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* Blog content overflow protection */
.blog-content,
.lexxy-content {
  overflow-x: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

/* Ensure all child elements respect container width */
.blog-content *,
.lexxy-content * {
  max-width: 100%;
  box-sizing: border-box;
}

/* Code blocks should scroll horizontally within their container */
.blog-content pre,
.lexxy-content pre {
  overflow-x: auto;
  white-space: pre;
}

/* Images and media should not overflow */
.blog-content img,
.blog-content video,
.blog-content iframe,
.lexxy-content img,
.lexxy-content video,
.lexxy-content iframe {
  max-width: 100%;
  height: auto;
}

/* Tables should scroll horizontally if too wide */
.blog-content table,
.lexxy-content table {
  display: block;
  overflow-x: auto;
  max-width: 100%;
}

/* CSS Variables for gradient colors */
:root {
  --accent-primary: #80cbc4;
  --accent-secondary: #a5d6a7;
}

/* Enable text selection - strengthened rules with higher specificity */
@layer base {
  html, body, div, span, p, h1, h2, h3, h4, h5, h6,
  ul, ol, li, article, aside, details, figcaption, figure,
  footer, header, main, nav, section, summary {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
    -webkit-user-drag: auto !important;
  }

  *:not([data-no-select]) {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
  }

  /* Allow links and interactive elements to have pointer cursor */
  a, button, [role="button"], .cursor-pointer {
    cursor: pointer !important;
  }
}

/* Mobile Menu Styles */
@layer components {
  /* Mobile menu transitions */
  [data-mobile-menu-target="menu"] {
    transition: opacity 0.3s ease;
    opacity: 0;
    pointer-events: none;
  }

  [data-mobile-menu-target="menu"]:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
  }

  /* Mobile menu items */
  [data-mobile-menu-target="menu"] a {
    position: relative;
    display: block;
    width: 100%;
  }

  [data-mobile-menu-target="menu"] a:after {
    content: '';
    position: absolute;
    left: 0;
    bottom: -1px;
    width: 0;
    height: 2px;
    background-color: #80cbc4;
    transition: width 0.3s ease;
  }

  [data-mobile-menu-target="menu"] a:hover:after {
    width: 100%;
  }

  /* Menu icon transitions */
  [data-mobile-menu-target="openIcon"],
  [data-mobile-menu-target="closeIcon"] {
    transition: opacity 0.2s ease;
  }
}

@layer components {
  .terminal-bg {
    @apply bg-[#eef2f7] border border-slate-200 shadow-sm;
  }

  .terminal-header {
    @apply px-3 pt-2 flex items-center border-b border-slate-200;
  }

  .btn-primary {
    @apply bg-[#80cbc4] hover:bg-[#a5d6a7] text-gray-700 transition-colors;
  }

  .console-text {
    @apply text-green-400;
  }

  .card-hover {
    @apply transition-all duration-300 ease-in-out hover:shadow-lg hover:-translate-y-1 hover:scale-[1.02];
  }
}

.gradient-text {
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  user-select: text !important;
  -webkit-user-select: text !important;
  cursor: text;
  display: inline-block;
  position: relative;
}

/* Enhanced button hover effects */
@layer components {
  .btn-cta-primary {
    @apply relative overflow-hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .btn-cta-primary:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 20px 40px rgba(128, 203, 196, 0.4);
  }
  
  .btn-cta-primary:active {
    transform: translateY(-2px) scale(1.02);
  }
}

/* Raw Markdown styling for blog - like viewing a .md file */
/* Inspired by Tailwind Typography prose-xl with custom markdown aesthetics */
@layer components {
  .markdown-raw {
    font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f8fafc;
    background-image:
      linear-gradient(rgba(0, 0, 0, 0.02) 1px, transparent 1px),
      linear-gradient(90deg, rgba(0, 0, 0, 0.02) 1px, transparent 1px);
    background-size: 24px 24px;
    color: #1e293b;
    line-height: 1.8;
    font-size: 1.25rem; /* 20px - matches prose-xl */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  /* Headings */
  .markdown-raw h1,
  .markdown-raw h2,
  .markdown-raw h3,
  .markdown-raw h4,
  .markdown-raw h5,
  .markdown-raw h6 {
    font-weight: 800;
    margin-top: 2em;
    margin-bottom: 0.8em;
    color: #0f172a;
    line-height: 1.25;
    letter-spacing: -0.025em;
  }

  .markdown-raw h1 { font-size: 2.5rem; margin-top: 0; }
  .markdown-raw h2 { font-size: 1.875rem; }
  .markdown-raw h3 { font-size: 1.5rem; }
  .markdown-raw h4 { font-size: 1.25rem; }

  /* Prepend markdown symbols to headings */
  .markdown-raw h1::before {
    content: "# ";
    color: #80cbc4;
    font-weight: 800;
  }

  .markdown-raw h2::before {
    content: "## ";
    color: #80cbc4;
    font-weight: 800;
  }

  .markdown-raw h3::before {
    content: "### ";
    color: #80cbc4;
    font-weight: 800;
  }

  .markdown-raw h4::before {
    content: "#### ";
    color: #80cbc4;
    font-weight: 800;
  }

  /* Paragraphs */
  .markdown-raw p {
    margin-top: 1.25em;
    margin-bottom: 1.25em;
    line-height: 1.8;
    color: #334155;
  }

  /* First paragraph after heading - no top margin */
  .markdown-raw h1 + p,
  .markdown-raw h2 + p,
  .markdown-raw h3 + p,
  .markdown-raw h4 + p {
    margin-top: 0.75em;
  }

  /* Links - use accent color */
  .markdown-raw a {
    color: #0d9488;
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
    transition: color 0.15s ease, text-decoration-color 0.15s ease;
  }

  .markdown-raw a:hover {
    color: #0f766e;
    text-decoration-color: #0f766e;
  }

  /* Lists */
  .markdown-raw ul,
  .markdown-raw ol {
    margin: 1.25em 0;
    padding-left: 1.75rem;
  }

  .markdown-raw ul {
    list-style-type: disc;
  }

  .markdown-raw ol {
    list-style-type: decimal;
  }

  .markdown-raw li {
    margin-top: 0.5em;
    margin-bottom: 0.5em;
    padding-left: 0.375em;
    line-height: 1.75;
  }

  .markdown-raw li::marker {
    color: #64748b;
  }

  /* Nested lists */
  .markdown-raw li > ul,
  .markdown-raw li > ol {
    margin-top: 0.5em;
    margin-bottom: 0.5em;
  }

  /* Blockquotes */
  .markdown-raw blockquote {
    border-left: 4px solid #80cbc4;
    padding-left: 1.5rem;
    margin: 1.5em 0;
    color: #475569;
    font-style: italic;
    background-color: rgba(128, 203, 196, 0.05);
    padding: 1rem 1.5rem;
    border-radius: 0 0.5rem 0.5rem 0;
  }

  .markdown-raw blockquote p {
    margin: 0.5em 0;
  }

  /* Horizontal rules */
  .markdown-raw hr {
    border: none;
    border-top: 2px solid #e2e8f0;
    margin: 2.5em 0;
  }

  /* Inline code - looks like `code` */
  .markdown-raw code:not(pre code) {
    background-color: #f1f5f9;
    color: #be185d;
    padding: 0.2em 0.4em;
    border-radius: 0.375rem;
    font-family: 'Fira Code', ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.875em;
    font-weight: 500;
  }

  /* Code blocks - dark theme */
  .markdown-raw pre {
    background-color: #1e293b;
    color: #e2e8f0;
    padding: 1.25rem 1.5rem;
    overflow-x: auto;
    margin: 1.75em 0;
    border-radius: 0.75rem;
    line-height: 1.6;
    border: 1px solid #334155;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  }

  .markdown-raw pre code {
    background: none !important;
    padding: 0 !important;
    font-family: 'Fira Code', ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.875rem;
    color: #e2e8f0;
    display: block;
    white-space: pre;
  }

/* Code block copy button */
.code-block-wrapper {
  position: relative;
}

.copy-code-button {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  background-color: rgba(51, 65, 85, 0.8);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 0.375rem;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
  z-index: 10;
}

.copy-code-button:hover {
  background-color: rgba(71, 85, 105, 0.9);
  color: #e2e8f0;
  border-color: rgba(148, 163, 184, 0.5);
}

.copy-code-button.copied {
  background-color: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  border-color: rgba(34, 197, 94, 0.4);
}

.copy-code-button svg {
  width: 0.875rem;
  height: 0.875rem;
  flex-shrink: 0;
}

  /* Images */
  .markdown-raw img {
    max-width: 100%;
    height: auto;
    margin: 2em 0;
    border-radius: 0.75rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  }

  /* Tables */
  .markdown-raw table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.75em 0;
    font-size: 0.95em;
  }

  .markdown-raw th,
  .markdown-raw td {
    border: 1px solid #e2e8f0;
    padding: 0.875rem 1rem;
    text-align: left;
  }

  .markdown-raw th {
    background-color: #f8fafc;
    color: #1e293b;
    font-weight: 600;
  }

  .markdown-raw tr:nth-child(even) {
    background-color: #f8fafc;
  }

  /* Strong/Bold */
  .markdown-raw strong {
    font-weight: 700;
    color: #0f172a;
  }

  /* Emphasis/Italic */
  .markdown-raw em {
    font-style: italic;
  }

  /* Override for elements inside white containers */
  .markdown-raw .bg-white h1::before,
  .markdown-raw .bg-white h2::before,
  .markdown-raw .bg-white h3::before,
  .markdown-raw .bg-white h4::before {
    color: #80cbc4;
  }

  /* Disable hash prefixes for specific sections */
  .markdown-raw .no-hash-prefix h1::before,
  .markdown-raw .no-hash-prefix h2::before,
  .markdown-raw .no-hash-prefix h3::before,
  .markdown-raw .no-hash-prefix h4::before,
  .markdown-raw .no-hash-prefix h5::before,
  .markdown-raw .no-hash-prefix h6::before {
    content: none !important;
  }

  /* Also disable for dark CTA sections (text-white parent) */
  .markdown-raw [class*="text-white"] h1::before,
  .markdown-raw [class*="text-white"] h2::before,
  .markdown-raw [class*="text-white"] h3::before,
  .markdown-raw [class*="text-white"] h4::before {
    content: none !important;
  }

  /* Fix heading colors in dark sections */
  .markdown-raw [class*="from-gray-900"] h3,
  .markdown-raw [class*="bg-gradient"] h3 {
    color: white;
    margin-top: 0;
  }

  /* Ensure lexxy-content inherits markdown-raw styling properly */
  .markdown-raw .lexxy-content {
    line-height: inherit;
    font-size: inherit;
    color: inherit;
  }
}

