/* Process costing practice: a plant's production cost report. Cool steel-grey paper, blue-black ink and one deep
   process-blue accent; plain sans headings like a control-room report, tabular figures, and the answers laid out in
   the order the costs flow (units, equivalent units, cost per unit, costs), each stage under a ruled band. */
:root {
  --bg: #edf1f3; --paper: #ffffff; --ink: #13222e; --muted: #3d4f5d; --line: #cfd8de; --line2: #7c8d99;
  --accent: #0b5878; --accent-ink: #ffffff; --accent-soft: #dcebf2;
  --ok: #1d6436; --ok-soft: #e1efe3; --bad: #a3231a; --bad-soft: #fae3df; --warn: #6f4e00; --warn-soft: #f6ebcc;
  --head: "Avenir Next", "Segoe UI", "Helvetica Neue", system-ui, sans-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: 6px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f171d; --paper: #16222b; --ink: #e3ecf2; --muted: #a9bac6; --line: #2a3a46; --line2: #5f7382;
    --accent: #6cc3e6; --accent-ink: #04212e; --accent-soft: #15384a;
    --ok: #8fd6a2; --ok-soft: #173020; --bad: #ff9b8f; --bad-soft: #3d1f1b; --warn: #efc46a; --warn-soft: #382e15;
  }
}
* { 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); }
.wrap { max-width: 1100px; 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(--head); line-height: 1.15; font-weight: 700; letter-spacing: -0.01em; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* hero */
.hero { padding: 22px 0 4px; }
.hero h1 { font-size: clamp(1.8rem, 5vw, 2.6rem); margin: 0 0 8px; }
.lede { margin: 4px 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: 4px; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip 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; }
.chip input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.setrow { display: flex; flex-wrap: wrap; gap: 10px 16px; 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; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { 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; background: var(--warn-soft); border-radius: var(--r); }
#store-note { overflow-wrap: anywhere; }
.note.info { background: var(--paper); border: 1px solid var(--line); }
@media (max-width: 600px) {
  .hero { padding-top: 12px; }
  .setup { gap: 6px; margin-top: 8px; }
  .chips { gap: 4px; }
  .chip span { padding: 6px 10px; white-space: normal; line-height: 1.2; border-radius: var(--r); }
  .sheet { padding: 12px 10px 14px; }
}


/* the sheet */
.sheet { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 20px 16px; margin: 10px 0 18px; box-shadow: 0 1px 0 var(--line); }
.sheet:focus { outline: none; }
.sheet-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 16px; border-bottom: 4px solid var(--accent); padding-bottom: 6px; }
.sheet-head h2 { margin: 0; font-size: 1.35rem; }
.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: 6px 0 2px; }
.rules summary, .work summary, .recent summary, .faq summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; gap: 8px; font-weight: 600; list-style: none; }
.rules summary::-webkit-details-marker, .work summary::-webkit-details-marker, .recent summary::-webkit-details-marker, .faq summary::-webkit-details-marker { display: none; }
.rules summary::before, .work summary::before, .recent summary::before, .faq summary::before { content: ""; flex: none; width: 0; height: 0; border-style: solid; border-width: 5px 0 5px 8px; border-color: transparent transparent transparent currentColor; }
.rules[open] > summary::before, .work[open] > summary::before, .recent[open] > summary::before, .faq[open] > summary::before { transform: rotate(90deg); }
.rules ul { margin: 4px 0 8px; padding-left: 20px; max-width: 82ch; }
.rules li { margin: 0 0 4px; }
.qs { list-style: none; margin: 0; padding: 0; }
.q { padding: 16px 0 6px; border-top: 1px solid var(--line2); margin-top: 12px; }
.q:first-child { margin-top: 6px; border-top: 0; }
.qhead { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 16px; margin: 0 0 6px; }
.qhead .see { font-weight: 600; }
.q h3 { margin: 0; font-size: 1.3rem; display: flex; gap: 10px; align-items: baseline; }
.qn { font-family: var(--mono); color: var(--accent-ink); background: var(--accent); border-radius: 50%; min-width: 1.6em; height: 1.6em; display: inline-flex; align-items: center; justify-content: center; font-size: 1rem; }
.scen { margin: 0 0 12px; max-width: 75ch; }

/* tables: ruled like a printed statement */
.twrap { max-width: 100%; margin: 0 0 12px; }
table.dt { border-collapse: collapse; font-variant-numeric: tabular-nums; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); }
.dt caption { text-align: left; font-family: var(--head); font-weight: 700; font-size: 1.05rem; padding: 0 0 4px; }
.dt th, .dt td { padding: 6px 10px; text-align: left; vertical-align: top; font-weight: 400; border-bottom: 1px solid var(--line); }
.dt thead th { font-weight: 700; border-bottom: 1px solid var(--ink); vertical-align: bottom; }
.dt .num { text-align: right; font-family: var(--mono); }
.dt thead th.num { font-family: var(--sans); }
.dt tbody th[scope="row"] { font-weight: 600; }
.dt tr.tot th, .dt tr.tot td { border-top: 1px solid var(--ink); font-weight: 700; }
.tpair { display: flex; flex-wrap: wrap; gap: 0 28px; align-items: flex-start; }
/* a T-account: Dr and Cr side by side with their totals on one line; stacked on a narrow screen, each under its heading */
.tacct { margin: 0 0 10px; container-type: inline-size; max-width: 900px; }
.tsides { display: flex; gap: 0 16px; align-items: stretch; }
.tside { flex: 1 1 0; min-width: 0; }
.tside table { width: 100%; height: 100%; }
.tside .dt th, .tside .dt td { padding: 4px 6px; }
.tside .dt td { white-space: nowrap; }
.tside thead th:first-child { font-family: var(--mono); }
.tside tr.pad th, .tside tr.pad td { border-bottom-color: transparent; }
@container (max-width: 34em) {
  .tsides { flex-direction: column; gap: 8px; }
  .tside tr.pad { display: none; }
}
/* a phone: each entry's name on its own line, its units and amount under it in fixed columns, under Dr | Units | Amount */
@container (max-width: 24em) {
  .tside table, .tside thead, .tside tbody { display: block; height: auto; }
  .tside tr { display: grid; grid-template-columns: minmax(0, 1fr) 4.6em 9.4em; border-bottom: 1px solid var(--line); }
  .tside thead tr { border-bottom: 1px solid var(--ink); }
  .tside th, .tside td, .tside .dt th, .tside .dt td { border: 0; padding: 3px 4px; }
  .tside tbody th[scope="row"] { grid-column: 1 / -1; padding-bottom: 0; }
  .tside tbody td:nth-of-type(1) { grid-column: 2; }
  .tside tr.tot { border-top: 1px solid var(--ink); }
}
.stmt tr.st-total th, .stmt tr.st-total td { font-weight: 700; border-top: 1px solid var(--ink); }
.stmt tr.st-sub th, .stmt tr.st-sub td { font-style: italic; }
input.cell { min-height: 44px; padding: 6px 8px; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; max-width: 100%; }
input.cell { width: calc(var(--w, 12) * 1ch + 18px); }
/* a box holds the set's longest key written the long way; anything longer typed in it widens it, up to the row */
@supports (field-sizing: content) { input.cell:not([type=radio]) { field-sizing: content; width: auto; min-width: calc(var(--w, 12) * 1ch + 18px); } }
.cell.is-right { border-color: var(--ok); background: var(--ok-soft); box-shadow: inset 0 0 0 1px var(--ok); }
.cell.is-wrong, .cell.is-unread { border-color: var(--bad); background: var(--bad-soft); box-shadow: inset 0 0 0 1px var(--bad); }
.cell.is-close { border-color: var(--warn); background: var(--warn-soft); box-shadow: inset 0 0 0 1px var(--warn); }
.cell.is-own { border-color: var(--warn); border-style: dashed; box-shadow: inset 0 0 0 1px var(--warn); }

/* answers: a variance is an amount box and an F/A pair */
.agroup { margin: 8px 0 4px; }
.agroup { counter-increment: stage; }
.agh { margin: 10px 0 2px; font-family: var(--head); font-weight: 700; font-size: 1.05rem; padding: 4px 0; border-top: 2px solid var(--ink); display: flex; gap: 8px; align-items: baseline; }
.agh::before { content: counter(stage); font-family: var(--mono); color: var(--accent); }
.q { counter-reset: stage; }
.answers { display: grid; gap: 0; max-width: 680px; }
/* the label and its box share a line while both fit (on a phone too); a long pair wraps the box under the label */
.arow { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; padding: 5px 0; border-bottom: 1px dotted var(--line2); }
.alab { font-weight: 600; flex: 1 1 7em; min-width: 0; }
.aval { display: inline-flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px 10px; min-width: 0; max-width: 100%; margin-left: auto; }
.arow > .fb { flex: 1 1 100%; margin: 2px 0 2px; }
.cwfa { display: inline-flex; align-items: center; gap: 4px; }
.fas { display: inline-flex; gap: 0; border: 1px solid var(--line2); border-radius: var(--r); overflow: hidden; }
.fa { position: relative; display: flex; align-items: center; justify-content: center; min-width: 56px; padding: 0 8px; min-height: 44px; cursor: pointer; font-family: var(--mono); font-weight: 700; background: var(--paper); }
.fa + .fa { border-left: 1px solid var(--line2); }
.fa input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.fa:has(input:checked) { background: var(--accent); color: var(--accent-ink); }
.fa:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: -3px; }
.fas.is-right .fa:has(input:checked) { background: var(--ok); color: var(--paper); }
.fas.is-wrong .fa:has(input:checked), .fas.is-unread .fa:has(input:checked) { background: var(--bad); color: var(--paper); }
.fas.is-own .fa:has(input:checked) { background: var(--warn); color: var(--paper); }
.kv { font-family: var(--mono); font-weight: 700; }

/* tables that do not fit (fit.js measures them; screen only): each row becomes a block, each value labelled with its column */
@media screen {
  .twrap.rows { width: 100%; flex: 1 1 100%; }
  .twrap.rows table, .twrap.rows tbody { display: block; width: 100%; }
  .twrap.rows table.dt { border-bottom: 0; }
  .twrap.rows caption { display: block; }
  .twrap.rows thead { display: none; }
  .twrap.rows tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(11em, 1fr)); gap: 4px 16px; padding: 8px 0; border-bottom: 1px solid var(--line2); }
  .twrap.rows tbody th[scope="row"] { grid-column: 1 / -1; }
  .twrap.rows th, .twrap.rows td { border: 0; padding: 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; min-width: 0; }
  .twrap.rows th { justify-content: flex-start; font-weight: 700; color: var(--ink); }
  .twrap.rows td::before { content: attr(data-l); font: 600 1rem var(--sans); color: var(--muted); }
  .twrap.rows td:empty { display: none; }
}
/* a phone: the data tables keep their columns, packed closer */
@media screen and (max-width: 600px) {
  .q .dt th, .q .dt td { padding: 5px 6px; }
  .q .dt .num { font-size: 0.95rem; }
  .tpair { gap: 0 16px; }
}
@media screen and (max-width: 560px) {
  .content .twrap { width: 100%; }
  .content .twrap table, .content .twrap tbody { display: block; width: 100%; }
  .content .twrap table.dt { border-bottom: 0; }
  .content .twrap caption { display: block; }
  .content .twrap thead { display: none; }
  .content .twrap tr { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; padding: 8px 0; border-bottom: 1px solid var(--line2); }
  .content .twrap th, .content .twrap td { border: 0; padding: 0; display: flex; justify-content: space-between; gap: 10px; min-width: 0; }
  .content .twrap td::before { content: attr(data-l); font: 600 1rem var(--sans); color: var(--muted); flex: none; }
}

/* feedback */
.fbwrap { margin: 6px 0; }
.fbl { margin: 4px 0; padding: 0 0 0 2.2em; max-width: 80ch; }
.fb { margin: 4px 0; padding: 6px 10px; border-radius: var(--r); background: var(--bad-soft); max-width: 80ch; }
.fbl .fb::marker { font-weight: 700; }
.fb.right { background: var(--ok-soft); }
.fb.close { background: var(--warn-soft); }
.fb.own { background: var(--paper); border: 1px dashed var(--warn); }
.fb.empty, .fb.sum { background: var(--paper); border: 1px solid var(--line); }
.cw { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; min-width: 0; }
.cw > .cell { flex: none; }
.mk { flex: none; min-width: 1.6em; font-weight: 700; font-size: 1.1rem; line-height: 1; white-space: nowrap; }
.mk-right { color: var(--ok); }
.mk-close, .mk-own { color: var(--warn); }
.mk-wrong, .mk-unread { color: var(--bad); }
.qfoot { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.work { margin: 4px 0 8px; }
.keyfig { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.kpart { min-width: 0; }
.kh { margin: 8px 0 2px; font-weight: 700; }
.kq, .kqp { display: none; }
.steps { margin: 4px 0 8px; padding-left: 2.6em; font-family: var(--mono); font-size: 1rem; max-width: 90ch; }
.steps li { margin: 4px 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: 2px solid var(--ink); }
.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 .when { display: block; color: var(--muted); }
.hint { color: var(--muted); }

/* content */
.content { max-width: 78ch; padding-bottom: 20px; }
.content h2 { font-size: 1.5rem; margin: 28px 0 8px; }
.content .dt { margin: 6px 0 10px; }
.faq details { border-bottom: 1px solid var(--line); }
.faq details p { margin: 0 0 12px; }
.sources { color: var(--muted); overflow-wrap: anywhere; }
footer { border-top: 4px solid var(--accent); padding: 18px 0 30px; color: var(--muted); }
.indep { margin: 0 0 10px; }
.sb-footer p { margin: 6px 0; }
.sb-more { line-height: 1.8; }
.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, 560px); z-index: 20; pointer-events: none; transition: transform 0.2s; }
.toast.on { transform: translate(-50%, 0); }
.toast.top { top: 16px; bottom: auto; transform: translate(-50%, -140%); }
.toast.top.on { transform: translate(-50%, 0); }
@media (max-width: 600px) {
  .toast { left: 8px; right: 8px; bottom: 8px; max-width: none; text-align: center; transform: translateY(140%); }
  .toast.top { top: 8px; bottom: auto; transform: translateY(-140%); }
  .toast.on, .toast.top.on { transform: none; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
[hidden] { display: none !important; }
.print-root { display: none; }

/* ---------- print ---------- */
@page { margin: 12mm; }
@media print {
  :root { --ink: #000; --muted: #333; --line: #999; --line2: #555; --paper: #fff; --bg: #fff; --accent: #000; }
  body { background: #fff; color: #000; font: 10.5pt/1.35 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: #333; padding-bottom: 4px; border-bottom: 0.5pt solid #888; }
  .ph { display: flex; justify-content: space-between; align-items: baseline; gap: 6pt 12pt; flex-wrap: wrap; margin-bottom: 4pt; }
  .ph h2 { margin: 4px 0 0; font-size: 15pt; }
  .pmeta { display: flex; gap: 14pt; margin: 0; }
  .prules { margin: 3px 0 4px; padding-left: 14pt; font-size: 9.5pt; line-height: 1.28; }
  .prules li { margin: 0 0 2px; break-inside: avoid; }
  .pq, .pk { list-style: none; margin: 0; padding: 0; }
  .pq > li, .pk > li { margin: 0 0 8pt; padding-top: 5pt; border-top: 1.2pt solid #000; break-inside: avoid; }
  /* a key may go on over a page between its working and its statement or accounts, each kept whole */
  .pk > li { break-inside: auto; }
  .pk .kpart, .pk .tacct, .pk .twrap { break-inside: avoid; }
  .pk > li:last-child, .pq > li:last-child { margin-bottom: 0; }
  .pq h3, .pk h3 { font-size: 12pt; margin: 0 0 3pt; break-after: avoid; }
  .scen { margin: 0 0 5pt; max-width: none; }
  .twrap { break-inside: avoid; margin: 0 0 5pt; }
  /* collapsed borders: inset so both outer rules sit inside the A4 content box */
  table.dt { font-size: 10pt; border-top: 1.2pt solid #000; border-bottom: 1.2pt solid #000; margin: 0 1pt; }
  .dt caption { font-size: 10pt; padding-bottom: 2pt; }
  .dt th, .dt td { padding: 1.5pt 7pt; border-bottom: 0.5pt solid #999; }
  .dt thead th { border-bottom: 0.75pt solid #000; }
  .tpair { gap: 0 10pt; flex-wrap: nowrap; }
  .tpair .twrap { flex: 0 1 auto; min-width: 0; }
  .tpair .dt th, .tpair .dt td { padding: 1.5pt 4pt; }
  .tpair .dt td { white-space: nowrap; }
  .pblank { display: inline-block; border: 0.75pt solid #000; height: 22pt; vertical-align: middle; }
  .pfa { font-family: var(--mono); font-weight: 700; margin-left: 6pt; }
  /* the answer rows run down three columns, each stage heading kept with its first row */
  .agroups { column-count: 3; column-gap: 12pt; }
  .answers { max-width: none; display: block; }
  .arow { break-inside: avoid; }
  .agh { break-after: avoid; }
  .arow { display: flex; flex-wrap: nowrap; justify-content: space-between; align-items: center; border-bottom: 0; padding: 1.5pt 0; gap: 8pt; }
  .alab { flex: 1 1 auto; }
  .arow > .fb { display: none; }
  .agh { font-size: 10.5pt; margin: 3pt 0 0; }
  .agroup { margin: 0 0 2pt; break-inside: auto; }
  .agkeep { break-inside: avoid; }
  .keyfig { display: block; }
  .kpart + .kpart { margin-top: 3pt; }
  .kh { margin: 2pt 0 1pt; font-size: 10pt; }
  .steps { font-size: 10pt; margin: 0; padding-left: 22pt; max-width: none; }
  .steps li { margin: 0.5pt 0; break-inside: avoid; }
  .kq { display: inline; }
  .kqp { display: block; }
  /* the key on paper: the working lines carry every value, then the statement or the accounts, Dr and Cr side by side */
  .tacct { container-type: normal; max-width: none; }

  .tsides { flex-direction: row; gap: 0 8pt; }
  .tside tr.pad { display: table-row; }
  .tside .dt th, .tside .dt td { padding: 1pt 4pt; }
  .agh { border-top: 0.75pt solid #000; padding: 1pt 0; }
  .agh::before { color: #000; }
  .kpart .answers .arow { min-height: 0; }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
