/* ─────────────────────────────────────────────
   DIGEST — App Stylesheet
   Design: Dark editorial. Ink-on-slate palette.
   Signature: The topic pill nav with live indicator.
───────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700;900&family=Inter:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Tokens ── */
:root {
  --bg: #0a0a0f;
  --bg2: #111118;
  --bg3: #1a1a24;
  --border: #232330;
  --border2: #2e2e40;
  --text: #e8e8f0;
  --text2: #8888a8;
  --text3: #55556a;
  --accent: #c8a96e;        /* warm gold — newsprint ink */
  --accent2: #7c6fff;       /* electric indigo for highlights */
  --red: #e05555;
  --green: #4caf80;
  --radius: 10px;
  --header-h: 100px;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 400;
  line-height: 1.6;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ── Header ── */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10,10,15,0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 10px;
  max-width: 900px;
  margin: 0 auto;
}

.wordmark {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: var(--accent);
}

.datestamp {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text3);
  margin-left: 12px;
  font-weight: 300;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-selector select {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 5px 10px;
  border-radius: 6px;
  outline: none;
  cursor: pointer;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--text); background: var(--bg3); }
.icon-btn.spinning svg { animation: spin 1s linear infinite; }

/* ── Topic Nav ── */
.topic-nav {
  display: flex;
  gap: 6px;
  padding: 10px 20px;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 900px;
  margin: 0 auto;
}
.topic-nav::-webkit-scrollbar { display: none; }

.topic-pill {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-body);
  letter-spacing: 0.03em;
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--border2);
  background: none;
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.topic-pill:hover { border-color: var(--accent); color: var(--accent); }
.topic-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0a0a0f;
}

/* ── Main ── */
#main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px 80px;
  min-height: calc(100dvh - var(--header-h));
}

/* ── State views ── */
.state-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 80px 20px;
  text-align: center;
  color: var(--text2);
}
.state-view h2 { color: var(--text); font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; }
.state-view p { font-size: 0.9rem; line-height: 1.7; max-width: 300px; }
.empty-icon { font-size: 3rem; }

/* ── Spinner ── */
.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Primary button ── */
.primary-btn {
  background: var(--accent);
  color: #0a0a0f;
  border: none;
  padding: 10px 22px;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.primary-btn:hover { opacity: 0.85; }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Topic Section ── */
.topic-section {
  margin-bottom: 48px;
}

.topic-heading {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.topic-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
}

.topic-count {
  font-size: 11px;
  color: var(--text3);
  font-family: var(--font-mono);
}

/* ── Article Cards ── */
.article-grid {
  display: grid;
  gap: 12px;
}

.article-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: block;
  text-decoration: none;
}
.article-card:hover {
  border-color: var(--border2);
  background: var(--bg3);
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.source-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--accent2);
  text-transform: uppercase;
}

.card-time {
  font-size: 11px;
  color: var(--text3);
  font-family: var(--font-mono);
}

.card-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text);
  margin-bottom: 10px;
}

.card-summary {
  font-size: 0.875rem;
  color: var(--text2);
  line-height: 1.65;
  font-weight: 300;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
}

.read-link {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.read-link:hover { text-decoration: underline; }

.read-time {
  font-size: 11px;
  color: var(--text3);
  font-family: var(--font-mono);
}

/* ── Settings Panel ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  backdrop-filter: blur(4px);
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  background: var(--bg2);
  border-left: 1px solid var(--border);
  z-index: 201;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}
.panel-header h2 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.panel-section {
  margin-bottom: 32px;
}
.panel-section h3 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text3);
  font-family: var(--font-mono);
  margin-bottom: 14px;
}

.form-row {
  margin-bottom: 10px;
}
.form-row input,
.form-row select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.form-row input:focus,
.form-row select:focus { border-color: var(--accent); }
.form-row input::placeholder { color: var(--text3); }

/* Source list items */
.source-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.source-item:last-child { border-bottom: none; }

.source-info { flex: 1; min-width: 0; }
.source-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.source-url {
  font-size: 11px;
  color: var(--text3);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.source-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.toggle-switch {
  position: relative;
  width: 34px;
  height: 20px;
  cursor: pointer;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 20px;
  transition: background 0.2s, border-color 0.2s;
}
.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  background: var(--text3);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.toggle-switch input:checked ~ .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle-switch input:checked ~ .toggle-track .toggle-thumb { transform: translateX(14px); background: #0a0a0f; }

.delete-btn {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  transition: color 0.15s;
}
.delete-btn:hover { color: var(--red); }

/* ── Article Modal ── */
.article-modal {
  position: fixed;
  inset: 0;
  z-index: 202;
  background: var(--bg);
  overflow-y: auto;
  padding: 0;
}

.modal-header {
  position: sticky;
  top: 0;
  background: rgba(10,10,15,0.95);
  backdrop-filter: blur(20px);
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

#articleContent {
  max-width: 680px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

.modal-source {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 12px;
}

.modal-title {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  font-weight: 900;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 20px;
}

.modal-summary {
  font-size: 1rem;
  color: var(--text2);
  line-height: 1.8;
  font-weight: 300;
  margin-bottom: 28px;
  padding: 20px;
  background: var(--bg2);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.modal-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
  font-size: 14px;
  border: 1px solid var(--accent);
  padding: 10px 20px;
  border-radius: 8px;
  transition: background 0.15s;
}
.modal-cta:hover { background: rgba(200,169,110,0.1); }

/* ── Run status toast ── */
#toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 13px;
  color: var(--text2);
  z-index: 300;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Responsive ── */
@media (min-width: 680px) {
  .article-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .header-inner { padding: 12px 16px 8px; }
  .topic-nav { padding: 8px 16px; }
  #main { padding: 20px 16px 80px; }
  .article-card { padding: 14px 16px; }
  .card-title { font-size: 0.95rem; }
}

/* iOS safe area */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #main { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* YouTube card badge */
.youtube-badge {
  font-size: 10px;
  background: #ff0000;
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.05em;
}

.duration-badge {
  font-size: 11px;
  color: var(--text3);
  font-family: var(--font-mono);
}

/* Wrap topic nav into two rows — permanent on top, dynamic below */
.topic-nav {
  display: flex !important;
  flex-wrap: wrap !important;
  overflow-x: visible !important;
  gap: 6px;
  padding: 8px 20px 12px !important;
}
.topic-pill.pinned {
  order: -1;
}

/* Wrap topic pills into multiple rows */
.topic-nav {
  display: flex !important;
  flex-wrap: wrap !important;
  overflow-x: visible !important;
  row-gap: 6px;
  padding-bottom: 14px !important;
}
.topic-pill.pinned {
  order: -1;
  border-color: var(--accent);
  color: var(--accent);
}

/* More visible date stamp */
.card-time {
  font-size: 11px;
  color: var(--text2) !important;
  font-family: var(--font-mono);
  background: var(--bg3);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Bullet point summaries */
.bullet-point {
  display: block;
  padding: 3px 0;
  padding-left: 4px;
  border-left: 2px solid var(--border2);
  margin-bottom: 6px;
  line-height: 1.55;
}
.bullet-point:last-child {
  margin-bottom: 0;
}

/* Two-row tab structure */
.topic-nav-wrapper {
  border-bottom: 1px solid var(--border);
  max-width: 900px;
  margin: 0 auto;
}
.topic-nav-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 20px;
}
.topic-nav-row.permanent {
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}
.topic-nav-row.dynamic {
  padding-top: 8px;
}
.topic-pill.section-pill {
  background: var(--bg3);
  border-color: var(--border2);
  color: var(--text2);
  font-weight: 600;
}
.topic-pill.section-pill.active,
.topic-pill.section-pill:hover {
  background: var(--accent2);
  border-color: var(--accent2);
  color: white;
}

.bullet-point {
  display: block;
  padding: 4px 0 4px 4px;
  border-left: 2px solid var(--border2);
  margin-bottom: 6px;
  line-height: 1.55;
}
.bullet-point:last-child { margin-bottom: 0; }

.topic-nav-row.sources {
  padding-top: 6px;
  padding-bottom: 12px;
  border-top: 1px solid var(--border);
}
.topic-pill.source-pill {
  font-size: 11px;
  padding: 3px 10px;
  border-color: var(--border);
  color: var(--text3);
}
.topic-pill.source-pill.active,
.topic-pill.source-pill:hover {
  border-color: var(--accent2);
  color: var(--accent2);
  background: none;
}

/* Dismiss / Mark as Read */
.dismiss-btn {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.dismiss-btn:hover { color: var(--red); background: rgba(224,85,85,0.1); }

.dismiss-modal-btn {
  background: none;
  border: 1px solid var(--border2);
  color: var(--text2);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.dismiss-modal-btn:hover { border-color: var(--red); color: var(--red); }

/* Single nav row */
.nav-divider {
  color: var(--border2);
  padding: 0 4px;
  line-height: 28px;
}

/* Increased contrast for readability */
:root {
  --text: #f5f5fa;
  --text2: #aaaabf;
  --text3: #74748a;
}
.card-summary {
  color: var(--text2) !important;
}
.bullet-point {
  color: var(--text2);
}
