/*
TABLE OF CONTENTS
1. Theme and Base
2. Canvas UI
3. Diagram Canvas
4. Panels and Nodes
5. Connectors and Labels
6. Responsive
*/

/*
--------------------
-- THEME AND BASE --
--------------------
*/
:root {
  --bg: #f2f0e9;
  --grid: rgba(46, 86, 57, .055);
  --ink: #171a17;
  --muted: #667066;
  --line: #56705d;
  --line-soft: #aebcaf;
  --card: #fbfaf6;
  --accent: #2e5639;
  --accent-soft: #dce6dc;
  --formal: #e8e2d7;
  --admin: #dfe5eb;
  --shadow: none;
  --shadow-hover: 0 3px 10px rgba(20, 30, 20, .1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Frutiger', Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button, a { font: inherit; }

.canvas-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
  cursor: default;
  user-select: none;
  touch-action: none;
}

.canvas-shell.pan-ready { cursor: grab; }
.canvas-shell.panning { cursor: grabbing; }

.canvas-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: 0 0;
}

/*
---------------
-- CANVAS UI --
---------------
*/
.canvas-nav,
.canvas-help,
.zoom-controls {
  position: fixed;
  z-index: 100;
  border: 1px solid rgba(201, 206, 197, .95);
  background: rgba(251, 250, 246, .94);
  box-shadow: none;
}

.canvas-nav {
  top: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 10px 8px 12px;
  border-radius: 5px;
}

.back-link {
  color: var(--accent);
  text-decoration: none;
  font-size: .83rem;
  font-weight: 700;
}

.jump-links {
  display: flex;
  gap: 5px;
}

.jump-links button,
.zoom-controls button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.jump-links button {
  padding: 6px 8px;
  border-radius: 7px;
  font-size: .76rem;
}

.jump-links button:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.canvas-help {
  left: 18px;
  bottom: 18px;
  top: auto;
  right: auto;
  display: grid;
  gap: 2px;
  padding: 10px 13px;
  border-radius: 5px;
  color: var(--muted);
  font-size: .72rem;
}

.canvas-help strong {
  color: var(--accent);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.touch-help {
  display: none;
}

.canvas-info {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 120;
}

.info-trigger {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(201, 206, 197, .95);
  border-radius: 50%;
  background: rgba(251, 250, 246, .96);
  box-shadow: none;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
  user-select: none;
  touch-action: manipulation;
}

.info-trigger::-webkit-details-marker {
  display: none;
}

.info-icon {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  font-family: Georgia, serif;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.info-popover {
  position: absolute;
  top: 36px;
  right: 0;
  width: 320px;
  min-height: 74px;
  max-width: calc(100vw - 36px);
  padding: 16px 18px;
  border: 1px solid rgba(201, 206, 197, .95);
  border-radius: 5px;
  background: rgba(251, 250, 246, .97);
  box-shadow: none;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.5;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 140ms ease, transform 140ms ease, visibility 140ms ease;
}

.info-popover p {
  margin: 0;
}

.canvas-info:hover .info-popover,
.canvas-info:focus-within .info-popover,
.canvas-info[open] .info-popover {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

kbd {
  padding: 1px 5px;
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  background: white;
  font-family: inherit;
  font-size: .68rem;
}

.zoom-controls {
  right: 18px;
  bottom: 18px;
  display: grid;
  overflow: hidden;
  border-radius: 12px;
}

.zoom-controls button {
  width: 40px;
  height: 38px;
  font-size: 1.1rem;
  border-bottom: 1px solid var(--line-soft);
}

.zoom-controls button:last-child { border-bottom: 0; }
.zoom-controls button:hover { background: var(--accent-soft); color: var(--accent); }

/*
--------------------
-- DIAGRAM CANVAS --
--------------------
*/
.world {
  position: absolute;
  left: 0;
  top: 0;
  width: 6200px;
  height: 5050px;
  transform-origin: 0 0;
  will-change: transform;
}

.connectors {
  position: absolute;
  inset: 0;
  width: 6200px;
  height: 5050px;
  overflow: visible;
  z-index: 2;
  pointer-events: none;
}

/*
---------------------------
-- CONNECTORS AND LABELS --
---------------------------
*/
.connectors path.relationship {
  fill: none;
  stroke: var(--line);
  stroke-width: 4;
  vector-effect: non-scaling-stroke;
}

.connectors path.relationship.arrowed {
  marker-end: url(#arrowHead);
}

.connectors path.relationship.dashed {
  stroke-dasharray: 9 8;
  stroke-width: 3;
}

.connectors marker path {
  fill: var(--line);
}

.edge-label text {
  fill: #3f5144;
  font-size: 16px;
  font-weight: 600;
  dominant-baseline: middle;
  text-anchor: middle;
}

.edge-label {
  pointer-events: none;
}

.edge-label rect {
  fill: rgba(242, 240, 233, .97);
  stroke: rgba(174, 188, 175, .8);
  stroke-width: 1;
  rx: 6;
}

/*
----------------------
-- PANELS AND NODES --
----------------------
*/
.level-panel {
  position: absolute;
  z-index: 0;
  left: 0;
  top: 0;
  width: 100px;
  height: 100px;
  border: 2px solid rgba(86, 112, 93, .25);
  border-radius: 30px;
  background: rgba(251, 250, 246, .42);
  box-shadow: 0 20px 70px rgba(20,30,20,.05);
  pointer-events: none;
  opacity: 0;
}

.level-panel.auto-sized {
  opacity: 1;
}

.panel-level {
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .075em;
  text-transform: uppercase;
  white-space: nowrap;
}

.node,
.branch-title,
.subbranch-title,
.junction {
  position: absolute;
  left: var(--x);
  top: var(--y);
  z-index: 5;
}

.node {
  width: var(--w, 470px);
  min-height: 150px;
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 16px;
  align-items: center;
  padding: 16px;
  border: 1px solid #c5ccc4;
  border-radius: 15px;
  background: rgba(251, 250, 246, .98);
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow);
  user-select: none;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.node:hover,
.node:focus-visible {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: var(--shadow-hover);
  outline: none;
}

.node.smaller {
  width: 430px;
  min-height: 145px;
}

.node.major-node {
  min-height: 160px;
  grid-template-columns: 100px 1fr;
  padding: 20px;
}

.node.state-constitution {
  min-height: 130px;
}

.node.formal-node .node-image { background: var(--formal); }
.node.admin-node .node-image { background: var(--admin); }

.executive-council-node {
  width: 650px;
  min-height: 190px;
  grid-template-columns: 96px 1fr;
  padding: 20px;
}

.executive-council-node .node-image {
  width: 96px;
  height: 96px;
}

.court-node {
  width: 470px;
  min-height: 150px;
}

.junction.routing-junction {
  width: 8px;
  height: 8px;
  border-width: 2px;
}

.node-image {
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: var(--accent-soft);
}

.major-node .node-image {
  width: 100px;
  height: 100px;
}

.node-image img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.node-tag {
  display: inline-block;
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.node h2,
.node h3 {
  margin: 0 0 5px;
  line-height: 1.05;
  letter-spacing: -.03em;
}

.node h2 { font-size: 25px; }
.node h3 { font-size: 19px; }

.node p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

.branch-title,
.subbranch-title {
  display: grid;
  place-items: center;
  border: 1px solid #b9c4ba;
  background: rgba(251, 250, 246, .98);
  box-shadow: var(--shadow);
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
}

.branch-title {
  width: 520px;
  height: 64px;
  border-radius: 18px;
  font-size: 15px;
}

.subbranch-title {
  width: 400px;
  height: 52px;
  border-radius: 14px;
  font-size: 13px;
}

.junction {
  width: 12px;
  height: 12px;
  border: 3px solid var(--line);
  border-radius: 50%;
  background: var(--bg);
  z-index: 4;
}

.major-junction {
  width: 14px;
  height: 14px;
  border-width: 4px;
}

.federalism-link {
  position: absolute;
  left: 3000px;
  top: 1645px;
  z-index: 6;
  width: 1800px;
  min-height: 86px;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 16px;
  row-gap: 2px;
  align-items: center;
  padding: 14px 18px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: rgba(251, 250, 246, .97);
  box-shadow: var(--shadow);
}

.federalism-link span {
  grid-row: 1 / 3;
  align-self: stretch;
  display: grid;
  place-items: center;
  padding: 0 14px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.federalism-link strong {
  font-size: 15px;
  line-height: 1.2;
}

.federalism-link small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.canvas-shell.pan-ready .node,
.canvas-shell.panning .node,
.canvas-shell.pan-ready .branch-title,
.canvas-shell.panning .branch-title {
  pointer-events: none;
}

/*
----------------
-- RESPONSIVE --
----------------
*/
@media (max-width: 720px) {
  .canvas-nav {
    right: 60px;
    left: 12px;
    top: 12px;
    overflow-x: auto;
  }

  .canvas-info {
    top: 12px;
    right: 12px;
  }

  .canvas-help {
    left: 12px;
    bottom: 12px;
  }

  .zoom-controls {
    right: 12px;
    bottom: 12px;
  }
}

@media (hover: none), (pointer: coarse) {
  .desktop-help {
    display: none;
  }

  .touch-help {
    display: inline;
  }

  .canvas-info:hover .info-popover {
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
  }

  .canvas-info[open] .info-popover,
  .canvas-info:focus-within .info-popover {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
}

.federalism-junction {
  z-index: 5;
}

.local-act-node .node-image {
  background: #e9e4d9;
}

.local-branch-title {
  width: 520px;
}

#local-mayor,
#local-councillors,
#local-ceo,
#local-officers {
  min-height: 170px;
}

.branch-description,
.routing-point {
  position: absolute;
  left: var(--x);
  top: var(--y);
}

.branch-description {
  z-index: 5;
  width: 400px;
  min-height: 48px;
  display: grid;
  place-items: center;
  padding: 9px 14px;
  border: 1px solid rgba(185, 196, 186, .9);
  border-radius: 10px;
  background: rgba(251, 250, 246, .96);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 7px 18px rgba(20, 30, 20, .05);
}

.routing-point {
  z-index: 1;
  width: 1px;
  height: 1px;
  pointer-events: none;
  opacity: 0;
}

.node.division-card {
  width: 430px;
  min-height: 130px;
  display: block;
  padding: 16px 18px;
}

.node.division-card h3 {
  margin-bottom: 7px;
}
