:root {
  color-scheme: dark;
  --bg: #080b10;
  --surface: #11161e;
  --surface-2: #171d27;
  --text: #f5f7fa;
  --muted: #99a3b1;
  --line: #29313d;
  --accent: #47a7ff;
  --accent-soft: #122a40;
  --success: #4ed695;
  --danger: #ff7186;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  width: min(100%, 620px);
  min-height: 100dvh;
  margin: 0 auto;
  padding-bottom: calc(86px + env(safe-area-inset-bottom));
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(15px + env(safe-area-inset-top)) 18px 13px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand h1 { margin: 0; font-size: 18px; line-height: 1; letter-spacing: .08em; font-weight: 700; }
.brand p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }

.logo {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 12px;
  background: var(--accent);
  color: #07111b;
}

.logo span { width: 2px; border-radius: 3px; background: currentColor; }
.logo span:nth-child(1) { height: 9px; }
.logo span:nth-child(2) { height: 17px; }
.logo span:nth-child(3) { height: 13px; }
.logo span:nth-child(4) { height: 7px; }

.profile {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}

main { padding: 16px 14px 12px; }

.view[hidden] { display: none; }

.search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.search-field { position: relative; }
.search-field > span {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-52%);
  color: var(--muted);
  font-size: 22px;
  pointer-events: none;
}

.search-field input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px 10px 41px;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  background: var(--surface);
  color: var(--text);
}

.search-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.primary-button {
  min-height: 46px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #07111b;
  font-weight: 650;
  cursor: pointer;
}

.primary-button:disabled { opacity: .55; cursor: progress; }

.source-row {
  display: flex;
  align-items: center;
  gap: 7px;
  overflow-x: auto;
  padding: 12px 0 2px;
  scrollbar-width: none;
}

.source-row::-webkit-scrollbar { display: none; }

.source-chip {
  flex: 0 0 auto;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.source-chip.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.source-note { flex: 0 0 auto; color: var(--muted); font-size: 11px; }

.import-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
}

.import-form input {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: none;
  background: var(--surface);
  color: var(--text);
}

.import-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.import-form button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

.import-form button:disabled { opacity: .55; cursor: progress; }
.import-hint { margin: 6px 3px 0; color: var(--muted); font-size: 10px; }

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 18px 2px 9px;
}

.section-heading h2 { margin: 0; font-size: 17px; font-weight: 650; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.section-heading > span { color: var(--muted); font-size: 12px; white-space: nowrap; }

.track-list { display: grid; gap: 8px; }

.track-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 68px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 16px;
  background: var(--surface);
}

.track-card.playing { border-color: var(--accent); background: var(--accent-soft); }

.artwork-wrap { position: relative; width: 50px; height: 50px; }
.artwork,
.artwork-fallback {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  object-fit: cover;
  background: linear-gradient(145deg, #766cff, #32a5d8);
}

.artwork-fallback { display: grid; place-items: center; color: white; font-weight: 700; }

.artwork-play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: rgba(5, 8, 13, .36);
  color: white;
  opacity: 0;
  cursor: pointer;
}

.artwork-wrap:hover .artwork-play,
.artwork-play:focus-visible,
.track-card.playing .artwork-play { opacity: 1; }
.artwork-play:disabled { cursor: not-allowed; opacity: .35; }

.track-copy { min-width: 0; }
.track-title, .track-artist, .track-album { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-title { font-size: 14px; font-weight: 650; }
.track-artist { margin-top: 3px; color: var(--muted); font-size: 12px; }
.track-album { display: flex; align-items: center; gap: 6px; min-width: 0; margin-top: 5px; color: var(--muted); font-size: 10px; }
.track-album > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.explicit { margin-left: 5px; color: var(--muted); font-size: 9px; vertical-align: 1px; }

.availability {
  flex: 0 0 auto;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 9px;
}
.availability.full { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.availability.embed { background: var(--accent-soft); color: var(--accent); }
.availability.link { background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--accent); }

.provider-links {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
}
.provider-links a { color: var(--accent); text-decoration: none; }

.track-actions { display: flex; gap: 2px; }
.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
}
.icon-button:hover { background: var(--surface-2); color: var(--text); }
.icon-button.saved { color: var(--success); }

.status-block {
  padding: 34px 18px;
  border-radius: 16px;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}
.status-block strong { display: block; margin-bottom: 5px; color: var(--text); }
.status-block.error strong { color: var(--danger); }

.skeleton {
  height: 68px;
  border-radius: 16px;
  background: linear-gradient(90deg, var(--surface) 20%, var(--surface-2) 50%, var(--surface) 80%);
  background-size: 200% 100%;
  animation: pulse 1.25s linear infinite;
}

@keyframes pulse { to { background-position: -200% 0; } }

.provider-credit { margin: 11px 4px 0; color: var(--muted); font-size: 10px; line-height: 1.45; }

.toast {
  min-height: 20px;
  padding: 0 14px;
  color: var(--accent);
  text-align: center;
  font-size: 11px;
}

.embed-player {
  position: sticky;
  z-index: 18;
  bottom: calc(68px + env(safe-area-inset-bottom));
  margin: 4px 10px 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 10px 35px rgba(0, 0, 0, .28);
}

.embed-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 3px 7px;
}
.embed-heading strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.embed-heading button { width: 28px; height: 28px; border: 0; border-radius: 9px; background: var(--surface-2); color: var(--text); cursor: pointer; }
.embed-player iframe { display: block; width: 100%; min-height: 152px; border: 0; border-radius: 12px; background: var(--surface-2); }

.player {
  position: sticky;
  z-index: 19;
  bottom: calc(68px + env(safe-area-inset-bottom));
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin: 4px 10px 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: 0 10px 35px rgba(0, 0, 0, .28);
  backdrop-filter: blur(18px);
}
.player:not([hidden]) { display: grid; }
.player-cover { width: 44px; height: 44px; border-radius: 11px; overflow: hidden; }
.player-cover img { width: 100%; height: 100%; object-fit: cover; }
.player-main { min-width: 0; }
.player-copy { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.player-copy > div { min-width: 0; }
.player-copy strong, .player-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-copy strong { font-size: 13px; }
.player-copy span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.player-copy time { flex: 0 0 auto; color: var(--muted); font-size: 9px; }

.progress {
  width: 100%;
  height: 12px;
  margin-top: 5px;
  padding: 0;
  border: 0;
  background: linear-gradient(var(--line), var(--line)) center / 100% 3px no-repeat;
  cursor: pointer;
}
.progress span { display: block; width: 0; height: 3px; border-radius: 3px; background: var(--accent); }
.player-toggle { width: 38px; height: 38px; border: 0; border-radius: 11px; background: transparent; color: var(--text); cursor: pointer; }

.bottom-nav {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 0;
  width: min(100%, 620px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 7px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(18px);
}

.nav-button {
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 7px 4px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
}
.nav-button span { font-size: 18px; line-height: 1; }
.nav-button.active { background: var(--accent-soft); color: var(--accent); }

@media (max-width: 380px) {
  main { padding-inline: 10px; }
  .search-form { grid-template-columns: 1fr; }
  .primary-button { width: 100%; }
  .import-form { grid-template-columns: 1fr; }
  .import-form button { width: 100%; }
  .track-card { grid-template-columns: auto minmax(0, 1fr); }
  .track-actions { grid-column: 2; justify-content: flex-end; margin-top: -3px; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}
