@page {
  size: auto;
  margin: 10mm;
}

.print-pages {
  color: #111;
  background: #fff;
  font-family: var(--puzzle-font, system-ui, sans-serif);
}

.print-sheet {
  display: grid;
  align-content: start;
  width: min(100%, 7.5in);
  min-height: 9.5in;
  margin: 0 auto;
  padding: 0.1in;
  color: #111;
  background: #fff;
}

.print-title {
  margin: 0 0 0.08in;
  font-size: 22pt;
  line-height: 1.1;
  text-align: center;
}

.print-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), 1fr);
  width: min(6.7in, calc(8.4in * var(--grid-cols) / var(--grid-rows)), 100%);
  aspect-ratio: var(--grid-cols) / var(--grid-rows);
  margin: 0 auto;
  border-top: 2px solid #111;
  border-left: 2px solid #111;
}

.print-cell {
  display: grid;
  place-items: center;
  min-width: 0;
  border-right: 1px solid #111;
  border-bottom: 1px solid #111;
  font-size: clamp(7pt, calc(34pt - var(--grid-cols) * 1pt), 18pt);
  line-height: 1;
  font-family: var(--puzzle-font, system-ui, sans-serif);
}

.answer-grid .answer-letter {
  color: #111;
  background: #b8ddb5;
  box-shadow: inset 0 0 0 1px #538d4e;
}

.word-bank {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.06in 0.18in;
  margin: 0.16in 0 0;
  padding: 0.12in;
  border: 2px solid #111;
  list-style: none;
  font-size: 10pt;
  text-align: center;
  font-family: var(--puzzle-font, system-ui, sans-serif);
}

.print-attribution {
  align-self: end;
  margin: auto 0 0;
  padding-top: 0.12in;
  font-size: 7pt;
  line-height: 1.2;
  text-align: center;
}

.puzzle-sheet {
  grid-template-rows: auto auto auto 1fr;
  break-after: page;
  page-break-after: always;
}

.print-error {
  max-width: 36rem;
  margin: 3rem auto;
  padding: 1.5rem;
  border: 3px solid #111;
  color: #111;
  background: #fff;
}

body.print-mode {
  background: #fff;
}

body.print-mode > *:not(#print-root),
body.print-mode [data-screen-only],
body.print-mode nav,
body.print-mode button,
body.print-mode input,
body.print-mode select,
body.print-mode textarea {
  display: none !important;
}

body.print-mode .print-pages {
  display: block;
}

@media screen {
  .print-pages {
    width: min(100% - 2rem, 8.5in);
    margin: 2rem auto;
    padding: 0.5in;
    color: #111;
    background: #fff;
    box-shadow: 0 8px 30px rgb(0 0 0 / 35%);
  }

  .print-sheet + .print-sheet {
    margin-top: 0.5in;
  }
}

@media print {
  html,
  body {
    width: 100%;
    margin: 0;
    color: #111;
    background: #fff;
  }

  body > *:not(#print-root) {
    display: none !important;
  }

  .print-pages {
    display: block !important;
  }
}

/* The auto page size respects both Letter and A4 selections in the browser print dialog. */
@media print and (max-width: 210mm) {
  .print-sheet {
    width: 100%;
    min-height: 267mm;
  }

  .print-grid {
    width: min(170mm, calc(213.36mm * var(--grid-cols) / var(--grid-rows)), 100%);
  }
}

/* Codex F6 fold: printed sheet uses the full page, not the editor column. */
@media print { .workspace { display: block; } }
