:root {
  --bg-top: #f6f1e8;
  --bg-bottom: #dbe7f3;
  --panel: rgba(16, 24, 32, 0.78);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #f6f7fb;
  --muted: rgba(246, 247, 251, 0.75);
  --canvas: rgba(255, 255, 255, 0.58);
  --canvas-border: rgba(18, 49, 78, 0.12);
  --node: rgba(255, 255, 255, 0.93);
  --node-border: rgba(13, 51, 85, 0.16);
  --node-shadow: 0 26px 60px rgba(14, 32, 47, 0.12);
  --federal: #0b7285;
  --state: #c05c2e;
  --local: #537d36;
  --accent: #003049;
  --line-glow: rgba(0, 119, 182, 0.25);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  font-family: "Trebuchet MS", "Gill Sans", sans-serif;
  color: #101820;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.85), transparent 30%),
    linear-gradient(135deg, var(--bg-top), var(--bg-bottom));
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.22) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.22) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(circle at center, black 55%, transparent 100%);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 24px;
  height: 100vh;
  padding: 24px;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 22px 20px;
  border-radius: 28px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(18px);
  min-height: 0;
  overflow: auto;
  scrollbar-width: none;
}

.control-panel::-webkit-scrollbar {
  display: none;
}

.eyebrow,
.stage-kicker {
  margin: 0;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.75rem;
  color: var(--muted);
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-family: "Trebuchet MS", "Gill Sans", sans-serif;
  font-size: 1.96rem;
  font-weight: 700;
  letter-spacing: 0;
}

h2 {
  font-family: Baskerville, "Palatino Linotype", serif;
  font-size: clamp(2rem, 3vw, 3.2rem);
  font-weight: 400;
  color: #11263a;
}

.intro,
.stage-note {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.55;
}

.tax-form {
  display: grid;
  gap: 10px;
}

.tax-form label {
  font-size: 0.84rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.tax-form input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font: inherit;
}

.tax-form button {
  margin-top: 6px;
  padding: 16px 18px;
  border: 0;
  border-radius: 18px;
  font: inherit;
  font-weight: 700;
  color: #f6f7fb;
  background: linear-gradient(135deg, #1e6e3f, #275d38);
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.form-note {
  margin: -4px 0 0;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--muted);
}

.tax-form button:hover,
.tax-form button:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(30, 110, 63, 0.26);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-card {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-card strong {
  font-size: 1.35rem;
}

.legend {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  color: var(--muted);
}

.legend-note {
  margin-top: 6px;
  font-size: 0.78rem;
  line-height: 1.35;
  color: rgba(246, 247, 251, 0.7);
}

.panel-divider {
  width: 100%;
  height: 1px;
  margin-top: 4px;
  background: rgba(255, 255, 255, 0.14);
}

.top-items-panel {
  display: grid;
  gap: 10px;
  padding-bottom: 4px;
}

.top-items-title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(246, 247, 251, 0.76);
}

.top-items-list {
  display: grid;
  gap: 8px;
}

.top-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.top-item-name {
  font-size: 0.84rem;
  line-height: 1.35;
  color: rgba(246, 247, 251, 0.92);
}

.top-item-metrics {
  text-align: right;
  white-space: nowrap;
}

.top-item-amount {
  display: block;
  font-size: 0.83rem;
  font-weight: 700;
  color: rgba(246, 247, 251, 0.96);
}

.top-item-share {
  display: block;
  font-size: 0.76rem;
  color: rgba(246, 247, 251, 0.66);
}

.legend-chip {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 10px;
  border-radius: 999px;
}

.legend-chip.federal {
  background: var(--federal);
}

.legend-chip.state {
  background: var(--state);
}

.legend-chip.local {
  background: var(--local);
}

.legend-chip.missing {
  background: #9aa3ad;
}

.chart-stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  gap: 14px;
}

.stage-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 14px 18px;
  border-radius: 24px;
  border: 1px solid rgba(17, 38, 58, 0.12);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 14px 34px rgba(8, 37, 63, 0.08);
  backdrop-filter: blur(10px);
  user-select: none;
  -webkit-user-select: none;
}

.toolbar-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.focus-readout {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 18px;
  flex: 1;
  min-width: 0;
  color: #234057;
}

.focus-name {
  font-size: 1.08rem;
  line-height: 1.2;
  font-weight: 700;
  text-align: center;
  justify-self: center;
}

.focus-metrics {
  display: grid;
  justify-items: end;
  min-width: 160px;
}

.focus-amount,
.focus-share {
  font-size: 0.96rem;
  line-height: 1.2;
  font-weight: 700;
  text-align: right;
}

.toolbar-group button {
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid rgba(17, 38, 58, 0.12);
  background: rgba(255, 255, 255, 0.72);
  color: #11263a;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background-color 180ms ease;
}

.toolbar-group button:hover,
.toolbar-group button:focus-visible {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 24px rgba(8, 37, 63, 0.1);
}

.chart-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  scrollbar-width: none;
  border-radius: 34px;
  border: 1px solid var(--canvas-border);
  margin-top: 2px;
  cursor: grab;
  touch-action: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0.4)),
    radial-gradient(circle at top center, rgba(181, 215, 255, 0.35), transparent 45%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 25px 50px rgba(8, 37, 63, 0.08);
}

.chart-viewport::-webkit-scrollbar {
  display: none;
}

.chart-viewport.is-panning {
  cursor: grabbing;
}

.chart-world {
  position: relative;
  min-width: 1800px;
  min-height: 1500px;
}

.chart-content {
  position: relative;
  transform-origin: top left;
}

.connector-layer,
.node-layer {
  position: absolute;
  inset: 0;
}

.connector-layer {
  z-index: 1;
  pointer-events: none;
}

.node-layer {
  z-index: 2;
}

.node-card {
  position: absolute;
  width: 250px;
  padding: 18px 18px 16px;
  border: 1px solid var(--node-border);
  border-radius: 22px;
  text-align: left;
  background: var(--node);
  box-shadow: var(--node-shadow);
  cursor: pointer;
  transition: transform 220ms ease, box-shadow 220ms ease, border-color 220ms ease;
  transform-origin: center;
  animation: rise-in 420ms ease both;
  overflow: visible;
}

.node-projection-mark {
  position: absolute;
  top: 10px;
  right: 12px;
  display: none;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  color: #7b8791;
}

.node-card:hover,
.node-card:focus-visible {
  transform: translateY(-4px);
  box-shadow: 0 30px 60px rgba(14, 32, 47, 0.18);
}

.node-card.active {
  transform: scale(1.03);
  border-color: rgba(0, 48, 73, 0.26);
  box-shadow: 0 28px 60px rgba(0, 48, 73, 0.2);
}

.node-card[data-tooltip]:hover::after,
.node-card[data-tooltip]:focus-visible::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 14px);
  transform: translateX(-50%);
  width: 260px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(12, 24, 36, 0.94);
  color: #f4f7fb;
  font-size: 0.78rem;
  line-height: 1.45;
  font-weight: 500;
  text-align: left;
  box-shadow: 0 14px 28px rgba(8, 20, 32, 0.22);
  z-index: 20;
  pointer-events: none;
}

.node-card[data-tooltip]:hover::before,
.node-card[data-tooltip]:focus-visible::before {
  box-shadow: none;
}

.node-card[data-tooltip]:hover .node-projection-mark,
.node-card[data-tooltip]:focus-visible .node-projection-mark {
  z-index: 21;
}

.node-card[data-tooltip]:hover::selection,
.node-card[data-tooltip]:focus-visible::selection {
  background: transparent;
}

.node-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 8px;
  border-radius: 22px 0 0 22px;
  background: var(--node-accent, var(--accent));
}

.node-type,
.node-share,
.node-note {
  display: block;
}

.node-type {
  margin-bottom: 10px;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #506576;
}

.node-title {
  display: block;
  margin-bottom: 12px;
  font-size: 1.05rem;
  line-height: 1.4;
  color: #08263d;
}

.node-amount {
  display: block;
  margin-bottom: 6px;
  font-size: 1.4rem;
  font-weight: 700;
  color: #0b2237;
}

.node-share {
  font-size: 0.88rem;
  color: #547080;
}

.node-note {
  margin-top: 8px;
  font-size: 0.77rem;
  line-height: 1.35;
  color: #708695;
}

.node-card.missing {
  background: rgba(236, 239, 243, 0.96);
  border-color: rgba(118, 129, 140, 0.26);
}

.node-card.missing .node-projection-mark {
  display: block;
}

.node-card.missing::before {
  background: #9aa3ad;
}

.node-card.missing .node-title,
.node-card.missing .node-amount {
  color: #5b6772;
}

.node-card.missing .node-type,
.node-card.missing .node-share,
.node-card.missing .node-note {
  color: #7b8791;
}

.connector {
  fill: none;
  stroke: rgba(43, 66, 84, 0.32);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: none;
}

.connector.flow {
  stroke: rgba(20, 128, 193, 0.95);
  stroke-width: 4;
  stroke-dasharray: 8 7;
  stroke-linejoin: round;
  filter: none;
  animation: drift 1.8s linear infinite;
}

.connector.highlight {
  stroke: rgba(30, 76, 108, 0.44);
  stroke-width: 4;
}

@keyframes drift {
  from {
    stroke-dashoffset: 0;
  }
  to {
    stroke-dashoffset: -48;
  }
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: 100vh;
  }

  .stage-toolbar {
    flex-direction: column;
    align-items: start;
  }

  .focus-readout {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .focus-name {
    justify-self: start;
    text-align: left;
  }

  .focus-metrics {
    justify-items: start;
  }

  .focus-amount,
  .focus-share {
    text-align: left;
  }

  .chart-viewport {
    min-height: 0;
  }

  .chart-world {
    min-width: 1500px;
  }
}
