:root {
  --bg: #121110;
  --surface: #1b1a18;
  --surface-2: #24221f;
  --line: #34312c;
  --text: #ece7df;
  --muted: #9a938a;
  --accent: #e8a33d;
  --accent-ink: #1a1206;
  --ok: #7cc58a;
  --warn: #e8c23d;
  --bad: #ef7a6b;
  --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --player-h: 84px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f3ee;
    --surface: #ffffff;
    --surface-2: #efebe4;
    --line: #ddd6cb;
    --text: #1d1b18;
    --muted: #6f685e;
    --accent: #b8741a;
    --accent-ink: #ffffff;
    --ok: #2f8a43;
    --warn: #9a7500;
    --bad: #c2402f;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
code, pre { font-family: var(--mono); font-size: 0.86em; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.ellipsis { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.error { color: var(--bad); min-height: 1.2em; margin: 0; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; }

/* Brand */
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 700; letter-spacing: -0.01em; }
.brand-lg { font-size: 1.6rem; }
.brand .mark { width: 1.15em; height: 1.15em; display: block; }
.wordmark { font-weight: 500; letter-spacing: -0.02em; }
.wordmark b { font-weight: 800; color: var(--accent); }
.about { font-size: .82rem; color: var(--muted); text-align: center; padding-top: .5rem; }
.disc {
  width: 1.15em; height: 1.15em; border-radius: 50%;
  background: radial-gradient(circle, var(--bg) 0 22%, transparent 23%),
              conic-gradient(from 30deg, var(--accent), #f3d08f, var(--accent), #c9822a, var(--accent));
}

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; padding: .5rem .95rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: transparent; cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.icon-btn.play { width: 42px; height: 42px; background: var(--text); color: var(--bg); }
.icon-btn.play:hover { background: var(--accent); }
input[type=text], input[type=password], input[type=search], input:not([type]), select {
  width: 100%; padding: .55rem .7rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); outline: none;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
label { display: grid; gap: .3rem; font-size: .9rem; color: var(--muted); }
label input, label select { color: var(--text); }
input[type=range] { accent-color: var(--accent); width: 100%; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: min(380px, 100%); display: grid; gap: 1rem; padding: 2rem; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line);
}
.auth-card p { margin: 0; }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1.5rem;
  padding: .75rem 1.25rem; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: .25rem; overflow-x: auto; }
.tabs a { padding: .4rem .75rem; border-radius: 8px; color: var(--muted); display: inline-flex; gap: .4rem; align-items: center; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); background: var(--surface-2); }
.view { padding: 1.5rem 1.25rem calc(var(--player-h) + 5rem); max-width: 1200px; margin: 0 auto; }
.toolbar { display: flex; gap: .75rem; align-items: center; margin-bottom: 1.25rem; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1 1 220px; width: auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; }
.stack { display: grid; gap: 1rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row > input, .row > select { width: auto; flex: 1 1 150px; }
.spacer { flex: 1; }
.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }

/* Pills */
.pill { font-size: .72rem; padding: .05rem .45rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill:empty { display: none; }
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }
.pill.bad { color: var(--bad); }
.pill.busy { color: var(--accent-ink); background: var(--accent); }

/* Album grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1.25rem 1rem; }
.album-card { display: grid; gap: .45rem; }
.album-card:hover .art { transform: translateY(-2px); box-shadow: 0 8px 24px rgb(0 0 0 / .3); }
.art {
  position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface-2);
  transition: transform .15s ease, box-shadow .15s ease; display: grid; place-items: center;
}
.art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.art .initials { position: absolute; font-size: 2rem; font-weight: 700; color: var(--muted); opacity: .5; }
.art img + .initials { display: none; }
.art.missing img { display: none; }
.art.missing .initials { display: block; }
.album-card .t { font-weight: 600; font-size: .92rem; }
.album-card .a { font-size: .85rem; }

/* Album detail */
.album-head { display: grid; grid-template-columns: 220px 1fr; gap: 1.5rem; align-items: end; margin-bottom: 1.5rem; }
.album-head .art { width: 220px; }
.tracks { list-style: none; margin: 0; padding: 0; }
.track {
  display: grid; grid-template-columns: 2.5rem 1fr auto auto; gap: .75rem; align-items: center;
  padding: .55rem .5rem; border-radius: 8px; cursor: pointer;
}
.track:hover { background: var(--surface-2); }
.track.current { color: var(--accent); }
.track .n { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.track .d { color: var(--muted); font-variant-numeric: tabular-nums; }
.track .icon-btn { width: 30px; height: 30px; opacity: 0; }
.track:hover .icon-btn, .track .icon-btn:focus-visible { opacity: 1; }

/* Rip */
.drive { display: flex; gap: 1rem; align-items: center; }
.drive .disc { width: 56px; height: 56px; flex: none; }
.drive.spinning .disc { animation: spin 1.6s linear infinite; }
.drive.idle .disc { filter: grayscale(1); opacity: .45; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .drive.spinning .disc { animation: none; } }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .4s ease; }
.log {
  max-height: 340px; overflow: auto; margin: 0; padding: .9rem 1rem; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word;
}
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* Upload */
.dropzone {
  display: grid; gap: 1rem; justify-items: center; text-align: center; padding: 2.5rem 1.25rem;
  border: 2px dashed var(--line); border-radius: 14px; background: var(--surface);
  transition: border-color .15s ease, background .15s ease;
}
.dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.dropzone > .disc { width: 48px; height: 48px; }
.dropzone .row { justify-content: center; }
label.check { display: inline-flex; flex-direction: row; align-items: center; gap: .45rem; cursor: pointer; }
label.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.uploads { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; }
.upload {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(7rem, auto); gap: .25rem 1rem;
  align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--line); font-size: .9rem;
}
.upload .progress { grid-column: 1 / -1; height: 4px; }
.upload .size { font-variant-numeric: tabular-nums; }
.upload .state { text-align: right; color: var(--muted); font-size: .85rem; }
.upload .state.done { color: var(--ok); }
.upload .state.exists { color: var(--warn); }
.upload .state.error { color: var(--bad); }
.upload .state.uploading { color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Player bar */
.playerbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: var(--player-h);
  display: grid; grid-template-columns: 56px minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, 1fr); gap: 1rem; align-items: center;
  padding: 0 1.25rem; padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.pb-art { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; background: var(--surface-2); }
.pb-art:not([src]), .pb-art[src=""] { visibility: hidden; }
.pb-title { font-weight: 600; }
.pb-artist { font-size: .88rem; }
.pb-center { display: grid; gap: .2rem; justify-items: center; }
.pb-controls { display: flex; gap: .5rem; align-items: center; }
.pb-progress { display: grid; grid-template-columns: 3rem 1fr 3rem; gap: .5rem; align-items: center; width: 100%; }
.time { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }
.pb-right { display: flex; gap: 1rem; align-items: center; justify-content: flex-end; }
.volume { display: flex; flex-direction: row; align-items: center; gap: .4rem; width: 140px; }
.volume svg { width: 18px; height: 18px; fill: var(--muted); flex: none; }
.format { font-family: var(--mono); font-size: .75rem; color: var(--ok); white-space: nowrap; }

.browser-player {
  position: fixed; left: 0; right: 0; bottom: var(--player-h); z-index: 19;
  display: flex; gap: 1rem; align-items: center; padding: .5rem 1.25rem;
  background: var(--surface-2); border-top: 1px solid var(--line);
}
.browser-player audio { flex: 1; height: 36px; min-width: 0; }
.bp-info { display: grid; min-width: 0; max-width: 35%; }
.bp-info .label { font-size: .72rem; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--player-h) + 1.25rem); transform: translateX(-50%); z-index: 30;
  padding: .6rem 1rem; border-radius: 8px; background: var(--text); color: var(--bg); font-size: .9rem;
  max-width: calc(100% - 32px);
}

@media (max-width: 760px) {
  :root { --player-h: 128px; }
  .topbar { gap: .75rem; padding: .6rem 16px; }
  .topbar .brand { display: none; }
  .view { padding-left: 16px; padding-right: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .album-head { grid-template-columns: 1fr; }
  .album-head .art { width: min(260px, 100%); }
  .playerbar {
    grid-template-columns: 48px minmax(0, 1fr) auto; grid-template-rows: auto auto;
    padding: .6rem 16px calc(.6rem + env(safe-area-inset-bottom)); gap: .4rem .75rem; height: auto; min-height: var(--player-h);
  }
  .pb-art { width: 48px; height: 48px; }
  .pb-center { grid-column: 1 / -1; grid-row: 2; }
  .pb-right { grid-column: 3; grid-row: 1; }
  .volume { display: none; }
  .track { grid-template-columns: 2rem 1fr auto; }
  .track .icon-btn { display: none; }
}
