:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f3f6;
  --text: #17202a;
  --muted: #5b6672;
  --border: #dde3ea;
  --accent: #1f6f8b;
  --accent-soft: #e3f1f6;
  --ok: #1d7a4a;
  --ok-soft: #e2f4ea;
  --warn: #9a5b00;
  --warn-soft: #fdf0dc;
  --danger: #b4232c;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .06);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .16);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1418;
    --surface: #172027;
    --surface-2: #1e2932;
    --text: #e6edf3;
    --muted: #9aa8b5;
    --border: #2b3843;
    --accent: #5cb8d6;
    --accent-soft: #17323d;
    --ok: #5fd39a;
    --ok-soft: #173326;
    --warn: #f0b45a;
    --warn-soft: #3a2a12;
    --danger: #ff7a82;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1418; --surface: #172027; --surface-2: #1e2932; --text: #e6edf3; --muted: #9aa8b5;
  --border: #2b3843; --accent: #5cb8d6; --accent-soft: #17323d; --ok: #5fd39a; --ok-soft: #173326;
  --warn: #f0b45a; --warn-soft: #3a2a12; --danger: #ff7a82; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
code { font-size: .9em; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px max(16px, calc((100vw - 1180px) / 2));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #3aa17e);
}
.topnav { display: flex; gap: 4px; flex-wrap: wrap; }
.topnav a {
  padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 500;
}
.topnav a:hover, .topnav a.active { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 48px; }
.loading, .empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* ---------- landing ---------- */
.hero h1 { font-size: clamp(24px, 4vw, 34px); margin: 8px 0 6px; letter-spacing: -.01em; }
.hero p { color: var(--muted); margin: 0 0 22px; max-width: 70ch; }
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 26px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 14px; min-width: 130px;
}
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 13px; }

.section-title { font-size: 18px; margin: 28px 0 12px; }
.subject-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.subject-tile {
  display: flex; flex-direction: column; gap: 10px;
  padding: 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: var(--text); text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.subject-tile:hover, .subject-tile:focus-visible {
  transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--accent); outline: none;
}
.subject-tile .tile-icon {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.subject-tile .tile-icon svg { width: 22px; height: 22px; }
.subject-tile h3 { margin: 0; font-size: 16px; }
.subject-tile .tile-meta { color: var(--muted); font-size: 13px; }
.subject-tile.disabled { opacity: .5; pointer-events: none; box-shadow: none; }

/* ---------- deadline list ---------- */
.deadline-list { display: grid; gap: 8px; }
.deadline-row {
  display: grid; grid-template-columns: 96px 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px;
}
.deadline-row .dl-date { font-weight: 700; }
.deadline-row .dl-date small { display: block; font-weight: 500; color: var(--muted); }
.deadline-row .dl-what { min-width: 0; }
.deadline-row .dl-what a { font-weight: 600; text-decoration: none; }
.deadline-row .dl-what div { color: var(--muted); font-size: 13px; }
@media (max-width: 560px) {
  .deadline-row { grid-template-columns: 80px 1fr; }
  .deadline-row .badge { grid-column: 2; justify-self: start; }
}

/* ---------- subject page ---------- */
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { text-decoration: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: clamp(22px, 3.5vw, 30px); }
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin: 16px 0 20px;
}
.search {
  flex: 1 1 240px; min-width: 0;
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none;
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 500;
}
.chip input { accent-color: var(--accent); margin: 0; }
.chip:has(input:checked) { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
select.chip { padding-right: 8px; }

.subject-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-top: 14px; scrollbar-width: thin; }
.subject-tabs a {
  flex: none; padding: 6px 12px; border-radius: 999px; font-size: 13px; text-decoration: none;
  border: 1px solid var(--border); color: var(--muted); background: var(--surface); white-space: nowrap;
}
.subject-tabs a.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- conference cards ---------- */
.card-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.card {
  position: relative; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); min-height: 200px;
  transition: box-shadow .15s ease, border-color .15s ease, transform .15s ease;
}
.card:hover, .card.open, .card:focus-within { border-color: var(--accent); box-shadow: var(--shadow-lg); }
.card:hover { transform: translateY(-2px); }
.card-body { padding: 16px 16px 12px; flex: 1; cursor: pointer; }
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card .acronym {
  font-size: 12px; font-weight: 700; letter-spacing: .04em; color: var(--accent);
  background: var(--accent-soft); padding: 3px 8px; border-radius: 6px;
}
.card h3 { font-size: 15.5px; line-height: 1.35; margin: 10px 0 8px; }
.meta { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.meta span { display: flex; gap: 6px; align-items: center; }
.meta svg { width: 14px; height: 14px; flex: none; }
.next-deadline { margin-top: 10px; font-size: 13px; }
.next-deadline b { color: var(--warn); }

.badge {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  font-size: 11.5px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.past { text-decoration: line-through; }

/* the icon tray that opens on hover */
/* Fixed-height tray so cards never change size; icons fade and rise in on hover. */
.tray {
  position: relative; display: flex; gap: 6px; align-items: center; height: 58px; padding: 0 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius);
}
.tray::before {
  content: "Hover for link, funder, deadline, eligibility…"; position: absolute; left: 14px;
  color: var(--muted); font-size: 12.5px; transition: opacity .15s ease;
}
.tray-item { position: relative; opacity: 0; transform: translateY(6px); transition: opacity .18s ease, transform .18s ease; }
.tray-item:nth-child(2) { transition-delay: .02s; } .tray-item:nth-child(3) { transition-delay: .04s; }
.tray-item:nth-child(4) { transition-delay: .06s; } .tray-item:nth-child(5) { transition-delay: .08s; }
.tray-item:nth-child(6) { transition-delay: .1s; }
.card:hover .tray::before, .card:focus-within .tray::before { opacity: 0; }
.card:hover .tray-item, .card:focus-within .tray-item { opacity: 1; transform: none; }
@media (hover: none) {
  .tray::before { opacity: 0; }
  .tray-item { opacity: 1; transform: none; }
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  text-decoration: none; font: inherit;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover, .icon-btn:focus-visible, .tray-item.show .icon-btn {
  background: var(--accent); color: #fff; border-color: var(--accent); outline: none;
}
.icon-btn.has-alert::after {
  content: ""; position: absolute; top: -3px; right: -3px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--warn); border: 2px solid var(--surface-2);
}
.pop {
  position: absolute; bottom: calc(100% + 10px); left: 50%; transform: translateX(-50%) translateY(4px);
  width: max-content; max-width: min(300px, 80vw); z-index: 30;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-lg); padding: 12px 14px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .12s ease, transform .12s ease;
}
.pop::after {
  content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 7px solid transparent; border-top-color: var(--surface);
}
.tray-item:first-child .pop { left: 0; transform: translateY(4px); }
.tray-item:first-child .pop::after { left: 19px; }
.tray-item:last-child .pop { left: auto; right: 0; transform: translateY(4px); }
.tray-item:last-child .pop::after { left: auto; right: 12px; transform: none; }
.tray-item:hover .pop, .tray-item:focus-within .pop, .tray-item.show .pop {
  opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0);
}
.tray-item:first-child:hover .pop, .tray-item:first-child:focus-within .pop, .tray-item:first-child.show .pop,
.tray-item:last-child:hover .pop, .tray-item:last-child:focus-within .pop, .tray-item:last-child.show .pop { transform: translateY(0); }
.pop h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.pop p { margin: 0 0 6px; }
.pop p:last-child { margin-bottom: 0; }
.pop a { word-break: break-all; }
.dl-table { display: grid; grid-template-columns: auto auto; gap: 4px 12px; }
.dl-table .lbl { color: var(--muted); }
.dl-table .val { font-weight: 600; white-space: nowrap; }
.dl-table .val.passed { color: var(--muted); text-decoration: line-through; font-weight: 500; }
.dl-table .val.soon { color: var(--warn); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10, 15, 20, .55); }
.modal-panel {
  position: relative; width: min(760px, 100%); max-height: 88vh; overflow: auto;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 24px;
}
.modal-close { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; }
.modal-panel h2 { margin: 6px 40px 4px 0; font-size: 20px; }
.modal-panel .sub { color: var(--muted); margin-bottom: 14px; }
.detail { display: grid; grid-template-columns: 190px 1fr; gap: 8px 16px; font-size: 14px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 600px) {
  .detail { grid-template-columns: 1fr; gap: 2px; }
  .detail dd { margin-bottom: 8px; }
}
.notice {
  margin-top: 14px; padding: 10px 12px; border-radius: 10px; font-size: 13px;
  background: var(--warn-soft); color: var(--warn);
}

/* ---------- funders table ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }

.footer {
  max-width: 1180px; margin: 0 auto; padding: 18px 16px 36px; color: var(--muted); font-size: 12.5px;
  border-top: 1px solid var(--border);
}
.footer p { margin: 4px 0; }

/* ---------- funding tracker additions ---------- */
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.open { background: var(--ok-soft); color: var(--ok); }
.badge.closed { text-decoration: line-through; }
.card .funder-tag {
  font-size: 12px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); padding: 3px 8px; border-radius: 6px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card .card-top { flex-wrap: wrap; }
.card .badges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.card .desc { color: var(--muted); font-size: 13px; margin: 8px 0 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta .amount { color: var(--text); font-weight: 600; }
.flag-dot { color: var(--warn); font-weight: 700; }
td .badge { margin-top: 2px; }

/* ---------- country-specific funding ---------- */
.cc-code {
  flex: none; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; letter-spacing: .04em;
  background: var(--accent); color: #fff;
}
.cc-code.lg { width: 52px; height: 52px; font-size: 16px; border-radius: 14px; }
.country-panel {
  margin: 4px 0 8px; padding: 18px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
}
.country-panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.country-panel-head h2 { margin: 0; font-size: 18px; }
.country-panel-head p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.country-panel-head a { font-weight: 600; text-decoration: none; font-size: 14px; }
.region-title { font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 8px; }
.country-panel-head + .region-title { margin-top: 0; }
.region-head { margin-top: 34px; }
.country-mini.none { opacity: .65; }
.country-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.country-mini {
  display: flex; gap: 12px; align-items: center; padding: 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.country-mini:hover, .country-mini:focus-visible { border-color: var(--accent); box-shadow: var(--shadow-lg); transform: translateY(-2px); outline: none; }
.country-mini-body { display: grid; gap: 2px; min-width: 0; }
.country-mini-body b { font-size: 16px; }
.country-mini-body span { color: var(--muted); font-size: 13px; }

.country-box {
  margin-top: 22px; padding: 20px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  scroll-margin-top: 80px;
}
.country-box-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.country-box-head > div { flex: 1 1 260px; min-width: 0; }
.country-box-head h2 { margin: 0; font-size: 21px; }
.country-box-head p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.box-title { font-size: 15px; margin: 22px 0 10px; }
.country-box .deadline-row { background: var(--surface-2); }
.country-box .dl-date { color: var(--muted); }
.empty.small { padding: 14px 0; text-align: left; }
.box-foot { margin: 18px 0 0; font-size: 14px; }
.box-foot a { font-weight: 600; text-decoration: none; }
