/* =========================================================================
   Binary Workbench — theme
   Direction: an engineer's bench. Warm drafting paper with a faint grid,
   dark ink, one signal colour (solder amber) and monospace "readouts" for
   every number. No external assets: system font stacks only.
   ========================================================================= */

/* ---------- Tokens ---------------------------------------------------- */
:root {
  color-scheme: light dark;

  /* Type */
  --font-sans: "Avenir Next", "Segoe UI Variable Text", "Segoe UI", "Helvetica Neue",
    system-ui, -apple-system, Roboto, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo,
    Consolas, "Liberation Mono", monospace;

  /* Light and dark palettes */
  --paper: light-dark(#f3efe6, #12161c);
  --paper-grid: light-dark(rgb(27 36 48 / 0.055), rgb(240 230 210 / 0.045));
  --surface: light-dark(#fffdf8, #1a2028);
  --surface-sunk: light-dark(#ece6d9, #0e1217);
  --ink: light-dark(#1b2430, #ece6da);
  --ink-soft: light-dark(#4a5463, #a6aebb);
  --line: light-dark(#d4ccbb, #313a46);
  --line-strong: light-dark(#1b2430, #8d97a6);
  --accent: light-dark(#b85c00, #f4b04a);
  --accent-fill: #f0a020;
  --accent-wash: light-dark(#fbe7c2, #3a2c15);
  --correct: light-dark(#1f6b3a, #7fd69a);
  --correct-wash: light-dark(#dcefdf, #16301f);
  --wrong: light-dark(#a3242a, #ff9b94);
  --wrong-wash: light-dark(#f7dcdb, #3a1a1c);
  --focus: light-dark(#0b5fd6, #7ab3ff);

  --radius: 0.5rem;
  --radius-sm: 0.3rem;
  --shadow:
    0 1px 0 light-dark(rgb(27 36 48 / 0.06), transparent),
    0 0 0 1px light-dark(transparent, rgb(0 0 0 / 0.2)),
    0 0.6rem 1.4rem -0.8rem light-dark(rgb(27 36 48 / 0.28), rgb(0 0 0 / 0.7));
  --press: 0 2px 0 var(--line-strong);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background-color: var(--paper);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--ink);
  /* drafting grid: 24px cells with a heavier line every 5 */
  background-image:
    linear-gradient(var(--paper-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--paper-grid) 1px, transparent 1px),
    linear-gradient(var(--paper-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--paper-grid) 1px, transparent 1px);
  background-size: 24px 24px, 24px 24px, 120px 120px, 120px 120px;
  background-position: -1px -1px;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
legend {
  margin: 0;
  line-height: 1.15;
  text-wrap: balance;
}

p {
  margin: 0;
  text-wrap: pretty;
}

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

button {
  cursor: pointer;
}

::selection {
  background: var(--accent-fill);
  color: #1b2430;
}

/* Keyboard focus: one consistent, high-contrast ring */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* ---------- Header ---------------------------------------------------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  max-width: 72rem;
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) clamp(1rem, 4vw, 2rem) 1rem;
  padding-left: max(clamp(1rem, 4vw, 2rem), calc(env(safe-area-inset-left) + 0.75rem));
  padding-right: max(clamp(1rem, 4vw, 2rem), calc(env(safe-area-inset-right) + 0.75rem));
  border-bottom: 2px solid var(--line-strong);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
}

.score {
  display: inline-flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.35rem 0.4rem 0.35rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.score small,
.score > span {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.score strong {
  min-width: 2.5ch;
  padding: 0.1rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--accent-fill);
  background: #1b2430;
  border-radius: 999px;
}

/* ---------- Shell & intro --------------------------------------------- */
.shell {
  max-width: 72rem;
  margin: 0 auto;
  padding: clamp(1.5rem, 5vw, 3rem) clamp(1rem, 4vw, 2rem) calc(4.5rem + env(safe-area-inset-bottom));
  padding-left: max(clamp(1rem, 4vw, 2rem), calc(env(safe-area-inset-left) + 0.75rem));
  padding-right: max(clamp(1rem, 4vw, 2rem), calc(env(safe-area-inset-right) + 0.75rem));
}

/* ---------- Start and exercise screens ------------------------------ */
.start-screen,
.practice-screen {
  margin-inline: auto;
}

.start-screen {
  max-width: 38rem;
}

@media (min-width: 46rem) and (min-height: 48rem) {
  body:has(.start-screen:not([hidden])) {
    display: grid;
    grid-template-rows: auto 1fr auto;
  }

  body:has(.start-screen:not([hidden])) > :is(.site-header, .shell) {
    width: 100%;
  }

  .shell:has(.start-screen:not([hidden])) {
    display: grid;
    align-items: center;
    padding-block: 2rem;
  }
}

.practice-screen {
  max-width: 52rem;
}

.analytics-consent {
  width: min(100%, 38rem);
  margin: 0 auto 1.5rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.analytics-consent h2 {
  margin-bottom: 0.5rem;
  font-size: 1.1rem;
}

.analytics-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.privacy-footer {
  padding: 0 1rem calc(1rem + env(safe-area-inset-bottom));
  text-align: center;
}

.privacy-footer button {
  padding: 0.5rem;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  text-decoration: underline;
}

.start-practice {
  width: 100%;
  margin-top: 1.4rem;
}

.start-heading,
.practice-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.practice-toolbar {
  margin-bottom: 0.9rem;
}

.settings-link[hidden] {
  display: none;
}

.practice-toolbar [data-open-guide] {
  margin-inline-start: auto;
}

.open-guide.new-question {
  min-width: 10rem;
  min-height: 4rem;
  background: var(--accent-fill);
  color: #1b2430;
  font-size: 1.35rem;
}

.practice-toolbar .new-question {
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.9rem;
}

@media (max-width: 45.99rem), (pointer: coarse) {
  .start-heading {
    flex-wrap: wrap;
  }

  .start-heading .open-guide {
    flex: 1 0 100%;
    min-height: 4.5rem;
    font-size: 1.5rem;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .practice-screen:not([hidden]) {
    animation: practice-in 300ms var(--ease) backwards;
  }
}

@keyframes practice-in {
  from {
    opacity: 0;
    transform: translateY(0.65rem);
  }
}

.controls,
.exercise {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Controls panel -------------------------------------------- */
.controls {
  padding: 1.25rem;
}

.controls h1,
.controls legend {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.mode-list {
  display: grid;
  gap: 0.4rem;
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 32rem) {
  .mode-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.mode {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 2.9rem;
  padding: 0.45rem 0.75rem 0.45rem 0.45rem;
  text-align: left;
  font-weight: 600;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease);
}

.mode:hover {
  background: var(--surface-sunk);
  border-color: var(--line);
}

.mode-icon {
  flex: none;
  display: grid;
  place-items: center;
  position: relative;
  width: 3rem;
  height: 2.1rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.mode-icon-convert {
  display: flex;
  justify-content: center;
  gap: 0.2rem;
}

.mode-arrow {
  width: 0.62rem;
  height: 0.62rem;
  position: relative;
}

.mode-arrow::before {
  position: absolute;
  inset: 50% 0 0;
  border-top: 2px solid currentColor;
  content: "";
}

.mode-arrow::after {
  position: absolute;
  top: calc(50% + 1px);
  right: 0;
  width: 0.42rem;
  height: 0.42rem;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: translateY(-50%) rotate(45deg);
  content: "";
}

.mode-icon-add::before,
.mode-icon-add::after,
.mode-icon-subtract::before {
  grid-area: 1 / 1;
  width: 0.9rem;
  height: 0;
  border-top: 2px solid currentColor;
  content: "";
}

.mode-icon-add::after {
  transform: rotate(90deg);
}

.mode > span:last-child {
  min-width: 0;
  line-height: 1.25;
}

.mode[aria-pressed="true"] {
  color: var(--surface);
  background: var(--ink);
  border-color: var(--ink);
}

.mode[aria-pressed="true"] .mode-icon {
  color: #1b2430;
  background: var(--accent-fill);
  border-color: var(--accent-fill);
}

/* Difficulty fieldset */
.controls fieldset {
  margin: 1.4rem 0 0;
  padding: 1.1rem 0 0;
  min-width: 0;
  border: 0;
  border-top: 1px dashed var(--line);
}

.controls legend {
  float: left; /* lets the legend sit inside the dashed rule cleanly */
  width: 100%;
  padding: 0;
  margin-bottom: 0.7rem;
}

.levels {
  clear: both;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 3px;
  gap: 3px;
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.levels button {
  min-height: 2.75rem;
  padding: 0.35rem 0.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  overflow-wrap: anywhere;
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}

.levels button:hover {
  color: var(--ink);
  background: var(--surface);
}

.levels button[aria-pressed="true"] {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line-strong), 0 2px 0 var(--line-strong);
}

.level-note {
  margin-top: 0.65rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

/* ---------- Exercise panel -------------------------------------------- */
.exercise {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.25rem;
  padding: clamp(1rem, 3.5vw, 1.75rem);
}

.exercise-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
}

.exercise-top h1 {
  font-size: clamp(1.25rem, 1.1rem + 0.8vw, 1.6rem);
  font-weight: 750;
  letter-spacing: -0.02em;
}

/* Shared button base */
.new-question,
.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.75rem;
  padding: 0.5rem 1.1rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease),
    background-color 150ms var(--ease);
}

.new-question {
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line-strong);
  box-shadow: var(--press);
}

.new-question:hover {
  background: var(--accent-wash);
}

.new-question:active,
.primary:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 var(--line-strong);
}

/* The problem "readout" */
.problem {
  container-type: inline-size;
  padding: clamp(1rem, 4vw, 1.75rem);
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent-fill);
  border-radius: var(--radius-sm);
}

.instruction {
  margin-bottom: 0.9rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.expression {
  display: grid;
  justify-content: end;
  justify-items: end;
  row-gap: 0.15em;
  margin: 0;
  /* 13 binary digits + operator ≈ 9.6em wide; 8.5cqi keeps that under ~82% of the box */
  font-family: var(--font-mono);
  font-size: clamp(1.15rem, 8.5cqi, 3rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums slashed-zero;
  line-height: 1.2;
  letter-spacing: 0.04em;
  color: var(--ink);
  max-width: 100%;
  overflow-x: auto;
  overflow-wrap: anywhere;
  scrollbar-width: thin;
}

/* Browsers without container units: size off the viewport instead */
@supports not (font-size: 1cqi) {
  .expression {
    font-size: clamp(1.15rem, 6vw, 3rem);
  }
}

/* Single number: centre it as a big readout */
.expression:not(:has(.operand)) {
  justify-content: center;
  justify-items: center;
  text-align: center;
}

/* Stacked arithmetic: operator column + right-aligned operands */
.expression:has(.operand) {
  grid-template-columns: auto auto;
  column-gap: 0.5ch;
}

.operand {
  grid-column: 2;
  text-align: right;
  white-space: nowrap;
}

.operator {
  grid-column: 1;
  color: var(--accent);
  font-weight: 700;
}

/* Ruled line under the final operand, like long-hand sums */
.expression:has(.operand) > .operand:last-child {
  padding-bottom: 0.2em;
  border-bottom: 3px solid var(--line-strong);
}

/* ---------- Answer form ----------------------------------------------- */
.answer-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.5rem;
}

.answer-form label {
  font-weight: 700;
}

.answer-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.answer-row input {
  flex: 1 1 14rem;
  min-width: 0;
  min-height: 3.25rem;
  padding: 0.5rem 0.9rem;
  font-family: var(--font-mono);
  font-size: clamp(1.1rem, 1rem + 1vw, 1.45rem);
  font-variant-numeric: tabular-nums slashed-zero;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-sm);
  transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
}

.answer-row input::placeholder {
  color: var(--ink-soft);
  opacity: 0.7;
  letter-spacing: 0.02em;
}

.answer-row input:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--focus);
}

.answer-row input[aria-invalid="true"] {
  border-color: var(--wrong);
}

.binary-keys {
  display: none;
}

@media (pointer: coarse) {
  .binary-keys:not([hidden]) {
    display: flex;
    gap: 0.5rem;
  }

  .binary-keys button {
    touch-action: manipulation;
    min-width: 3.25rem;
    min-height: 2.75rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-sunk);
    font-family: var(--font-mono);
    font-weight: 700;
  }

  .answer-row .binary-keys {
    flex-basis: 100%;
  }

  #table-keys {
    margin-top: 0.5rem;
  }

  .editable-bit input[data-keypad-target] {
    box-shadow: inset 0 0 0 2px var(--focus);
  }
}

.primary {
  flex: 0 0 auto;
  min-height: 3.25rem;
  padding-inline: 1.5rem;
  color: #1b2430;
  background: var(--accent-fill);
  border: 2px solid var(--line-strong);
  box-shadow: var(--press);
}

.primary:hover {
  background: #ffb63a;
}

/* On narrow screens the submit button goes full width under the input */
@media (max-width: 26rem) {
  .primary {
    flex: 1 1 100%;
  }
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

/* ---------- Feedback -------------------------------------------------- */
.feedback {
  min-height: 1.5rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.feedback:empty {
  min-height: 0;
}

.feedback[data-state] {
  padding: 0.75rem 1rem;
  border: 1px solid currentColor;
  border-radius: var(--radius-sm);
  animation: feedback-in 220ms var(--ease);
}

.feedback[data-state="correct"] {
  color: var(--correct);
  background: var(--correct-wash);
}

.feedback[data-state="wrong"] {
  color: var(--wrong);
  background: var(--wrong-wash);
}

.feedback[data-state]:empty {
  display: none;
}

@keyframes feedback-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Help ------------------------------------------------------ */
.help {
  border-top: 1px dashed var(--line);
  padding-top: 1rem;
}

.help summary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.help summary::-webkit-details-marker {
  display: none;
}

.help summary::before {
  content: "+";
  display: grid;
  place-items: center;
  width: 1.4rem;
  height: 1.4rem;
  font-family: var(--font-mono);
  font-weight: 700;
  line-height: 1;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  transition: transform 150ms var(--ease);
}

.help[open] summary::before {
  content: "\2212";
  background: var(--accent-fill);
  color: #1b2430;
  border-color: var(--accent-fill);
}

.help summary:hover {
  color: var(--accent);
}

.help-copy {
  max-width: 60ch;
  margin-top: 0.5rem;
  padding: 0.9rem 1rem;
  color: var(--ink-soft);
  background: var(--surface-sunk);
  border-radius: var(--radius-sm);
}

.help-copy > * + * {
  margin-top: 0.6rem;
}

.help-copy code,
.help-copy kbd {
  font-family: var(--font-mono);
  font-size: 0.92em;
  padding: 0.05em 0.35em;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.25rem;
}

@media (max-width: 45.99rem) {
  html {
    scroll-padding-top: calc(4rem + env(safe-area-inset-top));
  }

  .site-header {
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
    flex-wrap: nowrap;
    gap: 0.5rem;
    padding-block: max(0.75rem, env(safe-area-inset-top)) 0.75rem;
    background: var(--paper);
  }

  .brand {
    min-width: 0;
    gap: 0.45rem;
    font-size: 1rem;
  }

  .brand-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .score {
    flex-shrink: 0;
    gap: 0.35rem;
    padding-inline: 0.55rem 0.3rem;
  }

  .score > span {
    letter-spacing: 0.04em;
  }

  .score-context {
    display: none;
  }
}

/* ---------- Narrow-screen tightening ---------------------------------- */
@media (max-width: 24rem) {
  .controls {
    padding: 1rem;
  }

  .expression {
    letter-spacing: 0;
  }
}

/* ---------- Accessibility preferences --------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .new-question:active,
  .primary:active {
    transform: none;
  }
}

@media (prefers-contrast: more) {
  :root {
    --line: var(--line-strong);
    --ink-soft: var(--ink);
  }
}

@media (forced-colors: active) {
  .mode[aria-pressed="true"],
  .levels button[aria-pressed="true"] {
    outline: 3px solid Highlight;
    outline-offset: -3px;
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }

  .problem,
  .feedback[data-state],
  .brand-mark {
    border: 2px solid CanvasText;
  }

  :focus-visible {
    outline-color: Highlight;
  }
}

@media print {
  body {
    background: #fff;
  }

  .controls,
  .new-question,
  .answer-form {
    display: none;
  }
}

.guided-toggle {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 44px;
  margin-top: 0.75rem;
  font-weight: 650;
  cursor: pointer;
}

.guided-work[hidden] {
  display: none;
}

.guided-toggle input {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  accent-color: var(--accent);
}

.theme-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  clear: both;
}

.theme-options label {
  position: relative;
  cursor: pointer;
}

.theme-options input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.theme-icon {
  display: grid;
  place-items: center;
  pointer-events: none;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-sunk);
  font-size: 1.25rem;
  line-height: 1;
}

.theme-options input:checked + .theme-icon {
  background: var(--accent-wash);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.theme-options input:focus-visible + .theme-icon {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.theme-monitor {
  position: relative;
  width: 1.05rem;
  height: 0.75rem;
  margin-bottom: 0.2rem;
  border: 2px solid currentColor;
  border-radius: 0.13rem;
}

.theme-monitor::after {
  position: absolute;
  bottom: -0.32rem;
  left: 25%;
  width: 50%;
  border-bottom: 2px solid currentColor;
  content: "";
}

@media (forced-colors: active) {
  .theme-options input:checked + .theme-icon {
    outline: 2px solid Highlight;
    outline-offset: -3px;
  }
}

.guided-work {
  min-width: 0;
  margin-bottom: 1rem;
}

.guided-work h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.place-table-scroll {
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.place-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums slashed-zero;
  text-align: center;
}

.place-table th,
.place-table td {
  min-width: 2rem;
  padding: 0.45rem 0.55rem;
  white-space: nowrap;
  border-inline-end: 1px solid var(--line);
}

.place-table th:last-child,
.place-table td:last-child {
  border-inline-end: 0;
}

.place-table tr + tr {
  border-top: 1px solid var(--line);
}

.place-table th {
  background: var(--surface-sunk);
}

.place-table th[scope="row"] {
  position: sticky;
  inset-inline-start: 0;
  text-align: start;
}

.place-table .current-place {
  background: var(--accent-wash);
  box-shadow: inset 0 -2px var(--accent);
}

.place-table .transfer-row > :is(th, td) {
  background: var(--accent-wash);
}

.place-table .result-row > :is(th, td) {
  background: var(--correct-wash);
}

.place-table .editable-bit {
  padding: 0.25rem;
}

.editable-bit input {
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: center;
}

.editable-bit input[aria-invalid="true"] {
  border-color: var(--wrong);
}

#check-table {
  margin-top: 0.85rem;
}

.guided-step {
  margin: 0.85rem 0 0;
  font-size: clamp(1.2rem, 1.05rem + 0.6vw, 1.5rem);
  line-height: 1.5;
}

.answer-row input[data-kind="binary"] {
  text-align: end;
}

.guided-step strong,
.feedback strong {
  font-weight: 800;
}

.working-toggle {
  justify-self: start;
}

.working-toggle[hidden] {
  display: none;
}

.guided-step > span {
  display: block;
  margin-top: 0.2em;
}

.guided-step .step-number {
  margin: 0 0 0.35em;
  font-size: 0.8em;
  color: var(--ink-soft);
  font-weight: 700;
}

.place-table .transfer-bit {
  color: var(--accent);
  font-weight: 800;
}

.place-table .transfer-arrived,
.place-table .bit-written {
  box-shadow: inset 0 -2px var(--accent);
  font-weight: 800;
}

@media (prefers-reduced-motion: no-preference) {
  .place-table .transfer-arrived > span {
    display: inline-block;
    animation: transfer-arrives 500ms ease-out;
  }

  .place-table .bit-written {
    animation: bit-written 500ms ease-out;
  }
}

@keyframes transfer-arrives {
  from {
    transform: translateX(1.5em);
    opacity: 0.35;
  }
}

@keyframes bit-written {
  from {
    background-color: var(--accent-wash);
    box-shadow: inset 0 0 0 2px var(--accent);
  }
}

.help-guide {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(58rem, calc(100% - 2rem));
  height: min(54rem, calc(100dvh - 2rem));
  max-width: none;
  max-height: none;
  padding: 0;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: hidden;
}

@media (max-width: 45.99rem) {
  .help-guide {
    width: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .guide-header {
    padding-top: max(0.8rem, env(safe-area-inset-top));
  }

  .guide-navigation {
    padding-bottom: max(0.8rem, env(safe-area-inset-bottom));
  }
}

.help-guide[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.help-guide::backdrop {
  background: rgb(0 0 0 / 0.52);
}

@media (prefers-reduced-motion: no-preference) {
  .help-guide[open] {
    animation: practice-in 240ms var(--ease) backwards;
  }
}

.guide-header,
.guide-navigation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.8rem;
  background: var(--surface-sunk);
}

.guide-header {
  border-bottom: 1px solid var(--line);
}

.guide-header p {
  margin-top: 0.2rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.guide-slides {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 100%;
  grid-template-rows: minmax(0, 1fr);
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.guide-slide {
  min-width: 0;
  padding: clamp(0.85rem, 4vw, 1.6rem);
  overflow-y: auto;
  scroll-snap-align: start;
}

@media (any-pointer: fine) {
  .guide-slides {
    cursor: grab;
    user-select: none;
  }
}

.guide-slides.is-dragging {
  cursor: grabbing;
  scroll-snap-type: none;
}

.guide-slide h3 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.2;
}

.guide-slide > p {
  margin-top: 0.8rem;
}

.guide-preview {
  position: relative;
  margin-top: 0.85rem;
}

.guide-pointer {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--accent-fill);
  box-shadow: 0 0 0 3px var(--surface);
  pointer-events: none;
}

.guide-demo-press {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.guide-preview .exercise,
.guide-preview.exercise {
  gap: 0.65rem;
  padding: clamp(0.6rem, 3vw, 1rem);
}

.guide-preview .problem {
  padding: 0.65rem 0.8rem;
}

.guide-preview .instruction {
  margin-bottom: 0.35rem;
}

.guide-preview .feedback {
  min-height: 3.2rem;
}

.guide-hint-explanation p {
  margin-top: 0.6rem;
  padding: 0.65rem 0.8rem;
  border-inline-start: 3px solid var(--accent);
  background: var(--accent-wash);
}

.guide-example {
  padding: 0.65rem 0.8rem;
  border-inline-start: 3px solid var(--accent);
  background: var(--accent-wash);
}

.guide-navigation {
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: auto 1fr auto;
}

.guide-navigation button {
  padding-inline: 0.65rem;
}

.guide-navigation span {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-align: center;
}

.calculator {
  position: fixed;
  z-index: 3;
  inset-inline-end: calc(0.75rem + env(safe-area-inset-right));
  inset-block-end: calc(0.75rem + env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100vw - 1.5rem);
  color: var(--ink);
}

.calculator[open] {
  inset-block-end: calc(0.75rem + max(env(safe-area-inset-bottom), var(--keyboard-inset, 0px)));
}

.calculator > summary {
  width: max-content;
  margin-inline-start: auto;
  padding: 0.6rem 0.9rem;
  min-height: 2.75rem;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--press);
  font-weight: 750;
  cursor: pointer;
}

.calculator-panel {
  position: absolute;
  inset-inline-end: 0;
  inset-block-end: calc(100% + 0.55rem);
  display: grid;
  gap: 0.55rem;
  width: min(17rem, calc(100vw - 1.5rem));
  max-height: calc(100vh - 5rem);
  max-height: max(5rem, calc(var(--visible-height, 100dvh) - 5rem - env(safe-area-inset-top)));
  overflow-y: auto;
  padding: 0.85rem;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.calculator-panel label {
  font-weight: 700;
}

.calculator-panel input {
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-sunk);
  color: var(--ink);
  font-family: var(--font-mono);
}

.calculator-panel output {
  min-height: 1.55em;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-weight: 700;
}

.calculator-keys {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
}

.calculator-keys button {
  min-height: 2.75rem;
  padding: 0.25rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-sunk);
  color: var(--ink);
  font-weight: 700;
}

.calculator-keys button[type="submit"] {
  grid-row: span 2;
  background: var(--accent-fill);
  color: #1b2430;
}

.calculator-keys button[data-key="0"] {
  grid-column: span 2;
}

.calculator-keys button:hover,
.calculator > summary:hover {
  box-shadow: inset 0 0 0 1px currentColor;
}

@media print {
  .calculator {
    display: none;
  }
}

.test-start,
.test-results {
  display: grid;
  gap: 0.65rem;
}

.test-start {
  margin-top: 0.75rem;
}

.test-start button {
  justify-content: space-between;
  text-align: start;
}

.test-duration {
  flex: none;
  color: var(--ink-soft);
  font: 600 0.8rem var(--font-mono);
}

.test-progress,
.test-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.test-progress {
  position: sticky;
  z-index: 1;
  top: 0;
  padding-block: 0.35rem;
  background: var(--surface);
  color: var(--ink-soft);
  font-weight: 700;
}

.test-clock {
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}

.test-clock strong {
  margin-inline-start: 0.25rem;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.test-clock[data-urgent="true"] {
  border-color: var(--wrong);
  background: var(--wrong-wash);
  color: var(--wrong);
}

.test-actions {
  justify-content: flex-start;
}

.test-results h3 {
  margin: 0;
  font-size: clamp(1.35rem, 1.15rem + 1vw, 1.9rem);
}

#test-summary {
  font-size: 1.15rem;
}

#test-review {
  margin: 0.25rem 0 0.75rem;
  padding-inline-start: 1.8rem;
}

#test-review li {
  padding: 0.6rem 0.3rem;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}

#test-review p {
  color: var(--wrong);
}

#test-review p[data-grade="correct"] {
  color: var(--correct);
}

#test-review p[data-grade="skipped"] {
  color: var(--ink-soft);
}

.test-results .primary {
  justify-self: start;
}

.exercise [hidden],
.calculator[hidden] {
  display: none;
}

.table-scroll-hint {
  margin-bottom: 0.4rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

@media (max-width: 45.99rem), (pointer: coarse) and (max-height: 31.25rem) {
  .site-header {
    gap: 0.55rem;
  }

  .score {
    gap: 0.35rem;
    padding-inline: 0.55rem 0.3rem;
  }

  .score > span {
    letter-spacing: 0.04em;
  }

  .brand {
    font-size: 1rem;
  }

  .shell {
    padding-top: 1.15rem;
  }

  .exercise {
    gap: 1rem;
  }

  .place-table th,
  .place-table td {
    padding-inline: 0.4rem;
  }
}

