/* ============================================================
   Dispatch — monochrome Apple HIG, sized for mobile perfection.

   Palette: the neutral greys from gabrielepizzi.com / gbrlpzz/index
   (#f5f5f7 field, rgba(0,0,0,.85) ink, rgba(0,0,0,.55) dim) — no
   colour tint anywhere. Dark mode mirrors them on pure black.

   Typography: root font = -apple-system-body so iOS Dynamic Type
   scales the whole interface; every text size is rem, and the
   surfaces (cards, pills, rows) scale with it. Touch targets are
   ≥44pt (HIG minimum). Reduced motion is honoured.
   ============================================================ */

:root {
  --bg: #f5f5f7;                        /* index field grey */
  --bg-card: #ffffff;
  --label: rgba(0, 0, 0, 0.85);         /* index ink */
  --secondary: rgba(0, 0, 0, 0.55);     /* index ink-dim */
  --tertiary: rgba(0, 0, 0, 0.35);
  --quaternary: rgba(0, 0, 0, 0.09);
  --separator: rgba(0, 0, 0, 0.14);
  --fill: rgba(0, 0, 0, 0.07);
  --fill-strong: rgba(0, 0, 0, 0.14);
  --accent: #000000;
  --accent-text: #ffffff;
  --nav-bg: rgba(245, 245, 247, 0.85);
  --error: #d70015;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 10px 28px -14px rgba(0, 0, 0, 0.16);
  --radius-card: 16px;
  --radius-sheet: 14px;
  --radius-pill: 999px;
  --ease: cubic-bezier(0.4, 0, 0.6, 1);
  --ease-fast: cubic-bezier(0.25, 0.1, 0.3, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-card: #1c1c1e;
    --label: rgba(255, 255, 255, 0.88);
    --secondary: rgba(255, 255, 255, 0.58);
    --tertiary: rgba(255, 255, 255, 0.36);
    --quaternary: rgba(255, 255, 255, 0.10);
    --separator: rgba(255, 255, 255, 0.18);
    --fill: rgba(255, 255, 255, 0.10);
    --fill-strong: rgba(255, 255, 255, 0.20);
    --accent: #ffffff;
    --accent-text: #000000;
    --nav-bg: rgba(0, 0, 0, 0.85);
    --error: #ff6961;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 28px -14px rgba(0, 0, 0, 0.6);
  }
}

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

html {
  font-family: var(--sans);
  font-size: 17px;                      /* fallback base */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
@supports (font: -apple-system-body) {
  html { font: -apple-system-body; }    /* iOS Dynamic Type drives rem sizing */
}

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

body {
  background: var(--bg);
  color: var(--label);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  overflow: hidden;
  position: fixed;
  inset: 0;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input { font: inherit; }
a { color: inherit; text-decoration: none; }

button, .pill, .bubble, input[type="date"] { touch-action: manipulation; }

:focus-visible {
  outline: 3px solid rgba(0, 0, 0, 0.5);
  outline-offset: 2px;
  border-radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :focus-visible { outline-color: rgba(255, 255, 255, 0.65); }
}

/* Honour reduced motion: kill every animation/transition. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

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

#app { height: 100%; display: flex; flex-direction: column; }

/* ---------------- Navigation bar (44pt + safe area) ---------------- */

#navbar {
  flex: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: calc(44px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 4px 0;
  background: var(--nav-bg);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 0.5px solid var(--separator);
  z-index: 10;
}

.nav-btn {
  flex: none;
  min-width: 60px;
  min-height: 44px;                     /* HIG minimum touch target */
  padding: 0 10px;
  border-radius: 10px;
  font-size: 1rem;                      /* 17pt */
  font-weight: 500;
  letter-spacing: -0.2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s var(--ease-fast);
}
.nav-btn:active { opacity: 0.35; }
.nav-btn--icon { min-width: 44px; width: 44px; color: var(--accent); }

.nav-right { display: flex; align-items: center; gap: 0; }

#nav-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 160px);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.25px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 6px;
  pointer-events: none;
}

/* ---------------- Day bubble strip ---------------- */

#strip {
  flex: none;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  /* Spotlight carousel: the strip is padded so any date can reach the
     centre, and every bubble snaps to that fixed centre. */
  padding: 0.59rem calc(50% - 32px) 0.71rem;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
}
#strip::-webkit-scrollbar { display: none; }

.bubble {
  flex: none;
  scroll-snap-align: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid transparent;
  transition: background-color 0.25s var(--ease), border-color 0.25s var(--ease), color 0.25s var(--ease), transform 0.4s var(--spring);
}
.bubble:active { transform: scale(0.92); }
.bubble .dn { font-size: 0.94rem; font-weight: 600; letter-spacing: -0.2px; line-height: 1.1; font-variant-numeric: tabular-nums; }

.bubble--default { color: var(--secondary); }
.bubble--past, .bubble--future { color: var(--tertiary); }
.bubble--today { color: var(--label); border-color: var(--label); }
.bubble--today .dn { font-weight: 700; }

.bubble--selected { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.bubble--selected .dn { color: var(--accent-text); }

/* ---------------- Day pager & content ---------------- */

#pager {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
  touch-action: pan-y;
}

#dayview {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 0.82rem 0 calc(28px + env(safe-area-inset-bottom));   /* 14pt top */
}

#pull-indicator {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: center;
  padding-top: 18px;
  z-index: 5;
  pointer-events: none;
}

.spinner {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2.5px solid var(--fill-strong);
  border-top-color: var(--secondary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Cards (16pt corners, 16pt gutters) ---------------- */

.card {
  display: block;
  background: var(--bg-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  margin: 0 16px 0.71rem;               /* 12pt bottom gutter */
  overflow: hidden;
  padding: 0.82rem;                     /* 14pt */
  transition: transform 0.4s var(--spring), opacity 0.2s var(--ease-fast);
}
a.card:active { transform: scale(0.98); opacity: 0.85; }

.card-media {
  margin: -0.82rem -0.82rem 0.71rem;
  aspect-ratio: 16 / 9;
  background: var(--quaternary);
  position: relative;
  overflow: hidden;
}
.card-media img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

.duration-badge {
  position: absolute;
  right: 8px; bottom: 8px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 0.706rem;                  /* 12pt */
  font-weight: 600;
  letter-spacing: 0.2px;
  font-variant-numeric: tabular-nums;
  padding: 3px 7px;
  border-radius: 6px;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.card-source-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0.47rem;               /* 8pt */
}
.source-badge {
  position: relative;
  width: 20px; height: 20px;
  border-radius: 6px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--fill);
  font-size: 0.647rem;                  /* 11pt */
  font-weight: 700;
  color: var(--secondary);
}
.source-badge img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.source-badge svg { width: 13px; height: 13px; }
.badge-letter { line-height: 1; }

.source-name {
  font-size: 0.765rem;                  /* 13pt */
  font-weight: 600;
  letter-spacing: -0.1px;
  color: var(--secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.relative-time { margin-left: auto; flex: none; font-size: 0.765rem; font-weight: 400; color: var(--tertiary); }

.card-title {
  font-size: 1rem;                      /* 17pt */
  font-weight: 600;
  letter-spacing: -0.3px;
  line-height: 1.25;
  margin-bottom: 0.18rem;
  overflow-wrap: anywhere;
}
.card-byline { font-size: 0.765rem; font-weight: 400; color: var(--secondary); margin-bottom: 0.35rem; }
.card-summary {
  font-size: 0.882rem;                  /* 15pt */
  font-weight: 400;
  letter-spacing: -0.1px;
  line-height: 1.4;
  color: var(--secondary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 0.71rem;                  /* 12pt */
  padding: 0.41rem 0.82rem;             /* 7/14pt */
  min-height: 2rem;
  border-radius: var(--radius-pill);
  background: var(--fill);
  font-size: 0.882rem;
  font-weight: 500;
  letter-spacing: -0.15px;
  transition: background-color 0.2s var(--ease-fast);
}
/* Expand the pill's hit area to the 44pt HIG minimum. */
.pill::after { content: ''; position: absolute; inset: -6px; }
.pill:active { background: var(--fill-strong); }
.pill-arrow { font-size: 0.765rem; opacity: 0.7; }

/* Card CTAs follow the index card anatomy: one consistent full-width action
   row, with the label left and the external-link affordance right. Empty
   states retain compact native buttons. */
.card > .pill {
  display: flex;
  width: 100%;
  justify-content: space-between;
}

/* Podcast card: square artwork left, Apple Podcasts style */
.pod-row { display: flex; gap: 0.71rem; align-items: flex-start; }
.pod-art {
  flex: none;
  width: 64px; height: 64px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--quaternary);
}
.pod-art img { width: 100%; height: 100%; object-fit: cover; }
.pod-body { min-width: 0; flex: 1; }

/* ---------------- Empty state ---------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 22vh 36px 0;
  gap: 8px;
}
.empty .empty-glyph {
  width: 84px; height: 84px;
  border-radius: 50%;
  background: var(--fill);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}
.empty .empty-glyph svg { width: 36px; height: 36px; color: var(--secondary); }
.empty h3 { font-size: 1.176rem; font-weight: 600; letter-spacing: -0.4px; }   /* 20pt */
.empty p { font-size: 0.882rem; color: var(--secondary); line-height: 1.35; max-width: 280px; }
.empty .empty-install { font-size: 0.765rem; color: var(--tertiary); max-width: 280px; }
.empty .pill { margin-top: 0.82rem; }
.empty .pill--primary { background: var(--accent); color: var(--accent-text); }
.empty .pill--primary:active { opacity: 0.8; }

/* ---------------- Toast ---------------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(30px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(30, 30, 32, 0.92);
  color: #fff;
  font-size: 0.824rem;                  /* 14pt */
  font-weight: 500;
  letter-spacing: -0.1px;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: min(86vw, 400px);
  text-align: center;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
#toast[hidden] { display: block; opacity: 0; transform: translateX(-50%) translateY(12px); pointer-events: none; }

/* ---------------- Sheet ---------------- */

#backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 40;
  opacity: 1;
  transition: opacity 0.3s var(--ease);
}
#backdrop[hidden] { display: block; opacity: 0; pointer-events: none; }

#sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  background: var(--bg);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
  transform: translateY(0);
  transition: transform 0.38s var(--ease);
  max-height: 88%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
#sheet[hidden] { display: flex; transform: translateY(105%); pointer-events: none; }

#sheet-grabber {
  flex: none;
  width: 36px; height: 5px;
  border-radius: 3px;
  background: var(--fill-strong);
  margin: 8px auto 4px;
  touch-action: none;
}

#sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 16px 18px;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.sheet-nav {
  position: sticky;
  top: -6px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 8px;
  background: var(--bg);
}
.sheet-nav h2 { font-size: 1rem; font-weight: 600; letter-spacing: -0.25px; }
.sheet-nav .nav-btn { min-width: 68px; }
.sheet-nav .nav-btn--disabled { opacity: 0.4; pointer-events: none; }

.field-label {
  font-size: 0.765rem;
  font-weight: 500;
  color: var(--secondary);
  margin: 0.82rem 4px 0.35rem;
  letter-spacing: 0.3px;
}
.field {
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 4px 14px;
  display: flex;
  align-items: center;
}
.field input {
  flex: 1;
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  font-size: 1rem;
  letter-spacing: -0.2px;
  color: var(--label);
  padding: 0.71rem 0;                   /* 12pt */
  -webkit-user-select: text;
  user-select: text;
  -webkit-appearance: none;
  appearance: none;
}
.field input::placeholder { color: var(--tertiary); }
.field input[type="date"] { min-height: 44px; }
.field svg { width: 18px; height: 18px; color: var(--tertiary); margin-right: 10px; flex: none; }

/* ---------------- Sources screen ---------------- */

#sources-screen {
  position: fixed; inset: 0;
  z-index: 45;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.35s var(--ease);
  padding-top: env(safe-area-inset-top);
}
#sources-screen[hidden] { display: flex; transform: translateX(100%); pointer-events: none; }

.screen-nav {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 4px;
  background: var(--nav-bg);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 0.5px solid var(--separator);
}
.screen-nav h2 { font-size: 1rem; font-weight: 600; letter-spacing: -0.25px; }

#sources-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1.18rem 16px 0.71rem;        /* 20/12pt */
  overscroll-behavior-y: contain;
}

.source-group {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 0.94rem;               /* 16pt */
}
.source-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0.71rem 0.82rem;             /* 12/14pt */
  background: var(--bg-card);
  min-height: 62px;
  touch-action: pan-y;
  transition: transform 0.3s var(--ease);
}
.source-row + .source-row { border-top: 0.5px solid var(--separator); }
.source-row .source-icon {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--fill);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 1.059rem;
  font-weight: 700;
  color: var(--secondary);
}
.source-row .source-icon { position: relative; }
.source-row .source-icon img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.source-row .source-icon svg { width: 20px; height: 20px; }
.source-letter { line-height: 1; }
.source-row .s-text { flex: 1; min-width: 0; }
.source-row .s-title { font-size: 1rem; font-weight: 500; letter-spacing: -0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-row .s-sub { font-size: 0.765rem; color: var(--secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-row .s-sub--error { color: var(--error); }
.source-row .s-chevron { flex: none; color: var(--tertiary); width: 12px; height: 12px; }
.source-row .s-delete {
  position: absolute;
  top: 0; right: -92px;
  width: 92px; height: 100%;
  background: #ff3b30;
  color: #fff;
  font-size: 0.882rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s var(--ease-fast);
}
.source-row .s-delete:active { opacity: 0.8; }

#sources-footer {
  flex: none;
  text-align: center;
  font-size: 0.765rem;
  color: var(--tertiary);
  padding: 4px 24px calc(18px + env(safe-area-inset-bottom));
}

/* ---------------- Misc ---------------- */

.mono-glyph { font-variant-numeric: tabular-nums; }

@supports (height: 100dvh) {
  #sheet { max-height: min(88dvh, calc(100dvh - env(safe-area-inset-top))); }
}
