/* Neural Ants — red and white, the way the flag is: full width bands of
   colour, one accent, and quiet patterns so nothing is ever flat. */

:root {
  --red: #b00300;
  --deep: #7d0200;
  --lift: #c9241f;      /* one step brighter, for rules drawn on red */
  --paper: #fbf7f0;
  --white: #ffffff;
  --ink: #241d19;
  --muted: #7b6f66;
  --line: #e8dccb;
  --sand: #fcdeb9;
  --sand-deep: #efe2d0;
  --cream: #f4ead9;

  --display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --text: "DM Sans", ui-sans-serif, -apple-system, "Segoe UI", Helvetica, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.65 var(--text);
}

/* a soft, even grain over everything, so the flat colour is not too flat */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  background: url("noise.svg");
  opacity: 0.55;
  pointer-events: none;
  z-index: 20;
}

h1, h2 { margin: 0; font-weight: 700; }
p { margin: 0; }
a { color: inherit; }

/* ---- the bands ---------------------------------------------------------- */

.band { width: 100%; }
.inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 38px 24px;
}
/* a thick sand rule wherever red meets paper */
.red {
  position: relative;
  overflow: hidden;
  background-color: var(--red);
  color: #fff;
  border-top: 8px solid var(--sand);
  border-bottom: 8px solid var(--sand);
}
header.red { border-top: none; }
.red .inner { position: relative; z-index: 1; }
.deep {
  background-color: var(--deep);
  color: rgba(255, 255, 255, 0.78);
}
.paper {
  background-color: var(--paper);
  background-image: url("dots.svg?v=9");
}

/* ---- the trails on the red, walked by the dashes ------------------------ */

.trails {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.trails path {
  animation: march 9s linear infinite; /* six dash periods, so it loops clean */
}
@keyframes march { to { stroke-dashoffset: -84; } }
@media (prefers-reduced-motion: reduce) { .trails path { animation: none; } }
/* dashed rules where two bands of the same colour meet */
.paper + .paper .inner { padding-top: 32px; border-top: 1px dashed var(--line); }
.edge .inner { padding-bottom: 48px; }

/* ---- masthead ----------------------------------------------------------- */

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  padding-top: 32px;
  padding-bottom: 32px;
}
h1 {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  font-family: var(--display);
  font-size: 44px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0;
}
.tag {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--sand);
}
.credit { text-align: right; }
.credit .who {
  display: block;
  margin-bottom: 3px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
}
.credit .names { font-family: var(--mono); font-size: 13.5px; color: var(--sand); }
.credit span.dot { padding: 0 2px; opacity: 0.5; }
/* both are underlined all the time; hovering only moves the colour */
.credit a {
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  transition: color 180ms ease;
}
.credit a:hover { color: #fff; }
.credit .era { font-size: 11.5px; color: rgba(252, 222, 185, 0.62); }

/* ---- the lede, with the lab beside it ---------------------------------- */

.lede-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}
.lede-row .lede { flex: 1 1 18em; margin-bottom: 0; max-width: 30em; font-size: 16px; }

/* the link to the lab: the site's own button, worn by an <a> */
.labgo { display: flex; align-items: center; justify-content: flex-end; gap: 14px; margin: 0 0 0 auto; text-align: right; }
.labgo .talks { display: flex; flex-direction: column; gap: 4px; }
.labgo .talk-note { font-size: 12px; color: var(--muted); }
.labgo .talk-links { display: flex; justify-content: flex-end; gap: 14px; font-size: 12px; }
.labgo a {
  display: inline-block;
  padding: 8px 14px;
  text-align: center;
  font: 700 14px var(--text);
  color: var(--deep);
  background: var(--sand);
  border: 1px solid var(--sand-deep);
  border-radius: 5px;
  text-decoration: none;
  box-shadow: 2px 2px 0 var(--sand-deep);
  transition: background 90ms linear, color 90ms linear, border-color 90ms linear;
}
.labgo a:hover { background: var(--red); border-color: var(--deep); color: #fff; box-shadow: 2px 2px 0 var(--deep); }
.labgo a:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--deep); }
.labgo a span { display: block; margin-top: 3px; font-size: 11.5px; font-weight: 400; opacity: 0.75; }
.labgo a.talk { display: inline; padding: 0; background: none; border: 0; box-shadow: none; font-size: 12px; font-weight: 400; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.labgo a.talk:hover { color: var(--red); background: none; box-shadow: none; }
.labgo a.talk:active { transform: none; }

.lede {
  max-width: 34em;
  margin-bottom: 28px;
  font-size: 18px;
  line-height: 1.6;
  color: var(--muted);
}

/* ---- the workbench ------------------------------------------------------ */

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 430px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}
@media (max-width: 760px) { .workbench { grid-template-columns: 1fr; } }

.head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding-bottom: 7px;
  border-bottom: 1px dashed var(--line);
}
h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}
.meter { display: flex; gap: 16px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.meter b { color: var(--red); }
.note { font-size: 12.5px; color: var(--muted); }

.field-wrap {
  position: relative;
  max-width: 430px;
  border-radius: 3px;
  outline: 1px solid var(--line);   /* a quiet frame, drawn without moving anything */
  outline-offset: 6px;
}
canvas {
  display: block;
  width: 100%;
  /* white, like the field the ants paint on: if the script ever fails to
     start, the empty canvas should look like a blank grid, not a dead screen */
  background: var(--white);
  border-radius: 3px;
  image-rendering: pixelated;
}
#stage { aspect-ratio: 1; cursor: crosshair; touch-action: none; }
.field-wrap.show-ghost #stage { cursor: none; }
.field-wrap, input[type="range"] { touch-action: none; }
#stage, .field-wrap { user-select: none; -webkit-user-select: none; }

#ghost {
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.9);
  background: rgba(176, 3, 0, 0.3);
  pointer-events: none;
  transform: translate(-50%, -50%);
  display: none;
}
.field-wrap.show-ghost #ghost { display: block; }

/* the origins: one faded dot per colony, only when asked for, draggable */
#origins { position: absolute; inset: 0; pointer-events: none; display: none; }
.field-wrap.show-origins #origins { display: block; }
.origin {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 1px rgba(36, 29, 25, 0.35);
  opacity: 0.45;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  transition: opacity 90ms linear;
}
.origin:hover, .origin.is-held { opacity: 0.9; cursor: grabbing; }
.origins-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
}
.origins-toggle input { accent-color: var(--red); margin: 0; }
.origins-toggle em { font-style: normal; opacity: 0.7; }

/* the zoom sits under the field it changes, not away in the controls */
.zoomer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  font-size: 12.5px;
  color: var(--muted);
}
.zoomer input { flex: 1; }
.zoomer b { font-family: var(--mono); color: var(--ink); min-width: 5.5em; }

#trouble {
  display: none;
  margin-top: 14px;
  padding: 8px;
  border-radius: 3px;
  background: var(--red);
  color: #fff;
  font-family: var(--mono);
  font-size: 11px;
  word-break: break-word;
}
#trouble.shown { display: block; }

/* ---- controls ----------------------------------------------------------- */

.panel {
  padding: 15px 16px 16px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 5px;
  box-shadow: 3px 3px 0 var(--sand-deep);
}
.panel h2 { margin-bottom: 14px; }
.row { display: block; margin-bottom: 13px; }
.row > span {
  display: block;
  margin-bottom: 5px;
  font-size: 12.5px;
  color: var(--muted);
}
.row b { color: var(--ink); font-family: var(--mono); }

input[type="range"] {
  width: 100%;
  height: 16px;
  appearance: none;
  background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 3px;
  background: var(--sand);
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--red);
  border: 2px solid var(--white);
  box-shadow: 1px 1px 0 var(--deep);
  cursor: grab;
}
input[type="range"]::-moz-range-track { height: 5px; border-radius: 3px; background: var(--sand); }
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--red); border: 2px solid var(--white); cursor: grab;
}

button {
  font: 500 12.5px var(--text);
  color: var(--deep);
  background: var(--sand);
  border: 1px solid var(--sand-deep);
  border-radius: 5px;
  padding: 6px 8px;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--sand-deep);
  transition: background 90ms linear, color 90ms linear, border-color 90ms linear;
}
button:hover {
  background: var(--red);
  border-color: var(--deep);
  color: #fff;
  box-shadow: 2px 2px 0 var(--deep);
}
button:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--deep); }
button.is-on {
  background: var(--red);
  border-color: var(--deep);
  color: #fff;
  box-shadow: 2px 2px 0 var(--deep);
}
button.is-on:hover { background: var(--deep); box-shadow: 2px 2px 0 var(--ink); }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* erase / stamp: two ordinary buttons side by side, each with its own shadow, hover and press */
.toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

/* the creature stamps: emoji big enough to read, six across */
.stamps {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
}
.stamps button {
  padding: 5px 0;
  font-size: 17px;
  line-height: 1.1;
  box-shadow: none;
  background: var(--white);
  border-color: var(--line);
}
.stamps button:hover { background: var(--sand); color: var(--deep); }
.stamps button.is-on {
  background: var(--red);
  border-color: var(--deep);
  box-shadow: 2px 2px 0 var(--deep);
}
.stamps button:active { transform: translate(1px, 1px); }

.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 15px; }
.tip {
  margin-top: 15px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
}

/* ---- the channel strip -------------------------------------------------- */

.channels { margin-top: 30px; }
#strip { height: 46px; background: var(--line); border-radius: 3px; }
.ticks {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  margin: 5px 0 0;
  padding: 0;
  list-style: none;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  text-align: center;
}

/* ---- the written parts -------------------------------------------------- */

.section {
  margin-bottom: 24px;
  font-family: var(--display);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: #fff;
}
.section.dark { color: var(--ink); }

.steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}
@media (max-width: 860px) { .steps { grid-template-columns: 1fr 1fr; gap: 26px; } }
@media (max-width: 520px) { .steps { grid-template-columns: 1fr; } }
.steps li { counter-increment: step; }
.steps li::before {
  content: counter(step, decimal-leading-zero);
  display: block;
  margin-bottom: 9px;
  padding-bottom: 9px;
  border-bottom: 1px dashed rgba(252, 222, 185, 0.55);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--sand);
}
.steps b { display: block; margin-bottom: 5px; font-size: 16px; font-weight: 700; }
.steps p { font-size: 13.5px; line-height: 1.65; color: rgba(255, 255, 255, 0.88); }

.after {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px dashed rgba(252, 222, 185, 0.5);
  font-family: var(--display);
  font-size: 18px;
  color: var(--sand);
}

.facts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px 28px;
  margin: 0;
}
@media (max-width: 860px) { .facts { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .facts { grid-template-columns: 1fr; } }
.facts dt {
  margin-bottom: 5px;
  padding-top: 9px;
  border-top: 2px solid var(--red);
  font-size: 14.5px;
  font-weight: 700;
}
.facts dd { margin: 0; font-size: 13.5px; line-height: 1.65; color: var(--muted); }

/* ---- train your own ----------------------------------------------------- */

.train {
  display: grid;
  grid-template-columns: 1fr 1.05fr;
  gap: 32px;
  align-items: start;
}
@media (max-width: 760px) { .train { grid-template-columns: 1fr; gap: 24px; } }
.train p { margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.more { margin: 0; font-size: 14px; }
.more a { color: var(--red); font-weight: 500; text-decoration: none; border-bottom: 1px solid var(--sand); }
.more a:hover { border-bottom-color: var(--red); }

.footnote { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); }
.footnote a { color: var(--red); text-decoration: none; border-bottom: 1px solid var(--sand); }
.footnote a:hover { border-bottom-color: var(--red); }

pre {
  margin: 0;
  padding: 16px 18px;
  border-radius: 5px;
  background: var(--ink);
  color: #f6efe4;
  box-shadow: 3px 3px 0 var(--sand-deep);
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.9;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
pre code { font-family: var(--mono); }
pre .c { color: #9a8c7c; }
code { font-family: var(--mono); font-size: 13px; }
p code { padding: 1px 5px; border-radius: 3px; background: var(--sand); color: var(--ink); }

/* ---- the citation ------------------------------------------------------ */

/* the whole band is the container: cream, edge to edge, nothing boxed in it */
.cream {
  background-color: var(--cream);
  background-image: url("trace.svg?v=37");  /* the ant trails, still and faint */
  border-top: 1px dashed var(--line);  /* the only line it needs */
}
.cream .inner { padding-top: 16px; padding-bottom: 18px; }
.cream .head { margin-bottom: 8px; padding-bottom: 0; border-bottom: none; }
.cream .head h2 { color: var(--red); }  /* the label carries the accent */

pre.cite {
  width: 100%;
  margin: 0;
  padding: 0;
  background: none;
  color: var(--muted);
  box-shadow: none;
}
/* the size has to be set on the code element: the global `code` rule beats
   anything inherited from the pre around it */
pre.cite, pre.cite code {
  font-size: 11px;
  font-weight: 400;
  line-height: 1.5;
}

.ghost-button {
  padding: 3px 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  background: none;
  border: 1px solid var(--line);
  box-shadow: none;
}
.ghost-button:hover { background: var(--red); border-color: var(--deep); color: #fff; }

/* ---- footer ------------------------------------------------------------- */

.deep .inner { padding-top: 22px; padding-bottom: 24px; text-align: center; }
.deep p { font-family: var(--mono); font-size: 12.5px; }
