:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1f2630;
  --border: #2a323d;
  --text: #e6edf3;
  --text-dim: #9aa6b2;
  --accent: #58a6ff;
  --male: #58a6ff;
  --female: #f97583;
  --grid: #2a323d;
  --code: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font:
    15px/1.55 -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    "Yu Gothic UI",
    system-ui,
    sans-serif;
}

main {
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 20px 72px;
}

header {
  margin-bottom: 20px;
}

h1 {
  font-size: 28px;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  font-family: var(--code);
  font-size: 12.5px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.lede {
  margin: 0;
  color: var(--text-dim);
  max-width: 720px;
}

.lede strong {
  color: var(--text);
}

section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 14px;
}

/* ────────── controls ────────── */

.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.year-display {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.year-number {
  font-family: var(--code);
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.year-suffix {
  font-size: 16px;
  color: var(--text-dim);
}

.control-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

button#play-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 32px;
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
}

button#play-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

button#play-btn.playing {
  background: rgba(88, 166, 255, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}

input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
}

/* ────────── pyramid ────────── */

.pyramid-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.legend {
  display: flex;
  gap: 14px;
  font-size: 13px;
  color: var(--text-dim);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-item .dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.legend-male .dot {
  background: var(--male);
}

.legend-female .dot {
  background: var(--female);
}

.status {
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--code);
}

.status.loading {
  color: #d29922;
}

.status.ready {
  color: #57c98a;
}

.status.error {
  color: #f85149;
}

#pyramid {
  display: block;
  width: 100%;
  height: auto;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.bar-male,
.bar-female {
  transition:
    x 0.15s ease-out,
    width 0.15s ease-out;
}

.bar-male {
  fill: var(--male);
}

.bar-female {
  fill: var(--female);
}

.age-label {
  fill: var(--text-dim);
  font-family: var(--code);
  font-size: 10.5px;
  text-anchor: middle;
  user-select: none;
}

.value-label-left {
  fill: var(--text-dim);
  font-family: var(--code);
  font-size: 10px;
  text-anchor: end;
  user-select: none;
}

.value-label-right {
  fill: var(--text-dim);
  font-family: var(--code);
  font-size: 10px;
  text-anchor: start;
  user-select: none;
}

.gridline {
  stroke: var(--grid);
  stroke-width: 1;
}

.axis-label {
  fill: var(--text-dim);
  font-family: var(--code);
  font-size: 10px;
}

/* ────────── stats ────────── */

.stats-section {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 600px) {
  .stats-section {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.stat-value {
  font-family: var(--code);
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ────────── footer ────────── */

footer {
  margin-top: 24px;
  font-size: 12.5px;
  color: var(--text-dim);
}

footer p {
  margin: 4px 0;
}
