* { box-sizing: border-box; }

body {
  margin: 0; background: #fafafa; color: #1a1a1a; overflow-wrap: anywhere;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit; cursor: pointer; padding: 6px 12px;
  border: 1px solid #ddd; background: #fff; border-radius: 8px;
}
button:hover { background: #f0f0f0; }
button:disabled { opacity: 0.4; cursor: default; }

.muted { color: #888; }
.small { font-size: 12px; }
.spacer { flex: 1; }

/* ── Onboarding ─────────────────────────── */
#onboarding { display: flex; justify-content: center; padding: 40px 20px 140px; }
/* the id display rule would otherwise beat the UA's [hidden] { display: none } */
#onboarding[hidden] { display: none !important; }
.onboard-inner { max-width: 760px; }
.onboard-inner h1 { margin: 0 0 4px; }

.custom-row { display: flex; gap: 8px; margin: 16px 0 24px; }
.custom-row input {
  flex: 1; min-width: 0; font: inherit; padding: 8px 12px; border: 1px solid #ddd; border-radius: 8px;
}

.seed-group { margin-bottom: 18px; }
.seed-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: #999; margin-bottom: 6px;
}
.chip { border-radius: 999px; margin: 0 6px 6px 0; padding: 6px 14px; }
.chip-on { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }
.chip-on:hover { background: #333; }

.start-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, #fafafa 40%);
  display: flex; justify-content: center;
}
#start-btn { padding: 12px 32px; font-weight: 600; background: #1a1a1a; color: #fff; border-color: #1a1a1a; }
#start-btn:disabled { background: #999; border-color: #999; }

/* ── Top bar ────────────────────────────── */
#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; background: #fffffff2;
  border-bottom: 1px solid #eee; backdrop-filter: blur(6px);
  font-size: 14px;
}

/* ── Layout ─────────────────────────────── */
#layout {
  display: flex; gap: 28px; justify-content: center;
  padding: 20px; align-items: flex-start;
}
#feed { width: 540px; max-width: 100%; }
#panel {
  width: 320px; position: sticky; top: 62px;
  max-height: calc(100vh - 80px); overflow-y: auto;
}

/* ── Cards ──────────────────────────────── */
.card {
  background: #fff; border: 1px solid #e8e8e8; border-radius: 14px;
  padding: 18px 20px; margin-bottom: 14px;
  min-height: 150px;
  transition: opacity 0.3s, border-color 0.3s;
  /* keep an endless feed cheap: offscreen cards skip layout/paint */
  content-visibility: auto;
  contain-intrinsic-size: auto 188px;
}
.card-top { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 10px; }
.post-num { color: #bbb; }

.reason { padding: 2px 8px; border-radius: 999px; font-size: 11px; }
.reason-for-you   { background: #e8f0fe; color: #1a56c4; }
.reason-adjacent  { background: #fef3e2; color: #b26a00; }
.reason-discovery { background: #eee;    color: #666; }

.card-entities { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.entity-primary { font-size: 22px; font-weight: 700; }
.entity-secondary { font-size: 15px; color: #666; }
.card-sub { color: #aaa; font-size: 13px; margin: 6px 0 14px; }

.like-btn { border-radius: 999px; }
.card-liked { border-color: #e0245e; }
.card-liked .like-btn { background: #ffe8ef; color: #e0245e; border-color: #e0245e; }
.card-skipped { opacity: 0.55; }

/* Credit-flow line: one row, ellipsis-truncated on narrow screens */
.card-flow { font-size: 12px; color: #999; margin: -6px 0 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-flow .flow-subject { color: #bbb; font-style: italic; }   /* broad "subject" credit */
.card-flow .flow-secondary { color: #b26a00; }                  /* co-tag share */

.card-status { margin-top: 12px; font-size: 12px; color: #999; }
.card-liked .card-status { color: #e0245e; }

/* ── Panel ──────────────────────────────── */
.panel-block {
  background: #fff; border: 1px solid #e8e8e8; border-radius: 14px;
  padding: 14px 16px; margin-bottom: 14px;
}
.panel-block h2 { font-size: 14px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }

.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #2fbf71; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.trend-row {
  display: grid; grid-template-columns: 1fr 80px 44px 48px; gap: 8px;
  align-items: center; font-size: 13px; padding: 3px 0;
}
.trend-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trend-bar-wrap { background: #f0f0f0; border-radius: 4px; height: 8px; overflow: hidden; }
.trend-bar { background: #2fbf71; height: 100%; border-radius: 4px; transition: width 0.5s; }
.trend-bar.trend-neg { background: #e05252; }
.trend-score { text-align: right; font-variant-numeric: tabular-nums; }
.trend-score.neg { color: #e05252; }
.trend-counts { color: #aaa; font-size: 11px; text-align: right; white-space: nowrap; }

.cand-row { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; }
.cand-via { color: #b9b9b9; font-size: 11px; }
.card-via { color: #b26a00; font-size: 12px; margin: -8px 0 12px; }
.cand-score { color: #b26a00; font-variant-numeric: tabular-nums; }

.empty { color: #bbb; font-size: 13px; padding: 8px 0; }

#sentinel { height: 1px; }

/* Mobile-only chrome (stats button, drawer header, drawer actions, scrim)
   is hidden on desktop; the media query below reveals it. */
.mobile-only { display: none; }
#scrim {
  display: none; position: fixed; inset: 0; z-index: 25;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
}

/* ── Mobile (≤920px): feed is the product, stats live in a drawer ── */
@media (max-width: 920px) {
  .desktop-only { display: none; }
  .btn-label { display: none; }

  /* Minimal top bar */
  #topbar {
    padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top));
    gap: 8px;
  }
  #topbar strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #topbar button { padding: 10px 14px; min-height: 44px; }
  #stats-btn { display: inline-block; white-space: nowrap; }
  #feed-progress { display: none; }

  /* Full-bleed feed cards, straight under the top bar */
  #layout { display: block; padding: 0 0 40px; }
  #feed { width: 100%; }
  .card {
    border-left: none; border-right: none; border-radius: 0;
    margin-bottom: 8px; padding: 20px 16px 18px;
  }
  .entity-primary { font-size: 24px; }
  .entity-secondary { font-size: 16px; }
  .card-sub { font-size: 14px; margin-bottom: 16px; }
  .reason { font-size: 12px; }
  .like-btn { padding: 12px 24px; font-size: 16px; }

  /* Stats drawer: full-height slide-over, over the feed */
  #panel {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
    width: min(420px, 100%); max-height: none;
    padding: 0 14px calc(20px + env(safe-area-inset-bottom));
    background: #fafafa; box-shadow: -12px 0 32px rgba(0, 0, 0, 0.18);
    transform: translateX(102%); transition: transform 0.25s ease;
    overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  }
  body.panel-open #panel { transform: translateX(0); }
  body.panel-open { overflow: hidden; } /* feed holds still behind the drawer */
  #scrim { display: block; }
  body.panel-open #scrim { opacity: 1; pointer-events: auto; }

  #panel-head {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 1;
    margin: 0 -14px 12px; padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    background: #fafafa; border-bottom: 1px solid #eee;
  }
  #panel-close { min-height: 44px; }
  .panel-actions { display: flex; gap: 10px; }
  .panel-actions button { flex: 1; padding: 12px; }

  /* Rows read comfortably at full drawer width */
  .trend-row, .cand-row { font-size: 14px; padding: 5px 0; }

  /* Onboarding on a phone */
  #onboarding { padding: 24px 14px 150px; }
  .custom-row input { font-size: 16px; padding: 12px 14px; }
  button { padding: 10px 14px; }
  .chip { padding: 10px 16px; }
  #start-btn { width: 100%; max-width: 420px; padding: 14px 32px; }
}
