/* SHA-256 Byte Inspector - MIT (c) 2026 ipusiron
 * Drafting-table look: thin single-color lines, monospace numbers, no fills except
 * bit 1 (foreground) and differences (--diff). Dark (blueprint) is the default;
 * theme-init.js (in <head>) sets data-theme on <html> from the saved choice, or dark
 * when none is saved, and app.js changes it when the toggle is pressed.
 * Layout: one page, one column at every width. The main element stacks five
 * numbered cards read top-down (input, input settings, bytes after UTF-8 encoding,
 * the SHA-256 computation, output); from 1280px the column, the header and the
 * footer are 1040px wide and centered. The computation card lays the whole
 * computation out at once (message block, 64 schedule rows, the round with its
 * 64-row table, the final addition, the digest) and the clock moves the emphasis.
 * The clock is fixed to the bottom on the surface color with a thin role-1 rule,
 * and the body keeps room for it through --clock-height (app.js measures the clock
 * at start-up and on resize). The round icon buttons for language, theme and help
 * sit at the right end of the title row; the help opens a <dialog>.
 * Reduced motion follows the OS setting (prefers-reduced-motion) only. */

:root {
  color-scheme: dark;
  --bg: #0d1117;
  --surface: #161d27;
  --fg: #e8eef4;
  --muted: #a7b4c2;
  --line: #2b3a4a;
  --bit0: #7d8b9a;
  --border: #7d8b9a;
  --role1: #56c8ff;
  --role2: #f2b84b;
  --role3: #c9a3ff;
  --role4: #6fd48a;
  --diff: #ff6fb5;
  --warn: #f2b84b;
  --focus: #ffffff;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  --bit-cell: 16px;
  --bit-gap: 1px;
  --byte-cell: 32px;
  --byte-gap: 2px;
  /* Room for the fixed clock: its measured height plus 8px. app.js overwrites this
   * fallback at start-up and on resize. */
  --clock-height: 128px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f5f0;
  --surface: #eeede6;
  --fg: #1b2129;
  --muted: #505a66;
  --line: #c9cfd6;
  --bit0: #5c6773;
  --border: #5c6773;
  --role1: #0a6c9a;
  --role2: #8a5200;
  --role3: #5f3bbf;
  --role4: #1f7a3a;
  --diff: #b5246d;
  --warn: #8a5200;
  --focus: #000000;
}

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

html {
  background: var(--bg);
}

body {
  margin: 0 auto;
  max-width: 1320px;
  min-height: 100dvh;
  padding: 16px 16px var(--clock-height);
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  overflow-wrap: anywhere;
}

h1 {
  margin: 0.5rem 0;
  font-size: 1.5rem;
  letter-spacing: 0.03em;
}

h2 {
  margin: 1.5rem 0 0.75rem;
  font-size: 1.25rem;
}

h3 {
  margin: 1rem 0 0.5rem;
  font-size: 1.125rem;
}

h4 {
  margin: 0.75rem 0 0.35rem;
  font-size: 1rem;
}

p {
  margin: 0.5rem 0;
}

code, pre, textarea, .mono, .byte-cell, .byte-offset, .byte-plain, .bit, .tile, .lane-label, .digest-groups, .sum, .stats .value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums slashed-zero;
}

code, pre {
  font-size: 0.875rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---- header and footer ---- */

.page-header, footer {
  text-align: center;
  padding-block: 0.5rem;
}

/* Title row: one column below 768px (title, then the two round buttons on their
 * own right-aligned row, then the description); from 768px a 1fr/auto/1fr grid
 * keeps the title centered with the buttons at the right end of the same row. */
.page-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  border-block-end: 1px solid var(--line);
}

footer {
  margin-block-start: 2rem;
  border-block-start: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.875rem;
}

.header-tools {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-block: 0 0.25rem;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--fg);
}

.icon-button svg {
  width: 22px;
  height: 22px;
}

.icon-button:hover, .icon-button:focus-visible {
  border-color: var(--role1);
}

/* ---- controls (44px targets) ---- */

button, input, select, textarea, summary, a {
  min-height: 44px;
  min-width: 44px;
}

button, input, select, textarea {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 2px;
}

button {
  cursor: pointer;
  padding: 0.4rem 0.75rem;
  max-width: 100%;
  background: var(--surface);
}

button:disabled {
  cursor: default;
  color: var(--muted);
}

select {
  padding: 0.3rem 0.5rem;
  max-width: 100%;
}

/* Height follows the rows attribute (4 for the inputs, 1 for the compare field);
 * the shared 44px minimum above keeps a one-row field tappable. */
textarea {
  display: block;
  width: 100%;
  padding: 0.5rem;
  font-size: 1rem;
  line-height: 1.5;
  resize: vertical;
}

/* Placeholder text in the muted token (the browser default is a mid grey below
 * 4.5:1 on both backgrounds); opacity 1 undoes the UA's fade. */
::placeholder {
  color: var(--muted);
  opacity: 1;
}

input[type="checkbox"], input[type="radio"] {
  width: 44px;
  height: 44px;
  margin: 0;
  flex: 0 0 44px;
  accent-color: var(--role1);
}

input[type="range"] {
  flex: 1 1 auto;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--role1);
}

a {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem;
  color: var(--role1);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

label {
  font-weight: 600;
}

.field > label {
  display: block;
  margin-block-end: 4px;
}

.choice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  cursor: pointer;
}

.inline-field {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  max-width: 100%;
}

.options-row, .actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-block: 0.5rem;
}

fieldset {
  min-width: 0;
  margin: 0.5rem 0;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--line);
}

legend {
  max-width: 100%;
  font-weight: 600;
}

/* Input type: the legend and the two radios share one row. A floated legend is
 * not a "rendered legend" (it leaves the border gap), so it is laid out like the
 * other children, and inside a flex container the float itself has no effect. */
.mode-switch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 24px;
}

.mode-switch legend {
  float: left;
  padding: 0;
}

.notes > p {
  margin-block: 0.25rem;
}

/* Hex mode disables the three text settings; their labels fade with them (app.js
 * sets data-off on the section). */
#input-options[data-off] label {
  color: var(--muted);
}

.muted {
  color: var(--muted);
  font-size: 0.875rem;
}

.warning {
  padding: 0.5rem 0.75rem;
  border-inline-start: 3px solid var(--warn);
  color: var(--warn);
}

.warning:empty, [role="status"]:empty {
  display: none;
}

.multiline {
  white-space: pre-line;
}

/* Read by assistive technology only: the live region #announcement (the position
 * is already shown on the stage), the stage heading and the clock's field labels. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

/* ---- the column of five cards ---- */

/* One column at every width: the five sections stacked with a 16px gap. The fixed
 * clock and the screen-reader-only announcement are out of flow; the error line is
 * display: none while empty, so neither takes a row. */
main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  margin-block-start: 16px;
}

.card {
  padding: 8px 6px;
  border: 1px solid var(--line);
  background: var(--surface);
}

/* Section headings: a numbered marker (role color on the border and the digit
 * only), then the title. The five numbers read as the flow of the page: input,
 * settings, bytes, computation, output. */
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
}

.section-number {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  min-width: 1.75rem;
  height: 1.75rem;
  padding-inline: 0.35rem;
  border: 1px solid var(--role1);
  color: var(--role1);
  font: 700 1rem/1 var(--mono);
  font-variant-numeric: tabular-nums slashed-zero;
}

/* ---- stats and byte grid (section 3) ---- */

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-block: 0.5rem;
  font-size: 0.875rem;
}

.stats > * {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 4px 8px;
  border: 1px solid var(--line);
}

.stats dt, .stats dd {
  margin: 0;
}

.stats .value, .stats strong {
  color: var(--role1);
  font-weight: 700;
}

.byte-grid {
  display: grid;
  gap: 4px;
  margin-block: 0.5rem;
}

.byte-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 2px 8px;
  min-width: 0;
}

.byte-offset {
  flex: 0 0 auto;
  min-width: 4ch;
  padding-block: 9px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
}

.byte-cells {
  display: grid;
  grid-template-columns: repeat(8, var(--byte-cell));
  gap: var(--byte-gap);
}

.byte-cell {
  display: grid;
  place-items: center;
  width: var(--byte-cell);
  height: var(--byte-cell);
  border: 1px solid var(--line);
  font-size: 14px;
  line-height: 1;
}

.byte-plain {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Character classes: a role color on the border and text plus an underline, so the
 * class is readable without color. Used by grid cells and legend swatches alike. */
[data-cls]:not([data-cls="text"]) {
  text-decoration: underline;
  text-underline-offset: 2px;
}

[data-cls="lf"], [data-cls="cr"] {
  color: var(--role1);
  border-color: var(--role1);
}

[data-cls="tab"], [data-cls="space"], [data-cls="nbsp"], [data-cls="ideographic-space"] {
  color: var(--role2);
  border-color: var(--role2);
  border-style: dashed;
}

[data-cls="zwsp"], [data-cls="zwj"], [data-cls="vs16"], [data-cls="format"] {
  color: var(--role3);
  border-color: var(--role3);
  border-style: dotted;
}

[data-cls="bom"] {
  color: var(--role4);
  border-color: var(--role4);
  border-style: double;
}

[data-cls="control"], [data-cls="replacement"], [data-cls="lone-surrogate"] {
  color: var(--diff);
  border-color: var(--diff);
}

/* Legend of the byte classes other than plain text, shown only when the grid holds
 * one. A rule and the caption separate it from the grid, and the swatch is smaller
 * than a grid cell so the two do not mix. */
.byte-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0.75rem 0 0.25rem;
  padding: 0.5rem 0 0;
  border-block-start: 1px solid var(--line);
  list-style: none;
  font-size: 0.875rem;
}

.byte-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-caption {
  color: var(--muted);
  font-weight: 600;
}

.legend-swatch {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  font: 14px/1 var(--mono);
}

/* ---- stage rail and position (section 4) ---- */

.stage-rail {
  display: flex;
  gap: 4px;
  margin-block: 0.25rem;
  padding: 4px 2px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.stage-rail button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.stage-rail [aria-current="step"] {
  color: var(--role1);
  border-color: var(--role1);
  border-block-end-width: 3px;
  font-weight: 700;
}

.position-line {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-block: 0.25rem 0.75rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.position-line:empty {
  display: none;
}

/* ---- the stage and its boards ---- */

.stage {
  min-width: 0;
}

/* Below 390px the board has no side frame: the card's content box is 274px wide
 * at 320px and the 16-cell band needs 271px, so the board's own padding and border
 * would push the band out. A top rule separates the board from the position line.
 * From 390px the board is framed like a card. */
.board {
  padding: 8px 0 0;
  border-block-start: 1px solid var(--line);
  /* Panels outside the window skip layout and paint; the browser keeps their last
   * measured height so the page does not jump. */
  content-visibility: auto;
  contain-intrinsic-size: auto 900px;
}

/* While the keys are moving the computation section shows the previous input. */
.is-stale .board-body {
  opacity: 0.5;
}

.board > h3:first-child {
  margin-block-start: 0;
}

.board-body {
  display: grid;
  gap: 12px;
}

.board-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

/* 32-bit band: fixed pixel cells so the band length does not depend on the font.
 * 16 cells per row below 768px (two rows per word), 32 cells from 768px. */
.bits {
  display: grid;
  grid-template-columns: repeat(16, var(--bit-cell));
  gap: var(--bit-gap);
  /* Each band is a layout and paint boundary: changing or moving one row does not make
   * the browser lay out the cells of the other rows again. */
  contain: layout paint style;
}

.bit {
  display: grid;
  place-items: center;
  width: var(--bit-cell);
  height: var(--bit-cell);
  border: 1px solid var(--bit0);
  color: var(--bit0);
  font-size: 14px;
  line-height: 1;
}

.bit.is-one, .bit[data-bit="1"] {
  color: var(--bg);
  background: var(--fg);
  border-color: var(--fg);
}

.bit.is-diff {
  color: var(--bg);
  background: var(--diff);
  border-color: var(--diff);
}

.bit.is-focus, .bit.is-current {
  border-width: 2px;
  border-color: var(--role1);
}

.bit.is-source { border-color: var(--role1); }
.bit.is-from { border-color: var(--role2); }
.bit.is-to { border-color: var(--role3); }
.bit.is-result { border-color: var(--role4); }

.lane {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  min-width: 0;
}

.lane-label {
  min-width: 3ch;
  font-size: 14px;
  color: var(--role1);
}

.lane.role2 .lane-label { color: var(--role2); }
.lane.role3 .lane-label { color: var(--role3); }
.lane.role4 .lane-label { color: var(--role4); }

.lane .tile {
  margin-inline-start: auto;
}

/* Word tiles: hex (default), binary or decimal text set by app.js. */
.tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tile {
  display: inline-grid;
  place-items: center;
  min-width: 9ch;
  padding: 2px 6px;
  border: 1px solid var(--line);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
}

.tile.is-current {
  border-width: 2px;
  border-color: var(--role1);
}

.tile.is-ref { border-color: var(--role2); }
.tile.is-result { border-color: var(--role4); }
.tile.is-diff {
  color: var(--bg);
  background: var(--diff);
  border-color: var(--diff);
}

.tile-label {
  display: block;
  color: var(--muted);
  font-size: 0.875rem;
}

/* Stacked additions: raw sum, dropped carries, result mod 2^32. */
.sum {
  display: grid;
  gap: 2px;
  font-size: 14px;
}

.sum-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 2px 0;
  border-block-end: 1px solid var(--line);
}

.sum-row.is-result {
  border-block-end: 2px solid var(--fg);
  font-weight: 700;
}

.sum-dropped {
  color: var(--role2);
}

.padding-segments {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.segment {
  padding: 2px 6px;
  border: 1px solid var(--line);
  font: 14px/1.5 var(--mono);
}

.segment.is-message { border-color: var(--role1); }
.segment.is-one { border-color: var(--role2); }
.segment.is-zeros { border-color: var(--line); border-style: dotted; }
.segment.is-length { border-color: var(--role3); }

.padding-segments {
  padding: 2px;
  border: 1px solid transparent;
}

.padding-segments.is-current {
  border-color: var(--role1);
}

/* ---- the computation laid out at once (section 4) ---- */

/* The panel that holds the current position takes a role-1 frame (the top rule only
 * below 390px, where the boards have no side frame). */
.board.is-active {
  border-color: var(--role1);
}

.board-body > h4 {
  margin-block: 0.5rem 0;
}

/* Ordinal buttons that choose the block to draw (two blocks or more). */
.block-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.block-tabs button[aria-current="true"] {
  color: var(--role1);
  border-color: var(--role1);
  font-weight: 700;
}

/* Word rows (message block, schedule): the index, the value tile, a tag (which
 * reference, or "from the block") and the 32 bits, which wrap under the head where
 * the row is narrower than the band. The current row has a role-1 frame; the rows
 * the current schedule word reads carry their role color and a text tag. */
.w-rows {
  display: grid;
  gap: 2px;
}

.w-rows.is-current {
  outline: 1px solid var(--role1);
  outline-offset: 1px;
}

/* No side padding: at 320px the 16-cell band (271px) and the row's own borders fill
 * the 274px content box, at 390px the band (303px) and the frame fill 306px. */
.w-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 8px;
  min-width: 0;
  contain: layout style;
  padding: 2px 0;
  border: 1px solid transparent;
}

.w-row.is-current {
  border-color: var(--role1);
  outline: 1px solid var(--role1);
}

.w-row[data-ref="16"], .w-row[data-ref="7"] { border-color: var(--role2); }
.w-row[data-ref="15"], .w-row[data-ref="2"] { border-color: var(--role3); }

.w-index {
  min-width: 6ch;
  color: var(--role1);
  font: 14px/1.5 var(--mono);
  font-variant-numeric: tabular-nums slashed-zero;
}

.w-row.is-current .w-index {
  font-weight: 700;
}

.w-tag {
  color: var(--muted);
  font-size: 14px;
}

.w-row[data-ref="16"] .w-tag, .w-row[data-ref="7"] .w-tag { color: var(--role2); }
.w-row[data-ref="15"] .w-tag, .w-row[data-ref="2"] .w-tag { color: var(--role3); }

/* Bits of the message block: the border names the padding segment of the byte. */
.bit.k-message { border-color: var(--role1); }
.bit.k-one { border-color: var(--role2); }
.bit.k-zeros { border-style: dotted; }
.bit.k-length { border-color: var(--role3); }

/* Legend of the row colors in the schedule panel. */
.row-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.875rem;
}

.row-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-key {
  display: inline-block;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border: 1px solid var(--line);
}

.legend-key.is-current { border-color: var(--role1); outline: 1px solid var(--role1); }
.legend-key.is-direct { border-color: var(--role2); }
.legend-key.is-sigma { border-color: var(--role3); }

/* The bands of the current step, slotted under the current schedule row or under
 * the working variables of the round. Role-1 rules above and below tie them to the
 * row; from 768px a rule on the left does (narrow boards have no room to indent). */
.insert {
  display: grid;
  gap: 12px;
  margin: 4px 0 8px;
  padding: 8px 0;
  border-block: 1px solid var(--role1);
}

.insert > h4 {
  margin: 0;
}

.register-lanes {
  display: grid;
  gap: 4px;
}

/* All 64 rounds: a heading row (from 768px) and 64 row buttons, each the round
 * index and a to h after the round in hex. Below 768px a row wraps its values into
 * as many 10ch columns as fit (the register letter, a space and 8 digits); from
 * 768px the nine columns stand in one line under the heading row and the letters
 * are read by assistive technology only. */
.round-table {
  display: grid;
  gap: 2px;
}

.rt-head {
  display: none;
}

.rt-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10ch, 1fr));
  gap: 2px 8px;
  width: 100%;
  contain: layout style;
  padding: 4px;
  border: 1px solid transparent;
  border-block-end-color: var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font: 14px/1.5 var(--mono);
  font-variant-numeric: tabular-nums slashed-zero;
  text-align: start;
}

.rt-row:hover {
  border-color: var(--border);
}

.rt-row.is-current {
  border-color: var(--role1);
  outline: 1px solid var(--role1);
}

.rt-index {
  color: var(--role1);
}

.rt-cell {
  white-space: nowrap;
}

.rt-key {
  color: var(--muted);
}

/* Final addition: one group per lane with H_in, the register, the sum and H_out. */
.final-lane {
  display: grid;
  gap: 4px;
  padding-block: 6px;
  border-block-end: 1px solid var(--line);
}

.final-lane:last-of-type {
  border-block-end: 0;
}

.digest-lanes {
  display: grid;
  gap: 4px;
}

/* The overflow statistics close the computation section; nothing shows without a result. */
.dropped-stats {
  margin-block: 0.75rem 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.dropped-stats:empty {
  display: none;
}

/* ---- output (section 5) ---- */

/* Heading at the left; the match badge at the right end of the same row (and
 * right-aligned on its own row when the heading wraps on a narrow screen). */
.result-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 4px 12px;
  margin-block-end: 0.5rem;
}

.result-head > h2, .result-head > .match-badge {
  margin: 0;
}

.result-head > h2 {
  margin-inline-end: auto;
}

.match-badge {
  padding: 6px 10px;
  border: 1px solid var(--border);
  font-weight: 700;
}

.match-badge.is-ok, .match-badge[data-state="ok"] {
  color: var(--role4);
  border-color: var(--role4);
}

.match-badge.is-ng, .match-badge[data-state="ng"] {
  color: var(--diff);
  border-color: var(--diff);
}

.match-badge.is-unknown, .match-badge[data-state="unknown"] {
  color: var(--warn);
  border-color: var(--warn);
}

/* The digest band: 8 groups, one per 32-bit word, in a 2px frame. Hex (8 digits):
 * two columns (four rows) up to 767px at 1.375rem, four columns (two rows) from
 * 768px at 1.5rem, one row of eight from 1280px. Column width follows the digits,
 * never the band. Binary (32 digits in four octets): one word per row, wrapping
 * between octets when the band is narrow. Decimal (up to 10 digits): as many
 * columns as fit. */
.digest-groups {
  display: grid;
  grid-template-columns: repeat(2, max-content);
  gap: 4px 12px;
  padding: 8px 10px;
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  font-size: 1.375rem;
  line-height: 1.4;
}

.digest-groups:empty {
  display: none;
}

.digest-groups span {
  white-space: nowrap;
}

.digest-groups[data-radix="bin"] {
  grid-template-columns: minmax(0, 1fr);
}

.digest-groups[data-radix="bin"] span {
  white-space: normal;
  overflow-wrap: anywhere;
}

.digest-groups[data-radix="dec"] {
  grid-template-columns: repeat(auto-fill, minmax(min(11ch, 100%), 1fr));
}

.result-note {
  margin: 0.25rem 0 0;
}

/* Copy: a small heading at the start of the row, then five short buttons. At 1040px
 * the card's content box is 1006px wide, so the gaps and the button padding are
 * tighter than the other option rows to keep the five on one line. */
.result-actions {
  gap: 8px 12px;
}

.result-actions button {
  padding-inline: 0.5rem;
  text-align: start;
}

.actions-label {
  font-weight: 600;
}

.result .field {
  margin-block-start: 0.75rem;
}

.compare-result {
  font-size: 0.875rem;
}

.compare-result.is-match { color: var(--role4); }
.compare-result.is-mismatch { color: var(--diff); }

/* ---- clock (fixed at the bottom; hidden while a textarea has focus) ---- */

/* The bar sits on the surface color under a thin role-1 rule, so it reads as a
 * separate instrument from the page. Below 768px it is three rows (heading and
 * position, slider and speed, buttons and step size) within 150px; from 768px one
 * row. The body's bottom padding (--clock-height) keeps the content clear of it. */
.clock {
  position: fixed;
  inset-inline: 0;
  inset-block-end: 0;
  z-index: 10;
  padding: 4px 16px;
  border-block-start: 1px solid var(--role1);
  background: var(--surface);
}

.clock.is-hidden {
  display: none;
}

.clock-inner {
  display: grid;
  gap: 4px;
  max-width: 1288px;
  margin: 0 auto;
}

/* The bold heading names the instrument; the position text follows on the same
 * line and wraps under it when the bar is narrow. */
.clock-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 12px;
  min-width: 0;
  font-size: 14px;
  line-height: 1.3;
}

.clock-title {
  font-weight: 700;
}

.clock-position {
  font-variant-numeric: tabular-nums;
}

.clock-row {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.clock-row > button {
  flex: 0 0 44px;
  padding: 0;
  font-size: 1.125rem;
}

#clock-range {
  flex: 1 1 120px;
  min-width: 100px;
}

#clock-speed {
  flex: 0 0 72px;
}

#granularity {
  flex: 1 1 44px;
  min-width: 44px;
}

#clock-play[aria-pressed="true"] {
  color: var(--role1);
  border-color: var(--role1);
}

/* ---- help dialog ---- */

/* Drafting look like the cards: surface, a 1px rule, no shadow. The backdrop is the
 * page background at 70%. The inner box carries the padding so that a click on the
 * dialog element itself means a click on the backdrop (app.js closes it then). */
.help-dialog {
  width: calc(100% - 32px);
  max-width: 640px;
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  overflow: auto;
}

.help-dialog::backdrop {
  background: var(--bg);
  opacity: 0.7;
}

.help-inner {
  padding: 12px 16px 16px;
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.help-head h2 {
  margin: 0;
  font-size: 1.25rem;
}

.help-body h3 {
  margin: 1rem 0 0.25rem;
  font-size: 1rem;
}

.help-body p, .help-body li {
  margin: 0.25rem 0;
}

.help-body ul {
  margin: 0;
  padding-inline-start: 1.25rem;
}

.help-keys {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 12px;
  margin: 0.25rem 0 0;
}

.help-keys dd {
  margin: 0;
}

kbd {
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 14px;
}

/* ---- motion (the OS setting is the only switch) ---- */

.bit, .tile, .lane {
  transition: transform 300ms, opacity 300ms;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* ---- wider screens ---- */

@media (min-width: 390px) {
  :root {
    --bit-cell: 18px;
  }

  .card, .board {
    padding: 12px;
  }

  .board {
    border: 1px solid var(--line);
  }
}

@media (min-width: 640px) {
  .byte-cells {
    grid-template-columns: repeat(16, var(--byte-cell));
  }
}

@media (min-width: 768px) {
  :root {
    --bit-cell: 19px;
    --clock-height: 112px;
  }

  body {
    padding-inline: 24px;
  }

  .page-header {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    column-gap: 8px;
  }

  .page-header h1 {
    grid-column: 2;
  }

  .header-tools {
    grid-column: 3;
    margin: 0;
  }

  .page-header p {
    grid-column: 1 / -1;
  }

  .bits {
    grid-template-columns: repeat(32, var(--bit-cell));
  }

  .card, .board {
    padding: 16px;
  }

  .digest-groups {
    grid-template-columns: repeat(4, max-content);
    font-size: 1.5rem;
  }

  .digest-groups[data-radix="dec"] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  /* Stacked additions are as wide as a lane with a one-letter label (e, f, g, a, b,
   * c): the label (1ch), the tile (8ch plus 14px of padding and border), the 8px
   * gap and the band (32 cells plus 31 gaps of 1px), so the values end on the
   * vertical line where those bands end instead of at the far edge of a wide
   * board. Between 768px and 800px the box is wider than the board (where the band
   * wraps under its head anyway), so nothing changes there. */
  .sum {
    max-width: calc(32 * var(--bit-cell) + 9ch + 53px);
  }

  /* One row: heading and position, then the slider and speed, then the five buttons
   * and the step size. The slider keeps at least 120px; the heading cell shrinks
   * first and wraps its position text under the heading. */
  .clock-inner {
    grid-template-columns: auto minmax(120px, 1fr) auto;
    align-items: center;
    column-gap: 12px;
  }

  .clock-head {
    max-width: 280px;
  }

  .clock-row > button {
    font-size: 1.25rem;
  }

  #granularity {
    flex: 0 0 auto;
  }

  .insert {
    padding: 8px 0 8px 8px;
    border-block: 0;
    border-inline-start: 2px solid var(--role1);
  }

  /* The round table in nine columns: the index and a to h, with the heading row. */
  .rt-head {
    display: grid;
    grid-template-columns: 3ch repeat(8, minmax(8ch, 1fr));
    gap: 2px 8px;
    padding: 0 5px 2px;
    color: var(--muted);
    font: 14px/1.5 var(--mono);
  }

  .rt-row {
    grid-template-columns: 3ch repeat(8, minmax(8ch, 1fr));
  }

  .rt-key {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }
}

/* Between 768px and 800px the single-row band (32 cells of 19px plus 31 gaps = 639px)
 * is wider than the board's content box (the card and the board each take 34px of
 * padding and border from a 703px body). Without the cell gap and with narrower
 * side padding the band stays inside the board. */
@media (min-width: 768px) and (max-width: 800px) {
  :root {
    --bit-gap: 0;
  }

  .board {
    padding-inline: 8px;
  }
}

@media (min-width: 1280px) {
  :root {
    --bit-cell: 20px;
  }

  /* The column is 1040px wide and centered: the 32-bit band (32 cells of 20px plus
   * gaps) and eight digest groups in one row both fit. The header (its rule and
   * the round buttons at the right end) and the footer take the same width, so
   * their edges line up with the cards. */
  .page-header, main, footer {
    max-width: 1040px;
    margin-inline: auto;
  }

  /* The eight hex groups in one row. The band's content box is 982px (1040px minus
   * the card's and the band's padding and borders); 8 x 8ch plus seven 12px gaps
   * need about 1009px at 1.5rem with a 0.6em-wide monospace glyph and 932px at
   * 1.375rem, so the smaller size is the largest that fits. */
  .digest-groups {
    grid-template-columns: repeat(8, max-content);
    font-size: 1.375rem;
  }

  /* Binary: two words of 32 digits (in four octets) per row, four rows. */
  .digest-groups[data-radix="bin"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
