/* The decoder page. Every colour is a token; light and dark differ only here. */
:root {
  --ink: #191c22;
  --quiet: #555c68;
  --rule: #dde1e6;
  --line: #878f9c;
  --paper: #ffffff;
  --panel: #f5f6f8;
  --accent: #0b5a72;
  --accent-soft: #e2f0f4;
  --on-accent: #ffffff;
  --good: #2a6a35;
  --good-bg: #e4f3e6;
  --warn: #875200;
  --warn-bg: #fcf0d7;
  --crit: #b0261d;
  --crit-bg: #fbeae8;
  /* Field hues, used mixed into the paper so the ink stays readable on them. */
  --c0: #2f7fd1;
  --c1: #d9772b;
  --c2: #2f9e6b;
  --c3: #b455c4;
  --c4: #c9a227;
  --c5: #d1495b;
  --c6: #1fa3a3;
  --c7: #7a6ff0;
  --tint: 24%;
  --dim: 0.45;
  --tint-on: 48%;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e7e9ec;
    --quiet: #a5acb7;
    --rule: #30363e;
    --line: #7b8592;
    --paper: #121417;
    --panel: #1a1d21;
    --accent: #6cc3da;
    --accent-soft: #14303a;
    --on-accent: #121417;
    --good: #6fc480;
    --good-bg: #1b2e20;
    --warn: #e2b04e;
    --warn-bg: #32291a;
    --crit: #f08b80;
    --crit-bg: #3a1f1f;
    --tint: 30%;
    --dim: 0.55;
    --tint-on: 52%;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--font);
}

main {
  max-width: 62rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 0.5rem; text-wrap: balance; }
h2 { font-size: 1.25rem; line-height: 1.3; margin: 0; }
p { margin: 0 0 0.75rem; }
.intro p { max-width: 44rem; color: var(--quiet); }
.intro strong, .own strong { color: var(--ink); }

code, .mono { font-family: var(--mono); font-size: 0.875em; }
.hint { color: var(--quiet); font-size: 0.875rem; margin: 0.375rem 0 0; }

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

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

.notice {
  padding: 0.625rem 0.75rem;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--rule);
  overflow-wrap: anywhere;
}
.notice.crit { background: var(--crit-bg); border-color: var(--crit); color: var(--ink); }
.notice.good { background: var(--good-bg); border-color: var(--good); }

/* Controls */
.controls {
  margin-top: 1.25rem;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 10px;
  display: grid;
  gap: 1rem;
}
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend, .field > span {
  display: block;
  padding: 0;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.choices { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.choice { position: relative; }
.choice input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.choice span {
  display: block;
  padding: 0.375rem 0.75rem;
  min-height: 2.25rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  font-size: 0.9375rem;
  white-space: nowrap;
}
.choice input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.choice input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.choice:hover span { border-color: var(--accent); }

.inputs { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: flex-start; }
.field { display: block; min-width: 0; }
.field.grow { flex: 1 1 18rem; }
select, input:not([type]), textarea {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font-size: 1rem;
}
textarea { display: block; resize: vertical; line-height: 1.4; font-family: var(--mono); overflow-wrap: anywhere; }
#frame-id { width: 9rem; font-family: var(--mono); }
[hidden] { display: none !important; }

.issues { margin: 0.5rem 0 0; padding: 0; list-style: none; font-size: 0.8125rem; overflow-wrap: anywhere; }
.issues li { padding: 0.125rem 0 0.125rem 0.625rem; border-left: 3px solid var(--warn); margin-bottom: 0.25rem; }
.issues li.error { border-left-color: var(--crit); }

/* Result */
.result { margin-top: 1.75rem; }
.result-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.875rem; margin-bottom: 0.75rem; }
.result-head .hint { margin: 0; }
#result-title { font-size: 1.5rem; overflow-wrap: anywhere; }

.badge {
  display: inline-block;
  padding: 0.0625rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--good);
  background: var(--good-bg);
  color: var(--ink);
  font-size: 0.8125rem;
  white-space: nowrap;
}
.badge.crit { border-color: var(--crit); background: var(--crit-bg); }

/* Reserves its height so the bit view below does not move as fields are pointed at. */
.inspector {
  min-height: 4.75rem;
  margin: 0 0 0.75rem;
  padding: 0.625rem 0.75rem;
  border-left: 4px solid var(--rule);
  background: var(--panel);
  border-radius: 0 6px 6px 0;
  font-size: 0.9375rem;
  overflow-wrap: anywhere;
}
.inspector.on { border-left-color: var(--c); }
.inspector .name { font-weight: 700; }
.inspector .raw { font-family: var(--mono); font-size: 0.875rem; color: var(--quiet); display: block; margin-top: 0.125rem; }
.inspector.idle { color: var(--quiet); }

/* The bit view: one grid per row of bytes. Columns are bits; a narrow track
   separates bytes. Row 1 names the byte, row 2 holds its bits, the rows below
   hold the fields that own those bits. */
.bits { display: grid; gap: 0.875rem; user-select: none; -webkit-user-select: none; }
.bit-row { display: grid; gap: 0; align-items: stretch; }

.byte-head {
  grid-row: 1;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 3px;
  padding: 0 2px 1px;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.8125rem;
  white-space: nowrap;
  overflow: hidden;
}
.byte-head .offset { color: var(--quiet); }
.byte-head .hex { font-weight: 700; }

.bit {
  grid-row: 2;
  display: grid;
  place-items: center;
  height: 2rem;
  min-width: 0;
  font-family: var(--mono);
  font-size: 0.875rem;
  font-weight: 600;
  background: color-mix(in srgb, var(--c, var(--line)) var(--tint), var(--paper));
  border-top: 3px solid transparent;
  cursor: default;
  transition: opacity 0.12s, background-color 0.12s;
}
.bit[data-f] { cursor: pointer; }
.bit.none { background: var(--panel); color: var(--quiet); font-weight: 400; }
.bit.zero { color: color-mix(in srgb, var(--ink) 62%, transparent); font-weight: 400; }
.bit.miss {
  background: transparent;
  color: var(--quiet);
  outline: 1px dashed var(--line);
  outline-offset: -2px;
  font-weight: 400;
}
.bit.first { border-top-left-radius: 5px; margin-left: 1px; }
.bit.last { border-top-right-radius: 5px; margin-right: 1px; }
.bit.disc { border-top-color: var(--ink); }

.seg {
  display: block;
  min-width: 0;
  height: 1.5rem;
  margin: 0 1px 2px;
  padding: 0 0.25rem;
  border: 0;
  border-bottom: 3px solid var(--c);
  border-radius: 0 0 5px 5px;
  background: color-mix(in srgb, var(--c) var(--tint), var(--paper));
  color: var(--ink);
  font: 600 0.8125rem/1.5rem var(--font);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: opacity 0.12s, background-color 0.12s;
}
.seg.tight { padding: 0; color: transparent; }

.bits.focus .bit:not(.on), .bits.focus .seg:not(.on) { opacity: var(--dim); }
.bit.on, .seg.on { background: color-mix(in srgb, var(--c) var(--tint-on), var(--paper)); }
.bit.on { color: var(--ink); font-weight: 700; }

#bits-note { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; }
#bits-note .numbering { flex-basis: 100%; }
.unit-inline { display: none; font-weight: 400; color: var(--quiet); font-family: var(--mono); font-size: 0.8125rem; }
.key { display: inline-flex; align-items: center; gap: 0.375rem; }
.key i { display: inline-block; width: 1.25rem; height: 0.875rem; background: var(--rule); }
.key i.disc { border-top: 3px solid var(--ink); }
.key i.miss { outline: 1px dashed var(--line); outline-offset: -2px; background: transparent; }

/* Fields table */
.table-wrap { margin-top: 1.25rem; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
th, td { text-align: left; padding: 0.375rem 0.625rem; border-bottom: 1px solid var(--rule); vertical-align: baseline; }
thead th { font-size: 0.8125rem; color: var(--quiet); font-weight: 600; border-bottom-color: var(--line); }
tbody tr { transition: background-color 0.12s; }
tbody tr.on { background: color-mix(in srgb, var(--c) var(--tint), var(--paper)); }
td.value { font-weight: 600; overflow-wrap: anywhere; }
td.value.null { font-weight: 400; color: var(--quiet); font-style: italic; }
td.bitrange, td.kind, td.unit { font-family: var(--mono); font-size: 0.8125rem; white-space: nowrap; }
td.kind, td.unit { color: var(--quiet); }

.field-button {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5rem;
  max-width: 100%;
  margin: -0.125rem -0.25rem;
  padding: 0.125rem 0.25rem;
  border: 0;
  border-radius: 4px;
  background: none;
  color: inherit;
  font: inherit;
  font-family: var(--mono);
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.field-button[aria-pressed="true"] { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.swatch {
  flex: none;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 3px;
  background: color-mix(in srgb, var(--c) 70%, var(--paper));
  border-bottom: 3px solid var(--c);
  align-self: center;
}

/* Own dictionary */
.own { margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); }
.own h2 { margin-bottom: 0.5rem; }
.own > p { max-width: 44rem; color: var(--quiet); }
.drop {
  padding: 1.25rem 1rem;
  border: 2px dashed var(--line);
  border-radius: 10px;
  text-align: center;
  transition: background-color 0.12s, border-color 0.12s;
}
.drop.over { background: var(--accent-soft); border-color: var(--accent); }
.drop-text { color: var(--quiet); margin-bottom: 0.75rem; }
.drop-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.625rem; }
.button {
  display: inline-block;
  position: relative;
  padding: 0.5rem 0.875rem;
  min-height: 2.5rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--paper);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}
.button:hover { background: var(--accent-soft); }
.button:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
#own-status { margin-top: 0.75rem; }

@media (max-width: 560px) {
  h1 { font-size: 1.4375rem; }
  main { padding-top: 1rem; }
  .controls { padding: 0.75rem; }
  .wide-only, td.kind, td.unit, th.unit { display: none; }
  .unit-inline { display: inline; }
  th, td { padding: 0.375rem 0.375rem; }
  .bit { height: 1.875rem; font-size: 0.8125rem; }
  .inspector { min-height: 6.25rem; }
}

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