/* The printable panel card.
   Two pages that have to survive a photocopier and a classroom wall, so the
   print rules are black ink on white paper and nothing else: no lamp glow, no
   chassis, no background fills a school printer would refuse.

   One layout for both papers. A4 is 210 by 297 mm and US Letter is 216 by
   279 mm, so a page that fits inside 190 by 250 mm prints on either without a
   reflow: A4 sets the width, Letter sets the height. The margin below is the
   same on both. */

.card-body {
  background: var(--page);
  color: var(--ink);
  margin: 0;
  padding: 0 0 2rem;
}

.card-masthead {
  max-width: 52rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 0.5rem;
}

.card-masthead p {
  margin: 0 0 0.5rem;
  color: var(--ink-dim);
}

.card-howto {
  font-size: 0.95rem;
  max-width: 40rem;
}

.card {
  max-width: 52rem;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.card-page {
  background: var(--page-raised);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 1.5rem;
  margin: 1.25rem 0;
}

.card-page h1 {
  font-size: 1.6rem;
  margin: 0 0 0.75rem;
}

.card-page h2 {
  font-size: 1.15rem;
  margin: 1.5rem 0 0.5rem;
}

.card-page p {
  max-width: 42rem;
}

.card-note {
  color: var(--ink-dim);
  font-size: 0.95rem;
}

/* Two blocks side by side where there is room. On paper this is what makes
   the first page one page: set in a single column it runs to 489 mm, which is
   two sheets of anything. */
.card-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 2rem;
  align-items: start;
}

@media (max-width: 45rem) {
  .card-cols {
    grid-template-columns: 1fr;
  }
}

.card-steps {
  max-width: 42rem;
  padding-left: 1.2rem;
}

.card-steps li {
  margin-bottom: 0.35rem;
}

/* ---- tables --------------------------------------------------------------
   Three shapes: the switch and lamp tables read as prose, the ruler is one
   byte drawn across the switches, the opcode table is eight columns of
   thirty-two. All of them go monospace for anything that is a number, so a
   column of octal lines up. */

.card-table,
.card-ruler,
.card-opcodes {
  border-collapse: collapse;
  width: 100%;
  margin: 0.5rem 0 1rem;
  font-size: 0.92rem;
}

.card-table caption,
.card-ruler caption {
  text-align: left;
  color: var(--ink-dim);
  font-size: 0.9rem;
  padding-bottom: 0.35rem;
}

.card-table th,
.card-table td {
  border-bottom: 1px solid var(--rule);
  padding: 0.3rem 0.5rem 0.3rem 0;
  text-align: left;
  vertical-align: top;
}

.card-table thead th {
  color: var(--ink-dim);
  font-weight: 600;
}

.card-listing {
  max-width: 28rem;
}

.card-listing .addr,
.card-listing .byte {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  white-space: nowrap;
}

.card-ruler td {
  border: 1px solid var(--rule);
  padding: 0.3rem 0.2rem;
  text-align: center;
  font-size: 0.85rem;
}

.card-ruler .bit b,
.card-ruler .grp b {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 1.05rem;
}

.card-ruler .grp {
  color: var(--ink-dim);
}

/* The opcode table is as wide as its widest mnemonic and no wider. Fixed
   columns with an ellipsis were tried first and turned CALL* addr into
   CALL* a… on an ordinary laptop, which is a card that lies. A narrow screen
   scrolls it sideways instead; the tabindex is what lets a keyboard do that. */
.card-scroll {
  overflow-x: auto;
}

.card-opcodes {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.72rem;
  table-layout: auto;
  width: auto;
}

.card-opcodes td {
  padding: 0.1rem 0.6rem 0.1rem 0;
  white-space: nowrap;
}

.card-opcodes b {
  color: var(--accent);
  font-weight: 600;
}

/* A wide table on a narrow phone scrolls sideways rather than squashing the
   mnemonics into two letters. */
@media (max-width: 40rem) {
  .card-opcodes {
    font-size: 0.68rem;
  }
  .card-page {
    padding: 1rem 0.75rem;
  }
}

/* ---- print ---------------------------------------------------------------- */

@media print {
  @page {
    margin: 12mm;
  }

  .card-body {
    background: #fff;
    color: #000;
    font-size: 9pt;
    /* Screen leading is generous on purpose and costs a whole sheet here. */
    line-height: 1.25;
  }

  .card-masthead,
  .card-foot {
    display: none;
  }

  .card {
    max-width: none;
    padding: 0;
  }

  .card-page {
    background: none;
    border: 0;
    border-radius: 0;
    padding: 0;
    margin: 0;
    break-after: page;
    break-after: page;
  }

  .card-page:last-child {
    break-after: auto;
    break-after: auto;
  }

  .card-page h1 {
    font-size: 16pt;
    margin: 0 0 4pt;
  }

  .card-page h2 {
    font-size: 11pt;
    margin: 6pt 0 2pt;
  }

  .card-table,
  .card-ruler,
  .card-opcodes {
    margin: 2pt 0 5pt;
  }

  .card-page p {
    margin: 0 0 4pt;
  }

  .card-page p,
  .card-steps {
    max-width: none;
    font-size: 8.5pt;
  }

  .card-table,
  .card-ruler {
    font-size: 7.5pt;
  }

  .card-cols {
    grid-template-columns: 1fr 1fr;
    gap: 0 6mm;
  }

  .card-table th,
  .card-table td {
    padding: 1pt 4pt 1pt 0;
  }

  .card-ruler td {
    padding: 2pt 1pt;
  }

  .card-steps li {
    margin-bottom: 1pt;
  }

  .card-table caption,
  .card-ruler caption,
  .card-note {
    color: #333;
  }

  .card-table th,
  .card-table td,
  .card-ruler td {
    border-color: #999;
  }

  .card-opcodes {
    font-size: 6.6pt;
    width: 100%;
  }

  .card-scroll {
    overflow: visible;
  }

  .card-opcodes b {
    color: #000;
  }

  /* A table split across a page break loses its top row to the fold. */
  .card-table,
  .card-ruler,
  .card-opcodes,
  .card-opcodes tr {
    break-inside: avoid;
    break-inside: avoid;
  }
}

/* Opcode cells and the sources list. */
.op { font-variant-numeric: tabular-nums; }
.card-sources { margin: 1rem 0 0; padding-left: 1.2rem; font-size: 0.75rem; }
@media print {
  /* Kept on paper as one small line, so the card stays two pages. */
  .card-sources-section { margin-top: 2mm; break-inside: avoid; }
  .card-sources-section h2 { display: none; }
  .card-sources { list-style: none; padding: 0; margin: 0; font-size: 6.5pt; line-height: 1.25; }
  .card-sources li { display: inline; }
  .card-sources li + li::before { content: ' \00b7 '; }
}

.card-sources-section { margin-top: 1rem; }
