:root, html[data-theme="light"] {
  --bg: #f2f3f5;
  --bg2: #ffffff;
  --card: #ffffff;
  --border: #e6e7eb;
  --text: #17171c;
  --muted: #82828f;
  --accent: #ff5500;
  --accent-soft: rgba(255, 85, 0, .08);
  --wave-base: #d4d5db;
  --shadow: 0 1px 3px rgba(20, 20, 30, .07);
  --ok: #0f9d58;
  --ok-bg: #0f9d5814;
  --err: #d93025;
  --err-bg: #d9302514;
}
html[data-theme="dark"] {
  --bg: #0e0e12;
  --bg2: #16161d;
  --card: #1c1c25;
  --border: #2a2a36;
  --text: #ececf1;
  --muted: #8b8b9a;
  --accent: #ff5500;
  --accent-soft: rgba(255, 85, 0, .16);
  --wave-base: #4a4a5c;
  --shadow: none;
  --ok: #6bffa0;
  --ok-bg: #2dff7a14;
  --err: #ff6b6b;
  --err-bg: #ff2d3f18;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 96px;
}
a { color: var(--text); text-decoration: none; }
.muted { color: var(--muted); }
.error { color: var(--err); background: var(--err-bg); border: 1px solid var(--err); border-radius: 10px; padding: 8px 12px; }
.success { color: var(--ok); background: var(--ok-bg); border: 1px solid var(--ok); border-radius: 10px; padding: 8px 12px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 28px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
  box-shadow: var(--shadow);
}
.logo { font-size: 21px; font-weight: 800; letter-spacing: .5px; flex-shrink: 0; }
.logo span { color: var(--accent); }
.nav-search { flex: 1; max-width: 520px; }
.nav-search input {
  width: 100%; padding: 9px 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 14px;
}
.topbar nav { display: flex; gap: 4px; margin-left: auto; }
.topbar nav a {
  color: var(--muted); font-weight: 600; padding: 7px 14px; border-radius: 999px; font-size: 14px;
}
.topbar nav a.active { color: var(--accent); background: var(--accent-soft); }
.topbar nav a:hover { color: var(--text); }
.topbar nav a.upload-cta, .topbar nav a.upload-cta.active {
  background: var(--accent); color: #fff;
}
.theme-toggle {
  margin: 0; padding: 0; width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  font-size: 15px; cursor: pointer; flex-shrink: 0;
}
.userbox { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.nav-credits { color: var(--accent); font-size: 12px; font-weight: 800; white-space: nowrap; }
.userbox .avatar { cursor: default; }
.userbox a { color: var(--muted); font-weight: 600; font-size: 13px; }
.userbox a:hover { color: var(--accent); }

.page { max-width: 1060px; margin: 0 auto; padding: 24px 28px; }

/* ---------- 3-column shell ---------- */
.shell {
  display: grid; grid-template-columns: 220px minmax(0, 1fr) 300px;
  gap: 24px; max-width: 1500px; margin: 0 auto; padding: 24px 28px;
  align-items: start;
}
.sidebar { position: sticky; top: 78px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a, .side-up {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 14px; border-radius: 10px; font-weight: 600; font-size: 14px;
  color: var(--muted); cursor: pointer;
}
.side-nav a:hover, .side-up:hover { color: var(--text); background: var(--card); }
.side-nav a.active, .side-up.active { color: var(--accent); background: var(--accent-soft); }
.s-ic { width: 18px; text-align: center; font-size: 15px; }
.side-sec { margin-top: 26px; border-top: 1px solid var(--border); padding-top: 14px; }
.side-sec h4, .panel h4 {
  margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); font-weight: 700; padding: 0 14px;
}
.side-up { padding: 7px 14px; }
.side-add {
  margin: 0; padding: 0; width: 20px; height: 20px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
  font-size: 13px; line-height: 1; float: right;
}
.side-add:hover { color: var(--accent); border-color: var(--accent); filter: none; }
.pl-thumb { width: 30px; height: 30px; border-radius: 6px; display: inline-block; flex-shrink: 0; }
.library-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--accent); font-weight: 800;
}
.pl-menu {
  position: absolute; z-index: 60; min-width: 190px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .22); padding: 6px; display: flex; flex-direction: column;
}
.pl-menu button {
  margin: 0; padding: 8px 12px; background: none; border: none; border-radius: 8px;
  color: var(--text); font-size: 13px; font-weight: 600; text-align: left; cursor: pointer;
}
.pl-menu button:hover { background: var(--accent-soft); color: var(--accent); filter: none; }
.plbar {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.plbar[hidden] { display: none; }
.plbar-name { font-weight: 800; font-size: 17px; }
.plbar .small { margin-left: 0; }
.plbar #plbar-play { margin-left: auto; }
.librarybar {
  display: flex; align-items: center; gap: 10px; padding: 10px 0;
  margin-bottom: 14px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.librarybar[hidden] { display: none; }
.librarybar > div { display: flex; flex-direction: column; min-width: 0; margin-right: auto; }
.librarybar strong { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.librarybar .muted { font-size: 12px; margin-top: 2px; }
.mobile-library-nav { display: none; }
.side-up .q-meta { display: flex; flex-direction: column; min-width: 0; }
.side-up .q-title { font-size: 13px; font-weight: 700; color: var(--text); }
.side-up .q-sub { font-size: 12px; }

/* ---------- hero ---------- */
.hero {
  display: flex; gap: 24px;
  background: var(--card); border: 1px solid var(--border); border-radius: 18px;
  padding: 22px; margin-bottom: 24px; box-shadow: var(--shadow);
}
.hero-art {
  width: 220px; height: 220px; border-radius: 12px; flex-shrink: 0;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 16px; color: #fff;
}
.hero-art span:first-child { font-weight: 800; font-size: 20px; text-transform: uppercase; line-height: 1.15; text-shadow: 0 1px 6px rgba(0,0,0,.4); }
.hero-art span:last-child { font-size: 12px; letter-spacing: 2px; text-transform: uppercase; opacity: .85; }
.hero-art.has-art span { display: none; }
.hero-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hero-top { display: flex; align-items: center; gap: 14px; }
.hero-play { width: 52px; height: 52px; font-size: 17px; }
.hero-kicker { color: var(--muted); font-size: 13px; font-weight: 600; }
.hero-title { margin: 8px 0 2px; font-size: 30px; line-height: 1.1; }
.hero-artist { color: var(--muted); font-weight: 600; margin-bottom: 12px; }
.hero-wave { width: 100%; height: 72px; cursor: pointer; display: block; }
.hero-times { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }
.hero-actions { display: flex; gap: 10px; margin-top: 14px; align-items: center; flex-wrap: wrap; }
.pill-stat, .pill-btn {
  display: inline-flex; align-items: center; gap: 6px; margin: 0;
  padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: var(--bg); border: 1px solid var(--border); color: var(--text); cursor: default;
}
.pill-btn { cursor: pointer; }
.pill-btn.disabled { opacity: .58; cursor: not-allowed; pointer-events: none; }
.pill-btn:hover { border-color: var(--accent); color: var(--accent); filter: none; background: var(--bg); }
.tag-row { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.tag {
  padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
}
.credit-stats {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: -8px 0 22px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.credit-stats div { padding: 11px 14px; border-right: 1px solid var(--border); }
.credit-stats div:last-child { border-right: none; }
.credit-stats strong { display: block; font-size: 18px; line-height: 1.1; color: var(--text); }
.credit-stats span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }

/* ---------- right column ---------- */
.rightcol { position: sticky; top: 78px; display: flex; flex-direction: column; gap: 20px; }
.panel {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px 8px; box-shadow: var(--shadow);
}
.panel-head { display: flex; justify-content: space-between; align-items: center; padding-right: 12px; }
.autoplay-lbl { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 12px; }
.q-item {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: 10px; cursor: pointer;
}
.q-item:hover { background: var(--accent-soft); }
.q-thumb { width: 44px; height: 44px; border-radius: 8px; flex-shrink: 0; }
.q-meta { flex: 1; min-width: 0; }
.q-title { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-sub { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-time { font-size: 12px; flex-shrink: 0; }

/* ---------- auth pages ---------- */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding-bottom: 0; }
.auth-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 36px; width: min(400px, 92vw); box-shadow: var(--shadow);
}
.auth-card h2 { margin: 18px 0 4px; }
.auth-card .logo { margin: 0; }
label { display: block; margin: 14px 0 4px; color: var(--muted); font-weight: 600; font-size: 13px; }
input[type=text], input[type=password], input[type=search], input[type=number], select {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg2); color: var(--text); font-size: 15px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
button {
  margin-top: 18px; padding: 10px 22px; border: none; border-radius: 999px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 15px; cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: default; }
button.small { margin: 0; padding: 5px 14px; font-size: 13px; }
button.danger, .icon-btn.danger { background: transparent; color: var(--err); border: 1px solid var(--err); }

/* ---------- library ---------- */
.row-head, .track-primary {
  display: grid;
  grid-template-columns: minmax(180px, 1.5fr) minmax(105px, 1fr) 36px 44px 38px 38px 36px 68px;
  gap: 12px; align-items: center;
}
.row-head { padding: 0 18px 6px; }
.row-head button, .row-head span {
  margin: 0; padding: 4px 0; background: none; border: none;
  color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; text-align: left; cursor: pointer;
}
.row-head button:hover { color: var(--text); }
.row-head button.sorted { color: var(--accent); }
.cell { font-size: 13px; }
.bpm-cell { color: var(--accent); font-weight: 700; }
.date-cell { font-size: 12px; }
.avatar {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  border-radius: 50%; background: var(--bg); border: 2px solid var(--border);
  font-size: 11px; font-weight: 800; letter-spacing: .5px; cursor: default; color: var(--text);
}
.track {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 18px; margin-bottom: 10px; cursor: pointer;
  transition: border-color .15s; box-shadow: var(--shadow);
}
.track-primary { align-items: start; }
.track-secondary {
  display: grid; grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 12px; align-items: center; margin-top: 10px;
}
.track:hover { border-color: var(--accent); }
.track.playing { border-color: var(--accent); background: linear-gradient(90deg, var(--accent-soft), var(--card) 45%); }
.play-btn {
  margin: 0; width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  font-size: 15px; display: grid; place-items: center; padding: 0;
}
.track-art {
  width: 58px; height: 58px; border-radius: 8px; overflow: hidden;
  display: grid; place-items: center; box-shadow: inset 0 0 0 1px rgba(255,255,255,.16);
}
.track-art-play {
  width: 24px; height: 24px; font-size: 10px; background: rgba(255,85,0,.88);
  border: 1px solid rgba(255,255,255,.88); box-shadow: 0 2px 6px rgba(0,0,0,.28);
}
.track-art-play.is-playing {
  width: 38px; height: 38px; font-size: 14px;
  border-width: 2px; box-shadow: 0 2px 9px rgba(0,0,0,.38);
}
.t-title, .t-artist, .t-sub { white-space: normal; overflow-wrap: normal; word-break: normal; }
.t-title { font-weight: 700; line-height: 1.25; }
.t-artist { color: var(--muted); font-weight: 650; line-height: 1.25; }
.t-sub { min-width: 0; color: var(--muted); font-size: 13px; line-height: 1.35; }
.fmt {
  display: inline-block; margin-right: 8px; padding: 0 6px;
  border: 1px solid var(--border); border-radius: 4px;
  font-size: 10px; font-weight: 800; letter-spacing: .5px; color: var(--muted);
}
.fmt-warn { color: var(--err); border-color: var(--err); }
.wave {
  display: block; height: 42px;
  width: calc(100% + 36px); max-width: none; margin: 2px -18px 0; cursor: pointer;
}
.wave:hover { filter: brightness(.92); }
html[data-theme="dark"] .wave:hover { filter: brightness(1.12); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  margin: 0; width: 34px; height: 34px; padding: 0; display: grid; place-items: center;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 15px; cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); }

/* ---------- toast ---------- */
.toast {
  position: fixed; top: 76px; left: 50%; transform: translateX(-50%);
  background: var(--card); color: var(--text); border: 1px solid var(--err);
  border-left: 4px solid var(--err); border-radius: 12px; padding: 12px 18px;
  max-width: min(520px, 90vw); font-size: 14px; z-index: 50;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
}

/* ---------- player bar ---------- */
.player[hidden] { display: none; }
.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  background: var(--bg2); border-top: 1px solid var(--border);
  padding: 12px 28px;
}
.transport { display: flex; gap: 8px; align-items: center; }
.pp { margin: 0; width: 50px; height: 50px; border-radius: 50%; padding: 0; font-size: 16px; }
.skip {
  margin: 0; width: 36px; height: 36px; border-radius: 50%; padding: 0; font-size: 13px;
  background: transparent; color: var(--text); border: none;
}
.skip:hover { color: var(--accent); filter: none; }
.skip.on { color: var(--accent); }
.np-thumb { width: 46px; height: 46px; border-radius: 8px; flex-shrink: 0; }
.np { min-width: 140px; max-width: 220px; }
.np-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.np-artist { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seek { flex: 1; min-width: 0; }
.seek { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.seek canvas { flex: 1; height: 40px; min-width: 0; cursor: pointer; display: block; }
.vol { display: flex; align-items: center; gap: 8px; }
.vol input { width: 100px; }
input[type=range] { accent-color: var(--accent); }

/* ---------- upload ---------- */
.dropzone {
  border: 2px dashed var(--border); border-radius: 16px; padding: 48px 24px;
  text-align: center; cursor: pointer; background: var(--card); margin-top: 18px;
  box-shadow: var(--shadow);
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.library-destination { margin-bottom: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.library-destination > label { margin-top: 0; }
.library-destination-row { display: flex; gap: 10px; align-items: center; }
.library-destination-row select { flex: 1; }
.library-destination-row .small { flex-shrink: 0; }
.dropzone input[type=file] { display: none; }
.up-progress { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.up-bar { flex: 1; height: 8px; background: var(--bg2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.up-bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.upqueue { list-style: none; padding: 0; margin: 14px 0 0; max-height: 320px; overflow-y: auto; }
.upqueue li {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 6px 10px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.q-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-status { flex-shrink: 0; }
.q-ok { color: var(--ok); }
.q-err { color: var(--err); }
.duplicate-dialog {
  width: min(460px, calc(100vw - 32px)); padding: 22px;
  color: var(--text); background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 18px 55px rgba(20, 20, 30, .24);
}
.duplicate-dialog::backdrop { background: rgba(20, 20, 30, .46); }
.duplicate-dialog h3 { margin: 0 0 10px; }
.duplicate-dialog p { margin: 0 0 20px; line-height: 1.5; }
.duplicate-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- admin ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px 24px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.card h3 { margin-top: 0; }
.row-form label { margin-top: 10px; }
.perms { border: none; padding: 0; margin: 12px 0 0; display: flex; gap: 18px; }
.perms label { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--text); }
.admin-table { width: 100%; border-collapse: collapse; }
.table-wrap { overflow-x: auto; }
.admin-table th, .admin-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.admin-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.badge { background: var(--accent); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 999px; margin-left: 6px; }
.actions { display: flex; gap: 6px; }
.inline { display: inline; }
.tag-input { width: 64px; text-transform: uppercase; }
.admin-table input[type=color], .tagrow input[type=color] {
  width: 40px; height: 30px; padding: 2px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--bg2); cursor: pointer;
}
.tagrow { display: flex; gap: 24px; align-items: flex-end; }
.tagrow label { margin-top: 12px; }
.credit-adjust-form { display: flex; align-items: center; gap: 6px; min-width: 132px; }
.credit-adjust-form input[type=number] { width: 64px; padding: 6px 8px; }
.small-note { font-size: 12px; margin: 6px 0 0; }

@media (max-width: 1250px) {
  .shell { grid-template-columns: 200px minmax(0, 1fr); }
  .rightcol { display: none; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .mobile-library-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
  .mobile-library-nav label { margin: 0; flex-shrink: 0; }
  .mobile-library-nav select { min-width: 0; }
  .hero { flex-direction: column; }
  .hero-art { width: 100%; height: 140px; }
  .row-head, .track-primary { grid-template-columns: minmax(0, 1.5fr) minmax(70px, 1fr) 34px 34px 34px; }
  .row-head [data-sortcol="duration"], .row-head [data-sortcol="plays"], .row-head [data-sortcol="added"],
  .track-primary .duration-cell, .track-primary .plays-cell, .track-primary .date-cell { display: none; }
  .topbar { gap: 10px; padding: 10px 14px; }
  .nav-credits { display: none; }
  .vol, .nav-search, .np-thumb, .np { display: none; }
}
@media (max-width: 560px) {
  .credit-stats div { padding: 9px 8px; }
  .credit-stats strong { font-size: 16px; }
  .library-destination-row { align-items: stretch; flex-direction: column; }
  .librarybar { align-items: flex-start; flex-wrap: wrap; }
  .librarybar > div { width: 100%; }
}
