:root {
  --bg: #14110e;
  --bg-2: #1c1814;
  --ink: #f6f0e6;
  --muted: #b5a99a;
  --line: rgba(246, 240, 230, 0.1);
  --gold: #e2b15a;
  --gold-2: #c9933c;
  --green: #8fbf9a;
  --red: #d37a6b;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(226, 177, 90, 0.12), transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: Outfit, system-ui, sans-serif;
}

.login-page { max-width: 520px; }
.login-panel { margin-top: 8px; }

.page {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 80px;
}

.hero h1 {
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(2.4rem, 5vw, 3.6rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 8px 0 12px;
}

.eyebrow {
  color: var(--gold);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.75rem;
  font-weight: 600;
  margin: 0;
}

.lede, .hint, .status, label {
  color: var(--muted);
}

.lede { margin: 0 0 32px; max-width: 42rem; line-height: 1.5; }

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

.panel, .track {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.panel { padding: 22px; }

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.tab {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font: inherit;
}

.tab.is-active {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

label { display: block; font-size: 0.9rem; margin-bottom: 8px; }

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

input[type="text"], input[type="password"], input[type="search"], textarea, select {
  width: 100%;
  background: #100e0c;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
}

input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}

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

.dropzone {
  display: grid;
  place-items: center;
  min-height: 140px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #100e0c;
  cursor: pointer;
  padding: 20px;
  text-align: center;
}

.dropzone input { display: none; }
.dropzone.is-hover { border-color: var(--gold); }

.actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.btn {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 999px;
  padding: 11px 18px;
  cursor: pointer;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(180deg, var(--gold), var(--gold-2));
  color: #1a140c;
}

.btn.ghost, .btn.small {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn.small { padding: 7px 12px; font-size: 0.85rem; }

.btn.danger { color: #e0564a; }

.btn.ghost.danger {
  border-color: rgba(224, 86, 74, 0.35);
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
}

.linkish {
  background: none;
  border: 0;
  color: var(--gold);
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.hint { margin: 0; font-size: 0.85rem; }

.results { margin-top: 28px; }
.is-hidden,
:not(dialog)[hidden] {
  display: none !important;
}

dialog.modal[open] {
  display: block;
}

.results-bar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.results-bar h2 {
  font-family: Fraunces, Georgia, serif;
  margin: 0 0 4px;
}

.results-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.progress {
  height: 6px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 16px;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--gold);
  transition: width 0.25s ease;
}

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

.track { padding: 16px; }

.track-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.track-query {
  width: 100%;
  font-weight: 600;
}

.badge {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.badge.ok { color: var(--green); border-color: rgba(143, 191, 154, 0.4); }
.badge.err { color: #e7b2a8; border-color: rgba(211, 122, 107, 0.45); }
.badge.wait { color: var(--gold); }

.pick {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 14px;
  margin-top: 14px;
}

.pick img {
  width: 120px;
  height: 68px;
  object-fit: cover;
  border-radius: 10px;
  background: #000;
}

.pick h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.meta { color: var(--muted); font-size: 0.88rem; margin: 0; }

.choices {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.choice {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #100e0c;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
}

.choice.is-selected { border-color: var(--gold); }

.choice img {
  width: 72px;
  height: 40px;
  object-fit: cover;
  border-radius: 8px;
}

.track-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.error { color: #e7b2a8; margin: 10px 0 0; }

.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 0;
}

.brand {
  font-family: Fraunces, Georgia, serif;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.2rem;
}

.nav-links { display: flex; gap: 8px; flex-wrap: wrap; }

.nav-links a {
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
}

.nav-links a.is-active {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.site-footer {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 8px 0 28px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.modal {
  width: min(460px, calc(100% - 24px));
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg-2);
  color: var(--ink);
  padding: 22px;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(8, 6, 4, 0.72);
}

.modal h2 {
  font-family: Fraunces, Georgia, serif;
  margin: 6px 0 8px;
}

.modal-track {
  color: var(--muted);
  margin: 0 0 16px;
  line-height: 1.4;
}

.modal fieldset {
  border: 1px solid var(--line);
  border-radius: 14px;
  margin: 0 0 12px;
  padding: 12px;
}

.modal legend { color: var(--gold); padding: 0 6px; }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}

.check input { accent-color: var(--gold); }

.modal select, .modal input[type="text"] { margin: 4px 0 8px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions .danger {
  margin-right: auto;
}

.library {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  align-items: start;
}

.playlists-toggle {
  display: none;
}

.playlists-body {
  display: block;
}

.playlists-heading,
.library-main h2 {
  font-family: Fraunces, Georgia, serif;
  margin: 0 0 12px;
}

.playlist-list { display: grid; gap: 8px; margin: 12px 0 18px; }

.playlist-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: #100e0c;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
}

.library-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.playlist-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
}

.playlist-row.is-sortable {
  grid-template-columns: 40px 1fr auto;
  user-select: none;
}

.playlist-row.is-sortable .playlist-item {
  cursor: pointer;
}

.playlist-row.is-dragging {
  cursor: grabbing;
  opacity: 0.7;
}

.playlist-row.is-dragging .playlist-item {
  border-color: var(--gold);
  cursor: grabbing;
}

.playlist-row.is-active .playlist-item { border-color: var(--gold); }

.btn.icon {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.78rem;
}

.btn.symbol {
  min-width: 2.15rem;
  padding: 7px 8px;
  font-size: 0.95rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.btn.symbol svg,
.icon-save,
.icon-trash {
  width: 1.05em;
  height: 1.05em;
  display: block;
  flex-shrink: 0;
}

.count { color: var(--muted); }

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.inline-form .btn { white-space: nowrap; }

.library-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.library-search {
  position: relative;
  margin: 12px 0 32px;
  max-width: 36rem;
}

.library-search .search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  width: 1.15rem;
  height: 1.15rem;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.library-search input {
  width: 100%;
  padding: 14px 18px 14px 46px;
  border-radius: 999px;
  background: var(--bg-2);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
}

.library-search input::placeholder {
  color: var(--muted);
}

.library-search input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(226, 177, 90, 0.2);
}

.library-search:focus-within .search-icon {
  color: var(--gold);
}

.library-search input::-webkit-search-decoration {
  -webkit-appearance: none;
}

.library-tracks { display: grid; gap: 10px; }

.library-track {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #100e0c;
}

.library-track.is-sortable {
  grid-template-columns: 40px 72px 1fr auto;
  user-select: none;
}

.library-track.is-sortable img {
  -webkit-user-drag: none;
}

.library-track.is-sortable .track-actions {
  cursor: default;
}

.drag-handle {
  width: 40px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  display: grid;
  place-items: center;
  -webkit-tap-highlight-color: transparent;
}

.drag-handle::before {
  content: "";
  width: 12px;
  height: 18px;
  background:
    radial-gradient(circle, currentColor 1.2px, transparent 1.35px) 0 0 / 6px 6px;
  opacity: 0.85;
}

.drag-handle:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: 10px;
}

.library-track.is-dragging {
  cursor: grabbing;
  opacity: 0.7;
  border-color: var(--gold);
  box-shadow: var(--shadow);
}

body.is-reordering {
  cursor: grabbing;
  user-select: none;
}

body.is-reordering .drag-handle {
  cursor: grabbing;
}

.library-track img {
  width: 72px;
  height: 40px;
  max-width: 100%;
  object-fit: cover;
  border-radius: 8px;
}

.library-track > div {
  min-width: 0;
}

.library-track h3 {
  margin: 0 0 4px;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-track .meta {
  overflow: hidden;
  text-overflow: ellipsis;
}

.player {
  position: sticky;
  bottom: 16px;
  width: min(1100px, calc(100% - 32px));
  margin: 24px auto 0;
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.player img {
  width: 72px;
  height: 40px;
  object-fit: cover;
  border-radius: 8px;
}

.library-track.is-playing { border-color: var(--gold); }

.player-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-controls .btn { white-space: nowrap; }

.player audio { width: min(280px, 100%); }

@media (max-width: 800px) {
  .library, .player {
    grid-template-columns: 1fr;
  }
  .playlists-heading {
    display: none;
  }
  .playlists-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
  }
  .playlists-toggle-text {
    display: grid;
    gap: 2px;
    min-width: 0;
  }
  .playlists-toggle-text strong {
    font-family: Fraunces, Georgia, serif;
    font-size: 1.35rem;
  }
  .playlists-toggle-text span {
    color: var(--muted);
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .playlists-chevron {
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg);
    transition: transform 0.15s ease;
  }
  .playlists-panel.is-open .playlists-chevron {
    transform: rotate(225deg);
    margin-top: 6px;
  }
  .playlists-panel:not(.is-open) {
    padding-top: 16px;
    padding-bottom: 16px;
  }
  .playlists-body {
    display: none;
    margin-top: 14px;
  }
  .playlists-panel.is-open .playlists-body {
    display: block;
  }
  .library-track {
    grid-template-columns: 72px 1fr;
  }
  .library-track .track-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
    flex-wrap: wrap;
  }
  .library-track.is-sortable {
    grid-template-columns: 40px 72px 1fr;
  }
  .library-track.is-sortable .drag-handle {
    grid-row: 1 / 3;
    height: 100%;
    min-height: 44px;
  }
  .library-track.is-sortable .track-actions {
    grid-column: 2 / -1;
  }
  .player-controls { justify-content: space-between; }
}

@media (max-width: 640px) {
  .pick { grid-template-columns: 1fr; }
  .pick img { width: 100%; height: 150px; }
}

.config-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.config-status .status { margin: 0; }

.cookie-label { margin-top: 18px; }

.cookie-upload {
  position: relative;
}

.cookie-upload input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.cookies-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  min-height: 280px;
  line-height: 1.45;
  white-space: pre;
}

#config-ok { color: var(--green); }

.panel h2 {
  font-family: Fraunces, Georgia, serif;
  margin: 0 0 12px;
  font-size: 1.35rem;
}

.steps {
  margin: 0 0 16px;
  padding-left: 1.2rem;
  color: var(--muted);
  line-height: 1.55;
}

.steps li { margin: 6px 0; }

.config-advanced {
  margin: 16px 0 8px;
  color: var(--muted);
}

.config-advanced summary {
  cursor: pointer;
  margin-bottom: 12px;
}

.config-advanced select { margin-top: 8px; }
