/* Runner Relay: one exchange board. Lamps, plates, a register, one key. */

@font-face {
  font-family: "Routed Gothic";
  src: url("/fonts/routed-gothic.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Routed Gothic Wide";
  src: url("/fonts/routed-gothic-wide.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  --panel: #0b1411;
  --lamp: #ffd9a0;
  --lamp-core: #fff4dc;
  --plate: #ece3cc;
  --ink: #15120c;
  --ink-2: #4a4333;
  --key: #d8281c;
  --key-hi: #dd3122;
  --key-lo: #b81f14;
  --pilot: #37c871;
  --bezel: #060908;
  --bezel-edge: #3a423d;

  --engrave: "Routed Gothic", "Helvetica Neue", Arial, sans-serif;
  --engrave-wide: "Routed Gothic Wide", "Routed Gothic", "Helvetica Neue", Arial, sans-serif;

  --gap: clamp(12px, 2.2vw, 28px);
  --seat: cubic-bezier(.16, 1, .3, 1);

  /* slotted screw heads, drawn once, two slot angles */
  --screw-a: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Ccircle cx='6' cy='6' r='4.4' fill='%236f6648'/%3E%3Ccircle cx='6' cy='6' r='3.5' fill='%23bdb292'/%3E%3Cpath d='M3.1 7.7 8.9 4.3' stroke='%2325200f' stroke-width='1.25' stroke-linecap='round'/%3E%3C/svg%3E");
  --screw-b: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Ccircle cx='6' cy='6' r='4.4' fill='%236f6648'/%3E%3Ccircle cx='6' cy='6' r='3.5' fill='%23bdb292'/%3E%3Cpath d='M4.6 2.9 7.4 9.1' stroke='%2325200f' stroke-width='1.25' stroke-linecap='round'/%3E%3C/svg%3E");
}

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

html {
  background: var(--panel);
  color: var(--plate);
  scrollbar-color: #6f6447 var(--panel);
  scrollbar-width: thin;
  -webkit-text-size-adjust: 100%;
}
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: var(--panel); }
::-webkit-scrollbar-thumb { background: #6f6447; border: 3px solid var(--panel); border-radius: 6px; }
::selection { background: var(--lamp); color: var(--ink); }

body {
  margin: 0;
  font-family: var(--engrave);
  font-size: clamp(1rem, .96rem + .2vw, 1.125rem);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  /* Without the board, the panel still shows its unlit lamps. */
  background-image: radial-gradient(circle at center, #1e1810 0 33%, transparent 36%);
  background-size: 12px 12px;
}
.lamps body { background-image: none; }

a { color: inherit; text-underline-offset: .2em; text-decoration-thickness: 1px; }
a:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 2px; }

/* ---------- the board ---------- */

#board {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
}
.lamps #board { display: block; }

.flash {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #fff1cf;
  opacity: 0;
  pointer-events: none;
}
.flash.go { animation: flash 640ms var(--seat); }
@keyframes flash {
  0% { opacity: 0; }
  10% { opacity: .9; }
  100% { opacity: 0; }
}

/* ---------- plates: flat engraved laminate, four slotted screws ---------- */

.plate,
.note {
  color: var(--ink);
  background-color: var(--plate);
  background-image: var(--screw-a), var(--screw-b), var(--screw-b), var(--screw-a);
  background-repeat: no-repeat;
  background-size: 12px 12px;
  background-position: left 5px top 5px, right 5px top 5px, left 5px bottom 5px, right 5px bottom 5px;
  border-radius: 3px;
  box-shadow: 0 0 0 1px #04070a, 0 10px 22px rgba(0, 0, 0, .5);
}

/* ---------- the rail: nameplate, register, key ---------- */

.rail {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 10px var(--gap);
  padding:
    max(var(--gap), env(safe-area-inset-top))
    max(var(--gap), env(safe-area-inset-right))
    0
    max(var(--gap), env(safe-area-inset-left));
  pointer-events: none;
}
.rail > * { pointer-events: auto; }

.nameplate {
  justify-self: start;
  padding: .62em 2.1em .56em;
  font-family: var(--engrave-wide);
  font-size: .95rem;
  line-height: 1.1;
  letter-spacing: .16em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  background-image: var(--screw-a), var(--screw-b);
  background-position: left 6px center, right 6px center;
}
.nameplate:focus-visible { outline: 2px solid var(--lamp-core); outline-offset: 5px; }

.register {
  justify-self: center;
  display: grid;
  justify-items: center;
  gap: .22em;
  padding: .5em 1.9em .42em;
}
.register__label,
.register__foot {
  font-family: var(--engrave-wide);
  text-transform: uppercase;
  line-height: 1.1;
}
.register__label { font-size: .7rem; letter-spacing: .2em; }
.register__foot { font-size: .64rem; letter-spacing: .18em; color: var(--ink-2); }
.register__window {
  position: relative;
  display: inline-flex;
  padding: 3px 4px;
  border-radius: 2px;
  background: #090907;
  font-size: 1.15rem;
  line-height: 1.25;
  color: #f3ead2;
}
.register__window::after {
  /* the wheels are cylinders: they fall away at the top and bottom of the window */
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(0, 0, 0, .72), transparent 30%, transparent 70%, rgba(0, 0, 0, .72));
  pointer-events: none;
}
.wheel {
  width: .7em;
  height: 1.25em;
  overflow: hidden;
  text-align: center;
  border-left: 1px solid rgba(255, 255, 255, .09);
}
.wheel:first-child { border-left: 0; }
.wheel:nth-child(3n + 1):not(:first-child) { margin-left: 4px; }
.wheel i {
  display: block;
  font-style: normal;
  transform: translateY(calc(var(--d, 0) * -1.25em));
  transition: transform 170ms var(--seat);
}
.wheel b { display: block; height: 1.25em; font-weight: 400; }
.wheel.spin i {
  transition: none;
  filter: blur(.7px);
  animation: spin var(--spin, 420ms) linear infinite;
  animation-delay: calc(var(--spin, 420ms) * var(--ph, 0));
}
@keyframes spin {
  from { transform: translateY(0); }
  to { transform: translateY(-12.5em); }
}

.keywell {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  transition: opacity 200ms var(--seat);
}
/* One key at a time: on the last frame the plate carries it. */
.at-last .keywell { opacity: 0; pointer-events: none; visibility: hidden; }

/* ---------- pilot lamp: lights once, on success ---------- */

.pilot {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 32%, #2f6f4b 0 22%, #163a27 24%);
  box-shadow: 0 0 0 2px var(--bezel), 0 0 0 3px var(--bezel-edge);
}
.is-copied .pilot { background: radial-gradient(circle at 36% 32%, #f1fff6 0 22%, var(--pilot) 24%); }

/* ---------- the key: a flat red cap in a black bezel ---------- */

.key {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  border: 0;
  cursor: pointer;
  min-height: 44px;
  padding: .85em 1.35em .8em;
  border-radius: 7px;
  font-family: var(--engrave-wide);
  font-size: .9rem;
  line-height: 1;
  letter-spacing: .14em;
  text-transform: uppercase;
  white-space: nowrap;
  color: #fff6ee;
  background: var(--key);
  border-top: 1px solid var(--key-hi);
  border-bottom: 2px solid var(--key-lo);
  box-shadow: 0 0 0 3px var(--bezel), 0 0 0 4px var(--bezel-edge), 0 7px 14px rgba(0, 0, 0, .6);
  transition: transform 90ms var(--seat), box-shadow 90ms var(--seat), background-color 140ms;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
/* Under the pointer the collar takes the key's red; the cap keeps its colour so the label keeps its contrast. */
@media (hover: hover) {
  .key:hover { box-shadow: 0 0 0 3px var(--bezel), 0 0 0 5px var(--key), 0 7px 14px rgba(0, 0, 0, .6); }
}
.key:active {
  transform: translateY(2px);
  background: var(--key-lo);
  border-bottom-width: 1px;
  box-shadow: 0 0 0 3px var(--bezel), 0 0 0 4px var(--bezel-edge), 0 2px 5px rgba(0, 0, 0, .6);
}
.key:focus-visible { outline: 2px solid var(--lamp-core); outline-offset: 7px; }
.closing .key:focus-visible { outline-color: var(--ink); }
.key--big {
  padding: 1em 2.2em .95em;
  border-radius: 10px;
  font-size: clamp(1.15rem, .95rem + 1vw, 1.6rem);
}

/* ---------- frames ---------- */

.frame {
  position: relative;
  min-height: 100svh;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 1.75rem;
  padding: 8rem var(--gap) 4rem;
}
.say {
  margin: 0;
  max-width: 17ch;
  font-family: var(--engrave-wide);
  font-weight: 400;
  font-size: clamp(2rem, 1rem + 5vw, 5.25rem);
  line-height: 1.04;
  letter-spacing: .03em;
  text-transform: uppercase;
  text-align: center;
  text-wrap: balance;
  color: var(--lamp);
}
.note {
  margin: 0;
  max-width: 36rem;
  padding: 1.05em 2.2em 1.1em;
  text-wrap: pretty;
}

.closing {
  display: grid;
  justify-items: center;
  gap: 1.05em;
  width: min(40rem, 100%);
  padding: 1.7em 2.4em 1.45em;
  text-align: center;
}
.closing__lead { margin: 0; max-width: 32rem; font-size: 1.0625rem; text-wrap: balance; }

/* the line the key copies, shown in a window like the register's */
.line {
  margin: 0;
  max-width: 100%;
  padding: .6em 1em .55em;
  border-radius: 2px;
  background: #090907;
  color: #f3ead2;
  font-size: 1rem;
  line-height: 1.4;
  letter-spacing: .02em;
  overflow-wrap: anywhere;
  user-select: all;
}
.line::selection { background: var(--lamp); color: var(--ink); }

.closing__action { position: relative; padding: .3em 0 .15em; }
.closing__action .pilot {
  position: absolute;
  right: calc(100% + 16px);
  top: 50%;
  margin-top: -6px;
}
/* The key needs the script; without it the line and the links are the action. */
html:not(.js) .keywell,
html:not(.js) .register,
html:not(.js) .closing__action { display: none; }

.closing__status {
  margin: 0;
  min-height: 1.2em;
  font-family: var(--engrave-wide);
  font-size: .8rem;
  line-height: 1.2;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.closing__fine {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .25em 1.3em;
  font-size: .95rem;
}

/* ---------- with the board running, the lamps and one plate carry the copy ---------- */

.lamps { scroll-snap-type: y proximity; }
.lamps .frame {
  height: 100svh;
  min-height: 0;
  padding: 0;
  scroll-snap-align: start;
}
.lamps .say,
.lamps .frame > .note {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.lamps .frame--last {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 0 var(--gap) max(calc(var(--gap) * 1.6), env(safe-area-inset-bottom));
}

.caption {
  display: none;
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(var(--gap), env(safe-area-inset-bottom));
  width: min(38rem, calc(100vw - 2 * var(--gap)));
  padding: 1.05em 2.2em 1.1em;
  transform: translateX(-50%);
  transition: opacity 220ms var(--seat), transform 220ms var(--seat);
}
.lamps .caption { display: block; }
.caption p { margin: 0; text-wrap: pretty; }
.caption.swap { animation: seat 420ms var(--seat); }
@keyframes seat {
  from { transform: translate(-50%, 12px); clip-path: inset(0 0 100% 0); }
  to { transform: translate(-50%, 0); clip-path: inset(0 0 0 0); }
}
.at-last .caption { opacity: 0; transform: translate(-50%, 18px); pointer-events: none; }

/* ---------- the document pages: one long plate on the panel ---------- */

.doc .rail { position: static; grid-template-columns: 1fr; padding-bottom: 0; }
.sheet {
  /* positioned, so the nameplate's shadow falls on the panel and stops at this plate's edge */
  position: relative;
  width: min(46rem, calc(100% - 2 * var(--gap)));
  margin: clamp(1.5rem, 4vw, 3rem) auto clamp(2rem, 6vw, 5rem);
  padding: clamp(1.6rem, 4vw, 3rem) clamp(1.4rem, 5vw, 3.5rem);
}
.sheet h1,
.sheet h2 {
  margin: 0;
  font-family: var(--engrave-wide);
  font-weight: 400;
  text-transform: uppercase;
  text-wrap: balance;
}
.sheet h1 { font-size: clamp(1.7rem, 1.2rem + 2.4vw, 2.6rem); line-height: 1.08; letter-spacing: .06em; }
.sheet h2 { margin-top: 2.2em; font-size: 1.02rem; line-height: 1.4; letter-spacing: .1em; }
.sheet p,
.sheet ol,
.sheet ul { margin: .55em 0 0; max-width: 68ch; text-wrap: pretty; }
.sheet ol, .sheet ul { padding-left: 1.3em; }
.sheet li + li { margin-top: .3em; }
.sheet .lede { margin-top: 1em; font-size: 1.125rem; line-height: 1.45; }
.sheet .line { display: inline-block; margin-top: .8em; }
.sheet code { font-family: inherit; padding: .05em .35em; border-radius: 2px; background: rgba(21, 18, 12, .1); }
.sheet .foot { margin-top: 2.6em; color: var(--ink-2); }

/* ---------- small boards ---------- */

@media (max-width: 720px) {
  .rail { grid-template-columns: 1fr auto; }
  .register { grid-column: 1 / -1; grid-row: 2; padding: .4em 1.7em .34em; }
  .register__window { font-size: 1rem; }
  .nameplate { font-size: .78rem; padding: .7em 2em .62em; letter-spacing: .13em; }
  .key--small { font-size: .78rem; padding: .85em 1.05em .8em; }
  .keywell { gap: 9px; }
  .caption, .note { padding: .95em 1.7em 1em; }
  .closing { padding: 1.5em 1.5em 1.3em; gap: .9em; }
  .closing__lead { font-size: 1rem; }
  .line { font-size: .95rem; }
}

@media (prefers-reduced-motion: reduce) {
  .flash.go, .caption.swap, .wheel.spin i { animation: none; }
  .wheel i, .key, .caption, .keywell { transition: none; }
  .lamps { scroll-snap-type: none; }
}
