/* The page around the player. Loaded after demo.css; see explorations/BRIEF.md. */

/*
  One grid. The player's column is cut in four, and the third line is where the fixed mark stands, in the player and
  in the plates: it is the page's one axis. Labels stand left of it; sentences begin on it.

  One rule for ivory. Quiet is engraving, bright is paint: what the visitor does, what has played, what was run.

  Written narrow first, so every width has one answer: the plates take their full width from 760 px, and the four
  columns appear at 1000 px. Nothing here touches #frame, #skin or .frame.
*/

:root {
  --leader: rgb(244 241 234 / 0.45); /* drawn lines that carry meaning: 4:1 against the page */
  --gutter: 24px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

body {
  padding-bottom: 64px;
}

p,
dd,
li {
  text-wrap: pretty;
}

/* Small quiet capitals: every label on the page. */
.label,
.facts dt,
.cap,
.flag,
.spans .what {
  margin: 0;
  color: var(--quiet);
  font: 400 11px / 16px var(--display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

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

.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: baseline;
  gap: 10px 0;
}

/* The page's one typographic event: the idea, in the skin's engraving face. */
.lede {
  max-width: none;
  color: var(--bright);
  font: 400 clamp(18px, 5vw, 22px) / 1.36 var(--display);
  letter-spacing: 0.01em;
  text-wrap: wrap;
}

.lede span {
  display: block;
}

/* The tag's numeral is set in the reading face: in the engraving face, 10 reads as IO. */
.wordmark span .n {
  margin: 0;
  font-family: var(--body);
  font-size: 1.04em;
  letter-spacing: 0.06em;
  font-variant-numeric: lining-nums tabular-nums;
}

/* Where the tag no longer fits beside the wordmark it goes under it whole, not one word of it. */
@media (max-width: 339px) {
  .wordmark span {
    display: block;
    margin: 6px 0 0;
  }
}

/* ---------------------------------------------------------------- the options: repairs only */

/* On a narrow screen each legend stands above its row, and no option is left alone on a line. */
@media (max-width: 599px) {
  .bench {
    justify-content: flex-start;
    gap: 12px 0;
  }

  .bench fieldset {
    width: 100%;
  }

  .bench legend {
    float: none;
    margin: 0 0 6px;
  }

  .bench label span {
    padding-inline: 9px;
  }
}

@media (max-width: 350px) {
  .bench label span {
    min-width: 42px;
    padding-inline: 6px;
    letter-spacing: 0.04em;
  }
}

/* Under a finger an option is 42 px tall to the touch, as wide as it was published, and looks as it did. */
@media (pointer: coarse) {
  .bench label {
    padding-block: 6px;
  }
}

@media (pointer: coarse) and (max-width: 599px) {
  .bench legend {
    margin-bottom: 0;
  }
}

/* ---------------------------------------------------------------- try it */

.try {
  margin-top: 28px;
}

.try h2 {
  margin: 0 0 8px;
  line-height: 16px;
}

.try-head p {
  color: var(--quiet);
}

.try ol {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 22px 0;
  margin: 20px 0 0;
  padding: 0;
  list-style: none;
}

.try h3 {
  margin: 0 0 10px;
  color: var(--quiet);
  font: 400 13px / 16px var(--display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* In the engraving face 01 reads as OI: the numerals are set in the reading face. */
.try h3 span {
  margin-inline-end: 0.5em;
  color: var(--amber);
  font: 400 13px / 16px var(--body);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.try li p {
  color: var(--quiet);
  line-height: 22px;
}

.try li .do {
  margin-bottom: 4px;
  color: var(--bright);
  font-size: 17px;
  line-height: 26px;
}

.try .do kbd {
  vertical-align: 2px;
}

@media (min-width: 860px) {
  .try ol {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .try li {
    padding-inline-end: var(--gutter);
  }
}

/* ---------------------------------------------------------------- sections */

.sec {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.sec h2 {
  margin: 0 0 12px;
  line-height: 24px;
}

.sec-head h2 {
  margin: 0;
}

.sec-head p {
  margin-bottom: 14px;
  color: var(--quiet);
}

/* A label left of the axis, a fact on it. */
.facts {
  margin: 0;
}

.facts > div {
  padding: 9px 0 10px;
  border-top: 1px solid var(--line);
}

.facts dt {
  margin-bottom: 2px;
}

.facts dd {
  margin: 0;
}

@media (min-width: 700px) {
  .facts > div {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    align-items: baseline;
  }

  .facts dt {
    margin: 0;
    padding-inline-end: var(--gutter);
  }
}

/* ---------------------------------------------------------------- after use: the plates */

/*
  Every position is read off the photographs themselves (explorations/kit/plates/raw/bare-560-full.png and
  lived-560-full.png, 2240 px across) and kept as a fraction of the player's width. The pictures show a window of
  that width, from --x0 to --x1; what the page draws is placed by calculation from the two, so a different crop
  needs only its window.
*/
.record {
  --m-back: 0.057143; /* the way-back button: its left edge, x 56, plus half its height, 72 */
  --m-a0: 0.342411; /* the first painted tick, 03:33: x 767 */
  --m-mark: 0.5; /* the red mark: x 1120 */
  --m-rail: 0.75; /* the rail runs the whole width: it is named on the fourth line */
  --m-b0: 0.612054; /* the tick of 03:47: x 1371 */
  --m-second: 0.696875; /* the amber second mark, 03:51: x 1561 */

  --x0: 0.214286; /* the closer crop: x 480 to 2096, between figures */
  --x1: 0.935714;

  --window: calc(var(--x1) - var(--x0));
  --back: calc((var(--m-back) - var(--x0)) / var(--window) * 100%);
  --a0: calc((var(--m-a0) - var(--x0)) / var(--window) * 100%);
  --mark: calc((var(--m-mark) - var(--x0)) / var(--window) * 100%);
  --rail: calc((var(--m-rail) - var(--x0)) / var(--window) * 100%);
  --b0: calc((var(--m-b0) - var(--x0)) / var(--window) * 100%);
  --second: calc((var(--m-second) - var(--x0)) / var(--window) * 100%);

  margin: 22px 0 0;
}

.stack picture {
  display: block;
}

.stack img {
  display: block;
  position: relative;
  width: 100%;
  height: auto;
  box-shadow: 0 0 0 1px var(--line);
}

.stack .wide {
  display: none;
}

/* Above the upper plate: what it is, and the two things it shares with the lower one. */
.over {
  display: grid;
  grid-template-columns: var(--mark) calc(var(--rail) - var(--mark)) minmax(0, 1fr);
  align-items: end;
}

.cap {
  grid-column: 1 / -1;
  padding-bottom: 10px;
}

/* A name, and a hairline from it down to the edge of the photograph. None is drawn across one. */
.flag {
  margin-left: -0.5px;
  padding: 0 0 10px 8px;
  border-left: 1px solid var(--leader);
  white-space: nowrap;
}

.flag-mark {
  grid-column: 2;
}

.flag-rail {
  grid-column: 3;
  white-space: normal; /* if a wider face ever leaves it no room, it folds inside the plate's edge */
}

.more,
.flag-back {
  display: none;
}

/* Between the plates the mark's hairline goes on: one line through both red marks. */
.between {
  position: relative;
  min-height: 14px;
}

.between::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--mark) - 0.5px);
  border-left: 1px solid var(--leader);
}

/* Under the lower plate: its stretches. A plain list here; a dimension line where there is room for one. */
.spans {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.spans li {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: baseline;
}

.spans .painted .what {
  color: var(--bright);
}

/* In the engraving face 03:41 reads as 03:4I: the times are set in the monospace. */
.spans .when {
  color: var(--text);
  font: 400 12px / 22px var(--mono);
}

.spans .bare .when,
.spans .second .when {
  color: var(--quiet);
}

/* The first stretch was played before this scale begins: it is on the rail only, so it is named, not measured. */
.spans .earlier .what::before {
  content: "←";
  content: "←" / "Earlier:";
  flex: none;
  margin-inline-end: 6px;
  border: 0;
  font-family: var(--body);
  letter-spacing: 0;
}

.record .told-row {
  margin-top: 22px;
}

.record .label {
  margin-bottom: 6px;
}

.told pre {
  margin: 0;
  color: var(--bright);
  font: 400 13px / 22px var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* A stretch of time, or an attribute with its value, is not broken in two. */
.told pre span,
.usage pre span {
  white-space: pre;
}

/* A browser sets code in its own fixed face; here it takes the one its box names. */
.told pre code,
.usage pre code {
  font-family: inherit;
}

.told p {
  margin-top: 10px;
  color: var(--quiet);
}

.at-full {
  display: none;
}

@media (min-width: 760px) {
  .record {
    --x0: 0;
    --x1: 1;

    margin-top: 26px;
  }

  .stack .wide {
    display: block;
  }

  .stack .narrow {
    display: none;
  }

  .cap {
    grid-row: 1;
    grid-column: 1;
    padding-inline-end: var(--gutter);
  }

  .flag-mark,
  .flag-rail {
    grid-row: 1;
  }

  .between {
    display: grid;
    grid-template-columns: var(--back) minmax(0, 1fr);
    padding-top: 18px;
  }

  .flag-back {
    display: block;
    grid-column: 2;
    padding-bottom: 12px;
  }

  /* The dimension line: its columns are the stretches themselves. */
  .spans {
    display: grid;
    position: relative;
    grid-template-columns:
      var(--a0) calc(var(--mark) - var(--a0)) calc(var(--b0) - var(--mark)) calc(var(--second) - var(--b0))
      minmax(0, 1fr);
    margin: 0;
  }

  /* One row, in the order of the source: what lies left of the scale, the three stretches on it, the second mark. */
  .spans li {
    display: block;
    position: relative;
    grid-row: 1;
    min-width: 0;
    padding-top: 9px;
    text-align: center;
  }

  /* A tick where a stretch begins. Under the mark it is the hairline going on, placed by the same sum. */
  .spans::before,
  .spans li::before {
    content: "";
    position: absolute;
    top: 0;
    left: -0.5px;
    height: 22px;
    border-left: 1px solid var(--leader);
  }

  .spans::before {
    left: calc(var(--mark) - 0.5px);
  }

  /* The name stands in the line it measures. A painted stretch is drawn in paint. */
  .spans .what {
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 12px;
    white-space: nowrap;
  }

  .spans .what::before,
  .spans .what::after {
    content: "";
    flex: 1 1 0;
    border-top: 1px solid var(--leader);
  }

  .spans .what::after {
    margin-inline-start: -0.14em; /* the tracking after the last letter */
  }

  .spans .painted .what::before,
  .spans .painted .what::after {
    border-color: var(--bright);
  }

  .spans .when {
    display: block;
    margin-top: 8px;
    font-size: 11px;
    line-height: 14px;
  }

  /* The second mark is a point, not a stretch: a name beside its hairline, like the names above. */
  .spans .second {
    margin-left: -0.5px;
    padding-left: 8px;
    border-left: 1px solid var(--leader);
    text-align: start;
  }

  /* The bare stretch begins under the mark, where the hairline already stands. */
  .spans .bare::before,
  .spans .second::before,
  .spans .second .what::before,
  .spans .second .what::after {
    content: none;
  }

  .spans .second .what {
    display: block;
    white-space: normal;
  }

  /* No tick and no line: it begins on the first line of the grid and points off the scale. */
  .spans .earlier {
    text-align: start;
  }

  .spans .earlier::before,
  .spans .earlier .what::after {
    content: none;
  }

  .spans .earlier .what::before {
    margin: 0;
  }
}

@media (min-width: 900px) {
  .more {
    display: inline;
  }
}

/* ---------------------------------------------------------------- underneath */

.under .facts {
  margin-top: 16px;
}

/* What was run is painted; what was not is left bare. The words say it first. */
.facts .run dt,
.facts .run dd {
  color: var(--bright);
}

.facts .not-run dd {
  color: var(--quiet);
}

/* ---------------------------------------------------------------- keys, or touch */

.keyboard dl {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  margin: 0;
}

.keyboard dl > div {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: baseline;
  padding: 8px 0 9px;
  border-top: 1px solid var(--line);
}

.keyboard dl > .own,
.touch .facts > div:first-child {
  padding-top: 0;
  border-top: 0;
}

.keyboard dt {
  white-space: nowrap;
}

.keyboard dd {
  margin: 0;
  color: var(--quiet);
}

.keyboard .own dd {
  color: var(--bright);
}

@media (max-width: 699px) {
  .touch .facts > div {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    align-items: baseline;
  }

  .touch .facts dt {
    margin: 0;
  }
}

@media (min-width: 760px) {
  .keyboard dl {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .keyboard .own {
    grid-column: 1 / -1;
  }
}

/* ---------------------------------------------------------------- use it */

/* A box no wider than its longest line; on a narrow screen a long line wraps, and nothing scrolls. */
.usage pre {
  width: fit-content;
  max-width: 100%;
  margin: 14px 0 0;
  padding: 14px 12px;
  border-radius: 8px;
  background: #0a0a0b;
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--bright);
  font: 400 11px / 18px var(--mono);
  tab-size: 2;
  white-space: pre-wrap;
}

.usage .label {
  margin-top: 18px;
}

/* Names in columns, never broken. At most four to a row, so the longest one is never in a column it overruns. */
.props {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(max(172px, 25%), 1fr));
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.props code {
  color: var(--bright);
  font: 400 13px / 24px var(--mono);
  white-space: nowrap;
}

@media (min-width: 600px) {
  .usage pre {
    padding: 16px 20px;
    font-size: 13px;
    line-height: 21px;
  }
}

/* ---------------------------------------------------------------- the name */

/* The page ends in the voice it began with: the lede's face and size. */
.defs {
  margin: 0;
  color: var(--bright);
  font: 400 clamp(18px, 5vw, 22px) / 1.36 var(--display);
  letter-spacing: 0.01em;
}

/* On a narrow screen a definition folds into two even lines, not a line and a word. */
.defs > div {
  text-wrap: balance;
}

.defs > div + div {
  margin-top: 6px;
}

.defs dt,
.defs dd {
  display: inline;
  margin: 0;
}

.name .form {
  margin-top: 10px;
  color: var(--quiet);
}

/* ---------------------------------------------------------------- colophon */

.colophon {
  color: var(--text);
  font-size: 15px;
}

/* A link is bright and underlined; the line under it is one that carries meaning, so it is drawn as one. */
.colophon a {
  color: var(--bright);
  text-decoration-color: var(--leader);
}

.links {
  margin: 0;
  padding: 0;
  list-style: none;
}

.links li + li {
  margin-top: 6px;
}

.credits {
  margin-top: 18px;
}

.colophon .credits p + p {
  margin-top: 10px;
}

/* A line that goes on from the one above it: where the film is hosted, what Witness is licensed under. */
.colophon .credits .on {
  margin-top: 0;
}

.colophon .credits .by {
  margin-top: 18px;
}

.colophon .back a {
  color: var(--quiet);
}

.colophon .back a:hover {
  color: var(--bright);
}

/* ---------------------------------------------------------------- the four columns */

@media (min-width: 1000px) {
  :root {
    --gutter: 32px;
  }

  /* The idea begins on the axis. */
  .masthead {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
    margin-bottom: 22px;
  }

  .lede {
    font-size: 22px;
    line-height: 30px;
  }

  .try {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-top: 30px;
  }

  .try-head {
    padding-inline-end: var(--gutter);
  }

  .try h2,
  .try h3 {
    margin-bottom: 12px;
  }

  /* The note keeps the lines of the steps beside it: the action's, then the first line under it. */
  .try-head p {
    margin-top: -1px;
    line-height: 28px;
  }

  .try ol {
    grid-column: 2 / -1;
    margin: 0;
  }

  /* An action is one line: it may run into the gutter, not onto a second line, and it stops short of the next. */
  .try li .do {
    margin-inline-end: calc(12px - var(--gutter));
    letter-spacing: -0.01em;
  }

  .sec {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: baseline;
    margin-top: 64px;
    padding-top: 28px;
  }

  /* On the axis, unless it is a label, a ledger or a plate. */
  .sec > * {
    grid-column: 3 / -1;
    min-width: 0;
  }

  .sec > h2,
  .sec > .sec-head {
    grid-column: 1;
    margin: 0;
    padding-inline-end: var(--gutter);
  }

  /* The note stands on the first row of keys under Z, clear of the rule between the two. */
  .sec-head p {
    margin: 17px 0 0;
  }

  .sec > .facts,
  .sec > .defs,
  .keyboard dl {
    grid-column: 2 / -1;
  }

  .sec > .record {
    grid-column: 1 / -1;
  }

  /* The first screen at 1440 x 900 ends with the three steps: the rule that opens the rest stands below it.
     The keys follow the steps (one of the two is shown, by input), so the rule is theirs. */
  .sec.keyboard,
  .sec.touch {
    margin-top: 72px;
  }

  .sec > .links,
  .usage .label {
    grid-column: 2;
    padding-inline-end: var(--gutter);
  }

  /* A sentence to a line. */
  .lead span,
  .told p > span {
    display: block;
  }

  .record .told-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: baseline;
    margin-top: 26px;
  }

  .record .label {
    grid-column: 2;
    margin: 0;
    padding-inline-end: var(--gutter);
  }

  .told {
    grid-column: 3 / -1;
  }

  .under .facts,
  .props {
    margin-top: 18px;
  }

  /* The names stand on the third and fourth lines. */
  .props {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .keyboard .own {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  }

  /* The larger line sets the row's baseline: the label keeps the drop under its rule that every other label has. */
  .sec.name {
    padding-top: 23px;
  }

  .defs {
    font-size: 22px;
    line-height: 30px;
  }

  .defs > div {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  }

  .defs > div + div {
    margin-top: 0;
  }

  .defs dt,
  .defs dd {
    display: block;
  }

  .name .form {
    margin-top: 12px;
  }

  /* Both columns of the colophon keep one set of lines, 24 px apart; a blank line parts film, type and author. */
  .links li + li {
    margin-top: 0;
  }

  .credits {
    margin-top: 0;
  }

  .colophon .credits p + p,
  .colophon .credits .by {
    margin-top: 24px;
  }

  .colophon .credits .back {
    margin-top: 12px;
  }
}

/* True only where the plates are 1120 px across. */
@media (min-width: 1168px) {
  .at-full {
    display: inline;
  }
}

/* ---------------------------------------------------------------- said for the hand that is there */

/* Keys and a pointer, or a finger: a screen with no keyboard is not told to press Z, nor shown a table of keys. */
@media (hover: none) and (pointer: coarse) {
  .no-touch {
    display: none !important;
  }
}

@media not all and (hover: none) and (pointer: coarse) {
  .touch-only {
    display: none !important;
  }
}

/* ---------------------------------------------------------------- what the visitor has asked for */

@media (prefers-contrast: more) {
  :root {
    --quiet: var(--text);
    --line: rgb(244 241 234 / 0.3);
    --leader: rgb(244 241 234 / 0.75);
  }

  /* The options keep their published colours: an option not chosen stays quiet, so the chosen one stands out. */
  .bench {
    --quiet: #8f8c86;
  }

  /* With every line brighter, the bare stretch is told from the painted ones by its line as well as its name. */
  .spans .bare .what::before,
  .spans .bare .what::after {
    border-top-style: dashed;
  }
}

@media (forced-colors: active) {
  /* What was drawn with a shadow is drawn with a line. */
  kbd,
  .usage pre,
  .stack img {
    outline: 1px solid;
    outline-offset: -1px;
  }

  /* The chosen option is filled, so the focus ring is still free to show. */
  .bench input:checked + span {
    background: Highlight;
    color: HighlightText;
    forced-color-adjust: none;
  }

  .bench input:focus-visible + span {
    outline-color: CanvasText;
  }

  /* Bare stays distinct from painted, and not run from run. */
  .facts .not-run dd,
  .spans .bare .what,
  .spans .bare .when {
    color: GrayText;
  }

  .spans .bare .what::before,
  .spans .bare .what::after {
    border-top-style: dashed;
    border-color: GrayText;
  }
}
