/* Worksheet maker and printable sheets. Everything on a sheet is measured in --ws-u, the width of one dot:
   on screen it is the sheet width divided by the page width in dots, so the preview is a true small copy of the page;
   on paper (.ws-at-print) it is 2 mm, or 2.8 mm for large print. */
.ws-maker { display: grid; gap: 16px; margin: 28px 0 0; padding: 24px; border-radius: var(--r-panel); background: var(--panel); box-shadow: var(--shadow); }
.article .ws-maker h2 { margin: 0; font-size: 26px; }
.article .ws-maker p { margin: 0; }
.article .ws-note { color: var(--sec); font-size: 15px; }
.ws-form { display: grid; gap: 16px; min-width: 0; }
.ws-form[hidden], .ws-output[hidden] { display: none; }
.ws-types { min-width: 0; margin: 0; padding: 0; border: 0; }
.ws-types legend { padding: 0; margin-bottom: 10px; font-weight: 600; }
.ws-choices-row, .ws-sets, .ws-checks, .ws-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ws-choice-label, .ws-check { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--tile); cursor: pointer; }
.ws-choice-label:has(input:checked) { border: 2px solid var(--ink); padding: 0 15px; font-weight: 650; }
.ws-choice-label input, .ws-check input { width: 20px; height: 20px; margin: 0; accent-color: var(--ink); }
.ws-set { min-height: 44px; padding: 0 16px; font-size: 15px; }
.ws-field-label { display: grid; gap: 6px; min-width: 0; font-weight: 600; }
.ws-form textarea, .ws-form input[type="text"], .ws-form input[type="number"] { display: block; width: 100%; min-width: 0; min-height: 48px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--ink); font-weight: 400; }
.ws-form textarea { min-height: 96px; resize: vertical; }
.ws-fields-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 14px; }
.ws-form input:disabled { opacity: 0.5; }
.ws-check:has(input:disabled) { opacity: 0.6; cursor: default; }
.ws-output { display: grid; gap: 14px; min-width: 0; }
.article .ws-status { font-weight: 600; overflow-wrap: anywhere; }
.ws-ready { display: grid; gap: 28px; }
.ws-ready-sheet { min-width: 0; }
.article .ws-ready-sheet h3 { margin-top: 28px; }
.article .ws-ready-sheet .ws-actions { margin-top: 12px; }
.ws-stage { min-width: 0; margin-top: 12px; }

/* The sheet. */
.ws-sheet { --ws-span: 87; --ws-pad: 16px; --ws-u: max(4.4px, calc((100cqw - 2 * var(--ws-pad)) / var(--ws-span))); container-type: inline-size; display: grid; gap: 12px; min-width: 0; }
.ws-sheet.ws-large { --ws-span: 62; }
.ws-sheet { --ws-text: max(14px, calc(var(--ws-u) * 2.1)); --ws-big: max(20px, calc(var(--ws-u) * 3.2)); --ws-line: max(1px, calc(var(--ws-u) * 0.15)); }
.ws-sheet .code { --u: var(--ws-u); }
.ws-sheet p, .ws-sheet ol, .ws-sheet ul, .ws-sheet li, .ws-sheet li + li { margin: 0; padding: 0; list-style: none; }
.ws-sheet .ws-page { display: grid; gap: calc(var(--ws-u) * 3); align-content: start; padding: var(--ws-pad); border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); font-size: var(--ws-text); }
.ws-sheet .ws-title { font-size: max(22px, calc(var(--ws-u) * 3.6)); font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }
.ws-sheet .ws-subtitle { color: var(--sec); }
.ws-sheet .ws-head { display: grid; gap: calc(var(--ws-u) * 2); }
.ws-sheet .ws-fields { display: flex; flex-wrap: wrap; gap: calc(var(--ws-u) * 4); }
.ws-sheet .ws-field { display: flex; flex: 1 1 calc(var(--ws-u) * 24); align-items: flex-end; gap: var(--ws-u); min-width: 0; }
.ws-sheet .ws-rule { flex: 1; min-width: calc(var(--ws-u) * 6); height: calc(var(--ws-u) * 2.4); border-bottom: var(--ws-line) solid var(--ink); }
.ws-sheet .ws-key summary { display: flex; align-items: center; min-height: 44px; font-weight: 600; cursor: pointer; }
.ws-sheet .ws-key .ws-answers { margin-top: 4px; }

/* Between two letters of the key there are at least 3 of the strip's own units, as between letters in Morse, so one
   letter's marks never run into the next letter's (inside a letter the marks are 1 unit apart). */
.ws-sheet .ws-strip { display: flex; flex-wrap: wrap; gap: calc(var(--ws-u) * 1.2) calc(var(--ws-u) * 2.6); padding: calc(var(--ws-u) * 1.5); border: var(--ws-line) solid var(--ink); }
.ws-sheet .ws-strip .code { --u: calc(var(--ws-u) * 0.85); }
.ws-sheet.ws-large .ws-strip { column-gap: calc(var(--ws-u) * 2.2); }
.ws-sheet.ws-large .ws-strip .code { --u: calc(var(--ws-u) * 0.7); }
.ws-sheet .ws-key-cell { display: grid; justify-items: center; gap: calc(var(--ws-u) * 0.5); min-width: calc(var(--ws-u) * 4); font-size: calc(var(--ws-text) * 0.95); }
.ws-sheet.ws-large .ws-key-cell { font-size: calc(var(--ws-text) * 0.75); }
.ws-sheet .ws-key-cell b { font-weight: 700; line-height: 1; }

.ws-sheet .ws-items { display: grid; gap: calc(var(--ws-u) * 2.2); }
.ws-sheet .ws-item { display: flex; align-items: flex-end; gap: calc(var(--ws-u) * 2); break-inside: avoid; }
.ws-sheet .ws-num { display: flex; flex: none; align-items: center; min-width: calc(var(--ws-u) * 3); min-height: calc(var(--ws-u) * 6); font-size: var(--ws-text); font-weight: 700; line-height: 1.2; }
.ws-sheet .ws-cells { display: flex; flex-wrap: wrap; gap: calc(var(--ws-u) * 1.5); min-width: 0; }
.ws-sheet .ws-cell { display: grid; justify-items: center; align-content: end; gap: var(--ws-u); min-width: calc(var(--ws-u) * 7); }
.ws-sheet .ws-cell.ws-wide { min-width: calc(var(--ws-u) * 10); }
.ws-sheet.ws-large .ws-box { height: calc(var(--ws-u) * 5); }
/* Large print: a box 6 dots wide (17 mm on paper) still takes a child's letter, and lets short words share a line,
   so a message such as THE TREAT IS UNDER THE BLUE BOX fits on one page. Words stay well apart (10 mm, letters 4 mm). */
.ws-sheet.ws-large .ws-cell:not(.ws-wide) { min-width: calc(var(--ws-u) * 6); }
.ws-sheet.ws-large .ws-paper .ws-cells { gap: calc(var(--ws-u) * 1.3); }
.ws-sheet.ws-large .ws-message { column-gap: calc(var(--ws-u) * 3.5); }
.ws-sheet .ws-glyph { display: flex; align-items: center; min-height: calc(var(--ws-u) * 1.6); }
.ws-sheet .ws-box { justify-self: stretch; height: calc(var(--ws-u) * 6); border: var(--ws-line) solid var(--ink); }
.ws-sheet .ws-letter { font-size: var(--ws-big); font-weight: 700; line-height: 1; }

.ws-sheet .ws-message { display: flex; flex-wrap: wrap; gap: calc(var(--ws-u) * 3) calc(var(--ws-u) * 5); }
.ws-sheet .ws-word { min-width: 0; }

.ws-sheet .ws-match { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: calc(var(--ws-u) * 6); align-items: start; }
.ws-sheet .ws-match .ws-items { gap: calc(var(--ws-u) * 2.5); }
.ws-sheet .ws-match .ws-item { align-items: center; min-height: calc(var(--ws-u) * 6); }
.ws-sheet .ws-codeword { display: flex; flex-wrap: wrap; flex: 1; gap: calc(var(--ws-u) * 2); min-width: 0; padding-left: calc(var(--ws-u) * 2); }
.ws-sheet .ws-box.ws-pick { flex: none; width: calc(var(--ws-u) * 6); height: calc(var(--ws-u) * 5); }
.ws-sheet .ws-choices { display: grid; gap: calc(var(--ws-u) * 2.5); }
.ws-sheet .ws-choice { display: flex; align-items: center; gap: calc(var(--ws-u) * 2); min-height: calc(var(--ws-u) * 6); font-size: var(--ws-big); font-weight: 700; line-height: 1; }
.ws-sheet .ws-choice .ws-num { font-size: var(--ws-text); }

.ws-sheet .ws-answer-list { display: grid; gap: calc(var(--ws-u) * 2); }
.ws-sheet .ws-answer { display: flex; flex-wrap: wrap; align-items: center; gap: calc(var(--ws-u) * 2); }
.ws-sheet .ws-reply, .ws-sheet .ws-solution { font-size: var(--ws-big); font-weight: 700; overflow-wrap: anywhere; }
.ws-sheet .ws-answer .ws-cells { gap: calc(var(--ws-u) * 2); }

/* Measuring and printing: a copy of the sheet at paper size. Page 1 is the worksheet, page 2 the answer key. */
.ws-at-print { --panel: #fff; --ink: #000; --line: #000; --sec: #000; color: #000; background: #fff; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
.ws-at-print .ws-sheet { --ws-pad: 0px; --ws-u: 2mm; display: block; width: calc(var(--ws-span) * var(--ws-u)); }
.ws-at-print .ws-sheet.ws-large { --ws-u: 2.8mm; }
.ws-at-print .ws-sheet .ws-page { padding: 0; border: 0; border-radius: 0; background: #fff; }
.ws-at-print .ws-sheet .ws-paper { break-after: page; }
.ws-at-print .ws-sheet .ws-strip, .ws-at-print .ws-sheet .ws-box { background: #fff; }
.ws-probe { position: fixed; top: 0; left: -10000px; visibility: hidden; }
.ws-ruler { height: 245mm; }
@page ws { margin: 15mm; }
@media screen { .ws-print-root { display: none; } }
@media print {
  .ws-print-root { page: ws; }
  html.ws-printing body > :not(.ws-print-root) { display: none !important; }
  html.ws-printing, html.ws-printing body { margin: 0; background: #fff; }
}

@media (max-width: 480px) {
  .ws-maker { padding: 18px 16px; }
  .ws-choice-label { flex: 1 1 100%; }
  .ws-fields-row { grid-template-columns: minmax(0, 1fr); }
  .ws-actions .btn { flex: 1 1 auto; }
  .ws-sheet { --ws-pad: 12px; }
}
