/* ==========================================================================
   Sonara Base Styles & Reset
   ========================================================================== */

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

html {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  background-color: var(--color-bg);
  color: var(--color-text-primary);
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  position: relative;
  background-color: var(--color-bg);
  color: var(--color-text-primary);
  overflow-x: hidden;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* Accessibility: Skip to Content */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-4);
  background: var(--color-accent);
  color: #FFFFFF;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  z-index: var(--z-toast);
  text-decoration: none;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: var(--space-4);
  outline: 2px solid #FFFFFF;
}

/* Accessibility: Focus visible */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
  border-radius: var(--radius-xs);
}

button:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
  outline: none;
}

/* Selection */
::selection {
  background-color: var(--color-accent);
  color: #FFFFFF;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--color-surface-hover);
  border-radius: var(--radius-full);
  border: 2px solid var(--color-bg);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

/* Typography Base */
h1, h2, h3, h4, h5, h6 {
  color: var(--color-text-primary);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.025em;
}

p {
  color: var(--color-text-secondary);
  line-height: 1.65;
}

a {
  color: inherit;
  text-decoration: none;
  transition: color var(--transition-fast);
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  border: none;
  background: none;
}

button {
  cursor: pointer;
}

img, svg {
  display: block;
  max-width: 100%;
}

ul, ol {
  list-style: none;
}

/* Container */
.container {
  width: 100%;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-6);
  padding-right: var(--space-6);
}

.container-wide {
  max-width: 1340px;
}

.container-narrow {
  max-width: 860px;
}

/* ==========================================================================
   Ambient Background & Grain Layer
   ========================================================================== */
.ambient-wrapper {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: var(--z-background);
}

.ambient-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.85;
  transform: translate3d(0, 0, 0);
  transition: opacity var(--transition-slow);
}

.blob-1 {
  top: -15%;
  left: 20%;
  width: 60vw;
  height: 55vw;
  max-width: 800px;
  max-height: 700px;
  background: radial-gradient(circle, var(--ambient-glow-1) 0%, rgba(139, 92, 246, 0) 70%);
  animation: floatSlow 22s ease-in-out infinite alternate;
}

.blob-2 {
  top: 35%;
  right: -10%;
  width: 50vw;
  height: 50vw;
  max-width: 650px;
  max-height: 650px;
  background: radial-gradient(circle, var(--ambient-glow-2) 0%, rgba(99, 102, 241, 0) 70%);
  animation: floatSlow 28s ease-in-out infinite alternate-reverse;
}

.blob-3 {
  bottom: -10%;
  left: 5%;
  width: 55vw;
  height: 50vw;
  max-width: 700px;
  max-height: 650px;
  background: radial-gradient(circle, var(--ambient-glow-3) 0%, rgba(167, 139, 250, 0) 70%);
  animation: floatSlow 32s ease-in-out infinite alternate;
}

/* Subtle SVG Noise Texture */
.ambient-noise {
  position: absolute;
  inset: 0;
  opacity: 0.028;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
  background-repeat: repeat;
}

[data-theme="light"] .ambient-noise {
  opacity: 0.018;
}

@keyframes floatSlow {
  0% {
    transform: translate(0, 0) scale(1);
  }
  50% {
    transform: translate(25px, 20px) scale(1.04);
  }
  100% {
    transform: translate(-20px, 35px) scale(0.97);
  }
}

/* ==========================================================================
   Desktop Custom Cursor
   ========================================================================== */
.custom-cursor {
  position: fixed;
  top: 0;
  left: 0;
  width: 6px;
  height: 6px;
  background: var(--color-accent);
  border-radius: 50%;
  pointer-events: none;
  z-index: var(--z-cursor);
  transform: translate(-50%, -50%);
  transition: width 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              height 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.2s ease;
  opacity: 0;
}

.custom-cursor-glow {
  position: fixed;
  top: 0;
  left: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--color-border-accent);
  background: var(--color-accent-subtle);
  pointer-events: none;
  z-index: calc(var(--z-cursor) - 1);
  transform: translate(-50%, -50%);
  transition: width 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              height 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              background 0.25s ease,
              border-color 0.25s ease,
              opacity 0.25s ease;
  opacity: 0;
}

.custom-cursor.is-active,
.custom-cursor-glow.is-active {
  opacity: 1;
}

.custom-cursor-glow.is-hovering {
  width: 52px;
  height: 52px;
  background: rgba(139, 92, 246, 0.18);
  border-color: var(--color-accent);
}

@media (pointer: coarse) {
  .custom-cursor,
  .custom-cursor-glow {
    display: none !important;
  }
}

/* ==========================================================================
   Minimal Initial Page Loader (< 700ms)
   ========================================================================== */
.initial-loader {
  position: fixed;
  inset: 0;
  background-color: var(--color-bg);
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: var(--space-4);
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.initial-loader.loaded {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--color-text-primary);
}

.loader-bars {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 20px;
}

.loader-bar {
  width: 3px;
  background: var(--color-accent);
  border-radius: var(--radius-full);
  animation: loaderPulse 0.8s ease-in-out infinite alternate;
}

.loader-bar:nth-child(1) { height: 8px; animation-delay: 0.1s; }
.loader-bar:nth-child(2) { height: 16px; animation-delay: 0.25s; }
.loader-bar:nth-child(3) { height: 22px; animation-delay: 0.4s; }
.loader-bar:nth-child(4) { height: 14px; animation-delay: 0.2s; }
.loader-bar:nth-child(5) { height: 9px; animation-delay: 0.05s; }

@keyframes loaderPulse {
  0% { transform: scaleY(0.4); opacity: 0.4; }
  100% { transform: scaleY(1); opacity: 1; }
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto !important;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .ambient-blob {
    animation: none !important;
    transform: none !important;
  }

  .custom-cursor,
  .custom-cursor-glow {
    display: none !important;
  }

  .js-reveal {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
}

/* ==========================================================================
   Scroll Reveal Animations
   ========================================================================== */
.js-reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.7s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: opacity, transform;
}

.js-reveal.revealed {
  opacity: 1;
  transform: translateY(0);
}
