* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f7fb;
  color: #182235;
}

.app-header {
  background: linear-gradient(135deg, #172033, #2f466c);
  color: white;
  padding: 38px 18px;
}

.app-header > div,
.container {
  max-width: 960px;
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 8px;
  opacity: .75;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1, h2, p {
  margin-top: 0;
}

.lead {
  margin-bottom: 0;
  opacity: .9;
}

.container {
  padding: 22px 14px 48px;
}

.card,
.track,
.empty,
.alert {
  background: white;
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(20, 32, 50, .08);
}

.card {
  padding: 20px;
  margin-bottom: 18px;
}

form label {
  display: block;
  font-weight: 700;
  margin-bottom: 14px;
}

input[type="text"],
input[type="file"] {
  display: block;
  width: 100%;
  margin-top: 7px;
  padding: 12px;
  border: 1px solid #d7deea;
  border-radius: 12px;
  background: #fbfcff;
}

button,
.download {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  background: #2563eb;
  color: white;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
}

button:hover,
.download:hover {
  filter: brightness(.96);
}

button.danger {
  background: #dc2626;
}

.note {
  color: #607089;
  font-size: 13px;
  margin: 12px 0 0;
}

.alert {
  padding: 14px 16px;
  margin-bottom: 16px;
  font-weight: 700;
}

.alert.success {
  border-left: 6px solid #16a34a;
}

.alert.error {
  border-left: 6px solid #dc2626;
}

#audioPlayer {
  width: 100%;
  margin-top: 10px;
}

.now-playing {
  padding: 12px;
  background: #eef4ff;
  border-radius: 12px;
  font-weight: 700;
}

.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.track-list h2 {
  margin: 22px 0 12px;
}

.track {
  padding: 15px;
  margin-bottom: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

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

.track-main strong,
.track-main span,
.track-main small {
  display: block;
}

.track-main span {
  color: #536278;
  margin-top: 3px;
}

.track-main small {
  color: #7b8798;
  margin-top: 5px;
  word-break: break-all;
}

.track-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.track-actions form {
  margin: 0;
}

.empty {
  padding: 18px;
  color: #607089;
}

@media (max-width: 680px) {
  .track {
    align-items: stretch;
    flex-direction: column;
  }

  .track-actions {
    justify-content: stretch;
  }

  .track-actions > *,
  .track-actions button,
  .track-actions .download {
    flex: 1;
  }
}

.offline-status {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f8fafc;
  color: #536278;
  font-size: 14px;
}

.offlineBtn.saved {
  background: #16a34a;
}

.track.active {
  outline: 2px solid #93c5fd;
}

@media (display-mode: standalone) {
  .app-header {
    padding-top: 48px;
  }
}

.quick-nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 16px;
  padding-bottom: 4px;
}

.quick-nav a {
  white-space: nowrap;
  color: #172033;
  background: #fff;
  border-radius: 999px;
  padding: 10px 14px;
  text-decoration: none;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(20, 32, 50, .06);
}

.section-title-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title-row h2 {
  margin-bottom: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.stat-card {
  border: 1px solid #e4e9f2;
  border-radius: 16px;
  padding: 13px;
  background: #fbfcff;
}

.stat-card span,
.saved-item span,
.saved-item small {
  display: block;
  color: #607089;
  font-size: 13px;
}

.stat-card strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.saved-stat {
  background: #ecfdf5;
  border-color: #bbf7d0;
}

.offline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

button.subtle,
.subtle {
  background: #e8eef8;
  color: #172033;
}

button.danger-outline,
.danger-outline {
  background: #fff1f2;
  color: #be123c;
  border: 1px solid #fecdd3;
}

button.active-filter {
  background: #172033;
  color: white;
}

.progress-wrap {
  margin: 14px 0;
}

.progress-bar {
  height: 10px;
  border-radius: 999px;
  background: #e5eaf3;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: #2563eb;
  transition: width .2s ease;
}

.offline-saved-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.saved-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid #e5eaf3;
}

.saved-item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.saved-item-actions button {
  min-height: 36px;
  padding: 8px 12px;
}

.empty.small {
  box-shadow: none;
  background: #f8fafc;
  padding: 14px;
}

.track-title-line {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
  background: #e5e7eb;
  color: #374151;
}

.badge.saved {
  background: #dcfce7;
  color: #166534;
}

.badge.unsaved {
  background: #fff7ed;
  color: #9a3412;
}

.track.offline-saved {
  border: 1px solid #bbf7d0;
}

.track.offline-unsaved {
  border: 1px solid transparent;
}

button:disabled {
  opacity: .75;
  cursor: not-allowed;
}

@media (max-width: 680px) {
  .section-title-row {
    flex-direction: column;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .offline-actions > *,
  .saved-item-actions > * {
    flex: 1;
  }

  .saved-item {
    align-items: stretch;
    flex-direction: column;
  }
}

.player-status-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  margin-top: 10px;
}

.player-status-row .offline-status {
  flex: 1;
  margin-top: 0;
}

.connection {
  min-width: 120px;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.connection.online {
  background: #dcfce7;
  color: #166534;
}

.connection.offline {
  background: #fee2e2;
  color: #991b1b;
}

.connection.checking {
  background: #e5e7eb;
  color: #374151;
}

.ready-stat {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.offline-check-panel {
  border: 1px solid #dbeafe;
  border-radius: 16px;
  padding: 14px;
  background: #f8fbff;
  margin: 12px 0;
}

.offline-check-panel strong {
  display: block;
  color: #1d4ed8;
  margin-bottom: 6px;
}

.offline-check-panel p {
  margin: 6px 0 0;
  color: #536278;
  font-size: 14px;
}

.offline-health {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
}

.offline-health.ready {
  background: #ecfdf5;
  color: #166534;
}

.offline-health.not-ready {
  background: #fff7ed;
  color: #9a3412;
}

.offline-health.checking,
.badge.checking {
  background: #eef2ff;
  color: #3730a3;
}

.track.offline-saved {
  border: 2px solid #86efac;
  background: #fbfffd;
}

.track.offline-unsaved {
  border: 1px solid #e5eaf3;
}

@media (max-width: 680px) {
  .player-status-row {
    flex-direction: column;
  }

  .connection {
    width: 100%;
  }
}
