/* The calculator page. Loaded after ../style.css, which owns the colour tokens. */

:root {
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  /* The editor and the gutter are separate elements showing the same lines side by side,
     so their line box has to be identical to the pixel. Both read these two values and
     nothing else is allowed to set a line-height inside the sheet. */
  --mono-size: 15px;
  --line-h: 26px;
}

.app { max-width: 1100px; padding-top: 28px; padding-bottom: 48px; }

.sheet {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(38%, auto);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 0;
  overflow: hidden;
}

#editor, #gutter { font: var(--mono-size)/var(--line-h) var(--mono); }

#editor {
  margin: 0;
  padding: 0 14px 0 18px;
  border: 0;
  outline: 0;
  resize: none;
  /* No scrollbars in either direction. A horizontal one would sit on top of the last
     line and throw the editor off the gutter's line grid; the caret still scrolls a long
     line into view when you arrow along it. */
  overflow: hidden;
  background: transparent;
  color: var(--text);
  tab-size: 2;
}

#editor::placeholder { color: var(--faint); }

#gutter {
  padding: 0 18px 0 14px;
  border-left: 1px solid var(--line);
  text-align: right;
  color: var(--muted);
  overflow: hidden;
}

#gutter .row {
  height: var(--line-h);
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
}

#gutter .value { color: var(--accent-ink); font-weight: 560; }
#gutter .error { color: #b4452f; font-size: 13px; }
#gutter .incomplete { color: var(--faint); }

@media (prefers-color-scheme: dark) {
  #gutter .error { color: #e08a72; }
}

/* The stacked result list, for screens too narrow to show a gutter beside the line. */

.results { display: none; }

/* On a template page the same list is prose, not a fallback, so it always shows. */
.results.always { display: block; margin: 10px 0 4px; }

.results .item {
  display: flex;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
  padding: 7px 2px;
  border-bottom: 1px solid var(--line);
}

.results .item:last-child { border-bottom: 0; }
.results .label { color: var(--muted); font-size: 14px; }
.results .text {
  font: 500 14px/1.4 var(--mono);
  color: var(--accent-ink);
  text-align: right;
}
.results .error .text { color: #b4452f; font-size: 13px; }

@media (prefers-color-scheme: dark) {
  .results .error .text { color: #e08a72; }
}

/* The headline: the one answer, said in a sentence, with its shape drawn beside it. */

.headline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 12px 36px;
  align-items: center;
  margin: 28px 0 12px;
  padding: 24px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.headline[hidden], .headline [hidden] { display: none; }
.headline p { margin: 0; }
.headline .says { color: var(--muted); font-size: 16px; }

.headline .big {
  font-size: clamp(28px, 4.2vw, 40px);
  font-weight: 680;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 4px 0 6px;
  color: var(--accent-ink);
  font-variant-numeric: tabular-nums;
}

.headline .mid { color: var(--muted); font-size: 14px; }
.headline .verdict { margin-top: 14px; font-size: 16px; }
.headline .verdict strong { color: var(--accent-ink); font-weight: 680; }

.histogram { width: 100%; height: auto; display: block; overflow: visible; }
.histogram .bar { fill: var(--accent); opacity: 0.28; }
.histogram .bar.inside { opacity: 1; }
.histogram .axis { stroke: var(--line); stroke-width: 1; }
.histogram .median { stroke: var(--accent-ink); stroke-width: 1.5; stroke-dasharray: 3 3; }
/* viewBox units, not pixels: the drawing is scaled to its column, so this lands near 11px. */
.histogram .tick { font: 17px var(--mono); fill: var(--muted); }
.histogram .tick.mid { fill: var(--accent-ink); font-weight: 600; }

@media (max-width: 760px) {
  .headline { grid-template-columns: minmax(0, 1fr); padding: 20px; }
}

/* The calculator view on template pages: fields on the left, what follows on the right. */

.calc {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 8px 44px;
  align-items: start;
  margin: 4px 0 8px;
}

.calc h2 { margin: 24px 0 4px; }
.calc .small { margin-bottom: 8px; }

.inputs .input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  align-items: center;
  padding: 7px 2px;
  border-bottom: 1px solid var(--line);
}

.inputs .input-row:last-child { border-bottom: 0; }
.inputs .label { color: var(--muted); font-size: 14px; }
.inputs .fields { display: flex; align-items: center; gap: 6px; justify-self: end; }
.inputs .field { display: inline-flex; align-items: baseline; gap: 4px; }
.inputs .affix, .inputs .to { font: 14px/1.4 var(--mono); color: var(--faint); white-space: nowrap; }
.inputs .to { padding: 0 2px; }

.inputs input {
  font: 500 14px/1.4 var(--mono);
  color: var(--accent-ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  text-align: right;
  /* `size` sets the width in characters; this stops a long number pushing the row out. */
  max-width: 9em;
  min-width: 0;
}

.inputs input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.inputs input[aria-invalid="true"] { border-color: #b4452f; color: #b4452f; }

/* Only an error, or a line the fields cannot reach, has anything to say here. */
.inputs .text { grid-column: 1 / -1; font: 13px/1.4 var(--mono); color: var(--muted); text-align: right; }
.inputs .text:empty { display: none; }
.inputs .error .text { color: #b4452f; }

/* The lists above already say everything the narrow fallback list would. */
.template #results { display: none; }

@media (prefers-color-scheme: dark) {
  .inputs input[aria-invalid="true"], .inputs .error .text { color: #e08a72; border-color: #e08a72; }
}

@media (max-width: 760px) {
  .calc { grid-template-columns: minmax(0, 1fr); }
}

/* Controls */

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

button.primary {
  font: inherit;
  font-weight: 560;
  font-size: 15px;
  padding: 9px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button.primary:hover { background: var(--accent-ink); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }

button.chip {
  font: inherit;
  font-size: 14px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

button.chip:hover { border-color: var(--accent); color: var(--accent-ink); }

.status { margin: 12px 2px 0; font-variant-numeric: tabular-nums; }

.notes { margin-top: 40px; }
.notes h2 { font-size: 19px; margin-bottom: 6px; }

@media (max-width: 640px) {
  :root { --mono-size: 13.5px; --line-h: 24px; }
  .sheet { grid-template-columns: minmax(0, 1fr); }
  #gutter { display: none; }
  .results { display: block; margin-top: 14px; }
  #editor { padding-left: 14px; padding-right: 14px; }
  .chips { margin-left: 0; }
}
