// ============================================================================
// Global Styles — Grackle Web UI
// ============================================================================
// Reset, base styles, scrollbars, keyframe animations, and accessibility
// overrides. Imported once in main.tsx; theme tokens come from theme.scss.
// ============================================================================

@use './theme.scss';
@use './prism-theme.scss';
@import url('https://cdn.jsdelivr.net/npm/firacode@6.2.0/distr/fira_code.css');
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;700;800&display=swap');
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,700;1,9..40,400&display=swap');

// =============================================================================
// Suppress transitions during theme changes (T3 pattern)
// =============================================================================

.no-transitions,
.no-transitions *,
.no-transitions *::before,
.no-transitions *::after {
  transition-duration: 0s !important;
  animation-duration: 0s !important;
}

// =============================================================================
// Reset
// =============================================================================

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body,
#root {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-regular);
  line-height: var(--line-height);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

// Subtle noise texture overlay (T3-inspired tactile feel)
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: var(--noise-opacity);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  z-index: 99999;
}

// =============================================================================
// Selection
// =============================================================================

::selection {
  background: var(--accent-green-selection);
  color: var(--text-primary);
}

// =============================================================================
// Scrollbars
// =============================================================================

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

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

::-webkit-scrollbar-thumb {
  background: var(--text-disabled);
  border-radius: var(--radius-full);

  &:hover {
    background: var(--text-tertiary);
  }
}

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

// =============================================================================
// Focus Ring (Accessibility)
// =============================================================================

:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

// Enable OpenType ligatures and contextual alternates globally
:root {
  font-feature-settings: 'liga' 1, 'calt' 1;
}

// =============================================================================
// Keyframe Animations
// =============================================================================

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

// =============================================================================
// Matrix — CRT scanline overlay + text glow
// =============================================================================

[data-theme="matrix"] {
  // Tunable scanline intensity — defaults to atmospheric, override via DevTools
  --matrix-scanline-opacity: 0.04;

  // Override the noise overlay with CRT scanlines
  body::after {
    opacity: var(--matrix-scanline-opacity);
    background-image: repeating-linear-gradient(
      0deg,
      rgba(0, 255, 65, 0.06) 0px,
      rgba(0, 255, 65, 0.06) 1px,
      transparent 1px,
      transparent 3px
    );
    background-size: 100% 3px;
  }

  // CRT text glow — subtle green halo
  body {
    text-shadow: 0 0 2px rgba(0, 255, 65, 0.12);
  }

  // Suppress glow on focused text inputs for readability
  input:focus,
  textarea:focus,
  [contenteditable="true"]:focus {
    text-shadow: none;
  }
}

// =============================================================================
// Accessibility: High Contrast
// =============================================================================
// Increase border visibility and text contrast for high-contrast mode.

@media (prefers-contrast: more) {
  [data-theme="grackle-light"],
  [data-theme="brutalist-light"],
  [data-theme="monokai-light"] {
    --text-secondary: #4b5563;
    --text-tertiary: #6b7280;
    --text-disabled: #9ca3af;
    --border-subtle: rgba(0, 0, 0, 0.20);
    --border-input: rgba(0, 0, 0, 0.30);
  }

  [data-theme="grackle-dark"],
  [data-theme="glass"],
  [data-theme="matrix"],
  [data-theme="monokai-dark"],
  [data-theme="brutalist-dark"],
  [data-theme="ubuntu"],
  [data-theme="sandstone"],
  [data-theme="verdigris"],
  [data-theme="primer"] {
    --text-secondary: #d1d5db;
    --text-tertiary: #9ca3af;
    --text-disabled: #6b7280;
    --border-subtle: rgba(255, 255, 255, 0.15);
    --border-input: rgba(255, 255, 255, 0.25);
  }
}

// =============================================================================
// Accessibility: Reduced Motion
// =============================================================================

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
