/* Ink, paper and greys. The one colour on the page is --zoop, and the one thing
   that wears it is the flourish when a curve comes home to the circle.
   The canvas reads --bg, --tube, --ramp and --zoop, so those are six-digit hex. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --fg: #24292e;
  --muted: #6a737d;
  --line: #eaecef;
  --zoop: #0366d6;
  --veil: rgba(255, 255, 255, 0.95);
  --tube: #383e45;
  --ramp: #c9ced4 #949ba3 #565d66 #15181c;
}

/* The rest of the site is always white, so dark is by request only. */
:root[data-theme=dark] {
  color-scheme: dark;
  --bg: #0d1117;
  --fg: #c9d1d9;
  --muted: #8b949e;
  --line: #21262d;
  --zoop: #58a6ff;
  --veil: rgba(13, 17, 23, 0.95);
  --tube: #b4bcc5;
  --ramp: #3a424c #68717c #a0a9b3 #f0f3f6;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 13px;
  line-height: 1.55;
  color: var(--fg);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

#view, .paper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh; /* what is left once the browser's own bars are out */
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  outline: none;
}
/* the line drawing that stands in for WebGL; the canvas under it keeps the pointer */
.paper { pointer-events: none; }

a { color: var(--fg); text-decoration: none; }
a:hover { text-decoration: underline; }
.sorry a { text-decoration: underline; }
i { font-family: Georgia, "Times New Roman", serif; }

button, input, output { font: inherit; color: inherit; }

/* Ink is for what can be pressed, grey for what can only be read. */
button {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  color: var(--fg);
  cursor: pointer;
  text-align: left;
}
button:hover { text-decoration: underline; }
button:disabled { color: var(--muted); opacity: 0.6; cursor: default; text-decoration: none; }
:focus-visible { outline: 1.5px solid var(--fg); outline-offset: 3px; border-radius: 1px; }

/* Name at the top, readout at the bottom, nothing in between. The column lets
   clicks through to the canvas except on its own contents. */
#ui {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 304px;
  padding: 26px 32px 28px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow-y: auto;
  scrollbar-width: none;
  pointer-events: none;
  transition: opacity 0.25s;
}
#ui::-webkit-scrollbar { display: none; }
#ui > * > * { pointer-events: auto; }
body.bare #ui { opacity: 0; }
body.bare #ui * { pointer-events: none; }

.home { font-size: 15px; font-weight: 600; letter-spacing: -0.3px; color: var(--fg); }

h1 {
  margin: 2px 0 0;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  white-space: nowrap;
}
h1 button { margin-left: 6px; }

#dock { display: flex; flex-direction: column; flex: none; margin-top: 24px; }

.energy {
  font-size: 28px;
  font-weight: 300;
  line-height: 1.1;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}
.energy i { font-size: 20px; margin-right: 9px; color: var(--muted); }

.chart { position: relative; height: 44px; margin-top: 10px; }
#spark { display: block; width: 100%; height: 100%; overflow: visible; }
#spark .ref { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; transition: stroke 0.6s; }
#spark .ref.lit { stroke: var(--fg); }
#trace {
  fill: none;
  stroke: var(--fg);
  stroke-width: 1.1;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.chart span {
  position: absolute;
  right: 0;
  padding-left: 4px;
  font-size: 9.5px;
  line-height: 1;
  color: var(--muted);
  background: var(--bg);
  transform: translateY(-50%);
  pointer-events: none;
}

/* The running commentary, for whoever points at the readout. */
.note {
  margin-top: 8px;
  height: 1.55em;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.25s;
}
.readout:hover .note { opacity: 1; }

/* margins, not gap: flex gap is newer than the rest of this page needs */
.bar { display: flex; align-items: baseline; margin-top: 4px; }
.bar > * + * { margin-left: 16px; }

/* Under the picture, as under a figure in a paper: what it is, and on a second
   line whatever has just been found out about it. */
#ui #caption {
  position: fixed;
  bottom: 82px;
  left: 304px;
  right: 304px;
  text-align: center;
  pointer-events: none;
}
#kind { font-size: inherit; color: var(--muted); }
.says { min-height: 1.55em; font-size: 12px; color: var(--muted); }
#verdict { transition: opacity 0.5s; }
#verdict.good, #verdict.good.fresh { color: var(--fg); }
/* what to see next, once the show is over */
#next { display: none; margin-left: 12px; color: var(--fg); pointer-events: auto; white-space: nowrap; }
#next.on { display: inline; animation: rise 0.8s; }
#next small { font-size: inherit; color: var(--muted); }
#next b { font-weight: 400; }
@keyframes rise { from { opacity: 0; } }

/* Like the controls of a film: while the curve is flowing and nobody stirs, all
   that can be pressed bows out, and is back at the first sign of life. A remark
   that has only just been made stays to be read. */
.fades { transition: opacity 0.15s, visibility 0.15s; }
body[data-idle] .fades { opacity: 0; visibility: hidden; transition: opacity 0.5s, visibility 0.5s; }
body[data-idle] #verdict { opacity: 0; }
body[data-idle] #verdict.fresh { opacity: 1; }

/* The drawer opens upwards, above the readout, which stays where it is. */
.drawer {
  order: -3;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

/* The other curves: a row of small knot diagrams under the picture, as in the
   table at the back of a book. Grey, but for the one on show. */
#ui #presets {
  position: fixed;
  bottom: 14px;
  left: 304px;
  right: 304px;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
/* those that come undone, those that cannot, and pot luck */
#presets > div { position: relative; flex: none; display: flex; margin: 0 12px; padding-bottom: 15px; }
#presets div small {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 0.04em;
  text-align: center;
  color: var(--muted);
}
#ui #presets a, #ui #presets button {
  position: relative;
  flex: none;
  width: 36px;
  height: 38px;
  margin: 0 4px;
  padding: 0 0 2px;
  border-bottom: 1px solid transparent;
  color: var(--muted);
  opacity: 0.75;
  pointer-events: auto;
  transition: color 0.2s, opacity 0.2s;
}
#presets svg {
  display: block;
  width: 36px;
  height: 36px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.2;
  stroke-linejoin: round;
}
#ui #presets :hover, #ui #presets :focus-visible, #ui #presets .on { color: var(--fg); opacity: 1; text-decoration: none; }
#ui #presets .on { border-bottom-color: var(--fg); }
#surprise { font: italic 19px/36px Georgia, "Times New Roman", serif; text-align: center; }
/* the name, over whichever is pointed at */
#presets a::after, #presets button::after {
  content: attr(aria-label);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 1px 6px 5px;
  background: var(--bg);
  font: 11px/1.3 -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--muted);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
#presets :hover::after, #presets :focus-visible::after { opacity: 1; }

#panel { color: var(--muted); }
.row { display: flex; align-items: center; min-height: 22px; }
.row.gap { margin-top: 8px; }
.row > :first-child { width: 72px; flex: none; }
.row > * + * + * { margin-left: 12px; }
.row input[type=range] { flex: 1; min-width: 0; }
#auto + input { margin-left: 16px; }
.row output { min-width: 1.9em; text-align: right; font-variant-numeric: tabular-nums; }
.set { display: flex; }
.set > * + * { margin-left: 12px; }
.set[data-key] button, #auto { color: var(--muted); }
.set[data-key] button:hover, #auto:hover { color: var(--fg); text-decoration: none; }
.set button[aria-pressed=true], #auto[aria-pressed=true] { color: var(--fg); font-weight: 600; }

input[type=range] {
  appearance: none;
  -webkit-appearance: none;
  height: 14px;
  margin: 0;
  background: none;
  cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track { height: 1px; background: var(--muted); opacity: 0.5; }
input[type=range]::-moz-range-track { height: 1px; background: var(--muted); opacity: 0.5; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 9px; height: 9px; margin-top: -4px;
  border-radius: 50%; border: 0; background: var(--fg);
}
input[type=range]::-moz-range-thumb { width: 9px; height: 9px; border-radius: 50%; border: 0; background: var(--fg); }
/* on automatic the slider only reports */
input[type=range].idle::-webkit-slider-thumb { background: var(--muted); }
input[type=range].idle::-moz-range-thumb { background: var(--muted); }

input[type=number], input[type=text] {
  appearance: textfield;
  -moz-appearance: textfield;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 0;
  color: var(--fg);
  text-align: center;
}
input[type=number] { width: 1.7em; margin: 0 2px; }
input[type=text] { flex: 1; min-width: 0; text-align: left; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number]:focus, input[type=text]:focus { outline: none; border-bottom-color: var(--fg); }
input.bad { border-bottom: 1px dashed var(--fg); }
::placeholder { color: var(--muted); opacity: 0.6; }

/* What a word or a number means, for whoever points at it, tabs to it or taps it. */
#tip {
  position: fixed;
  z-index: 2;
  max-width: 260px;
  padding: 8px 11px 9px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  pointer-events: none;
  animation: rise 0.15s;
}
[data-tip] { cursor: help; }
[data-tip] button, [data-tip] input, [data-tip] label { cursor: pointer; }
[data-tip] input[type=text], [data-tip] input[type=number] { cursor: text; }
#verdict[data-tip]:hover, .row[data-tip]:hover > :first-child, #title[data-tip]:hover {
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
#ui #caption #verdict, #ui #caption #title[data-tip] { pointer-events: auto; }

#help {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow-y: auto;
  padding: 26px 32px;
  background: var(--veil);
}
.sheet { max-width: 500px; margin: 8vh auto 0; color: var(--fg); }
.sheet p { margin: 0 0 12px; }
.sheet .formula { margin: 16px 0; text-align: center; font-size: 15px; }
.sheet sup { line-height: 0; }
.sheet dl {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 1px 16px;
  margin: 22px 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.sheet dt { white-space: nowrap; }
.sheet dd { margin: 0; color: var(--muted); }

.sorry { position: fixed; top: 40%; left: 0; right: 0; margin: 0; padding: 0 16px; text-align: center; color: var(--muted); }

/* Fingers: everything that can be pressed is at least 40 px tall, by padding,
   so that the type stays small. */
@media (pointer: coarse), (max-width: 720px) {
  .home, h1 button, .bar button, .set button, #auto, #help-close {
    padding-top: 11px;
    padding-bottom: 11px;
    touch-action: manipulation;
  }
  .home { display: inline-block; margin: -11px 0; }
  h1 { margin-top: 0; }
  h1 button { margin: -11px 0 -11px 2px; padding-left: 8px; padding-right: 8px; }
  .bar { margin: 0 0 -11px; }
  .bar button { min-width: 44px; }
  .bar > * + * { margin-left: 12px; }
  #more { text-align: right; }
  .bar, .drawer { font-size: 14px; }
  #ui #presets a, #ui #presets button { width: 40px; height: 42px; margin: 0; padding: 2px 2px 3px; touch-action: manipulation; }
  #presets > div { margin: 0 3px; }
  #surprise { line-height: 38px; }
  #next { padding: 11px 0; }
  .row { min-height: 42px; }
  .row.gap { margin-top: 0; }
  .row > :first-child { width: 84px; }
  .set > * + * { margin-left: 0; }
  .set button { padding-right: 16px; }
  input[type=range] { height: 40px; }
  input[type=range]::-webkit-slider-thumb { width: 15px; height: 15px; margin-top: -7px; }
  input[type=range]::-moz-range-thumb { width: 15px; height: 15px; }
  /* iOS zooms the page in on any field set smaller than this */
  input[type=number], input[type=text] { font-size: 16px; padding: 8px 0; }
  input[type=number] { width: 2em; }
}

/* Narrow windows: the same two blocks, pinned to the top and bottom edges and
   kept clear of notches and home bars. */
@media (max-width: 720px) {
  #ui { position: static; width: auto; padding: 0; overflow: visible; display: block; }
  #intro {
    position: fixed;
    top: 0; left: 0; right: 0;
    padding: 14px 16px 0;
    padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  }
  #dock {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    margin: 0;
    padding: 10px 16px 12px;
    padding: 10px max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    max-height: 82vh;
    max-height: 82dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: var(--veil);
    pointer-events: auto;
  }
  /* the strip joins the dock, and slides sideways if it has to */
  #ui #presets {
    position: static;
    order: -1;
    justify-content: flex-start;
    margin: 0 -16px 12px;
    padding: 0 4px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    pointer-events: auto;
  }
  #presets::-webkit-scrollbar { display: none; }
  #presets a::after, #presets button::after { display: none; }
  #ui #caption { position: static; order: -2; margin: 0 0 4px; pointer-events: auto; }
  /* with the drawer open there is not room for everything, and the curve comes first */
  #ui #dock[data-open] #caption, #ui #dock[data-open] #presets { display: none; }
  .readout { display: grid; grid-template-columns: auto 1fr; column-gap: 18px; align-items: end; }
  .energy { font-size: 24px; }
  .energy i { font-size: 18px; margin-right: 7px; }
  .chart { height: 30px; margin: 0; }
  .chart span { display: none; }
  .note { display: none; }
  /* never so tall as to crowd out the curve it is there to change */
  .drawer {
    margin-bottom: 12px;
    padding-bottom: 8px;
    max-height: 48vh;
    max-height: 48dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  #help { padding: 16px; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
  .sheet { margin-top: 0; }
  .sheet dl { grid-template-columns: auto 1fr; }
}

/* Wide but short, as a phone on its side: no room above the readout, so the
   drawers open beside it, as a second column. */
@media (min-width: 721px) and (max-height: 520px) {
  #ui {
    padding: 16px 24px 16px 32px;
    padding: 16px 24px max(16px, env(safe-area-inset-bottom)) max(32px, env(safe-area-inset-left));
    width: 296px;
    width: calc(264px + max(32px, env(safe-area-inset-left)));
    overflow: visible;
  }
  .chart { height: 30px; }
  #ui #presets { bottom: 4px; bottom: max(4px, env(safe-area-inset-bottom)); overflow-x: auto; scrollbar-width: none; pointer-events: auto; }
  #presets a::after, #presets button::after, #presets div small { display: none; }
  #presets > div { padding-bottom: 0; }
  /* and the caption keeps to one line */
  #ui #caption { bottom: 50px; bottom: calc(46px + max(4px, env(safe-area-inset-bottom))); }
  #caption > div { display: inline; }
  .says { margin-left: 10px; }
  .drawer {
    position: fixed;
    top: 0; bottom: 0;
    left: 296px;
    left: calc(264px + max(32px, env(safe-area-inset-left)));
    width: 330px;
    margin: 0;
    padding: 12px 20px;
    border-bottom: 0;
    border-left: 1px solid var(--line);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
