/* SAGE's website: a dark dashboard. Colour only where it means something:
   the threat level, how likely things are, and how tense. */

:root {
  --bg: #0b0d10;
  --panel: #12161b;
  --panel-2: #181d24;
  --line: #232a32;
  --line-strong: #34404c;
  --text: #e7eaee;
  --muted: #98a3ad;
  --faint: #6b7781;
  --chance-0: #98a3ad;
  --chance-1: #e5b84f;
  --chance-2: #f28b4b;
  --chance-3: #ff5b4f;
  --calm: #6b7781;
  --alert: #ff5b4f;
  --alert-bg: #2a1214;
  --pick-2: #8ea4bb;
  --map-none: #1b2129;
  --map-0: #2a3440;
  --map-1: #4d4434;
  --map-2: #8a5426;
  --map-3: #c4651d;
  --map-4: #ea4b2b;
  --map-5: #ff2b3b;
  --threat-0: #3b9c46;
  --threat-1: #2f6cc9;
  --threat-2: #f2c12e;
  --threat-3: #f07d22;
  --threat-4: #d22b2b;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", "Segoe UI Mono", Menlo, Consolas, "Roboto Mono", "DejaVu Sans Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--text); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.threat-level, th[title] { cursor: help; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.faint { color: var(--faint); }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
.topbar .wrap { position: relative; display: flex; align-items: center; gap: 14px; height: 54px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; flex: none; }
.brand img { width: 30px; height: 30px; }
.brand span { font: 700 16px/1 var(--mono); letter-spacing: 0.24em; }
.stamp { font: 11px/1.3 var(--mono); color: var(--faint); letter-spacing: 0.05em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
nav { display: flex; gap: 4px; flex: none; }
nav a {
  font: 600 12px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); text-decoration: none; padding: 9px 10px; border: 1px solid transparent; border-radius: 4px;
  white-space: nowrap;
}
nav a:hover { color: var(--text); }
nav a[aria-current="page"] { color: var(--text); border-color: var(--line-strong); background: var(--panel); }

/* Search */
.find { position: relative; margin-left: auto; width: 280px; flex: none; }
.find .icon { position: absolute; left: 10px; top: 50%; width: 14px; height: 14px; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.find input {
  width: 100%; font: 14px/1.2 var(--sans); color: var(--text); background: var(--panel);
  border: 1px solid var(--line-strong); border-radius: 4px; padding: 8px 30px 8px 32px;
}
.find input::placeholder { color: var(--faint); }
.find input:focus { outline: none; border-color: var(--muted); }
.find kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font: 11px/1 var(--mono); color: var(--faint);
  border: 1px solid var(--line-strong); border-radius: 3px; padding: 2px 5px; pointer-events: none;
}
.find input:focus ~ kbd, .find input:not(:placeholder-shown) ~ kbd { display: none; }
#q-list {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; min-width: 320px; z-index: 10;
  margin: 0; padding: 4px 0; list-style: none; max-height: 60vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 6px; box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55);
}
#q-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto 44px; gap: 10px; align-items: center; padding: 9px 12px; cursor: pointer; }
#q-list li.active, #q-list li:hover { background: var(--panel-2); }
#q-list li.none { display: block; color: var(--muted); cursor: default; }
#q-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#q-list .pct { text-align: right; font: 600 13px/1 var(--mono); }
.find-toggle {
  display: none; align-items: center; justify-content: center; width: 38px; height: 34px; flex: none;
  background: none; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--muted); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.find-toggle svg { width: 16px; height: 16px; }
body.finding .find-toggle { color: var(--text); border-color: var(--muted); }

main { padding: 14px 0 8px; min-height: 70vh; }

/* Panels */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  min-width: 0; display: flex; flex-direction: column; overflow: hidden;
}
.panel > header {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; padding: 10px 14px; border-bottom: 1px solid var(--line);
  font: 600 11.5px/1.3 var(--mono); letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted);
}
.panel > header h2 { font: inherit; margin: 0; color: var(--text); }
.panel > header .right { margin-left: auto; }
.body { padding: 14px; }
.body p { margin: 0 0 10px; }
.body p:last-child { margin-bottom: 0; }
.note { color: var(--muted); font-size: 13.5px; }
.note a { color: var(--text); }
.empty { color: var(--muted); padding: 14px; margin: 0; }

/* Tags, flags and bars */
.tag {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font: 600 11px/1.2 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.tag i { width: 8px; height: 8px; border-radius: 1px; flex: none; }
.flag {
  display: inline-block; font: 700 10.5px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--bg); background: var(--alert); padding: 4px 5px 3px; border-radius: 3px; white-space: nowrap;
}
.mbar { display: block; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.mbar i { display: block; height: 100%; }

/* Rows in lists */
.rows { list-style: none; margin: 0; padding: 0; }
.rows > li > a, .rows > li > .row, .rows > .rows-head {
  display: grid; align-items: center; gap: 10px; padding: 9px 14px;
  border-top: 1px solid var(--line); color: inherit; text-decoration: none;
  grid-template-columns: minmax(0, 1fr) auto 56px;
}
.rows > li:first-child > a, .rows > li:first-child > .row, .rows > .rows-head { border-top: 0; }
.rows > .rows-head + li > a { border-top: 0; }
.rows > .rows-head {
  padding-top: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line);
  font: 600 10.5px/1.2 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint);
}
.rows > .rows-head span:last-child { text-align: right; }
.rows > li > a:hover { background: var(--panel-2); }
.rows .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .name .flag { margin-left: 8px; vertical-align: 1px; }
.rows .pct { text-align: right; font: 600 13.5px/1 var(--mono); }
.rows.ranked > li > a { grid-template-columns: 22px minmax(0, 1fr) 70px 48px; }
.rows .rank { font: 12px/1 var(--mono); color: var(--faint); }
.scroll { max-height: 420px; overflow-y: auto; }

/* Every country */
.table-scroll { max-height: 560px; overflow-y: auto; }
table.list { width: 100%; border-collapse: collapse; }
.list thead th { position: sticky; top: 0; z-index: 1; background: var(--panel); border-bottom: 1px solid var(--line-strong); padding: 0; text-align: left; }
.list thead th.num { text-align: right; }
.list thead button {
  width: 100%; background: none; border: 0; padding: 9px 14px; cursor: pointer; text-align: inherit;
  font: 600 10.5px/1.2 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.list thead button:hover { color: var(--text); }
.list th[aria-sort="ascending"] button, .list th[aria-sort="descending"] button { color: var(--text); }
.list th[aria-sort="ascending"] button::after { content: " ↑"; }
.list th[aria-sort="descending"] button::after { content: " ↓"; }
.list td { padding: 9px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
.list tbody tr:first-child td { border-top: 0; }
.list tbody tr { cursor: pointer; }
.list tbody tr:hover { background: var(--panel-2); }
.list td a { text-decoration: none; font-weight: 600; }
.list td a:hover { text-decoration: underline; }
.list td .flag { margin-left: 8px; vertical-align: 1px; }
.list td .sub { display: none; margin-top: 4px; }
.list .status-col { width: 240px; }
.list td.num { text-align: right; font: 600 13.5px/1 var(--mono); width: 120px; }
.list td.num .mbar { margin-top: 6px; width: 80px; margin-left: auto; }

/* Global threat level */
.threat-row { display: grid; grid-template-columns: minmax(210px, 0.8fr) minmax(0, 2fr); flex: 1; }
.threat-level { padding: 16px; display: flex; flex-direction: column; justify-content: center; }
.level {
  display: block; text-align: center; font: 800 28px/1 var(--mono); letter-spacing: 0.16em;
  padding: 14px 10px; border-radius: 4px;
}
.meter { display: flex; gap: 3px; margin-top: 10px; }
.meter span { flex: 1; height: 6px; border-radius: 1px; opacity: 0.22; }
.meter span.now { opacity: 1; }
.meter-ends { display: flex; justify-content: space-between; margin-top: 6px; font: 10.5px/1 var(--mono); letter-spacing: 0.08em; color: var(--faint); text-transform: uppercase; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
.stat { padding: 14px 16px; border-left: 1px solid var(--line); display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.stat b { font: 700 30px/1 var(--mono); font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; line-height: 1.35; color: var(--muted); }
.stat.hot b { color: var(--alert); }

/* Map */
.map-wrap { position: relative; padding: 6px 8px 0; flex: 1 1 auto; }
.map-wrap svg { display: block; width: 100%; height: auto; }
.map-wrap path, .map-wrap circle { stroke: var(--bg); stroke-width: 0.6; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.map-wrap .live { cursor: pointer; }
.map-wrap .live:hover { stroke: var(--text); stroke-width: 1.5; }
.map-wrap .picked { stroke: var(--text); stroke-width: 1.5; }
.tip {
  position: absolute; pointer-events: none; z-index: 2; background: var(--bg); border: 1px solid var(--line-strong);
  border-radius: 4px; padding: 6px 9px; font: 12px/1.35 var(--mono); white-space: nowrap; transform: translate(-50%, calc(-100% - 12px));
}
.tip.below { transform: translate(-50%, 14px); }
.tip b { display: block; font-family: var(--sans); font-size: 13.5px; }
.tip span { display: block; color: var(--muted); }
.tip a { display: inline-block; margin-top: 6px; font-weight: 700; text-decoration: none; }
.tip.pinned { pointer-events: auto; padding: 8px 11px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 10px 14px 12px; }
.legend .tag { color: var(--muted); cursor: default; }
.toggle { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 4px; overflow: hidden; }
.toggle button {
  font: 600 11px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  background: none; border: 0; padding: 6px 9px; cursor: pointer;
}
.toggle button + button { border-left: 1px solid var(--line-strong); }
.toggle button[aria-pressed="true"] { background: var(--text); color: var(--bg); }

/* Where you are, alerts */
.place-name { font-size: 20px; font-weight: 700; margin: 0 0 6px; }
.place-name a { text-decoration: none; }
.place-name a:hover { text-decoration: underline; }
.meters { display: grid; gap: 10px; margin: 12px 0; }
.meters .top { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; margin-bottom: 5px; }
.meters .top .num { font-weight: 600; }
.alert-item { padding: 12px 14px; border-top: 1px solid var(--line); }
.alert-item:first-child { border-top: 0; }
.alert-item .place-name { font-size: 16px; display: flex; align-items: center; gap: 8px; }
.alert-item p { margin: 0; color: var(--muted); font-size: 13.5px; }
.alert-box { background: var(--alert-bg); border: 1px solid color-mix(in srgb, var(--alert) 45%, transparent); border-radius: 4px; padding: 12px; margin-top: 12px; }
.alert-box b { display: block; color: var(--alert); font: 700 11.5px/1.3 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 4px; }

/* Summary lines */
.lines { list-style: none; margin: 0; padding: 0; }
.lines li { padding: 10px 14px 10px 32px; border-top: 1px solid var(--line); position: relative; }
.lines li:first-child { border-top: 0; }
.lines li::before { content: "›"; position: absolute; left: 14px; color: var(--faint); font-family: var(--mono); }

/* App strip */
.app-strip { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 20px; padding: 14px; }
.app-strip p { margin: 0; color: var(--muted); flex: 1 1 320px; }
.app-strip p b { color: var(--text); }
.button {
  display: inline-flex; align-items: center; justify-content: center; padding: 10px 14px; border-radius: 4px;
  font: 700 12px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; text-decoration: none;
  background: var(--text); color: var(--bg); white-space: nowrap;
}
.button.ghost { background: none; color: var(--text); border: 1px solid var(--line-strong); }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; }

/* Country and pair pages */
.back {
  display: inline-block; margin: 2px 0 12px; font: 600 11.5px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); text-decoration: none;
}
.back:hover { color: var(--text); }
.head-row { display: grid; grid-template-columns: minmax(0, 1.6fr) repeat(3, minmax(0, 1fr)); }
.head-row.solo { grid-template-columns: minmax(0, 1fr); }
.head-row .who { padding: 16px; }
.kicker { font: 600 11.5px/1.3 var(--mono); letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
h1 { font-size: 32px; line-height: 1.12; margin: 0 0 10px; letter-spacing: -0.01em; }
.tags { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 0; }
.tags .when { margin-left: -8px; font: 11px/1.2 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); }
.tags a { font: 600 11.5px/1.2 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.tags a:hover { color: var(--text); }
.head-row .stat { border-left: 1px solid var(--line); }

table.chances { width: 100%; border-collapse: collapse; font-size: 14px; }
.chances th, .chances td { padding: 10px 14px; border-top: 1px solid var(--line); text-align: right; vertical-align: top; }
.chances thead th, .chances thead td {
  border-top: 0; font: 600 11px/1.2 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.chances th[scope="row"] { text-align: left; font-weight: 600; }
.chances th[scope="row"] span { display: block; font-weight: 400; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.chances td { font: 600 14px/1 var(--mono); font-variant-numeric: tabular-nums; }
.chances td .mbar { margin-top: 7px; width: 100%; min-width: 36px; margin-left: auto; }
.chances .next { background: var(--panel-2); }
.chances thead .next { color: var(--text); }
.chances td.usual { color: var(--muted); font-weight: 400; }
.phone-only { display: none; }

.why-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.why-cols > div { padding: 14px; border-left: 1px solid var(--line); }
.why-cols > div:first-child { border-left: 0; }
.why-cols h3 { font: 600 11.5px/1.3 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
ul.bullets { margin: 0; padding-left: 18px; }
ul.bullets li + li { margin-top: 6px; }
ul.bullets li::marker { color: var(--faint); }

/* Page layouts */
.home { grid-template-areas: "threat threat here" "map map risks" "alerts tension brief" "all all all" "app app app"; }
.country { grid-template-areas: "head head head" "chances chances situation" "map map relations" "why why why"; }
.country.bare { grid-template-areas: "head head head" "situation situation situation" "map map relations"; }
.pair { grid-template-areas: "head head head" "map map situation"; }
.about { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.about .wide { grid-column: 1 / -1; }
.a-threat { grid-area: threat; } .a-map { grid-area: map; } .a-risks { grid-area: risks; } .a-here { grid-area: here; }
.a-alerts { grid-area: alerts; } .a-tension { grid-area: tension; } .a-brief { grid-area: brief; } .a-all { grid-area: all; }
.a-app { grid-area: app; } .a-head { grid-area: head; } .a-chances { grid-area: chances; } .a-situation { grid-area: situation; }
.a-relations { grid-area: relations; } .a-why { grid-area: why; }

footer { border-top: 1px solid var(--line); margin-top: 28px; padding: 18px 0 40px; color: var(--faint); font-size: 13px; }
footer p { margin: 0 0 6px; }
footer a { color: var(--muted); }
.loading { color: var(--muted); padding: 60px 0; text-align: center; font-family: var(--mono); font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; }

@media (max-width: 1180px) {
  .stamp { display: none; }
}

@media (max-width: 1000px) {
  .home { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-areas: "threat threat" "here alerts" "map map" "risks tension" "brief brief" "all all" "app app"; }
  .country, .country.bare, .pair { grid-template-columns: minmax(0, 1fr); grid-template-areas: none; }
  .country > *, .pair > * { grid-area: auto; }
  .threat-row { grid-template-columns: minmax(0, 1fr); }
  .threat-level { border-bottom: 1px solid var(--line); }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stats .stat:first-child { border-left: 0; }
  .stats .stat:nth-child(n+3) { border-top: 0; }
}

@media (max-width: 680px) {
  .find { display: none; position: absolute; left: 0; right: 0; top: 100%; width: auto; margin: 0; padding: 8px 16px 10px; background: var(--bg); border-bottom: 1px solid var(--line); }
  body.finding .find { display: block; }
  .find .icon { left: 26px; top: 21px; transform: none; }
  .find input { font-size: 16px; }
  .find kbd { display: none; }
  #q-list { left: 16px; right: 16px; min-width: 0; }
  .find-toggle { display: inline-flex; }
  nav { margin-left: auto; }
  nav a.wide { display: none; }
  .home { grid-template-columns: minmax(0, 1fr); grid-template-areas: "threat" "here" "map" "risks" "alerts" "tension" "brief" "all" "app"; }
  .about { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats .stat:nth-child(odd) { border-left: 0; }
  .stats .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
  .head-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .head-row .who { grid-column: 1 / -1; border-bottom: 1px solid var(--line); }
  .head-row .stat:nth-child(2) { border-left: 0; }
  .head-row .stat:nth-child(4) { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  .stat { padding: 12px 14px; }
  .stat b { font-size: 26px; }
  .level { font-size: 24px; }
  h1 { font-size: 27px; }
  .table-scroll { max-height: 70vh; }
  .list td, .list thead button { padding-left: 12px; padding-right: 12px; }
  .list td.num { width: 76px; }
  .list .status-col { display: none; }
  .list td .sub { display: block; }
  .list td.num .mbar { width: 52px; }
  .why-cols > div { border-left: 0; border-top: 1px solid var(--line); }
  .why-cols > div:first-child { border-top: 0; }
  .chances th, .chances td { padding: 9px 8px; }
  .chances th[scope="row"] { padding-left: 14px; }
  .chances td:last-child, .chances thead th:last-child { padding-right: 14px; }
  .phone-only { display: block; }
  .chances th[scope="row"] span { display: none; }
}

@media (max-width: 400px) {
  .brand span { display: none; }
  nav a { padding: 8px 7px; }
}
