/* Cost and Revenue Practice: an economics exercise sheet on graph paper. Cool blue-grey ground, a white sheet ruled
   with a faint 8 px graph grid, teal column heads like the ruled headings of a schedule, and one curve-red accent (the
   colour the MC curve is drawn in) for problem numbers and the button that matters. Gill Sans style headings over a
   system body, figures in tabular numerals, square corners. On paper: black rules on white, no tints. */
:root {
  --bg: #eef2f6;
  --paper: #ffffff;
  --ink: #17212b;
  --muted: #4a5664;
  --line: #c9d3dd;
  --grid: rgba(23, 92, 108, 0.07);
  --head: #e3f0f1;
  --head-ink: #0b4f57;
  --teal: #0b5f68;
  --teal-ink: #ffffff;
  --red: #b3261e;
  --red-ink: #ffffff;
  --red-soft: #fbe9e7;
  --link: #0a5b8f;
  --wash: #f4f8fa;
  --given: #17212b;
  --undef: #7a8794;
  --ok: #1a6a3a;
  --ok-soft: #dcefe2;
  --close: #7a5300;
  --close-soft: #f6ead0;
  --bad: #a3271f;
  --bad-soft: #f9e2de;
  --focus: #1b5fd0;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: "Gill Sans", "Gill Sans MT", "Seravek", Calibri, "Segoe UI", system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720;
    --paper: #16212c;
    --ink: #e3e9ef;
    --muted: #a6b3c0;
    --line: #2c3a48;
    --grid: rgba(120, 200, 210, 0.06);
    --head: #18363b;
    --head-ink: #bfe6ea;
    --teal: #5fc2cc;
    --teal-ink: #08181b;
    --red: #ff8f84;
    --red-ink: #2a0b08;
    --red-soft: #3a1c18;
    --link: #8cc6f2;
    --wash: #1b2834;
    --given: #e3e9ef;
    --undef: #8796a5;
    --ok: #8fd8a3;
    --ok-soft: #15301d;
    --close: #f0c56b;
    --close-soft: #352a12;
    --bad: #ff9c8f;
    --bad-soft: #3a1c18;
    --focus: #8ab8ff;
  }
}
* { 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); font-variant-numeric: tabular-nums; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
a { color: var(--link); text-underline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--paper); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- hero and setup ---------- */
.hero { padding: 22px 0 6px; }
h1 { font-family: var(--display); font-weight: 600; font-size: clamp(1.6rem, 4.6vw, 2.4rem); line-height: 1.12; margin: 0 0 6px; max-width: 24ch; letter-spacing: -0.005em; }
h1::after { content: ""; display: block; width: 88px; height: 10px; margin-top: 8px; background: no-repeat center / 88px 10px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 88 10'%3E%3Cpath d='M2 2 Q44 16 86 2' fill='none' stroke='%23b3261e' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E"); }
.lede { margin: 0 0 12px; color: var(--muted); max-width: 66ch; }
.setup { display: grid; gap: 10px; margin-bottom: 14px; padding: 12px 0; border-top: 2px solid var(--teal); }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { font-weight: 600; font-size: 0.92rem; color: var(--muted); padding: 0; margin-bottom: 4px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.sg { position: relative; display: flex; }
.sg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.sg span { display: flex; align-items: center; min-height: 44px; padding: 6px 14px; font-size: 0.95rem; border: 1px solid var(--line); background: var(--paper); cursor: pointer; white-space: nowrap; }
.sg input:checked + span { border-color: var(--teal); box-shadow: inset 0 -3px 0 var(--teal); color: var(--teal); font-weight: 600; }
.sg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; }
.setrow { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; }
.field { display: grid; gap: 2px; font-size: 0.92rem; font-weight: 600; color: var(--muted); }
.task-f select { min-width: 12em; }
.taskdesc { margin: 0; font-size: 0.93rem; color: var(--muted); max-width: 72ch; }
select, input { font: inherit; font-size: 16px; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 0; }
select { min-height: 44px; padding: 4px 8px; font-weight: 400; border-color: var(--teal); }
.btn { font: inherit; font-size: 0.97rem; min-height: 44px; padding: 8px 16px; border: 1px solid var(--teal); background: var(--paper); color: var(--teal); cursor: pointer; border-radius: 0; font-weight: 600; }
.btn:hover { background: var(--wash); }
.btn.primary { background: var(--red); color: var(--red-ink); border-color: var(--red); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { min-height: 40px; padding: 6px 14px; }
.link { font: inherit; background: none; border: 0; color: var(--link); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; padding: 10px 4px; min-height: 44px; }

/* ---------- notes ---------- */
.note { overflow-wrap: anywhere; padding: 10px 12px; background: var(--bad-soft); border: 1px solid var(--bad); margin: 0 0 12px; }
.note.info { background: var(--head); border-color: var(--teal); }

/* ---------- the sheet: graph paper ---------- */
.sheet { background-color: var(--paper); background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 8px 8px; border: 1px solid var(--line); padding: 14px 18px 16px; outline: none; }
.sheet-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 14px; border-bottom: 2px solid var(--ink); padding-bottom: 8px; margin-bottom: 6px; }
.sheet-head h2 { margin: 0; font-family: var(--display); font-weight: 600; font-size: 1.35rem; }
.code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.06em; }
.sline { margin: 0; color: var(--muted); font-size: 0.95rem; }
.score { margin: 0 0 0 auto; font-size: 0.95rem; font-weight: 600; }
.rules { margin: 2px 0 6px; font-size: 0.95rem; }
.rules summary, .work summary, .recent summary, .faq summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--link); font-weight: 600; }
.rules ul { margin: 4px 0 8px; padding-left: 20px; color: var(--muted); max-width: 80ch; }
.qs { list-style: none; margin: 0; padding: 0; }
.q { padding: 8px 0 20px; border-bottom: 1px solid var(--line); }
.q:last-child { border-bottom: 0; }
.q h3 { font-family: var(--display); font-weight: 600; font-size: 1.2rem; margin: 10px 0 4px; display: flex; gap: 10px; align-items: baseline; }
.qn { display: inline-flex; min-width: 1.7em; height: 1.7em; align-items: center; justify-content: center; background: var(--red); color: var(--red-ink); font-size: 0.9rem; flex: none; }
.scen { margin: 0 0 8px; max-width: 78ch; font-weight: 500; }
.qnote { margin: 0 0 8px; font-size: 0.93rem; color: var(--muted); max-width: 78ch; }

/* ---------- the schedule ---------- */
.twrap { container-type: inline-size; max-width: 100%; margin: 4px 0 0; }
.sched { border-collapse: collapse; width: auto; max-width: 100%; background: var(--paper); font-size: 0.97rem; border-top: 2px solid var(--teal); border-bottom: 2px solid var(--teal); }
.sched th, .sched td { padding: 3px 6px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: middle; }
.sched td + td, .sched th + td, .sched thead th + th { border-left: 1px solid var(--line); }
.sched thead th { background: var(--head); color: var(--head-ink); font-weight: 600; font-size: 0.86rem; line-height: 1.25; vertical-align: bottom; padding: 6px; min-width: 4.2em; }
.sched th.rk { text-align: center; font-weight: 700; width: 4.6em; }
.sched thead th.rk { text-align: center; }
.rkl { display: none; }
.sched td.g { color: var(--given); font-weight: 600; white-space: nowrap; padding-right: 10px; }
.sched td.u { color: var(--undef); text-align: center; }
.sched td.a { padding: 2px; }
.sched td.k { white-space: nowrap; padding-right: 10px; }
.sched td.b { height: 28px; }
.cell { width: 5.6em; min-width: 3.6em; min-height: 44px; padding: 4px 6px; text-align: right; font-size: 16px; border: 1px solid var(--line); border-bottom: 2px solid var(--teal); background: var(--wash); font-variant-numeric: tabular-nums; }
.cell.ask { width: 8em; }
.pick { min-height: 44px; max-width: 100%; border: 1px solid var(--line); border-bottom: 2px solid var(--teal); background: var(--wash); }
.cell:focus, .pick:focus { background: var(--paper); outline: 2px solid var(--focus); outline-offset: 0; }
.cell.is-right, .pick.is-right { border-color: var(--ok); background: var(--ok-soft); }
.cell.is-wrong, .cell.is-unread, .pick.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.cell.is-close { border-color: var(--close); background: var(--close-soft); }
/* narrow boxes: each row becomes a block of labelled cells, so a table never scrolls sideways (the widths are what
   the row key plus one 5.6em box per column needs) */
@container (max-width: 760px) {
  .q .sched-8 { border-top: 0; }
  .q .sched-8 thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .q .sched-8, .q .sched-8 tbody { display: block; }
  .q .sched-8 tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.6rem, 1fr)); gap: 0 12px; padding: 6px 0 8px; border-top: 2px solid var(--teal); }
  .q .sched-8 th.rk { grid-column: 1 / -1; width: auto; text-align: left; border: 0; padding: 2px 0 4px; font-family: var(--display); font-size: 1.02rem; }
  .q .sched-8 .rkl { display: inline; }
  .q .sched-8 td { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 0; border-bottom: 1px dotted var(--line); padding: 2px 0; min-height: 36px; }
  .q .sched-8 td::before { content: attr(data-l); font-size: 0.88rem; font-weight: 600; color: var(--head-ink); text-align: left; }
  .q .sched-8 td.a .cell { width: 6.4em; flex: none; }
}
@container (max-width: 670px) {
  .q .sched-7 { border-top: 0; }
  .q .sched-7 thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .q .sched-7, .q .sched-7 tbody { display: block; }
  .q .sched-7 tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.6rem, 1fr)); gap: 0 12px; padding: 6px 0 8px; border-top: 2px solid var(--teal); }
  .q .sched-7 th.rk { grid-column: 1 / -1; width: auto; text-align: left; border: 0; padding: 2px 0 4px; font-family: var(--display); font-size: 1.02rem; }
  .q .sched-7 .rkl { display: inline; }
  .q .sched-7 td { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 0; border-bottom: 1px dotted var(--line); padding: 2px 0; min-height: 36px; }
  .q .sched-7 td::before { content: attr(data-l); font-size: 0.88rem; font-weight: 600; color: var(--head-ink); text-align: left; }
  .q .sched-7 td.a .cell { width: 6.4em; flex: none; }
}
@container (max-width: 570px) {
  .q .sched-6 { border-top: 0; }
  .q .sched-6 thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .q .sched-6, .q .sched-6 tbody { display: block; }
  .q .sched-6 tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.6rem, 1fr)); gap: 0 12px; padding: 6px 0 8px; border-top: 2px solid var(--teal); }
  .q .sched-6 th.rk { grid-column: 1 / -1; width: auto; text-align: left; border: 0; padding: 2px 0 4px; font-family: var(--display); font-size: 1.02rem; }
  .q .sched-6 .rkl { display: inline; }
  .q .sched-6 td { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 0; border-bottom: 1px dotted var(--line); padding: 2px 0; min-height: 36px; }
  .q .sched-6 td::before { content: attr(data-l); font-size: 0.88rem; font-weight: 600; color: var(--head-ink); text-align: left; }
  .q .sched-6 td.a .cell { width: 6.4em; flex: none; }
}
@container (max-width: 470px) {
  .q .sched-5 { border-top: 0; }
  .q .sched-5 thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .q .sched-5, .q .sched-5 tbody { display: block; }
  .q .sched-5 tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.6rem, 1fr)); gap: 0 12px; padding: 6px 0 8px; border-top: 2px solid var(--teal); }
  .q .sched-5 th.rk { grid-column: 1 / -1; width: auto; text-align: left; border: 0; padding: 2px 0 4px; font-family: var(--display); font-size: 1.02rem; }
  .q .sched-5 .rkl { display: inline; }
  .q .sched-5 td { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 0; border-bottom: 1px dotted var(--line); padding: 2px 0; min-height: 36px; }
  .q .sched-5 td::before { content: attr(data-l); font-size: 0.88rem; font-weight: 600; color: var(--head-ink); text-align: left; }
  .q .sched-5 td.a .cell { width: 6.4em; flex: none; }
}
@container (max-width: 420px) {
  .q .sched-4 { width: 100%; }
  .q .sched-4 .cell { width: 100%; min-width: 0; }
  .q .sched-4 thead th { min-width: 0; }
  .sched th.rk { width: 3.4em; }
}

/* ---------- questions under the table ---------- */
.asks { margin-top: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; max-width: 640px; }
.arow { margin: 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; padding: 4px 0; border-bottom: 1px dotted var(--line); }
.arow label, .arow .alab { font-size: 0.97rem; flex: 1 1 14em; }
.aval { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; }
.aval .pick { min-width: 0; }
.wline { display: inline-block; width: 34mm; border-bottom: 1px solid #000; height: 1.3em; }

/* ---------- feedback, key ---------- */
.fbwrap { margin-top: 8px; }
.fb { margin: 4px 0; padding: 6px 10px; font-size: 1rem; border: 1px solid var(--line); background: var(--wash); max-width: 80ch; }
.fb.right { border-color: var(--ok); background: var(--ok-soft); }
.fb.wrong, .fb.unread { border-color: var(--bad); background: var(--bad-soft); }
.fb.close { border-color: var(--close); background: var(--close-soft); }
.qfoot { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.work { margin-top: 6px; }
.keyfig { margin-top: 4px; }
.kv { font-variant-numeric: tabular-nums; }
.lead, .steps { margin: 10px 0 0; padding-left: 20px; font-size: 0.95rem; max-width: 86ch; }
.lead li, .steps li { margin: 4px 0; }
.steps { list-style: none; padding-left: 0; font-variant-numeric: tabular-nums; }
.steps li { padding-left: 10px; border-left: 2px solid var(--line); }

/* ---------- share, recent ---------- */
.sheet-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 12px; }
.confirm { margin: 0; flex-basis: 100%; padding: 10px 12px; background: var(--bad-soft); border: 1px solid var(--bad); }
.share { margin: 16px 0 6px; }
.print-row { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
.print-row label { display: inline-flex; align-items: center; gap: 8px; }
.share-out label { display: grid; gap: 4px; font-size: 0.95rem; }
.share-out input { width: 100%; min-height: 44px; padding: 6px 8px; }
.recent ul { list-style: none; padding: 0; margin: 4px 0; }
.recent li { display: flex; justify-content: space-between; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); padding: 4px 0; }
.recent small { display: block; color: var(--muted); }
.hint { font-size: 0.9rem; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 16px; transform: translate(-50%, 140%); background: var(--ink); color: var(--bg); padding: 10px 16px; max-width: min(92vw, 520px); font-size: 0.95rem; transition: transform 0.2s; z-index: 20; pointer-events: none; }
.toast.on { transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* ---------- content and footer ---------- */
.content { max-width: 75ch; padding: 20px 0 10px; }
.content h2 { font-family: var(--display); font-weight: 600; font-size: 1.4rem; margin: 26px 0 6px; }
.faq details { border-bottom: 1px solid var(--line); }
.faq details p { margin: 0 0 12px; }
.sources { font-size: 0.92rem; color: var(--muted); margin-top: 22px; }
footer { border-top: 2px solid var(--teal); margin-top: 20px; padding: 14px 0 26px; font-size: 0.92rem; color: var(--muted); }
.indep { margin: 0 0 8px; }
.sb-footer p { margin: 6px 0; }
.sb-more { line-height: 1.9; }
.sb-more a, .sb-credit a { color: var(--link); }

/* ---------- phones ---------- */
@media (max-width: 560px) {
  body { font-size: 16px; }
  .sheet { padding: 10px 10px 14px; margin: 0 -8px; border-left: 0; border-right: 0; }
  .seg { display: grid; grid-template-columns: 1fr 1fr; }
  .sg span { width: 100%; justify-content: center; padding: 6px 6px; font-size: 0.92rem; }
  .setrow { display: grid; grid-template-columns: 1fr auto; }
  .setrow .btn { grid-column: 1 / -1; }
  .task-f select { min-width: 0; width: 100%; }
  .score { margin-left: 0; flex-basis: 100%; }
  .sched { font-size: 0.92rem; }
  .sched thead th { font-size: 0.8rem; padding: 4px 3px; }
  .arow label, .arow .alab { flex-basis: 100%; }
  .aval { margin-left: auto; }
}

/* read by screen readers only */
.vh { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- print ---------- */
.print-root { display: none; }
@page { margin: 13mm 12mm; }
@media print {
  body { background: #fff; color: #000; font: 10.5pt/1.4 var(--sans); }
  main, footer, .skip, .toast { display: none !important; }
  .print-root { display: block; }
  :root { --paper: #fff; --ink: #000; --muted: #333; --line: #888; --head: #fff; --head-ink: #000; --teal: #000; --given: #000; --undef: #000; --wash: #fff; }
  .pt { width: 100%; border-collapse: collapse; }
  .pt > thead td.prun { font-size: 8pt; color: #444; padding-bottom: 4px; text-align: right; }
  .psheet, .pkey { break-after: page; }
  .pkey:last-child { break-after: auto; }
  .ph { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid #000; margin-bottom: 4px; }
  .ph h2 { font-family: var(--display); font-size: 15pt; margin: 0; }
  .ph p { margin: 0; font-size: 9.5pt; }
  .pmeta { display: flex; justify-content: space-between; margin: 6px 0; font-size: 10pt; }
  .plabel { font-size: 9pt; margin: 0 0 6px; }
  .pq, .pk { list-style: none; padding: 0; margin: 0; }
  .pq > li, .pk > li { padding: 6px 0 12px; border-bottom: 0.6pt solid #999; break-inside: avoid; }
  .pq > li:last-child, .pk > li:last-child { border-bottom: 0; }
  .pq h3, .pk h3 { font-family: var(--display); font-size: 11.5pt; margin: 2px 0 2px; }
  .pscen { margin: 0 0 3px; }
  .qnote { font-size: 9pt; color: #000; margin: 0 0 3px; }
  .twrap { container-type: normal; }
  .sched { width: 100%; max-width: none; font-size: 9.5pt; border-top: 1.2pt solid #000; border-bottom: 1.2pt solid #000; table-layout: fixed; }
  .sched th, .sched td { padding: 1.5pt 4pt; border-bottom: 0.5pt solid #777; color: #000; }
  .sched td + td, .sched th + td, .sched thead th + th { border-left: 0.5pt solid #777; }
  .sched thead th { background: #fff; color: #000; border-bottom: 1pt solid #000; font-size: 8.5pt; padding: 2pt 3pt; }
  .sched th.rk { width: 15mm; }
  .sched td.b { height: 17pt; }
  .sched tbody tr { break-inside: avoid; }
  .asks { display: block; margin-top: 6px; max-width: none; }
  .arow { border-bottom: 0; padding: 3pt 0; justify-content: flex-start; }
  .arow .alab { flex: 0 1 auto; min-width: 72mm; font-size: 10pt; }
  .arow .kv { font-size: 10pt; }
  .pk > li { break-inside: auto; }
  .pk h3 { break-after: avoid; }
  .pk .kblock, .pk .lead li, .pk .steps li, .pq .asks { break-inside: avoid; }
  .pkwork { break-inside: avoid; }
  .pkwh { margin: 6pt 0 0; font-size: 9.5pt; font-weight: 700; }
  .pchoice { font-size: 9pt; }
  .lead { font-size: 9pt; margin-top: 4px; padding-left: 14px; }
  .steps { font-size: 9pt; margin-top: 4px; }
  .steps li { margin: 1pt 0; border-left: 0; padding-left: 0; }
  .steps .wl { white-space: nowrap; }
}
