/*
 * "Ink & Teal" newsroom palette: cool paper, deep navy ink, one teal accent,
 * and four distinct section colours. Type is Poppins (UI) and Lora (headlines).
 */
:root {
  --ink-900: #0f1b2a;
  --ink-700: #33475b;
  --ink-500: #5f6f80;
  --mist-300: #c9d3db;
  --mist-200: #dce3e8;
  --mist-100: #eaeff2;
  --paper: #f6f8f9;
  --teal-600: #0e7c72;
  --teal-700: #0a6159;
  --teal-100: #d5eeea;
  --amber-100: #f7e6c8;

  --font-sans: "Poppins", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-serif: "Lora", ui-serif, Georgia, "Times New Roman", serif;

  --bg: var(--paper);
  --surface: #ffffff;
  --surface-2: var(--mist-100);
  --border: var(--mist-200);
  --border-strong: var(--mist-300);
  --text: var(--ink-900);
  --text-2: var(--ink-700);
  --text-3: var(--ink-500);
  --accent: var(--teal-600);
  --accent-strong: var(--teal-700);
  --accent-soft: var(--teal-100);
  --focus: var(--teal-600);
  --on-media: var(--ink-900);
  --rank-bg: var(--ink-900);
  --rank-fg: var(--paper);
  --shadow: 0 1px 2px rgb(15 27 42 / 5%), 0 6px 20px -12px rgb(15 27 42 / 22%);

  --cat-world: #2e64a8;
  --cat-ai: #7a5af0;
  --cat-tech: #d9922e;
  --cat-security: #d1495b;
  --cat-economy: #4d8b31;
  --cat-local: #c0398a;
  --cat-blogs: #5f6f80;

  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c141d;
    --surface: #132030;
    --surface-2: #1a2a3c;
    --border: #233447;
    --border-strong: #30455b;
    --text: #eaf0f5;
    --text-2: #b4c2cf;
    --text-3: #8496a7;
    --accent: #2bb3a3;
    --accent-strong: #4fd1c1;
    --accent-soft: #12332f;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px -14px rgb(0 0 0 / 60%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c141d;
  --surface: #132030;
  --surface-2: #1a2a3c;
  --border: #233447;
  --border-strong: #30455b;
  --text: #eaf0f5;
  --text-2: #b4c2cf;
  --text-3: #8496a7;
  --accent: #2bb3a3;
  --accent-strong: #4fd1c1;
  --accent-soft: #12332f;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px -14px rgb(0 0 0 / 60%);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

/* ---- masthead ---------------------------------------------------------- */
.masthead {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.masthead__inner, .tabs, .page, .footer { max-width: 1240px; margin: 0 auto; padding-left: 24px; padding-right: 24px; }
.masthead__inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 18px; padding-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 12px; flex: 1 1 auto; min-width: 0; }
.brand > div { min-width: 0; }
.brand__name { margin: 0; font-family: var(--font-serif); font-weight: 500; font-size: 28px; letter-spacing: -0.01em; line-height: 1.1; }
.brand__meta { margin: 2px 0 0; color: var(--text-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.masthead__actions { display: flex; align-items: center; gap: 8px; flex: none; }

.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding-bottom: 0; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 14px 14px; border: 0; background: none; cursor: pointer;
  color: var(--text-2); font-size: 14px; font-weight: 500; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); }
.tab[aria-selected="true"]::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px;
  background: var(--accent); border-radius: 2px;
}
.tab__count { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ---- controls ---------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 999px; border: 1px solid transparent; cursor: pointer;
  font-size: 14px; font-weight: 500; transition: background .15s, border-color .15s, color .15s;
}
.btn--ghost { background: var(--surface); border-color: var(--border-strong); }
.btn--ghost:hover { border-color: var(--text-3); }
.btn--icon { width: 36px; padding: 0; justify-content: center; background: transparent; }
.btn--icon:hover { background: var(--surface-2); }
.btn--link { background: none; color: var(--accent-strong); padding: 0 6px; }
.btn--link:hover { text-decoration: underline; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.is-spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { display: inline-flex; white-space: nowrap; align-items: center; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge--demo { background: var(--amber-100); color: var(--ink-900); }
.badge--ai { background: var(--accent-soft); color: var(--accent-strong); }

.page { padding-top: 20px; padding-bottom: 48px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 22px; }
.search {
  flex: 1 1 200px; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 999px; color: var(--text-3);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; width: 0; min-width: 0; border: 0; background: none; outline: none; color: var(--text); font-size: 14px; }
.segmented { display: inline-flex; padding: 3px; background: var(--surface-2); border-radius: 999px; }
.segmented button {
  border: 0; background: none; height: 32px; padding: 0 12px; border-radius: 999px; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--text-2); font-variant-numeric: tabular-nums;
}
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.select {
  height: 36px; padding: 0 32px 0 14px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2387867f' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 16px;
  appearance: none; font-size: 14px; cursor: pointer;
}
.select--category { height: 40px; min-width: 190px; font-weight: 500; padding-left: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235f6f80' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"), radial-gradient(circle, var(--cat, var(--accent)) 0 4px, transparent 4.5px);
  background-position: right 10px center, 12px center; background-size: 16px, 16px; background-repeat: no-repeat; }
.select--category:focus-visible, .select:focus-visible { border-color: var(--accent); }
.filters.is-trending .feed-only { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

.dropdown { position: relative; }
.dropdown__panel {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 30; width: min(560px, calc(100vw - 32px));
  max-height: 60vh; overflow: auto; padding: 14px; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow);
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 4px 16px;
}
.dropdown__group { grid-column: 1 / -1; margin: 8px 0 2px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.dropdown__group:first-child { margin-top: 0; }
.dropdown__panel label { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; cursor: pointer; }
.dropdown__panel input { accent-color: var(--accent); }

/* ---- feed grid --------------------------------------------------------- */
.result-count { margin: 0 0 14px; color: var(--text-3); font-size: 13px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 20px; }
.card {
  display: flex; flex-direction: column; overflow: hidden; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  transition: border-color .15s;
}
.card:hover { border-color: var(--border-strong); }
.card__media { display: block; aspect-ratio: 16 / 9; background: var(--surface-2); overflow: hidden; position: relative; }
.card__media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.placeholder {
  position: absolute; inset: 0; display: flex; align-items: flex-end; padding: 14px 16px;
  font-family: var(--font-serif); font-size: 22px; line-height: 1.15; color: var(--on-media);
  background:
    radial-gradient(circle at 78% 30%, color-mix(in srgb, var(--c) 70%, white) 0 22%, transparent 23%),
    linear-gradient(160deg, color-mix(in srgb, var(--c) 22%, var(--paper)), color-mix(in srgb, var(--c) 45%, var(--mist-100)));
}
.card__body { display: flex; flex-direction: column; gap: 8px; padding: 16px 18px 18px; flex: 1; }
.card__meta { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-3); min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c, var(--accent)); flex: none; }
.dot { color: var(--border-strong); }
.card__title { margin: 0; font-family: var(--font-serif); font-weight: 500; font-size: 19px; line-height: 1.3; letter-spacing: -0.005em; }
.card__title a:hover { color: var(--accent-strong); }
.card__desc { margin: 0; color: var(--text-2); font-size: 14px; line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.card__url {
  margin-top: auto; padding-top: 6px; display: flex; align-items: center; gap: 6px; min-width: 0;
  font-size: 12.5px; color: var(--accent-strong);
}
.card__url span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card__url svg { width: 13px; height: 13px; }
.card__url:hover span { text-decoration: underline; }

.more { display: flex; justify-content: center; margin-top: 28px; }
.empty { grid-column: 1 / -1; padding: 64px 16px; text-align: center; color: var(--text-3); }
.empty h3 { margin: 0 0 6px; font-family: var(--font-serif); font-weight: 500; font-size: 22px; color: var(--text); }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius); min-height: 320px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- trending ---------------------------------------------------------- */
.trending-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.section-title { margin: 0; font-family: var(--font-serif); font-weight: 500; font-size: 30px; letter-spacing: -0.01em; }
.next-ai { flex-basis: 100%; }
.section-sub { margin: 4px 0 0; color: var(--text-3); font-size: 13px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.trending { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 20px; }
.story { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.story--lead { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
.story__media { position: relative; aspect-ratio: 16 / 9; background: var(--surface-2); overflow: hidden; }
.story--lead .story__media { aspect-ratio: auto; min-height: 320px; }
.story__media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.story__rank {
  position: absolute; top: 0; left: 0; min-width: 36px; padding: 6px 10px;
  background: var(--rank-bg); color: var(--rank-fg); border-bottom-right-radius: 8px;
  font-family: var(--font-serif); font-size: 17px; line-height: 1; text-align: center; font-variant-numeric: tabular-nums;
}
.story__body { display: flex; flex-direction: column; gap: 10px; padding: 18px 20px 20px; flex: 1; }
.story--lead .story__body { padding: 28px 30px; }
.story__title { margin: 0; font-family: var(--font-serif); font-weight: 500; font-size: 22px; line-height: 1.25; }
.story--lead .story__title { font-size: 32px; letter-spacing: -0.01em; }
.story__summary { margin: 0; color: var(--text-2); font-size: 14.5px; line-height: 1.6; max-width: 65ch;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.story--lead .story__summary { font-size: 16px; -webkit-line-clamp: 5; }
.story__why { margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--text-3); font-style: italic; max-width: 65ch; }
.story__sources { list-style: none; margin: 6px 0 0; padding: 4px 0 0; display: flex; flex-direction: column; border-top: 1px solid var(--border); }
.story__sources li { display: flex; flex-direction: column; gap: 2px; padding: 10px 0; min-width: 0; }
.story__sources li + li { border-top: 1px solid var(--border); }
.src-title { font-size: 14px; line-height: 1.4; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.src-title:hover { color: var(--accent-strong); text-decoration: underline; }
.src-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.src-name { font-weight: 500; color: var(--text-2); }
.src-more { margin: 0; font-size: 12.5px; color: var(--text-3); }
.src-first { font-size: 11px; letter-spacing: .02em; color: var(--text-3); border: 1px solid var(--border-strong); border-radius: 4px; padding: 0 4px; }

.footer p { margin: 0 0 6px; }
.footer { padding-top: 24px; padding-bottom: 40px; color: var(--text-3); font-size: 12.5px; border-top: 1px solid var(--border); }

@media (max-width: 760px) {
  .masthead__inner, .tabs, .page, .footer { padding-left: 16px; padding-right: 16px; }
  .brand__name { font-size: 24px; }
  #refresh span { display: none; }
  #refresh { width: 36px; padding: 0; justify-content: center; }
  .grid, .trending { grid-template-columns: 1fr; }
  .story--lead { display: flex; }
  .story--lead .story__media { min-height: 0; aspect-ratio: 16 / 9; }
  .story--lead .story__body { padding: 18px 20px 20px; }
  .story--lead .story__title { font-size: 24px; }
  .segmented { order: 3; }
  .category, .select--category, .region, .region .select { flex: 1 1 100%; width: 100%; }
  .filters { position: relative; }
  .dropdown { position: static; }
  .dropdown__panel { left: 0; right: 0; width: auto; }
  .badge--demo { padding: 0 8px; }
  .section-title { font-size: 26px; }
}
