/* ─── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ─── Design tokens ──────────────────────────────────────────────── */
:root {
  color-scheme: light dark;

  --bg:      #f5f5f7;
  --surface: #ffffff;
  --surface2:#f5f5f7;
  --border:  #e8e8ed;
  --border2: #d2d2d7;
  --text:    #1d1d1f;
  --muted:   #6e6e73;
  --muted2:  #86868b;
  --accent:  #0071e3;
  --red:     #e3212b;
  --green:   #248a3d;
  --orange:  #ff9f0a;
  --shadow:  rgba(0, 0, 0, 0.08);
  --radius:  16px;
  --radius-sm: 12px;

  --warn-bg:     #fff8e1;
  --warn-border: #ffe082;
  --warn-text:   #664d03;

  /* source badges: background / text */
  --ynet-bg:   #fce4ec; --ynet-fg:   #c62828;
  --maariv-bg: #e3f2fd; --maariv-fg: #1565c0;
  --walla-bg:  #ede7f6; --walla-fg:  #4527a0;
  --globes-bg: #e8f5e9; --globes-fg: #2e7d32;
  --ih-bg:     #fff3e0; --ih-fg:     #e65100;
  --tm-bg:     #e0f7fa; --tm-fg:     #00695c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #000000;
    --surface: #1c1c1e;
    --surface2:#2c2c2e;
    --border:  #2c2c2e;
    --border2: #3a3a3c;
    --text:    #f5f5f7;
    --muted:   #aeaeb2;
    --muted2:  #8e8e93;
    --accent:  #0a84ff;
    --red:     #ff453a;
    --green:   #30d158;
    --shadow:  rgba(0, 0, 0, 0.5);

    --warn-bg:     rgba(255, 214, 10, 0.1);
    --warn-border: rgba(255, 214, 10, 0.3);
    --warn-text:   #ffd60a;

    --ynet-bg:   rgba(255, 69, 58, 0.18);  --ynet-fg:   #ff7b72;
    --maariv-bg: rgba(10, 132, 255, 0.18); --maariv-fg: #64b5ff;
    --walla-bg:  rgba(191, 90, 242, 0.18); --walla-fg:  #d69cf5;
    --globes-bg: rgba(48, 209, 88, 0.16);  --globes-fg: #5fe07f;
    --ih-bg:     rgba(255, 159, 10, 0.18); --ih-fg:     #ffb340;
    --tm-bg:     rgba(100, 210, 255, 0.16);--tm-fg:     #70d7ff;
  }
}

/* ─── Base ───────────────────────────────────────────────────────── */
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

/* ─── Status ─────────────────────────────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-inline-start: auto;
  font-size: 0.78rem;
  color: var(--muted2);
  white-space: nowrap;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted2);
  flex-shrink: 0;
}

.dot.live    { background: #34c759; animation: pulse 2s infinite; }
.dot.error   { background: var(--red); }
.dot.loading { background: var(--orange); animation: pulse 1s infinite; }

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

/* ─── Main ───────────────────────────────────────────────────────── */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 4rem;
}

/* ─── State messages ─────────────────────────────────────────────── */
.state-msg {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--muted2);
}

.state-msg h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.state-msg p {
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 400px;
  margin: 0 auto;
  line-height: 1.6;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

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

/* ─── Feed grid ──────────────────────────────────────────────────── */
.feed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

/* ─── Article card ───────────────────────────────────────────────── */
.card {
  position: relative; /* anchor for the stretched .card-link */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s, transform 0.2s;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px var(--shadow);
}

.card:has(.card-link:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card-image {
  width: 100%;
  height: 180px;
  object-fit: cover;
  display: block;
  background: var(--surface2);
}

.card-body {
  padding: 1.25rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}

.pub-date {
  font-size: 0.75rem;
  color: var(--muted2);
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
  overflow-wrap: break-word;
  word-break: break-word;
}

.card-link {
  color: inherit;
  text-decoration: none;
}

/* whole card is the click/tap target */
.card-link::after {
  content: "";
  position: absolute;
  inset: 0;
}

.card-link:focus-visible { outline: none; }
.card:hover .card-link { color: var(--accent); }

.card-desc {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.55;
  overflow-wrap: break-word;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ─── Source badges ──────────────────────────────────────────────── */
.source-badge {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.2rem 0.6rem;
  border-radius: 980px;
  white-space: nowrap;
  background: var(--surface2);
  color: var(--muted);
}

.src-ynet        { background: var(--ynet-bg);   color: var(--ynet-fg); }
.src-maariv      { background: var(--maariv-bg); color: var(--maariv-fg); }
.src-walla       { background: var(--walla-bg);  color: var(--walla-fg); }
.src-globes      { background: var(--globes-bg); color: var(--globes-fg); }
.src-israelhayom { background: var(--ih-bg);     color: var(--ih-fg); }
.src-themarker   { background: var(--tm-bg);     color: var(--tm-fg); }

/* ─── Shared pill buttons (view toggle, source filter, poly toggle) ─ */
.view-btn,
.source-filter-btn,
.poly-view-btn {
  border-radius: 980px;
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.view-btn:hover,
.source-filter-btn:hover,
.poly-view-btn:hover {
  background: var(--surface2);
  color: var(--text);
}

.view-btn.active,
.source-filter-btn.active,
.poly-view-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ─── View toggle toolbar ────────────────────────────────────────── */
.view-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0.75rem 0 0.5rem;
}

.view-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0.3rem 0.85rem;
  font-size: 0.8rem;
}

/* ─── Source filter bar ──────────────────────────────────────────── */
.source-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 0;
  margin-bottom: 0.5rem;
}

.source-filter-btn {
  padding: 0.35rem 0.9rem;
  font-size: 0.8rem;
}

/* ─── Feed errors (one compact line) ─────────────────────────────── */
.feed-errors:empty { display: none; }
.feed-errors { margin-bottom: 1rem; }

.feed-error {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.9rem;
  font-size: 0.8rem;
  color: var(--warn-text);
}

/* ─── Polymarket section ─────────────────────────────────────────── */
.poly-section {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
}

.poly-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.poly-section-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.poly-section-link {
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
  margin-left: 2.5rem; /* room for the floating refresh button */
  direction: ltr;
  white-space: nowrap;
}

.poly-section-link:hover { text-decoration: underline; }

.poly-body {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.poly-status {
  font-size: 0.875rem;
  color: var(--muted);
}

.poly-days-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
  width: 100%;
}

.poly-day-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  flex: 1;
  min-width: 70px;
  text-align: center;
}

.poly-day-today {
  background: var(--surface);
  border: 2px solid var(--accent);
}

.poly-day-name {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted2);
}

.poly-day-pct {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.poly-day-today .poly-day-pct {
  font-size: 2.4rem;
  color: var(--accent);
  letter-spacing: -0.03em;
}

.poly-day-date {
  font-size: 0.62rem;
  color: var(--muted2);
}

.poly-day-trend {
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.poly-day-trend.up   { color: var(--green); }
.poly-day-trend.down { color: var(--red); }

.poly-vol {
  font-size: 0.8rem;
  color: var(--muted2);
  direction: ltr;
}

/* ─── Polymarket view toggle ─────────────────────────────────────── */
.poly-view-toggle {
  display: flex;
  gap: 4px;
}

.poly-view-btn {
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
}

/* ─── Polymarket graph ───────────────────────────────────────────── */
.poly-graph-wrap {
  width: 100%;
  direction: ltr;
}

.poly-graph-wrap svg {
  width: 100%;
  height: auto;
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.poly-graph-grid {
  stroke: var(--border2);
  stroke-width: 1;
}

.poly-graph-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.poly-graph-axis-label {
  font-size: 13px;
  fill: var(--muted2);
}

.poly-graph-peak-dot      { fill: var(--accent); }
.poly-graph-peak-dot--max { fill: var(--red); }

.poly-graph-peak-label {
  font-size: 12px;
  font-weight: 600;
  fill: var(--accent);
}

.poly-graph-peak-label--max { fill: var(--red); }

/* ─── Footer ─────────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.8rem;
  color: var(--muted2);
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: 2rem;
}

footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ─── Refresh button ─────────────────────────────────────────────── */
.refresh-btn {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 1000;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  background: var(--surface);
  box-shadow: 0 2px 8px var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--muted);
  transition: color 0.15s, box-shadow 0.15s;
}

.refresh-btn:hover {
  color: var(--accent);
  box-shadow: 0 4px 12px var(--shadow);
}

/* spins continuously while feeds / Polymarket are loading */
.refresh-btn.spinning svg {
  animation: spin 0.8s linear infinite;
}

/* ─── Timeline view ──────────────────────────────────────────────── */
/*
 * Layout: .feed-timeline has padding-right: 0.5rem (8px) for the dot/track area.
 * The ::before track sits at right: 0.75rem (12px), center at 13px from container right.
 * .tl-dot is the first (rightmost in RTL) flex child; its right edge = content area right
 * = 8px from container right, so its center = 13px — aligns with the track. ✓
 */
.feed-timeline {
  position: relative;
  padding-right: 0.5rem;
}

.feed-timeline::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0.75rem;
  width: 2px;
  background: var(--border2);
  border-radius: 1px;
}

.tl-group-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted2);
  letter-spacing: 0.04em;
  padding: 1.25rem 0 0.4rem;
  /* extend into container padding to mask the track behind label text */
  margin-right: -0.5rem;
  padding-right: 0.5rem;
  background: var(--bg);
  position: relative;
  z-index: 1;
}

.feed-timeline > .tl-group-label:first-child {
  padding-top: 0.25rem;
}

.tl-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.45rem 0;
}

/* In RTL: .tl-dot is the first flex child → appears on the RIGHT */
.tl-dot {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  background: var(--muted2);
  margin-top: 4px;
  position: relative;
  z-index: 1;
}

.tl-dot--1 { background: var(--muted2); }
.tl-dot--2 { background: var(--orange); }
.tl-dot--3 { background: var(--red); }

.tl-content {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.4rem 0.6rem;
  flex: 1;
  min-width: 0;
}

.tl-time {
  font-size: 0.72rem;
  color: var(--muted2);
  white-space: nowrap;
  flex-shrink: 0;
}

.tl-headline {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  line-height: 1.35;
  overflow-wrap: break-word;
  word-break: break-word;
  flex: 1;
  min-width: 160px;
}

.tl-headline:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ─── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Poly section */
  .poly-section {
    padding: 1rem;
  }

  .poly-section-header {
    margin-bottom: 10px;
  }

  .poly-days-row {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  .poly-day-card {
    min-width: 76px;
    flex-shrink: 0;
    padding: 8px 10px;
  }

  .poly-day-today .poly-day-pct { font-size: 1.4rem; }
  .poly-day-pct { font-size: 0.95rem; }
  .poly-day-name,
  .poly-day-pct,
  .poly-day-date,
  .poly-day-trend { white-space: nowrap; }

  /* Main & grid */
  main {
    padding: 1rem 0.75rem 3rem;
  }

  .feed-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .card-body {
    padding: 1rem;
  }

  /* Source filter: one swipeable row instead of wrapping */
  .source-filter-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    margin-inline: -0.75rem;
    padding-inline: 0.75rem;
  }

  .source-filter-bar::-webkit-scrollbar { display: none; }

  /* Footer */
  footer {
    padding: 1.5rem 1rem;
    line-height: 2;
  }

  /* Timeline: time + source on one line, headline full-width below */
  .tl-headline {
    flex-basis: 100%;
    font-size: 0.9rem;
  }

  .view-toolbar {
    padding-top: 0.5rem;
  }

  /* Graph labels — bump SVG font-sizes to stay legible after scale-down */
  .poly-graph-axis-label {
    font-size: 18px;
  }

  .poly-graph-peak-label {
    font-size: 20px;
  }
}

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

  .card:hover { transform: none; }
}
