/**
 * Global styles for Styloma UI
 *
 * Contains:
 * - CSS custom properties (design tokens)
 * - CSS reset/normalization
 * - Utility classes (.sr-only, .is-offline, loading states)
 * - Animation keyframes (fadeIn, slideIn, pulse)
 * - Focus-visible styles for keyboard navigation
 */

/* ===== CSS Custom Properties (Design Tokens) ===== */

:root {
  /* Brand Colors - Light Mode */
  --color-primary: #6d435a;
  --color-primary-light: #8b5a7a;
  --color-primary-dark: #4d2f40;
  --color-primary-button: #7A5E6B;
  --color-primary-button-hover: #6D435A;
  --color-secondary: #8b5a7a;
  --color-secondary-light: #a77b96;
  --color-secondary-dark: #6d435a;

  /* Background Colors */
  --color-bg-default: #f8f7f4;
  --color-bg-paper: #ffffff;
  --color-bg-item: #fcfcfc;
  --color-bg-accent-subtle: #F2EFF0;
  --color-bg-control: #F5F2EF;

  /* Text Colors */
  --color-text-primary: #333333;
  --color-text-secondary: #6F6F6F;
  --color-text-tertiary: #727272;
  --color-text-muted: #6b7280;
  --color-text-medium: #525252;
  --color-text-button: #374151;
  --color-text-disabled: #727272;

  /* Semantic Colors */
  --color-error: #DF4759;
  --color-error-light: #ef5350;
  --color-error-dark: #C73545;
  --color-success: #388e3c;
  --color-success-light: #66bb6a;
  --color-warning: #f57c00;
  --color-warning-light: #ffa726;
  --color-info: #1976d2;
  --color-info-light: #42a5f5;

  /* Accent Variants */
  --color-accent-soft: rgba(109, 67, 90, 0.12);
  --color-accent-muted: rgba(109, 67, 90, 0.6);

  /* Interactive State Colors */
  --color-hover-subtle: rgba(0, 0, 0, 0.04);
  --color-hover-subtle-light: rgba(0, 0, 0, 0.02);
  --color-accent-hover: rgba(122, 94, 107, 0.08);
  --color-action-overlay: rgba(255, 255, 255, 0.9);
  --color-action-overlay-hover: rgba(255, 255, 255, 1);
  --color-primary-bright: #6d435a;

  /* Border and Utility Colors */
  --color-border-subtle: #e0d9d4;
  --color-border-light: #EFEFEF;
  --color-border-medium: #CDCDCD;
  --color-border-input: #e5e7eb;
  --color-light-gray: #e5e5e5;

  /* Special/Accent Colors */
  --color-accent-number: #988C8A;
  --color-icon-light: #AAA8AF;

  /* Typography */
  --font-family-serif: 'Playfair Display', Georgia, serif;
  --font-family-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
    Roboto, 'Helvetica Neue', Arial, sans-serif;

  /* Font Sizes */
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base-sm: 0.9375rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 2rem;
  --font-size-4xl: 2.5rem;
  --font-size-display-sm: 6rem;
  --font-size-display-lg: 8rem;

  /* Font Weights */
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Line Heights */
  --line-height-tight: 1.2;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.7;

  /* Spacing (8px grid) */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  --spacing-2xl: 48px;
  --spacing-3xl: 64px;
  --spacing-4xl: 80px;

  /* Mobile Touch Targets */
  --touch-target-min: 44px;
  /* Note: 48px nav items use existing --spacing-2xl */
  --mobile-header-height: 56px;
  --bottom-nav-height: 56px;

  /* Mobile Typography */
  --mobile-body-min: 16px;

  /* Mobile Spacing */
  --mobile-edge-padding: 16px;
  --mobile-safe-area-top: env(safe-area-inset-top, 0px);
  --mobile-safe-area-bottom: env(safe-area-inset-bottom, 0px);

  /* Mobile Bottom Sheet */
  --mobile-sheet-min-height: 60vh;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-button: 6px;
  --radius-button-lg: 10px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Shadows */
  --shadow-sm: 0 2px 4px rgba(109, 67, 90, 0.1);
  --shadow-md: 0 8px 20px rgba(109, 67, 90, 0.15);
  --shadow-lg: 0 18px 38px rgba(109, 67, 90, 0.16);
  --shadow-card: 0 24px 48px rgba(0, 0, 0, 0.06);

  /* Transitions */
  --transition-fast: 150ms;
  --transition-normal: 250ms;
  --transition-slow: 500ms;
  --transition-easing: ease-in-out;
}

/* Dark Mode Variables - Explicit User Selection */
:root[data-theme="dark"] {
  /* Brand Colors - Dark Mode */
  --color-primary: #8B5B77;
  --color-primary-light: #A57590;
  --color-primary-dark: #724B62;
  --color-primary-button: #8B5B77;
  --color-primary-button-hover: #976381;
  --color-secondary: #845873;
  --color-secondary-light: #90607D;
  --color-secondary-dark: #6B475D;

  /* Background Colors */
  --color-bg-default: #1a1a1a;
  --color-bg-paper: #242424;
  --color-bg-item: #2a2a2a;
  --color-bg-accent-subtle: #2d2a2b;
  --color-bg-control: #2A2A2A;

  /* Text Colors */
  --color-text-primary: #e8e8e8;
  --color-text-secondary: #b8b8b8;
  --color-text-tertiary: #9a9a9a;
  --color-text-muted: #8a8a8a;
  --color-text-medium: #a0a0a0;
  --color-text-button: #d4d4d4;
  --color-text-disabled: #707070;

  /* Semantic Colors (adjusted for dark mode) */
  --color-error: #ef5350;
  --color-error-light: #f77774;
  --color-error-dark: #e53935;
  --color-success: #66bb6a;
  --color-warning: #ffa726;
  --color-info: #42a5f5;

  /* Shadows (darker for dark mode) */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 18px 38px rgba(0, 0, 0, 0.5);
  --shadow-card: 0 24px 48px rgba(0, 0, 0, 0.3);

  /* Accent Variants */
  --color-accent-soft: rgba(167, 123, 150, 0.15);
  --color-accent-muted: rgba(167, 123, 150, 0.7);

  /* Interactive State Colors */
  --color-hover-subtle: rgba(255, 255, 255, 0.08);
  --color-hover-subtle-light: rgba(255, 255, 255, 0.05);
  --color-accent-hover: rgba(167, 123, 150, 0.15);
  --color-action-overlay: rgba(0, 0, 0, 0.7);
  --color-action-overlay-hover: rgba(0, 0, 0, 0.85);
  --color-primary-bright: #d4afbf;

  /* Border and Utility Colors */
  --color-border-subtle: #3a3a3a;
  --color-border-light: #404040;
  --color-border-medium: #4a4a4a;
  --color-border-input: #505050;
  --color-light-gray: #505050;

  /* Special/Accent Colors */
  --color-accent-number: #8a8080;
  --color-icon-light: #7a767c;
}

/* Dark Mode Utility Class Overrides */

/* Skeleton loader - dark mode explicit selection */
:root[data-theme="dark"] .skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.06) 25%,
    rgba(255, 255, 255, 0.12) 37%,
    rgba(255, 255, 255, 0.06) 63%
  );
}

/* Skeleton loader - dark mode auto (system preference) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .skeleton {
    background: linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.06) 25%,
      rgba(255, 255, 255, 0.12) 37%,
      rgba(255, 255, 255, 0.06) 63%
    );
  }
}

/* Pulse animation - dark mode explicit selection */
:root[data-theme="dark"] .pulse {
  animation: pulse-dark 1.5s ease-in-out infinite;
}

/* Pulse animation - dark mode auto (system preference) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pulse {
    animation: pulse-dark 1.5s ease-in-out infinite;
  }
}

@keyframes pulse-dark {
  0%,
  100% {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(167, 123, 150, 0);
  }
  50% {
    opacity: 0.85;
    box-shadow: 0 0 20px 4px rgba(167, 123, 150, 0.4);
  }
}

/* ===== CSS Reset/Normalization ===== */

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

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

body {
  font-family: var(--font-family-sans);
  color: var(--color-text-primary);
  background-color: var(--color-bg-default);
}

/* Remove default button styles */
button {
  border: none;
  background: none;
  font: inherit;
  cursor: pointer;
}

/* Remove default list styles */
ul,
ol {
  list-style: none;
}

/* Remove default anchor styles */
a {
  text-decoration: none;
  color: inherit;
}

/* Remove default input styles */
input,
textarea,
select {
  font: inherit;
}

/* Placeholder text - ensure WCAG AA contrast (5.02:1 on white) */
::placeholder {
  color: var(--color-text-secondary);
  opacity: 1; /* Firefox sets opacity < 1 by default */
}

/* ===== Utility Classes ===== */

/* Screen reader only - visually hidden but accessible to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Offline indicator */
.is-offline {
  filter: grayscale(50%);
  opacity: 0.7;
}

.is-offline::after {
  content: '';
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: repeating-linear-gradient(
    45deg,
    var(--color-warning),
    var(--color-warning) 10px,
    var(--color-warning-light) 10px,
    var(--color-warning-light) 20px
  );
  z-index: 9999;
  animation: offline-slide 1s linear infinite;
}

@keyframes offline-slide {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 28px 0;
  }
}

/* Loading states */
.loading {
  position: relative;
  pointer-events: none;
  opacity: 0.6;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--color-primary);
  border-radius: 50%;
  border-top-color: transparent;
  animation: spinner 0.8s linear infinite;
}

@keyframes spinner {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.skeleton {
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.06) 25%,
    rgba(0, 0, 0, 0.15) 37%,
    rgba(0, 0, 0, 0.06) 63%
  );
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
}

@keyframes skeleton-loading {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

/* ===== Animation Keyframes ===== */

/* Fade in animation */
.fade-in {
  animation: fadeIn var(--transition-normal) ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Slide in from bottom */
.slide-in {
  animation: slideIn var(--transition-normal) ease-out;
}

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

/* Pulse animation for auto-filters (1.5s glow fade in/out) */
.pulse {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(109, 67, 90, 0);
  }
  50% {
    opacity: 0.85;
    box-shadow: 0 0 20px 4px rgba(109, 67, 90, 0.4);
  }
}

/* Scale in animation */
.scale-in {
  animation: scaleIn 0.2s ease-out;
}

@keyframes scaleIn {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* Confetti animation for celebration modals */
@keyframes confetti-fall {
  0% {
    transform: translateY(-100%) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

@keyframes confetti-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(15px);
  }
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -10px;
  animation:
    confetti-fall 2s ease-out forwards,
    confetti-shake 0.5s ease-in-out infinite;
}

/* ===== Reduced Motion Support ===== */

/**
 * Respect user's motion preferences
 * Disables animations for users who prefer 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;
  }

  /* Remove pulse animation */
  .pulse {
    animation: none;
    box-shadow: none;
  }

  /* Disable skeleton loading animation */
  .skeleton {
    animation: none;
    background: rgba(0, 0, 0, 0.06);
  }

  /* Disable loading spinner animation */
  .loading::after {
    animation: none;
    border: 2px solid var(--color-primary);
  }

  /* Disable confetti animation */
  .confetti-piece {
    animation: none;
    display: none;
  }

  /* Disable offline indicator animation */
  .is-offline::after {
    animation: none;
  }
}

/* ===== Focus Styles for Keyboard Navigation ===== */

/* Enhanced focus-visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

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

/* Skip to main content link */
.skip-to-main {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--color-primary);
  color: white;
  padding: var(--spacing-sm) var(--spacing-md);
  text-decoration: none;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 10000;
  transition: top var(--transition-fast);
}

.skip-to-main:focus {
  top: 0;
  outline: 2px solid var(--color-primary-light);
  outline-offset: 2px;
}

/* ===== Responsive Helpers ===== */

.mobile-only {
  display: block;
}

.desktop-only {
  display: none;
}

@media (min-width: 960px) {
  .mobile-only {
    display: none;
  }

  .desktop-only {
    display: block;
  }
}

/* ===== Scrollbar Styling ===== */

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

::-webkit-scrollbar-track {
  background: var(--color-bg-default);
}

::-webkit-scrollbar-thumb {
  background: var(--color-primary);
  border-radius: 5px;
}

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

/* ===== Item Selection Overlay ===== */

/* Highlight bounding box when voronoi cell is hovered or focused */
.item-selection-overlay-voronoi-cell:hover + .item-selection-overlay-bounding-box,
.item-selection-overlay-voronoi-cell:focus + .item-selection-overlay-bounding-box {
  stroke: #ffeb3b;
  filter: drop-shadow(0 4px 12px rgba(255, 235, 59, 0.5));
}

/* Remove default focus outline on voronoi cells */
.item-selection-overlay-voronoi-cell:focus {
  outline: none;
}
