/* CRJ and CPJ practice: the cream paper and navy ink of a school answer book, with the faint red money rules that
   divide its amount columns. Figures are tabular, and the double rule under a journal's totals is the page's motif. */
:root {
  --bg: #f3efe6; --paper: #fffdf8; --ink: #1c2333; --muted: #4a5163; --line: #d6d0c2; --line2: #8d8778;
  --accent: #24477a; --accent-ink: #ffffff; --accent-soft: #e2e9f4; --rule: #e3b4ad;
  --ok: #1d6b3a; --ok-soft: #e1f1e6; --bad: #a3261b; --bad-soft: #fbe5e2; --warn: #7d5200; --warn-soft: #fbf0d6;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --r: 6px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d; --paper: #1e2128; --ink: #e7e9ee; --muted: #b0b5c1; --line: #363a45; --line2: #626877;
    --accent: #8db4ec; --accent-ink: #10192a; --accent-soft: #1f2c42; --rule: #5a3a37;
    --ok: #79d39a; --ok-soft: #1c3426; --bad: #ff9a8f; --bad-soft: #3d1f1c; --warn: #f0c46b; --warn-soft: #3a2f16;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); }
.wrap { max-width: 1060px; margin: 0 auto; padding: 0 16px; }
/* the widest journals (grade 10 CRJ, 10 columns; the debtors CRJ) fit as tables on a laptop screen */
@media (min-width: 1240px) { .wrap { max-width: 1220px; } }
a { color: var(--accent); }
.skip { position: absolute; left: -999px; top: 8px; background: var(--paper); padding: 8px 12px; z-index: 9; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { line-height: 1.2; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* hero: the double rule under the title */
.hero { padding: 22px 0 8px; }
.hero h1 { font-size: clamp(1.6rem, 4.6vw, 2.35rem); margin: 0 0 8px; display: inline-block; padding-bottom: 6px; border-bottom: 4px double var(--accent); letter-spacing: -0.01em; }
.lede { margin: 6px 0 0; max-width: 62ch; color: var(--muted); }

/* setup */
.setup { margin: 14px 0 10px; display: grid; gap: 10px; }
.setup fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.setup legend { font-weight: 700; margin-bottom: 6px; }
.steps-row { display: flex; flex-wrap: wrap; gap: 6px; }
.step { position: relative; max-width: 100%; }
.step input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.step span { display: flex; align-items: center; min-height: 44px; padding: 6px 14px; border: 1px solid var(--line2); background: var(--paper); border-radius: var(--r); }
.step input:checked + span { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.step input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.lvdesc { margin: 8px 0 0; color: var(--muted); max-width: 75ch; }
.setrow { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.inline { display: inline-flex; gap: 8px; align-items: center; font-weight: 600; }
select, input { font: inherit; font-size: 16px; color: var(--ink); background: var(--paper); border: 1px solid var(--line2); border-radius: var(--r); }
select { min-height: 44px; padding: 6px 10px; max-width: 100%; }
.btn { font: inherit; min-height: 44px; padding: 8px 16px; border-radius: var(--r); border: 1px solid var(--ink); background: var(--paper); color: var(--ink); cursor: pointer; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { min-height: 44px; padding: 6px 14px; }
.btn:hover { filter: brightness(0.96); }
.link { font: inherit; background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 10px 4px; min-height: 44px; }
.note { margin: 8px 0; padding: 10px 12px; border: 1px solid var(--warn); background: var(--warn-soft); border-radius: var(--r); }
.note.info { border-color: var(--line2); background: var(--paper); }
#store-note { overflow-wrap: anywhere; }

/* the sheet */
.sheet { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px 16px; margin: 10px 0 18px; border-top: 4px solid var(--ink); }
.sheet:focus { outline: none; }
.sheet-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 16px; }
.sheet-head h2 { margin: 0; font-size: 1.3rem; }
.code { font-family: var(--mono); letter-spacing: 0.08em; color: var(--accent); }
.lvname { font-weight: 400; font-size: 1rem; color: var(--muted); }
.score { margin: 0; color: var(--muted); }
.rules { margin: 8px 0 4px; }
.rules summary, .work summary, .recent summary, .faq summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; }
/* display: flex drops the browser's triangle, so draw one: it shows the line opens */
.rules summary::before, .work summary::before, .recent summary::before, .faq summary::before { content: ''; flex: none; width: 0; height: 0; margin-right: 10px; border-left: 7px solid currentColor; border-top: 5px solid transparent; border-bottom: 5px solid transparent; }
.rules[open] > summary::before, .work[open] > summary::before, .recent[open] > summary::before, .faq details[open] > summary::before { transform: rotate(90deg); }
.rules ul { margin: 4px 0 8px; padding-left: 20px; max-width: 80ch; }
.qs { list-style: none; margin: 0; padding: 0; }
.q { padding: 16px 0 6px; border-top: 2px solid var(--line); }
.q:first-child { border-top: 0; }
.q h3 { margin: 4px 0 6px; font-size: 1.2rem; display: flex; gap: 10px; align-items: baseline; }
.qn { font-family: var(--mono); color: var(--accent-ink); background: var(--accent); border-radius: 4px; padding: 0 7px; }
.scen { margin: 0 0 12px; max-width: 75ch; }
.qhint { color: var(--muted); margin: 8px 0; max-width: 75ch; }

/* the information given */
.fig { display: grid; gap: 18px; }
.info-block { display: grid; gap: 14px; }
.twrap { max-width: 100%; }
.fig > *, .info-block > *, .forms > * { min-width: 0; }
/* a table wider than its box (measured in app.js) shows each row as a block: the item on its own line, then the
   figures side by side, each under its column heading */
@media screen {
  .twrap.stack table, .twrap.stack tbody, .twrap.stack tr, .twrap.stack th, .twrap.stack td { display: block; width: auto; }
  .twrap.stack thead { display: none; }
  .twrap.stack caption { display: block; }
  .twrap.stack tr { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); column-gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
  .twrap.stack th[scope="row"] { grid-column: 1 / -1; border: 0; padding: 0 0 2px; font-weight: 600; }
  .twrap.stack td { border: 0; padding: 0; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  .twrap.stack td[data-h]::before { content: attr(data-h); display: block; color: var(--muted); }
  /* journals, accounts and the trial balance: the boxes of a line wrap in a grid, the details across the full width,
     and the cells that stay empty in the key are left out */
  .twrap.stack table.jrn tr, .twrap.stack table.aside tr, .twrap.stack table.tacct tr, .twrap.stack table.tb tr { grid-template-columns: repeat(auto-fill, minmax(min(100%, 8em), 1fr)); row-gap: 6px; }
  .twrap.stack table.dt td, .twrap.stack table.dt th { width: auto; min-width: 0; }
  .twrap.stack td.det { grid-column: 1 / -1; }
  .twrap.stack td.nt, .twrap.stack td.e, .twrap.stack tr.blank { display: none; }
  .twrap.stack table.jrn td, .twrap.stack table.tacct td { border-left: 0; }
}
table.dt { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.dt caption { text-align: left; font-weight: 700; padding: 0 0 6px; }
.dt th, .dt td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-weight: 400; }
.dt th { hyphens: auto; overflow-wrap: break-word; }
.dt thead th { font-weight: 700; color: var(--muted); border-bottom: 2px solid var(--line2); }
.dt .num { text-align: right; white-space: nowrap; }
.dt thead th.num { white-space: normal; }
table.info { max-width: 680px; }
table.info.c3 td.num { width: 8.2em; }
table.info.c2 td.num { width: 8.5em; }
.addl { max-width: 80ch; }
.tcap { font-weight: 700; margin: 0 0 6px; }
.adj { margin: 0; padding-left: 24px; }
.adj li { margin: 0 0 6px; }

/* the transactions and the information given */
table.txl { max-width: 900px; }
table.txl td.day, table.txl th.day { width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; padding-right: 12px; }
table.jcols { max-width: 900px; }
table.jcols th[scope="row"] { width: 40%; }

/* journals: amount columns divided by the red money rules, a double rule under the totals */
.forms { display: grid; gap: 22px; }
table.jrn caption { border-bottom: 2px solid var(--ink); padding-bottom: 4px; margin-bottom: 2px; }
table.jrn .jp { font-family: var(--mono); color: var(--muted); font-weight: 400; margin-left: 10px; white-space: nowrap; }
table.jrn th, table.jrn td { padding: 4px 6px; }
table.jrn td.num, table.jrn td.in, table.jrn thead th.num { border-left: 1px solid var(--rule); }
table.jrn thead th.sund { text-align: center; border-left: 1px solid var(--rule); border-bottom: 1px solid var(--line); }
table.jrn thead th { vertical-align: bottom; }
table.jrn td.in { min-width: 6.5em; }
table.jrn td.in.day { min-width: 3.6em; width: 3.6em; border-left: 0; }
table.jrn td.in.det { min-width: 10em; }
table.jrn .sm { white-space: nowrap; }
table.jrn tr.r-tot th { font-weight: 700; text-align: right; vertical-align: middle; }
table.jrn tr.r-tot td { border-bottom: 4px double var(--ink); font-weight: 700; }
table.jrn.key tr.r-tot td.num:not(.nt) { border-top: 1px solid var(--ink); }
input.cell { width: 100%; min-height: 44px; padding: 6px 8px; text-align: right; font-variant-numeric: tabular-nums; }
input.cell.day { text-align: center; padding: 6px 4px; }
select.cell { width: 100%; min-width: 0; padding: 6px 4px; }
.cell.is-right { border-color: var(--ok); background: var(--ok-soft); box-shadow: inset 4px 0 0 var(--ok); }
.cell.is-wrong, .cell.is-unread { border-color: var(--bad); background: var(--bad-soft); box-shadow: inset 4px 0 0 var(--bad); }
.cell.is-close { border-color: var(--warn); background: var(--warn-soft); }

/* General Ledger accounts: the debit side and the credit side next to each other where they fit */
.acct { border-top: 2px solid var(--ink); padding-top: 4px; }
.acap { margin: 0 0 4px; font-weight: 700; display: flex; gap: 12px; }
.af { font-family: var(--mono); color: var(--muted); font-weight: 400; }
.sides { display: grid; gap: 4px 18px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22em), 1fr)); }
table.aside caption { font-weight: 600; color: var(--muted); padding-bottom: 2px; }
table.aside td.in { padding: 3px 4px; }
table.aside td.in.fol { width: 6.4em; }
table.aside td.in:last-child { width: 8.5em; border-left: 1px solid var(--rule); }
table.aside tr.r-tot th { text-align: right; font-weight: 700; vertical-align: middle; }
table.aside tr.r-tot td { border-bottom: 4px double var(--ink); }
/* a narrow side: the Details menu on its own line, so long names like Total receipts show in full */
@media screen { .sides > .twrap { container-type: inline-size; } }
@container (max-width: 430px) {
  table.aside thead tr, table.aside tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) 8.5em; }
  table.aside th.det, table.aside td.det { grid-column: 1 / -1; border-bottom: 0; }
  table.aside td.in.fol { width: auto; }
}
.bbd { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: end; padding: 8px 0 2px; }
.bbd .bl { font-weight: 600; flex-basis: 100%; }
.bbd label { display: grid; gap: 2px; color: var(--muted); min-width: 9em; }
.bbd label .cell { color: var(--ink); }
table.tacct caption { border-bottom: 2px solid var(--ink); padding-bottom: 4px; text-align: center; }
table.tacct caption .dr { float: left; }
table.tacct caption .cr { float: right; }
table.tacct caption .af { margin-left: 8px; }
table.tacct .an { font-weight: 700; }
/* the same column widths in every account, where they fit; a narrower account shows each line as a block */
@media (min-width: 760px), print {
  table.tacct { table-layout: fixed; }
  table.tacct th.sm:nth-child(4n+1) { width: 11%; }
  table.tacct th.sm:nth-child(4n+3) { width: 9%; }
  table.tacct th.num { width: 13%; }
}
table.tacct td:nth-child(5), table.tacct th:nth-child(5) { border-left: 2px solid var(--ink); }
table.tacct td.num, table.tacct th.num { border-left: 1px solid var(--rule); }
table.tacct tr.r-tot td.num { border-top: 1px solid var(--ink); border-bottom: 4px double var(--ink); font-weight: 700; }
table.tacct .sm { white-space: nowrap; }

/* the trial balance */
table.tb { max-width: 720px; }
table.tb td.in { width: 9em; padding: 3px 0 3px 6px; }
table.tb td.num { width: 8.5em; border-left: 1px solid var(--rule); }
table.tb th[scope="row"], table.tb td.sm { vertical-align: middle; }
table.tb tr.sect th { font-weight: 700; color: var(--muted); padding-top: 10px; }
table.tb tr.r-tot th { font-weight: 700; text-align: right; vertical-align: middle; }
table.tb tr.r-tot td { border-bottom: 4px double var(--ink); font-weight: 700; }
table.tb.key tr.r-tot td { border-top: 1px solid var(--ink); }

/* 1. journal and column */
.clist { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; max-width: 900px; }
.crow { padding: 10px 0; border-bottom: 1px solid var(--line); }
.cl { margin: 0 0 6px; }
.cday { font-weight: 700; margin-right: 6px; white-space: nowrap; }
.ckey .crow { padding: 6px 0; }
.ck { margin: 2px 0 0; font-weight: 600; }
.csel { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14em), 1fr)); gap: 8px 14px; }
.csel label { display: grid; gap: 2px; color: var(--muted); }
.csel select { width: 100%; color: var(--ink); }

/* feedback */
.fbwrap { margin: 6px 0; }
.fb { margin: 4px 0; padding: 6px 10px; border-radius: var(--r); background: var(--bad-soft); }
.fb.right { background: var(--ok-soft); }
.fb.close { background: var(--warn-soft); }
.fb.more { background: transparent; color: var(--muted); padding: 0 10px; }
.fb.sum { background: transparent; padding: 4px 0; }
.qfoot { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.work { margin: 4px 0 8px; }
.keyfig { margin: 6px 0 14px; }
.lead { margin: 8px 0; padding: 8px 12px; background: var(--accent-soft); border-radius: var(--r); max-width: 80ch; }
.steps { margin: 6px 0 8px; padding-left: 20px; font-variant-numeric: tabular-nums; max-width: 90ch; }
.steps li { margin: 3px 0; overflow-wrap: anywhere; }

.sheet-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.confirm { flex-basis: 100%; margin: 0; padding: 10px; background: var(--warn-soft); border-radius: var(--r); }
.save-hint { flex-basis: 100%; margin: 0; color: var(--muted); }

/* print and share */
.share { margin: 0 0 24px; }
.print-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.print-row label { display: inline-flex; gap: 8px; align-items: center; font-weight: 600; flex-wrap: wrap; max-width: 100%; }
.share-out label { display: grid; gap: 4px; font-weight: 600; }
.share-out input { width: 100%; min-height: 44px; padding: 6px 10px; font-family: var(--mono); }
.recent { margin-top: 12px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 4px 12px; }
.recent ul { list-style: none; margin: 0; padding: 0; }
.recent li { display: flex; justify-content: space-between; gap: 10px; align-items: center; border-top: 1px solid var(--line); padding: 6px 0; }
.recent .meta { display: block; color: var(--muted); }
.hint { color: var(--muted); }

/* content */
.content { max-width: 75ch; padding-bottom: 20px; }
.content h2 { font-size: 1.35rem; margin: 26px 0 8px; }
.faq details { border-bottom: 1px solid var(--line); }
.faq details p { margin: 0 0 12px; }
.sources { color: var(--muted); }
footer { border-top: 4px double var(--line2); padding: 18px 0 30px; color: var(--muted); }
.sb-footer p { margin: 6px 0; }
.sb-more a { color: var(--muted); }
.sb-credit a { color: var(--accent); }

.toast { pointer-events: none; position: fixed; left: 50%; bottom: 16px; transform: translate(-50%, 140%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--r); max-width: min(92vw, 520px); z-index: 20; transition: transform 0.2s; }
.toast.on { transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
[hidden] { display: none !important; }
.print-root { display: none; }

@media (max-width: 420px) {
  .sheet { padding: 12px 10px 14px; }
  .dt th, .dt td { padding: 6px 4px; }
}

/* ---------- print ---------- */
@page { margin: 14mm 12mm; }
@media print {
  :root { --ink: #000; --muted: #333; --line: #888; --line2: #444; --paper: #fff; --bg: #fff; --accent: #000; --accent-soft: #fff; --rule: #b56a60; }
  body { background: #fff; color: #000; font: 10pt/1.3 var(--sans); }
  main, footer, .skip, .toast { display: none !important; }
  .print-root { display: block; }
  .psheet, .pkey { break-after: page; }
  .pkey:last-child, .psheet:last-child { break-after: auto; }
  table.pt { width: 100%; border-collapse: collapse; }
  .pt > thead .prun { font-size: 8pt; color: #333; padding-bottom: 4px; border-bottom: 0.5pt solid #888; }
  .ph h2 { margin: 4px 0 0; font-size: 15pt; border-bottom: 3px double #000; display: inline-block; padding-bottom: 2px; }
  .ph p { margin: 2px 0 6px; font-size: 9pt; }
  .pmeta { display: flex; justify-content: space-between; gap: 10px; margin: 6px 0; }
  .plabel { font-size: 9pt; margin: 0 0 6px; }
  .pq, .pk { list-style: none; margin: 0; padding: 0; }
  .pq > li, .pk > li { margin: 0 0 10px; }
  .pq > li + li { margin-top: 14pt; padding-top: 6pt; border-top: 0.75pt solid #000; }
  .pq > li.pq-cls + li, .pq > li + li.pq-cls { break-before: page; margin-top: 0; padding-top: 0; border-top: 0; }
  .pqh, table.txl, table.jcols, table.info { break-inside: avoid; }
  .pk > li + li { margin-top: 14pt; padding-top: 6pt; border-top: 0.75pt solid #000; }
  .pqh h3, .pk h3 { font-size: 12pt; margin: 6px 0 2px; }
  .pscen { margin: 0 0 6px; }
  .fig, .forms, .info-block, .sides { display: block; }
  .fig > *, .forms > *, .info-block > * { margin-bottom: 8pt; }
  .twrap, table.txl tr, .crow, table.ctable tr { break-inside: avoid; }
  table.dt { font-size: 9pt; width: 100%; }
  .dt th, .dt td { padding: 1.5pt 3pt; line-height: 1.2; border-bottom: 0.5pt solid #777; }
  .dt caption { font-size: 10pt; padding-bottom: 3pt; }
  table.txl { font-size: 9.5pt; }
  table.txl td.day, table.txl th.day { width: 2.6em; }
  table.info { width: 60%; max-width: none; }
  table.info td.num { width: 7.5em; }
  table.jrn caption, table.tacct caption { border-bottom: 1pt solid #000; }
  table.jrn tr.blank td, table.tacct tr.blank td { height: 18pt; }
  table.jrn td, table.jrn thead th.num, table.jrn thead th.sund { border-left: 0.5pt solid var(--rule); }
  table.jrn td:first-child { border-left: 0; }
  table.jrn thead th { font-size: 8pt; line-height: 1.15; }
  table.jrn thead th.sm { width: 6%; }
  table.jrn thead th.det { width: 17%; }
  table.jrn thead th.num { width: 11%; }
  table.jrn.wide thead th.sm { width: 5%; }
  table.jrn.wide thead th.det { width: 15%; }
  table.jrn.wide thead th.num { width: 8.5%; }
  table.jrn tr.r-tot td { border-bottom: 2.5pt double #000; }
  table.jrn.key tr.r-tot td.num:not(.nt), table.jrn.print tr.r-tot td.num:not(.nt) { border-top: 0.75pt solid #000; }
  table.jrn tr.r-tot th { text-align: right; }
  table.tacct td:nth-child(5), table.tacct th:nth-child(5) { border-left: 1pt solid #000; }
  table.tacct tr.r-tot td.num { border-top: 0.75pt solid #000; border-bottom: 2.5pt double #000; }
  table.tacct.print tr.r-tot td:nth-child(4), table.tacct.print tr.r-tot td:nth-child(8) { border-top: 0.75pt solid #000; border-bottom: 2.5pt double #000; }
  table.tb { width: 80%; max-width: none; }
  table.tb.print td.num { height: 18pt; }
  table.tb tr.r-tot td { border-top: 0.75pt solid #000; border-bottom: 2.5pt double #000; }
  table.ctable td.blank { height: 24pt; width: 17%; }
  table.ctable td.sm { width: 2.4em; }
  .legend { margin: 0 0 4pt; }
  .keyfig { margin: 0; }
  .clist .crow { padding: 1pt 0; }
  .ckey .crow p { display: inline; }
  .ckey .ck::before { content: '\00a0\2192\00a0'; font-weight: 400; }
  .ck { font-weight: 700; }
  .lead { padding: 0; margin: 4pt 0; }
  .steps { font-size: 9pt; margin: 4px 0; }
  .tcap { margin: 6pt 0 2pt; break-after: avoid; }
  .pk h3, .pqh, .dt caption { break-after: avoid; }
  .pkw > .tcap { break-before: avoid; }
  .pkw > ul.steps { break-inside: avoid; }
  .lead { break-inside: avoid; }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
