:root {
  color-scheme: dark light;
  --bg: #0d1519;
  --panel: #152126;
  --panel-strong: #1d2d33;
  --panel-soft: #263940;
  --line: #334b54;
  --text: #f3f8f8;
  --muted: #a8b7bc;
  --accent: #2db8b3;
  --accent-soft: #80dfda;
  --official: #4ecb87;
  --high: #77b9ec;
  --rumour: #e0a63b;
  --danger: #dc6c6c;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef4f3;
    --panel: #ffffff;
    --panel-strong: #e5eeec;
    --panel-soft: #d8e6e3;
    --line: #c1d2cf;
    --text: #142126;
    --muted: #5f7076;
    --accent: #087f7a;
    --accent-soft: #086c68;
    --official: #167a4d;
    --high: #276c9d;
    --rumour: #99680d;
    --danger: #a33c3c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1519;
  --panel: #152126;
  --panel-strong: #1d2d33;
  --panel-soft: #263940;
  --line: #334b54;
  --text: #f3f8f8;
  --muted: #a8b7bc;
  --accent: #2db8b3;
  --accent-soft: #80dfda;
  --official: #4ecb87;
  --high: #77b9ec;
  --rumour: #e0a63b;
  --danger: #dc6c6c;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef4f3;
  --panel: #ffffff;
  --panel-strong: #e5eeec;
  --panel-soft: #d8e6e3;
  --line: #c1d2cf;
  --text: #142126;
  --muted: #5f7076;
  --accent: #087f7a;
  --accent-soft: #086c68;
  --official: #167a4d;
  --high: #276c9d;
  --rumour: #99680d;
  --danger: #a33c3c;
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body.dialog-open { overflow: hidden; }

body {
  height: 100vh;
  height: 100dvh;
  margin: 0;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 10%, transparent), transparent 26rem),
    var(--bg);
  color: var(--text);
  font-size: calc(16px * var(--research-font-scale, 1));
}

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

.research-shell {
  display: flex;
  flex-direction: column;
  width: calc(100% - 24px);
  height: 100vh;
  height: 100dvh;
  max-width: 1680px;
  margin: 0 auto;
  padding: 12px 0 8px;
  overflow: hidden;
}
.research-shell > * { min-width: 0; max-width: 100%; }

.research-topbar {
  display: grid;
  grid-template-columns: minmax(220px, .8fr) minmax(180px, auto) minmax(500px, 1.6fr) auto;
  align-items: center;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
}
.research-topbar > *, .research-toolbar > *, .research-summary > * { min-width: 0; }

.research-brand, .research-current, .research-nav { display: flex; align-items: center; }
.research-brand { gap: 12px; }
.research-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: var(--accent);
  color: #071719;
  font-size: 2rem;
  font-weight: 900;
}
.research-brand h1 { margin: 0; font-size: 1.45rem; line-height: 1.05; }
.research-brand p { margin: 4px 0 0; color: var(--muted); font-size: .82rem; font-weight: 750; }

.research-current { justify-content: center; gap: 10px; min-width: 0; }
.research-current-logo {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
}
.research-current-logo img { width: 100%; height: 100%; object-fit: contain; }
.research-current strong, .research-current span { display: block; }
.research-current strong { font-size: 1rem; }
.research-current span { color: var(--muted); font-size: .76rem; font-weight: 750; }
.research-nav { justify-content: flex-end; gap: 8px; }
.icon-button, .hub-button, .refresh-button, .research-menu-button {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--text);
  font-weight: 900;
}
.icon-button { width: 42px; font-size: 1.25rem; }
.hub-button { padding: 0 18px; }
.research-menu-button { width: 52px; height: 52px; font-size: 1.3rem; }
.icon-button:hover, .hub-button:hover, .refresh-button:hover { border-color: var(--accent); color: var(--accent-soft); }

.research-menu {
  position: fixed;
  z-index: 80;
  top: 86px;
  right: max(12px, calc((100vw - 1680px) / 2 + 12px));
  display: none;
  width: min(390px, calc(100vw - 24px));
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}
.research-menu.open { display: grid; }
.research-menu .ad-menu-section { display: grid; gap: 9px; }
.research-font-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 850;
}
.research-font-row input { width: 100%; accent-color: var(--accent); }
.research-font-row strong { color: var(--accent-soft); }

.research-dialog-backdrop {
  position: fixed;
  z-index: 120;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 10, 13, .76);
  backdrop-filter: blur(5px);
}
.research-dialog-backdrop[hidden] { display: none; }
.research-dialog {
  width: min(980px, 100%);
  max-height: min(820px, calc(100vh - 36px));
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 28px 80px rgba(0, 0, 0, .45);
}
.research-dialog > header {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  backdrop-filter: blur(8px);
}
.research-dialog h2, .research-dialog p { margin: 0; }
.research-dialog h2 { font-size: 1.18rem; }
.research-dialog p { margin-top: 3px; color: var(--muted); font-size: .76rem; font-weight: 700; }
.research-source-actions { display: flex; gap: 8px; padding: 12px 16px 0; }
.research-source-actions button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  background: var(--panel-strong);
  color: var(--text);
  font-weight: 850;
}
.research-source-actions button:hover { border-color: var(--accent); }
.research-source-settings { display: grid; gap: 12px; padding: 12px 16px 18px; }
.source-settings-section {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--panel-strong);
}
.source-settings-section h3 { margin: 0 0 10px; color: var(--accent-soft); font-size: .78rem; text-transform: uppercase; }
.source-toggle-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.source-toggle-card, .source-channel-row, .publisher-toggle-grid label {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.source-toggle-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  min-height: 72px;
  padding: 9px;
}
.source-toggle-card input, .source-channel-row input, .publisher-toggle-grid input { accent-color: var(--accent); }
.source-toggle-card strong, .source-toggle-card small, .source-channel-row strong, .source-channel-row small { display: block; }
.source-toggle-card small, .source-channel-row small { margin-top: 2px; color: var(--muted); font-size: .68rem; line-height: 1.25; }
.source-toggle-card b, .publisher-toggle-grid b { color: var(--accent-soft); font-size: .72rem; }
.source-channel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.source-channel-row { display: grid; grid-template-columns: minmax(0, 1fr) 36px; align-items: stretch; opacity: .58; }
.source-channel-row.active { opacity: 1; }
.source-channel-row label { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 8px; padding: 8px; }
.source-channel-row > a { display: grid; place-items: center; border-left: 1px solid var(--line); color: var(--accent-soft); font-weight: 950; }
.source-channel-row > a:hover { background: color-mix(in srgb, var(--accent) 13%, var(--panel)); }
.publisher-settings { padding: 0; }
.publisher-settings summary { display: flex; justify-content: space-between; padding: 11px 12px; color: var(--accent-soft); cursor: pointer; font-weight: 900; list-style: none; }
.publisher-settings summary::-webkit-details-marker { display: none; }
.publisher-settings summary span { color: var(--muted); }
.publisher-toggle-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; border-top: 1px solid var(--line); padding: 10px; }
.publisher-toggle-grid label { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 7px; padding: 7px 8px; font-size: .74rem; font-weight: 800; }
.publisher-toggle-grid span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.article-summary-hover {
  position: fixed;
  z-index: 110;
  width: min(440px, calc(100vw - 24px));
  max-height: min(420px, calc(100vh - 24px));
  overflow: auto;
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 13px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  color: var(--text);
  box-shadow: 0 22px 65px rgba(0, 0, 0, .42);
  backdrop-filter: blur(10px);
}
.article-summary-hover[hidden] { display: none; }
.article-hover-head { display: flex; align-items: center; gap: 10px; }
.article-hover-head span, .article-hover-head strong {
  color: var(--accent-soft);
  font-size: .68rem;
  font-weight: 900;
  text-transform: uppercase;
}
.article-hover-head strong { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; text-transform: none; }
.article-summary-hover h3 { margin: 9px 0 8px; font-size: 1rem; line-height: 1.25; }
.article-hover-summary {
  border-top: 1px solid var(--line);
  padding-top: 9px;
  color: var(--text);
  font-size: .82rem;
  line-height: 1.48;
}
.article-hover-summary.loading { color: var(--muted); }
.article-hover-summary.loading::after { content: ""; display: inline-block; width: 1.1em; height: 1.1em; margin-left: 7px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; vertical-align: -.2em; animation: hover-spin .75s linear infinite; }
.article-summary-hover > small { display: block; margin-top: 7px; color: var(--muted); font-size: .68rem; }
.article-summary-hover footer { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 10px; border-top: 1px solid var(--line); padding-top: 9px; color: var(--muted); font-size: .72rem; font-weight: 800; }
.article-summary-hover footer a { color: var(--accent-soft); }
.article-summary-hover footer a:hover { text-decoration: underline; }
@keyframes hover-spin { to { transform: rotate(360deg); } }

.research-toolbar {
  display: grid;
  grid-template-columns: minmax(170px, .7fr) minmax(230px, 1fr) minmax(300px, 1.5fr) 44px;
  gap: 10px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--panel);
}
.field { min-width: 0; }
.field span, .compact-field span, .eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: .67rem;
  font-weight: 900;
  text-transform: uppercase;
}
.field select, .field input, .compact-field select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
  background: var(--panel-strong);
  color: var(--text);
  outline: none;
}
.field select:focus, .field input:focus, .compact-field select:focus { border-color: var(--accent); }
.refresh-button { align-self: end; width: 44px; height: 38px; min-height: 38px; font-size: 1.25rem; }

.research-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
}
.research-status-copy strong, .research-status-copy span { display: block; }
.research-status-copy strong { font-size: .88rem; }
.research-status-copy span { margin-top: 2px; color: var(--muted); font-size: .66rem; font-weight: 750; white-space: nowrap; }
.summary-counters { display: flex; gap: 7px; }
.summary-counters button {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  background: var(--panel);
  color: var(--muted);
}
.summary-counters button.active { border-color: var(--accent); color: var(--text); }
.summary-counters strong { color: var(--accent-soft); font-size: .88rem; }
.summary-counters span { font-size: .65rem; font-weight: 850; }

.research-filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.topic-filters { display: flex; flex: 1; gap: 6px; overflow-x: auto; padding-bottom: 1px; }
.topic-filters button {
  flex: 0 0 auto;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: .78rem;
  font-weight: 850;
}
.topic-filters button.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--panel)); color: var(--text); }
.compact-field { flex: 0 0 150px; }
.compact-field select { min-height: 36px; font-size: .78rem; }

.research-notice {
  margin-top: 10px;
  border: 1px solid color-mix(in srgb, var(--rumour) 70%, var(--line));
  border-radius: 8px;
  padding: 9px 12px;
  background: color-mix(in srgb, var(--rumour) 10%, var(--panel));
  color: var(--text);
  font-size: .82rem;
  font-weight: 750;
}

.research-feed {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: 138px;
  align-content: start;
  gap: 8px;
  margin-top: 8px;
  padding: 0 3px 8px 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.news-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 138px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px;
  background: var(--panel);
  transition: border-color 130ms ease, transform 130ms ease;
}
.news-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.news-card.saved { box-shadow: inset 3px 0 var(--accent); }
.news-card.confirmed { opacity: .64; background: color-mix(in srgb, var(--official) 5%, var(--panel)); }
.news-card-head { display: flex; align-items: center; gap: 6px; padding-right: 72px; }
.trust-chip, .topic-chip {
  border-radius: 999px;
  padding: 3px 7px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: .65rem;
  font-weight: 900;
}
.trust-chip.official { color: var(--official); }
.trust-chip.high { color: var(--high); }
.trust-chip.rumour { color: var(--rumour); }
.save-button, .confirm-button {
  position: absolute;
  top: 7px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: .95rem;
}
.save-button { right: 6px; }
.confirm-button { right: 40px; }
.save-button.active { border-color: var(--accent); color: var(--accent-soft); }
.confirm-button.active { border-color: var(--official); background: color-mix(in srgb, var(--official) 18%, var(--panel-strong)); color: var(--official); }
.news-card h2 {
  display: -webkit-box;
  overflow: hidden;
  margin: 11px 0 4px;
  font-size: .9rem;
  line-height: 1.22;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.news-card h2 a:hover { color: var(--accent-soft); }
.news-card p {
  display: -webkit-box;
  overflow: hidden;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: .73rem;
  line-height: 1.3;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.news-source-strip { display: flex; min-width: 0; align-items: center; gap: 3px; overflow-x: auto; scrollbar-width: none; }
.news-source-strip::-webkit-scrollbar { display: none; }
.source-badge {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  max-width: 116px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 5px 1px 2px;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: .54rem;
  font-weight: 850;
}
.source-badge i {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 14px;
  height: 14px;
  margin-right: 3px;
  border-radius: 50%;
  background: var(--panel-soft);
  color: var(--text);
  font-size: .46rem;
  font-style: normal;
  font-weight: 950;
}
.source-badge b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-badge:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--panel-strong)); color: var(--text); }
.source-badge.official { border-color: color-mix(in srgb, var(--official) 55%, var(--line)); color: var(--official); }
.source-badge.social { border-color: color-mix(in srgb, var(--high) 55%, var(--line)); color: var(--high); }
.news-card-footer {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 5px;
  margin-top: auto;
  padding-top: 5px;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 750;
}
.news-card-footer strong { display: block; flex: 0 0 auto; color: var(--text); }
.news-card-footer .news-source-strip { flex: 1 1 auto; }
.open-source { flex: 0 0 auto; margin-left: auto; color: var(--accent-soft); white-space: nowrap; }
.empty-feed {
  grid-column: 1 / -1;
  min-height: 240px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 30px;
  color: var(--muted);
  text-align: center;
  font-weight: 750;
}
.loading-card { min-height: 138px; background: linear-gradient(110deg, var(--panel) 25%, var(--panel-strong) 42%, var(--panel) 60%); background-size: 240% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position-x: -240%; } }

@media (max-width: 1080px) {
  .research-feed { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .research-topbar { grid-template-columns: minmax(190px, .7fr) minmax(460px, 1.5fr) auto; }
  .research-current { display: none; }
}

@media (max-width: 760px) {
  .research-shell { width: calc(100% - 12px); padding: 6px 0; }
  .research-topbar { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  .research-brand { grid-column: 1; grid-row: 1; }
  .research-nav { grid-column: 2; grid-row: 1; }
  .research-mark { width: 46px; height: 46px; }
  .research-brand h1 { font-size: 1.15rem; }
  .research-brand p { display: none; }
  .source-toggle-grid, .source-channel-grid, .publisher-toggle-grid { grid-template-columns: 1fr; }
  .research-toolbar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 42px; }
  .search-field { grid-column: 1 / -1; grid-row: 2; }
  .refresh-button { grid-column: 3; grid-row: 1; }
  .research-summary { grid-column: 1 / -1; grid-row: 2; width: 100%; align-items: center; flex-wrap: wrap; }
  .summary-counters { width: 100%; min-width: 0; gap: 4px; }
  .summary-counters button { min-width: 0; flex: 1; justify-content: center; padding-inline: 4px; }
  .field select, .field input { min-width: 0; }
  .research-filter-row { min-width: 0; flex-wrap: wrap; overflow: hidden; }
  .topic-filters { flex-basis: 100%; }
  .compact-field { flex: 1 1 140px; }
  .research-feed { width: 100%; grid-template-columns: minmax(0, 1fr); }
  .news-card { width: 100%; min-width: 0; }
}
