/* Coda — design system. See build spec §12.
   Provenance is the organising idea: where a track came from determines
   whether you can seek, download, or trust it to still be here tomorrow. */

:root {
  --ground:  #E2E4DB;   /* pale sage-limestone — page field */
  --surface: #F2F3EE;   /* raised rows, sheets */
  --ink:     #1C201A;   /* deep olive-black — primary text */
  --muted:   #6B7065;   /* secondary text, metadata */
  --wire:    #C3C7BA;   /* hairline rules, stamp borders */
  --accent:  #7A2E2E;   /* oxblood — now playing, transport, progress ONLY */

  --face-display: 'Darker Grotesque', sans-serif;
  --face-body: 'Public Sans', sans-serif;
  --face-mono: 'Martian Mono', monospace;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--face-body);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

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

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

a { color: inherit; }

.mono {
  font-family: var(--face-mono);
  letter-spacing: 0.04em;
  font-size: 12px;
}

/* ── Progress rule — full bleed, 2px, top of viewport ─────────────────── */

.progress-rule {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--wire);
  z-index: 40;
}
.progress-rule__fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s linear;
}

/* ── Nav ───────────────────────────────────────────────────────────────── */

.nav {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 18px 20px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }

.nav__brand {
  font-family: var(--face-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.nav__tabs {
  display: flex;
  gap: 20px;
  flex: 1;
}

.nav__tab {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
}
.nav__tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

.nav__settings {
  font-size: 18px;
  color: var(--muted);
  flex-shrink: 0;
}

/* ── View shell ────────────────────────────────────────────────────────── */

.view {
  padding: 8px 20px calc(96px + var(--safe-bottom));
  max-width: 720px;
  margin: 0 auto;
}

.view__header {
  margin: 16px 0 8px;
}
.view__title {
  font-family: var(--face-display);
  font-weight: 700;
  font-size: 28px;
  letter-spacing: -0.02em;
  margin: 0;
}
.view__subtitle {
  color: var(--muted);
  font-size: 14px;
  margin: 4px 0 0;
}

.view__empty {
  color: var(--muted);
  padding: 40px 0;
  font-size: 15px;
  line-height: 1.5;
}

/* ── Search box ────────────────────────────────────────────────────────── */

.search-box {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--wire);
  border-radius: 2px;
  font-size: 16px;
  margin: 12px 0;
}
.search-box:focus { outline: 1px solid var(--ink); }

.search-group__label {
  font-family: var(--face-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-transform: uppercase;
  margin: 20px 0 4px;
  cursor: pointer;
}

/* ── Track rows — full width, hairline separators, no cards ─────────────── */

.track-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--wire);
}
.track-row:last-child { border-bottom: none; }

.track-row__art {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  background: var(--wire);
  object-fit: cover;
}

.track-row__body {
  flex: 1;
  min-width: 0;
}

.track-row__title {
  font-family: var(--face-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-row__artist {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-row.is-playing .track-row__title { color: var(--accent); }

.stamp {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--wire);
  padding: 2px 6px;
  font-family: var(--face-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 3px;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.stamp__source { color: var(--ink); }
.stamp--live .stamp__source { color: var(--accent); }
.stamp--flip { transform: scaleY(0.1); }

.track-row__dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--wire);
  display: inline-block;
  margin-right: 4px;
}

.track-row.is-dead { opacity: 0.4; }
.track-row__find-again {
  font-size: 12px;
  color: var(--accent);
  text-decoration: underline;
  flex-shrink: 0;
}

.heart {
  font-size: 18px;
  color: var(--wire);
  flex-shrink: 0;
  line-height: 1;
  padding: 4px;
}
.heart.is-liked { color: var(--accent); }

.track-row__duration {
  font-family: var(--face-mono);
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
  min-width: 34px;
  text-align: right;
}

.track-row__actions { flex-shrink: 0; }

.track-row__add {
  font-size: 16px;
  color: var(--muted);
  flex-shrink: 0;
  line-height: 1;
  padding: 4px 6px;
}

.playlist-menu {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--wire);
  min-width: 160px;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}
.playlist-menu__item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  font-size: 14px;
  border-bottom: 1px solid var(--wire);
}
.playlist-menu__item:last-child { border-bottom: none; }
.playlist-menu__item:hover { background: var(--ground); }

/* ── Now playing bar ───────────────────────────────────────────────────── */

.now-playing {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: var(--surface);
  border-top: 2px solid var(--accent);
  z-index: 30;
}

.now-playing__art img {
  width: 40px; height: 40px;
  object-fit: cover;
  background: var(--wire);
  display: block;
}

.now-playing__meta { flex: 1; min-width: 0; }
.now-playing__title {
  font-family: var(--face-display);
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.now-playing__stamp {
  font-family: var(--face-mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.now-playing__stamp .stamp__source { color: var(--ink); }
.now-playing__stamp.is-live { color: var(--accent); }

.now-playing__time {
  font-family: var(--face-mono);
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}

.now-playing__transport {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.now-playing__transport button {
  font-size: 20px;
  color: var(--ink);
}
#npPlayPause { color: var(--accent); }

.now-playing__expand-area {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  text-align: left;
}

/* ── Full-screen Now Playing ──────────────────────────────────────────── */

.np-full {
  position: fixed;
  inset: 0;
  background: var(--ground);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 24px calc(24px + var(--safe-bottom));
  overflow-y: auto;
}

.np-full__header {
  width: 100%;
  max-width: 420px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.np-full__header button {
  font-size: 14px;
  color: var(--muted);
  padding: 8px;
}
#npfCollapse { font-size: 18px; }

.np-full__art {
  width: min(72vw, 320px);
  height: min(72vw, 320px);
  background: var(--wire);
  object-fit: cover;
  margin: 8px 0 24px;
}

.np-full__meta {
  text-align: center;
  max-width: 420px;
  width: 100%;
}
.np-full__title {
  font-family: var(--face-display);
  font-weight: 700;
  font-size: 28px;
  letter-spacing: -0.02em;
}
.np-full__artist {
  color: var(--muted);
  font-size: 15px;
  margin-top: 2px;
}
.np-full__stamp {
  display: inline-flex;
  gap: 4px;
  border: 1px solid var(--wire);
  padding: 3px 8px;
  font-family: var(--face-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 10px;
}

.np-full__scrub {
  width: 100%;
  max-width: 420px;
  margin: 28px 0 8px;
}
.np-full__scrub input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.np-full__times {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.np-full__transport {
  width: 100%;
  max-width: 420px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 16px 0;
}
.np-full__transport button {
  font-size: 22px;
  color: var(--ink);
  padding: 8px;
}
.np-full__transport button.is-active { color: var(--accent); }
.np-full__play { font-size: 34px; color: var(--accent); }
#npfShuffle, #npfRepeat { font-size: 18px; color: var(--muted); }

.np-full__secondary {
  width: 100%;
  max-width: 420px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}
.np-full__volume {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 220px;
  margin-left: 24px;
  color: var(--muted);
}
.np-full__volume input[type="range"] {
  flex: 1;
  accent-color: var(--ink);
}

/* ── Queue panel ───────────────────────────────────────────────────────── */

.queue-panel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 70vh;
  background: var(--surface);
  border-top: 1px solid var(--wire);
  z-index: 70;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
}
.queue-panel__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--wire);
  flex-shrink: 0;
}
.queue-panel__header button { font-size: 16px; color: var(--muted); padding: 4px; }
.queue-panel__list {
  overflow-y: auto;
  padding: 0 20px;
}
.queue-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--wire);
}
.queue-row.is-current .queue-row__title { color: var(--accent); }
.queue-row__title {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.queue-row__reorder { display: flex; gap: 2px; flex-shrink: 0; }
.queue-row__reorder button, .queue-row__remove {
  color: var(--muted);
  padding: 4px 6px;
  font-size: 14px;
}

/* Volume slider is intentionally never rendered on iOS — §11.5 */

/* ── Login screen ──────────────────────────────────────────────────────── */

.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.login__mark {
  font-family: var(--face-display);
  font-weight: 700;
  font-size: 44px;
  letter-spacing: -0.02em;
}
.login__tagline {
  color: var(--muted);
  max-width: 320px;
  margin: 8px 0 32px;
}
.login__form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 280px;
}
.login__form label {
  font-family: var(--face-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-align: left;
  color: var(--muted);
}
.login__form input {
  padding: 12px 14px;
  border: 1px solid var(--wire);
  background: var(--surface);
  border-radius: 2px;
  font-size: 18px;
  letter-spacing: 0.05em;
}
.login__form button {
  padding: 12px;
  background: var(--ink);
  color: var(--ground);
  border-radius: 2px;
  font-weight: 500;
}
.login__hint { color: var(--muted); font-size: 13px; }

/* ── Overlays ──────────────────────────────────────────────────────────── */

.tap-overlay {
  position: fixed; inset: 0;
  background: var(--ground);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.tap-overlay button {
  padding: 16px 32px;
  background: var(--ink);
  color: var(--ground);
  font-size: 16px;
  border-radius: 2px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--ground);
  padding: 10px 16px;
  border-radius: 2px;
  font-size: 14px;
  max-width: 90vw;
  z-index: 50;
}

.sync-prompt {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--wire);
  padding: 12px 16px;
  border-radius: 2px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 50;
  max-width: 90vw;
}
.sync-prompt button {
  font-weight: 500;
  text-decoration: underline;
  flex-shrink: 0;
}

/* ── Settings ──────────────────────────────────────────────────────────── */

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--wire);
}
.settings-row__label { font-size: 15px; }
.settings-row__sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.settings-row button {
  font-size: 14px;
  text-decoration: underline;
}
.storage-meter {
  height: 6px;
  background: var(--wire);
  margin: 8px 0;
}
.storage-meter__fill { height: 100%; background: var(--accent); }

/* ── Motion — almost none, all inside prefers-reduced-motion guard ───────── */

@media (prefers-reduced-motion: no-preference) {
  .stamp { transition: transform 0.12s ease; }
  .track-row__art, .now-playing__art img { transition: opacity 0.18s ease; }
}

/* ── Layout niceties ───────────────────────────────────────────────────── */

@media (min-width: 720px) {
  .view { padding-left: 0; padding-right: 0; }
}

[hidden] { display: none !important; }
