/*
  The accent colour is not a design decision. It is the top 24 bits of the register,
  written into --accent by app.js on every flip, so the page is literally painted with
  whatever the word currently says.
*/
:root {
  --ink: #e6e9f0;
  --ink-dim: #8b93a7;
  --ink-faint: #5a6178;
  --ground: #0b0e14;
  --panel: #11151f;
  --panel-line: #1e2433;
  --accent: #474f4f;
  --off: #1a2030;
  --on: var(--accent);
  --damaged: #ff5c5c;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --edge: 10px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  padding: 0 20px 96px;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.65;
  /* A faint wash of the register's own colour, so the whole page drifts as it decays. */
  background-image: radial-gradient(120% 80% at 50% -10%, color-mix(in oklab, var(--accent) 18%, transparent), transparent 70%);
  transition: background-image 600ms ease;
}

main, .masthead { max-width: 760px; margin: 0 auto; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---- masthead ---------------------------------------------------------- */

.masthead {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: baseline; justify-content: space-between;
  padding: 28px 0 8px;
}
.masthead h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.host { color: var(--ink); }
.tld { color: var(--ink-faint); }

.status { margin: 0; font-size: 13px; color: var(--ink-dim); display: flex; align-items: center; gap: 8px; }
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-faint); flex: none;
  transition: background-color 200ms ease;
}
.status[data-state="live"] .dot { background: #4ade80; box-shadow: 0 0 0 3px rgb(74 222 128 / 0.15); }
.status[data-state="lost"] .dot { background: var(--damaged); }

/* ---- lede -------------------------------------------------------------- */

.lede { margin: 40px 0 32px; }
h2 { font-size: 13px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-dim); margin: 0 0 14px; }
.lede p { margin: 0 0 10px; max-width: 60ch; color: var(--ink); }
.lede code { color: var(--ink); background: var(--panel); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--panel-line); }
.lede-action { color: var(--ink-dim) !important; font-size: 14px; }

.noscript {
  border: 1px solid var(--panel-line); background: var(--panel);
  padding: 14px 16px; border-radius: var(--edge); color: var(--ink-dim);
}

/* ---- the register ------------------------------------------------------ */

.register { margin: 0 0 34px; }

/*
  Four bytes to a row, so the word reads as two lines of thirty-two bits rather than
  whatever happens to fit. The bits themselves are flexible, which keeps the grid
  legible from a phone to a desktop without a single fixed width.
*/
.word {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px 14px;
  padding: 22px 20px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--edge);
}

.byte { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.byte-bits { display: flex; gap: 2px; }
.byte-label {
  font-size: 10px; color: var(--ink-faint); letter-spacing: 0.08em;
  display: flex; justify-content: center; gap: 7px; align-items: baseline;
}
.byte-char {
  color: var(--ink); font-size: 12px;
  min-width: 1ch; text-align: center;
}

.bit {
  flex: 1 1 0; min-width: 0;
  aspect-ratio: 3 / 4;
  padding: 0; margin: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  background: var(--off);
  color: #737c92;
  font: inherit; font-size: 11px;
  display: grid; place-items: center;
  cursor: pointer;
  position: relative;
  transition: background-color 160ms ease, color 160ms ease, transform 120ms ease, box-shadow 160ms ease;
}
.bit:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--ink-faint); }
.bit:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.bit[aria-checked="true"] { background: var(--on); color: #0b0e14; font-weight: 600; }

/* A bit that no longer matches the word as manufactured. */
.bit[data-damaged="true"]::after {
  content: ""; position: absolute; inset: auto 0 -6px; height: 2px;
  background: var(--damaged); border-radius: 2px;
}
.bit:disabled { cursor: not-allowed; opacity: 0.55; }

@keyframes struck {
  0% { transform: scale(1.32); box-shadow: 0 0 0 6px color-mix(in oklab, var(--damaged) 45%, transparent); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 transparent; }
}
.bit[data-struck="true"] { animation: struck 520ms ease-out; }

.cooldown { min-height: 20px; margin: 12px 2px 0; font-size: 13px; color: var(--ink-dim); }
.cooldown[data-denied="true"] { color: var(--damaged); }

/* ---- integrity --------------------------------------------------------- */

.integrity { margin: 0 0 34px; }
.meter {
  height: 8px; border-radius: 4px; overflow: hidden;
  background: var(--off); border: 1px solid var(--panel-line);
}
.meter-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #4ade80, #4ade80);
  transition: width 400ms ease, background 400ms ease;
}
.meter[data-state="correctable"] .meter-fill { background: linear-gradient(90deg, #4ade80, #facc15); }
.meter[data-state="detectable"] .meter-fill { background: linear-gradient(90deg, #facc15, #fb923c); }
.meter[data-state="silent"] .meter-fill { background: linear-gradient(90deg, #fb923c, var(--damaged)); }

.verdict { margin: 12px 0 4px; font-size: 14px; color: var(--ink-dim); }
.verdict strong { color: var(--ink); font-size: 18px; }
.ecc { color: var(--ink); margin-left: 6px; }
.ecc-note { margin: 0; font-size: 13px; color: var(--ink-faint); }

/* The repair control. It is deliberately inert most of the time: a correction is
   possible at exactly one wrong bit and at no other distance. */
.repair {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  margin-top: 18px;
}

.correct {
  font: inherit; font-size: 13px; letter-spacing: 0.04em;
  padding: 8px 18px; border-radius: 6px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  color: var(--ink-faint);
  cursor: not-allowed;
  flex: none;
  transition: background-color 200ms ease, color 200ms ease, border-color 200ms ease, box-shadow 200ms ease;
}

.correct[data-live="true"] {
  border-color: #4ade80;
  background: color-mix(in oklab, #4ade80 16%, var(--panel));
  color: #bbf7d0;
  cursor: pointer;
  animation: recoverable 2.4s ease-in-out infinite;
}
.correct[data-live="true"]:hover:not(:disabled) {
  background: color-mix(in oklab, #4ade80 28%, var(--panel));
  color: #ffffff;
}
.correct[data-live="true"]:disabled { animation: none; opacity: 0.6; cursor: not-allowed; }
.correct:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

@keyframes recoverable {
  0%, 100% { box-shadow: 0 0 0 0 rgb(74 222 128 / 0.30); }
  50%      { box-shadow: 0 0 0 7px rgb(74 222 128 / 0); }
}

.repair-note { margin: 0; font-size: 13px; color: var(--ink-faint); flex: 1 1 240px; }

/* ---- decode ------------------------------------------------------------ */

.decode { margin: 0 0 34px; }
.readings { margin: 0; display: grid; gap: 1px; background: var(--panel-line); border: 1px solid var(--panel-line); border-radius: var(--edge); overflow: hidden; }
.reading { display: grid; grid-template-columns: 92px 1fr; gap: 14px; background: var(--panel); padding: 11px 16px; align-items: baseline; }
.reading dt { color: var(--ink-faint); font-size: 12px; letter-spacing: 0.06em; }
.reading dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }
#r-ascii { letter-spacing: 0.22em; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 8px; border: 1px solid rgb(255 255 255 / 0.2); }

/* ---- feed -------------------------------------------------------------- */

.feed { margin: 0 0 44px; }
.total { margin: 0 0 14px; font-size: 14px; color: var(--ink-dim); }
.total strong { color: var(--ink); }
.flips { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; background: var(--panel-line); border: 1px solid var(--panel-line); border-radius: var(--edge); overflow: hidden; }
.flips:empty { display: none; }
.flips li {
  background: var(--panel); padding: 9px 16px; font-size: 13px;
  display: flex; gap: 12px; align-items: baseline; color: var(--ink-dim);
}
.flips li.fresh { background: color-mix(in oklab, var(--panel) 82%, var(--accent)); }
.flip-bit { color: var(--ink); min-width: 62px; }
.flip-dir { min-width: 78px; }
.flip-dir[data-raised="true"] { color: #4ade80; }
.flip-dir[data-raised="false"] { color: #60a5fa; }
.flip-dir[data-corrected="true"] { color: #4ade80; }
.flip-when { margin-left: auto; color: var(--ink-faint); font-size: 12px; white-space: nowrap; }

/* ---- about ------------------------------------------------------------- */

.about { border-top: 1px solid var(--panel-line); padding-top: 30px; }
.about p { max-width: 62ch; color: var(--ink-dim); margin: 0 0 14px; }
.about strong { color: var(--ink); }
.about abbr { text-decoration: underline dotted; cursor: help; }
.ecc-ladder { max-width: 62ch; margin: 0 0 16px; padding-left: 20px; color: var(--ink-dim); }
.ecc-ladder li { margin-bottom: 5px; }
.colophon { font-size: 13px; color: var(--ink-faint) !important; }
a { color: var(--ink); text-underline-offset: 3px; }
a:hover { color: var(--accent); }

/* ---- narrow ------------------------------------------------------------ */

@media (max-width: 560px) {
  body { padding: 0 14px 72px; font-size: 14px; }
  .word { grid-template-columns: repeat(2, 1fr); gap: 18px 12px; padding: 18px 14px; }
  .reading { grid-template-columns: 74px 1fr; gap: 10px; padding: 10px 13px; }
  .flip-bit { min-width: 54px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
