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

:root {
  --bg: #050505;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-raised: rgba(255, 255, 255, 0.07);
  --surface-hover: rgba(255, 255, 255, 0.10);
  --border: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.12);
  --text-primary: #f5f5f7;
  --text-secondary: rgba(255, 255, 255, 0.55);
  --text-tertiary: rgba(255, 255, 255, 0.30);
  --radius-sm: 12px;
  --radius-md: 20px;
  --radius-lg: 28px;
  --radius-xl: 40px;
  --transition: 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --spring: 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);

  --mood-happy: #FFB84D;
  --mood-sad: #5B8DEF;
  --mood-angry: #EF5B5B;
  --mood-surprised: #E87DE8;
  --mood-neutral: #8E8E93;
  --mood-fearful: #9B7DDB;
  --mood-disgusted: #5BBF6F;
  --mood-current: var(--mood-neutral);
}

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

body {
  font-family: 'Sora', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Ambient glow */
.ambient-glow {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 140vmax;
  height: 140vmax;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--mood-current) 12%, transparent) 0%,
    color-mix(in srgb, var(--mood-current) 4%, transparent) 35%,
    transparent 65%
  );
  pointer-events: none;
  z-index: 0;
  transition: background 1.5s ease;
  will-change: background;
}

/* Top bar */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  background: linear-gradient(to bottom, rgba(5, 5, 5, 0.9) 0%, transparent 100%);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.02em;
}

.topbar-name {
  font: inherit;
  margin: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang-switcher {
  display: flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 2px;
}

.lang-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.lang-btn:hover {
  color: rgba(255, 255, 255, 0.7);
}

.lang-btn.active {
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.9);
}

.topbar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--mood-current), color-mix(in srgb, var(--mood-current) 60%, #fff));
  border-radius: 9px;
  font-weight: 700;
  font-size: 18px;
  color: #000;
  transition: background 1s ease;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  transition: all var(--transition);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  transform: scale(1.05);
}

.icon-btn:active {
  transform: scale(0.95);
}

/* Main layout */
.main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 80px 28px 28px;
  position: relative;
  z-index: 1;
  gap: 20px;
}

/* Camera */
.camera-wrap {
  position: relative;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-xl);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.03),
    0 20px 60px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  display: block;
}

.camera-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(5, 5, 5, 0.85);
  -webkit-backdrop-filter: blur(30px);
  backdrop-filter: blur(30px);
  z-index: 5;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.camera-placeholder.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.camera-placeholder-icon {
  color: var(--text-tertiary);
  animation: breathe 3s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.05); }
}

.camera-placeholder-text {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.camera-placeholder-sub {
  font-size: 13px;
  color: var(--text-tertiary);
  text-align: center;
  max-width: 280px;
  line-height: 1.5;
}

/* Scan line animation */
.scan-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--mood-current), transparent);
  opacity: 0;
  z-index: 4;
  pointer-events: none;
  transition: background 1s ease;
}

.scan-line.active {
  opacity: 0.6;
  animation: scanDown 2s ease-in-out;
}

@keyframes scanDown {
  0% { top: 0; opacity: 0; }
  10% { opacity: 0.6; }
  90% { opacity: 0.6; }
  100% { top: 100%; opacity: 0; }
}

/* Primary button */
.btn-primary {
  padding: 12px 28px;
  border: none;
  border-radius: 100px;
  background: #fff;
  color: #000;
  font-family: 'Sora', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--spring);
  letter-spacing: -0.01em;
}

.btn-primary:hover {
  transform: scale(1.04);
  box-shadow: 0 8px 30px rgba(255, 255, 255, 0.15);
}

.btn-primary:active {
  transform: scale(0.97);
}

/* Mood card */
.mood-card {
  width: 100%;
  max-width: 640px;
}

.mood-card-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 18px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  -webkit-backdrop-filter: blur(40px);
  backdrop-filter: blur(40px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  transition: all 0.5s ease;
}

.mood-indicator {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.mood-emoji {
  font-size: 36px;
  line-height: 1;
  width: 50px;
  text-align: center;
  transition: all var(--spring);
}

.mood-emoji.pop {
  animation: emojiPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes emojiPop {
  0% { transform: scale(0.5) rotate(-10deg); opacity: 0; }
  60% { transform: scale(1.2) rotate(3deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.mood-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mood-label {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  transition: color 0.5s ease;
}

.mood-sub {
  font-size: 12px;
  color: var(--text-tertiary);
}

.mood-divider {
  width: 1px;
  height: 36px;
  background: var(--border);
  flex-shrink: 0;
}

/* Now playing */
.now-playing {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.now-playing-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 18px;
  opacity: 0.3;
  transition: opacity 0.5s ease;
}

.now-playing-bars.active {
  opacity: 1;
}

.now-playing-bars span {
  width: 3px;
  background: var(--mood-current);
  border-radius: 2px;
  transition: background 1s ease;
}

.now-playing-bars.active span {
  animation: bars 1.2s ease-in-out infinite;
}

.now-playing-bars span:nth-child(1) { height: 6px; animation-delay: 0s; }
.now-playing-bars span:nth-child(2) { height: 12px; animation-delay: 0.15s; }
.now-playing-bars span:nth-child(3) { height: 8px; animation-delay: 0.3s; }
.now-playing-bars span:nth-child(4) { height: 14px; animation-delay: 0.45s; }

@keyframes bars {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1); }
}

.now-playing-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.now-playing-label {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.now-playing-playlist {
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Settings panel */
.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: all 0.4s ease;
}

.settings-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 100vw;
  background: rgba(18, 18, 20, 0.95);
  -webkit-backdrop-filter: blur(60px) saturate(180%);
  backdrop-filter: blur(60px) saturate(180%);
  border-left: 1px solid var(--border);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.55s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.settings-panel.open {
  transform: translateX(0);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 28px 20px;
  flex-shrink: 0;
}

.settings-header h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.settings-close {
  background: rgba(255, 255, 255, 0.06);
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 28px 40px;
  scrollbar-width: none;
}

.settings-body::-webkit-scrollbar {
  display: none;
}

/* Settings sections */
.settings-section {
  padding: 24px 0;
  border-bottom: 1px solid var(--border);
}

.settings-section-last {
  border-bottom: none;
}

.settings-section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 16px;
}

.settings-section-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: -8px;
  margin-bottom: 16px;
  line-height: 1.4;
}

/* Spotify card */
.spotify-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  gap: 16px;
}

.spotify-status {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.spotify-icon {
  flex-shrink: 0;
  color: #1DB954;
  display: flex;
}

.spotify-status-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.spotify-status-label {
  font-size: 14px;
  font-weight: 500;
}

.spotify-status-sub {
  font-size: 11px;
  color: var(--text-tertiary);
}

.btn-spotify {
  padding: 8px 18px;
  border: none;
  border-radius: 100px;
  background: #1DB954;
  color: #000;
  font-family: 'Sora', sans-serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--spring);
  white-space: nowrap;
}

.btn-spotify:hover {
  transform: scale(1.05);
  background: #1ed760;
  box-shadow: 0 4px 20px rgba(29, 185, 84, 0.3);
}

.btn-spotify:active {
  transform: scale(0.96);
}

.btn-spotify.connected {
  background: rgba(29, 185, 84, 0.15);
  color: #1DB954;
}

/* Playlist grid */
.playlist-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.playlist-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: all var(--transition);
}

.playlist-card:hover {
  background: var(--surface-raised);
  border-color: var(--border-light);
}

.playlist-card.active {
  border-color: var(--mood-color);
  box-shadow: 0 0 20px color-mix(in srgb, var(--mood-color) 15%, transparent);
}

.playlist-card.disabled {
  opacity: 0.45;
}

.playlist-card.disabled .playlist-input {
  pointer-events: none;
}

.playlist-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.playlist-toggle {
  margin-left: auto;
  flex-shrink: 0;
}

.playlist-mood-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mood-color);
  box-shadow: 0 0 8px var(--mood-color);
}

.playlist-mood-name {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.playlist-input {
  width: 100%;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: 'Sora', sans-serif;
  font-size: 11px;
  outline: none;
  transition: all var(--transition);
}

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

.playlist-input:focus {
  border-color: var(--mood-color);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--mood-color) 10%, transparent);
}

.playlist-search-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-family: 'Sora', sans-serif;
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition);
}

.playlist-search-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

/* Setting rows */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
}

.setting-row + .setting-row {
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.setting-label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.setting-label > span:first-child {
  font-size: 14px;
  font-weight: 500;
}

.setting-hint {
  font-size: 11px;
  color: var(--text-tertiary);
}

/* Stacked setting (label above input) */
.setting-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-stack-label {
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.setting-stack-label .setting-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 400;
}

/* Input */
.setting-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'Sora', sans-serif;
  font-size: 13px;
  outline: none;
  transition: all var(--transition);
}

.setting-input:focus {
  border-color: rgba(255, 255, 255, 0.2);
  background: var(--surface-raised);
}

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

/* Range slider */
.setting-range {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  outline: none;
  flex-shrink: 0;
}

.setting-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s ease;
}

.setting-range::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.setting-range::-webkit-slider-thumb:active {
  transform: scale(0.95);
}

/* Toggle */
.toggle {
  position: relative;
  flex-shrink: 0;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  display: block;
  width: 48px;
  height: 28px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.35s ease;
  position: relative;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.toggle input:checked + .toggle-track {
  background: #34C759;
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(20px);
}

/* Select */
.setting-select {
  padding: 8px 32px 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: 'Sora', sans-serif;
  font-size: 13px;
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.4)' stroke-width='2' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: all var(--transition);
  flex-shrink: 0;
  max-width: 200px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.setting-select:focus {
  border-color: rgba(255, 255, 255, 0.2);
}

/* About */
.about-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
}

.about-row + .about-row {
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.about-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.about-value {
  font-size: 13px;
  color: var(--text-tertiary);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.12);
  -webkit-backdrop-filter: blur(30px);
  backdrop-filter: blur(30px);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  z-index: 500;
  opacity: 0;
  transition: all 0.5s cubic-bezier(0.32, 0.72, 0, 1);
  pointer-events: none;
}

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

/* Responsive */
@media (max-width: 700px) {
  .main {
    padding: 72px 16px 16px;
    gap: 14px;
  }

  .camera-wrap {
    border-radius: var(--radius-lg);
  }

  .mood-card-inner {
    flex-direction: column;
    gap: 14px;
    padding: 16px 18px;
  }

  .mood-divider {
    width: 100%;
    height: 1px;
  }

  .settings-panel {
    width: 100vw;
  }

  .playlist-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    padding: 16px 20px;
  }
}

/* Staggered settings animations */
.settings-panel.open .settings-section {
  animation: settingSlideIn 0.5s cubic-bezier(0.32, 0.72, 0, 1) both;
}

.settings-panel.open .settings-section:nth-child(1) { animation-delay: 0.05s; }
.settings-panel.open .settings-section:nth-child(2) { animation-delay: 0.12s; }
.settings-panel.open .settings-section:nth-child(3) { animation-delay: 0.19s; }
.settings-panel.open .settings-section:nth-child(4) { animation-delay: 0.26s; }

@keyframes settingSlideIn {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Focus ring */
:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.3);
  outline-offset: 2px;
}

/* Scrollbar for non-webkit */
.settings-body {
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

/* Spotify embed */
.spotify-embed {
  width: 100%;
  max-width: 640px;
  border-radius: var(--radius-md);
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.5s cubic-bezier(0.32, 0.72, 0, 1);
  pointer-events: none;
  height: 0;
}

.spotify-embed.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  height: 152px;
}

/* Now playing active state */
.now-playing.active .now-playing-label {
  color: var(--text-primary);
}

.now-playing-artist {
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Mood card glow when active */
.mood-card-inner.active-mood {
  border-color: color-mix(in srgb, var(--mood-current) 30%, transparent);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.3),
    0 0 40px color-mix(in srgb, var(--mood-current) 8%, transparent);
}

.site-footer {
  text-align: center;
  padding: 24px 16px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.4);
}

.site-footer a {
  color: rgba(255, 255, 255, 0.6);
  text-decoration: none;
}

.site-footer a:hover {
  color: rgba(255, 255, 255, 0.85);
}
