/* ─── Reset & Base ─── */
body, html {
  margin: 0;
}
html {
  overflow-x: clip;
}
body, html, .wealth-wrapper-outer, .wealth-row {
  min-height: 100%;
}

/* ─── Title Screen ─── */
.title-screen {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  position: relative;
}
h1 {
  text-align: center;
  font-size: 60px;
  line-height: 0.9;
  width: 100%;
  margin-top: 100px;
}
.inspired-by {
  position: absolute;
  bottom: 16px;
  right: 1em;
  font-size: 12px;
  color: #00000055;
  margin: 0;
}
.inspired-by a {
  color: inherit;
  text-decoration: underline;
}
.scroll-this-way {
  width: 165px;
  height: 360px;
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 48px;
  font-size: 30px;
  color: #00000033;
  background-image: url(img/down.svg);
  background-repeat: no-repeat;
  background-size: 50%;
  background-position: 50px 50px;
  animation: bouncy-arrow 3s infinite;
}
@keyframes bouncy-arrow {
  0%   { background-position: 50px 50px; }
  20%  { background-position: 50px 50px; }
  25%  { background-position: 50px 70px; }
  30%  { background-position: 50px 45px; }
  35%  { background-position: 50px 70px; }
  40%  { background-position: 50px 50px; }
  100% { background-position: 50px 50px; }
}

/* ─── Layout ─── */
.wealth-wrapper-outer {
  font-family: sans-serif;
  overflow: visible;
  display: block;
}
.wealth-row {
  display: flex;
  flex-direction: column;
}
.wealth-wrapper {
  margin: 3em 1em;
}

/* ─── Arrow ─── */
.arrow {
  margin-top: -7.5px;
  margin-left: 5px;
}

/* ─── Wealth Bars ─── */
.wealth {
  background-color: black;
  align-items: center;
  display: flex;
  flex-direction: column;
}
.title {
  margin-bottom: 5px;
}
.wealth-title {
  align-self: flex-start;
  margin-bottom: 5px;
  margin-top: 0;
  color: black;
  background: transparent;
  box-sizing: border-box;
}
.wealth > .wealth-title {
  flex-basis: auto;
  padding: 10px;
}
.billion .wealth > .wealth-title {
  flex-basis: auto;
  position: static;
}
.wealth-header {
  position: sticky;
  top: 0;
  z-index: 3;
  align-self: flex-start;
  width: calc(100% - 90px);
}
.wealth-header .wealth-title {
  padding-left: 4px;
}

/* ─── Calibration Bars ─── */
.one-thousand {
  width: 1px;
  height: 1px;
  margin-top: 5px;
}
.median {
  height: 200px;
  width: 100%;
}
.median .wealth {
  width: 7.94px;
  height: 7.94px;
}
.million {
  height: 200px;
  width: 100%;
}
.million .wealth {
  width: 33.62px;
  height: 33.62px;
  background-color: #4CAF50;
}
.billion .wealth {
  height: var(--billion-h, 2000px);
  width: var(--bar-width-billion, 500px);
  background-color: #03A9F4;
}
.richest .wealth {
  height: var(--richest-h);
  width: var(--bar-width, 500px);
  background-color: orange;
}
.all-billionaires .wealth {
  margin-top: 100px;
  height: var(--all-billionaires-h);
  width: var(--bar-width, 500px);
  background-color: #03A9F4;
}

/* ─── Ruler & Scale Key ─── */
.ruler {
  background-image: url('img/ruler-vert.svg');
  background-repeat: repeat-y;
  background-position: right 0;
  background-size: 30px 160px;
}
.key {
  position: sticky;
  top: 0;
  align-self: flex-end;
  margin-right: 35px;
  margin-left: 0;
  width: 25px;
  height: 160px;
  flex-shrink: 0;
  background: url(img/scale-vert.svg) no-repeat right center;
  background-size: 9px 160px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
}
.key > span {
  display: inline-block;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 11px;
  white-space: nowrap;
  padding: 1px 0;
}
.richest .key > span {
  background-color: orange;
}
.counter {
  color: black;
  padding: 5px;
  min-width: 140px;
  background: transparent;
}

/* ─── Infoboxes (comparison items inside bars) ─── */
.infobox {
  z-index: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  content-visibility: auto;
  contain-intrinsic-size: auto 100vh;
}
.infobox .title,
.infobox .comparison-rect-wrapper {
  font-weight: normal;
  line-height: 1.4;
  width: 75vw;
  max-width: 600px;
  text-align: center;
  margin-left: auto;
  margin-right: auto;
}
.infobox ul {
  text-align: left;
  display: inline-block;
  margin: 0.5em auto;
}

/* ─── Sticky centering for infobox content ─── */
.text-infobox .title,
.infobox .comparison-rect-wrapper:not(.comparison-rect-large) {
  position: sticky;
  top: 50%;
  transform: translateY(-50%);
  margin-left: auto;
  margin-right: auto;
  margin-top: 25vh;
  margin-bottom: 25vh;
}
.cause-card,
.summary-card,
.comparison-image-wrapper {
  position: sticky;
  top: 50%;
  transform: translateY(-50%);
}

/* ─── Comparison Rectangles ─── */
.infobox .comparison-rect-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.comparison-rect {
  margin-top: 8px;
}
.comparison-rect-label {
  color: inherit;
}
.comparison-rect-medium .comparison-rect {
  margin-top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.comparison-rect-medium .comparison-rect-label {
  text-align: center;
}
.comparison-rect-large {
  width: 90%;
  max-width: none;
  margin-left: auto;
  margin-right: auto;
}
.comparison-rect-large .comparison-rect {
  margin-top: 0;
}
.comparison-rect-large .comparison-rect-label {
  position: sticky;
  top: 50%;
  transform: translateY(-50%);
  display: block;
  text-align: center;
  z-index: 1;
  margin-top: 25vh;
  margin-bottom: 25vh;
}

/* ─── Bar Segments ─── */
.bar-segment {
  display: block;
}
.all-billionaires .wealth-header,
.all-billionaires .key {
  z-index: 3;
}
.all-billionaires .infobox {
  height: auto;
  min-height: 100vh;
}

/* ─── Image Comparisons ─── */
.comparison-image-wrapper {
  width: 75vw;
  max-width: 700px;
  text-align: center;
}
.comparison-image-wrapper .title {
  margin-bottom: 12px;
}
.comparison-image {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

/* ─── Cause Cards ─── */
.cause-card {
  width: 75vw;
  max-width: 560px;
}
.cause-pie {
  position: relative;
  display: inline-block;
  margin-bottom: 12px;
}
.cause-pie .piechart-outer {
  width: 120px;
  height: 120px;
  transform: rotate(-38deg);
  background: yellowgreen;
  border-radius: 50%;
}
.cause-pie .piechart-inner {
  fill: yellowgreen;
  stroke: #655;
  stroke-width: 32;
}
.pie-label {
  position: absolute;
  left: 130px;
  top: 42px;
  font-size: 20px;
  font-weight: bold;
  white-space: nowrap;
}
.cause-title {
  margin: 8px 0 4px;
  font-size: 22px;
}
.cause-cost {
  font-size: 15px;
  color: #555;
  margin-bottom: 8px;
}
.cause-desc {
  line-height: 1.5;
  margin-bottom: 10px;
}
.cause-desc a {
  color: #1565C0;
}
.cause-deaths {
  background: #fff3f3;
  border-left: 4px solid #d32f2f;
  padding: 8px 12px;
  margin: 10px 0;
  font-size: 14px;
}
.pocket-change {
  background: #f3f8ff;
  border-left: 4px solid #1565C0;
  padding: 8px 12px;
  margin: 10px 0;
  font-size: 14px;
  font-style: italic;
}
.cause-source {
  font-size: 12px;
  color: #888;
  margin-top: 8px;
}
.cause-source a {
  color: #888;
}

/* ─── Summary Cards ─── */
.summary-card {
  width: 75vw;
  max-width: 560px;
}
.side-by-side-chart {
  margin: 16px 0;
}
.bar-row {
  display: flex;
  align-items: center;
  margin: 4px 0;
  font-size: 13px;
}
.bar-label {
  width: 160px;
  flex-shrink: 0;
  text-align: right;
  padding-right: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-track {
  flex: 1;
  height: 18px;
  background: #e8e8e8;
  border-radius: 3px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: #03A9F4;
  border-radius: 3px;
  min-width: 2px;
}
.bar-amount {
  width: 70px;
  flex-shrink: 0;
  padding-left: 8px;
  font-weight: bold;
  white-space: nowrap;
}
.summary-total {
  margin: 12px 0;
  font-size: 16px;
  padding: 8px 0;
  border-top: 2px solid #333;
}
.summary-pie {
  margin-top: 12px;
}
.summary-pie .piechart-outer {
  width: 180px;
  height: 180px;
}

/* ─── Death Ticker ─── */
.death-ticker {
  position: fixed;
  bottom: 12px;
  right: 12px;
  z-index: 100;
  background: rgba(30, 30, 30, 0.92);
  color: #fff;
  padding: 12px 16px 32px 16px;
  border-radius: 8px;
  font-family: sans-serif;
  font-size: 13px;
  max-width: 280px;
  max-height: calc(80vh - 40px);
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  backdrop-filter: blur(6px);
}
.death-ticker-close {
  position: absolute;
  top: 6px;
  right: 10px;
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  z-index: 101;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.death-ticker-close:hover {
  opacity: 1;
}
.death-ticker-reopen {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 101;
  background: #222;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 22px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
  transition: opacity 0.2s;
}
.death-ticker-reopen:hover {
  opacity: 1;
}
.next-message-btn {
  position: fixed;
  bottom: 16px;
  left: calc(max(16px, env(safe-area-inset-left)) + 14px);
  z-index: 101;
  background: #222;
  color: #fff;
  border: none;
  border-radius: 999px;
  height: 44px;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  cursor: pointer;
  opacity: 0.88;
  transition: opacity 0.2s;
}
.next-message-btn:hover {
  opacity: 1;
}
.next-message-btn:disabled,
.next-message-btn.is-scrolling {
  opacity: 0.45;
  cursor: default;
}
.death-ticker-label {
  display: block;
  font-size: 11px;
  color: #aaa;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.ticker-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2px 0;
}
.ticker-count {
  font-weight: bold;
  font-size: 15px;
  color: #ff6b6b;
  margin-right: 8px;
  font-variant-numeric: tabular-nums;
}
.ticker-label {
  color: #ccc;
}
.ticker-total {
  border-top: 1px solid rgba(255,255,255,0.2);
  margin-top: 4px;
  padding-top: 6px;
  font-weight: bold;
}
.ticker-total .ticker-count {
  font-size: 17px;
  color: #ff4444;
}
.ticker-total .ticker-label {
  color: #fff;
}
.ticker-group + .ticker-group {
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.ticker-group-total .ticker-label {
  color: #eee;
  font-weight: bold;
}
.ticker-count-group {
  color: #ff8c8c;
}
.ticker-group-causes {
  color: #9fb0bc;
  font-size: 10px;
  line-height: 1.3;
  margin: 1px 0 0 0;
  text-align: right;
}
.ticker-item {
  padding-left: 8px;
}
.ticker-item .ticker-count {
  font-size: 12px;
  color: #cc5555;
}
.ticker-item .ticker-label {
  font-size: 11px;
  color: #999;
}

/* ─── Mobile ─── */
@media (max-width: 450px) {
  h1 {
    font-size: 40px;
  }
  h3 {
    font-size: 14px;
  }
  .wealth-title {
    font-size: 19px;
  }

  .bar-label {
    width: 90px;
    font-size: 11px;
  }
  .bar-amount {
    width: 55px;
    font-size: 11px;
  }
  .pie-label {
    left: 100px;
    top: 35px;
    font-size: 16px;
  }
  .cause-pie .piechart-outer {
    width: 90px;
    height: 90px;
  }

  /* Death ticker */
  .death-ticker {
    bottom: 4px;
    right: 4px;
    font-size: 11px;
    max-width: 200px;
  }
  .next-message-btn {
    bottom: 8px;
    left: calc(max(8px, env(safe-area-inset-left)) + 10px);
    height: 38px;
    padding: 0 12px;
    font-size: 12px;
  }
  .ticker-count {
    font-size: 13px;
  }
}

/* ─── Desktop ─── */
@media (min-width: 1000px) {
  .infobox .title,
  .infobox .comparison-rect-wrapper {
    max-width: 750px;
  }
  .text-infobox .title {
    max-width: 550px;
  }
}