:root {
  --bg: #0f1115;
  --bg-2: #171a21;
  --bg-3: #20242d;
  --fg: #eef0f4;
  --fg-2: #a3a9b6;
  --line: #2a2f3a;
  --accent: #8b6cff;
  --accent-fg: #fff;
  --danger: #ff5d6c;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --tabs-h: 58px;
  --mini-h: 62px;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f6f6f9;
  --bg-2: #ffffff;
  --bg-3: #eceef3;
  --fg: #15171c;
  --fg-2: #646b78;
  --line: #dfe2e8;
  --accent: #6a46f5;
  --shadow: 0 10px 30px rgba(20,20,40,.15);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
svg { width: 24px; height: 24px; fill: currentColor; flex: none; }
[hidden] { display: none !important; }
.muted { color: var(--fg-2); }
.error { color: var(--danger); min-height: 1.4em; }

.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--fg); }
.icon-btn:active { background: var(--bg-3); }
.icon-btn.on { color: var(--accent); }
.icon-btn.big svg { width: 32px; height: 32px; }

.btn { height: 44px; padding: 0 20px; border-radius: 22px; background: var(--bg-3); font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.btn.primary { background: var(--accent); color: var(--accent-fg); }
.btn.small { height: 36px; padding: 0 14px; font-size: 14px; }
.btn svg { width: 20px; height: 20px; }
.btn:active { opacity: .8; }

.chip { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 12px; background: var(--bg-3); color: var(--fg-2); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 12px; scrollbar-width: none; }
.chips button { flex: none; height: 34px; padding: 0 14px; border-radius: 17px; background: var(--bg-3); font-size: 14px; }
.chips button.on { background: var(--accent); color: var(--accent-fg); }

/* ---------- login */
#login { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.login-box { width: 100%; max-width: 380px; text-align: center; }
.login-box .logo img { display: block; width: min(68vw, 260px); height: auto; margin: 0 auto 4px; -webkit-user-drag: none; }
/* letras brancas no tema escuro, letras pretas no tema claro */
.login-box .logo .logo-light { display: none; }
:root[data-theme="light"] .login-box .logo .logo-dark { display: none; }
:root[data-theme="light"] .login-box .logo .logo-light { display: block; }
#login-form { display: grid; gap: 14px; margin-top: 24px; text-align: left; }
#login-form label { display: grid; gap: 6px; font-size: 13px; color: var(--fg-2); }
.field, #login-form input {
  height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-2); outline: none; width: 100%;
}
.field:focus, #login-form input:focus { border-color: var(--accent); }

/* ---------- layout */
#topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px;
  height: calc(56px + var(--top)); padding: var(--top) 8px 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px);
}
#topbar h1 { font-size: 22px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#back { margin-left: -10px; }
#offline-badge { font-size: 12px; padding: 3px 10px; border-radius: 10px; background: var(--danger); color: #fff; margin-right: 8px; }
#view { padding-bottom: calc(var(--tabs-h) + var(--mini-h) + var(--bottom) + 16px); min-height: 100vh; }

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  height: calc(var(--tabs-h) + var(--bottom)); padding-bottom: var(--bottom);
  background: var(--bg-2); border-top: 1px solid var(--line);
}
#tabs a { flex: 1; display: grid; place-items: center; align-content: center; gap: 2px; font-size: 11px; color: var(--fg-2); }
#tabs a svg { width: 22px; height: 22px; }
#tabs a.on { color: var(--accent); }

/* ---------- mini player */
#mini {
  position: fixed; left: 8px; right: 8px; z-index: 11; bottom: calc(var(--tabs-h) + var(--bottom) + 6px);
  height: var(--mini-h); display: flex; align-items: center; gap: 10px; padding: 0 6px 0 8px;
  background: var(--bg-3); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden;
}
#mini .cover { width: 46px; height: 46px; border-radius: 8px; }
.mini-text { flex: 1; min-width: 0; display: grid; }
.mini-text b, .mini-text span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-text span { font-size: 13px; color: var(--fg-2); }
.mini-progress { position: absolute; left: 12px; right: 12px; bottom: 0; height: 2px; background: var(--line); }
.mini-progress i { display: block; height: 100%; width: 0; background: var(--accent); }

.cover { background: var(--bg-3) center/40% no-repeat; object-fit: cover; display: block; }
.cover.none { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='1.4'%3E%3Cpath d='M9 18V5l12-2v13'/%3E%3Ccircle cx='6' cy='18' r='3'/%3E%3Ccircle cx='18' cy='16' r='3'/%3E%3C/svg%3E"); }

/* ---------- grids & lists */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 16px 12px; padding: 0 16px; }
.card { content-visibility: auto; contain-intrinsic-size: 150px 210px; min-width: 0; }
.card .cover { width: 100%; aspect-ratio: 1; border-radius: 10px; }
.card b, .card span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card b { margin-top: 8px; font-size: 14px; }
.card span { font-size: 13px; color: var(--fg-2); }
.card:active { opacity: .7; }
.card .dl-dot { position: relative; }

.list { padding: 0 8px; }
.row {
  display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 6px 8px; border-radius: 10px;
  content-visibility: auto; contain-intrinsic-size: auto 58px;
}
.row:active { background: var(--bg-3); }
.row .num { width: 24px; text-align: center; color: var(--fg-2); font-size: 14px; flex: none; }
.row .cover { width: 46px; height: 46px; border-radius: 6px; flex: none; }
.row .txt { flex: 1; min-width: 0; }
.row .txt b, .row .txt span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.row .txt span { font-size: 13px; color: var(--fg-2); }
.row .dur { font-size: 13px; color: var(--fg-2); flex: none; }
.row .ok svg { width: 16px; height: 16px; color: var(--accent); }
.row.playing .txt b, .row.playing .num { color: var(--accent); }
.row.unavailable { opacity: .4; }
.row .icon-btn { width: 38px; height: 38px; margin-right: -6px; }
.row .icon-btn svg { width: 20px; height: 20px; }

.section-title { font-size: 18px; margin: 18px 16px 10px; }
.empty { text-align: center; color: var(--fg-2); padding: 60px 24px; }
.empty svg { width: 56px; height: 56px; opacity: .5; }

/* ---------- album header */
.album-head { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 4px 16px 12px; }
.album-head .cover { width: min(64vw, 260px); aspect-ratio: 1; border-radius: 14px; box-shadow: var(--shadow); }
.album-head h2 { margin: 16px 0 2px; font-size: 21px; }
.album-head p { margin: 0; color: var(--fg-2); }
.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 16px 0 6px; }

/* ---------- search */
.search-box { padding: 0 16px 12px; }

/* ---------- settings */
.settings { padding: 0 16px; display: grid; gap: 18px; }
.group { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--fg-2); margin: 14px 16px 6px; }
.opt { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 16px; border-top: 1px solid var(--line); }
.group h3 + .opt { border-top: 0; }
.opt > span { flex: 1; }
.opt small { display: block; color: var(--fg-2); }
.opt select { background: var(--bg-3); border: 0; border-radius: 10px; height: 38px; padding: 0 10px; }
.seg { display: flex; background: var(--bg-3); border-radius: 10px; padding: 3px; }
.seg button { height: 32px; padding: 0 12px; border-radius: 8px; font-size: 14px; color: var(--fg-2); }
.seg button.on { background: var(--bg-2); color: var(--fg); box-shadow: 0 1px 3px rgba(0,0,0,.25); font-weight: 600; }

/* ---------- now playing */
#np {
  position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column;
  padding: calc(var(--top) + 8px) 24px calc(var(--bottom) + 20px); overflow: hidden;
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.np-bg { position: absolute; inset: -40px; background: center/cover no-repeat; filter: blur(50px) saturate(1.4); opacity: .35; z-index: -1; transform: translateZ(0); }
.np-head { display: flex; align-items: center; justify-content: space-between; margin: 0 -10px; }
.np-cover { width: min(100%, 46vh, 420px); aspect-ratio: 1; margin: auto auto 0; border-radius: 16px; box-shadow: var(--shadow); }
.np-meta { margin-top: 26px; min-width: 0; }
.np-title { margin: 0; font-size: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-artist { margin: 4px 0 0; color: var(--fg-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-seek { margin-top: 18px; }
.times { display: flex; justify-content: space-between; font-size: 12px; color: var(--fg-2); font-variant-numeric: tabular-nums; }
.np-controls { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.play-btn { width: 72px; height: 72px; border-radius: 50%; background: var(--fg); color: var(--bg); display: grid; place-items: center; }
.play-btn svg { width: 34px; height: 34px; }
.play-btn:active { transform: scale(.95); }
.np-extra { display: flex; justify-content: space-around; margin: 18px 0 auto; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; }
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(var(--accent), var(--accent)) 0/var(--p, 0%) 100% no-repeat, var(--line);
}
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: var(--fg); }

/* ---------- bottom sheet */
#sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 85vh; overflow-y: auto;
  background: var(--bg-2); border-radius: 18px 18px 0 0; padding: 8px 0 calc(var(--bottom) + 12px);
  animation: up .2s ease-out;
}
.sheet-body::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 8px; }
.sheet-head { display: flex; gap: 12px; align-items: center; padding: 4px 16px 12px; border-bottom: 1px solid var(--line); }
.sheet-head .cover { width: 48px; height: 48px; border-radius: 6px; }
.sheet-head div { min-width: 0; }
.sheet-head b, .sheet-head span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-head span { font-size: 13px; color: var(--fg-2); }
.sheet-item { display: flex; width: 100%; align-items: center; gap: 16px; height: 52px; padding: 0 20px; text-align: left; }
.sheet-item:active { background: var(--bg-3); }
.sheet-item.danger { color: var(--danger); }
.sheet-item svg { width: 22px; height: 22px; color: var(--fg-2); }
.sheet-pad { padding: 8px 16px; display: grid; gap: 12px; }
.sheet-title { margin: 4px 16px 8px; font-size: 18px; }

/* ---------- equalizer */
.eq-bands { display: grid; gap: 2px; padding: 0 16px; }
.eq-band { display: grid; grid-template-columns: 48px 1fr 54px; align-items: center; gap: 10px; font-size: 13px; }
.eq-band span:first-child { color: var(--fg-2); text-align: right; }
.eq-band span:last-child { font-variant-numeric: tabular-nums; }
.switch { position: relative; width: 50px; height: 30px; border-radius: 15px; background: var(--line); transition: background .15s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(20px); }

/* ---------- toast */
#toast {
  position: fixed; left: 50%; z-index: 60; bottom: calc(var(--tabs-h) + var(--mini-h) + var(--bottom) + 20px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s;
  background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 20px; font-size: 14px;
  max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- computador: menu lateral */
@media (min-width: 900px) {
  :root { --side: 220px; --tabs-h: 0px; }
  body { padding-left: var(--side); }
  #tabs {
    top: 0; right: auto; width: var(--side); height: 100%; flex-direction: column; gap: 4px;
    padding: 20px 12px; border-top: 0; border-right: 1px solid var(--line);
  }
  #tabs::before { content: "Minha Música"; font-weight: 700; font-size: 18px; padding: 4px 12px 18px; color: var(--fg); }
  #tabs a { flex: none; display: flex; gap: 14px; height: 44px; padding: 0 12px; border-radius: 10px; font-size: 15px; }
  #tabs a:hover { background: var(--bg-3); }
  #tabs a.on { background: var(--bg-3); }
  #mini { left: calc(var(--side) + 16px); right: 16px; bottom: 16px; height: 72px; padding: 0 12px; }
  #mini .cover { width: 54px; height: 54px; }
  #toast { left: calc(50% + var(--side) / 2); bottom: 110px; }
  #view { padding-bottom: 120px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 24px 18px; padding: 0 24px; }
  .list, .settings { max-width: 900px; }
  .settings { padding: 0 24px; }
  .row:hover { background: var(--bg-3); }
  .card:hover .cover { filter: brightness(1.08); }
  .sheet-body { left: 50%; right: auto; width: 480px; transform: translateX(-50%); bottom: 24px; border-radius: 18px; max-height: 80vh; }
  .sheet-body { animation: none; }
  #np { align-items: center; }
  #np > * { width: min(100%, 480px); }
  #np > .np-bg { width: auto; }
  .np-head { width: min(100% + 20px, 500px) !important; }
}

.progress-line { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin-top: 6px; }
.progress-line i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
