:root {
  --bg: #ffffff;
  --bg-warm: #fff8f0;
  --ink: #14110f;
  --ink-dim: #6b645c;
  --sun: #ffd24d;
  --orange: #ff8a2b;
  --coral: #ff5e5e;
  --line: rgba(20, 17, 15, 0.14);
  --font-display: 'Poppins', sans-serif;
  --font-body: 'Inter', sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg-warm);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ===== HEADER ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
}

.logo-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  overflow: hidden;
  flex: none;
  box-shadow: 0 6px 16px rgba(20, 17, 15, 0.18);
}
.logo-mark img { width: 100%; height: 100%; display: block; }

.install-btn {
  padding: 0.55rem 1rem;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.8rem;
}
.install-btn:hover { background: var(--ink); color: #fff; }

/* ===== NOW PLAYING ===== */
.now-playing {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 0.5rem 1.5rem 2rem;
}

.vinyl-stage {
  position: relative;
  width: min(62vw, 280px);
  height: min(62vw, 280px);
  margin-top: 0.5rem;
}

.vinyl {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  position: relative;
  background:
    repeating-radial-gradient(circle at 50% 50%,
      rgba(20, 17, 15, 0.09) 0px, rgba(20, 17, 15, 0.09) 1.5px,
      transparent 1.5px, transparent 5px),
    conic-gradient(from 200deg at 50% 50%,
      var(--coral) 0deg 180deg,
      var(--orange) 180deg 360deg);
  box-shadow: 0 25px 60px rgba(20, 17, 15, 0.22);
  animation: spin 14s linear infinite;
  animation-play-state: paused;
}
.vinyl.spinning { animation-play-state: running; }

@keyframes spin { to { transform: rotate(360deg); } }

.vinyl::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.vinyl-label {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 34%;
  height: 34%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(20, 17, 15, 0.25);
}
.vinyl-label img { width: 100%; height: 100%; display: block; }

.tonearm {
  position: absolute;
  top: -6%;
  right: -8%;
  width: 34%;
  height: 34%;
  border: 4px solid var(--ink);
  border-left-color: transparent;
  border-bottom-color: transparent;
  border-radius: 50%;
  transform: rotate(-35deg);
  transform-origin: 80% 20%;
  transition: transform 0.4s ease;
  opacity: 0.85;
}
.tonearm.playing { transform: rotate(0deg); }

.track-meta {
  text-align: center;
}
.track-meta h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.track-meta p {
  color: var(--ink-dim);
  font-size: 0.9rem;
  margin-top: 0.15rem;
}

.seek-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.time {
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  color: var(--ink-dim);
  min-width: 2.4em;
}

#seek {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  outline: none;
}
#seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ink);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(20, 17, 15, 0.3);
}
#seek::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: none;
  border-radius: 50%;
  background: var(--ink);
  cursor: pointer;
}

.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.4rem;
  margin-top: 0.25rem;
}

.transport-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.transport-btn:hover { transform: translateY(-1px); }
.transport-btn.ghost { color: var(--ink-dim); opacity: 0.75; }
.transport-btn.ghost[aria-pressed="true"] { color: var(--coral); opacity: 1; }

.transport-btn.primary {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 10px 24px rgba(20, 17, 15, 0.28);
}
.transport-btn.primary:hover { transform: scale(1.04); }

/* ===== PLAYLIST ===== */
.playlist-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  box-shadow: 0 -10px 30px rgba(20, 17, 15, 0.06);
  padding: 1.5rem 1.5rem 0.5rem;
  min-height: 0;
}

.playlist-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.tab-btn {
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--ink-dim);
}
.tab-btn.active {
  background: var(--ink);
  color: #fff;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg-warm);
  border-radius: 12px;
  padding: 0.65rem 0.9rem;
  margin-bottom: 0.75rem;
  color: var(--ink-dim);
}
.search-row input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--ink);
}
.search-row input::placeholder { color: var(--ink-dim); }

.playlist-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 1rem;
}

.playlist-empty {
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.9rem;
  padding: 2.5rem 1rem;
}

.track-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.7rem 0.5rem;
  border-radius: 14px;
  transition: background 0.15s ease;
}
.track-row:hover { background: var(--bg-warm); }
.track-row.playing { background: var(--bg-warm); }

.track-index {
  width: 1.6rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  color: var(--ink-dim);
  flex: none;
}
.track-row.playing .track-index { color: var(--coral); }

.track-info {
  flex: 1;
  min-width: 0;
  text-align: left;
}
.track-info .t-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.track-info .t-artist {
  font-size: 0.78rem;
  color: var(--ink-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-fav {
  flex: none;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-dim);
}
.track-fav svg { transition: transform 0.15s ease; }
.track-fav:hover svg { transform: scale(1.15); }
.track-fav.active { color: var(--coral); }
.track-fav.active svg { fill: var(--coral); }

.track-cache {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--ink-dim);
  opacity: 0.5;
}
.track-cache.cached { color: var(--orange); opacity: 1; }

/* ===== OFFLINE BAR ===== */
.offline-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1.5rem;
  font-size: 0.78rem;
  color: var(--ink-dim);
  border-top: 1px solid var(--line);
  background: #fff;
}

.offline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-dim);
  flex: none;
}
.offline-dot.syncing {
  background: var(--orange);
  animation: pulse-dot 1s ease-in-out infinite;
}
.offline-dot.ready { background: #38b06a; }
.offline-dot.error { background: var(--coral); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

#offline-bar button {
  margin-left: auto;
  font-weight: 600;
  color: var(--coral);
  text-decoration: underline;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 640px) {
  .app-shell {
    min-height: 92vh;
    margin: 4vh auto;
    border-radius: 32px;
    overflow: hidden;
    box-shadow: 0 40px 90px rgba(20, 17, 15, 0.18);
  }
}