/**
 * SpatialTones Custom Styles
 * 
 * Custom CSS beyond Tailwind utilities.
 * Includes fonts, CSS variables, component styles, and widget visuals.
 */

/* ========== Fonts ========== */
@font-face {
  font-family: 'Caviar Dreams';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('https://fonts.cdnfonts.com/s/77/CaviarDreams.woff') format('woff');
}

@font-face {
  font-family: 'Caviar Dreams';
  font-style: italic;
  font-weight: 300;
  font-display: swap;
  src: url('https://fonts.cdnfonts.com/s/77/CaviarDreamsItalic.woff') format('woff');
}

@font-face {
  font-family: 'Caviar Dreams';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('https://fonts.cdnfonts.com/s/77/CaviarDreams_Bold.woff') format('woff');
}

@font-face {
  font-family: 'Caviar Dreams';
  font-style: italic;
  font-weight: 500;
  font-display: swap;
  src: url('https://fonts.cdnfonts.com/s/77/CaviarDreams_BoldItalic.woff') format('woff');
}

/* ========== CSS Variables ========== */
:root {
  /* Brand colors */
  --st-primary: #4889B7;
  --st-primary-dark: #3a6f95;
  --st-primary-darker: #2d5673;
  --st-primary-light: #78a9c9;
  --st-primary-lighter: #ecf3f9;
  --st-primary-muted: rgba(72, 137, 183, 0.12);
  --st-accent: #B77648;
  --st-accent-dark: #8f5a35;
  --st-accent-light: #d19a70;

  /* Light mode (default) */
  --st-bg: #ffffff;
  --st-bg-secondary: #f8fafc;
  --st-bg-tertiary: #f1f5f9;
  --st-text: #0f172a;
  --st-text-secondary: #475569;
  --st-text-muted: #94a3b8;
  --st-border: #e2e8f0;
  --st-border-light: #f1f5f9;
  --st-card-bg: #ffffff;
  --st-card-bg-alt: rgba(255, 255, 255, 0.7);
  --st-input-bg: #ffffff;
  --st-shadow: rgba(2, 6, 23, 0.06);
  --st-watermark-opacity: 0.08;
}

/* Dark mode */
[data-theme="dark"] {
  --st-bg: #0f172a;
  --st-bg-secondary: #1e293b;
  --st-bg-tertiary: #334155;
  --st-text: #f1f5f9;
  --st-text-secondary: #cbd5e1;
  --st-text-muted: #64748b;
  --st-border: #334155;
  --st-border-light: #1e293b;
  --st-card-bg: #1e293b;
  --st-card-bg-alt: rgba(30, 41, 59, 0.9);
  --st-input-bg: #1e293b;
  --st-shadow: rgba(0, 0, 0, 0.3);
  --st-watermark-opacity: 0.05;
  --st-primary-muted: rgba(72, 137, 183, 0.2);
  --st-primary-lighter: #1e3a5f;
}

/* System preference detection */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --st-bg: #0f172a;
    --st-bg-secondary: #1e293b;
    --st-bg-tertiary: #334155;
    --st-text: #f1f5f9;
    --st-text-secondary: #cbd5e1;
    --st-text-muted: #64748b;
    --st-border: #334155;
    --st-border-light: #1e293b;
    --st-card-bg: #1e293b;
    --st-card-bg-alt: rgba(30, 41, 59, 0.9);
    --st-input-bg: #1e293b;
    --st-shadow: rgba(0, 0, 0, 0.3);
    --st-watermark-opacity: 0.05;
    --st-primary-muted: rgba(72, 137, 183, 0.2);
    --st-primary-lighter: #1e3a5f;
  }
}

/* ========== Base Styles ========== */
body {
  font-family: 'Caviar Dreams', 'Space Grotesk', system-ui, sans-serif;
  position: relative;
  z-index: 0;
  background-color: var(--st-bg);
  color: var(--st-text);
  transition: background-color 0.3s ease, color 0.3s ease;
}

body>* {
  position: relative;
  z-index: 1;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url('/assets/icons/spatialtones_icon_dark.png');
  background-repeat: no-repeat;
  background-size: clamp(420px, 65vmax, 960px);
  background-position: 88% 18%;
  opacity: var(--st-watermark-opacity);
  filter: blur(4px);
  pointer-events: none;
  z-index: 0;
  transform: translateZ(0);
  transition: opacity 0.3s ease;
}

/* Use light icon in dark mode */
[data-theme="dark"] body::before {
  background-image: url('/assets/icons/spatialtones_icon_light.png');
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body::before {
    background-image: url('/assets/icons/spatialtones_icon_light.png');
  }
}

/* ========== Component Styles ========== */
.card {
  box-shadow: 0 8px 20px var(--st-shadow);
  background-color: var(--st-card-bg);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.num {
  font-variant-numeric: tabular-nums;
}

/* Hide number input spinners */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* ========== Accordion Styles ========== */
.acc summary::-webkit-details-marker {
  display: none;
}

.acc .acc-icon {
  transition: transform .2s ease;
}

.acc details[open] .acc-icon {
  transform: rotate(90deg);
}

/* ========== Widget/Carousel Styles ========== */
.carousel {
  display: flex;
  transition: transform 0.4s ease-in-out;
}

.carousel-container {
  position: relative;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 12px;
}

.carousel-slide {
  position: relative;
  min-width: 100%;
  box-sizing: border-box;
  padding: 0;
  text-align: center;
  overflow: hidden;
  height: 0;
  padding-top: 100%;
  border-radius: 12px;
  color: white;
  user-select: none;
}

.song-bg {
  position: absolute;
  inset: 0;
  background-size: contain;
  background-position: center;
  filter: blur(3px);
  opacity: 0.6;
  background-color: rgba(0, 0, 0, 0.4);
  background-blend-mode: multiply;
  border-radius: 12px;
}

.overlay-content {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px;
  box-sizing: border-box;
  border-radius: 12px;
}

.overlay-content h2 {
  margin: 0;
  font-weight: 800;
  font-size: 1.125rem;
  color: gold;
  text-shadow: 0 0 5px black;
  user-select: text;
  flex-shrink: 0;
}

.controls {
  margin-top: 10px;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  gap: 10px;
  align-items: center;
  user-select: none;
}

/* ========== A/B Toggle Button ========== */
.toggle-ab {
  background-color: rgba(220, 20, 60, 0.85);
  border: 3px solid #b22222;
  border-radius: 50%;
  color: white;
  font-size: 3rem;
  width: 200px;
  height: 200px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 0 15px 5px rgba(220, 20, 60, 0.6), inset 0 0 10px 3px #ff4444;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto;
  transition: background-color .3s ease, box-shadow .3s ease;
}

.toggle-ab:hover {
  background-color: #ff1744;
  box-shadow: 0 0 25px 10px rgba(255, 23, 68, 0.9), inset 0 0 15px 6px #ff6677;
  color: #fff;
}

@keyframes goldPulse {
  0% {
    filter: drop-shadow(0 0 8px gold);
  }

  50% {
    filter: drop-shadow(0 0 16px gold);
  }

  100% {
    filter: drop-shadow(0 0 8px gold);
  }
}

.toggle-ab.active {
  background-color: gold;
  color: #111;
  border-color: gold;
  box-shadow: 0 0 9px 3.5px gold, inset 0 0 5px 2px #ffd700;
  filter: drop-shadow(0 0 3.5px gold);
  animation: goldPulse .6s infinite;
}

/* ========== Carousel Navigation ========== */
.prev,
.next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.3);
  border: none;
  padding: 10px 15px;
  cursor: pointer;
  font-size: 20px;
  color: white;
  border-radius: 6px;
  z-index: 2;
  user-select: none;
}

.prev {
  left: 10px;
}

.next {
  right: 10px;
}

/* ========== Waveform Styles ========== */
.waveform {
  width: 90%;
  max-width: 520px;
  margin: 8px auto 12px auto;
  height: 72px;
}

.stwv-waveform {
  background: linear-gradient(135deg, rgba(13, 25, 37, 0.95), rgba(27, 45, 61, 0.88));
  position: relative;
  border-radius: 16px;
}

.st-widget-v2 [data-st-track] {
  transition: all .2s ease;
}

/* ========== Oscilloscope Styles ========== */
.stwv-oscilloscope {
  margin: 0.75rem auto 0;
  width: 100%;
  max-width: 520px;
  height: 104px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(72, 137, 183, 0.22), rgba(183, 118, 72, 0.16));
  position: relative;
  overflow: hidden;
}

.stwv-oscilloscope canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ========== Tailwind Overrides (Brand Colors) ========== */
.bg-emerald-600 {
  background-color: var(--st-primary) !important;
  color: #fff !important;
}

.bg-emerald-600:hover {
  background-color: var(--st-primary-dark) !important;
}

.bg-emerald-600:focus {
  background-color: var(--st-primary-dark) !important;
}

.bg-emerald-600:active {
  background-color: var(--st-primary-darker) !important;
}

.hover\:bg-emerald-700:hover {
  background-color: var(--st-primary-dark) !important;
}

.bg-emerald-500\/90 {
  background-color: rgba(72, 137, 183, 0.9) !important;
  color: #fff !important;
}

.hover\:bg-emerald-500:hover {
  background-color: var(--st-primary-dark) !important;
}

.bg-emerald-50 {
  background-color: var(--st-primary-muted) !important;
  color: var(--st-primary-dark) !important;
}

.bg-emerald-100 {
  background-color: var(--st-primary-lighter) !important;
  color: var(--st-primary) !important;
}

.text-emerald-200 {
  color: var(--st-primary-light) !important;
}

.text-emerald-500,
.text-emerald-600,
.text-emerald-700 {
  color: var(--st-primary) !important;
}

.border-emerald-500 {
  border-color: var(--st-primary) !important;
}

.decoration-emerald-400 {
  text-decoration-color: var(--st-accent) !important;
}

.decoration-emerald-400:hover {
  text-decoration-color: var(--st-accent-dark) !important;
}

.bg-emerald-600:focus-visible {
  outline-color: var(--st-accent) !important;
}

/* ========== Vices Overlay ========== */
#ws-vices-overlay {
  display: none;
}

#ws-vices-overlay.active {
  display: block;
  position: absolute;
  inset: 0;
  pointer-events: auto;
  z-index: 2;
  background: var(--st-bg-secondary, #f1f5f9);
  border-radius: 0.5rem;
}

/* ========== Drag & Drop Upload ========== */
[data-upload-zone] {
  border: 2px dashed var(--st-border);
  border-radius: 1rem;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--st-bg-secondary);
}

[data-upload-zone]:hover {
  border-color: var(--st-primary);
  background: var(--st-bg-tertiary);
}

[data-upload-zone].drag-over {
  border-color: var(--st-primary);
  background: rgba(16, 185, 129, 0.1);
  transform: scale(1.01);
}

[data-upload-zone].has-files {
  border-style: solid;
  border-color: var(--st-primary);
}

[data-upload-zone] input[type="file"] {
  display: none;
}

/* ========== Portal Navigation ========== */
.portal-nav {
  background-color: var(--st-card-bg-alt, rgba(255, 255, 255, 0.8));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-color: var(--st-border);
}

.portal-nav a {
  color: var(--st-text);
}

.nav-link {
  color: var(--st-text-secondary);
  transition: color 0.2s ease;
}

.nav-link:hover {
  color: var(--st-text);
}

/* Dark mode logout button */
[data-theme="dark"] .dark-border {
  border-color: var(--st-border) !important;
}

[data-theme="dark"] .dark-text-secondary {
  color: var(--st-text-secondary) !important;
}

[data-theme="dark"] .dark-border:hover {
  background-color: var(--st-bg-tertiary) !important;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .dark-border {
    border-color: var(--st-border) !important;
  }
  :root:not([data-theme="light"]) .dark-text-secondary {
    color: var(--st-text-secondary) !important;
  }
  :root:not([data-theme="light"]) .dark-border:hover {
    background-color: var(--st-bg-tertiary) !important;
  }
}

/* ========== Enhanced A/B Toggle ========== */
.ab-toggle-container {
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.ab-toggle-btn {
  color: rgba(255, 255, 255, 0.7);
  background: transparent;
  min-width: 80px;
  cursor: pointer;
  border: none;
  position: relative;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.ab-toggle-btn:hover {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.1);
}

.ab-toggle-btn.active {
  background: var(--st-primary);
  color: white;
  box-shadow: 0 2px 8px rgba(72, 137, 183, 0.5);
}

.ab-toggle-a.active {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  box-shadow: 0 2px 12px rgba(220, 38, 38, 0.5);
}

.ab-toggle-b.active {
  background: linear-gradient(135deg, #16a34a, #15803d);
  box-shadow: 0 2px 12px rgba(22, 163, 74, 0.5);
}

.ab-toggle-btn .ab-label {
  font-size: 1rem;
  font-weight: 800;
}

.ab-toggle-btn.active .ab-sublabel {
  opacity: 1;
}

/* Keyboard hint */
.ab-toggle-container::after {
  content: 'Press Space to toggle';
  position: absolute;
  bottom: -24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: rgba(255, 255, 255, 0.5);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
}

.ab-toggle-container:hover::after,
.ab-toggle-container:focus-within::after {
  opacity: 1;
}

/* Pulse animation when switching */
@keyframes abPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.ab-toggle-btn.switching {
  animation: abPulse 0.2s ease-out;
}

/* ========== Theme Toggle Button ========== */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--st-border);
  background-color: var(--st-card-bg);
  color: var(--st-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px var(--st-shadow);
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

.theme-toggle:hover {
  background-color: var(--st-bg-tertiary);
  transform: scale(1.05);
}

.theme-toggle:active {
  transform: scale(0.95);
}

.theme-toggle svg {
  width: 24px;
  height: 24px;
  transition: transform 0.3s ease;
}

.theme-toggle:hover svg {
  transform: rotate(15deg);
}

.theme-toggle .sun-icon {
  display: none;
}

.theme-toggle .moon-icon {
  display: block;
}

[data-theme="dark"] .theme-toggle .sun-icon {
  display: block;
}

[data-theme="dark"] .theme-toggle .moon-icon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun-icon {
    display: block;
  }
  :root:not([data-theme="light"]) .theme-toggle .moon-icon {
    display: none;
  }
}

/* ========== Dark Mode Overrides ========== */
[data-theme="dark"] .bg-white,
[data-theme="dark"] .bg-white\/70 {
  background-color: var(--st-card-bg) !important;
}

[data-theme="dark"] .bg-slate-50 {
  background-color: var(--st-bg-secondary) !important;
}

[data-theme="dark"] .bg-slate-100 {
  background-color: var(--st-bg-tertiary) !important;
}

[data-theme="dark"] .text-slate-900 {
  color: var(--st-text) !important;
}

[data-theme="dark"] .text-slate-800 {
  color: var(--st-text) !important;
}

[data-theme="dark"] .text-slate-700 {
  color: var(--st-text-secondary) !important;
}

[data-theme="dark"] .text-slate-600 {
  color: var(--st-text-secondary) !important;
}

[data-theme="dark"] .text-slate-500 {
  color: var(--st-text-muted) !important;
}

[data-theme="dark"] .text-slate-400 {
  color: var(--st-text-muted) !important;
}

[data-theme="dark"] .border-slate-200 {
  border-color: var(--st-border) !important;
}

[data-theme="dark"] .border-slate-300 {
  border-color: var(--st-border) !important;
}

[data-theme="dark"] .divide-slate-200 > * + * {
  border-color: var(--st-border) !important;
}

[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select {
  background-color: var(--st-input-bg) !important;
  color: var(--st-text) !important;
  border-color: var(--st-border) !important;
}

[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
  color: var(--st-text-muted) !important;
}

[data-theme="dark"] .hover\:bg-slate-50:hover {
  background-color: var(--st-bg-tertiary) !important;
}

[data-theme="dark"] .hover\:bg-white:hover {
  background-color: var(--st-bg-tertiary) !important;
}

/* System preference dark mode overrides */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .bg-white,
  :root:not([data-theme="light"]) .bg-white\/70 {
    background-color: var(--st-card-bg) !important;
  }

  :root:not([data-theme="light"]) .bg-slate-50 {
    background-color: var(--st-bg-secondary) !important;
  }

  :root:not([data-theme="light"]) .bg-slate-100 {
    background-color: var(--st-bg-tertiary) !important;
  }

  :root:not([data-theme="light"]) .text-slate-900 {
    color: var(--st-text) !important;
  }

  :root:not([data-theme="light"]) .text-slate-800 {
    color: var(--st-text) !important;
  }

  :root:not([data-theme="light"]) .text-slate-700 {
    color: var(--st-text-secondary) !important;
  }

  :root:not([data-theme="light"]) .text-slate-600 {
    color: var(--st-text-secondary) !important;
  }

  :root:not([data-theme="light"]) .text-slate-500 {
    color: var(--st-text-muted) !important;
  }

  :root:not([data-theme="light"]) .text-slate-400 {
    color: var(--st-text-muted) !important;
  }

  :root:not([data-theme="light"]) .border-slate-200 {
    border-color: var(--st-border) !important;
  }

  :root:not([data-theme="light"]) .border-slate-300 {
    border-color: var(--st-border) !important;
  }

  :root:not([data-theme="light"]) .divide-slate-200 > * + * {
    border-color: var(--st-border) !important;
  }

  :root:not([data-theme="light"]) input,
  :root:not([data-theme="light"]) textarea,
  :root:not([data-theme="light"]) select {
    background-color: var(--st-input-bg) !important;
    color: var(--st-text) !important;
    border-color: var(--st-border) !important;
  }

  :root:not([data-theme="light"]) input::placeholder,
  :root:not([data-theme="light"]) textarea::placeholder {
    color: var(--st-text-muted) !important;
  }

  :root:not([data-theme="light"]) .hover\:bg-slate-50:hover {
    background-color: var(--st-bg-tertiary) !important;
  }

  :root:not([data-theme="light"]) .hover\:bg-white:hover {
    background-color: var(--st-bg-tertiary) !important;
  }
}

/* ========== Mobile Improvements ========== */
@media (max-width: 768px) {
  /* Larger touch targets */
  button,
  [role="button"],
  input,
  select,
  textarea {
    min-height: 44px;
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  /* Better spacing on mobile */
  .theme-toggle {
    top: 0.75rem;
    right: 0.75rem;
    width: 44px;
    height: 44px;
  }

  /* Improve accordion tap targets */
  .acc summary {
    padding: 1rem;
    margin: -1rem;
  }

  /* Better scroll behavior */
  html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }

  /* Prevent horizontal scroll */
  body {
    overflow-x: hidden;
  }

  /* Better mobile card spacing */
  .card {
    margin-left: -0.25rem;
    margin-right: -0.25rem;
  }
}

/* ========== Smooth Transitions ========== */
* {
  transition-property: background-color, border-color, color;
  transition-duration: 0s;
}

.card,
body,
input,
textarea,
select,
button,
.theme-toggle {
  transition-duration: 0.3s;
  transition-timing-function: ease;
}

/* ========== Focus Styles for Accessibility ========== */
:focus-visible {
  outline: 2px solid var(--st-primary);
  outline-offset: 2px;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--st-primary);
  outline-offset: 2px;
}

/* ========== Safe Area for Notched Devices ========== */
@supports (padding: env(safe-area-inset-top)) {
  .theme-toggle {
    top: max(1rem, env(safe-area-inset-top));
    right: max(1rem, env(safe-area-inset-right));
  }
}
