/* Experiment: this game's own styles. The site's look, the same on every page
   (tokens for both themes, base, controls, top bar, floating panels, the stage
   panel and the end-of-level card), is ../site.css, loaded first. This file
   adds only what this game draws, using the site's tokens: it names no colour
   and no corner of its own. Colour is for visitors, arms and state. See _doctrine/design.md. */

/* ---- this game's own labels, in the site's label style ---- */

.tally th,
.chart figcaption {
  font: 600 11px/1.4 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

#field:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---- layout: knobs, picture and readout, stage ----
   Wide: knobs on the left, the picture and readout in the middle, the stage
   on the right. Medium: the picture and readout beside one column that holds
   the knobs and then the stage. Narrow: one column, and the page scrolls. */

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 304px;
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: 'controls centre mission';
}

.side {
  display: contents;
}

.controls,
.mission {
  padding: 16px;
  overflow-y: auto;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.controls {
  grid-area: controls;
  border-right: 1px solid var(--line);
}

.mission {
  grid-area: mission;
  border-left: 1px solid var(--line);
  gap: 12px;
}

.centre {
  grid-area: centre;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ---- the knobs ---- */

.control {
  display: flex;
  flex-direction: column;
}

.knobs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 -8px 8px;
}

.knob {
  padding: 6px 8px 7px;
  border-left: 3px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.knob h3 {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
}

.knob.chosen {
  background: var(--sunken);
  border-left-color: var(--focus);
}

.knob.chosen h3 {
  color: var(--ink);
}

/* A knob's settings are a joined control, as the speed is. The panel is narrow,
   so unlike the ones in the top bar they may run onto a second line. */
.knob .joined {
  flex-wrap: wrap;
  row-gap: 4px;
}

/* ---- the picture ---- */

.field-wrap {
  position: relative;
  flex: 1 1 0;
  min-height: 340px;
  overflow: hidden;
  background-color: color-mix(in srgb, var(--level) var(--tint), var(--paper));
  background-image: radial-gradient(color-mix(in srgb, var(--level) 30%, var(--line-strong)) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* the rule in the level's colour, drawn over the picture */
.field-wrap::after {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--level);
}

/* the foot of the picture is left clear for the key that floats there */
#field {
  position: absolute;
  inset: 10px 8px 50px;
  width: calc(100% - 16px);
  height: calc(100% - 60px);
  user-select: none;
}

#field text {
  font-family: var(--font-mono);
}

.wire-line {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 0.75;
}

/* a lane nobody is sent down, and the links that are not a visitor's way */
.wire-line.idle {
  stroke-dasharray: 3 6;
}

/* chevrons along a wire, pointing the way visitors go */
.ticks {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 0.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.node {
  cursor: pointer;
}

.node.source,
.node.market {
  cursor: default;
}

/* the line work of the story pictures */
.box {
  fill: var(--box);
  stroke: var(--box-line);
  stroke-width: 1.2;
  stroke-linejoin: round;
}

.detail {
  fill: none;
  stroke: var(--box-line);
  stroke-width: 1.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.glyph {
  fill: var(--box-line);
}

/* ---- the cells: the Panel look (chosen 2026-10-13) ----
   Every box an instrument cell: a title bar with an icon, the name and a lamp;
   the setting; one live number over an eight-step gauge (two on an arm); a
   short note. The selected cell's title bar inverts. Thin lines throughout. */

#field .box {
  fill: var(--panel);
  stroke: var(--box-line);
  stroke-width: 0.75;
}

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

.rule {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 0.75;
}

#field .icon {
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* a tray keeps the colour of a visitor who converted */
#field .node.tray .icon {
  stroke: var(--ok);
}

#field .node .title {
  fill: var(--ink-2);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.08em;
}

#field .node .label {
  fill: var(--ink);
  font-size: 11.5px;
  font-weight: 500;
}

#field .node .label.tight {
  font-size: 9.5px;
}

#field .node .key {
  fill: var(--muted);
  font-size: 9.5px;
}

#field .node .value {
  fill: var(--ink-2);
  font-size: 9.5px;
}

#field .node .sub {
  fill: var(--muted);
  font-size: 9.5px;
}

#field .node .sub.warn {
  fill: var(--warn-text);
}

.gauge {
  fill: var(--line);
}

.gauge.on {
  fill: var(--muted);
}

.lamp {
  fill: var(--ok);
}

.lamp.warn {
  fill: var(--write);
}

.lamp.idle {
  fill: var(--line-strong);
}

/* selected: the title bar inverts */
#field .node.selected .box {
  stroke: var(--ink);
  stroke-width: 1;
}

.node.selected .bar {
  fill: var(--ink);
}

#field .node.selected .icon {
  stroke: var(--paper);
}

#field .node.selected .title {
  fill: var(--paper);
}

/* not in use: a dashed border */
#field .node.idle .box {
  stroke-dasharray: 3 3;
}

/* visitors: the colour says who is arriving, then what they did */
.dot {
  pointer-events: none;
  fill: var(--read);
}

.dot.seg {
  fill: var(--flood);
}

/* someone who has been before: a ring */
.dot.back {
  fill: var(--box);
  stroke: var(--read);
  stroke-width: 1.5;
}

.dot.seg.back {
  stroke: var(--flood);
}

.dot.buy {
  fill: var(--ok);
}

.dot.click {
  fill: var(--write);
}

.dot.refund {
  fill: var(--bad);
}

.dot.left {
  fill: var(--muted);
  opacity: 0.55;
}

.fx {
  pointer-events: none;
  fill: none;
  stroke-width: 1;
  stroke-linecap: round;
  transform-box: fill-box;
  transform-origin: center;
  animation: fade 0.6s ease-out forwards;
}

.fx.land {
  stroke: var(--ok);
  animation-name: ring;
}

/* lost and landed: thin marks, as the rest of the cell */
.fx.lost {
  stroke: var(--bad);
  stroke-width: 1.25;
}

@keyframes ring {
  from {
    transform: scale(0.6);
    opacity: 0.9;
  }
  to {
    transform: scale(1.8);
    opacity: 0;
  }
}

@keyframes fade {
  from {
    opacity: 1;
  }
  to {
    transform: translateY(-12px);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fx {
    animation-duration: 0.01s;
  }
}

/* what the dots are: the floating key of the site, in the corner where Scaling has its own */
.dot-key {
  position: absolute;
  left: 12px;
  bottom: 12px;
  gap: 4px 14px;
  max-width: calc(100% - 24px);
  min-height: 0;
  padding: 6px 12px;
  font: 12px/1.5 var(--font-sans);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  pointer-events: none;
}

/* ---- the readout ---- */

.board {
  flex: none;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

/* a knob that changes how the numbers are read lights the readout, as a knob of a box lights the box */
.board.chosen {
  box-shadow: inset 3px 0 0 var(--focus);
}

.board-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 12px;
  margin-bottom: 8px;
}

.board-head h2 {
  margin: 0;
}

/* the numbers in a row, then the charts in a row under them: three charts
   beside a column of numbers would each be too small to read on a laptop */
.board-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.readout {
  display: grid;
  grid-template-columns: minmax(0, 250px) minmax(0, 1fr);
  gap: 4px 20px;
  align-items: start;
  min-width: 0;
}

.tally {
  width: 100%;
  border-collapse: collapse;
  font: 12px/1.5 var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.tally th,
.tally td {
  padding: 2px 6px 2px 0;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}

.tally th:first-child,
.tally td:first-child {
  text-align: left;
}

.tally td:first-child {
  color: var(--ink);
  font-weight: 600;
}

/* the arm's colour, as in the charts */
.tally .key {
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}

.tally td {
  color: var(--ink-2);
}

.lines li {
  padding: 1px 0;
  font: 12px/1.5 var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  min-height: 18px;
  font: 12px/1.5 var(--font-mono);
  color: var(--muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

/* the same colours as the dots, for the key at the foot of the picture */
.swatch {
  flex: none;
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--read);
}

.swatch.seg {
  background: var(--flood);
}

.swatch.back {
  background: var(--box);
  border: 1.5px solid var(--read);
}

.swatch.buy {
  background: var(--ok);
}

.swatch.click {
  background: var(--write);
}

.swatch.refund {
  background: var(--bad);
  border-radius: 1px;
}

.swatch.left {
  background: var(--muted);
  opacity: 0.55;
}

/* ---- charts: numbers on the axis, days along the bottom, a key with the values now.
   Amounts start at zero. Differences run the same distance either side of a marked zero. ---- */

.charts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.chart {
  min-width: 0;
  margin: 0;
}

.chart figcaption {
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart svg {
  display: block;
  width: 100%;
  max-width: 380px;
  height: auto;
}

.axis {
  fill: var(--muted);
  font: 9.5px var(--font-mono);
}

.grid {
  fill: none;
  stroke: var(--line);
  stroke-width: 1;
}

.frame {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 1;
}

.zero {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1;
}

.limit {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1;
  stroke-dasharray: 5 3;
}

/* one colour an arm, in every chart and in the table */
.line {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.75;
  stroke-linejoin: round;
}

.band {
  fill: var(--muted);
  stroke: none;
  opacity: 0.16;
}

.line.arm-b {
  stroke: var(--read);
}

.band.arm-b {
  fill: var(--read);
}

.line.arm-c {
  stroke: var(--flood);
}

.band.arm-c {
  fill: var(--flood);
}

.line.arm-d {
  stroke: var(--write);
}

.band.arm-d {
  fill: var(--write);
}

/* a short piece of each line, for the key under a chart */
.key {
  flex: none;
  width: 12px;
  height: 0;
  border-top: 2px solid var(--muted);
}

.key.arm-b {
  border-color: var(--read);
}

.key.arm-c {
  border-color: var(--flood);
}

.key.arm-d {
  border-color: var(--write);
}

.key.limit {
  border-top: 1px dashed var(--ink);
}

/* ---- medium screens: two columns ---- */

@media (max-width: 1279px) {
  main {
    grid-template-columns: minmax(0, 1fr) 304px;
    grid-template-areas: 'centre side';
  }

  .side {
    grid-area: side;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: var(--panel);
    border-left: 1px solid var(--line);
  }

  .controls,
  .mission {
    overflow-y: visible;
    border: 0;
  }

  .mission {
    order: 1;
    border-bottom: 1px solid var(--line);
  }

  .controls {
    order: 2;
  }

  .field-wrap {
    min-height: 320px;
  }
}

/* ---- narrow screens: one column, and the page scrolls ---- */

@media (max-width: 759px) {
  html,
  body {
    height: auto;
    min-height: 100%;
  }

  main {
    display: flex;
    flex-direction: column;
  }

  .side {
    display: contents;
  }

  .centre {
    order: 2;
    overflow-y: visible;
  }

  /* the story first, then the picture and readout, then the knobs */
  .mission {
    order: 1;
    border-bottom: 1px solid var(--line);
  }

  .controls {
    order: 3;
    border-top: 1px solid var(--line);
  }

  .field-wrap {
    flex: none;
    height: 56vw;
    min-height: 220px;
  }

  .charts,
  .readout {
    grid-template-columns: minmax(0, 1fr);
  }
}
