/* Base sheet: design tokens, themes, reset, shared components, Live screen.
   Every colour, size and space used anywhere comes from a token below. Templates hold none.
   Themes: follows the OS (prefers-color-scheme); <html data-theme="light|dark"> overrides it.
   Palette "plotting room": chart paper, navy ink, plotting blue for actions. Each signal colour
   has one meaning: red is war, amber is flash, olive is a primary (first-hand) source, green is working. */

:root {
  /* type: Inter for everything; mono only for raw strings (URLs, locators, codes) */
  --font-sans: "Inter", "Noto Sans Devanagari", "Segoe UI", "Nirmala UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", Consolas, "Noto Sans Devanagari", monospace;
  --text-xs: 11px; --text-sm: 12px; --text-base: 14px; --text-md: 15px; --text-title: 16px; --text-lg: 18px; --text-xl: 22px;
  --leading-tight: 1.3; --leading: 1.5;
  /* space: one scale, 4 8 12 16 24 32 */
  --space-1: 2px; --space-2: 4px; --space-3: 8px; --space-4: 12px; --space-5: 16px; --space-6: 24px;
  /* shape */
  --radius: 6px; --radius-lg: 10px; --radius-pill: 999px; --border: 1px; --border-strong: 2px; --ring: 3px;
  --shadow: 0 1px 2px rgb(20 33 43 / .10), 0 6px 16px rgb(20 33 43 / .08);
  --measure: 72ch;
  --target: 36px;
  --fast: 150ms; --ease: cubic-bezier(.2, .7, .3, 1); --z-nav: 20; --z-toast: 30;   /* every transition; none at all under reduced motion */

  /* light theme */
  color-scheme: light;
  --bg: #f0f3f3; --surface: #ffffff; --surface-2: #f5f8f7; --sunken: #e6eceb;
  --ink: #172b30; --ink-2: #3c5258; --muted: #596d73;
  --line: #d9e2e1; --line-strong: #829793;
  --accent: #087568; --accent-ink: #ffffff; --focus: #087568; --tint-accent: #e2f3ee;
  --war: #a31f1f; --war-ink: #ffffff;
  --flash: #7a4900;
  --olive: #4d5d2c;
  --ok: #1b6a39; --warn: #7a5600; --off: #59646e;
  --tint-war: #f8e6e5; --tint-flash: #f6ecda; --tint-ok: #e4f2e8; --tint-warn: #f6edd6; --tint-olive: #e6ebdb;
  /* story colours, one job each: olive first-hand/official, blue mainstream and urgency, teal specialist,
     violet OSINT and "not yet first-hand or confirmed", umber adversary, slate coverage, green confirmed */
  --olive-ink: #ffffff; --slate: #3f5566; --tint-slate: #e3eaef; --slate-line: #6f8494;
  --violet: #a8306a; --tint-violet: #f7e6ee; --violet-muted: #8a4a68;
  --teal: #0b6b62; --blue: #2457a3; --tint-blue: #e2eaf6; --umber: #6b5444;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c1318; --surface: #121d24; --surface-2: #17252d; --sunken: #0a1015;
    --ink: #e5eeef; --ink-2: #b8c9ce; --muted: #97adb5;
    --line: #263740; --line-strong: #576f79;
    --accent: #70dac3; --accent-ink: #09231e; --focus: #70dac3; --tint-accent: #17362f;
    --war: #f0807b; --war-ink: #1b0808;
    --flash: #e9b45a;
    --olive: #a8b878;
    --ok: #7ccf92; --warn: #e9b45a; --off: #8a96a0;
    --tint-war: #2b1716; --tint-flash: #2a2110; --tint-ok: #14261b; --tint-warn: #2a2210; --tint-olive: #1d2416;
  --olive-ink: #141a0b; --slate: #a9bdcc; --tint-slate: #1c2a33; --slate-line: #6c8394;
  --violet: #e9a1be; --tint-violet: #2f1a25; --violet-muted: #d4a3b9;
  --teal: #5fc4b6; --blue: #8ab4f0; --tint-blue: #18263a; --umber: #c4ab97;
    --shadow: 0 1px 2px rgb(0 0 0 / .5), 0 6px 16px rgb(0 0 0 / .35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1318; --surface: #121d24; --surface-2: #17252d; --sunken: #0a1015;
  --ink: #e5eeef; --ink-2: #b8c9ce; --muted: #97adb5;
  --line: #263740; --line-strong: #576f79;
  --accent: #70dac3; --accent-ink: #09231e; --focus: #70dac3; --tint-accent: #17362f;
  --war: #f0807b; --war-ink: #1b0808;
  --flash: #e9b45a;
  --olive: #a8b878;
  --ok: #7ccf92; --warn: #e9b45a; --off: #8a96a0;
  --tint-war: #2b1716; --tint-flash: #2a2110; --tint-ok: #14261b; --tint-warn: #2a2210; --tint-olive: #1d2416;
  --olive-ink: #141a0b; --slate: #a9bdcc; --tint-slate: #1c2a33; --slate-line: #6c8394;
  --violet: #e9a1be; --tint-violet: #2f1a25; --violet-muted: #d4a3b9;
  --teal: #5fc4b6; --blue: #8ab4f0; --tint-blue: #18263a; --umber: #c4ab97;
  --shadow: 0 1px 2px rgb(0 0 0 / .5), 0 6px 16px rgb(0 0 0 / .35);
}

/* ---------- reset and page ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 var(--text-base)/var(--leading) var(--font-sans);
  font-feature-settings: "cv11" 1; }
h1, h2, h3 { line-height: var(--leading-tight); }
h1 { font-size: var(--text-md); font-weight: 600; margin: 0; }
h2 { font-size: var(--text-lg); font-weight: 600; margin: var(--space-5) 0 var(--space-2); color: var(--ink); letter-spacing: -.005em; }
h3 { font-size: var(--text-md); font-weight: 600; margin: 0; }
p { margin: var(--space-2) 0; }
a { color: var(--accent); text-underline-offset: 3px; transition: color var(--fast), text-decoration-color var(--fast); }
/* thin scrollbars in the page colours */
html, .rail { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
code, kbd { font-family: var(--font-mono); font-size: var(--text-sm); }
time, .num, .count { font-variant-numeric: tabular-nums; }
code { background: var(--sunken); padding: 0 var(--space-1); border-radius: var(--radius); }
::selection { background: var(--accent); color: var(--accent-ink); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
/* Hindi and Marathi: no tracking, a little more size and room for matras */
:lang(hi), :lang(mr) { font-size: 1.06em; line-height: 1.75; letter-spacing: 0; text-transform: none; }

/* one focus ring for everything that can take focus */
:focus { outline: none; }
:focus-visible { outline: var(--ring) solid var(--focus); outline-offset: 2px; border-radius: var(--radius); }
.skip { position: absolute; left: -999px; top: var(--space-2); }
.skip:focus { left: var(--space-2); z-index: 20; background: var(--surface); color: var(--ink); padding: var(--space-2) var(--space-3); border: var(--border-strong) solid var(--ink); }

/* ---------- app bar and navigation ---------- */
.bar { display: flex; flex-wrap: wrap; gap: 0 var(--space-5); align-items: stretch; padding: 0 var(--space-5);
  background: var(--surface); border-bottom: var(--border) solid var(--line); min-height: 52px; }
.brand { display: inline-flex; align-items: center; gap: var(--space-2); font-weight: 600; font-size: var(--text-md); color: var(--ink); }
.brand h1 { font-size: inherit; }
.brand svg { color: var(--accent); flex: none; }
h1 .sub { color: var(--muted); font-weight: 400; margin-left: var(--space-1); }
h1 .sub::before { content: "/"; margin-right: var(--space-2); color: var(--line-strong); }
.controls { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin-left: auto; padding: var(--space-2) 0; }
.nav { display: flex; gap: var(--space-1); flex-wrap: wrap; align-items: stretch; }
/* current page: ink text, weight and a bar underneath, so it never rests on colour alone */
.nav a { display: inline-flex; align-items: center; padding: 0 var(--space-3); color: var(--ink-2); text-decoration: none;
  border-bottom: 3px solid transparent; border-top: 3px solid transparent; min-height: var(--target); }
.nav a:hover { color: var(--ink); border-bottom-color: var(--line-strong); }
.nav a[aria-current="page"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.tabs a { padding: var(--space-1) var(--space-3); color: var(--ink-2); text-decoration: none; border-radius: var(--radius);
  border: var(--border) solid transparent; }
.tabs a:hover { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
.tabs a[aria-current="page"] { background: var(--ink); color: var(--surface); font-weight: 600; }

main { padding: var(--space-4) var(--space-5) var(--space-6); max-width: 1100px; margin: 0 auto; }
main.wide { max-width: 1480px; }
.page-head { margin: var(--space-4) 0 var(--space-4); }
.page-title { font-size: var(--text-xl); font-weight: 600; letter-spacing: -.015em; margin: 0; }
.lede { color: var(--ink-2); font-size: var(--text-md); max-width: var(--measure); margin: var(--space-1) 0 0; }

/* ---------- buttons ---------- */
.btn { transition: background-color var(--fast), border-color var(--fast); display: inline-flex; gap: var(--space-2); align-items: center; padding: var(--space-1) var(--space-3); min-height: var(--target);
  border: var(--border) solid var(--line-strong); background: var(--surface); color: var(--ink); border-radius: var(--radius);
  font: 600 var(--text-base)/1 var(--font-sans); cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); border-color: var(--ink-2); }
.btn:active { background: var(--sunken); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn.small { min-height: 26px; padding: var(--space-1) var(--space-2); font-size: var(--text-sm); }
.btn svg { flex: none; }

/* ---------- connection state: green and sweeping when live, dark dashed with "!" when down ---------- */
.conn { display: inline-flex; gap: var(--space-2); align-items: center; padding: var(--space-1) var(--space-3); min-height: var(--target);
  border: var(--border) solid var(--line-strong); border-radius: var(--radius); font-size: var(--text-sm); font-weight: 600; color: var(--ink-2); }
.conn-up { color: var(--ok); border-color: var(--ok); }
.conn-down { color: var(--ink); border: var(--border-strong) dashed var(--ink); background: var(--sunken); }
.conn-down::before { content: "!"; font-weight: 700; }
.radar { flex: none; }
.radar .sweep { transform-box: view-box; transform-origin: 12px 12px; opacity: 0; }
.conn-up .radar .sweep { opacity: 1; animation: sweep 2.4s linear 2; }   /* two turns (under 5 s, WCAG 2.2.2) each time the link comes up, then still */
@keyframes sweep { to { transform: rotate(360deg); } }

/* ---------- badges: one size, radius, padding and weight ----------
   Meaning is carried by the word and the shape first, colour second.
   WAR: filled red, solid triangle. FLASH: amber outline, hollow ring. STUB: dashed outline. Red and amber mean nothing else. */
.badge, .tag, .flag, .tierbadge { display: inline-flex; align-items: center; gap: var(--space-1); height: 20px; padding: 0 var(--space-2);
  border: var(--border) solid transparent; border-radius: var(--radius); font: 600 var(--text-xs)/1 var(--font-sans);
  letter-spacing: .04em; white-space: nowrap; }
.badge-war { background: var(--war); color: var(--war-ink); border-color: var(--war); }
.badge-war::before { content: ""; width: 9px; height: 8px; background: currentcolor; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.badge-flash { background: var(--tint-flash); color: var(--flash); border-color: var(--flash); }
.badge-flash::before { content: ""; width: 8px; height: 8px; border: 2px solid currentcolor; border-radius: 50%; }
.badge-stub { background: transparent; color: var(--muted); border: var(--border) dashed var(--muted); }
.badge-noprimary { background: transparent; color: var(--violet); border-color: var(--violet); }   /* violet outline: no first-hand post yet */

/* ---------- notes, empty and error states ---------- */
.note { padding: var(--space-2) var(--space-3); border: var(--border) solid var(--line); border-radius: var(--radius); background: var(--surface); }
.note.ok { border-left: 6px solid var(--ok); background: var(--tint-ok); }
/* refusals and warnings: strong and neutral, because red and amber are kept for alert levels */
.note.bad { border-left: 6px dashed var(--ink); background: var(--sunken); }
.note.warn { border-left: 6px dotted var(--ink-2); background: var(--tint-slate); }
.empty-state { display: grid; justify-items: start; gap: var(--space-1); padding: var(--space-5); border: var(--border) dashed var(--line-strong);
  border-radius: var(--radius-lg); color: var(--ink-2); background: var(--surface); }
.empty-state strong { color: var(--ink); font-size: var(--text-md); font-weight: 600; }
.empty-state svg { color: var(--muted); }
.count { font-size: var(--text-sm); color: var(--muted); }
.tag { border-color: var(--muted); color: var(--muted); }

/* ---------- Live screen ---------- */
/* readiness: three checks, each ticked by the state the script already keeps (no extra script) */
.ready { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: var(--space-3); margin: 0 0 var(--space-4); }
.check { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--space-3); padding: var(--space-4); background: var(--surface);
  border: var(--border) solid var(--line); border-radius: var(--radius-lg); box-shadow: 0 1px 2px rgb(20 33 43 / .06); }
.check h3 { font-size: var(--text-base); margin: 0 0 var(--space-2); }
.check p { margin: var(--space-2) 0 0; font-size: var(--text-sm); color: var(--ink-2); max-width: 46ch; }
.check .btn { max-width: 100%; }
/* mark: dashed ring = not yet, green tick = done, dark "!" = broken */
.mark { width: 22px; height: 22px; border-radius: 50%; border: var(--border-strong) dashed var(--line-strong); display: grid; place-items: center;
  margin-top: 1px; color: var(--surface); font: 700 var(--text-sm)/1 var(--font-sans); }
.check-conn:has(.conn-up) .mark, .check-sound:has(#sound[data-state="on"]) .mark, .check-notify:has(#notify[data-state="on"]) .mark {
  border: 0; background: var(--ok); }
.check-conn:has(.conn-up) .mark::after, .check-sound:has(#sound[data-state="on"]) .mark::after, .check-notify:has(#notify[data-state="on"]) .mark::after {
  content: ""; width: 5px; height: 10px; border: solid currentcolor; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.check-conn:has(.conn-down) .mark, .check-sound:has(#sound[data-state="wait"]) .mark, .check-notify:has(#notify[data-state="blocked"]) .mark {
  border: 0; background: var(--ink); }
.check-conn:has(.conn-down) .mark::after, .check-sound:has(#sound[data-state="wait"]) .mark::after, .check-notify:has(#notify[data-state="blocked"]) .mark::after { content: "!"; }
.offline { display: none; }
body:has(.conn-down) .offline { display: block; }

.live-grid { display: grid; grid-template-columns: minmax(0, 1fr) 22rem; gap: var(--space-6); align-items: start; }
.live-grid > section, .newest-part { grid-column: 1; }
.live-side { grid-column: 2; grid-row: 1 / span 2; }
.newest-part { margin-top: var(--space-5); }
.newest-part h2 { display: flex; align-items: baseline; gap: var(--space-3); margin: 0 0 var(--space-2); }
.newest-part h2 .count { font-weight: 400; }
.newest-part .newest { background: var(--surface); border: var(--border) solid var(--line); border-radius: var(--radius-lg); padding: 0 var(--space-4); }
.newest-part .n-title { font-size: var(--text-base); }
.newest-part .newest .byline { font-size: var(--text-sm); }
.live-grid #history h2 { margin-top: 0; display: flex; align-items: baseline; gap: var(--space-3); }
.live-side { display: grid; gap: var(--space-3); }
.side-card { background: var(--surface); border: var(--border) solid var(--line); border-radius: var(--radius-lg); padding: var(--space-3) var(--space-4); }
.side-card h2 { font-size: var(--text-md); margin: 0 0 var(--space-2); }
.side-card .legend { grid-template-columns: 5.5rem minmax(0, 1fr); gap: var(--space-2) var(--space-3); font-size: var(--text-sm); margin: 0; }
.side-card.key[open] { padding: var(--space-2) var(--space-4) var(--space-3); }
.newest { list-style: none; margin: 0; padding: 0; display: grid; }
.newest li { display: grid; gap: var(--space-1); padding: var(--space-2) 0 var(--space-2) var(--space-3); border-top: var(--border) solid var(--line);
  box-shadow: inset 3px 0 0 var(--line-strong); }
.newest li:first-child { border-top: 0; }
.newest li[data-tier="primary"], .newest li[data-tier="official"] { box-shadow: inset 3px 0 0 var(--olive); }
.newest li[data-tier="mainstream"] { box-shadow: inset 3px 0 0 var(--blue); }
.newest li[data-tier="specialist"] { box-shadow: inset 3px 0 0 var(--teal); }
.newest li[data-tier="osint"] { box-shadow: inset 3px 0 0 var(--violet); }
.newest li[data-tier="adversary"] { box-shadow: inset 3px 0 0 var(--umber); }
.n-title { font-weight: 600; font-size: var(--text-sm); line-height: 1.35; }
.newest .byline { font-size: var(--text-xs); }
.side-more { margin: var(--space-2) 0 0; font-size: var(--text-sm); font-weight: 600; }
.side-more a { display: inline-flex; align-items: center; min-height: 24px; }

/* alert cards, in the list and as toasts: badge, headline, source and age, flags, actions */
.toasts { position: fixed; top: 64px; right: var(--space-4); width: min(420px, calc(100vw - 2 * var(--space-4))); display: flex;
  flex-direction: column; gap: var(--space-2); z-index: 5; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3); }
.alert { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--space-1) var(--space-3); align-items: center;
  background: var(--surface); border: var(--border) solid var(--line); border-radius: var(--radius-lg); padding: var(--space-3) var(--space-4);
  box-shadow: 0 1px 2px rgb(20 33 43 / .06); }
.alert > .badge { grid-column: 1; grid-row: 1; }
.alert .headline { grid-column: 2 / 4; grid-row: 1; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.alert .entity { grid-column: 2; grid-row: 2; font-size: var(--text-sm); font-weight: 600; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert .age { grid-column: 3; grid-row: 2; font-size: var(--text-sm); color: var(--muted); white-space: nowrap; }
.alert .muted-flag { grid-column: 2; grid-row: 3; justify-self: start; }
.alert .acked-flag { grid-column: 3; grid-row: 3; justify-self: end; }
.alert .actions { grid-column: 2 / 4; grid-row: 4; display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-1); }
/* level on the card: the same rings as the Matrix, solid red for war, dashed amber for flash */
.alert.war.unacked { outline: var(--border-strong) solid var(--war); outline-offset: 2px; }
.alert.flash { outline: var(--border-strong) dashed var(--flash); outline-offset: 2px; }
.alert.war:not(.unacked) { border-left: 4px solid var(--line-strong); }
.alert.muted { opacity: .85; }
.toast { box-shadow: var(--shadow); }
/* while alerts sit in the corner stack, wide screens make room for it so it never hides a control (WCAG 2.4.11) */
@media (min-width: 1200px) { .toasts { width: min(420px, 32vw); } body:has(#toasts .toast) main { padding-right: calc(min(420px, 32vw) + var(--space-6)); } }
.muted-flag, .acked-flag { display: inline-flex; align-items: center; height: 20px; font: 600 var(--text-xs)/1 var(--font-sans); letter-spacing: .04em;
  border: var(--border) dashed var(--muted); padding: 0 var(--space-2); color: var(--muted); border-radius: var(--radius); }
.acked-flag { border-style: solid; color: var(--ok); border-color: var(--ok); }
@media (max-width: 1000px) { .live-grid { grid-template-columns: minmax(0, 1fr); } .live-side { grid-column: 1; grid-row: auto; } }
/* on a phone the stack would cover the page, so it sits in the flow above the alert list */
@media (max-width: 700px) { .toasts { position: static; width: auto; margin: 0 0 var(--space-4); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
@media print { .bar, .toasts, .nav { display: none; } body { background: none; } }
