/* Consignment and joint venture practice: an Indian account book. Navy ink on pale ruled paper, the red margin rule of a
   ledger page as the one motif (on the sheet's left edge and under every account's totals), serif headings and
   tabular figures. */
:root {
  --bg: #e7ecf0; --paper: #fbfcf8; --ink: #13243d; --muted: #485569; --line: #c9d3dc; --line2: #8d9bab;
  --accent: #1f3f73; --accent-ink: #ffffff; --rule: #b3261e; --dr: #1f3f73; --cr: #7a2e12;
  --ok: #1b6a37; --ok-soft: #e0f1e5; --bad: #a3261b; --bad-soft: #fbe6e3; --warn: #7d5300; --warn-soft: #faf0d4; --own: #3d4f9a; --own-soft: #e6e9f7;
  --serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --r: 4px;
  --mk-right: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%231b6a37' stroke-width='2.4'%3E%3Cpath d='M2.5 8.5l3.5 3.5 7.5-8'/%3E%3C/svg%3E");
  --mk-wrong: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23a3261b' stroke-width='2.4'%3E%3Cpath d='M3.5 3.5l9 9M12.5 3.5l-9 9'/%3E%3C/svg%3E");
  --mk-own: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%233d4f9a' stroke-width='2.2'%3E%3Cpath d='M2 8h10M8.5 4l4 4-4 4'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1520; --paper: #162132; --ink: #e3eaf4; --muted: #a9b6c8; --line: #2e3c50; --line2: #52627a;
    --accent: #9cc0ff; --accent-ink: #0e1520; --rule: #ff8b80; --dr: #9cc0ff; --cr: #f0b48e;
    --ok: #7fd49c; --ok-soft: #173023; --bad: #ff9a8f; --bad-soft: #3a1d1b; --warn: #f0c46b; --warn-soft: #362c14; --own: #b0bcff; --own-soft: #232a4a;
    --mk-right: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%237fd49c' stroke-width='2.4'%3E%3Cpath d='M2.5 8.5l3.5 3.5 7.5-8'/%3E%3C/svg%3E");
    --mk-wrong: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23ff9a8f' stroke-width='2.4'%3E%3Cpath d='M3.5 3.5l9 9M12.5 3.5l-9 9'/%3E%3C/svg%3E");
    --mk-own: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23b0bcff' stroke-width='2.2'%3E%3Cpath d='M2 8h10M8.5 4l4 4-4 4'/%3E%3C/svg%3E");
  }
}
* { 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; }
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 { font-family: var(--serif); line-height: 1.2; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.hero { padding: 22px 0 8px; }
.hero h1 { font-size: clamp(1.6rem, 4.6vw, 2.35rem); margin: 0 0 8px; }
.lede { margin: 6px 0 0; max-width: 64ch; 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; }
.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); white-space: nowrap; }
.step b { font-family: var(--mono); margin-right: 6px; color: var(--muted); }
.step input:checked + span { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.step input:checked + span b { color: var(--paper); }
.step input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.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; }
.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; }
.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); }

/* the sheet: a ledger page with its red margin rule */
.sheet { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px 16px; margin: 10px 0 18px; }
.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-family: var(--sans); font-size: 1rem; font-weight: 400; 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; }
.rules ul { margin: 4px 0 8px; padding-left: 20px; max-width: 80ch; }
.qs { list-style: none; margin: 0; padding: 0; }
.q { padding: 14px 0 6px; border-top: 1px solid var(--line); }
.q:first-child { border-top: 0; }
.q h3 { margin: 4px 0 6px; font-size: 1.15rem; display: flex; flex-wrap: wrap; gap: 0 10px; align-items: baseline; }
.q h3 .see { margin-left: auto; font: 600 1rem var(--sans); white-space: nowrap; padding: 10px 0; }
.qn { font-family: var(--mono); color: var(--paper); background: var(--ink); border-radius: 3px; padding: 0 7px; font-size: 1rem; }
.scen { margin: 0 0 10px; max-width: 78ch; }
.qhint { color: var(--muted); margin: 0 0 10px; max-width: 78ch; }

/* the expenses given */
.fig { display: grid; gap: 14px; }
.givens { display: flex; flex-wrap: wrap; gap: 10px 24px; }
.givens .twrap { flex: 1 1 260px; max-width: 380px; }
.tcap { font-weight: 700; margin: 0 0 4px; }
table.dt { border-collapse: collapse; width: 100%; font-size: 1rem; }
.dt th, .dt td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; font-weight: 400; }
.dt thead th { font-weight: 700; border-bottom: 2px solid var(--line2); }
.dt .num, .ledger .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* accounts on screen: Item, Dr, Cr */
.books { display: grid; gap: 18px; }
.atitle { margin: 0 0 4px; display: flex; flex-wrap: wrap; gap: 0 10px; align-items: baseline; }
.at { font-family: var(--serif); font-weight: 700; font-size: 1.05rem; }
.asub { color: var(--muted); }
table.ledger { border-collapse: collapse; width: 100%; font-size: 1rem; }
.ledger th, .ledger td { border-bottom: 1px solid var(--line); padding: 4px 6px; vertical-align: middle; text-align: left; font-weight: 400; }
.ledger thead th { font-weight: 700; border-bottom: 2px solid var(--line2); }
.grid .ledger th.c-x { line-height: 1.3; }
/* fixed layout: every Dr and Cr cell exactly the width set below, whatever the item labels */
.grid table.ledger { table-layout: fixed; }
/* wide enough for the longest accepted form with its mark: "Rs. 1,70,70,480/-" (tested in tests/qa.mjs) */
.grid .ledger thead th.c-d, .grid .ledger thead th.c-c { width: 13em; text-align: right; }
.grid .ledger thead th.c-d { color: var(--dr); }
.grid .ledger thead th.c-c { color: var(--cr); }
.grid td.in { padding: 3px 4px; }
.grid td.c-d { border-left: 1px solid var(--line2); }
.grid td.c-c { border-left: 1px solid var(--line2); border-right: 1px solid transparent; }
.grid tr.r-tot th, .grid tr.r-tot td { border-top: 1px solid var(--ink); border-bottom: 3px double var(--rule); font-weight: 700; }
.grid tr.r-bd th { font-style: italic; }
input.cell { width: 100%; min-height: 44px; padding: 6px 8px; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
/* a mark is a tick, a cross or an arrow (follows your figures), never colour alone */
input.cell.is-right { border-color: var(--ok); background-color: var(--ok-soft); box-shadow: inset 0 0 0 1px var(--ok); }
input.cell.is-wrong, input.cell.is-unread { border-color: var(--bad); background-color: var(--bad-soft); box-shadow: inset 0 0 0 1px var(--bad); }
input.cell.is-own { border-color: var(--own); background-color: var(--own-soft); box-shadow: inset 0 0 0 1px var(--own); }
input.cell:is(.is-right, .is-wrong, .is-unread, .is-own) { background-repeat: no-repeat; background-position: 4px center; background-size: 15px; padding-left: 22px; }
input.cell.is-right { background-image: var(--mk-right); }
input.cell.is-wrong, input.cell.is-unread { background-image: var(--mk-wrong); }
input.cell.is-own { background-image: var(--mk-own); }

/* phones: each line on its own row, the Dr and Cr cells below it, each labelled */
@media (max-width: 560px) {
  .grid table.ledger, .grid table.ledger tbody { display: block; }
  .grid table.ledger thead { display: none; }
  .grid table.ledger tr { display: grid; grid-template-columns: 1fr 1fr; column-gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--line); }
  .grid table.ledger th, .grid table.ledger td { border: 0; padding: 0; display: block; }
  .grid table.ledger th.c-x { grid-column: 1 / -1; padding: 0 0 4px; }
  .grid table.ledger td.in { display: flex; align-items: center; gap: 4px; }
  .grid table.ledger td.in::before { font: 700 1rem var(--sans); }
  .grid table.ledger td.c-d::before { content: "Dr"; color: var(--dr); }
  .grid table.ledger td.c-c::before { content: "Cr"; color: var(--cr); }
  .grid table.ledger tr.r-tot { border-bottom: 3px double var(--rule); }
  .grid table.ledger tr.r-tot th, .grid table.ledger tr.r-tot td { border: 0; }
  .grid input.cell { padding-right: 4px; }
  .sheet { padding-left: 10px; padding-right: 10px; }
}
/* phones (the grid above): Dr and Cr one under the other, so the longest accepted form ("Rs. 1,70,70,480/-") with its mark fits */
@media (max-width: 560px) {
  .grid table.ledger tr { grid-template-columns: 1fr; row-gap: 4px; }
  .grid table.ledger td.in::before { min-width: 1.4em; }
}

/* level 1: one box per figure */
.answers { display: grid; gap: 6px; max-width: 760px; }
.arow { display: grid; grid-template-columns: 1fr 14em; gap: 4px 12px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line); }
.ab { display: flex; align-items: center; gap: 4px; }
.rsym { font-family: var(--mono); color: var(--muted); }
.kv { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
@media (max-width: 480px) { .arow { grid-template-columns: 1fr; } }

/* the key: the account as a textbook writes it */
.tacct table.ledger { table-layout: fixed; }
.tacct col.k-a { width: 7.5em; }
.tacct .gs { border-left: 2px solid var(--ink); }
.tacct thead th.num { text-align: right; }
.tacct tr.r-tot td.num, .tside tr.r-tot td.num { border-top: 1px solid var(--ink); border-bottom: 3px double var(--rule); font-weight: 700; }
.tacct tr.r-tot td.txt { border-bottom-color: transparent; }
.tstack { display: none; }
@media screen and (max-width: 900px) {
  .tpair { display: none; }
  .tstack { display: grid; gap: 8px; }
}

/* 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.own { background: var(--own-soft); }
.fb.sum { background: var(--paper); border: 1px solid var(--line2); }
.fblist { margin: 6px 0 0; padding-left: 1.8em; }
.qfoot { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.work { margin: 4px 0 8px; }
.keyfig { display: grid; gap: 16px; }
.steps { margin: 10px 0; padding-left: 20px; font-family: var(--mono); font-size: 1rem; }
.steps li { margin: 4px 0; overflow-wrap: anywhere; }
.steps li.say { font-family: var(--sans); }

.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; }
.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 small { display: block; color: var(--muted); font-size: 1rem; }
.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: 3px double var(--rule); 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 { 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; pointer-events: none; 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; }

/* ---------- print ---------- */
@page { margin: 13mm 12mm; }
@media print {
  :root { --ink: #000; --muted: #222; --line: #888; --line2: #444; --paper: #fff; --bg: #fff; --accent: #000; --rule: #000; }
  body { background: #fff; color: #000; font: 10.5pt/1.32 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: 10pt; color: #222; padding-bottom: 4px; border-bottom: 0.5pt solid #888; }
  .phrow { display: flex; justify-content: space-between; align-items: baseline; gap: 12pt; flex-wrap: wrap; }
  .ph h2 { margin: 4px 0 0; font-size: 15pt; }
  .ph p { margin: 2px 0 6px; font-size: 10pt; }
  .pmeta { display: flex; gap: 14pt; margin: 6px 0; }
  .prules { margin: 2pt 0 6pt; padding-left: 14pt; font-size: 10pt; }
  .prules li { margin: 0; }
  .pq, .pk { list-style: none; margin: 0; padding: 0; }
  .pq > li + li { break-before: page; }
  /* keys pack several to a page, but a problem's key is never split across pages */
  .pk > li { margin: 0 0 14pt; break-inside: avoid; }
  .pqh h3, .pk h3 { font-size: 12pt; margin: 6px 0 2px; }
  .scen { margin: 0 0 6pt; max-width: none; }
  .fig { display: block; }
  .givens { display: flex; gap: 6pt 18pt; margin-bottom: 8pt; }
  .givens .twrap { flex: 0 1 46%; max-width: none; break-inside: avoid; }
  table.dt, table.ledger { font-size: 10pt; width: 100%; }
  .dt th, .dt td, .ledger th, .ledger td { padding: 2pt 4pt; border-bottom: 0.5pt solid #777; }
  .books { display: block; }
  .books.pnext { break-before: page; }
  .books > .tacct, .keyfig > .tpair { margin-top: 10pt; break-inside: avoid; }
  .pcont { margin: 0 0 4pt; font: 700 11pt var(--serif); }
  .tacct .gs { border-left: 1pt solid #000; }
  .tacct col.k-a { width: 16%; }
  .tacct.blank tbody td { height: 21pt; vertical-align: bottom; }
  .tacct tr.r-tot td.num { border-top: 0.75pt solid #000; border-bottom: 2.5pt double #000; }
  .at { font-size: 11pt; }
  .answers { max-width: none; gap: 0; }
  .arow { grid-template-columns: 1fr 13em; padding: 0; min-height: 26pt; border-bottom: 0; }
  .pblank { display: block; height: 21pt; border-bottom: 0.75pt solid #000; font-family: var(--mono); padding-top: 6pt; }
  .keyfig { display: block; }
  .tstack { display: none; }
  .steps { font-size: 10pt; margin: 6pt 0; }
  /* the key: one page per problem even for the tallest (worst-case print test in tests/qa.mjs) */
  .tacct.key col.k-a { width: 76pt; }
  .tacct.key .ledger th, .tacct.key .ledger td { padding: 1pt 4pt; line-height: 1.2; }
  .keyfig > .tpair { margin-top: 6pt; }
  .tacct.key .atitle { margin: 0 0 2pt; }
  .steps { line-height: 1.22; break-inside: avoid; }
  .steps li { margin: 1pt 0; }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
