:root {
  --fg: #0b0b0f;
  --fg-dim: rgba(11, 11, 15, 0.55);
  --glass: rgba(255, 255, 255, 0.28);
  --glass-border: rgba(0, 0, 0, 0.09);
  --glass-hi: rgba(255, 255, 255, 0.7);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --track: rgba(0, 0, 0, 0.12);
  --interdependent: #3b528b;
  --individual: #b5de2b;
  --accent: #21918c;
  --ease: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --theme: 0.8s var(--ease);
  --morph: 0.6s cubic-bezier(0.32, 0.72, 0, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Google Sans Flex', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
  color: var(--fg);
}

.app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #fff;
  --c-pad: clamp(20px, 3vw, 40px);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: border-radius 1.2s var(--ease);
}

.app.apocalyptic {
  border-radius: 10px;
  --fg: #fff;
  --fg-dim: rgba(255, 255, 255, 0.6);
  --glass: rgba(24, 24, 30, 0.34);
  --glass-border: rgba(255, 255, 255, 0.14);
  --glass-hi: rgba(255, 255, 255, 0.18);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  --track: rgba(255, 255, 255, 0.2);
  --interdependent: #7f9bff;
}

.apocalypse-overlay {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: #000;
  clip-path: circle(0% at var(--spawn-x, 50%) var(--spawn-y, 50%));
  transition: clip-path 1.2s var(--ease);
  will-change: clip-path;
}

.app.apocalyptic .apocalypse-overlay {
  clip-path: circle(150% at var(--spawn-x, 50%) var(--spawn-y, 50%));
}

#bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  touch-action: none;
}

/* ---------- Census (backdrop layer, under the canvas) ----------
   The Population History the boids swim over. Greys out while the HUD is collapsed. */

.census {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  color: var(--fg);
  transition: color var(--theme);
}

.census-body {
  position: absolute;
  bottom: calc(76px + env(safe-area-inset-bottom));
  left: var(--c-pad);
  width: min(310px, calc(100% - 2 * var(--c-pad)));
  transition: bottom var(--morph);
}

/* Population History: drawn by hud.js, with the counts labelled at the line ends. */
.history {
  display: block;
  width: 100%;
  height: 130px;
}

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  color: var(--fg);
  transition: color var(--theme);
}

.hud>* {
  pointer-events: auto;
}

.glass {
  background: var(--glass);
  backdrop-filter: blur(6px) saturate(170%);
  -webkit-backdrop-filter: blur(6px) saturate(170%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow), inset 0 1px 0 var(--glass-hi);
  transition: background var(--theme), border-color var(--theme), box-shadow var(--theme);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

/* Dock: one glass surface. hud.js sets its width/height so it can morph into
   the pill; only the surface animates, the contents cross-fade. */

.dock {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  translate: -50% 0;
  overflow: hidden;
  border-radius: 22px;
  transition: width var(--morph), height var(--morph), border-radius var(--morph),
    left var(--morph), translate var(--morph), background var(--theme), border-color var(--theme), box-shadow var(--theme);
}

.dock.measuring,
.dock.measuring * {
  transition: none !important;
}

.dock-full {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--full-w, max-content);
  translate: -50% -50%;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px 5px 14px;
  transition: opacity 0.25s var(--ease-out) 0.2s;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-right: 8px;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s infinite;
}

.app.apocalyptic .pulse {
  background: #fff;
  box-shadow: 0 0 14px #fff;
  animation-duration: 1.2s;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 0.4;
  }

  50% {
    opacity: 1;
  }
}

.sep {
  width: 1px;
  height: 20px;
  background: var(--glass-border);
  margin: 0 2px;
  flex: none;
}

.break {
  display: none;
}

.btn {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.25s, transform 0.25s var(--ease-out);
}

.btn:hover {
  background: var(--track);
}

.btn:active {
  transform: scale(0.94);
}

.btn svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn .i-play {
  display: none;
}

.btn[aria-pressed="true"] .i-play {
  display: block;
}

.btn[aria-pressed="true"] .i-pause {
  display: none;
}

.speed {
  min-width: 44px;
  font-variant-numeric: tabular-nums;
}

.cap-control {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
}

.cap-control output {
  font-size: 13px;
  font-weight: 500;
  min-width: 3ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  width: 104px;
  height: 36px;
  cursor: pointer;
}

input[type=range]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: var(--track);
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6.5px;
  border-radius: 50%;
  background: var(--fg);
  border: none;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s var(--ease-out), background var(--theme);
}

input[type=range]:active::-webkit-slider-thumb {
  transform: scale(1.3);
}

input[type=range]::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: var(--track);
}

input[type=range]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: none;
  background: var(--fg);
}

.switch {
  height: 36px;
  padding: 0 10px;
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.switch:hover {
  background: var(--track);
}

.switch .knob {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 10px;
  background: var(--track);
  transition: background 0.4s;
  flex: none;
}

.switch .knob::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--fg);
  transition: transform 0.4s var(--ease-out), background var(--theme);
}

.switch[aria-checked="true"] .knob::after {
  transform: translateX(14px);
}

.switch[aria-checked="true"] .knob {
  background: rgba(255, 255, 255, 0.35);
}

.portfolio {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 10px;
  border-radius: 18px;
  font-size: 13px;
  font-weight: 500;
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
  flex: none;
  opacity: 0.85;
  transition: opacity 0.3s, background 0.25s;
}

.portfolio:hover {
  opacity: 1;
  background: var(--track);
}

.portfolio svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.4s var(--ease-out);
}

.portfolio:hover svg {
  transform: rotate(-45deg);
}

/* Collapsed: the dock surface shrinks to the pill; contents cross-fade. */

.pill {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease-out);
}

.pill-chevron {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.6;
}

.hud.collapsed .dock {
  border-radius: 20px;
}

.hud.collapsed .dock-full {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s var(--ease-out);
}

.hud.collapsed .pill {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.3s var(--ease-out) 0.2s;
}

.hud.collapsed .pill:hover {
  background: var(--track);
}

/* ---------- Responsive ---------- */

.hud.collapsed .dock {
  left: var(--c-pad);
  translate: 0 0;
}

/* Wide screens: the Census takes the left quarter of the bottom band and the Dock
   sits right beside it, growing rightwards and collapsing back to the left. */
@media (min-width: 1101px) {
  .census-body {
    bottom: calc(16px + env(safe-area-inset-bottom));
    width: calc(25% - var(--c-pad));
  }

  .dock,
  .hud.collapsed .dock {
    left: calc(25% + 8px);
    translate: 0 0;
  }
}

/* Stacked layouts: when the Dock folds to the pill, the Census drops down to sit just above it. */
@media (max-width: 1100px) {
  .app.hud-collapsed .census-body {
    bottom: calc(66px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 920px) {
  .census-body {
    bottom: calc(112px + env(safe-area-inset-bottom));
  }

  .dock-full {
    flex-wrap: wrap;
    justify-content: center;
    padding: 6px 8px;
    row-gap: 2px;
  }

  .sep {
    display: none;
  }

  /* Row 1: brand, pause, reset, speed, fold. Row 2: cap, apocalyptic, link. */
  .brand {
    order: 0;
    flex: 1 1 auto;
    padding: 0 4px 0 6px;
  }

  .fold {
    order: 5;
  }

  .break {
    display: block;
    order: 6;
    flex-basis: 100%;
    height: 0;
  }

  .cap-control {
    order: 10;
    flex: 1 1 120px;
    padding: 0 4px;
  }

  .switch {
    order: 11;
  }

  .portfolio {
    order: 12;
  }

  input[type=range] {
    flex: 1 1 auto;
    width: 100%;
    min-width: 60px;
  }
}

@media (max-width: 760px) {
  .app {
    --c-pad: 16px;
  }

  .portfolio span {
    display: none;
  }

  .dock .speed {
    min-width: 36px;
  }

  .switch {
    padding: 0 6px;
    gap: 8px;
  }

  .portfolio {
    padding: 0 8px;
  }
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
