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

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

  html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  body {
    @apply bg-background text-foreground;
    font-family: var(--font-sans);
    font-feature-settings: "rlig" 1, "calt" 1, "ss01" 1;
    font-kerning: normal;
    line-height: var(--leading-normal);
  }

  /* Dark mode: Geist renders well at 400 */
  .dark body {
    font-weight: 400;
  }

  /* OpenType: disable ligatures on monospace/code for readability */
  code,
  pre,
  kbd,
  samp,
  .font-mono {
    font-variant-ligatures: none;
  }

  /* Headings */
  h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-sans);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
    font-weight: 600;
  }

  /* Tabular numbers for data */
  [data-numeric],
  .tabular-nums,
  table td,
  .stat-value {
    font-variant-numeric: tabular-nums;
  }

  /* OpenType: proper fractions for recipe/fraction display */
  .fractions {
    font-variant-numeric: diagonal-fractions;
  }

  /* OpenType: small caps for abbreviations */
  abbr,
  .small-caps {
    font-variant-caps: all-small-caps;
    text-decoration: none;
  }

  /* Prose content max-width */
  .prose-content {
    max-width: var(--prose-max-width);
  }

  /* Blog prose styling */
  .blog-prose h1 {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    color: hsl(var(--foreground));
  }

  .blog-prose h2 {
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.3;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    color: hsl(var(--foreground));
  }

  .blog-prose h3 {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.4;
    margin-top: 1.75rem;
    margin-bottom: 0.5rem;
    color: hsl(var(--foreground));
  }

  .blog-prose p {
    margin-top: 0;
    margin-bottom: 1.25rem;
    line-height: 1.75;
    color: hsl(var(--muted-foreground));
  }

  .blog-prose a {
    color: hsl(var(--foreground));
    text-decoration: underline;
    text-underline-offset: 3px;
    transition: opacity 0.15s;
  }

  .blog-prose a:hover {
    opacity: 0.8;
  }

  .blog-prose ul,
  .blog-prose ol {
    margin-top: 0;
    margin-bottom: 1.25rem;
    padding-left: 1.5rem;
    color: hsl(var(--muted-foreground));
  }

  .blog-prose ul {
    list-style-type: disc;
  }

  .blog-prose ol {
    list-style-type: decimal;
  }

  .blog-prose li {
    margin-bottom: 0.375rem;
    line-height: 1.75;
  }

  .blog-prose strong {
    font-weight: 600;
    color: hsl(var(--foreground));
  }

  .blog-prose code {
    font-size: 0.875em;
    padding: 0.2em 0.4em;
    border-radius: 0.25rem;
    background-color: hsl(var(--muted));
    color: hsl(var(--foreground));
  }

  .blog-prose pre {
    margin-top: 0;
    margin-bottom: 1.25rem;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    background-color: hsl(var(--muted));
  }

  .blog-prose pre code {
    padding: 0;
    background-color: transparent;
  }

  .blog-prose blockquote {
    margin-top: 0;
    margin-bottom: 1.25rem;
    padding-left: 1rem;
    border-left: 3px solid hsl(var(--border));
    color: hsl(var(--muted-foreground));
    font-style: italic;
  }

  .blog-prose hr {
    margin-top: 2rem;
    margin-bottom: 2rem;
    border: none;
    border-top: 1px solid hsl(var(--border));
  }

  /* Selection styling */
  ::selection {
    background-color: hsl(var(--selection-bg));
    color: hsl(var(--selection-fg));
  }

  /* Focus-visible defaults */
  :focus-visible {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 2px;
    border-radius: var(--radius-sm);
  }

  /* Remove focus outline on mouse click */
  :focus:not(:focus-visible) {
    outline: none;
  }

  /* Strip shadows in both themes — Vercel aesthetic uses borders for depth */
  .shadow-sm,
  .shadow,
  .shadow-md {
    box-shadow: none;
  }

  .shadow-lg,
  .shadow-xl {
    box-shadow: none;
  }
}

@layer components {
  /* Skip link — visible only on focus for keyboard users */
  .skip-link {
    position: absolute;
    top: -100%;
    left: 1rem;
    z-index: var(--z-tooltip, 100);
    padding: 0.75rem 1.5rem;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border-radius: var(--radius-lg);
    font-weight: 600;
    font-size: 0.875rem;
    text-decoration: none;
    transition: top 200ms ease-out;
  }

  .skip-link:focus {
    top: 1rem;
  }

  /* Touch target sizing */
  @media (pointer: coarse) {
    .touch-target {
      min-height: 2.75rem; /* 44px */
      min-width: 2.75rem;
      padding: 0.75rem 1.25rem; /* 12px 20px */
    }
  }

  @media (pointer: fine) {
    .touch-target {
      padding: 0.5rem 1rem; /* 8px 16px */
    }
  }

  /* Touch target pseudo-element for icon buttons — expands tap area */
  .icon-btn-touch {
    position: relative;
  }

  .icon-btn-touch::before {
    content: "";
    position: absolute;
    inset: -10px;
  }
}

@layer utilities {
  /* Prefers reduced motion */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }

  /* Hover media query guard — prevent stuck hover on touch devices */
  @media (hover: none) {
    .hover\:-translate-y-0\.5:hover,
    .hover\:-translate-y-1:hover {
      transform: none !important;
    }

    .hover\:shadow-lg:hover,
    .hover\:shadow-xl:hover {
      box-shadow: inherit !important;
    }

  }

  /* Safe-area insets for notched devices */
  .safe-area-padding {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Scrollbar styling */
  .scrollbar-thin {
    scrollbar-width: thin;
    scrollbar-color: hsl(var(--border)) transparent;
  }

  .scrollbar-thin::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }

  .scrollbar-thin::-webkit-scrollbar-track {
    background: transparent;
  }

  .scrollbar-thin::-webkit-scrollbar-thumb {
    background-color: hsl(var(--border));
    border-radius: var(--radius-full);
  }

  .scrollbar-thin::-webkit-scrollbar-thumb:hover {
    background-color: hsl(var(--muted-foreground) / 0.4);
  }

  /* Auto-fit responsive grid */
  .grid-auto-fill {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }

  /* Responsive table-to-cards for mobile */
  @media (max-width: 640px) {
    .responsive-table table,
    .responsive-table thead,
    .responsive-table tbody,
    .responsive-table tr,
    .responsive-table th,
    .responsive-table td {
      display: block;
    }

    .responsive-table thead {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0, 0, 0, 0);
      white-space: nowrap;
      border-width: 0;
    }

    .responsive-table tr {
      padding: 1rem;
      margin-bottom: 0.75rem;
      border: 1px solid hsl(var(--border));
      border-radius: var(--radius-lg);
      background: hsl(var(--card));
    }

    .responsive-table td {
      padding: 0.25rem 0;
      border: none;
      text-align: left;
    }

    .responsive-table td::before {
      content: attr(data-label);
      display: block;
      font-size: 0.75rem;
      font-weight: 500;
      color: hsl(var(--muted-foreground));
      margin-bottom: 0.125rem;
    }
  }
}
