/* ===================== OPTIMIZED GLOBAL THEME ===================== */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500&family=Major+Mono+Display&family=Noto+Sans+JP:wght@300;400;500&family=VT323&display=swap');

@layer theme, tailwind-base, tailwind-utilities;

@import "tailwindcss/theme.css" layer(theme);
@import "tailwindcss/preflight.css" layer(tailwind-base);
@import "tailwindcss/utilities.css" layer(tailwind-utilities);

@layer theme {
  :root {
    /* Font variables */
    --font-terminal: 'JetBrains Mono', monospace;
    --font-terminal-retro: 'VT323', monospace;
    --font-terminal-nier: 'Major Mono Display', monospace;
    --font-noto-jp: 'Noto Sans JP', sans-serif;

    /* NieR Automata UI colors */
    --color-nier-bg: #dcd8c0;
    --color-nier-dark: #5a5a50;
    --color-nier-mid: #adaba0;
    --color-nier-text-dark: #292925;
    --color-nier-text-light: #dcd8c0;
    --color-nier-border: #a39e8c;
    --color-nier-grid: #bfbcad;
    --color-nier-accent: #292925;
    --color-nier-highlight: #5a5a50;
    --color-nier-checkered-bg: #d1cdb7;
    --color-nier-checkered-grid: #ccc8b1;
  }

  /* Dark mode variables */
  @media (prefers-color-scheme: dark) {
    :root {
      --color-nier-bg: #292925;
      --color-nier-dark: #adaba0;
      --color-nier-mid: #5a5a50;
      --color-nier-text-dark: #dcd8c0;
      --color-nier-text-light: #292925;
      --color-nier-border: #5a5a50;
      --color-nier-grid: #3f3e39;
      --color-nier-accent: #dcd8c0;
      --color-nier-highlight: #adaba0;
      --color-nier-checkered-bg: #121210;
      --color-nier-checkered-grid: #323232;
    }
  }

  /* Manual theme classes */
  .dark {
    --color-nier-bg: #292925;
    --color-nier-dark: #adaba0;
    --color-nier-mid: #5a5a50;
    --color-nier-text-dark: #dcd8c0;
    --color-nier-text-light: #292925;
    --color-nier-border: #5a5a50;
    --color-nier-grid: #3f3e39;
    --color-nier-accent: #dcd8c0;
    --color-nier-highlight: #adaba0;
    --color-nier-checkered-bg: #121210;
    --color-nier-checkered-grid: #323232;
  }

  .light {
    --color-nier-bg: #dcd8c0;
    --color-nier-dark: #5a5a50;
    --color-nier-mid: #adaba0;
    --color-nier-text-dark: #292925;
    --color-nier-text-light: #dcd8c0;
    --color-nier-border: #a39e8c;
    --color-nier-grid: #bfbcad;
    --color-nier-accent: #292925;
    --color-nier-highlight: #5a5a50;
    --color-nier-checkered-bg: #d1cdb7;
    --color-nier-checkered-grid: #ccc8b1;
  }
}

@layer tailwind-utilities {
  /* Font utilities */
  .font-terminal { font-family: var(--font-terminal); }
  .font-terminal-retro { font-family: var(--font-terminal-retro); }
  .font-terminal-nier { font-family: var(--font-terminal-nier); }
  .font-noto-jp {
    font-family: var(--font-noto-jp);
    letter-spacing: -0.02em;
  }

  /* Background utilities */
  .bg-nier-bg { background-color: var(--color-nier-bg); }
  .bg-nier-dark { background-color: var(--color-nier-dark); }
  .bg-nier-mid { background-color: var(--color-nier-mid); }

  /* Text utilities */
  .text-nier-dark { color: var(--color-nier-text-dark); }
  .text-nier-light { color: var(--color-nier-text-light); }

  /* Border utilities */
  .border-nier-border { border-color: var(--color-nier-border); }
  .border-nier-accent { border-color: var(--color-nier-accent); }

  /* Pattern utilities */
  .checkered-background {
    background-color: var(--color-nier-checkered-bg);
    background-size: 0.3rem 0.3rem;
    background-image:
      linear-gradient(to right, var(--color-nier-checkered-grid) 1px, transparent 1px),
      linear-gradient(to bottom, var(--color-nier-checkered-grid) 1px, transparent 1px);
    color: var(--color-nier-text-dark);
    transition: all 0.3s ease;
  }

  .nier-grid {
    display: grid;
    background-color: var(--color-nier-bg);
    background-size: 2rem 2rem;
    background-image:
      linear-gradient(to right, var(--color-nier-grid) 1px, transparent 1px),
      linear-gradient(to bottom, var(--color-nier-grid) 1px, transparent 1px);
    border: 1px solid var(--color-nier-border);
    transition: all 0.3s ease;
  }

  /* ===================== NIER CUSTOM SCROLLBAR ===================== */

  /* Global scrollbar for all elements */
  * {
    scrollbar-width: thin;
    scrollbar-color: var(--color-nier-accent) var(--color-nier-border);
  }

  /* WebKit browsers (Chrome, Safari, Edge) */
  ::-webkit-scrollbar {
    width: 12px;
    height: 12px;
  }

  ::-webkit-scrollbar-track {
    background: var(--color-nier-bg);
    border: 1px solid var(--color-nier-border);
    border-radius: 2px;
  }

  ::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--color-nier-accent) 0%, var(--color-nier-highlight) 100%);
    border: 1px solid var(--color-nier-border);
    border-radius: 1px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  ::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, var(--color-nier-highlight) 0%, var(--color-nier-accent) 100%);
    transform: scale(1.1);
  }

  ::-webkit-scrollbar-thumb:active {
    background: var(--color-nier-dark);
    transform: scale(0.95);
  }

  ::-webkit-scrollbar-corner {
    background: var(--color-nier-bg);
    border: 1px solid var(--color-nier-border);
  }

  /* Body scrollbar (main page scroll) */
  body::-webkit-scrollbar {
    width: 14px;
  }

  body::-webkit-scrollbar-track {
    background: var(--color-nier-checkered-bg);
    background-size: 8px 8px;
    background-image:
      linear-gradient(to right, var(--color-nier-checkered-grid) 1px, transparent 1px),
      linear-gradient(to bottom, var(--color-nier-checkered-grid) 1px, transparent 1px);
    border: 2px solid var(--color-nier-border);
  }

  /* Code blocks and pre elements */
  pre::-webkit-scrollbar,
  code::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

  pre::-webkit-scrollbar-track,
  code::-webkit-scrollbar-track {
    background: var(--color-nier-dark);
    border: 1px solid var(--color-nier-accent);
  }

  pre::-webkit-scrollbar-thumb,
  code::-webkit-scrollbar-thumb {
    background: var(--color-nier-accent);
    border: none;
  }

  /* Tables */
  table::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }

  /* Modal and overlay scrollbars */
  .modal::-webkit-scrollbar,
  .overlay::-webkit-scrollbar,
  .dialog::-webkit-scrollbar,
  [role="dialog"]::-webkit-scrollbar {
    width: 8px;
  }

  .modal::-webkit-scrollbar-track,
  .overlay::-webkit-scrollbar-track,
  .dialog::-webkit-scrollbar-track,
  [role="dialog"]::-webkit-scrollbar-track {
    background: var(--color-nier-mid);
    border: 1px solid var(--color-nier-border);
  }

  /* Responsive adjustments */
  @media (max-width: 768px) {
    ::-webkit-scrollbar {
      width: 8px;
      height: 8px;
    }

    body::-webkit-scrollbar {
      width: 10px;
    }

    ::-webkit-scrollbar-thumb {
      border-radius: 4px;
    }
  }

  /* High contrast mode support */
  @media (prefers-contrast: high) {
    ::-webkit-scrollbar-thumb {
      background: var(--color-nier-text-dark);
      border: 2px solid var(--color-nier-accent);
    }

    ::-webkit-scrollbar-track {
      background: var(--color-nier-bg);
      border: 2px solid var(--color-nier-border);
    }
  }

  /* Reduced motion support */
  @media (prefers-reduced-motion: reduce) {
    ::-webkit-scrollbar-thumb {
      transition: none;
      transform: none;
    }

    ::-webkit-scrollbar-thumb:hover,
    ::-webkit-scrollbar-thumb:active {
      transform: none;
    }
  }

  /* Special scrollbar for checkered backgrounds */
  .checkered-bg::-webkit-scrollbar-track,
  .checkered-background::-webkit-scrollbar-track {
    background: var(--color-nier-checkered-bg);
    background-size: 6px 6px;
    background-image:
      linear-gradient(to right, var(--color-nier-checkered-grid) 1px, transparent 1px),
      linear-gradient(to bottom, var(--color-nier-checkered-grid) 1px, transparent 1px);
  }

  /* NieR UI specific scrollbars */
  .nier-panel::-webkit-scrollbar,
  .nier-menu::-webkit-scrollbar {
    width: 10px;
  }

  .nier-panel::-webkit-scrollbar-track,
  .nier-menu::-webkit-scrollbar-track {
    background: var(--color-nier-bg);
    border: 2px inset var(--color-nier-border);
  }

  .nier-panel::-webkit-scrollbar-thumb,
  .nier-menu::-webkit-scrollbar-thumb {
    background: var(--color-nier-accent);
    border: 1px outset var(--color-nier-highlight);
    border-radius: 0;
  }
}
