* {
  box-sizing: border-box;
}

:root {
  --bg-1: #f4f8f6;
  --bg-2: #ecf2ff;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-strong: #ffffff;
  --text: #15221b;
  --muted: #576a60;
  --line: #d8e2dc;
  --spotify: #1db954;
  --spotify-deep: #168944;
  --pill: #eff7f2;
  --danger: #a33232;
  --success-bg: #e9f8ee;
  --success-text: #155724;
  --success-line: #b9e6c6;
  --error-bg: #fdecec;
  --error-text: #7f1d1d;
  --error-line: #f6c6c6;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 12% -8%, #d8efe0 0%, transparent 70%),
    radial-gradient(900px 420px at 98% 3%, #dce7ff 0%, transparent 72%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 100%);
  min-height: 100vh;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

.stack {
  display: grid;
  gap: 14px;
}

.product-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.tabs-nav {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid #d5dfdb;
  border-radius: 999px;
  padding: 5px;
  gap: 4px;
}

.nav a {
  color: #294438;
  text-decoration: none;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
}

.nav a.active {
  background: #173d2f;
  color: #ffffff;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-items: end;
}

.account-session {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.account-login-btn {
  white-space: nowrap;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

button {
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
  background: var(--spotify);
  color: #ffffff;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(22, 137, 68, 0.2);
  background: var(--spotify-deep);
}

button:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

button.secondary {
  background: #173d2f;
}

button.secondary:hover:not(:disabled) {
  background: #0f2c22;
  box-shadow: 0 6px 18px rgba(15, 44, 34, 0.3);
}

button.ghost {
  background: #f0f4f7;
  color: #2a3a34;
  border: 1px solid #d0d9de;
}

button.ghost:hover:not(:disabled) {
  background: #e8edf3;
  box-shadow: none;
}

.card {
  background: var(--surface);
  border: 1px solid rgba(216, 226, 220, 0.92);
  border-radius: 18px;
  padding: 18px;
  backdrop-filter: blur(7px);
  box-shadow: 0 10px 30px rgba(17, 48, 35, 0.06);
}

.hero-card h1 {
  margin: 0 0 6px;
  font-size: clamp(1.45rem, 3vw, 2rem);
}

.hero-card p {
  margin: 0;
  color: #375246;
  max-width: 64ch;
}

.section-heading h1,
h1,
h2,
h3 {
  margin: 0;
}

.section-heading p {
  margin: 6px 0 0;
}

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  color: #223a31;
}

textarea,
input[type="text"] {
  width: 100%;
  border-radius: 14px;
  border: 1px solid #cfdbd4;
  background: rgba(255, 255, 255, 0.82);
  padding: 12px 13px;
  color: #163126;
  font-size: 14px;
}

textarea {
  min-height: 180px;
  resize: vertical;
}

textarea:focus,
input[type="text"]:focus {
  outline: 2px solid rgba(29, 185, 84, 0.35);
  border-color: #8ccfab;
}

.notification {
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 14px;
  border: 1px solid transparent;
}

.notification.success {
  background: var(--success-bg);
  border-color: var(--success-line);
  color: var(--success-text);
}

.notification.error {
  background: var(--error-bg);
  border-color: var(--error-line);
  color: var(--error-text);
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.account-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border-radius: 999px;
  padding: 7px 12px 7px 8px;
  border: 1px solid #d5e1da;
  background: var(--pill);
  min-width: 220px;
}

.account-text {
  min-width: 0;
}

.account-empty {
  background: #f4f7f6;
}

.account-avatar,
.account-avatar-image {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
}

.account-avatar {
  display: grid;
  place-items: center;
  background: #173d2f;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
}

.account-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}

.account-meta {
  font-size: 12px;
  color: #496156;
  line-height: 1.2;
}

.logout-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-weight: 800;
  line-height: 1;
}

.account-pill-logout {
  margin-left: 6px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  width: 16px;
  height: 16px;
  display: inline-block;
  flex-shrink: 0;
}

.app-grid {
  gap: 14px;
}

.composer-card {
  gap: 12px;
  padding: 20px;
}

.playlist-inline-controls {
  margin-top: 4px;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid #dde6e1;
}

.composer-card #results {
  margin-top: 2px;
}

#playlistSection .row {
  margin-top: 0;
}

#createPlaylistBtn {
  min-width: 170px;
}

.song-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 8px;
  background: var(--surface-strong);
  overflow: hidden;
}

.song-group.not-found {
  border-color: #efc5c5;
}

.selected-track {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
}

.selected-track-info {
  flex: 1;
  min-width: 0;
}

.selected-track-name,
.alt-name,
.alt-artist,
.alt-album,
.playlist-name,
.playlist-meta {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selected-track-name {
  font-weight: 700;
}

.selected-track-artist,
.alt-artist,
.playlist-meta {
  font-size: 13px;
  color: var(--muted);
}

.toggle-alternatives-btn {
  font-size: 12px;
  padding: 7px 10px;
}

.alternatives-list {
  border-top: 1px solid #eaf0ed;
  max-height: 260px;
  overflow-y: auto;
}

.alternative-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  border-bottom: 1px solid #f0f4f2;
  cursor: pointer;
}

.alternative-item:hover {
  background: #f4faf6;
}

.alternative-item.active {
  background: #ebf8ef;
  border-left: 3px solid var(--spotify);
}

.alt-check {
  width: 60px;
  font-size: 11px;
  font-weight: 700;
  color: var(--spotify-deep);
}

.alt-info {
  min-width: 0;
}

.alt-name {
  font-size: 14px;
  font-weight: 700;
}

.alt-album {
  font-size: 11px;
  color: #769184;
}

.search-summary {
  font-size: 14px;
  color: #2e4f43;
  margin-top: 6px;
}

#playlistsList {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-strong);
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid #edf2f0;
}

.playlist-item:last-child {
  border-bottom: none;
}

.playlist-name {
  font-weight: 700;
  flex: 1;
  color: #147a3d;
  text-decoration: none;
}

.playlist-name:visited {
  color: #147a3d;
}

.playlist-name:hover {
  text-decoration: underline;
}

.playlist-badge {
  font-size: 10px;
  font-weight: 700;
  color: #1e7e43;
  background: #ebf7ef;
  border-radius: 999px;
  padding: 5px 8px;
}

.playlist-link {
  color: #147a3d;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}

.playlist-link:hover {
  text-decoration: underline;
}

.text-link {
  color: #147a3d;
  text-decoration: none;
}

.text-link:hover {
  text-decoration: underline;
}

.error-text {
  color: var(--danger);
}

.history-list {
  display: grid;
  gap: 10px;
}

.period-select {
  border: 1px solid #d0d9de;
  background: #ffffff;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  color: #1f3229;
}

.subtabs {
  display: inline-flex;
  gap: 6px;
  background: #f2f6f8;
  border: 1px solid #d5dde3;
  border-radius: 999px;
  padding: 5px;
  width: fit-content;
}

.tabs-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.subtab-btn {
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
}

.subtab-btn.active {
  background: #173d2f;
  color: #ffffff;
  border-color: #173d2f;
}

.subtab-btn.active:hover:not(:disabled) {
  background: #0f2c22;
}

.panel-actions {
  display: flex;
  justify-content: center;
}

.stats-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stats-card {
  border: 1px solid #dce5e0;
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.9);
}

.stats-card h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.stats-card .panel-actions {
  margin-top: 10px;
}

.stats-more-btn {
  width: 100%;
}

.stats-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.stats-list li {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 6px;
  align-items: baseline;
}

.stats-rank {
  font-weight: 700;
  color: #3f5f50;
}

.stats-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-meta {
  grid-column: 2;
  font-size: 12px;
  color: #54695f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid #dce5e0;
  border-radius: 14px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.9);
}

.history-art-wrap {
  width: 56px;
  height: 56px;
}

.history-art {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  object-fit: cover;
  background: #e7edeb;
}

.history-art-empty {
  border: 1px dashed #c9d4ce;
}

.history-main {
  min-width: 0;
}

.history-title {
  margin: 0;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-sub,
.history-album {
  margin: 2px 0 0;
  font-size: 13px;
  color: #486154;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-side {
  text-align: right;
  font-size: 12px;
  color: #4b6558;
  display: grid;
  gap: 5px;
}

@media (max-width: 860px) {
  .product-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-right {
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  .tabs-toolbar {
    align-items: stretch;
  }

  .tabs-toolbar .period-select {
    width: 100%;
  }

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

  .history-item {
    grid-template-columns: auto 1fr;
  }

  .history-side {
    grid-column: 1 / -1;
    text-align: left;
  }

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