/* Math Worksheet Generator (math_worksheets/page.html): the form, the preview,
   the sheets and printing. Plain CSS, not built by Tailwind; colours come from
   the site's theme tokens, except the sheets, which are ink on white paper in
   every theme. Sheet sizes are container units (cqw) of the sheet, so the
   preview and the printed page are the same design. */

.mw [hidden] { display: none !important; }

/* ---- Layout and form ---- */
.mw-layout { display: grid; gap: 1.25rem; align-items: start; }
@media (min-width: 64rem) {
  .mw-layout { grid-template-columns: minmax(20rem, 25rem) minmax(0, 1fr); }
  .mw-side { position: sticky; top: 5.5rem; }
}
@media (max-width: 63.99rem) { .mw-side { order: -1; } }

.mw-panel {
  min-width: 0;
  padding: 1.25rem;
  border: 1px solid var(--color-base-300);
  border-radius: var(--r-md);
  background: var(--color-base-100);
}
@media (min-width: 40rem) { .mw-panel { padding: 1.5rem; } }
.mw-form { display: flex; flex-direction: column; gap: 1.15rem; }
.mw-form input, .mw-form select { font-size: 1rem; }   /* 16px keeps iOS from zooming in */

.mw-section { display: flex; flex-direction: column; gap: 1rem; min-width: 0; margin: 0; padding: 1.1rem 0 0; border: 0; border-top: 1px solid var(--color-base-300); }
.mw-section-title { float: left; width: 100%; padding: 0; font-size: 1.0625rem; font-weight: 650; }
.mw-section-title + * { clear: both; }
.mw-field { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; margin: 0; padding: 0; border: 0; }
.mw-field > legend { float: left; width: 100%; }
.mw-field > legend + * { clear: both; }
.mw-label { padding: 0; font-size: 0.9375rem; font-weight: 600; }
.mw-optional { margin-left: 0.2rem; font-size: 0.8125rem; font-weight: 400; color: var(--muted); }
.mw-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9rem; align-items: end; }
.mw-ranges { display: flex; flex-direction: column; gap: 1rem; }
.mw-range { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 0.6rem; align-items: center; }
.mw-range > span { font-size: 0.875rem; color: var(--muted); }
.mw-check { display: flex; align-items: center; gap: 0.6rem; font-size: 0.9375rem; cursor: pointer; }
.mw-has-links { position: relative; }
.mw-links { position: absolute; top: 0.1rem; right: 0; display: flex; gap: 0.9rem; font-size: 0.875rem; }

/* Segmented choices built from radios (or pressed buttons), so they work with the keyboard as usual. */
.mw-seg {
  display: grid;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: var(--r-sm);
  background: color-mix(in oklab, var(--color-base-content) 7%, transparent);
}
.mw-seg-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mw-seg-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mw-seg label { position: relative; min-width: 0; cursor: pointer; }
.mw-seg input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.mw-seg span {
  display: block;
  padding: 0.45rem 0.35rem;
  border-radius: calc(var(--r-sm) - 0.15rem);
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
  transition: background-color 0.15s, color 0.15s;
}
.mw-seg span b { font-weight: 700; }
.mw-seg input:checked + span,
.mw-seg button[aria-pressed="true"] span { background: var(--color-base-100); color: var(--color-base-content); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.mw-seg input:focus-visible + span,
.mw-seg button:focus-visible span { outline: 2px solid var(--color-primary); outline-offset: 1px; }
.mw-seg button { display: block; min-width: 0; padding: 0; border: 0; background: none; cursor: pointer; }
.mw-seg button:focus-visible { outline: none; }

/* Toggle chips built from checkboxes: the operations to mix and the times tables. */
.mw-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.mw-tables { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr)); }
.mw-chip { position: relative; cursor: pointer; }
.mw-chip input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.mw-chip span {
  display: block;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--color-base-300);
  border-radius: var(--r-sm);
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.mw-chip input:checked + span { border-color: var(--color-base-content); background: var(--color-base-content); color: var(--color-base-100); }
.mw-chip input:focus-visible + span { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* ---- Preview and actions ---- */
.mw-side { display: flex; flex-direction: column; gap: 0.9rem; min-width: 0; }
.mw-viewbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem; }
.mw-view { min-width: 15rem; }
.mw-pager { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.mw-pager-btn {
  display: grid; place-items: center; width: 2.25rem; height: 2.25rem;
  border: 1px solid var(--color-base-300); border-radius: 50%; background: var(--color-base-100);
  font-size: 1.25rem; line-height: 1; cursor: pointer;
}
.mw-pager-btn:disabled { opacity: 0.4; cursor: default; }
.mw-pager-btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* Squared paper under the sheet. */
.mw-stage {
  display: flex;
  justify-content: center;
  padding: clamp(0.75rem, 4vw, 2rem);
  border-radius: var(--r-md);
  background-color: color-mix(in oklab, var(--color-base-content) 6%, var(--color-base-200));
  background-image:
    linear-gradient(color-mix(in oklab, var(--color-base-content) 7%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in oklab, var(--color-base-content) 7%, transparent) 1px, transparent 1px);
  background-size: 1.25rem 1.25rem;
}
.mw-paper {
  box-sizing: border-box;
  width: 100%;
  max-width: 34rem;
  padding: 4.5%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 10px 28px rgb(0 0 0 / 0.14);
}
.mw-paper.is-empty { display: grid; place-items: center; aspect-ratio: var(--ratio); color: #5b6272; font-size: 0.9375rem; text-align: center; }
.mw-paper > .mw-sheet { aspect-ratio: var(--ratio); }

.mw-alert {
  padding: 0.7rem 1rem;
  border: 1px solid color-mix(in oklab, var(--color-error) 40%, transparent);
  border-radius: var(--r-sm);
  background: color-mix(in oklab, var(--color-error) 9%, var(--color-base-100));
  color: var(--color-error);
  font-size: 0.9rem;
  line-height: 1.5;
}
.mw-notes {
  margin: 0;
  padding: 0.7rem 1rem 0.7rem 2rem;
  border: 1px solid color-mix(in oklab, var(--color-warning) 45%, transparent);
  border-radius: var(--r-sm);
  background: color-mix(in oklab, var(--color-warning) 10%, var(--color-base-100));
  font-size: 0.875rem;
  line-height: 1.5;
  list-style: disc;
}
.mw-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.mw-actions .btn { gap: 0.5rem; }
.mw-set { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem 1rem; font-size: 0.875rem; }
.mw-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.08em; }
.mw-fine { font-size: 0.8125rem; line-height: 1.5; color: var(--muted); }

/* ---- Sheets (preview and print) ---- */
.mw-sheet {
  container-type: inline-size;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
  background: #fff;
  color: #15171c;
  font-family: "Archivo", Arial, Helvetica, sans-serif;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.mw-sheet > * { flex: none; box-sizing: border-box; margin: 0; }
.mw-head { display: flex; align-items: center; justify-content: space-between; gap: 2cqw; border-bottom: 0.3cqw solid #15171c; }
.mw-title { min-width: 0; font-weight: 700; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mw-tag { flex: none; padding: 0.25em 0.75em; border-radius: 999px; background: #b42318; color: #fff; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.mw-lines { display: flex; align-items: flex-end; gap: 3.5cqw; padding-bottom: 0.2cqw; }
.mw-line { display: flex; align-items: baseline; gap: 0.5em; font-weight: 600; }
.mw-line i { display: inline-block; height: 1em; border-bottom: 0.14cqw solid #15171c; }
.mw-instr { display: flex; align-items: flex-end; color: #30343d; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mw-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 2cqw; color: #6b7080; letter-spacing: 0.02em; }

.mw-grid { display: grid; padding: 0; list-style: none; font-weight: 500; line-height: 1.2; font-variant-numeric: tabular-nums lining-nums; }
.mw-cell { display: flex; min-width: 0; min-height: 0; justify-content: center; align-items: flex-start; }
.is-horizontal .mw-cell { justify-content: flex-start; align-items: center; }
.mw-num { flex: none; width: 1.75em; padding-top: 0.32em; color: #555b66; }
.is-horizontal .mw-num { padding-top: 0.1em; }
.mw-num span { display: block; font-size: 0.55em; font-weight: 600; }
.mw-key { color: #b42318; font-weight: 700; }

/* Stacked: operator column, digits right-aligned, a rule, then the answer space. */
.mw-v { display: inline-grid; grid-template-columns: auto auto; column-gap: 0.35em; line-height: 1.22; text-align: right; }
.mw-o { text-align: left; }
.mw-d { min-height: 1.22em; }
.mw-box { justify-self: end; display: inline-block; box-sizing: border-box; height: 1.12em; margin: 0.05em 0; border: 0.06em solid #15171c; border-radius: 0.12em; line-height: 1; text-align: center; }
.mw-rule { grid-column: 1 / -1; height: 0.3em; border-top: 0.075em solid #15171c; margin-top: 0.04em; }
.mw-a { grid-column: 1 / -1; display: block; }

/* In a row: 12 × 4 = ____ */
.mw-h { display: flex; align-items: baseline; gap: 0.28em; white-space: nowrap; }
.mw-blank { display: inline-block; box-sizing: border-box; min-height: 1.15em; border-bottom: 0.07em solid #15171c; line-height: 1.1; text-align: center; }

/* Long division: the quotient over a bracket, with room for the working underneath. */
.mw-ld { display: inline-grid; grid-template-columns: auto auto auto; line-height: 1.25; }
.mw-ld-q { min-height: 1.25em; padding-right: 0.1em; text-align: right; }
.mw-ld-r { padding-left: 0.3em; white-space: nowrap; text-align: left; }
.mw-ld-d { padding-right: 0.28em; text-align: right; }
.mw-ld > .mw-box { margin-right: 0.28em; }
.mw-ld-n { position: relative; padding: 0.06em 0.1em 0 0.48em; border-top: 0.075em solid #15171c; }
.mw-ld-n::before {
  content: "";
  position: absolute;
  left: -0.02em;
  top: -0.075em;
  bottom: -0.12em;
  width: 0.3em;
  border-right: 0.075em solid #15171c;
  border-radius: 0 0 100% 0 / 0 0 35% 0;
}
.mw-ld-work { grid-column: 1 / -1; display: block; }

/* ---- Printing: only the sheets ---- */
.mw-print { display: none; }
@media print {
  body > *:not(.mw-print) { display: none !important; }
  html, body { background: #fff !important; }
  .mw-print { display: block; }
  .mw-print .mw-sheet { width: var(--sheet-w); height: var(--sheet-h); break-after: page; page-break-after: always; }
  .mw-print .mw-sheet:last-child { break-after: auto; page-break-after: auto; }
}

/* ---- Below the tool ---- */
.mw-presets { display: grid; gap: 0.9rem; margin: 1.25rem 0 0; padding: 0; list-style: none; }
.mw-presets li { display: flex; flex-direction: column; gap: 0.15rem; font-size: 0.9375rem; line-height: 1.5; }
.mw-preset-link { font-weight: 600; text-decoration: underline; text-underline-offset: 0.18em; }
.mw-grades { display: grid; gap: 0; margin: 1.25rem 0 0; border-top: 1px solid var(--color-base-300); }
.mw-grades > div { display: grid; gap: 0.25rem 1.5rem; padding: 0.85rem 0; border-bottom: 1px solid var(--color-base-300); font-size: 0.9375rem; line-height: 1.55; }
@media (min-width: 40rem) { .mw-grades > div { grid-template-columns: 8rem minmax(0, 1fr); } }
.mw-grades dt { font-weight: 650; }
.mw-grades dd { margin: 0; color: var(--muted); }
