/* ==========================================================================
   Faces of Diplomacy Viewer — built for pigeon-effect.com in the site design
   language (token surfaces, Space Mono throughout — the site uses a single
   typewriter face — hairline borders, soft shadows). Unlike the UNGA /
   migration viewers this one was
   not migrated from a GitHub Pages repo: the original project
   (github.com/Pigeon-Effect/Faces-of-Diplomacy) published static SVGs from
   Python (plotly treemap + seaborn heatmap); this D3 app re-implements both
   as interactive views over the same data, vendored as
   treemap_data.json / heatmap_data.json (see data notes in main.js).
   ========================================================================== */

:root {
  /* Every colour is a site token (core/css/tokens.css), so the viewer follows
     the site theme; the continent fills in main.js are data, not tokens. */
  --bg: rgb(var(--pe-paper));
  --card: rgb(var(--pe-surface));          /* panel / tooltip surface          */
  --line: rgb(var(--pe-line) / .1);        /* hairline borders                 */
  --line-strong: rgb(var(--pe-line) / .18);
  --ink-head: rgb(var(--pe-ink));          /* headings, hover                  */
  --ink: rgb(var(--pe-ink));               /* body text                        */
  --ink-2: rgb(var(--pe-ink-2));           /* secondary                        */
  --ink-3: rgb(var(--pe-ink-3));           /* muted                            */
  --accent: rgb(var(--pe-accent));         /* active fills                     */
  --accent-text: rgb(var(--pe-accent-text));
  --on-accent: rgb(var(--pe-on-accent));
  --shadow-card: 0 1px 2px rgb(var(--pe-chrome) / .04), 0 8px 24px -20px rgb(var(--pe-chrome) / .25);
  --shadow-pop: 0 12px 32px -12px rgb(var(--pe-chrome) / .25);
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: var(--pe-font);
  font-weight: 300;
  background-color: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px clamp(16px, 16vw, 280px);
  box-sizing: border-box;
}

/* Standalone mode (not iframed): leave room for the fixed site-style footer. */
body.standalone {
  padding-bottom: 54px;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgb(var(--pe-line) / .25); border-radius: 4px; }

/* ── Controls bar ─────────────────────────────────────────────────────────── */
#controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 18px;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
}

.mode-switch, .subset-switch { display: flex; gap: 8px; }

.mode-button, .subset-button {
  font-family: var(--pe-font);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  transition: color .25s ease, border-color .25s ease, background .25s ease;
}
.mode-button:hover, .subset-button:hover { color: var(--ink-head); border-color: var(--ink-3); }
.mode-button.active, .subset-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

#context-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 18px;
  min-width: 0;
}

.hint {
  font-size: 11px;
  color: var(--ink-3);
}

/* Heatmap legend */
#legend { display: flex; align-items: center; gap: 8px; }
#legend .legend-bar {
  width: 120px; height: 8px; border-radius: 4px;
  border: 1px solid var(--line-strong);
}
#legend .legend-tick {
  font-family: var(--pe-font);
  font-size: 11px;
  color: var(--ink-3);
}

/* ── Main panel ───────────────────────────────────────────────────────────── */
#viz-panel {
  flex: 1;
  min-height: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  box-sizing: border-box;
  overflow: hidden;
  position: relative;
}

#treemap-view { position: absolute; inset: 16px; }
#treemap-view svg { display: block; width: 100%; height: 100%; }

.tm-node { cursor: default; }
.tm-tile { stroke: var(--card); stroke-width: 1.2px; }
.tm-label { pointer-events: none; font-family: var(--pe-font); }
.tm-label .tm-name { font-weight: 400; }
.tm-label .tm-count { font-family: var(--pe-font); opacity: 0.75; }
.tm-group-label {
  pointer-events: none;
  fill: var(--ink-2);
  font-family: var(--pe-font);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.tm-subgroup-label {
  pointer-events: none;
  fill: var(--ink);
  font-family: var(--pe-font);
  letter-spacing: 0.04em;
}

/* ── Heatmap ──────────────────────────────────────────────────────────────── */
#heatmap-view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 0 20px 20px 20px;
  box-sizing: border-box;
}

#heatmap-grid {
  display: grid;
  /* label column + 7 emotion columns (set from JS) */
  grid-template-columns: 168px repeat(7, minmax(52px, 1fr));
  gap: 2px;
  min-width: 620px;
}

.hm-corner, .hm-col-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--card);
  padding: 10px 4px 8px 4px;
}
.hm-col-head {
  font-family: var(--pe-font);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
  text-align: center;
  cursor: pointer;
  border-bottom: 1px solid var(--line-strong);
  user-select: none;
  white-space: nowrap;
}
.hm-col-head:hover { color: var(--ink-head); }
.hm-col-head.sorted { color: var(--accent-text); }
.hm-corner {
  font-family: var(--pe-font);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  border-bottom: 1px solid var(--line-strong);
  display: flex;
  align-items: flex-end;
  cursor: pointer;
  user-select: none;
}
.hm-corner:hover { color: var(--ink-head); }
.hm-corner.sorted { color: var(--accent-text); }

.hm-row-label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  height: 20px;
  padding-right: 6px;
}
.hm-row-label .hm-name {
  font-size: 11px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hm-cell { height: 20px; border-radius: 2px; }
.hm-cell:hover { outline: 1.5px solid var(--ink-head); outline-offset: -1.5px; }

/* ── Tooltip ──────────────────────────────────────────────────────────────── */
#tooltip {
  position: fixed;
  display: none;
  pointer-events: none;
  z-index: 50;
  max-width: 260px;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  padding: 9px 12px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink);
}
#tooltip .tt-title {
  font-weight: 400;
  color: var(--ink-head);
  margin-bottom: 2px;
}
#tooltip .tt-mono {
  font-family: var(--pe-font);
  font-size: 11px;
  color: var(--ink-2);
}

/* ── Site-style footer (standalone only) ──────────────────────────────────── */
.viewer-footer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 28px;
  background: rgb(var(--pe-chrome));
  border-top: 2px solid rgb(var(--pe-accent));
}
.viewer-footer-brand {
  font-family: var(--pe-font);
  font-size: 16px;
  letter-spacing: 0.05em;
  color: rgb(var(--pe-on-chrome));
  text-decoration: none;
}
.viewer-footer-label {
  font-family: var(--pe-font);
  font-size: 11px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: rgb(var(--pe-on-chrome-2));
}
.viewer-footer a#exitViewerBtn {
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgb(var(--pe-on-chrome));
  text-decoration: none;
  transition: color .3s ease;
}
.viewer-footer a#exitViewerBtn:hover { color: rgb(var(--pe-accent)); }
