/* Groundish — light and dark, no build step, no web fonts. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #16191d;
  --muted: #626b76;
  --faint: #8d96a0;
  --accent: #1f6feb;

  --unrated: #7a828c;
  --left: #2f6fd0;
  --lean_left: #7aa7e8;
  --center: #9aa3ae;
  --lean_right: #ef9b86;
  --right: #d93b30;

  --ok: #17803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 14px rgba(16,24,40,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c232c;
    --border: #2a323d;
    --text: #e6edf3;
    --muted: #98a3b0;
    --faint: #6e7c8c;
    --accent: #58a6ff;
    --unrated: #6b7280;
    --left: #4b8bee;
    --lean_left: #6f9be0;
    --center: #8b95a1;
    --lean_right: #e08a72;
    --right: #f0554a;
    --ok: #3fb950;
    --warn: #d29922;
    --bad: #f85149;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.28);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: inherit; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 20px; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 16px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { display: flex; width: 34px; height: 34px; border-radius: 9px; overflow: hidden; box-shadow: var(--shadow); }
.logo i { flex: 1; }
.logo .l { background: var(--left); }
.logo .c { background: var(--center); }
.logo .r { background: var(--right); }
h1 { font-size: 20px; margin: 0; letter-spacing: -.02em; }
.tagline { margin: 0; font-size: 12.5px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.freshness { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.freshness.busy { color: var(--accent); }

.btn {
  font: inherit; font-size: 13px; font-weight: 550;
  padding: 7px 13px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; }

.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tab {
  font: inherit; font-size: 14px; font-weight: 550;
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 10px 12px; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-count:empty { display: none; }
.tab-count {
  font-size: 11px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 20px; padding: 1px 7px; margin-left: 2px; color: var(--muted);
}

/* --------------------------------------------------------------- filters */
main { padding-top: 20px; padding-bottom: 48px; }
.panel {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; margin-bottom: 18px;
}
.search {
  flex: 1 1 260px; min-width: 180px; font: inherit; font-size: 14px;
  padding: 8px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
.search:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.field select {
  font: inherit; font-size: 13px; padding: 7px 9px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.result-count { font-size: 12.5px; color: var(--faint); margin-left: auto; }

/* --------------------------------------------------------------- stories */
.story {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.story h2 { overflow-wrap: anywhere; font-size: 17.5px; line-height: 1.35; margin: 0 0 6px; letter-spacing: -.01em; }
.story-meta { font-size: 12.5px; color: var(--muted); margin: 0 0 12px; }
.story-meta b { color: var(--text); font-weight: 600; }
.dot::before { content: "·"; margin: 0 7px; color: var(--faint); }

/* Collapsible consensus summary under each headline. */
.tldr { margin: -2px 0 11px; }
.tldr > summary {
  cursor: pointer; font-size: 12.5px; color: var(--muted);
  list-style: none; display: inline-flex; align-items: center; gap: 5px;
  user-select: none; padding: 2px 0;
}
.tldr > summary::-webkit-details-marker { display: none; }
.tldr > summary::before {
  content: "›"; font-size: 14px; line-height: 1;
  transition: transform .15s ease; display: inline-block;
}
.tldr[open] > summary::before { transform: rotate(90deg); }
.tldr > summary:hover { color: var(--accent); }
.tldr .body {
  margin: 7px 0 0; padding: 0 0 0 11px;
  border-left: 2px solid var(--border);
  font-size: 13.5px; line-height: 1.5; color: var(--text);
}
.tldr .via { display: block; margin-top: 6px; font-size: 11.5px; color: var(--faint); }

/* "Write with Gemini" control inside a summary toggle. */
.tldr > summary .gen {
  margin-left: 10px; font: inherit; font-size: 11px; font-weight: 600;
  padding: 2px 9px; border-radius: 20px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
}
.tldr > summary .gen:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.tldr > summary .gen:disabled { opacity: .7; cursor: default; }
.tldr .note { color: var(--warn); }
.dots::after {
  content: "…"; display: inline-block; width: 1em; text-align: left;
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "…"; } }

/* Key entry, shown only where the browser must supply its own credential. */
.keypanel {
  position: absolute; right: 20px; top: 62px; z-index: 40;
  width: min(380px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; box-shadow: var(--shadow);
}
.keypanel p { margin: 0 0 10px; font-size: 12px; line-height: 1.5; color: var(--muted); }
.keypanel input {
  width: 100%; font: inherit; font-size: 13px; padding: 8px 10px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
.keypanel .row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.keypanel .row .freshness { white-space: normal; line-height: 1.4; }
#addpanel { width: min(460px, calc(100vw - 32px)); }
#addresult:not(:empty) {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--muted); max-height: 260px; overflow-y: auto;
}
#addresult .hit { padding: 3px 0; line-height: 1.5; }
#addresult .hit b { color: var(--text); font-weight: 600; }

.badge {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; padding: 3px 9px; border-radius: 20px; margin-bottom: 8px;
}
.badge.bs-right { background: color-mix(in srgb, var(--right) 16%, transparent); color: var(--right); border: 1px solid color-mix(in srgb, var(--right) 40%, transparent); }
.badge.added {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}
.badge.bs-left  { background: color-mix(in srgb, var(--left) 16%, transparent);  color: var(--left);  border: 1px solid color-mix(in srgb, var(--left) 40%, transparent); }

.biasbar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.biasbar span { display: block; transition: filter .15s; }
.biasbar span:hover { filter: brightness(1.15); }
.seg-left { background: var(--left); }
.seg-lean_left { background: var(--lean_left); }
.seg-center { background: var(--center); }
.seg-lean_right { background: var(--lean_right); }
.seg-right { background: var(--right); }
.seg-unrated { background: var(--unrated); background-image:
  repeating-linear-gradient(45deg, rgba(255,255,255,.14) 0 4px, transparent 4px 8px); }

.biaslegend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 7px; }
.biaslegend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.biaslegend b { color: var(--text); font-weight: 600; }

.pills { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.pill {
  font-size: 11.5px; padding: 3px 9px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
}
.pill b { color: var(--text); font-weight: 600; }
.pill.flag { border-color: color-mix(in srgb, var(--warn) 45%, transparent); color: var(--warn); }
.pill.high { color: var(--ok); }
.pill.low { color: var(--bad); }

.story-actions { margin-top: 12px; display: flex; gap: 8px; }

/* -------------------------------------------------------- framing / modal */
.framing { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(min(168px, 100%), 1fr)); margin-top: 14px; }
.frame {
  border: 1px solid var(--border); border-top-width: 3px; border-radius: 10px;
  padding: 10px 12px; background: var(--bg);
}
.frame.left { border-top-color: var(--left); }
.frame.lean_left { border-top-color: var(--lean_left); }
.frame.center { border-top-color: var(--center); }
.frame.lean_right { border-top-color: var(--lean_right); }
.frame.right { border-top-color: var(--right); }
.frame.unrated { border-top-color: var(--unrated); }
.frame h4 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.frame h4 span { color: var(--faint); font-weight: 500; }
.frame a { overflow-wrap: anywhere; display: block; font-size: 13.5px; line-height: 1.4; text-decoration: none; margin-bottom: 9px; }
.frame a:hover .hl { text-decoration: underline; }
.frame .src { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(3,7,14,.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px; z-index: 60; overflow-y: auto;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  max-width: 880px; width: 100%; padding: 22px; position: relative; box-shadow: var(--shadow);
}
.modal-close {
  position: absolute; top: 10px; right: 12px; background: none; border: 0;
  font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer;
}
.modal h2 { margin: 0 8px 8px 0; font-size: 21px; line-height: 1.3; }
.modal h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 0 10px; }

.outlet-row {
  display: flex; align-items: baseline; gap: 10px; padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.outlet-row:last-child { border-bottom: 0; }
.outlet-tag {
  flex: 0 0 132px; font-size: 12px; font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}
.outlet-tag i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.outlet-row a { font-size: 14px; text-decoration: none; min-width: 0; overflow-wrap: anywhere; }
.outlet-row a:hover { text-decoration: underline; }
.outlet-row .when { margin-left: auto; font-size: 11.5px; color: var(--faint); white-space: nowrap; padding-left: 10px; }

/* --------------------------------------------------------------- sources */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(255px, 100%), 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-left-width: 3px; border-radius: 10px; padding: 12px 14px;
}
.card.left { border-left-color: var(--left); }
.card.lean_left { border-left-color: var(--lean_left); }
.card.center { border-left-color: var(--center); }
.card.lean_right { border-left-color: var(--lean_right); }
.card.right { border-left-color: var(--right); }
.card h4 { margin: 0 0 3px; font-size: 14.5px; }
.card p { margin: 0; font-size: 12px; color: var(--muted); }
.card .n { float: right; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.section-head { margin: 26px 0 12px; display: flex; align-items: baseline; gap: 10px; }
.section-head h3 { margin: 0; font-size: 15px; }
.section-head span { font-size: 12.5px; color: var(--muted); }

.stat-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); margin-bottom: 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 13px 15px; }
.stat b { display: block; font-size: 24px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

table.owners { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.owners td { padding: 7px 0; border-bottom: 1px solid var(--border); }
table.owners td:last-child { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.meter { height: 6px; border-radius: 3px; background: var(--accent); min-width: 2px; }

.prose { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; }
.prose h3 { margin-top: 22px; font-size: 15px; }
.prose h3:first-child { margin-top: 0; }
.prose p, .prose li { color: var(--muted); font-size: 14px; }
.prose strong { color: var(--text); }
.prose code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.spinner {
  width: 22px; height: 22px; border: 2.5px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
[hidden] { display: none !important; }

@media (max-width: 700px) {
  .wrap { padding: 0 14px; }
  .result-count { margin-left: 0; }
  .topbar-inner { flex-wrap: wrap; }
  .search { flex-basis: 100%; }
  .story { padding: 14px; }
  .modal { padding: 18px 14px; }
  .outlet-row { flex-wrap: wrap; row-gap: 2px; }
  .outlet-tag { flex: 0 0 100%; }
  .outlet-row .when { margin-left: 0; padding-left: 0; }
}
