/* ============================================================
   SoundWire — Design System
   Dark theme · Glassmorphism · Black & White
   ============================================================ */

/* ---------- Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ---------- CSS Variables ---------- */
:root {
  --bg-primary: #050505;
  --bg-secondary: #0a0a0a;
  --bg-tertiary: #111111;

  --glass-bg: rgba(255, 255, 255, 0.04);
  --glass-bg-hover: rgba(255, 255, 255, 0.07);
  --glass-bg-active: rgba(255, 255, 255, 0.10);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-border-hover: rgba(255, 255, 255, 0.16);
  --glass-blur: 24px;

  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.55);
  --text-tertiary: rgba(255, 255, 255, 0.35);
  --text-disabled: rgba(255, 255, 255, 0.2);

  --accent: #ffffff;
  --live-red: #ff3b30;
  --success: #30d158;
  --error: #ff453a;
  --warning: #ffd60a;

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 300ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 500ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Consolas', monospace;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(255, 255, 255, 0.06);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.5;
}

/* Subtle radial glow in center */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(
    ellipse 60% 50% at 50% 40%,
    rgba(255, 255, 255, 0.02) 0%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 0;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
input { font-family: inherit; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

/* ---------- Layout ---------- */
.page-wrapper {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.page-header {
  display: flex;
  align-items: center;
  padding: 1rem 1.5rem;
  gap: 1rem;
  position: relative;
  z-index: 10;
}

.header-title {
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.page-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  gap: 2rem;
}

/* ---------- Glass Card ---------- */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 2.5rem;
  transition: border-color var(--transition-normal),
              background var(--transition-normal),
              transform var(--transition-normal),
              box-shadow var(--transition-normal);
  position: relative;
  overflow: hidden;
}

.glass-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
}

.glass-card-interactive {
  cursor: pointer;
}

.glass-card-interactive:hover {
  border-color: var(--glass-border-hover);
  background: var(--glass-bg-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.glass-card-interactive:active {
  transform: translateY(0);
  background: var(--glass-bg-active);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  padding: 0.875rem 1.75rem;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-normal);
  background: var(--glass-bg);
  color: var(--text-primary);
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn:hover {
  background: var(--glass-bg-hover);
  border-color: var(--glass-border-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-glow);
}

.btn:active {
  transform: translateY(0);
  background: var(--glass-bg-active);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-primary:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 30px rgba(255, 255, 255, 0.08);
}

.btn-danger {
  border-color: rgba(255, 59, 48, 0.3);
  color: var(--live-red);
}

.btn-danger:hover {
  background: rgba(255, 59, 48, 0.1);
  border-color: rgba(255, 59, 48, 0.4);
  box-shadow: 0 0 20px rgba(255, 59, 48, 0.1);
}

.btn-icon {
  padding: 0.625rem;
  border-radius: var(--radius-sm);
  min-width: 40px;
  min-height: 40px;
}

.btn-back {
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-back:hover {
  color: var(--text-primary);
  background: var(--glass-bg);
  border-color: var(--glass-border);
}

/* ---------- Mode Selector (Home) ---------- */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  width: 100%;
  max-width: 560px;
}

.mode-card {
  padding: 3rem 2rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.mode-card .mode-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-normal);
}

.mode-card .mode-icon svg {
  width: 28px;
  height: 28px;
  stroke: var(--text-secondary);
  transition: stroke var(--transition-normal);
}

.glass-card-interactive.mode-card:hover .mode-icon {
  background: rgba(255, 255, 255, 0.1);
}

.glass-card-interactive.mode-card:hover .mode-icon svg {
  stroke: var(--text-primary);
}

.mode-card h2 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.mode-card p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ---------- Home Title ---------- */
.home-title {
  text-align: center;
  margin-bottom: 0.5rem;
}

.home-title h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 0.5rem;
}

.home-title p {
  font-size: 0.9375rem;
  color: var(--text-secondary);
}

.home-logo {
  width: 48px;
  height: 48px;
  margin: 0 auto 1rem;
  opacity: 0.8;
}

/* ---------- Views (toggle setup/live) ---------- */
.view {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.view.hidden {
  display: none;
}

.view-card {
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.view-card .card-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.25rem;
}

.view-card .card-icon svg {
  width: 32px;
  height: 32px;
  stroke: var(--text-secondary);
}

.view-card h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.view-card .subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ---------- Audio Mode Selector ---------- */
.mode-selector {
  display: flex;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
  width: 100%;
}

.mode-selector-btn {
  flex: 1;
  padding: 0.625rem 0.75rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.mode-selector-btn:hover {
  color: var(--text-primary);
}

.mode-selector-btn.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.mode-selector-btn .mode-label {
  font-size: 0.8125rem;
  font-weight: 500;
}

.mode-selector-btn .mode-desc {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  font-weight: 400;
}

.mode-selector-btn.active .mode-desc {
  color: var(--text-secondary);
}

/* ---------- Live Indicator ---------- */
.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--live-red);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--live-red);
  animation: pulse-dot 2s ease-in-out infinite;
  box-shadow: 0 0 8px var(--live-red);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}

/* ---------- Room Code ---------- */
.code-display-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.code-display {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: 0.25em;
  color: var(--text-primary);
  padding: 0.75rem 1.25rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  user-select: all;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.code-display:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--glass-border-hover);
}

.copy-feedback {
  position: absolute;
  top: -2rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  font-family: var(--font-sans);
  color: var(--success);
  letter-spacing: 0;
  opacity: 0;
  transition: opacity var(--transition-fast);
  pointer-events: none;
}

.copy-feedback.show {
  opacity: 1;
}

/* ---------- QR Code ---------- */
.qr-wrapper {
  background: white;
  padding: 12px;
  border-radius: var(--radius-md);
  display: inline-block;
  line-height: 0;
}

.qr-wrapper canvas,
.qr-wrapper img {
  border-radius: 4px;
  display: block;
}

/* ---------- Text Input ---------- */
.input-label {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  text-align: left;
}

.text-input {
  width: 100%;
  padding: 0.875rem 1rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9375rem;
  outline: none;
  transition: all var(--transition-normal);
}

.text-input::placeholder {
  color: var(--text-disabled);
}

.text-input:focus {
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.05);
}

/* ---------- Input with Toggle (password) ---------- */
.input-with-toggle {
  position: relative;
  width: 100%;
}

.input-with-toggle .text-input {
  padding-right: 3rem;
}

.btn-toggle-password {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 0.375rem;
  border-radius: var(--radius-xs);
  transition: color var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-toggle-password:hover {
  color: var(--text-primary);
}

.btn-toggle-password svg {
  width: 18px;
  height: 18px;
}

/* ---------- Lock Badge ---------- */
.lock-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  transition: color var(--transition-fast);
}

.lock-badge svg {
  width: 16px;
  height: 16px;
}

.lock-badge.hidden {
  display: none;
}

/* ---------- Listener Count ---------- */
.listener-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.listener-info svg {
  width: 18px;
  height: 18px;
}

.listener-count {
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* ---------- Audio Visualizer ---------- */
.audio-visualizer {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  height: 48px;
  padding: 0.5rem 0;
}

.audio-bar {
  width: 3px;
  min-height: 3px;
  background: var(--text-primary);
  border-radius: var(--radius-full);
  opacity: 0.4;
  transition: height 80ms ease;
}

.audio-visualizer.active .audio-bar {
  opacity: 0.7;
}

/* ---------- Code Input ---------- */
.code-input-wrapper {
  width: 100%;
}

.code-input {
  width: 100%;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: 0.3em;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  outline: none;
  transition: all var(--transition-normal);
  text-transform: uppercase;
}

.code-input::placeholder {
  color: var(--text-disabled);
  letter-spacing: 0.3em;
}

.code-input:focus {
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.05);
}

/* ---------- Volume Control ---------- */
.volume-control {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 280px;
}

.volume-control svg {
  width: 20px;
  height: 20px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  outline: none;
  transition: background var(--transition-fast);
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  transition: transform var(--transition-fast);
}

.volume-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.volume-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* ---------- Connection Status ---------- */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.875rem;
  border-radius: var(--radius-full);
  font-size: 0.8125rem;
  font-weight: 500;
}

.status-badge.connected {
  background: rgba(48, 209, 88, 0.1);
  color: var(--success);
  border: 1px solid rgba(48, 209, 88, 0.2);
}

.status-badge.disconnected {
  background: rgba(255, 69, 58, 0.1);
  color: var(--error);
  border: 1px solid rgba(255, 69, 58, 0.2);
}

.status-badge.connecting {
  background: rgba(255, 214, 10, 0.1);
  color: var(--warning);
  border: 1px solid rgba(255, 214, 10, 0.2);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge.connected .status-dot {
  animation: pulse-dot 2s ease-in-out infinite;
  box-shadow: 0 0 6px var(--success);
}

/* ---------- Status Text ---------- */
.status-text {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  text-align: center;
}

/* ---------- Error Message ---------- */
.error-message {
  font-size: 0.8125rem;
  color: var(--error);
  text-align: center;
  min-height: 1.2em;
}

/* ---------- Divider ---------- */
.divider {
  width: 100%;
  height: 1px;
  background: var(--glass-border);
  margin: 0.5rem 0;
}

/* ---------- Footer ---------- */
.page-footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.75rem;
  color: var(--text-disabled);
  letter-spacing: 0.05em;
}

/* ---------- Animations ---------- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.animate-in {
  animation: fadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
}

.animate-in:nth-child(1) { animation-delay: 0ms; }
.animate-in:nth-child(2) { animation-delay: 80ms; }
.animate-in:nth-child(3) { animation-delay: 160ms; }
.animate-in:nth-child(4) { animation-delay: 240ms; }

/* ---------- Toast notification ---------- */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.25rem;
  font-size: 0.8125rem;
  color: var(--text-primary);
  opacity: 0;
  transition: all var(--transition-normal);
  pointer-events: none;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  .mode-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .mode-card {
    padding: 2rem 1.5rem;
    flex-direction: row;
    text-align: left;
    gap: 1.25rem;
  }

  .mode-card .mode-text {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }

  .glass-card {
    padding: 2rem 1.5rem;
  }

  .code-display {
    font-size: 1.5rem;
    letter-spacing: 0.2em;
  }

  .home-title h1 {
    font-size: 1.75rem;
  }

  .page-content {
    padding: 1rem;
  }
}

@media (max-width: 380px) {
  .code-display {
    font-size: 1.25rem;
  }

  .code-input {
    font-size: 1.25rem;
  }
}

/* ---------- Utility ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.text-center { text-align: center; }
.w-full { width: 100%; }
.gap-sm { gap: 0.75rem; }
.gap-md { gap: 1.25rem; }
.mt-sm { margin-top: 0.5rem; }
.mt-md { margin-top: 1rem; }
