:root {
  /* layout: the page fills the window in three bands. A small bar for choosing the proof with the mathematics under it,
     the phrase stream, and the 3D figure, which takes all the height that is left. The theorem pane slides over the right
     on T, the properties over the bottom on P. The menu at the lower left stays on top of all of them. */
  --ground: #050505;
  --ink: #f4f4f1;
  --ink-dim: #a9a9a4;
  --ink-faint: #666661;
  --rule: #2b2b28;
  --font-text: "VT323", "Cousine", "Courier New", "DejaVu Sans Mono", monospace;
  --font-mono: "Cousine", "Courier New", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  /* the notation is set like a mathematics book: a serif text face for letters, a mathematics face for the symbols */
  --font-math: "STIX Two Text", "STIX Two Math", "Cambria Math", "Latin Modern Math", "Times New Roman", "DejaVu Serif", serif;
  --gutter: clamp(12px, 2vw, 28px);
  /* sizes follow the window, in this order of weight: the figure, the mathematics, the phrase stream, the top bar */
  --math: clamp(20px, min(3.1vw + 6px, 5vh), 56px);
  --stream: clamp(13px, min(0.45vw + 9.5px, 2.2vh), 19px);
  --bar: clamp(13px, 0.3vw + 10.5px, 15px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { height: 100%; }
html, body { margin: 0; }

body {
  display: grid;
  min-height: 100vh;
  grid-template-rows: auto auto minmax(max(56vh, 280px), 1fr);
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 18px;
  font-weight: 400;
  font-synthesis: none;
  line-height: 1.22;
  overflow-x: hidden;
}

.eyebrow {
  margin: 0;
  color: var(--ink-dim);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 14px;
  font-weight: 400;
}

@supports (height: 100dvh) {
  body { min-height: 100dvh; grid-template-rows: auto auto minmax(max(56dvh, 280px), 1fr); }
}

/* ---- band 1: a small bar to choose the proof, and the mathematics ---- */

.proof {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: 4px;
  padding: 7px var(--gutter) 8px;
  text-align: center;
}
.ident { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 8px; max-width: 100%; }
.ident select, .ident button { font-size: var(--bar); padding: 3px 8px; color: var(--ink-dim); border-color: var(--rule); }
.ident select { max-width: min(100%, 58ch); }
.ident select:hover, .ident button:hover, .ident select:focus-visible { color: var(--ink); border-color: var(--ink-faint); }
.ident button[aria-pressed="true"] { color: var(--ground); }

/* the symbolic stream: the notation of the last symbols read, the newest largest */
.symbolic {
  width: 100%;
  max-width: 34em;
  height: 2.95em;
  font-size: var(--math);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 0.05em;
  font-family: var(--font-math);
}
/* π-rough sans: the same notation, upright, in a sans-serif */
html.sans { --font-math: "Inter", "Noto Sans Math", "Helvetica Neue", "Segoe UI", Arial, "DejaVu Sans", sans-serif; }
html.sans .symbolic i, html.sans .line .symc i { font-style: normal; }
.symbolic, .line .symc { font-synthesis: style; }      /* if the italic face is missing, slant the upright one */
.symbolic i, .line .symc i { font-style: italic; }
.symbolic .sym.lean { font-family: var(--font-mono); }
.symbolic .sym {
  flex: none;
  max-width: 100%;
  opacity: 0.25;
  font-size: 0.42em;
  line-height: 1.25;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-wrap: balance;
}
.symbolic .sym:nth-last-child(2) { opacity: 0.5; font-size: 0.54em; }
.symbolic .sym:last-child { opacity: 1; font-size: 1em; line-height: 1.15; }
.symbolic .sym.l:last-child { font-size: 0.74em; }          /* long lines step down so that they stay on the page */
.symbolic .sym.xl:last-child { font-size: 0.56em; }
.symbolic .sym.lean { font-size: 0.36em; }
.symbolic .sym.lean:nth-last-child(2) { font-size: 0.42em; }
.symbolic .sym.lean:last-child { font-size: 0.6em; }

h1 {
  margin: 0;
  font-family: var(--font-text);
  font-weight: 700;
  font-size: 22px;
  line-height: 1;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.field { display: grid; gap: 3px; }
select, input[type="range"] { max-width: 100%; }
select {
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: var(--ground);
  border: 1px solid var(--ink-faint);
  padding: 5px 8px;
  cursor: pointer;
}
select:hover { border-color: var(--ink); }
select:focus-visible, input:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

.source {
  margin: 0;
  max-width: 100%;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 14.5px;
  font-weight: 400;
  line-height: 1.7;
  text-align: left;                 /* the block is centred, its lines keep their indentation */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 8.6em;
  overflow-y: auto;
}
.source span { transition: background-color 120ms, color 120ms; }
.source .ln { display: block; min-height: 1.7em; }
.source .on { background: var(--ink); color: var(--ground); }
.source .echo { box-shadow: inset 0 -2px 0 var(--ink); }
.source.qed { background: var(--ink); color: var(--ground); }

/* ---- the theorem pane: hidden until T ---- */
.side {
  position: fixed;
  top: 0; right: 0; bottom: var(--menu-h, 44px);
  z-index: 6;
  width: min(500px, 94%);
  overflow-y: auto;
  padding: 18px var(--gutter) 28px 24px;
  border-left: 1px solid var(--ink-faint);
  background: rgba(5, 5, 5, 0.93);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: grid;
  align-content: start;
  gap: 12px;
}
.side[hidden] { display: none; }
.side-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.side p { margin: 0; }
.side .source { max-height: 48vh; }
.side .says { font-size: clamp(18px, 0.8vw + 13px, 23px); line-height: 1.14; }
.side .how { color: var(--ink-dim); }

/* ---- band 2: the phrase stream, secondary to the mathematics ---- */

.stream {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  padding: 5px var(--gutter);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.stream .eyebrow { padding-top: 3px; font-size: 12px; width: 11ch; color: var(--ink-faint); }

.lines {
  height: 5.9em;                      /* four symbols */
  font-size: var(--stream);
  line-height: 1.42;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 30%);
  mask-image: linear-gradient(to bottom, transparent, #000 30%);
}
.line {
  flex: none;
  display: grid;
  grid-template-columns: 2.2em 3.2em minmax(0, 1.1fr) minmax(0, 0.7fr) minmax(0, 1.6fr);
  gap: 0.9em;
  align-items: baseline;
  opacity: 0.28;
  overflow-wrap: anywhere;
}
.line:nth-last-child(3) { opacity: 0.42; }
.line:nth-last-child(2) { opacity: 0.6; }
.line:last-child { opacity: 1; }
.line .idx, .line .kind, .line .formal, .line .symc { font-family: var(--font-mono); font-size: 0.74em; font-weight: 400; }
.line .symc { font-family: var(--font-math); font-size: 1.06em; white-space: pre-wrap; }
.line .symc.lean { font-family: var(--font-mono); font-size: 0.78em; }
.line .formal { font-size: 0.76em; color: var(--ink-dim); }
.line .english { font-size: 1.14em; }
.line .idx, .line .kind { color: var(--ink-dim); font-variant-numeric: tabular-nums; }

/* ---- band 3: the figure ---- */

.stage { position: relative; min-height: 0; }
#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#stage.dragging { cursor: grabbing; }
/* the menu: fixed at the lower left, above every panel */
.keys {
  position: fixed;
  left: var(--gutter);
  bottom: 8px;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 18px;
  max-width: calc(100% - var(--gutter) * 2 - 13ch);      /* leaves the lower right to the signature */
}
.keys button {
  border: 0;
  padding: 4px 0;
  color: var(--ink-faint);
  font-size: 16px;
}
.keys button:hover { color: var(--ink); }
.keys button[aria-pressed="true"] { background: transparent; color: var(--ink); text-decoration: underline; text-underline-offset: 5px; }
.keys button[aria-pressed="true"] kbd { background: var(--ink); color: var(--ground); border-color: var(--ink); }
/* while a panel is open the menu becomes a bar along the bottom, and the panels end where it begins */
body.has-panel .keys {
  left: 0; right: 0; bottom: 0;
  max-width: none;
  padding: 5px var(--gutter) 7px;
  background: var(--ground);
  border-top: 1px solid var(--ink-faint);
}
kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  border: 1px solid var(--ink-faint);
  padding: 1px 6px;
  margin-right: 7px;
  color: var(--ink-dim);
}
.sig {
  position: absolute;
  right: var(--gutter);
  bottom: 11px;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  pointer-events: none;
}
/* ---- help: opens on H ---- */
.help {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: var(--menu-h, 44px);
  z-index: 10;
  overflow-y: auto;
  padding: 20px var(--gutter) 40px;
  background: var(--ground);
}
.help[hidden] { display: none; }
.help-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; }
.help-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 24px 40px; max-width: 1500px; }
.help h2 {
  margin: 0 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--rule);
  font: inherit;
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.help ul { list-style: none; margin: 0; padding: 0; }
.help p, .help li { margin: 0 0 7px; max-width: 64ch; color: var(--ink-dim); }
.help li { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 8px; align-items: start; }
.help li svg { width: 22px; height: 17px; margin-top: 2px; color: var(--ink); }
.help b { font-weight: 400; color: var(--ink); }
.help .about { grid-column: 1 / -1; padding-top: 16px; border-top: 1px solid var(--rule); }
.help .about p { color: var(--ink); font-size: 21px; line-height: 1.2; max-width: 70ch; }
.help .about .by { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.06em; color: var(--ink-dim); }

.figmsg { position: absolute; left: var(--gutter); top: 12px; margin: 0; color: var(--ink-dim); }

/* ---- the tools: hidden until P ---- */

.desk {
  position: fixed;
  left: 0; right: 0; bottom: var(--menu-h, 44px);
  z-index: 5;
  max-height: 76%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px var(--gutter) 18px;
  border-top: 1px solid var(--ink-faint);
  background: rgba(5, 5, 5, 0.9);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: grid;
  gap: 12px;
}
.desk[hidden] { display: none; }
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px 18px;
}
.controls .spacer { flex: 1 1 0; }
.tempo { display: grid; gap: 3px; min-width: 190px; }
.tempo .row { display: flex; align-items: center; gap: 10px; }
.tempo output { font-family: var(--font-mono); font-size: 12.5px; font-variant-numeric: tabular-nums; min-width: 8ch; }
input[type="range"] { accent-color: #f4f4f1; width: min(130px, 34vw); }
.buttons { display: flex; gap: 8px; flex-wrap: wrap; }

.library {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
}
.library .fit { display: flex; align-items: center; gap: 8px; color: var(--ink-dim); }
.library input[type="number"] {
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: var(--ground);
  border: 1px solid var(--ink-faint);
  padding: 5px 6px;
  width: 5.5ch;
}
.library input[type="text"] {
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: var(--ground);
  border: 1px solid var(--ink-faint);
  padding: 5px 8px;
  width: 220px;
  max-width: 100%;
}
.library .status { margin: 0; flex: 1 1 260px; color: var(--ink-dim); font-family: var(--font-mono); font-size: 12px; overflow-wrap: anywhere; }
body.dropping .stage { outline: 1px dashed var(--ink); outline-offset: -8px; }

.readout {
  display: grid;
  grid-template-columns: minmax(0, 470px) minmax(0, 1fr);
  gap: 14px 28px;
  align-items: start;
}
.info {
  margin: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 1px 14px;
  font-size: 16px;
}
.info dt { color: var(--ink-dim); letter-spacing: 0.1em; text-transform: uppercase; font-size: 13px; padding-top: 1px; }
.info dd { margin: 0; font-family: var(--font-mono); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.lanes {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}
.lanes ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-rows: repeat(6, 20px);
  color: var(--ink-dim);
  font-size: 14px;
}
.lanes li { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.lanes svg { flex: none; width: 18px; height: 14px; color: var(--ink); }
#env { width: 100%; height: 120px; display: block; }

button {
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink-faint);
  padding: 6px 14px;
  cursor: pointer;
  letter-spacing: 0.04em;
}
button:hover { border-color: var(--ink); }
button:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
button[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }
button:disabled { color: var(--ink-faint); cursor: default; border-color: var(--rule); }

/* ---- other windows ---- */

/* a narrower window: the stream keeps the notation and the English */
@media (max-width: 1100px) {
  .stream { grid-template-columns: minmax(0, 1fr); }
  .stream .eyebrow { display: none; }
}
@media (max-width: 900px) {
  .line { grid-template-columns: 2.2em minmax(0, 1fr) minmax(0, 1.25fr); }
  .line .kind, .line .formal { display: none; }
}
/* a phone held upright: each symbol takes two lines, its notation and then its sentence */
@media (max-width: 560px) {
  h1 { font-size: 20px; }
  .ident { flex-wrap: nowrap; width: 100%; }
  .ident select { flex: 1 1 auto; min-width: 0; max-width: none; }
  .ident button { flex: none; }
  .source { font-size: 12.5px; }
  .lines { height: 5.9em; }
  .line { grid-template-columns: 2.2em minmax(0, 1fr); gap: 0 0.7em; }
  .line .english { grid-column: 2; }
  .tempo { min-width: 150px; }
  .lanes li span { display: none; }
  .controls .spacer { display: none; }
}
@media (max-width: 720px) {
  .readout { grid-template-columns: minmax(0, 1fr); }
}
/* a touch screen or a narrow window: the menu shows its words alone, as buttons to tap */
@media (max-width: 560px), (pointer: coarse) {
  .keys { gap: 0 16px; }
  .keys kbd { display: none; }
  .keys button { padding: 9px 0; color: var(--ink-dim); }
}
/* a low window, such as a phone on its side: the figure keeps its share and the text bands give way */
@media (max-height: 620px) {
  .proof { padding-top: 5px; padding-bottom: 5px; }
  .symbolic { height: 2.3em; }
  .lines { height: 2.95em; }
  .desk { max-height: 88%; }
}
