* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Plus Jakarta Sans', sans-serif;
}

:root {
  --bg-color: #0b0c12;
  --surface-color: #14151f;
  --surface-alt: #191b27;
  --surface-border: rgba(255, 255, 255, 0.08);
  --primary-color: #6366f1;
  --primary-hover: #4f46e5;
  --accent-2: #c084fc;
  --accent-3: #f472b6;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

html { color-scheme: dark; }

body {
  background: radial-gradient(circle at top, #1a1c29 0%, #0b0c12 100%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: clamp(0.75rem, 4vw, 2rem);
  padding-top: max(clamp(0.75rem, 4vw, 2rem), env(safe-area-inset-top));
  padding-bottom: max(clamp(0.75rem, 4vw, 2rem), env(safe-area-inset-bottom));
}

.app-shell {
  width: 100%;
  max-width: 620px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

button, .tab-btn, .chip-toggle, .btn-icon, .btn-pill {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand { display: flex; align-items: center; gap: 0.85rem; }

.logo-3d {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #818cf8 0%, #c084fc 50%, #f472b6 100%);
  border-radius: 14px;
  padding: 2px;
  box-shadow:
    0 10px 15px -3px rgba(99, 102, 241, 0.4),
    0 4px 6px -4px rgba(99, 102, 241, 0.2),
    inset 0 2px 3px rgba(255, 255, 255, 0.4),
    inset 0 -2px 4px rgba(0, 0, 0, 0.4);
  transform: perspective(300px) rotateX(10deg) rotateY(-8deg);
  transition: transform 0.3s ease;
}
.logo-3d:hover { transform: perspective(300px) rotateX(0deg) rotateY(0deg) scale(1.05); }

.logo-inner {
  background: #11131a;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #a5b4fc;
}
.logo-inner svg { width: 22px; height: 22px; }

h1 { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.02em; }
.subtitle { font-size: 0.78rem; color: var(--text-muted); }

.btn-install {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  color: var(--text-main);
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
}
.btn-install svg { width: 16px; height: 16px; }
.btn-install:hover { background: var(--primary-color); transform: translateY(-1px); }

/* ---------- Tabs ---------- */
.source-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  padding: 4px;
  border-radius: 12px;
  gap: 2px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.6rem;
  font-weight: 600;
  font-size: 0.82rem;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.tab-btn.active {
  background: var(--primary-color);
  color: #fff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.hint {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  line-height: 1.4;
}
.hint a { color: var(--primary-color); }
.hint.muted { opacity: 0.85; }

/* ---------- Form Controls ---------- */
.input-group { display: flex; gap: 8px; }

input[type="text"] {
  flex: 1;
  min-width: 0;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  color: #fff;
  outline: none;
  font-size: 0.9rem;
}
input[type="text"]:focus { border-color: var(--primary-color); }

.btn-primary {
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.25rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease;
}
.btn-primary:hover { background: var(--primary-hover); }

/* ---------- Dropzone ---------- */
.file-dropzone {
  border: 2px dashed var(--surface-border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.file-dropzone:hover,
.file-dropzone.drag-over { border-color: var(--primary-color); background: rgba(99, 102, 241, 0.06); }
.file-dropzone .highlight { color: var(--primary-color); font-weight: 600; }

/* ---------- Search Results ---------- */
.search-results {
  list-style: none;
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 320px;
  overflow-y: auto;
}

.search-result {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  cursor: pointer;
  transition: background 0.15s ease;
}
.search-result:hover { background: rgba(255, 255, 255, 0.05); }

.result-art {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: linear-gradient(135deg, #818cf8, #c084fc);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
}

.result-meta { flex: 1; min-width: 0; }
.result-title { font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-artist { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.result-play { flex-shrink: 0; }

/* ---------- Player Card ---------- */
.player-card {
  background: var(--surface-color);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.media-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
}

.media-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#yt-player-container iframe,
video.media-layer {
  width: 100%;
  height: 100%;
  border: none;
  object-fit: contain;
  background: #000;
}

#wave-canvas { background: #000; }

.placeholder-art {
  width: 30%;
  aspect-ratio: 1;
  max-width: 120px;
  border-radius: 50%;
  background: linear-gradient(135deg, #818cf8 0%, #c084fc 50%, #f472b6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(0, 0, 0, 0.55);
  box-shadow: 0 0 0 10px rgba(255, 255, 255, 0.03), 0 20px 40px rgba(0, 0, 0, 0.5);
  animation: placeholder-pulse 2.4s ease-in-out infinite;
}
.placeholder-art svg { width: 42%; height: 42%; }

#audio-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #1a1c29 0%, #050509 100%);
}

@keyframes placeholder-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.frame-overlay {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
}

.chip-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(11, 12, 18, 0.75);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, opacity 0.2s ease;
}
.chip-toggle svg { width: 14px; height: 14px; }
.chip-toggle:hover:not(:disabled) { background: var(--primary-color); }
.chip-toggle:disabled { opacity: 0.35; cursor: not-allowed; }

/* ---------- Now Playing ---------- */
.now-playing { text-align: center; }
.now-title { font-size: 0.95rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-artist { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Transport Controls ---------- */
.controls-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.btn-icon {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--surface-border);
  border-radius: 50%;
  color: var(--text-main);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.btn-icon svg { width: 18px; height: 18px; fill: currentColor; }
.btn-icon:hover { background: rgba(255, 255, 255, 0.1); }
.btn-icon.active { background: var(--primary-color); border-color: var(--primary-color); }

.btn-play {
  width: 44px;
  height: 44px;
  background: var(--primary-color);
  border-color: var(--primary-color);
}
.btn-play:hover { background: var(--primary-hover); }

.time { font-size: 0.72rem; color: var(--text-muted); font-variant-numeric: tabular-nums; width: 34px; text-align: center; flex-shrink: 0; }

.controls-bar-secondary {
  justify-content: space-between;
}

.btn-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--surface-border);
  color: var(--text-main);
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}
.btn-pill svg { width: 15px; height: 15px; }
.btn-pill:hover { background: rgba(255, 255, 255, 0.1); }
.btn-pill.active { background: var(--primary-color); border-color: var(--primary-color); }

.seek-bar {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary-color) 0%, var(--primary-color) var(--progress, 0%), rgba(255, 255, 255, 0.12) var(--progress, 0%));
  cursor: pointer;
}
.seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}
.seek-bar::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  border: none;
  cursor: pointer;
}

/* ---------- A-B Loop Panel ---------- */
.ab-panel {
  display: none;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.75rem;
  align-items: end;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 0.85rem;
}
.ab-panel.open { display: grid; }

.ab-field { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.75rem; color: var(--text-muted); }
.ab-field label span { color: var(--text-main); font-weight: 600; margin-left: 4px; }

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--surface-border);
  color: var(--text-main);
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  font-size: 0.78rem;
  cursor: pointer;
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.1); }

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.72rem;
  cursor: pointer;
  text-decoration: underline;
  justify-self: end;
}

/* ---------- Toast ---------- */
.toast {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-main);
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: 999px;
  padding: 0.6rem 1rem;
}

/* ---------- Footer ---------- */
.app-footer { text-align: center; }
.app-footer p { font-size: 0.68rem; color: var(--text-muted); line-height: 1.6; }
kbd {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--surface-border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.65rem;
  font-family: inherit;
}

/* ---------- Responsive ---------- */
@media (max-width: 420px) {
  .app-header h1 { font-size: 1.15rem; }
  .btn-install span { display: none; }
  .ab-panel { grid-template-columns: 1fr 1fr; }
  .btn-text { grid-column: 1 / -1; justify-self: center; }
  .time { width: 28px; }
}

@media (max-width: 480px) {
  body { padding: 0.6rem; }
  .player-card { padding: 1rem; border-radius: 16px; }
  .btn-icon { width: 42px; height: 42px; }
  .btn-play { width: 50px; height: 50px; }
  .seek-bar { height: 6px; }
  .seek-bar::-webkit-slider-thumb { width: 18px; height: 18px; }
  .seek-bar::-moz-range-thumb { width: 18px; height: 18px; }
  .btn-pill { padding: 0.6rem 0.85rem; font-size: 0.74rem; }
  .btn-pill span { display: none; }
  .search-result { padding: 0.6rem; }
  .chip-toggle { padding: 0.5rem 0.8rem; }
}
