:root {
  --bg: #121212;
  --surface: #1c1c1c;
  --surface-2: #262626;
  --text: #f2f2f2;
  --muted: #999;
  --accent: #ff5500;
  --accent-hover: #ff7733;
  --player-h: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 14px;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

/* ---- top bar ---- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  background: rgba(18,18,18,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #2a2a2a;
}
.brand { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.brand span { color: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.count { color: var(--muted); font-size: 13px; }
#user-avatar { width: 30px; height: 30px; border-radius: 50%; display: block; background: var(--surface-2); }

.btn {
  background: var(--accent); color: #fff;
  padding: 7px 14px; border-radius: 4px; font-weight: 600; font-size: 13px;
  transition: background .15s;
}
.btn:hover { background: var(--accent-hover); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.ghost:hover { background: #333; }
.btn.small { padding: 5px 10px; }
.btn.cta { font-size: 15px; padding: 12px 24px; display: inline-block; margin-top: 18px; }

/* ---- login / loading ---- */
#login-view, #loading-view {
  min-height: 80vh; display: flex; align-items: center; justify-content: center;
}
.login-card { text-align: center; max-width: 420px; padding: 40px 20px; }
.login-logo { font-size: 64px; }
.login-card h1 { font-size: 32px; margin: 8px 0 12px; letter-spacing: -.03em; }
.login-card p { color: var(--muted); line-height: 1.5; }

.spinner {
  width: 42px; height: 42px; margin: 0 auto 20px;
  border: 3px solid var(--surface-2); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress {
  height: 4px; background: var(--surface-2); border-radius: 2px;
  margin-top: 18px; overflow: hidden;
}
#progress-bar { height: 100%; width: 0%; background: var(--accent); transition: width .3s; }

/* ---- grid ---- */
#grid-view { padding: 20px 20px calc(var(--player-h) + 30px); }
#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 20px 16px;
}
.tile { position: relative; }
.cover {
  position: relative; width: 100%; aspect-ratio: 1;
  background: var(--surface-2); border-radius: 4px; overflow: hidden;
  cursor: pointer;
}
.cover img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform .2s;
}
.cover:hover img { transform: scale(1.04); }
.cover .play-ico {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.35); opacity: 0; transition: opacity .15s;
}
.cover:hover .play-ico { opacity: 1; }
.play-ico::before {
  content: ''; width: 46px; height: 46px; border-radius: 50%;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E") center/22px no-repeat;
}
.tile.playing .cover { outline: 2px solid var(--accent); }
.tile.playing .play-ico { opacity: 1; }
.tile.playing .play-ico::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M6 4h4v16H6zM14 4h4v16h-4z'/%3E%3C/svg%3E");
}
.sc-link {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(0,0,0,.55) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M14 3h7v7h-2V6.4l-9.3 9.3-1.4-1.4L17.6 5H14V3zM5 5h6v2H7v10h10v-4h2v6H5V5z'/%3E%3C/svg%3E") center/14px no-repeat;
  opacity: 0; transition: opacity .15s;
}
.tile:hover .sc-link { opacity: 1; }
.sc-link:hover { background-color: var(--accent); }
.dur {
  position: absolute; bottom: 6px; right: 6px;
  background: rgba(0,0,0,.7); color: #eee;
  font-size: 11px; padding: 1px 5px; border-radius: 3px;
}
.tile .t-title {
  display: block; margin-top: 8px; font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile .t-title:hover { color: var(--accent); }
.tile .t-artist {
  display: block; color: var(--muted); font-size: 12px; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#sentinel { height: 1px; }

/* ---- player ---- */
#player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: var(--player-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px;
  background: var(--surface);
  border-top: 1px solid #2e2e2e;
}
#p-art { width: 44px; height: 44px; border-radius: 3px; background: var(--surface-2); object-fit: cover; }
.p-meta { display: flex; flex-direction: column; min-width: 0; width: 220px; flex-shrink: 0; }
#p-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#p-title:hover { color: var(--accent); }
#p-artist { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-controls { display: flex; align-items: center; gap: 6px; }
.p-controls button { font-size: 18px; padding: 6px; border-radius: 4px; }
.p-controls button:hover { background: var(--surface-2); }
#p-play { font-size: 22px; color: var(--accent); }
.p-seek { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.p-seek span { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  height: 4px; background: var(--surface-2); border-radius: 2px; outline: none;
  flex: 1; min-width: 0; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 12px; height: 12px; border-radius: 50%; background: var(--accent);
}
input[type=range]::-moz-range-thumb {
  width: 12px; height: 12px; border: none; border-radius: 50%; background: var(--accent);
}
#p-vol { max-width: 90px; flex: 0 0 90px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--player-h) + 16px); transform: translateX(-50%);
  background: var(--surface-2); color: var(--text);
  padding: 10px 18px; border-radius: 6px; font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40;
}
#toast.on { opacity: 1; }

@media (max-width: 700px) {
  #grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 14px 10px; }
  .p-meta { width: 130px; }
  #p-vol { display: none; }
  .count { display: none; }
}
