:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1b1a17;
  --muted: #5f5b53;
  --border: #dcd8cf;
  --accent: #c2410c;
  --accent-soft: #fde7da;
  --rail: #d6d1c6;
  --focus: #2563eb;

  --c-misconfiguration: #b45309;
  --c-unauthorized-access: #b91c1c;
  --c-exploited-vulnerability: #c2410c;
  --c-software-bug: #6d28d9;
  --c-third-party: #0f766e;
  --c-supply-chain: #be185d;
  --c-insider: #4d7c0f;
  --c-other: #57534e;

  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --surface: #1a1918;
    --surface-2: #242320;
    --text: #ecebe7;
    --muted: #a19d94;
    --border: #2f2d2a;
    --accent: #fb923c;
    --accent-soft: #3a2316;
    --rail: #34322e;
    --focus: #60a5fa;

    --c-misconfiguration: #fbbf24;
    --c-unauthorized-access: #f87171;
    --c-exploited-vulnerability: #fb923c;
    --c-software-bug: #a78bfa;
    --c-third-party: #2dd4bf;
    --c-supply-chain: #f472b6;
    --c-insider: #a3e635;
    --c-other: #a8a29e;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--sans);
}

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }

.skip {
  position: absolute; left: -9999px; top: 8px;
  background: var(--surface); padding: 8px 12px; border-radius: 6px; z-index: 10;
}
.skip:focus { left: 8px; }

/* Header: the days-since counter is the headline on every screen size. */
.site-header { padding: 56px 0 40px; border-bottom: 1px solid var(--border); }
.head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "logo    hero"
    "tagline hero"
    "stats   hero";
  grid-template-rows: auto auto 1fr;
  column-gap: 48px;
}
.logo {
  grid-area: logo;
  margin: 0;
  font: 700 clamp(2rem, 6vw, 2.75rem)/1.1 var(--mono);
  letter-spacing: -0.03em;
}
.logo-mark { color: var(--accent); margin-right: 0.35em; font-size: 0.6em; vertical-align: 0.25em; }
.logo-dot { color: var(--accent); }
.tagline { grid-area: tagline; margin: 10px 0 24px; color: var(--muted); max-width: 40ch; font-size: 1.05rem; }

.stats dt { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.hero {
  grid-area: hero;
  align-self: end;
  padding-left: 40px;
  border-left: 1px solid var(--border);
  min-width: 15rem;
}
/* Reads as one phrase: "4 days since the last incident". */
.hero-count { margin: 0; }
.hero-label { display: block; margin-top: 8px; font-size: 1.15rem; font-weight: 600; }
.hero-num {
  display: block;
  font: 700 clamp(6rem, 14vw, 9.5rem)/0.9 var(--mono);
  letter-spacing: -0.05em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.hero-unit { white-space: pre; word-spacing: -0.35em; font-size: 0.34em; font-weight: 600; letter-spacing: -0.02em; }
.hero-sub, .hero-trend { display: block; font-size: 0.95rem; color: var(--muted); }
.hero-sub { margin-top: 14px; text-decoration: none; }
.hero-sub:hover { color: var(--accent); }
.hero-trend { margin-top: 2px; }
.hero-trend b { color: var(--text); font-family: var(--mono); }
.trend-arrow { font-size: 0.7em; vertical-align: 0.1em; margin-right: 2px; }
.trend-arrow.up { color: var(--accent); }
.trend-arrow.down { color: var(--c-third-party); }
.hero-sub[hidden], .hero-trend[hidden] { display: none; }

.stats { grid-area: stats; align-self: end; display: flex; flex-wrap: wrap; gap: 12px 40px; margin: 0; }
.stat { min-width: 0; }
.stats dd { margin: 2px 0 0; }
.stat-num { display: block; font: 600 1.75rem/1.2 var(--mono); font-variant-numeric: tabular-nums; }

.scroll-cue { display: none; }

/* Phones: the header is the landing screen, built around the numbers. */
@media (max-width: 680px) {
  .site-header {
    display: flex;
    min-height: 100vh;
    min-height: 100svh;
    padding: 40px 0 24px;
  }
  .head { display: flex; flex-direction: column; width: 100%; }
  .tagline { margin-bottom: 0; }

  /* Centre the counter and the small stats in whatever height is left. */
  .hero, .stats { align-self: stretch; }
  .hero { margin-top: auto; padding: clamp(16px, 5vh, 40px) 0 0; border: 0; min-width: 0; }
  .hero-num { font-size: clamp(5.5rem, 34vw, 9rem); line-height: 0.95; letter-spacing: -0.04em; margin-top: 4px; }
  .hero-sub { margin-top: 10px; }
  .stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin: clamp(16px, 3.5vh, 28px) 0 auto;
    padding-bottom: clamp(16px, 5vh, 40px);
  }
  .stat { padding-top: 16px; border-top: 1px solid var(--border); }
  .stat-num { font-size: clamp(2.25rem, 12vw, 3rem); line-height: 1.05; margin-top: 4px; }

  .scroll-cue {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px;
    color: var(--muted);
    font-size: 0.95rem;
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: 999px;
  }
  .scroll-cue:hover { color: var(--text); border-color: var(--muted); }
}

/* Activity heatmap */
.activity { padding: 28px 0 20px; scroll-margin-top: 16px; }
.activity[hidden] { display: none; }
.activity-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 16px; margin-bottom: 12px; }
.activity h2 { margin: 0; font-size: 1rem; font-weight: 600; }
#activity-total { font-family: var(--mono); color: var(--accent); }
.activity-peak { margin: 0; color: var(--muted); font-size: 0.85rem; }

.heatmap { position: relative; --cell: 12px; --gap: 3px; }
.heatmap-months { position: relative; height: 18px; font-size: 0.75rem; color: var(--muted); }
.heatmap-months button {
  position: absolute; top: 0;
  font: inherit; line-height: 1; color: inherit;
  background: none; border: 0; padding: 0 2px; margin-left: -2px;
  border-radius: 3px; cursor: pointer; white-space: nowrap;
}
.heatmap-months button:hover, .heatmap-months button[aria-pressed="true"] { color: var(--text); }
.heatmap-months button[aria-pressed="true"] { text-decoration: underline; text-underline-offset: 3px; }
.heatmap-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, var(--cell));
  grid-auto-columns: var(--cell);
  gap: var(--gap);
}
.cell {
  display: inline-block;
  width: var(--cell); height: var(--cell);
  padding: 0; border: 0; border-radius: 2px;
  background: var(--surface-2);
}
.cell[data-level="1"] { background: color-mix(in srgb, var(--accent) 38%, var(--surface-2)); }
.cell[data-level="2"] { background: color-mix(in srgb, var(--accent) 68%, var(--surface-2)); }
.cell[data-level="3"] { background: var(--accent); }
button.cell { cursor: pointer; }
button.cell:hover, .cell.is-selected { outline: 2px solid var(--text); outline-offset: 1px; }
.cell.is-future { visibility: hidden; }

.heatmap-tip {
  position: absolute; z-index: 6;
  width: max-content; max-width: min(300px, 100%);
  padding: 8px 10px;
  background: var(--text); color: var(--bg);
  border-radius: 6px;
  font-size: 0.8rem; line-height: 1.4;
  pointer-events: none;
}
.heatmap-tip[hidden] { display: none; }
.heatmap-tip strong { display: block; }
.heatmap-tip ul { margin: 4px 0 0; padding-left: 14px; }

.heatmap-legend { display: flex; justify-content: flex-end; align-items: center; gap: 3px; margin-top: 8px; font-size: 0.75rem; color: var(--muted); }
.heatmap-legend .cell { --cell: 10px; margin: 0 1px; }

/* Filters */
.filters {
  position: sticky; top: 0; z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 2fr) repeat(2, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin: 0 -16px;
  padding: 14px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field span { font-size: 0.75rem; color: var(--muted); }
.field input, .field select, .reset {
  width: 100%;
  font: inherit; font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 38px;
}
.reset { width: auto; cursor: pointer; background: var(--surface-2); }
.reset:hover { border-color: var(--muted); }

/* Category chips: the filter and the colour key for the timeline dots. */
.cats { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.cat {
  --cat: var(--c-other);
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 30px; padding: 4px 10px;
  font: inherit; font-size: 0.8rem; line-height: 1;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.cat::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--cat); }
.cat:hover { border-color: var(--muted); }
.cat[aria-pressed="true"] { border-color: var(--cat); background: color-mix(in srgb, var(--cat) 14%, var(--surface)); }
.cat-n { color: var(--muted); font: 0.75rem var(--mono); }

@media (max-width: 680px) {
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); position: static; }
  .field-search { grid-column: 1 / -1; }
  .reset { grid-column: 1 / -1; width: 100%; order: 1; }
  .cat { min-height: 36px; }
}

.result-count { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 16px 0 0; color: var(--muted); font-size: 0.9rem; min-height: 1.4em; }
.when-chip {
  font: inherit; font-size: 0.8rem; line-height: 1;
  padding: 6px 10px;
  color: var(--text);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  cursor: pointer;
}
.when-chip::after { content: " ×"; color: var(--muted); }
.when-chip[hidden] { display: none; }

/* Timeline */
.timeline { padding: 8px 0 24px; }
.year {
  margin: 28px 0 8px;
  font: 700 1.1rem/1 var(--mono);
  color: var(--muted);
  letter-spacing: 0.02em;
}
.year:first-child { margin-top: 8px; }

.incident {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  scroll-margin-top: 100px;
}
.incident-rail { position: relative; }
.incident-rail::before {
  content: ""; position: absolute; left: 8px; top: 0; bottom: 0; width: 2px; background: var(--rail);
}
.dot {
  position: absolute; left: 3px; top: 24px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--bg);
  border: 3px solid var(--c-other);
}
.incident[data-category="misconfiguration"] .dot { border-color: var(--c-misconfiguration); }
.incident[data-category="unauthorized-access"] .dot { border-color: var(--c-unauthorized-access); }
.incident[data-category="exploited-vulnerability"] .dot { border-color: var(--c-exploited-vulnerability); }
.incident[data-category="software-bug"] .dot { border-color: var(--c-software-bug); }
.incident[data-category="third-party"] .dot { border-color: var(--c-third-party); }
.incident[data-category="supply-chain"] .dot { border-color: var(--c-supply-chain); }
.incident[data-category="insider"] .dot { border-color: var(--c-insider); }

.incident-body {
  margin: 10px 0;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
}
.incident.is-target .incident-body { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.incident-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.incident-date { font: 600 0.85rem/1 var(--mono); color: var(--muted); margin-right: 4px; }
.chip {
  display: inline-block;
  font-size: 0.75rem; line-height: 1;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  white-space: nowrap;
}
.chip-vendor { font-weight: 600; }
.chip-category { color: var(--c-other); background: transparent; border: 1px solid currentColor; }
.chip-category[data-category="misconfiguration"] { color: var(--c-misconfiguration); }
.chip-category[data-category="unauthorized-access"] { color: var(--c-unauthorized-access); }
.chip-category[data-category="exploited-vulnerability"] { color: var(--c-exploited-vulnerability); }
.chip-category[data-category="software-bug"] { color: var(--c-software-bug); }
.chip-category[data-category="third-party"] { color: var(--c-third-party); }
.chip-category[data-category="supply-chain"] { color: var(--c-supply-chain); }
.chip-category[data-category="insider"] { color: var(--c-insider); }

.incident-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.permalink, .share { color: var(--muted); text-decoration: none; padding: 2px 6px; border-radius: 4px; }
.permalink { font-family: var(--mono); }
.share { font: inherit; font-size: 0.8rem; background: none; border: 0; cursor: pointer; }
.permalink:hover, .share:hover { color: var(--accent); background: var(--surface-2); }
.share.is-done { color: var(--accent); }

.incident-title { margin: 10px 0 6px; font-size: 1.15rem; line-height: 1.35; text-wrap: balance; }
.incident-summary { margin: 0 0 12px; }

.incident-meta {
  display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px;
  margin: 0 0 12px; font-size: 0.9rem;
}
.incident-meta dt { color: var(--muted); }
.incident-meta dd { margin: 0; }
@media (max-width: 480px) {
  .incident-meta { grid-template-columns: minmax(0, 1fr); }
  .incident-meta dd { margin-bottom: 6px; }
}

.tags { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0; margin: 0 0 12px; }
.tags button {
  font: 0.75rem/1 var(--mono);
  color: var(--muted);
  background: var(--surface-2);
  border: 0; border-radius: 4px;
  padding: 5px 7px;
  cursor: pointer;
}
.tags button::before { content: "#"; opacity: 0.6; }
.tags button:hover { color: var(--text); }

.sources { border-top: 1px dashed var(--border); padding-top: 10px; }
.sources h4 { margin: 0 0 6px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.sources ul { margin: 0; padding-left: 18px; font-size: 0.9rem; }
.sources li { margin: 3px 0; overflow-wrap: anywhere; }
.publisher { color: var(--muted); margin-left: 6px; font-size: 0.85em; }
.publisher::before { content: "— "; }

.status { color: var(--muted); padding: 24px 0; }
.timeline[aria-busy="true"] { opacity: 0.55; transition: opacity 0.15s ease 0.15s; }

/* Pinned permalink target that isn't on a loaded page */
.linked { padding-top: 8px; }
.linked[hidden] { display: none; }

/* Paging */
.more { display: flex; justify-content: center; padding: 0 0 32px; }
.more-btn {
  font: inherit; color: var(--text); cursor: pointer;
  min-height: 44px; padding: 8px 20px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
}
.more-btn:hover:not(:disabled) { border-color: var(--muted); }
.more-btn:disabled { cursor: progress; color: var(--muted); }
.more-btn[hidden] { display: none; }

/* About & footer */
.about { margin: 24px 0 48px; padding-top: 24px; border-top: 1px solid var(--border); max-width: 68ch; }
.about h2 { font-size: 1.1rem; margin: 0 0 8px; }
.about p { color: var(--muted); }
.about strong { color: var(--text); }

.site-footer { border-top: 1px solid var(--border); padding: 20px 0 32px; color: var(--muted); font-size: 0.85rem; }
.site-footer p { margin: 2px 0; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

.notfound { padding-top: 64px; padding-bottom: 64px; }
