/* ============================================
   Guest View — Mobile First
   ============================================ */

html, body { overscroll-behavior-y: contain; }

.view { display: none; min-height: 100vh; }
.view.active { display: block; }

#view-loading, #view-error {
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}
#view-loading.active, #view-error.active { display: flex; }

.center-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
  margin-top: var(--space-4);
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === Topbar === */
.g-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg-overlay);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
}
.g-topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.g-profile-btn {
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
}

/* === Avatars === */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  font-weight: var(--font-weight-bold);
  color: var(--color-bg);
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
  text-transform: uppercase;
  user-select: none;
}
.avatar-sm { width: 32px; height: 32px; font-size: 0.75rem; }
.avatar-md { width: 40px; height: 40px; font-size: 0.875rem; }

/* === Tabs === */
.g-tabs {
  position: sticky;
  top: 56px;
  z-index: 9;
  display: flex;
  background: var(--color-bg-overlay);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
}
.g-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  padding: var(--space-4) var(--space-3);
  cursor: pointer;
  position: relative;
  transition: color var(--transition-base);
  -webkit-tap-highlight-color: transparent;
}
.g-tab.active {
  color: var(--color-primary);
}
.g-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 3px;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  box-shadow: 0 0 12px var(--color-primary-glow);
}

.g-tab-content { display: none; padding: var(--space-4); padding-bottom: var(--space-16); }
.g-tab-content.active { display: block; animation: fade-in var(--transition-base) ease-out; }

/* === Now Playing card === */
.now-playing {
  background: linear-gradient(135deg, var(--color-primary-dim), transparent);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  position: relative;
  overflow: hidden;
}
.now-playing::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 32' preserveAspectRatio='none'><path d='M0,16 Q10,4 20,16 T40,16 T60,8 T80,16 T100,24 T120,8 T140,16 T160,12 T180,20 T200,16' stroke='%23FF6B1A' stroke-width='2' fill='none' stroke-linecap='round' opacity='0.2'/></svg>");
  background-size: 200% 100%;
  background-repeat: no-repeat;
  background-position: 0 80%;
  pointer-events: none;
}
.np-label {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-primary);
  margin-bottom: var(--space-2);
}
.np-row { display: flex; gap: var(--space-3); align-items: center; }
.np-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-md);
  flex-shrink: 0;
  background: var(--color-bg-elevated);
}
.np-meta { min-width: 0; }
.np-title {
  font-weight: var(--font-weight-bold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.np-sub {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* === Queue list (compact mobile cards) === */
.g-queue-list { display: flex; flex-direction: column; gap: var(--space-2); }

.g-track {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  position: relative;
  transition: all var(--transition-base);
}
.g-track.is-mine { border-color: var(--color-primary-bright); }
.g-track.is-top {
  background: linear-gradient(135deg, var(--color-primary-dim), var(--color-bg-elevated));
  border-color: var(--color-primary);
}
.g-track-rank {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-dim);
  font-size: var(--font-size-lg);
}
.g-track.is-top .g-track-rank { color: var(--color-primary); }

.g-track-body { min-width: 0; }
.g-track-title {
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-base);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.g-track-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}
.g-track-meta .by-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--color-bg);
  border-radius: var(--radius-full);
  padding: 2px 8px 2px 2px;
  border: 1px solid var(--color-border);
}
.g-track-meta .by-pill .avatar-sm { width: 22px; height: 22px; font-size: 0.625rem; }
.g-track-meta .by-pill .by-name {
  font-size: var(--font-size-xs);
  color: var(--color-text);
  font-weight: var(--font-weight-medium);
}

.g-track-vote {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 44px;
}
.vote-btn {
  background: transparent;
  border: none;
  color: var(--color-text-dim);
  font-size: 1.4rem;
  width: 36px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.vote-btn:active { transform: scale(0.88); }
.vote-btn.up.active { color: var(--color-up); }
.vote-btn.down.active { color: var(--color-down); }
.vote-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.vote-btn.popped { animation: vote-pop 0.3s ease-out; }

.vote-score {
  font-family: var(--font-mono);
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-sm);
  color: var(--color-primary);
  min-width: 28px;
  text-align: center;
}
.vote-score.zero { color: var(--color-text-muted); }
.vote-score.negative { color: var(--color-down); }

.mine-tag {
  display: inline-block;
  font-size: 0.625rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-primary);
  font-weight: var(--font-weight-bold);
  margin-left: var(--space-1);
}

.status-tag {
  display: inline-block;
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-weight: var(--font-weight-bold);
  margin-left: var(--space-1);
}
.status-tag.played { background: var(--color-border); color: var(--color-text-muted); }
.status-tag.playing { background: var(--color-primary); color: var(--color-bg); }

/* === Search results === */
.search-bar { margin-bottom: var(--space-4); }
.g-results-list { display: flex; flex-direction: column; gap: var(--space-2); }
.g-result {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  gap: var(--space-3);
  padding: var(--space-2);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  align-items: center;
}
.g-result-thumb {
  width: 80px;
  height: 45px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--color-bg);
}
.g-result-body { min-width: 0; }
.g-result-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.g-result-sub {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.g-result-add {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-bg);
  border: none;
  font-size: 1.4rem;
  font-weight: var(--font-weight-bold);
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.g-result-add:active { transform: scale(0.9); }
.g-result-add:disabled { opacity: 0.4; cursor: not-allowed; }

/* === Empty state === */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  line-height: 1.6;
}

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  background: var(--color-bg-overlay);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 100;
}
.modal-box {
  background: var(--color-bg-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-elevated);
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-bg-raised);
  border: 1px solid var(--color-border-bright);
  border-radius: var(--radius-full);
  padding: var(--space-3) var(--space-6);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  box-shadow: var(--shadow-elevated);
  z-index: 200;
  animation: fade-in var(--transition-base) ease-out;
  max-width: 90vw;
}
.toast.success { border-color: var(--color-success); }
.toast.error { border-color: var(--color-danger); }

.error-msg {
  color: var(--color-danger);
  font-size: var(--font-size-sm);
  margin-top: var(--space-3);
  text-align: center;
}

/* === Confetti === */
#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 300;
}

/* Profile pill (top-right) */
.g-profile-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 12px 4px 6px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  color: var(--color-text);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  max-width: 180px;
}
.g-profile-pill:hover { border-color: var(--color-primary); }
.g-profile-pill:active { transform: scale(0.96); }
.g-profile-emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  background: var(--color-bg);
  font-size: 1rem;
  flex-shrink: 0;
}
.g-profile-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.g-profile-pill.is-guest .g-profile-emoji {
  background: var(--color-bg);
}
.g-profile-pill.is-anon .g-profile-emoji {
  color: var(--color-text-muted);
}
.g-profile-pill.is-anon .g-profile-name {
  color: var(--color-text-muted);
}

/* Code-entry screen */
#view-code-entry.active {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  min-height: 100vh;
}
.code-entry-box {
  background: var(--color-bg-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-elevated);
}
.code-input-field {
  font-family: var(--font-mono);
  font-size: var(--font-size-2xl);
  text-align: center;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  padding: var(--space-4);
}
