/* Animal nutrition practice: feed-sack kraft, dark soil-brown ink and a maize ochre for the accent. The Pearson
   square's crossed diagonals are the page's one motif (favicon, og image and the square itself). */
:root {
  --bg: #efe9dc; --paper: #fffdf7; --ink: #2b2418; --muted: #574c3c; --line: #d8cfbd; --line2: #9a8d77;
  --accent: #7a4f00; --accent-ink: #ffffff; --accent-soft: #f6e7c4;
  --ok: #24663a; --ok-soft: #e2f0e2; --bad: #a4261c; --bad-soft: #fbe4df; --warn: #7a5200; --warn-soft: #fbf0d4;
  --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;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1712; --paper: #221e17; --ink: #ece6d8; --muted: #c2b8a5; --line: #3d362b; --line2: #6e6453;
    --accent: #e8b84a; --accent-ink: #1e1606; --accent-soft: #3a2f17;
    --ok: #86d39c; --ok-soft: #1b3324; --bad: #ff9d90; --bad-soft: #3e1f1b; --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: 17px/1.55 var(--sans); }
.wrap { max-width: 1000px; 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 { line-height: 1.2; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* hero */
.hero { padding: 22px 0 6px; }
.hero h1 { font-size: clamp(1.55rem, 4.4vw, 2.3rem); margin: 0 0 8px; max-width: 28ch; letter-spacing: -0.01em; }
.hero h1::after { content: ''; display: block; width: 72px; height: 4px; margin-top: 10px; background: var(--accent); }
.lede { margin: 6px 0 0; max-width: 62ch; color: var(--muted); }
.practice { margin: 12px 0 0; display: inline-block; padding: 6px 12px; border: 2px solid var(--ink); font-weight: 700; background: var(--paper); }

/* 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: 22px; }
.step input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.step input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.lvdesc { margin: 8px 0 0; color: var(--muted); max-width: 75ch; }
.lvdesc:empty { display: none; }
.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(--ink); border-color: var(--ink); color: var(--paper); }
.btn.small { min-height: 44px; padding: 6px 14px; }
.btn:hover { filter: brightness(0.95); }
.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); }
#store-note { overflow-wrap: anywhere; }
.note.info { border-color: var(--line2); background: var(--paper); }

/* the sheet */
.sheet { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 18px 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; padding-bottom: 8px; border-bottom: 2px solid var(--ink); }
.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; }
.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: 18px 0 6px; border-top: 1px solid var(--line2); }
.q:first-child { border-top: 0; }
.q h3 { margin: 4px 0 8px; font-size: 1.2rem; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.qn { font-family: var(--mono); color: var(--accent); }
.qn::after { content: '.'; }
.see { font-size: 1rem; font-weight: 400; margin-left: auto; padding: 10px 0; }
.scen { margin: 0 0 12px; max-width: 72ch; }
.qhint { color: var(--muted); margin: 8px 0; max-width: 75ch; }

/* the information given */
.fig { display: grid; gap: 16px; }
.given { display: flex; flex-wrap: wrap; gap: 16px 28px; align-items: flex-start; }
.given > *, .fig > * { min-width: 0; }
.twrap { max-width: 100%; flex: 0 1 420px; }
@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; }
  .twrap.stack td[data-h]::before { content: attr(data-h); display: block; color: var(--muted); }
}
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 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; }

/* the Pearson square: HTML text over an SVG square with its diagonals */
.square { margin: 0; width: min(100%, 360px); }
.sq { display: grid; grid-template-columns: auto minmax(96px, 1fr) auto; grid-template-rows: auto minmax(56px, 1fr) auto; column-gap: 8px; }
.sq-box { grid-column: 2; grid-row: 1 / 4; position: relative; margin: 10px 0; }
.sq-lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.sq-lines rect, .sq-lines line { fill: none; stroke: var(--line2); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.sq-c { line-height: 1.3; }
.sq-c b { font-size: 1.1rem; }
.sq-c.tl { grid-column: 1; grid-row: 1; text-align: right; }
.sq-c.tr { grid-column: 3; grid-row: 1; }
.sq-c.mid { grid-column: 2; grid-row: 2; justify-self: center; align-self: center; position: relative; z-index: 1; display: grid; text-align: center; padding: 4px 8px; background: var(--paper); border: 1px solid var(--line2); }
.sq-c.mid span { font-size: 0.85rem; color: var(--muted); }
.sq-c.bl { grid-column: 1; grid-row: 3; text-align: right; align-self: end; }
.sq-c.br { grid-column: 3; grid-row: 3; align-self: end; }
.sq-c .blank { color: var(--muted); }
.square figcaption { color: var(--muted); margin-top: 6px; }

/* answer rows */
.asks { display: grid; gap: 2px; max-width: 760px; }
.arow { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.arow > label, .arow > .ap { flex: 1 1 15em; margin: 0; }
.aval { display: inline-flex; align-items: center; gap: 6px; flex: 0 1 13em; min-width: 0; margin-left: auto; }
.aval input.cell { flex: 1; min-width: 0; }
.pre, .post { font-weight: 600; white-space: nowrap; }
.mk { width: 1.1em; font-weight: 700; text-align: center; }
.mk-right { color: var(--ok); } .mk-close { color: var(--warn); } .mk-wrong, .mk-unread { color: var(--bad); }
.ach { display: block; }
.ach .ap { margin: 0 0 6px; }
input.cell { width: 100%; min-height: 44px; padding: 6px 8px; text-align: right; font-variant-numeric: tabular-nums; }
.cell.is-right { border-color: var(--ok); background: var(--ok-soft); }
.cell.is-wrong, .cell.is-unread { border-color: var(--bad); background: var(--bad-soft); }
.cell.is-close { border-color: var(--warn); background: var(--warn-soft); }
.radios { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15em), 1fr)); gap: 6px; border-radius: var(--r); padding: 2px; }
.radios .opt { display: flex; gap: 10px; align-items: center; min-height: 44px; padding: 6px 10px; border: 1px solid var(--line2); border-radius: var(--r); background: var(--paper); cursor: pointer; }
.radios .opt input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--accent); }
.radios .opt:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.radios.is-right .opt:has(input:checked) { border-color: var(--ok); background: var(--ok-soft); }
.radios.is-wrong .opt:has(input:checked) { border-color: var(--bad); background: var(--bad-soft); }

/* 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; }
.qfoot { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.work { margin: 4px 0 8px; }
.keyfig { margin: 6px 0 14px; display: grid; gap: 10px; }
.akey { margin: 0; font-weight: 700; text-align: right; margin-left: auto; font-variant-numeric: tabular-nums; }
.lead { margin: 4px 0; padding: 8px 12px; background: var(--accent-soft); border-radius: var(--r); max-width: 80ch; }
.tcap { font-weight: 700; margin: 0; }
.steps { margin: 0 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: 72ch; 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: 1px solid 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; }
  .see { margin-left: 0; }
  /* less space above the first problem on a phone */
  .hero { padding-top: 12px; }
  .hero h1::after { margin-top: 8px; }
  .practice { margin-top: 10px; }
  .setup { margin: 12px 0 6px; gap: 8px; }
  .sheet { margin-top: 6px; }
  .qs > .q:first-child { padding-top: 8px; }
  .q h3 { margin-bottom: 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; }
  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 h2 { margin: 4px 0 0; font-size: 15pt; }
  .ph p { margin: 2px 0 6px; font-size: 10pt; }
  .pmeta { display: flex; justify-content: space-between; gap: 10px; margin: 6px 0; }
  .plabel { font-size: 10pt; margin: 0 0 8px; padding: 3pt 6pt; border: 1pt solid #000; }
  .pq, .pk { list-style: none; margin: 0; padding: 0; }
  .pq > li { break-inside: avoid; margin: 0 0 12pt; padding-top: 6pt; border-top: 0.75pt solid #000; }
  .pk > li { margin: 0 0 10pt; padding-top: 6pt; border-top: 0.75pt solid #000; }
  .pk > li { break-inside: avoid; }
  .pqh h3, .pk h3 { font-size: 12pt; margin: 2px 0 2px; }
  .pscen { margin: 0 0 6px; }
  .fig { display: block; }
  .given { display: flex; gap: 10pt 18pt; margin-bottom: 6pt; }
  .twrap { flex: 0 1 85mm; break-inside: avoid; }
  table.dt { font-size: 10pt; }
  .dt th, .dt td { padding: 1.5pt 4pt; line-height: 1.2; border-bottom: 0.5pt solid #777; }
  .dt caption { font-size: 10pt; padding-bottom: 3pt; }
  .square { width: 62mm; flex: 0 0 62mm; break-inside: avoid; font-size: 10pt; }
  .square figcaption { font-size: 10pt; }
  /* the Pearson square beside its answer rows, so two problems fit on a page */
  .fig:has(.square), .kfig:has(.square) { display: flex; gap: 8pt 14pt; align-items: flex-start; }
  .fig:has(.square) > .given { margin: 0; }
  .fig:has(.square) > .asks, .kfig:has(.square) > .asks { flex: 1; min-width: 0; }
  .sq-c.mid { background: #fff; }
  .sq-c b { font-size: 10.5pt; }
  .sq-c.mid span { font-size: 10pt; }
  .sq-lines rect, .sq-lines line { stroke: #000; }
  .asks { display: block; }
  .arow { display: flex; justify-content: space-between; align-items: flex-end; gap: 10pt; padding: 3pt 0; border-bottom: 0; break-inside: avoid; }
  .arow .ap { margin: 0; flex: 1; }
  .aline { margin: 0; white-space: nowrap; }
  .aline .rule { display: inline-block; width: 30mm; border-bottom: 0.75pt solid #000; height: 11pt; margin: 0 2pt; }
  .ach { display: block; }
  .opts { list-style: none; margin: 2pt 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 2pt 14pt; }
  .opts .box { display: inline-block; width: 8pt; height: 8pt; border: 0.75pt solid #000; margin-right: 4pt; vertical-align: -1pt; }
  .pwork { height: 28mm; margin-top: 4pt; }
  .pwork p { margin: 0; font-size: 10pt; color: #333; }
  .akey { font-weight: 700; }
  .keyfig { display: block; margin: 0; }
  .keyfig > * { margin-bottom: 4pt; }
  .lead { padding: 0; margin: 4pt 0; font-weight: 600; }
  .steps { font-size: 10pt; margin: 2px 0; }
  .tcap { margin: 4pt 0 2pt; break-after: avoid; }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
