/* =========================================================
   Goodue — design tokens
   Concept: a mixtape you make with a friend. Warm tape-deck
   palette, cassette-side track numbering (A1, A2, B1…),
   spinning reels while a session is live.
   ========================================================= */

:root {
  --bg: #101820;
  --bg-glow: #16212b;
  --surface: #172230;
  --surface-2: #1e2c3b;
  --surface-hover: #24384a;
  --border: rgba(243, 238, 225, 0.08);
  --border-strong: rgba(243, 238, 225, 0.16);

  --text: #f3eee1;
  --text-muted: #92a3b0;
  --text-faint: #5d6d79;

  --accent: #f2a93b;
  --accent-strong: #ffc169;
  --accent-2: #ff6a55;
  --danger: #ef5350;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;

  --shadow-card: 0 1px 0 rgba(243, 238, 225, 0.04) inset, 0 8px 24px rgba(0, 0, 0, 0.28);
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.4);

  --font-display: "Space Grotesk", "Inter", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
}

body {
  font-family: var(--font-body);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* =========================================================
   Stage — centers the mini app and gives it room to breathe
   when viewed outside the cramped Telegram webview (desktop
   browser preview, etc.)
   ========================================================= */

.stage {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  background:
    radial-gradient(60% 50% at 50% 0%, var(--bg-glow) 0%, var(--bg) 60%),
    var(--bg);
}

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}

/* =========================================================
   Top bar
   ========================================================= */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  background: rgba(16, 24, 32, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: none;
  object-fit: cover;
  display: block;
  border-radius: 50%;
  background: #ffffff;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.01em;
}

.me {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 5px 12px 5px 5px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  max-width: 46%;
}

.me:has(.me-name:empty) {
  display: none;
}

.me-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.me-avatar-img {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex: none;
  object-fit: cover;
  display: block;
}

.me-avatar-chip {
  width: 26px;
  height: 26px;
  font-size: 11px;
}

/* =========================================================
   Layout / sections
   ========================================================= */

#views {
  flex: 1;
  padding: 4px 20px 108px;
}

.view {
  display: none;
  animation: view-in 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.view.active {
  display: block;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-head {
  padding: 22px 2px 18px;
}

.eyebrow {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.section-head h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: -0.01em;
}

.hint {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
  margin: 0;
}

.mono {
  font-family: var(--font-mono);
}

/* =========================================================
   Buttons
   ========================================================= */

button {
  font-family: inherit;
  cursor: pointer;
}

.playlist-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.btn-share {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 13px 16px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14.5px;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.playlist-actions .btn-share {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-share svg {
  width: 17px;
  height: 17px;
  color: var(--accent);
  flex-shrink: 0;
}

.btn-share:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-share:active {
  transform: scale(0.98);
}

.btn-share:disabled {
  opacity: 0.65;
  cursor: default;
  transform: none;
}

.btn-add-track .icon-spinner {
  display: none;
}

.btn-add-track.uploading .icon-default {
  display: none;
}

.btn-add-track.uploading .icon-spinner {
  display: block;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn-primary {
  padding: 11px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  color: #1a1006;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(0.97); }

.btn-ghost {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-ghost:hover {
  background: var(--surface);
  color: var(--text);
}

.btn-danger {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(239, 83, 80, 0.35);
  background: rgba(239, 83, 80, 0.1);
  color: #ff9d99;
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.15s ease;
}

.btn-danger:hover {
  background: rgba(239, 83, 80, 0.18);
}

/* =========================================================
   Cards (tracks / friends / stats rows)
   ========================================================= */

.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.card:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.cover-sm {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 10px;
  flex: none;
  overflow: hidden;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
}

.cover-sm img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover-fallback-icon {
  width: 19px;
  height: 19px;
  color: rgba(255, 255, 255, 0.88);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2));
}

.meta {
  flex: 1;
  min-width: 0;
}

.t1 {
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.t2 {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-code {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 0.02em;
  flex: none;
  min-width: 24px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}

.actions button {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
}

.actions button svg {
  width: 17px;
  height: 17px;
}

.actions button[data-action="delete"]:hover {
  color: var(--danger);
}

.actions button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.avatar-chip {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: #1a1006;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent-2));
}

/* =========================================================
   Empty states
   ========================================================= */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  padding: 48px 20px;
  color: var(--text-faint);
}

.empty-icon {
  width: 72px;
  height: auto;
  color: var(--text-faint);
  opacity: 0.8;
}

.empty-state .hint {
  max-width: 260px;
}

/* =========================================================
   Friends: add row
   ========================================================= */

.add-friend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 14px;
  margin-bottom: 18px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
}

.add-friend-row:focus-within {
  border-color: var(--accent);
}

.input-icon {
  width: 17px;
  height: 17px;
  color: var(--text-faint);
  flex: none;
}

.add-friend-row input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
  padding: 10px 0;
  outline: none;
}

.add-friend-row input::placeholder {
  color: var(--text-faint);
}

/* =========================================================
   Player / session — the signature "tape deck" moment
   ========================================================= */

.player {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0 16px;
}

.player.hidden,
.hidden {
  display: none !important;
}

.deck {
  position: relative;
  width: 220px;
  height: 220px;
  margin: 12px 0 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.reel {
  position: absolute;
  top: 50%;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  transform: translateY(-50%);
  background:
    radial-gradient(circle at center, var(--surface-2) 0 22%, transparent 22.5%),
    repeating-conic-gradient(var(--text-faint) 0deg 6deg, transparent 6deg 24deg);
  border: 1px solid var(--border-strong);
  opacity: 0.9;
  transition: opacity 0.2s ease;
}

.reel-left { left: -14px; }
.reel-right { right: -14px; }

.reel span {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.player.is-playing .reel {
  animation: reel-spin 3.4s linear infinite;
}

.player.is-playing .reel-right {
  animation-direction: reverse;
}

@keyframes reel-spin {
  from { transform: translateY(-50%) rotate(0deg); }
  to { transform: translateY(-50%) rotate(360deg); }
}

.cover {
  width: 178px;
  height: 178px;
  border-radius: var(--radius-lg);
  object-fit: cover;
  background: linear-gradient(135deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-pop);
  z-index: 2;
}

.rec-light {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-faint);
  z-index: 3;
  box-shadow: 0 0 0 3px rgba(16, 24, 32, 0.6);
}

.player.is-playing .rec-light {
  background: var(--accent-2);
  animation: rec-pulse 1.6s ease-in-out infinite;
}

@keyframes rec-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(16, 24, 32, 0.6), 0 0 0 0 rgba(255, 106, 85, 0.5); }
  50% { box-shadow: 0 0 0 3px rgba(16, 24, 32, 0.6), 0 0 0 6px rgba(255, 106, 85, 0); }
}

.track-info {
  text-align: center;
  margin-bottom: 18px;
}

.track-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
}

.track-artist {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-top: 3px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  background-image: repeating-linear-gradient(
    -45deg,
    rgba(243, 238, 225, 0.04) 0 2px,
    transparent 2px 6px
  );
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.4s linear;
}

.time-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-faint);
  margin-bottom: 20px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 22px;
}

.btn-transport {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-transport svg {
  width: 18px;
  height: 18px;
}

.btn-transport:hover {
  background: var(--surface-hover);
}

.btn-transport:active {
  transform: scale(0.94);
}

.btn-transport-main {
  width: 60px;
  height: 60px;
  font-size: 20px;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  color: #1a1006;
  border: none;
  box-shadow: 0 8px 20px rgba(242, 169, 59, 0.28);
}

.btn-transport-main:hover {
  filter: brightness(1.05);
}

.participants {
  display: flex;
  gap: -8px;
  margin-bottom: 14px;
}

.participants span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  padding: 5px 12px;
  border-radius: 999px;
  margin-left: -8px;
}

.participants span:first-child {
  margin-left: 0;
}

.timer-live {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 22px;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-2);
  flex: none;
  animation: rec-pulse 1.6s ease-in-out infinite;
}

.session-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

.session-actions button {
  flex: 1;
}

/* =========================================================
   Stats
   ========================================================= */

.stat-total-card {
  text-align: center;
  padding: 26px 20px 30px;
  margin-bottom: 20px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
}

.stat-total {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 48px;
  line-height: 1;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stat-total-label {
  margin-top: 8px;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.stat-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 13px 14px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
}

.stat-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13.5px;
}

.stat-row-top .name {
  font-weight: 600;
}

.stat-row-top .value {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 12px;
}

.stat-bar-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

/* =========================================================
   Bottom tab bar
   ========================================================= */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  background: rgba(16, 24, 32, 0.9);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 8px max(12px, env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom));
}

#app .tabbar {
  position: sticky;
}

.tab {
  flex: 1;
  max-width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px 6px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  border-radius: 12px;
  transition: color 0.15s ease, background 0.15s ease;
}

.tab svg {
  width: 21px;
  height: 21px;
}

/* =========================================================
   Toasts / in-app notifications
   ========================================================= */

.toast-container {
  position: fixed;
  left: 50%;
  bottom: max(96px, calc(76px + env(safe-area-inset-bottom)));
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius-md);
  background: rgba(23, 34, 48, 0.92);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-pop);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  opacity: 0;
  transform: translateY(14px) scale(0.97);
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast-icon {
  flex-shrink: 0;
  font-size: 17px;
  line-height: 1;
}

.toast-text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.toast-success {
  border-color: rgba(107, 211, 145, 0.35);
  background: linear-gradient(0deg, rgba(107, 211, 145, 0.14), rgba(107, 211, 145, 0.14)), rgba(23, 34, 48, 0.92);
}

.toast-error {
  border-color: rgba(239, 83, 80, 0.4);
  background: linear-gradient(0deg, rgba(239, 83, 80, 0.14), rgba(239, 83, 80, 0.14)), rgba(23, 34, 48, 0.92);
}

.toast-info {
  border-color: rgba(242, 169, 59, 0.35);
  background: linear-gradient(0deg, rgba(242, 169, 59, 0.12), rgba(242, 169, 59, 0.12)), rgba(23, 34, 48, 0.92);
}

.tab span {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.tab:hover {
  color: var(--text-muted);
}

.tab.active {
  color: var(--accent);
  background: rgba(242, 169, 59, 0.08);
}

/* =========================================================
   Scrollbar (desktop preview polish)
   ========================================================= */

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-thumb {
  background: var(--surface-2);
  border-radius: 999px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

/* Focus visibility for keyboard users */
a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* The friend-add input already gets a rounded highlight from
   .add-friend-row:focus-within, so suppress the square outline
   above to avoid a "square inside a square" look. */
.add-friend-row input:focus-visible {
  outline: none;
}
