/* Register of the Present. Screen: cream ground, square controls. Sheet: paper in every scheme. */

*,
*::before,
*::after {
  box-sizing: border-box;
  border-radius: 0;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
}

main {
  max-width: calc(297mm + 32px);
  margin: 0 auto;
  padding: 32px 16px 56px;
}

main:has(.sheet[data-paper="Letter"]) {
  max-width: calc(279.4mm + 32px);
}

/* Introduction */

h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.15;
  font-weight: var(--fw-bold);
  color: var(--c-earth);
}

.lede {
  margin: 0 0 24px;
  font-size: 16px;
  line-height: 1.45;
  max-width: 62ch;
}

/* Controls */

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--ink-soft);
}

.field.grow {
  flex: 1 1 220px;
}

select,
input,
textarea,
button {
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--ink);
  border-radius: 0;
  margin: 0;
}

select,
input,
button {
  height: 40px;
  padding: 0 10px;
}

#month {
  width: 150px;
}

#year {
  width: 96px;
  font-variant-numeric: tabular-nums;
}

#paper {
  width: 96px;
}

#title {
  width: 100%;
}

button {
  padding: 0 18px;
  cursor: pointer;
}

select {
  cursor: pointer;
}

button:hover,
select:hover {
  background: var(--ink);
  color: var(--bg);
}

select:focus-visible,
input:focus-visible,
textarea:focus-visible,
button:focus-visible,
.preview:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.names {
  margin-top: 16px;
}

textarea {
  width: 100%;
  min-height: 176px;
  padding: 10px;
  line-height: 1.45;
  resize: vertical;
}

textarea::placeholder {
  color: var(--ink-soft);
}

.empty {
  margin: 10px 0 0;
  font-size: 14px;
  color: var(--ink-soft);
}

.empty[hidden] {
  display: none;
}

/* Preview: the sheet at its printed size, scrolling inside its own box */

.preview {
  margin-top: 24px;
  overflow-x: auto;
  padding-bottom: 12px;
}

/* The sheet: fixed paper and ink whatever the scheme */

.sheet {
  --pw: 297mm;
  --ph: 210mm;
  width: var(--pw);
  min-height: var(--ph);
  padding: 10mm;
  background: #ffffff;
  color: #1a1a1a;
  outline: 1px solid rgba(26, 26, 26, 0.28);
  outline-offset: -1px;
  color-scheme: light;
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
}

.sheet[data-paper="Letter"] {
  --pw: 279.4mm;
  --ph: 215.9mm;
}

.sheet p,
.sheet h2 {
  margin: 0;
}

.sheet-head {
  margin-bottom: 2mm;
  font-size: 9pt;
  line-height: 1.2;
}

.sheet-head h2 {
  font-size: 14pt;
  line-height: 1.2;
  font-weight: var(--fw-bold);
}

/* Grid */

#grid,
#key table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

#grid th,
#grid td,
#key td {
  border: 0.25pt solid #1a1a1a;
}

#grid th,
#grid td {
  padding: 0;
}

#grid col.no {
  width: 6mm;
}

#grid col.name {
  width: 42mm;
}

#grid col.tot {
  width: 14mm;
}

#grid thead {
  display: table-header-group;
}

#grid thead th {
  height: 12mm;
  padding-bottom: 0.7mm;
  vertical-align: bottom;
  text-align: center;
  font-weight: 400;
  font-size: 7pt;
  line-height: 1.2;
}

#grid thead th.name {
  text-align: left;
  padding-left: 1mm;
}

#grid th .wd,
#grid th .dn {
  display: block;
}

#grid th .wd {
  color: #5b5b5b;
}

#grid th.tot {
  font-size: var(--tot-size, 6pt);
  padding: 0 0.3mm 0.7mm;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
  text-wrap: balance;
}

#grid tr {
  break-inside: avoid;
}

#grid td {
  height: 5.5mm;
}

#grid td.no {
  font-size: 7pt;
  text-align: center;
  vertical-align: middle;
}

#grid td.name {
  padding: 0.6mm 1mm;
  font-size: 8pt;
  line-height: 1.2;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.sheet .we {
  background: rgba(26, 26, 26, 0.12);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* Key and colophon follow the last row and stay together */

.end {
  break-inside: avoid;
}

#key {
  display: flex;
  align-items: flex-start;
  gap: 2mm;
  margin-top: 1mm;
  font-size: 7pt;
  line-height: 1.1;
}

#key table {
  flex: 1 1 0;
}

#key col.sym {
  width: 5mm;
}

#key td {
  height: 3.4mm;
  padding: 0.3mm;
  vertical-align: middle;
}

#key td.sym {
  text-align: center;
}

.colophon {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 6mm;
  margin-top: 1.5mm;
  font-size: 7pt;
  line-height: 1.2;
  color: #5b5b5b;
}

.colophon img {
  display: block;
  width: 22mm;
  height: auto;
  filter: brightness(0) opacity(0.643);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) h1 {
    color: var(--ink);
  }
}

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

/* Print: only the sheet, ink on white, at the paper size chosen in #paper */

@media print {
  html,
  body {
    background: #ffffff;
    color: #1a1a1a;
  }

  main {
    max-width: none;
    padding: 0;
  }

  .intro,
  .controls {
    display: none;
  }

  .preview {
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  .sheet {
    width: calc(var(--pw) - 20mm);
    min-height: 0;
    padding: 0;
    outline: none;
  }
}
