/* City Listen — calm, readable, mobile-first, dark-friendly */

:root {
  --bg: #0b1220;
  --bg-elev: #121a2b;
  --bg-card: #162033;
  --border: rgba(148, 163, 184, 0.14);
  --text: #e8eef7;
  --muted: #94a3b8;
  --accent: #14b8a6;
  --accent-dim: #0f766e;
  --accent-soft: rgba(20, 184, 166, 0.14);
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --player-h: 168px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f7fb;
    --bg-elev: #ffffff;
    --bg-card: #ffffff;
    --border: rgba(15, 23, 42, 0.08);
    --text: #0f172a;
    --muted: #64748b;
    --accent: #0f766e;
    --accent-dim: #0d9488;
    --accent-soft: rgba(15, 118, 110, 0.1);
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(20, 184, 166, 0.12), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(59, 130, 246, 0.08), transparent 50%),
    var(--bg);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

.hidden, [hidden] { display: none !important; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 16px 16px calc(var(--player-h) + var(--safe-b) + 20px);
}

/* —— Top bar —— */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.city-switcher {
  display: inline-flex;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.city-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.city-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.city-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* —— Library —— */
.library-head {
  margin-bottom: 12px;
}

.library-head h2 {
  margin: 0;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.hint {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.status-banner {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.85rem;
  margin-bottom: 12px;
}

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

.episode {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.episode.is-playing {
  border-color: rgba(20, 184, 166, 0.45);
}

.episode.is-pinned {
  background: linear-gradient(180deg, var(--accent-soft), var(--bg-card) 48%);
}

.ep-main {
  display: flex;
  gap: 4px;
  align-items: stretch;
}

.ep-play-hit {
  flex: 1;
  text-align: left;
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 14px 8px 14px 14px;
  cursor: pointer;
  min-width: 0;
}

.ep-play-hit:focus-visible,
.icon-btn:focus-visible,
.ctrl:focus-visible,
.city-btn:focus-visible,
.scrub:focus-visible,
#speedSelect:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.ep-date {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.ep-title {
  display: block;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.ep-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
}

.ep-duration {
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ep-badge {
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--muted);
}

.ep-badge.source {
  background: rgba(59, 130, 246, 0.12);
  color: #93c5fd;
}

@media (prefers-color-scheme: light) {
  .ep-badge.source { color: #1d4ed8; background: rgba(37, 99, 235, 0.1); }
}

.ep-badge.life.saved {
  background: var(--accent-soft);
  color: var(--accent);
}

.ep-badge.life.warn {
  background: rgba(251, 191, 36, 0.14);
  color: var(--warn);
}

.ep-badge.offline {
  background: rgba(167, 139, 250, 0.15);
  color: #c4b5fd;
}

@media (prefers-color-scheme: light) {
  .ep-badge.offline { color: #6d28d9; background: rgba(109, 40, 217, 0.1); }
}

.ep-actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 8px 8px 8px 0;
}

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.icon-btn:hover { background: rgba(148, 163, 184, 0.1); color: var(--text); }
.icon-btn.pinned { color: var(--accent); }
.icon-btn.delete-btn:hover { color: var(--danger); }
.icon-btn.expand-btn[aria-expanded="true"] { color: var(--accent); }

.ep-summary {
  border-top: 1px solid var(--border);
  padding: 12px 14px 14px;
  background: rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: light) {
  .ep-summary { background: rgba(15, 23, 42, 0.02); }
}

.summary-body {
  font-size: 0.9rem;
  color: var(--text);
  white-space: pre-wrap;
}

.summary-body strong { font-weight: 700; }

.source-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
}

.source-link:hover { text-decoration: underline; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
}

/* —— Player —— */
.player-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + var(--safe-b));
  box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.25);
  max-width: 560px;
  margin: 0 auto;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.player-bar.collapsed {
  opacity: 0.85;
}

.player-meta { margin-bottom: 8px; min-width: 0; }

.player-title {
  font-weight: 650;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-sub {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}

.scrub-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.time {
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 2.4em;
}

.scrub {
  width: 100%;
  accent-color: var(--accent);
  height: 4px;
  cursor: pointer;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.ctrl {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
  min-width: 48px;
  height: 40px;
  border-radius: 12px;
  cursor: pointer;
}

.ctrl:disabled { opacity: 0.4; cursor: not-allowed; }

.ctrl.play {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-dim);
  border-color: transparent;
  color: #ecfdf5;
  display: grid;
  place-items: center;
}

.ctrl.play.is-playing .icon-play {
  width: 14px;
  height: 14px;
  border: 0;
  background:
    linear-gradient(#ecfdf5, #ecfdf5) left / 4px 100% no-repeat,
    linear-gradient(#ecfdf5, #ecfdf5) right / 4px 100% no-repeat;
  margin-left: 0;
}

.icon-play {
  display: block;
  width: 0; height: 0;
  border-style: solid;
  border-width: 8px 0 8px 14px;
  border-color: transparent transparent transparent #ecfdf5;
  margin-left: 3px;
}

.speed-wrap select {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 650;
  padding: 8px 10px;
  border-radius: 12px;
  cursor: pointer;
}

.speed-wrap select:disabled { opacity: 0.4; cursor: not-allowed; }

@media (min-width: 600px) {
  .player-bar {
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    border-radius: 16px 16px 0 0;
  }
}
