/* What the payday savings challenge, /payday-savings-challenge, adds to style.css and tools.css (both loaded first):
   its form, the chart of paydays, and the same chart as one printed page of boxes to color in. Colours are the
   site's tokens only, so the page follows the site into dark mode and onto paper. */

/* A field the chosen schedule doesn't need, and a chart that can't be worked out yet. Without this the site's
   `.tool label { display: grid }` would go on showing a hidden field. */
.tool [hidden] { display: none; }

/* One height for every field. A date field is a few pixels taller than a select left to itself, which lifts its
   label above its neighbours' in the row. */
.tool input, .tool select { height: 47px; }

/* The goal: a dollar sign set inside the field. */
.tool .money { position: relative; display: block; }
.tool .money::before { content: "$"; position: absolute; left: 13px; top: 50%; transform: translateY(-50%); font-weight: 400; color: var(--quiet); pointer-events: none; }
.tool .money input { width: 9.5em; padding-left: 27px; font-variant-numeric: tabular-nums; }

/* The starting points under the form. */
.tool .starts { margin-top: 16px; font-size: 0.95rem; color: var(--muted); }

/* The chart: a row for each payday, with the date, the amount, the total saved by then and a box to tick. A chart
   of very large amounts scrolls sideways inside its frame. */
.chart { margin-top: 20px; border: 1px solid var(--card-line); border-radius: var(--radius); overflow-x: auto; }
.doc .chart table { min-width: 0; font-variant-numeric: tabular-nums; }
.doc .chart th, .doc .chart td { height: 46px; padding-block: 0; vertical-align: middle; white-space: nowrap; }
.doc .chart thead th { border-bottom: 1px solid var(--card-line); }
.doc .chart .num { text-align: right; }
.doc .chart tbody th { font-weight: 500; }
.doc .chart td.total { color: var(--muted); }
.doc .chart tfoot th, .doc .chart tfoot td { border-top: 1px solid var(--card-line); font-weight: 700; }
/* The box to tick. Its whole cell is the target, and a payday ticked off is colored in. */
.doc .chart thead th:last-child, .doc .chart td.tick { width: 76px; padding-inline: 12px; text-align: center; }
.chart .tick label { display: grid; place-items: center; height: 44px; cursor: pointer; }
.tool .chart input { width: 22px; height: 22px; min-height: 0; margin: 0; padding: 0; accent-color: var(--green); cursor: pointer; }
.chart tbody tr:has(:checked) { background: var(--gold-soft); }

/* On a small tablet the columns close up. (Both of these are for screens only, so that a browser which lays a
   printed page out narrow still prints the sheet further down.) */
@media screen and (max-width: 640px) {
  .doc .chart th, .doc .chart td { padding-inline: 10px; }
  .doc .chart thead th:last-child, .doc .chart td.tick { width: 56px; padding-inline: 6px; }
}
/* On a phone four columns don't fit, so each payday is one line of a list: the date with the total saved under it
   in small type, the amount, and the box. The column heads stay for screen readers only. */
@media screen and (max-width: 480px) {
  .chart { overflow-x: visible; }
  .doc .chart table, .chart tbody, .chart tfoot { display: block; }
  .chart thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .chart tbody tr, .chart tfoot tr { display: grid; grid-template-columns: minmax(0, 1fr) auto 44px; grid-template-areas: "date amount tick" "total amount tick"; align-items: center; column-gap: 8px; padding: 6px 4px 6px 12px; }
  .chart tbody tr { border-bottom: 1px solid var(--card-line); }
  .doc .chart tbody th, .doc .chart tbody td, .doc .chart tfoot th, .doc .chart tfoot td { display: block; height: auto; padding: 0; border: 0; font-size: 1rem; line-height: 1.3; white-space: normal; }
  .doc .chart tbody th, .doc .chart tfoot th { grid-area: date; }
  .doc .chart td.num { grid-area: amount; font-weight: 600; }
  .doc .chart td.total { grid-area: total; text-align: left; font-size: 0.82rem; font-weight: 400; }
  .chart td.total::after { content: " saved"; }
  .doc .chart td.tick { grid-area: tick; width: auto; padding: 0; }
  .chart tfoot tr { grid-template-areas: "date amount tick"; min-height: 50px; }
  .doc .chart tfoot td.num { font-weight: 700; }
  .doc .chart tfoot td:empty, .doc .chart tfoot td.print-only { display: none; }
}

/* Under the chart: one line that hands off to the app, then the other free tools. */
.tool .next { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--card-line); }
.tool .next + .next { margin-top: 8px; padding-top: 0; border-top: 0; }

/* On paper: one US Letter page to keep on the fridge. The sheet's own title, the goal and the schedule in words
   stand in place of the page's headline and form; then the plan in a sentence, a box for each payday, a line to
   write what the money is for, the total, and where the sheet came from. Lines are 1px or 2px: Chrome prints
   nothing thinner than 1px. */
@media print {
  /* The sheet is as wide as the page inside its margins. */
  .doc .wrap { width: auto; }
  .tool { margin-top: 0; }

  .print-only.sheet-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 4pt 24pt; border-top: 2px solid var(--ink); padding-top: 9pt; }
  .doc .sheet-head p { margin-top: 0; }
  .sheet-title, .sheet-goal { font: 400 24pt/1.1 var(--serif); letter-spacing: -0.02em; }
  .sheet-goal strong { font-weight: 500; }
  .doc .sheet-line { grid-column: 1 / -1; font-size: 10pt; line-height: 1.4; color: var(--muted); }
  .tool .answer { font-size: 11.5pt; margin-top: 7pt; }

  /* The table becomes a grid of boxes, one per payday, in the columns savings-challenge.js chose for their number
     (.fit-3 to .fit-8; four across is .fit-4, which needs no rule of its own). The grid has one height whatever
     the number, and the rows share it, so every chart ends at the same place on the page: 4 rows of three for 12
     paydays, 7 rows of four for 26, 9 rows of six for 53. With that height the sheet is about 9.1 inches of the
     page's 10 (9.3 when the sentence takes two lines), so a browser that prints its own header and footer, or
     keeps wider margins, still gets it onto one page. */
  .chart { margin-top: 10pt; border: 0; border-radius: 0; overflow: visible; }
  .doc .chart table, .chart tfoot { display: block; }
  .chart thead { display: none; }
  .chart tbody { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: minmax(0, 1fr); gap: 6pt; height: 7in; }
  .chart.fit-3 tbody { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8pt; }
  .chart.fit-5 tbody { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5.5pt; }
  .chart.fit-6 tbody { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5pt; }
  .chart.fit-8 tbody { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4pt; }
  /* A short chart keeps boxes of a sensible height instead of stretching three rows down the page. */
  .chart.rows-1 tbody { height: 1.7in; }
  .chart.rows-2 tbody { height: 3.45in; }
  .chart.rows-3 tbody { height: 5.2in; }

  /* A box: the date at the top with a square to tick beside it, the amount in the middle, and under it the total
     saved by then. The rest is room to color in. */
  .chart tbody tr { position: relative; display: flex; flex-direction: column; justify-content: space-between; border: 1px solid var(--ink); border-radius: 5pt; padding: 6pt 8pt 7pt; break-inside: avoid; }
  .doc .chart tbody th, .doc .chart tbody td, .doc .chart tfoot th, .doc .chart tfoot td { display: block; height: auto; padding: 0; border: 0; background: none; }
  .doc .chart tbody th { font: 600 8.5pt/1.2 var(--sans); }
  .doc .chart tbody td.num { font: 600 17pt/1 var(--sans); letter-spacing: -0.01em; text-align: center; }
  .doc .chart tbody td.total { font: 400 7.5pt/1.2 var(--sans); letter-spacing: 0; color: var(--quiet); }
  .chart tbody td.total::after { content: " saved"; }
  .doc .chart tbody td.tick { position: absolute; top: 5pt; right: 6pt; width: 12pt; height: 12pt; padding: 0; border: 1px solid var(--ink); border-radius: 2pt; }
  .chart .tick label { display: none; }
  /* A box ticked on the screen prints ticked. */
  .chart tbody tr:has(:checked) td.tick::after { content: "\2713"; position: absolute; inset: 0; display: grid; place-items: center; font: 700 9pt/1 var(--sans); }

  /* Three across, for 18 paydays or fewer: the boxes are large, so their type is too. */
  .chart.fit-3 tbody tr { padding: 9pt 11pt 10pt; }
  .doc .chart.fit-3 tbody th { font-size: 11pt; }
  .doc .chart.fit-3 tbody td.num { font-size: 24pt; }
  .doc .chart.fit-3 tbody td.total { font-size: 9pt; }
  .doc .chart.fit-3 tbody td.tick { top: 8pt; right: 9pt; width: 16pt; height: 16pt; }
  /* Five across, for 29 to 35 paydays. */
  .chart.fit-5 tbody tr { padding: 5pt 7pt 6pt; border-radius: 4.5pt; }
  .doc .chart.fit-5 tbody th { font-size: 7.5pt; }
  .doc .chart.fit-5 tbody td.num { font-size: 14.5pt; }
  .doc .chart.fit-5 tbody td.total { font-size: 7pt; }
  .doc .chart.fit-5 tbody td.tick { top: 4.5pt; right: 5pt; width: 10.5pt; height: 10.5pt; }
  /* A year of weekly pay: smaller boxes and type. */
  .chart.fit-6 tbody tr { padding: 4.5pt 6pt 5pt; border-radius: 4pt; }
  .doc .chart.fit-6 tbody th { font-size: 7pt; }
  .doc .chart.fit-6 tbody td.num { font-size: 12.5pt; }
  .doc .chart.fit-6 tbody td.total { font-size: 6.5pt; }
  .doc .chart.fit-6 tbody td.tick { top: 4pt; right: 4.5pt; width: 9.5pt; height: 9.5pt; }
  /* More than a year of weekly pay: the date and the amount only. */
  .chart.fit-8 tbody tr { padding: 3pt 4.5pt 3.5pt; border-radius: 3pt; }
  .doc .chart.fit-8 tbody th { font-size: 6pt; }
  .doc .chart.fit-8 tbody td.num { font-size: 9.5pt; }
  .doc .chart.fit-8 tbody td.total { display: none; }
  .doc .chart.fit-8 tbody td.tick { top: 2.5pt; right: 3pt; width: 7pt; height: 7pt; border-radius: 1.5pt; }

  /* Under the boxes: a line to write what the money is for, and the total. */
  .chart tfoot { margin-top: 12pt; }
  .chart tfoot tr { display: flex; align-items: baseline; gap: 9pt; }
  .doc .chart tfoot td.for { display: flex; align-items: baseline; gap: 6pt; margin-right: auto; font: 400 10pt/1 var(--sans); color: var(--muted); }
  .chart tfoot .for span { width: 2.9in; border-bottom: 1px solid var(--ink); }
  .doc .chart tfoot th { font: 600 10pt/1 var(--sans); }
  .doc .chart tfoot td.num { font: 500 20pt/1 var(--serif); letter-spacing: -0.015em; }
  .doc .chart tfoot td:empty { display: none; }
  .print-only.sheet-foot { margin-top: 10pt; }
}
