/* ==========================================================================
   Faces of Diplomacy Viewer — built for pigeon-effect.com in the site design
   language (white surface, 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 {
  --bg: #ffffff;
  --card: #ffffff;                         /* panel / tooltip surface          */
  --frost: rgba(231, 229, 228, 0.8);       /* footer bar (stone-200/80)        */
  --line: rgba(0, 0, 0, 0.07);             /* hairline borders                 */
  --line-strong: rgba(0, 0, 0, 0.12);
  --ink-head: #0f172a;                     /* slate-900 — headings, hover      */
  --ink: #1e293b;                          /* slate-800 — body text            */
  --ink-2: #64748b;                        /* slate-500 — secondary            */
  --ink-3: #94a3b8;                        /* slate-400 — muted                */
  --accent: #e15761;                       /* faces-of-diplomacy accent        */
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px -20px rgba(15, 23, 42, 0.25);
  --shadow-pop: 0 12px 32px -12px rgba(15, 23, 42, 0.25);
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: 'Space Mono', 'Courier New', monospace;
  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: rgba(0, 0, 0, 0.18); 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: 'Space Mono', 'Courier New', monospace;
  font-size: 10px;
  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: #ffffff;
}

#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: 'Space Mono', 'Courier New', monospace;
  font-size: 9px;
  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: #ffffff; stroke-width: 1.2px; }
.tm-label { pointer-events: none; font-family: 'Space Mono', 'Courier New', monospace; }
.tm-label .tm-name { font-weight: 400; }
.tm-label .tm-count { font-family: 'Space Mono', 'Courier New', monospace; opacity: 0.75; }
.tm-group-label {
  pointer-events: none;
  font-family: 'Space Mono', 'Courier New', monospace;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.tm-subgroup-label {
  pointer-events: none;
  font-family: 'Space Mono', 'Courier New', monospace;
  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: 'Space Mono', 'Courier New', monospace;
  font-size: 9.5px;
  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); }
.hm-corner {
  font-family: 'Space Mono', 'Courier New', monospace;
  font-size: 8.5px;
  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); }

.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: 'Space Mono', 'Courier New', monospace;
  font-size: 10px;
  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: var(--frost);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.viewer-footer-brand {
  font-family: 'Space Mono', 'Courier New', monospace;
  font-size: 16px;
  letter-spacing: 0.05em;
  color: var(--ink);
  text-decoration: none;
}
.viewer-footer-label {
  font-family: 'Space Mono', 'Courier New', monospace;
  font-size: 8px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.viewer-footer a#exitViewerBtn {
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink-2);
  text-decoration: none;
  transition: color .3s ease;
}
.viewer-footer a#exitViewerBtn:hover { color: var(--ink-head); }
