:root {
  --bg: #0a0a0b;
  --bg-2: #141416;
  --bg-3: #1d1d20;
  --line: #232327;
  --fg: #f4f4f5;
  --mute: #8b8b92;
  --dim: #5a5a61;
  --accent: #f4f4f5;
  --r: 10px;
  --mini-h: 64px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { background: var(--bg); color: var(--fg); }
html { -webkit-text-size-adjust: 100%; }
body {
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(var(--mini-h) + 24px);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
img { display: block; }
img:not([src]), img[src=""] { visibility: hidden; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.fill { fill: currentColor; stroke: none; }
[hidden] { display: none !important; }

/* respuesta táctil inmediata */
.icon, .btn, .row, .card, .tabs button, .sheet-item {
  transition: transform 90ms ease-out, opacity 90ms ease-out, background-color 120ms;
}
.icon:active, .btn:active, .card:active { transform: scale(.92); opacity: .7; }
.row:active { background: var(--bg-2); }

.icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; color: var(--fg); }

/* ---------- cabecera ---------- */
.top { display: flex; align-items: center; gap: 4px; padding: 14px 8px 6px 20px; }
.top h1 { flex: 1; font-size: 30px; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .back { margin-left: -14px; }
.top.detail h1 { font-size: 17px; font-weight: 600; text-align: center; }
.top.detail { padding-right: 52px; }
.top.detail #import, .top.detail #account { display: none; }
#account { color: var(--dim); }
#account.on { color: var(--fg); }

.bar { padding: 4px 20px 8px; }
#q {
  width: 100%; height: 38px; padding: 0 12px; border: 0; border-radius: var(--r);
  background: var(--bg-2); color: var(--fg); font: inherit; font-size: 16px; outline: none;
  -webkit-appearance: none; appearance: none;
}
#q::placeholder { color: var(--dim); }
.tabs { display: flex; gap: 22px; margin-top: 14px; border-bottom: 1px solid var(--line); }
.tabs button { padding: 6px 0 10px; color: var(--mute); font-size: 15px; font-weight: 500; position: relative; }
.tabs button.on { color: var(--fg); }
.tabs button.on::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--fg); border-radius: 2px; }

.hint { margin: 4px 20px 8px; padding: 12px 40px 12px 14px; background: var(--bg-2); border-radius: var(--r); color: var(--mute); font-size: 13px; position: relative; }
.hint b { color: var(--fg); font-weight: 600; }
.hint button { position: absolute; top: 4px; right: 6px; width: 32px; height: 32px; font-size: 20px; color: var(--mute); }

/* ---------- listas ---------- */
.list { list-style: none; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 0 4px 0 20px; height: 60px;
  content-visibility: auto; contain-intrinsic-size: auto 60px;
}
.thumb, .ph { width: 44px; height: 44px; border-radius: 6px; flex: none; background: var(--bg-3); object-fit: cover; }
.meta { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; height: 100%; border-bottom: 1px solid var(--line); }
.meta b, .meta span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta b { font-weight: 500; font-size: 16px; }
.meta span { color: var(--mute); font-size: 13px; }
.row .more { color: var(--mute); }
.row.playing .meta b { color: var(--fg); }
.row.playing .meta b::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--fg); margin: 0 7px 2px 0; vertical-align: middle; }
.row .num { width: 22px; text-align: right; color: var(--mute); font-size: 14px; font-variant-numeric: tabular-nums; flex: none; }
.row.plain { height: 54px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px 16px; padding: 16px 20px; }
.card { min-width: 0; text-align: left; }
.card img, .card .ph { width: 100%; height: auto; aspect-ratio: 1; border-radius: 8px; }
.card b, .card span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card b { margin-top: 8px; font-size: 14px; font-weight: 500; }
.card span { color: var(--mute); font-size: 13px; }

.head { padding: 8px 20px 20px; text-align: center; }
.head img, .head .ph { width: min(62vw, 260px); height: auto; aspect-ratio: 1; margin: 0 auto 16px; border-radius: 10px; box-shadow: 0 18px 40px rgba(0,0,0,.5); }
.head h2 { font-size: 21px; font-weight: 700; letter-spacing: -.01em; }
.head p { color: var(--mute); margin-top: 2px; }
.head small { display: block; color: var(--dim); font-size: 12px; margin-top: 6px; letter-spacing: .02em; }
.actions { display: flex; gap: 12px; margin-top: 18px; }
.btn { flex: 1; height: 46px; border-radius: var(--r); background: var(--bg-2); font-weight: 600; font-size: 15px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--fg); color: var(--bg); }
.btn.danger { color: #ff6b6b; }

.empty { padding: 18vh 32px 0; text-align: center; color: var(--mute); }
.empty h2 { color: var(--fg); font-size: 20px; margin-bottom: 8px; }
.empty .btn { display: inline-flex; padding: 0 24px; margin-top: 22px; flex: none; }
.empty small { display: block; margin-top: 18px; font-size: 12px; color: var(--dim); }

#storage { padding: 28px 20px 8px; color: var(--dim); font-size: 12px; text-align: center; }

/* ---------- mini reproductor ---------- */
#mini {
  position: fixed; left: 8px; right: 8px; bottom: 8px; height: var(--mini-h);
  display: flex; align-items: center; gap: 12px; padding: 0 6px 0 8px;
  background: rgba(24, 24, 27, .88); -webkit-backdrop-filter: blur(24px) saturate(160%); backdrop-filter: blur(24px) saturate(160%);
  border-radius: 14px; border: 1px solid rgba(255,255,255,.06); z-index: 10; overflow: hidden;
}
#mini-art { width: 46px; height: 46px; border-radius: 6px; object-fit: cover; background: var(--bg-3); flex: none; }
.mini-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mini-meta b, .mini-meta span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-meta b { font-weight: 500; font-size: 15px; }
.mini-meta span { font-size: 13px; color: var(--mute); }
.mini-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: rgba(255,255,255,.06); }
.mini-progress i { display: block; height: 100%; width: 100%; background: var(--fg); transform-origin: left; transform: scaleX(0); }

/* ---------- reproduciendo ---------- */
#now {
  position: fixed; inset: 0; z-index: 20; background: var(--bg);
  display: flex; flex-direction: column; padding: 8px 28px max(28px, env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform 320ms var(--ease); visibility: hidden;
}
#now.open { transform: none; visibility: visible; }
#now.drag { transition: none; }
#now .close { align-self: center; color: var(--mute); }
.now-art { flex: 1; display: grid; place-items: center; min-height: 0; padding: 8px 0 20px; }
.now-art img { width: 100%; max-width: 380px; max-height: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; background: var(--bg-3); box-shadow: 0 24px 60px rgba(0,0,0,.6); transition: transform 320ms var(--ease); }
#now:not(.playing) .now-art img { transform: scale(.88); }
.now-meta h2 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-meta p { color: var(--mute); font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { display: inline-block; margin-top: 10px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 11px; letter-spacing: .04em; color: var(--mute); }
.badge:empty { display: none; }

.seek { margin-top: 22px; }
#seek { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; touch-action: none; --p: 0%; }
#seek::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--fg) var(--p), var(--bg-3) var(--p)); }
#seek::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: var(--fg); border: 0; }
#seek::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--fg) var(--p), var(--bg-3) var(--p)); }
#seek::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--fg); border: 0; }
.times { display: flex; justify-content: space-between; color: var(--dim); font-size: 12px; font-variant-numeric: tabular-nums; margin-top: 2px; }

.controls { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; }
.icon.sm { color: var(--dim); }
.icon.sm.on { color: var(--fg); }
.icon.sm svg { width: 22px; height: 22px; }
.icon.lg { width: 64px; height: 64px; }
.icon.lg svg { width: 34px; height: 34px; }
.icon.xl { width: 78px; height: 78px; background: var(--fg); color: var(--bg); }
.icon.xl svg { width: 34px; height: 34px; }

/* ---------- hoja de acciones ---------- */
#sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; padding: 8px; animation: fade 160ms ease-out; }
.sheet-card { width: 100%; background: var(--bg-2); border-radius: 14px; overflow: hidden; animation: up 220ms var(--ease); margin-bottom: env(safe-area-inset-bottom); }
.sheet-title { padding: 14px 18px 10px; color: var(--mute); font-size: 13px; border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-item { display: block; width: 100%; text-align: left; padding: 15px 18px; font-size: 16px; border-bottom: 1px solid var(--line); }
.sheet-item:last-child { border-bottom: 0; }
.sheet-item:active { background: var(--bg-3); }
.sheet-item.danger { color: #ff6b6b; }
.sheet-item.cancel { text-align: center; font-weight: 600; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--mini-h) + 24px); transform: translate(-50%, 10px); z-index: 40;
  max-width: calc(100% - 40px); padding: 10px 16px; border-radius: 12px; background: var(--bg-3); color: var(--fg);
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 180ms, transform 180ms var(--ease); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; }
}

.row.remote .meta b { color: #c9c9cf; }
#storage b { color: var(--mute); font-weight: 500; }
.login { display: flex; flex-direction: column; gap: 10px; padding: 0 16px 16px; }
.login .sheet-title { margin: 0 -16px 6px; }
.login input { height: 46px; padding: 0 14px; border: 0; border-radius: var(--r); background: var(--bg-3); color: var(--fg); font: inherit; font-size: 16px; outline: none; }
.login .btn { flex: none; }
.login .note { color: var(--mute); font-size: 13px; }
#code-step { display: flex; flex-direction: column; gap: 10px; }
#code-step[hidden] { display: none !important; }
.login .err { color: #ff6b6b; font-size: 13px; min-height: 1em; }
