* { box-sizing: border-box; border-radius: 0; }

html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font-body);
}
#results { overflow-wrap: anywhere; }
main { max-width: 760px; margin: 0 auto; padding: 24px 16px 48px; }

.mast { margin-bottom: 40px; }
.wordmark { display: block; width: 140px; height: auto; }

h1 { font-size: 1.75rem; line-height: 1.2; font-weight: var(--fw-bold); margin: 0 0 8px; }
h2 { font-size: 1.05rem; font-weight: var(--fw-bold); margin: 32px 0 12px; }
h3 { font-size: 1rem; font-weight: var(--fw-bold); margin: 0; }
p { margin: 0 0 6px; }
.lede { max-width: 36em; margin-bottom: 24px; }

.form { display: grid; gap: 4px; max-width: 30em; }
label { font-weight: var(--fw-medium); margin-top: 8px; }
input {
  -webkit-appearance: none;
  appearance: none;
  font: 1rem/1.4 ui-monospace, Menlo, monospace;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--ink);
  padding: 8px 10px;
  width: 100%;
}
input:focus { outline: 2px solid var(--ink); outline-offset: 1px; }

.controls { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 24px; margin-top: 14px; }
#practice { margin: 0; }
button {
  -webkit-appearance: none;
  appearance: none;
  font: inherit;
  color: var(--ink);
  background: none;
  border: 0;
  padding: 2px 4px;
  cursor: pointer;
}
#practice button { text-decoration: underline; text-underline-offset: 3px; }
#print { border: 1px solid var(--ink); padding: 4px 16px; }
button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

#message { min-height: 1.5em; margin: 16px 0 0; }
#message.error { color: var(--error); }
#message.soft { color: var(--ink-soft); }

/* The item: square cells with the position above. */
#item { margin-top: 16px; }
.cells { display: flex; flex-wrap: wrap; gap: 8px; }
.slot { display: flex; flex-direction: column; align-items: center; max-width: 100%; }
.pos { font-size: 0.7rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.cell, .kcell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 2.75em;
  min-height: 2.75em;
  max-width: 100%;
  padding: 0 0.45em;
  border: 1px solid var(--ink);
  font-family: ui-monospace, Menlo, monospace;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
  text-align: center;
}

.rule { border-top: 1px solid var(--ink); padding: 14px 0 18px; }
.rule-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 16px; margin-bottom: 6px; }
.next { margin: 0; font-family: ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.formula { margin: 8px 0; }
code, td, .reference {
  font-family: ui-monospace, Menlo, monospace;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
code { font-size: 0.95em; }
.caption, .small, .also-label { color: var(--ink-soft); font-size: 0.875rem; }
.also-label { margin-top: 12px; }
ul[data-field="also"] { margin: 4px 0 0; padding-left: 1.2em; }
ul[data-field="also"] li { margin-bottom: 4px; overflow-wrap: anywhere; }

table { border-collapse: collapse; margin: 10px 0; font-size: 0.9rem; }
th, td { border-bottom: 1px solid var(--ink); padding: 3px 10px 3px 0; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
th { font-weight: var(--fw-medium); border-bottom-width: 1px; }
table.check, table.accepted { width: 100%; table-layout: fixed; }
table.check th:nth-child(1) { width: 3em; }
table.check th:nth-child(4) { width: 4.5em; }
table.accepted th:nth-child(2) { width: 4.5em; }
table.accepted th:nth-child(3) { width: 40%; }

.digits { border-top: 1px solid var(--ink); }
.digits h2 { margin-top: 18px; }

/* The answer key: a separate sheet. */
#key {
  margin-top: 40px;
  padding: 18px 16px 14px;
  background: var(--c-lavlt);
  border-top: 3px double var(--ink);
  border-bottom: 3px double var(--ink);
}
.key-item { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 16px; }
.key-item p { margin: 0 0 0.7em; }
#key h2 { margin-top: 20px; }
#key hr { border: 0; border-top: 1px solid var(--ink); margin: 14px 0 8px; }
[data-field="reference"] { font-family: ui-monospace, Menlo, monospace; font-size: 0.85rem; overflow-wrap: anywhere; }

.colophon { margin-top: 48px; color: var(--ink-soft); font-size: 0.8rem; }

.print-only { display: none; }
[hidden] { display: none !important; }

@page { size: A4; margin: 16mm; }
@media print {
  html, body { background: #fff; color: #000; font-size: 12.5px; line-height: 1.35; }
  th, td { padding: 1px 10px 1px 0; }
  table { margin: 6px 0; }
  .digits h2 { margin-top: 10px; }
  h1 { font-size: 1.5rem; }
  h2 { margin: 18px 0 8px; }
  main { max-width: none; padding: 0; }
  .form, #terms, #answer, label, #practice, #print, #message, .lede, .colophon, .mast { display: none; }
  .print-only { display: block; }
  .sheet-head { display: flex; gap: 32px; margin-bottom: 18px; }
  .sheet-head p { flex: 1; display: flex; gap: 8px; }
  .blank { flex: 1; border-bottom: 1px solid #000; }
  .pos, .caption, .small, .also-label, #message.soft { color: #000; }
  .cell, .kcell, th, td, .rule, .digits, #key hr { border-color: #000; }
  #item [data-field="typed"] { margin-top: 10px; }
  .rule { padding: 10px 0 12px; }
  tr, .rule-head, .formula { break-inside: avoid; }
  .rule-head, h2 { break-after: avoid; }
  #key {
    break-before: page;
    background: none;
    margin-top: 0;
    padding: 12px 0;
    border-color: #000;
  }
}
