@font-face {
  font-family: "Kufi";
  src: url("assets/fonts/kufi.ttf") format("truetype");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --paper: oklch(0.968 0.010 85);
  --paper-2: oklch(0.938 0.014 82);
  --ink: oklch(0.24 0.018 60);
  --ink-2: oklch(0.46 0.018 60);
  --ink-3: oklch(0.62 0.014 70);
  --line: oklch(0.86 0.014 80);
  --accent: oklch(0.30 0.02 60); /* ink: orange belongs to clashes only */
  --gov: #2E6B3A;
  --hou: #D9483B;
  --strike: oklch(0.57 0.20 28);
  --contest: oklch(0.70 0.15 62);
  --path: #1F6FD8;
  --r: 8px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --t-xs: 0.8125rem; --t-s: 0.9375rem; --t-m: 1rem; --t-l: 1.25rem; --t-xl: 1.75rem;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Kufi", "Segoe UI", system-ui, sans-serif;
  background: var(--paper-2);
  color: var(--ink);
  display: grid;
  grid-template-rows: 56px 1fr auto;
  overflow: hidden;
  font-size: var(--t-m);
}
button, select { font: inherit; color: inherit; }
h2 { font-size: var(--t-s); font-weight: 700; margin: 0 0 var(--s3); color: var(--ink); }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: var(--s5);
  padding: 0 var(--s5);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: var(--s2); font-size: var(--t-l); }
.brand-logo { height: 38px; width: auto; display: block; }
.brand-sub { color: var(--ink-2); font-size: var(--t-s); padding-inline-start: var(--s3); border-inline-start: 1px solid var(--line); }
.incident { display: flex; align-items: baseline; gap: var(--s4); color: var(--ink-2); font-size: var(--t-s); }
.incident-name { color: var(--ink); font-weight: 700; font-size: var(--t-m); }
.incident-range { padding: 2px var(--s3); border: 1px solid var(--line); border-radius: 999px; }
.side-filter { margin-inline-start: auto; display: flex; background: var(--paper-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.side-filter button {
  border: 0; background: none; padding: 5px var(--s4); border-radius: 999px; cursor: pointer; font-size: var(--t-s); color: var(--ink-2);
  transition: background 180ms var(--ease), color 180ms var(--ease);
}
.side-filter button[aria-checked="true"] { background: var(--ink); color: var(--paper); }
.side-filter button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* stage */
.stage { display: grid; grid-template-columns: 1fr 340px; min-height: 0; }
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: oklch(0.70 0.03 220); }
.map-clock {
  position: absolute; z-index: 3; top: var(--s4); right: var(--s4);
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--s3) var(--s4); background: color-mix(in oklch, var(--paper) 92%, transparent);
  border: 1px solid var(--line); border-radius: var(--r);
}
.clock-day { font-size: var(--t-s); color: var(--ink-2); font-weight: 700; }
.clock-date { font-size: var(--t-xl); font-weight: 800; font-variant-numeric: tabular-nums; }

.legend {
  position: absolute; z-index: 3; top: var(--s4); left: var(--s4); margin: 0; padding: var(--s3) var(--s4);
  list-style: none; display: grid; gap: 6px; font-size: var(--t-s); font-weight: 600;
  background: color-mix(in oklch, var(--paper) 92%, transparent); border: 1px solid var(--line); border-radius: var(--r);
}
.legend li { display: flex; align-items: center; gap: var(--s2); }
.sw { width: 22px; height: 12px; border-radius: 3px; flex: none; }
.sw-gov { background: var(--gov); }
.sw-hou { background: var(--hou); }
.sw-clash { border: 1.5px dashed #E0901A; background: repeating-linear-gradient(-45deg, #E0901A 0 2px, transparent 2px 5px); }
.sw-path { height: 4px; background: linear-gradient(270deg, var(--path), #8CC8FF); }
.cam-toggle {
  position: absolute; bottom: var(--s4); left: 64px; padding: 6px var(--s4); border-radius: 999px; cursor: pointer;
  font-size: var(--t-xs); font-weight: 700; border: 1px solid var(--line); background: var(--paper); color: var(--ink-2);
}
.cam-toggle[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.cam-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.attrib { position: absolute; bottom: var(--s2); right: var(--s4); margin: 0; font-size: 11px; padding: 2px 8px; border-radius: 4px; color: var(--ink-2); background: color-mix(in oklch, var(--paper) 85%, transparent); }

/* panel (left in RTL) */
.panel { background: var(--paper); border-inline-start: 1px solid var(--line); overflow-y: auto; }
.panel-block { padding: var(--s5); border-bottom: 1px solid var(--line); }
.layers { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.layers label { display: grid; grid-template-columns: 18px 28px 1fr auto; align-items: center; gap: var(--s3); cursor: pointer; font-size: var(--t-s); }
.layers input { accent-color: var(--ink); width: 16px; height: 16px; margin: 0; }
.swatch { width: 28px; height: 18px; border-radius: 4px; border: 1px solid var(--line); }
.layers .count { color: var(--ink-3); font-variant-numeric: tabular-nums; font-size: var(--t-xs); }

/* dock */
.dock { background: var(--paper); border-top: 1px solid var(--line); padding: var(--s3) var(--s5) var(--s4); }
.timeline { display: flex; align-items: center; gap: var(--s4); }
.transport { display: flex; align-items: center; gap: var(--s2); }
.play { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper-2); cursor: pointer; display: grid; place-items: center; }
.play span { width: 12px; height: 12px; border-inline: 4px solid var(--ink); }
.play.paused span { border: 0; width: 0; height: 0; border-block: 7px solid transparent; border-inline-end: 11px solid var(--ink); }
.transport select { border: 1px solid var(--line); background: var(--paper-2); border-radius: 6px; padding: 4px 6px; }
.track { position: relative; flex: 1; height: 44px; cursor: pointer; }
.track:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.track .rail { position: absolute; inset-inline: 0; top: 14px; height: 4px; background: var(--paper-2); border-radius: 2px; }
.track .done { position: absolute; inset-inline-start: 0; top: 14px; height: 4px; background: var(--ink-2); border-radius: 2px; }
.track .tick { position: absolute; top: 10px; width: 2px; height: 12px; border-radius: 1px; opacity: 0.85; transition: opacity 200ms var(--ease); }
.track .tick.ahead { opacity: 0.18; } /* not happened yet */
.track[data-side="G"] .tick[data-side="H"], .track[data-side="H"] .tick[data-side="G"] { display: none; }
.track .day { position: absolute; top: 26px; transform: translateX(50%); font-size: var(--t-xs); color: var(--ink-2); white-space: nowrap; }
.track .head { position: absolute; top: 6px; width: 3px; height: 20px; background: var(--ink); border-radius: 2px; transform: translateX(50%); }
.track .head-label {
  position: absolute; top: -22px; transform: translateX(50%); white-space: nowrap;
  background: var(--ink); color: var(--paper); font-size: var(--t-xs); padding: 1px 8px; border-radius: 4px; font-variant-numeric: tabular-nums;
}
.dock-row { display: grid; grid-template-columns: 1fr 1fr 1fr 1.4fr; gap: var(--s5); margin-top: var(--s3); height: 196px; overflow: hidden; } /* fixed: the map never jumps while it plays */
.dock-row[data-side="G"] .chart[data-for="H"], .dock-row[data-side="H"] .chart[data-for="G"] { opacity: 0.2; filter: grayscale(1); }
.chart { margin: 0; min-width: 0; }
.chart figcaption { font-size: var(--t-xs); color: var(--ink); font-weight: 700; margin-bottom: var(--s1); }
.chart figcaption small { display: block; font-weight: 400; color: var(--ink-2); font-size: 11px; }
.chart svg { width: 100%; height: 86px; display: block; }
.key-events h2 { margin-bottom: var(--s2); }
.key-events ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.key-events li { display: grid; grid-template-columns: 10px 1fr auto; gap: var(--s2); align-items: center; font-size: var(--t-xs); cursor: pointer; }
.key-events li .dot { width: 8px; height: 8px; border-radius: 50%; }
.key-events li .txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.key-events li time { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.key-events li.fresh .txt { font-weight: 700; }

/* map markers */
/* labels over terrain: white text on a dark translucent halo (maplibre-cartography, imagery rule) */
.lbl-city { font-size: 15px; font-weight: 700; color: #fff; text-shadow: 0 0 3px rgb(0 0 0 / 0.75), 0 0 6px rgb(0 0 0 / 0.5); white-space: nowrap; display: flex; align-items: center; gap: 6px; pointer-events: none; }
.lbl-city::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgb(0 0 0 / 0.55); }
.lbl-front {
  font-size: 12px; padding: 3px 8px; border-radius: 4px; white-space: nowrap; pointer-events: none;
  background: var(--paper); border: 1px solid var(--line); box-shadow: 0 2px 8px oklch(0.2 0.02 60 / 0.15);
}
.lbl-front b { display: block; font-size: 13px; }
.lbl-front time { color: var(--ink-2); font-weight: 700; font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* map controls: match the paper panels */
.maplibregl-ctrl-group { background: var(--paper) !important; border: 1px solid var(--line); box-shadow: none !important; }
.maplibregl-ctrl-group button { width: 34px !important; height: 34px !important; }

/* event card (map popup): the full report behind a mark */
.detail-pop .maplibregl-popup-content {
  direction: rtl; text-align: right; font-family: inherit; padding: var(--s4) var(--s4) var(--s3);
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: 0 10px 30px oklch(0.2 0.02 60 / 0.25);
  max-height: 46vh; overflow-y: auto;
}
.detail-pop .maplibregl-popup-close-button { left: 6px; right: auto; font-size: 20px; color: var(--ink-2); padding: 2px 8px; }
.detail-pop.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--paper); }
.detail-pop.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--paper); }
.detail-pop.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--paper); }
.detail-pop.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--paper); }
.detail-list > h2 { font-size: var(--t-xs); color: var(--ink-2); margin: 0 0 var(--s2); padding-inline-end: var(--s5); }
.detail + .detail { margin-top: var(--s3); padding-top: var(--s3); border-top: 1px solid var(--line); }
.detail header { display: flex; align-items: center; gap: var(--s2); padding-inline-end: var(--s5); }
.detail .chip { font-size: var(--t-xs); font-weight: 700; color: var(--c); background: color-mix(in oklch, var(--c) 12%, var(--paper)); padding: 1px 8px; border-radius: 999px; }
.detail header time { font-size: var(--t-xs); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.detail h3 { font-size: var(--t-s); font-weight: 700; margin: var(--s2) 0 var(--s1); line-height: 1.5; }
.detail p { font-size: var(--t-m); line-height: 1.75; margin: 0 0 var(--s2); color: var(--ink); }
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 2px var(--s3); margin: 0 0 var(--s2); font-size: var(--t-xs); }
.detail dt { color: var(--ink-3); }
.detail dd { margin: 0; font-weight: 600; }
.detail dd.unconf { color: var(--ink); text-decoration: underline dashed; text-underline-offset: 3px; }
.detail footer { display: flex; gap: var(--s3); font-size: var(--t-xs); }
.detail footer a { color: var(--ink); font-weight: 700; }
.detail-more { font-size: var(--t-xs); color: var(--ink-3); margin-top: var(--s2); }
.key-events li:hover .txt, .key-events li:focus-visible .txt { text-decoration: underline; text-underline-offset: 3px; }
.key-events li:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* «الحصيلة المعلنة»: labelled rows, each block says who reported it */
.tally h2 { margin-bottom: var(--s4); }
.tally h3 { font-size: var(--t-s); margin: var(--s4) 0 2px; }
.tally h3:first-of-type { margin-top: 0; }
.tally .how { margin: 0 0 var(--s2); font-size: var(--t-xs); color: var(--ink-2); }
.tally dl { margin: 0; display: grid; gap: 2px; }
.tally .row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); padding: 5px 0; border-bottom: 1px solid var(--line); }
.tally dt { font-size: var(--t-s); color: var(--ink-2); }
.tally dd { margin: 0; font-size: var(--t-l); font-weight: 800; font-variant-numeric: tabular-nums; }
.tally .gap { margin: var(--s2) 0 0; font-size: var(--t-xs); color: var(--ink-2); }
.tally a.src { display: inline-block; margin-top: var(--s2); font-size: var(--t-xs); color: var(--ink); }

/* «الموجز»: the report at the playhead, on the map, big enough for the phone video */
.brief {
  position: absolute; z-index: 3; left: 50%; top: var(--s4); transform: translateX(-50%); /* the horizon: the pitched camera keeps the action low */
  width: min(660px, calc(100% - 560px)); min-width: 320px; padding: var(--s3) var(--s4) var(--s3);
  background: color-mix(in oklch, var(--paper) 95%, transparent); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: 0 8px 28px oklch(0.2 0.02 60 / 0.22); cursor: pointer;
}
.brief[hidden] { display: none; }
.brief.in { animation: brief-in 380ms var(--ease); }
@keyframes brief-in { from { opacity: 0; transform: translate(-50%, -8px); } }
.brief header { display: flex; align-items: center; gap: var(--s2); font-size: var(--t-s); color: var(--ink-2); }
.brief .chip { font-weight: 700; color: var(--c); background: color-mix(in oklch, var(--c) 12%, var(--paper)); padding: 1px 10px; border-radius: 999px; }
.brief time { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.brief p { margin: 6px 0 4px; font-size: var(--t-l); line-height: 1.6; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.brief footer { font-size: var(--t-xs); color: var(--ink-2); }
.brief:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .brief.in { animation: none; } }

/* the programme's mark on the map: a quiet watermark that survives screenshots and recordings */
.map-mark {
  position: absolute; z-index: 2; right: var(--s4); bottom: 44px; width: 92px; height: auto;
  opacity: 0.6; pointer-events: none; filter: drop-shadow(0 1px 3px oklch(0.2 0.02 60 / 0.55));
}

/* ===================== Every screen size =====================
   Desktop keeps map + side panel + dock. Below 1024px the page becomes one column: map, timeline, then one
   section at a time behind tabs (الأحداث / الحصيلة / الأرقام / الطبقات). .stage, .panel, .dock and .dock-row
   dissolve (display: contents) so their pieces join the page grid in reading order. */
.tabs { display: none; }

/* laptops with short screens: give the map the height, slim the dock */
@media (min-width: 1024px) and (max-height: 820px) {
  .dock { padding-block: var(--s2) var(--s3); }
  .dock-row { height: 150px; margin-top: var(--s2); }
  .chart svg { height: 64px; }
  .chart figcaption small { display: none; }
  .key-events ol { gap: 3px; }
}
@media (min-width: 1024px) and (max-width: 1279px) {
  .stage { grid-template-columns: 1fr 290px; }
  .incident-place { display: none; }
  .brief { width: min(560px, calc(100% - 520px)); }
}

@media (max-width: 1023px) {
  body { display: grid; grid-template-rows: none; grid-auto-rows: auto; overflow-y: auto; overflow-x: hidden; min-height: 100svh; height: auto; }
  .stage, .panel, .dock, .dock-row { display: contents; }

  /* top bar: logo and dates on one line, the side filter full width under it */
  .topbar { order: 1; flex-wrap: wrap; gap: var(--s2) var(--s3); padding: var(--s2) var(--s4); }
  .brand-sub, .incident-name, .incident-place { display: none; }
  .incident { margin-inline-start: auto; }
  .side-filter { order: 3; width: 100%; margin: 0; }
  .side-filter button { flex: 1; min-height: 44px; font-size: var(--t-s); white-space: nowrap; }
  .brand-logo { height: 32px; }

  /* the map: most of the screen, but the timeline stays in view under it */
  .map-wrap { order: 2; height: clamp(320px, 58svh, 760px); }
  .legend { display: none; } /* the same keys live in the الطبقات tab */
  .map-clock { top: var(--s2); right: var(--s2); padding: var(--s2) var(--s3); }
  .clock-day { font-size: var(--t-xs); }
  .clock-date { font-size: var(--t-l); }
  .brief {
    top: auto; bottom: 34px; left: var(--s2); right: var(--s2); width: auto; min-width: 0; transform: none;
    padding: var(--s2) var(--s3);
  }
  @keyframes brief-in { from { opacity: 0; transform: translateY(6px); } }
  .brief header { font-size: var(--t-xs); flex-wrap: wrap; }
  .brief .where { display: none; }
  .brief p { font-size: var(--t-m); -webkit-line-clamp: 2; margin: 4px 0 2px; }
  .brief footer { display: none; }
  .map-mark { top: var(--s2); bottom: auto; left: var(--s2); right: auto; width: 58px; opacity: 0.55; }
  .attrib { font-size: 10px; right: var(--s2); bottom: var(--s1); padding: 1px 6px; }
  .cam-toggle { bottom: auto; top: calc(var(--s2) + 76px); left: var(--s2); padding: 6px var(--s3); }
  .maplibregl-ctrl-bottom-left { bottom: 34px; }
  .ctrl-turn { display: none; } /* two-finger rotate and tilt on touch screens */

  /* timeline right under the map, big touch targets */
  .timeline { order: 3; padding: var(--s3) var(--s4) var(--s2); gap: var(--s3); background: var(--paper); border-top: 1px solid var(--line); }
  .play { width: 44px; height: 44px; }
  .transport select { min-height: 44px; }
  .track .day { font-size: 11px; }

  /* tabs */
  .tabs {
    order: 4; display: grid; grid-template-columns: repeat(4, 1fr); position: sticky; top: 0; z-index: 15;
    background: var(--paper); border-block: 1px solid var(--line);
  }
  .tabs button {
    min-height: 48px; border: 0; background: none; cursor: pointer; font-size: var(--t-s); font-weight: 700; color: var(--ink-2);
    border-bottom: 3px solid transparent;
  }
  .tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
  .tabs button:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }

  [data-pane] { order: 5; background: var(--paper); padding: var(--s4); border-bottom: 1px solid var(--line); }
  body:not([data-tab="events"]) [data-pane="events"],
  body:not([data-tab="tally"]) [data-pane="tally"],
  body:not([data-tab="charts"]) [data-pane="charts"],
  body:not([data-tab="layers"]) [data-pane="layers"] { display: none; }
  .panel-block { border-bottom: 1px solid var(--line); }

  /* the news list reads in full on small screens */
  .key-events h2 { display: none; }
  .key-events ol { gap: 0; }
  .key-events li { grid-template-columns: 10px 1fr; grid-template-rows: auto auto; gap: 2px var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--line); min-height: 44px; font-size: var(--t-s); }
  .key-events li .dot { grid-row: 1 / span 2; align-self: start; margin-top: 7px; }
  .key-events li .txt { white-space: normal; line-height: 1.7; }
  .key-events li time { grid-column: 2; font-size: var(--t-xs); }
  .chart svg { height: 110px; }
  .layers label { min-height: 44px; }
  .layers input { width: 20px; height: 20px; }

  .detail-pop { max-width: calc(100vw - 24px) !important; }
  .detail-pop .maplibregl-popup-content { max-height: 50svh; }
}

/* tablets and open foldables: charts side by side, tally in two columns */
@media (min-width: 600px) and (max-width: 1023px) {
  body[data-tab="charts"] { grid-template-columns: repeat(3, 1fr); }
  body[data-tab="charts"] > :not([data-pane="charts"]) { grid-column: 1 / -1; }
  .tally { columns: 2; column-gap: var(--s6); }
  .tally h2 { column-span: all; }
  .brief { left: 50%; right: auto; width: min(620px, calc(100% - 32px)); transform: translateX(-50%); }
  @keyframes brief-in { from { opacity: 0; transform: translate(-50%, 6px); } }
}

/* phones held sideways: the map takes the screen, everything else scrolls under it */
@media (max-width: 1023px) and (max-height: 500px) and (orientation: landscape) {
  .map-wrap { height: 86svh; }
  .topbar { position: static; }
  .side-filter { order: 0; width: auto; margin-inline-start: auto; }
  .side-filter button { min-height: 36px; }
  .tabs { top: 0; }
}

/* phones: one-line filter, fewer day labels, gestures instead of map buttons */
@media (max-width: 599px) {
  .side-filter button { white-space: nowrap; font-size: var(--t-xs); padding-inline: var(--s2); }
  .track .day:nth-of-type(even) { visibility: hidden; }
}
@media (max-width: 1023px) and (pointer: coarse) {
  .maplibregl-ctrl-bottom-left { display: none; } /* pinch to zoom, two fingers to turn and tilt */
}

/* attacks in motion: a canvas over the map, above the layers, below the panels */
.fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.scope-toggle {
  position: absolute; bottom: var(--s4); left: 230px; padding: 6px var(--s4); border-radius: 999px; cursor: pointer;
  font-size: var(--t-xs); font-weight: 700; border: 1px solid var(--hou); background: var(--paper); color: var(--hou); z-index: 2;
}
.scope-toggle[aria-pressed="true"] { background: var(--hou); color: var(--paper); }
.scope-toggle:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.lbl-sa { font-size: 13px; }
@media (max-width: 1023px) {
  .scope-toggle { bottom: auto; top: calc(var(--s2) + 118px); left: var(--s2); padding: 6px var(--s3); }
}
