/* Number Lab: shared tokens, page shell and machine parts. Each experiment adds its own stylesheet. */

:root {
  --enamel: #d5dbd3;
  --enamel-deep: #c5cdc2;
  --paper: #fcfcfa;
  --ink: #1c2120;
  --ink-soft: #4d5552;
  --rule: color-mix(in srgb, var(--ink) 16%, transparent);
  --red: #c8262e;
  --key: #26302c;
  --on-key: #eef2ec;
  --rep: #c2c8c1;

  /* Ink ramp for ordered steps, light to dark; validated as an ordinal ramp on --paper. */
  --r1: #78b6ff;
  --r2: #629eeb;
  --r3: #4c88d3;
  --r4: #3672bb;
  --r5: #205ca3;
  --r6: #03478c;
  --r7: #003275;

  --font: 'Bricolage Grotesque', system-ui, sans-serif;
  --print: 'Courier Prime', 'Courier New', monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --enamel: #1b201e;
    --enamel-deep: #262d2a;
    --paper: #232926;
    --ink: #e9eee8;
    --ink-soft: #a3aca7;
    --red: #ff6e66;
    --key: #e4e9e2;
    --on-key: #1b201e;
    --rep: #4a524e;

    /* Same ramp idea, anchored dark near the surface. */
    --r1: #365c8c;
    --r2: #4971a2;
    --r3: #5e85b8;
    --r4: #729bcf;
    --r5: #87b1e6;
    --r6: #9dc7fe;
    --r7: #b3deff;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--enamel);
  color: var(--ink);
  font: 400 1.0625rem/1.55 var(--font);
  font-optical-sizing: auto;
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 3px solid var(--r4);
  outline-offset: 2px;
}

h1,
h2 {
  margin: 0;
  font-weight: 760;
  font-variation-settings: 'wdth' 85;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

h1 {
  font-size: clamp(2.1rem, 1.6rem + 2.4vw, 3.25rem);
}

h2 {
  font-size: 1.4rem;
}

p {
  margin: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.page {
  max-width: 1160px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

.lab-bar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  font-weight: 600;
  font-size: 0.95rem;
}

.lab-bar a {
  text-decoration: none;
}

.lab-bar a:hover {
  text-decoration: underline;
}

.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 12px;
  background: var(--key);
  color: var(--on-key);
  font: 650 1rem/1 var(--font);
  cursor: pointer;
  box-shadow: inset 0 -4px 0 color-mix(in srgb, #000 28%, transparent);
  transition: transform 80ms ease-out, box-shadow 80ms ease-out;
}

.key:active {
  transform: translateY(2px);
  box-shadow: inset 0 -2px 0 color-mix(in srgb, #000 28%, transparent);
}

.key[hidden] {
  display: none;
}

.key:disabled,
.key[aria-disabled='true'] {
  cursor: default;
  opacity: 0.55;
  transform: none;
}

.key--plain {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--ink);
}

.key--plain:active {
  box-shadow: inset 0 0 0 2px var(--ink);
}

.site-foot {
  max-width: 62ch;
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.site-foot p + p {
  margin-top: 6px;
}

/* Experiment pages share these machine parts; each experiment sizes and moves its own. */

.toy {
  display: grid;
  gap: 40px;
}

@media (min-width: 980px) {
  .toy {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr);
    align-items: start;
    gap: 48px;
  }
}

.intro {
  margin-bottom: 24px;
}

.lede {
  max-width: 52ch;
  margin-top: 12px;
  font-size: 1.125rem;
}

.section-lede {
  max-width: 56ch;
  margin: 10px 0 18px;
  color: var(--ink-soft);
}

.noscript {
  margin: 0 0 24px;
  font-weight: 650;
}

/* The machine panel and its entry form */

.machine {
  padding: 24px 20px 28px;
  border-radius: 22px;
  background: var(--enamel-deep);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, #fff 35%, transparent),
    0 3px 0 color-mix(in srgb, var(--ink) 14%, transparent);
}

@media (max-width: 420px) {
  .machine {
    padding-inline: 14px;
  }
}

.entry label {
  display: block;
  margin-bottom: 8px;
  font-weight: 650;
}

.entry-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.entry input {
  flex: 1 1 7.5ch;
  min-width: 0;
  max-width: 10ch;
  min-height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font: 700 1.6rem/1 var(--print);
  letter-spacing: 0.12em;
  box-shadow: inset 0 2px 0 color-mix(in srgb, var(--ink) 18%, transparent);
}

.entry input::placeholder {
  color: color-mix(in srgb, var(--ink) 35%, transparent);
}

.hint {
  margin-top: 8px;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.hint.is-error {
  color: var(--ink);
  font-weight: 650;
}

.verdict {
  min-height: 3.1em;
  text-align: center;
  font-weight: 600;
  text-wrap: balance;
}

/* Digit tiles. An experiment sets --tile-w and --tile-h and places them. */

.tile {
  display: grid;
  place-items: center;
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: 10px;
  background: var(--key);
  color: var(--on-key);
  font-size: calc(var(--tile-h) * 0.66);
  font-weight: 720;
  font-variation-settings: 'wdth' 75;
  line-height: 1;
  box-shadow: inset 0 -5px 0 color-mix(in srgb, #000 30%, transparent);
}

.tile.is-answer {
  background: var(--red);
  color: #fff;
}

@media (prefers-color-scheme: dark) {
  .tile.is-answer {
    color: var(--on-key);
  }
}

/* The paper tape that prints one line per round. */

.tape-slot {
  margin-top: 18px;
  padding-top: 10px;
  border-top: 6px solid var(--key);
  border-radius: 3px 3px 0 0;
}

.tape-slot[hidden] {
  display: none;
}

.tape {
  width: min(100%, 26ch);
  margin: 0 auto;
  padding: 10px 16px 22px;
  list-style: none;
  background: var(--paper);
  font: 400 1.05rem/1.7 var(--print);
  text-align: right;
}

/* Paper with a torn bottom edge. */
.tape,
.torn {
  --tear: 8px;
  mask:
    linear-gradient(#000 0 0) top / 100% calc(100% - var(--tear)) no-repeat,
    conic-gradient(from -45deg at 50% 100%, #000 90deg, #0000 0) bottom / calc(var(--tear) * 2) var(--tear) repeat-x;
}

.tape li {
  white-space: pre;
}

.tape .is-answer {
  color: var(--red);
  font-weight: 700;
}

/* Histogram whose columns double as a legend. An experiment sets the column count. */

.histogram {
  max-width: 560px;
  margin: 28px 0 0;
}

.histogram figcaption {
  font-weight: 650;
}

.bars {
  display: grid;
  align-items: end;
  height: 168px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  border-bottom: 1px solid var(--rule);
}

.bars li {
  height: 100%;
}

.bars button {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 6px 6px 0 0;
  background: none;
  color: var(--ink);
  font: inherit;
  cursor: default;
}

.bars .bar {
  width: min(24px, 60%);
  height: calc(var(--h) * 0.8%);
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  background: var(--c);
}

.bars-axis {
  display: grid;
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  color: var(--ink-soft);
  font-size: 0.9rem;
  text-align: center;
}

/* A colour key's square */

.swatch {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

/* Notes */

.notes {
  max-width: 64ch;
  margin-top: 56px;
}

.notes p {
  margin-top: 12px;
}

@media (prefers-reduced-motion: reduce) {
  .key {
    transition: none;
  }
}
