/* Share capital practice. Look: a share certificate. Ivory paper, certificate green ink, a bronze seal, a framed sheet
   with a double rule inside the frame (the certificate border), tabular figures for every amount. */
:root {
  --bg: #f4f1e6; --paper: #fffdf7; --ink: #1b2421; --muted: #4c5853; --line: #cbc3aa; --line2: #9a927a;
  --accent: #1d5a49; --accent-ink: #fff; --seal: #8a5a1f; --soft: #e6efe9;
  --right: #1d6b3c; --wrong: #a3261c; --close: #8a5a00; --info: #234e78;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --r: 4px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101a17; --paper: #15221e; --ink: #e6eee9; --muted: #a8b7b0; --line: #2f433c; --line2: #4c6359;
    --accent: #72c6a8; --accent-ink: #0d1714; --seal: #d9a660; --soft: #1b2d27;
    --right: #6fd394; --wrong: #ff8f80; --close: #f0c060; --info: #8fc1ef;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.55 var(--sans); }
a { color: var(--accent); }
.wrap { max-width: 1060px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 8px; background: var(--paper); padding: 8px 12px; z-index: 9; }
:focus-visible { outline: 3px solid var(--seal); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; }

/* hero: the seal sits beside the title */
.hero { padding: 26px 0 8px; position: relative; padding-right: 72px; }
.hero::after { content: ""; position: absolute; right: 0; top: 24px; width: 56px; height: 56px; border-radius: 50%;
  background: radial-gradient(circle, var(--bg) 0 38%, var(--seal) 39% 46%, var(--bg) 47% 54%, var(--seal) 55% 100%);
  -webkit-mask: radial-gradient(circle, #000 0 68%, transparent 69%), repeating-conic-gradient(#000 0 6deg, transparent 6deg 12deg);
  mask: radial-gradient(circle, #000 0 68%, transparent 69%), repeating-conic-gradient(#000 0 6deg, transparent 6deg 12deg); opacity: .9; }
.hero h1 { font-size: clamp(1.6rem, 4.6vw, 2.35rem); margin: 0 0 8px; color: var(--accent); }
.lede { margin: 0 0 6px; max-width: 64ch; font-size: 1.06rem; }

/* setup */
.setup { margin: 12px 0 14px; }
fieldset { border: 0; margin: 0 0 10px; padding: 0; min-width: 0; }
legend { font-weight: 650; margin-bottom: 6px; }
.steps-row { display: flex; flex-wrap: wrap; gap: 6px; }
.step { position: relative; }
.step input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.step span { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 6px 12px; border: 1px solid var(--line2); border-radius: var(--r); background: var(--paper); font-size: .95rem; }
.step b { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--accent); color: var(--accent); font-size: .85rem; }
.step input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.step input:checked + span b { border-color: var(--accent-ink); color: var(--accent-ink); }
.step input:focus-visible + span { outline: 3px solid var(--seal); outline-offset: 2px; }
.setrow { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.inline { display: inline-flex; align-items: center; gap: 8px; }
select, input { font: inherit; font-size: 16px; color: var(--ink); background: var(--paper); border: 1px solid var(--line2); border-radius: var(--r); min-height: 44px; padding: 6px 8px; max-width: 100%; }
.btn { font: inherit; font-weight: 600; min-height: 44px; padding: 8px 16px; border-radius: var(--r); border: 1.5px solid var(--accent); background: var(--paper); color: var(--accent); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.small { min-height: 40px; padding: 6px 14px; font-size: .95rem; }
.link { font: inherit; background: none; border: 0; padding: 8px 2px; color: var(--accent); text-decoration: underline; cursor: pointer; min-height: 44px; }
.note { padding: 10px 12px; border: 1px solid var(--wrong); background: var(--paper); margin: 8px 0; border-radius: var(--r); }
#store-note { overflow-wrap: anywhere; }
.note.info { border-color: var(--info); }
[hidden] { display: none !important; }

/* the sheet: framed like a certificate */
.sheet { background: var(--paper); border: 2px solid var(--accent); outline: 1px solid var(--accent); outline-offset: -7px; padding: 18px 18px 14px; margin: 10px 0 18px; }
.sheet-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 16px; border-bottom: 3px double var(--line2); padding-bottom: 6px; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; }
.code { font-family: var(--mono); letter-spacing: .06em; color: var(--seal); }
.lvname { font-family: var(--sans); font-weight: 400; font-size: 1rem; color: var(--muted); }
.score { margin: 0; color: var(--muted); font-size: 1rem; }
.rules { margin: 8px 0; font-size: 1rem; }
.rules summary, details.work summary, .recent summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; color: var(--accent); }
.rules ul { margin: 4px 0 8px; padding-left: 20px; }
.qs { list-style: none; margin: 0; padding: 0; }
.q { padding: 14px 0 16px; border-bottom: 1px solid var(--line); }
.q h3 { font-size: 1.15rem; margin: 4px 0 8px; display: flex; gap: 10px; align-items: baseline; }
.qn { font-family: var(--mono); color: var(--seal); }
.qtext { max-width: 72ch; }
.scen { margin: 0 0 8px; }
.scen.ask { font-weight: 600; }

/* the instalments table */
.terms-wrap { margin: 4px 0 10px; }
table.terms { border-collapse: collapse; font-size: 1rem; }
.terms caption { text-align: left; font-weight: 600; padding-bottom: 2px; color: var(--muted); font-size: 1rem; }
.terms th, .terms td { padding: 3px 10px 3px 0; border-bottom: 1px solid var(--line); text-align: left; font-weight: 400; }
.terms td.num { font-family: var(--mono); text-align: right; padding-right: 12px; }
.tnote { color: var(--muted); font-size: 1rem; }

/* parts of a problem */
.part { margin: 14px 0 6px; }
.ph4 { font-family: var(--serif); font-size: 1.05rem; margin: 0 0 6px; color: var(--accent); border-bottom: 1px solid var(--line); padding-bottom: 3px; }
.jents { list-style: none; margin: 0; padding: 0; counter-reset: je; container-type: inline-size; }
.jent { counter-increment: je; padding: 8px 0 10px; border-bottom: 1px dashed var(--line); }
.jlab { margin: 0 0 6px; font-weight: 600; font-size: 1rem; }
.jlab::before { content: counter(je) ". "; font-family: var(--mono); color: var(--seal); }
.jgrid { display: grid; gap: 6px; }
.jl { display: grid; grid-template-columns: minmax(0, 1fr) 9.5rem 9.5rem; gap: 6px; align-items: end; }
.jc { display: grid; gap: 2px; }
.jcl { font-size: 1rem; color: var(--muted); }
.jl:not(:first-child) .jcl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.cell { width: 100%; min-width: 0; font-family: var(--mono); }
select.cell { font-family: var(--sans); }
input.cell { text-align: right; }
@container (max-width: 560px) {
  .jl { grid-template-columns: 1fr 1fr; padding-bottom: 6px; }
  .jl .t-acct { grid-column: 1 / -1; }
  .jl:not(:first-child) .jcl { position: static; width: auto; height: auto; clip: auto; }
}
.cell.is-right { border-color: var(--right); box-shadow: inset 0 0 0 1px var(--right); }
.cell.is-wrong, .cell.is-unread { border-color: var(--wrong); box-shadow: inset 0 0 0 1px var(--wrong); }
.cell.is-missing, .cell.is-close { border-color: var(--close); box-shadow: inset 0 0 0 1px var(--close); border-style: dashed; }

/* cash book, figures, note */
.docs.cb { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.docs.cb.stack { grid-template-columns: 1fr; }
@media (max-width: 700px) { .docs.cb { grid-template-columns: 1fr; } }
.twrap { overflow-x: auto; max-width: 100%; }
table.cbt, table.ntab, table.jt { border-collapse: collapse; width: 100%; }
.cbt caption, .ntab caption { text-align: left; font-weight: 600; color: var(--muted); font-size: 1rem; }
.cbt th, .cbt td, .ntab th, .ntab td { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; font-weight: 400; vertical-align: middle; }
.cbt .num, .ntab .num { text-align: right; width: 9.5rem; font-family: var(--mono); }
.cbt.scr td:first-child { min-width: 0; }
.cbtot th, .cbtot td { border-top: 1.5px solid var(--ink); border-bottom: 3px double var(--ink); font-weight: 600; }
.figs { display: grid; gap: 8px; }
.fig1 { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 12px; max-width: 40rem; }
.figin { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); width: 11.5rem; }
.ntab .nh th { font-weight: 650; padding-top: 10px; }
.ntab .nlab { width: auto; }
.ncount { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 4px; font-size: 1rem; color: var(--muted); }
.ncount .cell { width: 8.5rem; }
.ntot th, .ntot td { border-top: 1.5px solid var(--ink); border-bottom: 3px double var(--ink); font-weight: 650; }
.hint { color: var(--muted); font-size: 1rem; margin: 6px 0; }

/* feedback */
.fbwrap { margin: 8px 0 0; }
.fb { margin: 4px 0; padding: 6px 10px; border: 1px solid var(--line2); border-radius: var(--r); background: var(--soft); font-size: 1rem; }
.fb.right { border-color: var(--right); }
.fb.wrong, .fb.unread { border-color: var(--wrong); }
.fb.missing, .fb.close { border-color: var(--close); }
.qfoot { margin-top: 8px; }

/* the key */
details.work { margin-top: 8px; }
.keyfig > * { margin: 8px 0; }
.tcap { font-weight: 600; margin: 6px 0 4px; color: var(--muted); font-size: 1rem; }
.jt th { text-align: left; font-size: 1rem; color: var(--muted); font-weight: 600; border-bottom: 1.5px solid var(--ink); padding: 4px 6px; }
.jt td { padding: 2px 6px; vertical-align: top; }
.jt .num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.jt .c-d { width: 2.4em; color: var(--seal); font-family: var(--mono); }
.jt .c-a { width: 8.5rem; }
.jt.key .c-f, .jt.key th.c-f { display: none; }
.jt .je { border-bottom: 1px solid var(--line); }
.jdr { float: right; }
.jacc.ind { padding-left: 1.6em; display: inline-block; }
.narr { color: var(--muted); font-style: italic; font-size: 1rem; }
.kfigs { display: grid; gap: 4px; margin: 8px 0; }
.kfigs div { display: flex; justify-content: space-between; gap: 12px; max-width: 40rem; border-bottom: 1px solid var(--line); }
.kfigs dt { margin: 0; } .kfigs dd { margin: 0; font-family: var(--mono); }
.steps { margin: 4px 0 8px; padding-left: 20px; font-size: 1rem; }
.steps li { margin: 2px 0; }

/* fitted layouts (fit.js): a table that would be cut off shows each line on two lines */
.twrap.rows table, .twrap.rows tbody, .twrap.rows tr { display: block; width: 100%; }
.twrap.rows thead { display: none; }
.twrap.rows tr { display: grid; grid-template-columns: 2.2em minmax(0, 1fr); padding: 2px 0; }
.twrap.rows td, .twrap.rows th { display: block; border: 0; width: auto !important; }
.twrap.rows td.num, .twrap.rows td.c-a { grid-column: 2; text-align: right; }
.twrap.rows td.c-a:empty, .twrap.rows td.c-f { display: none; }
.twrap.rows .cbt tr, .twrap.rows .ntab tr { grid-template-columns: minmax(0, 1fr); }
.twrap.rows .cbt td.num, .twrap.rows .ntab td.num { grid-column: 1; }

.sheet-foot { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin-top: 12px; }
.confirm { flex-basis: 100%; margin: 0; padding: 8px 10px; background: var(--soft); border: 1px solid var(--close); border-radius: var(--r); }
.save-hint { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 1rem; }
.share { margin: 0 0 22px; }
.print-row { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end; }
.print-row label { display: grid; gap: 2px; font-size: .92rem; }
.share-out label { display: grid; gap: 2px; }
.share-out input { width: 100%; font-family: var(--mono); font-size: 14px; }
.recent ul { list-style: none; padding: 0; margin: 4px 0; }
.recent li { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); padding: 4px 0; }
.recent small { display: block; color: var(--muted); }

/* content below the tool */
.content { max-width: 72ch; padding-bottom: 20px; }
.content h2 { font-size: 1.35rem; margin: 26px 0 8px; color: var(--accent); }
.faq details { border-bottom: 1px solid var(--line); }
.faq summary { cursor: pointer; padding: 10px 0; font-weight: 600; min-height: 44px; }
.faq p { margin: 0 0 12px; }
.sources { font-size: 1rem; color: var(--muted); }

footer { border-top: 3px double var(--line2); padding: 16px 0 28px; color: var(--muted); font-size: .9rem; }
.indep { margin: 0 0 10px; }
.sb-footer p { margin: 6px 0; }
.sb-more { line-height: 1.8; }
.sb-footer a { color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 16px; transform: translate(-50%, 140%); max-width: min(92vw, 520px); background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: var(--r); transition: transform .2s; z-index: 10; pointer-events: none; }
.toast.on { transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
.print-root { display: none; }

@media (max-width: 520px) {
  body { font-size: 16px; }
  .hero { padding-right: 0; }
  .hero::after { display: none; }
  .sheet { padding: 12px 10px; outline-offset: -5px; }
  .steps-row { display: grid; grid-template-columns: 1fr 1fr; }
  .step span { padding: 6px 8px; font-size: .88rem; width: 100%; line-height: 1.25; }
  .figin { width: 100%; }
}

@media print {
  :root { --ink: #000; --muted: #333; --line: #999; --line2: #555; --paper: #fff; --bg: #fff; --accent: #000; --seal: #000; }
  @page { margin: 14mm 13mm; }
  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 + li { break-before: page; }
  .pk > li + li { margin-top: 16pt; padding-top: 6pt; border-top: 0.5pt solid #777; }
  .pqh h3, .pk h3 { font-size: 12pt; margin: 6px 0 4px; }
  .pk h3, .jkey .tcap { break-after: avoid; }
  .scen { margin: 0 0 5px; }
  .twrap { overflow: visible; break-inside: avoid; margin-bottom: 8px; }
  .jpaper, .jkey { break-inside: auto; }
  .jpaper { break-before: page; }
  .jpaper .tcap { margin-top: 0; }
  .tcap { color: #000; font-size: 10pt; margin: 6px 0 2px; }
  table.terms { font-size: 9.5pt; }
  table.jt, table.cbt, table.ntab { font-size: 9.5pt; width: 100%; table-layout: fixed; }
  .jt th, .jt td, .cbt th, .cbt td, .ntab th, .ntab td { border: 0.5pt solid #777; padding: 1.5pt 4pt; }
  .jt .c-d { width: 9%; } .jt .c-f { width: 6%; } .jt .c-a { width: 15%; }
  .jt.key .c-f, .jt.key th.c-f { display: table-cell; }
  .jt.blank td { height: 13.5pt; }
  .jt tbody.je { break-inside: avoid; }
  .cbt.blank .c-d { width: 9%; } .cbt.blank .c-a { width: 14%; }
  .cbt.blank td { height: 15pt; }
  .docs.cb { display: grid; grid-template-columns: 1fr 1fr; gap: 8pt; }
  .ntab .num { width: 22%; }
  .ntab.blank td.num { height: 15pt; }
  .pblank { letter-spacing: 1px; }
  .pfigs { margin: 6pt 0; }
  .pfig { display: flex; justify-content: space-between; border-bottom: 0.5pt solid #777; padding: 10pt 0 1pt; margin: 0; max-width: 75%; }
  .kfigs div { border-bottom: 0.5pt solid #777; }
  .steps { font-size: 9.5pt; margin: 4px 0; }
  .wnotes .tcap { break-after: avoid; }
  .steps li { break-inside: avoid; }
  .steps li:first-child, .steps li:last-child { break-before: avoid; }
  .narr { color: #000; font-size: 9pt; }
  .tnote, .terms caption, .cbt caption, .ntab caption { font-size: 9.5pt; }
  .jt th, .ncount, .hint { font-size: 9.5pt; }
  .keyfig > * { margin-bottom: 6px; }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

/* narrow screens: the cash book picker gets its own line, and each note line puts its boxes under the words */
.cbside, .notepart { container-type: inline-size; }
@container (max-width: 440px) {
  .cbt.scr tbody, .cbt.scr tr { display: block; }
  .cbt.scr thead { display: none; }
  .cbt.scr tr { display: grid; grid-template-columns: minmax(0, 1fr) 9.5rem; gap: 4px 8px; padding: 4px 0; border-bottom: 1px solid var(--line); }
  .cbt.scr td, .cbt.scr th { display: block; border: 0; padding: 0; width: auto; }
  .cbt.scr td:first-child:has(select) { grid-column: 1 / -1; }
  .cbt.scr td.num { grid-column: 2; }
  .cbt.scr tr.cbtot, .cbt.scr tr.cbbal { align-items: center; }
  .cbt.scr tr.cbtot { border-bottom: 3px double var(--ink); border-top: 1.5px solid var(--ink); }
}
@container (max-width: 560px) {
  .ntab.scr, .ntab.scr tbody { display: block; }
  .ntab.scr thead { display: none; }
  .ntab.scr tr { display: grid; grid-template-columns: minmax(0, 1fr) 9.5rem; gap: 4px 8px; align-items: end; padding: 5px 0; border-bottom: 1px solid var(--line); }
  .ntab.scr tr.nh { display: block; border: 0; }
  .ntab.scr th, .ntab.scr td { display: block; border: 0; padding: 0; width: auto; }
  .ntab.scr tr.ntot { border-top: 1.5px solid var(--ink); border-bottom: 3px double var(--ink); }
  .ntab.scr th.nlab { grid-column: 1 / -1; }
  .ntab.scr tr.ntot th.nlab, .ntab.scr tr.nres th.nlab, .ntab.scr tr.nr-ca th.nlab, .ntab.scr tr.nr-sf th.nlab { grid-column: 1; }
  .ntab.scr td.num { grid-column: 2; }
  .ntab.scr .ncount { font-size: 1rem; }
}
@media (max-width: 520px) {
  .sheet { padding: 12px 8px; }
  select.cell { padding: 6px 2px 6px 4px; letter-spacing: -0.01em; }
}
