:root {
  --bg: #121214;
  --surface: #1a1a1e;
  --surface-raised: #212126;
  --border: #2b2b31;
  --text: #ececee;
  --text-dim: #8f8f98;
  --accent: #d4a537;
  --accent-dim: #7a6423;
  --danger: #c4432b;
  --radius: 10px;
  --font-display: "Space Grotesk", sans-serif;
  --font-body: "Inter", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: var(--font-body);
  cursor: pointer;
}

input {
  font-family: var(--font-body);
}

.hidden { display: none !important; }

/* Gate */
.gate {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.gate-card {
  width: 100%;
  max-width: 320px;
  text-align: center;
}
.gate-mark {
  font-size: 40px;
  color: var(--accent);
  margin-bottom: 4px;
}
.gate-card h1 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 24px;
}
.gate-card input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 12px;
}
.gate-card button {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: #1a1409;
  font-weight: 600;
  font-size: 15px;
}
.gate-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-top: 12px;
}

/* App shell */
.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
}
.brand-mark { color: var(--accent); font-size: 20px; }

main {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px calc(88px + env(safe-area-inset-bottom));
}

.view { display: none; }
.view.active { display: block; }

/* Bottom tab bar */
.bottom-tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.bottom-tabs .tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 8px 4px;
  border-radius: var(--radius);
  min-height: 48px;
}
.bottom-tabs .tab.active {
  color: var(--accent);
}
.tab-icon { font-size: 19px; line-height: 1; }
.tab-label { font-size: 11px; font-weight: 500; }

/* Player bar sits above the tab bar */
#player-bar.player-bar {
  bottom: calc(58px + env(safe-area-inset-bottom));
}

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.search-bar input {
  flex: 1;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
}
.search-bar button {
  padding: 12px 18px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: #1a1409;
  font-weight: 600;
  font-size: 14px;
}

.status-line {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 20px 0;
}

.library-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.library-header h2 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}
.storage-info {
  font-size: 12px;
  color: var(--text-dim);
}

.track-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.track {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid transparent;
}
.track.playing {
  border-color: var(--accent-dim);
  background: var(--surface-raised);
}
.track img {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-raised);
  flex-shrink: 0;
}
.track-meta {
  flex: 1;
  min-width: 0;
}
.track-title {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.track-artist {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.track-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.track-actions button {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.track-actions button.dl-active {
  color: var(--accent);
  border-color: var(--accent-dim);
}
.track-actions button.dl-done {
  color: var(--text-dim);
}

/* Player bar */
.player-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 41;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.player-art {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}
.player-art img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-raised);
}
.vinyl-ring {
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
}
.player-bar.playing .vinyl-ring {
  opacity: 1;
  animation: spin 3s linear infinite;
}
.player-bar.playing .player-art img {
  animation: spin 3s linear infinite;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.player-info {
  flex: 1;
  min-width: 0;
}
.player-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-artist {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.seek {
  width: 100%;
  height: 3px;
  accent-color: var(--accent);
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.player-controls button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#player-toggle {
  background: var(--accent);
  color: #1a1409;
  width: 42px;
  height: 42px;
}

#audio { display: none; }

/* Gate tabs */
.gate-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border-radius: 999px;
  padding: 3px;
  margin-bottom: 16px;
}
.gate-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
}
.gate-tab.active {
  background: var(--surface-raised);
  color: var(--text);
}

/* Logout */
.logout-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  padding: 6px 8px;
}

/* Playlists */
.playlist-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.playlist-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}
.playlist-card-name {
  font-weight: 500;
  font-size: 14px;
}
.playlist-card-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}
.playlist-card-delete {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
  padding: 6px;
}

.back-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
}

#playlist-detail-name {
  font-family: var(--font-display);
  font-size: 18px;
  margin: 10px 0 14px;
}

.import-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 14px;
}

/* Add-to-playlist button on tracks */
.track-actions button.add-btn {
  font-size: 15px;
}

/* Picker modal */
.picker-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
.picker-card {
  width: 100%;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 20px;
  max-height: 70vh;
  overflow-y: auto;
}
.picker-card h3 {
  font-family: var(--font-display);
  margin: 0 0 12px;
  font-size: 16px;
}
.picker-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.picker-list li button {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 14px;
}
