/* Printable crossword. --pcw-cell is one square: fluid on screen, fixed millimetres on paper —
   the squares are square, so a percentage width would make the grid as tall as it is wide and
   push the clues onto a second page. */
.pcw { --pcw-cell: clamp(19px, calc((100vw - 76px) / 13), 38px); }
.pcw [hidden] { display: none !important; }

/* One class per column count, since the CSP rules out setting the property inline: a puzzle
   wider than the last class gets no grid at all. */
.pcw-cols-5 { --pcw-cols: 5; }
.pcw-cols-6 { --pcw-cols: 6; }
.pcw-cols-7 { --pcw-cols: 7; }
.pcw-cols-8 { --pcw-cols: 8; }
.pcw-cols-9 { --pcw-cols: 9; }
.pcw-cols-10 { --pcw-cols: 10; }
.pcw-cols-11 { --pcw-cols: 11; }
.pcw-cols-12 { --pcw-cols: 12; }
.pcw-cols-13 { --pcw-cols: 13; }
.pcw-cols-14 { --pcw-cols: 14; }
.pcw-cols-15 { --pcw-cols: 15; }
.pcw-cols-16 { --pcw-cols: 16; }
.pcw-cols-17 { --pcw-cols: 17; }
.pcw-cols-18 { --pcw-cols: 18; }

/* --- the form ------------------------------------------------------------- */
.pcw-ui {
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius);
  padding: 20px; margin: 18px 0 24px;
}
.pcw-pick, .pcw-checks { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
.pcw-legend { font-weight: 600; padding: 0; margin-bottom: 8px; }
.pcw-list { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.pcw-option {
  display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--c-border); border-radius: 10px; background: var(--c-surface);
  cursor: pointer;
}
.pcw-option:has(input:checked) { border-color: var(--c-primary, #6c5ce7); }
.pcw-option input { grid-row: 1 / span 2; margin: 0; }
.pcw-option-name { font-weight: 600; }
.pcw-option-meta { color: var(--c-text-soft); font-size: .85rem; }
.pcw-pick-actions { margin: 10px 0 0; display: flex; gap: 16px; }
.pcw-link {
  background: none; border: 0; padding: 0; font: inherit; color: var(--c-primary, #6c5ce7);
  text-decoration: underline; cursor: pointer;
}
.pcw-check { display: block; margin-bottom: 6px; color: var(--c-text); }
.pcw-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.pcw-msg { margin: 12px 0 0; color: var(--c-error); }

/* --- a sheet -------------------------------------------------------------- */
.pcw-sheet, .pcw-key {
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius);
  padding: 22px; margin-bottom: 18px;
}
.pcw-sheet-head { text-align: center; margin-bottom: 14px; }
.pcw-sheet-head h2 { margin: 0; font-size: 1.35rem; }
.pcw-sheet-head p { margin: 2px 0 0; color: var(--c-text-soft); font-size: .9rem; }

/* Borders overlap by one line, so two squares side by side share an edge instead of doubling it. */
.pcw-grid {
  display: grid;
  grid-template-columns: repeat(var(--pcw-cols), var(--pcw-cell));
  grid-auto-rows: var(--pcw-cell);
  width: max-content; max-width: 100%; margin: 0 auto;
}
.pcw-cell {
  position: relative; box-sizing: border-box; background: #fff; border: 1px solid #000;
  margin: 0 -1px -1px 0; display: flex; align-items: center; justify-content: center;
}
.pcw-cell i {
  position: absolute; top: 1px; left: 2px; font-style: normal; font-weight: 700; line-height: 1; color: #000;
  font-size: calc(var(--pcw-cell) * .3);
}
.pcw-cell b { font-size: calc(var(--pcw-cell) * .6); line-height: 1; font-weight: 600; color: #000; }

.pcw-clues { display: grid; gap: 14px 28px; margin-top: 20px; }
.pcw-clue-block h3 { margin: 0 0 6px; font-size: 1rem; }
.pcw-clue-block ul { list-style: none; margin: 0; padding: 0; }
.pcw-clue-block li { margin-bottom: 4px; padding-left: 2em; text-indent: -2em; }
.pcw-clue-block li b { display: inline-block; width: 2em; text-indent: 0; }
.pcw-clue-block li span { color: var(--c-text-soft); white-space: nowrap; }
@media (min-width: 560px) { .pcw-clues { grid-template-columns: 1fr 1fr; } }

.pcw-credit { margin: 18px 0 0; text-align: center; font-size: .72rem; color: #999; }
.pcw-no-credit .pcw-credit { display: none; }

/* --- the answer key ------------------------------------------------------- */
.pcw:not(.pcw-is-answers) .pcw-keys { display: none; }
.pcw-key { --pcw-cell: 14px; }
.pcw-key h2 { margin: 0 0 10px; font-size: .95rem; text-align: center; }
.pcw-key h2 span { font-weight: 400; color: var(--c-text-soft); }
.pcw-keys { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.pcw-keys .pcw-credit { grid-column: 1 / -1; }
.pcw-key { margin-bottom: 0; }

@page { margin: 10mm 14mm; }

@media print {
  .site-header, .site-footer, .fb-dialog, .tool-hero, .tool-prose,
  #tool-root[data-tool="printable-crossword"] .breadcrumb, .pcw-ui { display: none !important; }
  html, body { background: #fff; }
  .container { max-width: none; padding: 0; }

  .pcw { --pcw-cell: 11mm; color: #000; }
  .pcw.pcw-is-large { --pcw-cell: 12mm; }

  .pcw-sheet, .pcw-key { border: 0; border-radius: 0; box-shadow: none; padding: 0; margin: 0; background: none; }
  /* Break BEFORE each sheet after the first, never after: a break-after on the last sheet
     ejects a blank page. Hidden sheets are display:none, so ~ only sees the ones that print. */
  .pcw-sheet:not([hidden]) ~ .pcw-sheet:not([hidden]) { break-before: page; page-break-before: always; }
  .pcw-keys { break-before: page; page-break-before: always; display: block; }
  .pcw:not(.pcw-is-answers) .pcw-keys { display: none !important; }

  .pcw-sheet-head { margin-bottom: 5mm; }
  .pcw-sheet-head h2 { font-size: 20pt; }
  .pcw-sheet-head p { color: #333; font-size: 10pt; }
  .pcw-cell { border: .6pt solid #000; margin: 0 -.6pt -.6pt 0; }
  .pcw-cell i { top: .4mm; left: .7mm; font-size: 7pt; }
  .pcw-cell b { font-size: 15pt; }
  .pcw-is-large .pcw-cell i { font-size: 8.5pt; }

  /* The clues and the credit line move as one block, so a line that would not fit under them
     never lands alone on a page of its own. */
  .pcw-tail { margin-top: 6mm; break-inside: avoid; }
  .pcw-clues { gap: 6mm 10mm; grid-template-columns: 1fr 1fr; font-size: 10.5pt; }
  .pcw-is-large .pcw-clues { font-size: 12pt; line-height: 1.3; }
  .pcw-clue-block h3 { font-size: 12pt; margin-bottom: 2mm; }
  .pcw-clue-block li { margin-bottom: 1.4mm; break-inside: avoid; }
  .pcw-clue-block li span { color: #333; }

  /* Four to a page. inline-block rather than grid: a grid container does not split cleanly
     across pages in every browser. */
  .pcw-key { display: inline-block; vertical-align: top; width: 47%; margin: 0 1% 8mm; break-inside: avoid; --pcw-cell: 6mm; }
  .pcw-key h2 { font-size: 10pt; margin-bottom: 3mm; }
  .pcw-key .pcw-cell b { font-size: 9pt; }
  .pcw-key .pcw-cell { border-width: .4pt; margin: 0 -.4pt -.4pt 0; }
  .pcw-credit { color: #777; font-size: 8pt; margin-top: 6mm; }
}
