:root {
  --bg: #e8ece5;
  --surface: #f6f8f3;
  --ink: #17201b;
  --muted: #55635a;
  --rule: #cbd3c8;
  --accent: #2d6a4f;

  /* tank */
  --sky-top: #a9cde0;
  --sky-bottom: #dcebe9;
  --soil-top: #9b7550;
  --soil-deep: #43301f;
  --rock: #7a756d;
  --tunnel: #2b1e15;
  --chamber: #1a110b;
  --glow: #e0a458;
  --sun: #fff1b8;
  --snow: #f4f8fb;

  /* ants and jobs */
  --r0: #f5a623;
  --r1: #ef6a4c;
  --r2: #3fbf7f;
  --r3: #4a90e2;

  /* genes */
  --t0: #d98a00;
  --t1: #8c5a2b;
  --t2: #2f9e63;
  --t3: #3a7bd5;
  --t4: #a4489f;
  --t5: #1f9aa0;

  /* lineages */
  --l0: #2d6a4f;
  --l1: #c2410c;
  --l2: #6d4bd1;
  --l3: #0e7490;
  --l4: #b5179e;
  --l5: #8a6d00;

  /* chart series */
  --s-pop: #2d6a4f;
  --s-brood: #8a9a90;
  --s-food: #c2410c;

  /* chronicle */
  --k-raid: #d1432f;
  --k-flood: #3a7bd5;
  --k-queen: #8e5bd6;
  --k-famine: #c98a00;
  --k-nuptial: #2f9e63;
  --k-dig: #8c5a2b;
  --k-quiet: #7a756d;
  --k-founded: #2d6a4f;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121815;
    --surface: #1a231e;
    --ink: #e3ebe4;
    --muted: #93a398;
    --rule: #27322b;
    --accent: #6cc39a;

    --sky-top: #0e1c2b;
    --sky-bottom: #27414f;
    --soil-top: #6b4e35;
    --soil-deep: #261a11;
    --rock: #4f4a43;
    --tunnel: #1a110a;
    --chamber: #0d0805;
    --sun: #e8ecd0;
    --snow: #cfd9e2;

    --t0: #f2b84b;
    --t1: #c99a66;
    --t2: #6fcf8a;
    --t3: #6fb0ff;
    --t4: #d58be0;
    --t5: #6fc7c9;

    --l0: #6cc39a;
    --l1: #f08a55;
    --l2: #a58cf2;
    --l3: #58c4dd;
    --l4: #ee7fd6;
    --l5: #d9b43a;

    --s-pop: #6cc39a;
    --s-brood: #7d8d83;
    --s-food: #f08a55;

    --k-raid: #f06a55;
    --k-flood: #6fb0ff;
    --k-queen: #b38af0;
    --k-famine: #e5b04a;
    --k-nuptial: #6fcf8a;
    --k-dig: #c99a66;
    --k-quiet: #8a857d;
    --k-founded: #6cc39a;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0 16px 48px;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.55 "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

.top, main, footer { max-width: 1120px; margin-inline: auto; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  font-weight: 700;
  font-stretch: 78%;
  letter-spacing: -0.015em;
  line-height: 1;
}

h2 {
  margin: 0 0 12px;
  font-size: 1.25rem;
  font-weight: 650;
  font-stretch: 85%;
  letter-spacing: -0.005em;
  line-height: 1.2;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px 32px;
  padding: 28px 0 18px;
}

.sub { margin: 8px 0 0; color: var(--muted); max-width: 46ch; }

.clock { text-align: right; line-height: 1; }
.clock-label { display: block; color: var(--muted); font-size: 0.9rem; margin-bottom: 6px; }
#countdown {
  font-size: clamp(2rem, 5vw, 2.8rem);
  font-weight: 600;
  font-stretch: 78%;
  letter-spacing: 0.01em;
}

main { display: grid; gap: 40px; }

/* ---- the tank: the one loud thing on the page ---- */

.tank {
  position: relative;
  border-radius: 16px;
  padding: 10px;
  background: linear-gradient(160deg, #3a3f38, #1c211d);
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.18) inset, 0 18px 40px -22px rgb(10 20 14 / 0.6);
}

.tank canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: var(--sky-bottom);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.5), inset 0 0 40px rgb(0 0 0 / 0.35);
}

/* faint glass reflection */
.tank::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 8px;
  pointer-events: none;
  background: linear-gradient(115deg, rgb(255 255 255 / 0.1) 0 18%, transparent 18% 100%);
}

.hud {
  position: absolute;
  top: 22px;
  z-index: 1;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 999px;
  color: #f4f7f2;
  background: rgb(14 20 16 / 0.58);
  backdrop-filter: blur(6px);
  font-size: 0.95rem;
}
.hud-left { left: 22px; }
.hud-right { right: 22px; }
.hud strong { font-weight: 650; font-size: 1.05rem; }
.hud span { opacity: 0.85; }

/* ---- shared small parts ---- */

.bar {
  display: flex;
  height: 14px;
  border-radius: 7px;
  overflow: hidden;
  background: var(--rule);
  gap: 2px;
}
.bar > i { display: block; min-width: 3px; }

.legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  margin: 12px 0 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.legend li { display: flex; align-items: center; gap: 7px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend b { color: var(--ink); font-weight: 600; }

.note { margin: -6px 0 10px; color: var(--muted); font-size: 0.95rem; }

/* ---- vitals + charts ---- */

.cols { display: grid; gap: 40px; align-items: start; }
@media (min-width: 860px) {
  .cols { grid-template-columns: minmax(260px, 340px) 1fr; gap: 56px; }
}

.vitals h2:not(:first-child), .charts h2:not(:first-child) { margin-top: 36px; }

.ledger { margin: 0; display: grid; }
.vital { padding: 12px 0; border-bottom: 1px solid var(--rule); }
.vital:first-child { padding-top: 0; }
.vital dt { color: var(--muted); font-size: 0.95rem; }
.vital dd { margin: 0; display: grid; gap: 4px; }
.vital .num {
  font-size: 2.1rem;
  font-weight: 650;
  font-stretch: 78%;
  line-height: 1.1;
  letter-spacing: -0.01em;
}
.vital .detail { color: var(--muted); font-size: 0.92rem; }
.meter { height: 6px; border-radius: 3px; background: var(--rule); overflow: hidden; margin-top: 4px; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }

.lineages { list-style: none; margin: 14px 0 0; padding: 0; }
.lineages li {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 4px 10px;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
}
.lineages i { width: 12px; height: 12px; border-radius: 4px; align-self: center; }
.lineages .pop { font-weight: 600; }
.lineages .meta { grid-column: 2 / -1; color: var(--muted); font-size: 0.9rem; }

.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart .grid { stroke: var(--rule); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .cursor { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.55; }
.chart .empty { color: var(--muted); padding: 28px 0; }

.tip {
  position: absolute;
  top: 8px;
  z-index: 2;
  min-width: 150px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.88rem;
  line-height: 1.4;
  box-shadow: 0 6px 22px -8px rgb(0 0 0 / 0.35), 0 0 0 1px var(--rule);
  pointer-events: none;
}
.tip b { display: block; margin-bottom: 2px; }
.tip span { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* ---- chronicle ---- */

.events {
  list-style: none;
  margin: 0;
  padding: 0 0 0 6px;
  max-height: 420px;
  overflow: auto;
}
.events li {
  position: relative;
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 12px;
  padding: 10px 0 10px 22px;
  border-left: 2px solid var(--rule);
}
.events li::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 16px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--k, var(--k-quiet));
  box-shadow: 0 0 0 3px var(--bg);
}
.events .when { color: var(--muted); font-size: 0.92rem; }
.events .what { max-width: 62ch; }

footer { color: var(--muted); font-size: 0.92rem; padding-top: 40px; max-width: 1120px; }

@media (max-width: 600px) {
  .top { flex-direction: column; align-items: flex-start; }
  .clock { text-align: left; }
  .tank { padding: 6px; border-radius: 12px; }
  .hud { top: 12px; padding: 4px 10px; font-size: 0.85rem; }
  .hud-left { left: 12px; }
  .hud-right { right: 12px; }
  .events li { grid-template-columns: 1fr; gap: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
.hud[hidden] { display: none; }

.changes { margin: -16px 0 0; color: var(--muted); max-width: 70ch; }
.changes b { color: var(--ink); font-weight: 650; }
