/* First Slip - a squared exercise book on a desk, with a red pen. */
:root {
  --bg: #f1eee6; --paper: #fffdf7; --grid: #d3e0ec; --margin: #e6a29d; --ink: #1c2333; --muted: #586174; --pencil: #6b7382;
  --red: #b8281b; --red-soft: #fbe4df; --line: #dad4c4; --chip: #e9e3d3; --accent: #27527d; --accent-ink: #ffffff;
  --good: #23704a; --good-bg: #dff1e6; --warn: #9a4a06; --warn-bg: #fcecd9; --info-bg: #e6eef7; --info: #27527d;
  --sticky: #fff0a3; --sticky-ink: #3a3206; --stamp: #b3261e; --shadow: 0 1px 2px rgba(28,35,51,.08), 0 4px 14px rgba(28,35,51,.06);
  --hand: "Segoe Print", "Bradley Hand", "Chalkboard SE", "Comic Sans MS", cursive;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #11141a; --paper: #191e27; --grid: #263041; --margin: #713a37; --ink: #e7ebf2; --muted: #a6afbe; --pencil: #9ba5b5;
  --red: #ff8b7b; --red-soft: #3a201d; --line: #2d3544; --chip: #232a36; --accent: #93bbe9; --accent-ink: #0e1520;
  --good: #82d7a6; --good-bg: #173326; --warn: #ffb870; --warn-bg: #3a2814; --info-bg: #1c2a3c; --info: #a9c8ee;
  --sticky: #3a3417; --sticky-ink: #f6ecb2; --stamp: #ff8b7b; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
a { color: var(--accent); }
.hidden { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.small { font-size: .875rem; } .muted { color: var(--muted); } .mono { font-family: var(--mono); }
.note { color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 6px 10px; }
.good { color: var(--good); } .off { color: var(--warn); }

/* Header */
.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--paper); flex-wrap: wrap; }
.back { text-decoration: none; font-size: .9rem; color: var(--muted); }
.brand { display: flex; align-items: center; gap: 8px; font-size: 1.05rem; margin-right: auto; }
.logo { width: 28px; height: 28px; }
.lg-paper { fill: var(--paper); stroke: var(--ink); stroke-width: 1.6; }
.lg-grid { stroke: var(--grid); stroke-width: 1.2; fill: none; }
.lg-tick { stroke: var(--red); stroke-width: 3.2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.session { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pill { font: inherit; font-size: .875rem; border: 1px solid var(--line); background: var(--paper); color: var(--ink); border-radius: 999px; padding: 6px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.pill:hover { border-color: var(--accent); }
.pill.solid { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pill.ghost { cursor: default; background: transparent; }
.pill.big { font-size: 1rem; padding: 10px 20px; font-weight: 600; }
.pill.tiny { font-size: .8rem; padding: 3px 10px; }
.pill:disabled { opacity: .5; cursor: not-allowed; }

/* Layout */
main { max-width: 1180px; margin: 0 auto; padding: 0 16px 40px; }
.hero { padding: 28px 0 8px; max-width: 860px; }
.kicker { font-size: .9rem; color: var(--muted); margin: 0 0 8px; }
.note-src { white-space: nowrap; }
h1 { font-size: clamp(1.6rem, 4.4vw, 2.4rem); line-height: 1.15; margin: 0 0 10px; letter-spacing: -.01em; overflow-wrap: anywhere; }
.lede { font-size: 1.05rem; margin: 0 0 14px; }
.samples { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip { font: inherit; font-size: .875rem; border: 1px dashed var(--line); background: var(--chip); color: var(--ink); border-radius: 8px; padding: 5px 12px; cursor: pointer; }
.chip.on { border-style: solid; border-color: var(--red); box-shadow: inset 0 0 0 1px var(--red); }
.layout { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; margin-top: 16px; align-items: start; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-top: 16px; box-shadow: var(--shadow); min-width: 0; }
.layout .panel { margin-top: 0; }
.ph { font-size: 1.1rem; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.step-no { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--red); color: var(--red); font-size: .85rem; font-weight: 700; flex: none; }
h3 { font-size: 1rem; margin: 18px 0 8px; }
.lbl { display: block; font-size: .85rem; font-weight: 600; margin: 10px 0 4px; }
input[type=text], select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
textarea { resize: vertical; }
#working { font-family: var(--mono); font-size: .95rem; line-height: 1.6; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fmt { margin: 6px 0; }
.drop { border: 1px dashed var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 8px; }
.drop.over { border-color: var(--accent); background: var(--info-bg); }
.filelbl { color: var(--accent); text-decoration: underline; cursor: pointer; }

/* The exercise-book page */
.sheet-host { min-width: 0; }
.page { position: relative; background-color: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px 14px 0; overflow: hidden;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 22px 22px; background-position: -1px -1px; }
.page::before { content: ""; position: absolute; top: 0; bottom: 0; left: 54px; width: 2px; background: var(--margin); }
.page-head { position: relative; padding: 6px 12px 10px 66px; min-height: 44px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.page.marked .page-head { padding-right: 104px; }
.ph-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.ph-problem { font-family: var(--mono); font-weight: 600; overflow-wrap: anywhere; }
.ph-sol { flex-basis: 100%; }
.lines { list-style: none; margin: 0; padding: 0; position: relative; }
.row { display: grid; grid-template-columns: 54px minmax(0, 1fr) auto; gap: 0 12px; align-items: start; min-height: 44px; padding: 8px 0 6px; }
.row.empty { grid-template-columns: 54px 1fr; }
.row.empty .work { grid-column: 2; }
.gutter { display: flex; align-items: center; justify-content: flex-end; gap: 4px; padding-right: 8px; height: 26px; }
.ln { font-family: var(--mono); font-size: .8rem; color: var(--muted); }
.body { min-width: 0; padding-left: 4px; }
.work { font-family: var(--mono); font-size: 1rem; line-height: 26px; display: inline-block; overflow-wrap: anywhere; padding: 0 6px; border: 2px solid transparent; }
.work.is-note { font-family: var(--hand); color: var(--muted); }
.work.circled { border-color: var(--red); border-radius: 48% 52% 50% 46% / 60% 55% 45% 40%; transform: rotate(-1deg); padding: 0 12px; }
.remark { display: block; font-family: var(--hand); color: var(--red); font-size: .95rem; line-height: 1.35; margin: 2px 0 0 6px; }
.pencil { font-size: .8rem; color: var(--pencil); white-space: nowrap; line-height: 26px; padding-right: 4px; max-width: 34ch; overflow: hidden; text-overflow: ellipsis; }
.pencil b { font-family: var(--mono); font-size: .95rem; margin-right: 2px; }
.pc-slip b { color: var(--warn); } .pc-slip { color: var(--warn); }
.pen { display: inline-grid; place-items: center; width: 22px; height: 22px; color: var(--red); font-family: var(--hand); font-size: .78rem; font-style: italic; font-weight: 700; }
.pen svg { width: 22px; height: 22px; }
.pen-stroke { fill: none; stroke: var(--red); stroke-width: 2.8; stroke-linecap: round; stroke-linejoin: round; }
.page-foot { margin: 8px 12px 0 66px; font-family: var(--hand); font-size: .95rem; }
.stamp { position: absolute; top: 8px; right: 10px; width: 88px; height: 88px; border-radius: 50%; border: 3px double var(--stamp); color: var(--stamp);
  display: grid; place-items: center; align-content: center; transform: rotate(-12deg); text-align: center; line-height: 1.05; z-index: 2; background: color-mix(in srgb, var(--paper) 70%, transparent); }
.stamp-top { font-size: .58rem; letter-spacing: .2em; text-transform: uppercase; opacity: .85; }
.stamp-word { font-size: .82rem; font-weight: 900; letter-spacing: .04em; padding: 0 6px; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 0; margin: 10px 0 0; color: var(--muted); }
.pk { font-family: var(--mono); font-weight: 700; margin-right: 4px; }
.pk-slip { color: var(--warn); }

/* Ask + progress */
.runrow { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 10px; }
.gate { margin: 10px 0 0; }
.steps { list-style: none; padding: 0; margin: 0; }
.step { padding: 3px 0; color: var(--muted); } .step.active { color: var(--ink); font-weight: 600; } .step.done { color: var(--good); }
.step-ic { font-family: var(--mono); display: inline-block; width: 1em; }
.raw { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: .8rem; max-height: 320px; overflow: auto; }

/* Result */
.res-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.res-head h2 { margin: 0; font-size: 1.25rem; overflow-wrap: anywhere; }
.badge { display: inline-block; border-radius: 6px; padding: 3px 10px; font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; border: 1px solid currentColor; }
.badge.v-full_marks { color: var(--good); background: var(--good-bg); }
.badge.v-one_slip { color: var(--warn); background: var(--warn-bg); }
.badge.v-rework { color: var(--red); background: var(--red-soft); }
.badge.v-unfinished { color: var(--info); background: var(--info-bg); }
.badge.v-none { color: var(--muted); }
.summary { font-size: 1.05rem; }
.slips { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.slipcard { border: 1px solid var(--line); border-left: 4px solid var(--red); border-radius: 8px; padding: 10px 12px; background: var(--bg); }
.slip-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 4px; }
.slip-ln { font-weight: 700; color: var(--red); }
.slip-work { overflow-wrap: anywhere; }
.sl { margin: 4px 0; display: grid; grid-template-columns: 4.5em 1fr; gap: 8px; }
.sl-k { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding-top: 3px; }
.sl-nudge .sl-v { font-family: var(--hand); color: var(--red); }
.fixbox { margin-top: 12px; }
.fixline { margin-top: 8px; padding: 10px 12px; border-radius: 8px; background: var(--bg); border: 1px dashed var(--red); }
.fixline code { font-size: 1rem; overflow-wrap: anywhere; }
.fixline p { margin: 6px 0 0; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.sticky { background: var(--sticky); color: var(--sticky-ink); padding: 14px 16px; transform: rotate(-1deg); box-shadow: 2px 4px 10px rgba(0,0,0,.15); border-radius: 2px 2px 10px 2px; margin-bottom: 10px; }
.sticky-q { margin: 0; font-family: var(--mono); font-weight: 600; overflow-wrap: anywhere; }
.sticky .muted { color: inherit; opacity: .75; }
.plain, .recon, .hist { list-style: none; padding: 0; margin: 0; }
.plain li, .recon li { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.well li::before { content: "\2713  "; color: var(--good); font-weight: 700; }
.recon li { padding-left: 10px; border-left: 3px solid var(--line); margin-bottom: 4px; border-bottom: 0; }
.recon li.warn { border-left-color: var(--warn); color: var(--warn); }
.recon li.ok { border-left-color: var(--good); }
.recon li.info { border-left-color: var(--accent); }
.none { color: var(--muted); font-style: italic; }
.exports, .cardrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.hrow { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); flex-wrap: wrap; }
.hinfo { flex: 1 1 220px; display: flex; flex-direction: column; min-width: 0; }
.hinfo b { overflow-wrap: anywhere; }

/* Footer, toasts */
.foot { max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--line); }
.toasts { position: fixed; bottom: 16px; right: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; z-index: 20; }
.toast { pointer-events: auto; max-width: 420px; background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: .9rem; transition: opacity .5s; }
.toast.err { background: var(--red); color: #fff; }
:root[data-theme="dark"] .toast.err { color: #1b0d0b; }
.toast a { color: inherit; font-weight: 700; }
.toast.gone { opacity: 0; }

@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } .cols { grid-template-columns: 1fr; } }
@media (max-width: 560px) {
  .two { grid-template-columns: 1fr; }
  .row { grid-template-columns: 40px minmax(0, 1fr); }
  .page::before { left: 40px; }
  .page-head { padding-left: 50px; }
  .page.marked .page-head { padding-right: 76px; }
  .page-foot { margin-left: 50px; }
  .pencil { grid-column: 2; padding-left: 10px; line-height: 20px; max-width: 100%; }
  .gutter { padding-right: 4px; gap: 2px; }
  .pen, .pen svg { width: 18px; height: 18px; }
  .ln { font-size: .72rem; }
  .stamp { width: 68px; height: 68px; top: 6px; right: 6px; }
  .stamp-word { font-size: .66rem; } .stamp-top { font-size: .5rem; }
  .bar { padding: 8px 12px; }
}
@media print {
  .bar, .hero, .inbox, .askbox, .histbox, .aboutbox, .foot, .toasts, .exports, .cardrow, #progressPanel, .legend, #sheetNote, .fixbox button { display: none !important; }
  .layout { display: block; } .panel { box-shadow: none; border: 0; }
  body { background: #fff; }
}
