/* ============================================================================
   Mathster — the working pad: toolbar, paper, ink, text blocks, equations, shapes.
   Shared by the homework page and the class game (the pupil explaining, and the board showing their working).
   Moved here unchanged from homework.blade.php (13 Oct 2026). Uses the student design tokens (--surface, --ink, …).
   ========================================================================== */
.wsbody{flex:1;min-height:0;position:relative}
.wspane{position:absolute;inset:0;display:none;flex-direction:column}
.wspane.active{display:flex}
.notewrap{position:relative;flex:1;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-width:none}
.notewrap::-webkit-scrollbar{width:0;height:0}
/* The paper is larger than the pane in both directions, so working can carry on
   past the edges; the hand tool drags the view rather than relying on bars.
   Its pixel size is set by the zoom level, so the document itself always keeps
   one fixed coordinate system in paper units. */
.padsheet{position:relative}
.zoomseg{display:flex;align-items:center;gap:2px;background:var(--surface-sunk);border-radius:8px;padding:2px}
.zoomseg button{width:22px;height:22px;border:0;background:transparent;border-radius:6px;font-size:15px;font-weight:700;
  color:var(--ink-2);cursor:pointer;line-height:1}
.zoomseg button:hover{background:var(--surface);color:var(--ink)}
.zoomseg span{min-width:34px;text-align:center;font-size:11px;font-weight:700;color:var(--ink-2);cursor:pointer}
.notewrap[data-tool="hand"] .inklayer{cursor:grab}
.notewrap[data-tool="hand"] .inklayer.grabbing{cursor:grabbing}
/* One combined surface: typed notes, freehand ink and draggable equations all
   live in the same stack, so a pupil can write a line and sketch beside it
   without switching workspace. Mode only decides which layer takes the pointer. */
.inklayer{position:absolute;inset:0;width:100%;height:100%;background:transparent;pointer-events:none;touch-action:auto}
.notewrap[data-mode="draw"] .inklayer{pointer-events:auto;cursor:crosshair;touch-action:none}
/* Hand tool overrides the crosshair, and re-enables touch panning. */
.notewrap[data-mode="draw"][data-tool="hand"] .inklayer{cursor:grab;touch-action:none}
.notewrap[data-mode="draw"][data-tool="hand"] .inklayer.grabbing{cursor:grabbing}
.notewrap[data-mode="draw"] .padnote{pointer-events:none}
.modeseg{display:flex;gap:2px;background:var(--surface-sunk);border-radius:999px;padding:2px}
.modeseg button{height:24px;padding:0 10px;border:0;background:transparent;border-radius:999px;font-size:11.5px;font-weight:700;color:var(--ink-2);cursor:pointer}
.modeseg button[aria-pressed="true"]{background:var(--surface);color:var(--ink);box-shadow:0 1px 2px rgba(11,14,26,.1)}
/* The paper itself is drawn on the canvas; this layer only catches clicks. */
.padnote{position:absolute;inset:0;padding:16px 18px;font-family:inherit;font-size:14.5px;color:var(--ink);outline:none}
.notewrap[data-empty="1"] .padnote::before{content:"Click anywhere to start writing…";color:var(--ink-3)}
/* Free-placed text: maths working is not a single column — a substitution may
   belong beside a diagram. Text blocks are the same draggable objects as
   equations, so both move the same way. */
.mitem.mtext{padding:1px 4px 1px 2px;background:transparent;border-color:transparent;box-shadow:none}
/* Only outline a text block while it is being used, so the ruled paper reads
   through finished working instead of sitting behind opaque cards. */
.mitem.mtext:hover,.mitem.mtext:focus-within,.mitem.mtext.dragging{background:rgba(255,255,255,.72);border-color:var(--border-2)}
.mitem.mtext.selected{border-color:var(--info);box-shadow:0 0 0 2px rgba(59,130,246,.18)}
/* A vertex label is a single letter, set like maths rather than prose. */
.mitem.mlabel .mbody{font-weight:700;font-style:italic;font-size:15px;min-width:12px;text-align:center}
.mitem.mlabel .mbody:empty::before{content:"?";color:var(--ink-3);font-style:normal}
.mitem.mmath{background:rgba(255,255,255,.82);border-color:var(--border-2)}
.mtext .mbody{min-width:18px;outline:none;font-size:14.5px;line-height:1.5;color:var(--ink);white-space:pre-wrap;
  word-break:break-word;max-width:34ch}
.mtext .mbody:empty::before{content:"…";color:var(--ink-3)}
.mathlayer{position:absolute;top:0;left:0;pointer-events:none;transform-origin:0 0}
.mitem{position:absolute;display:flex;align-items:center;gap:4px;pointer-events:auto;background:#fff;
  border:1px solid var(--border-2);border-radius:8px;padding:2px 4px 2px 2px;box-shadow:0 1px 3px rgba(11,14,26,.12);max-width:92%}
.mitem.dragging{opacity:.8;box-shadow:0 6px 18px rgba(11,14,26,.2)}
.mitem:focus-within{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-dim)}
.mitem math-field{display:inline-block;min-width:64px;font-size:1.08em;padding:0 2px;--caret-color:var(--accent);--primary-color:var(--accent)}
.mgrip{flex:0 0 auto;width:14px;height:24px;border:0;background:transparent;padding:0;color:var(--ink-3);cursor:grab;display:flex;align-items:center;justify-content:center;touch-action:none}
.mtext .mgrip{opacity:0;transition:opacity .15s}
.mtext:hover .mgrip,.mtext:focus-within .mgrip,.mtext.dragging .mgrip{opacity:1}
.mgrip:hover{color:var(--accent-hover)}
.mdel{flex:0 0 auto;width:18px;height:18px;border-radius:50%;border:1px solid var(--border-2);background:#fff;color:var(--ink-3);font-size:10px;line-height:1;cursor:pointer;padding:0;display:none;align-items:center;justify-content:center}
.mitem:hover .mdel,.mitem:focus-within .mdel{display:flex}
.mdel:hover{color:#9B3A2F;border-color:#F3C6C6;background:var(--error-bg)}

/* Diagram chrome. The canvas underneath stays fully drawable — only the two
   controls take pointer events, so a diagram can still be annotated over. */
.figchrome{position:absolute;z-index:12;display:none;pointer-events:none}
.figchrome.show{display:block}
/* The outline encloses the handles, as the text blocks' container does — so the
   whole thing reads as one object rather than an image with bits floating off it. */
.figchrome .fcbox{position:absolute;inset:-10px -44px;border:1px dashed var(--accent);border-radius:10px;opacity:.55}
/* Padding widens the hit area, so the panel is held as soon as the pointer
   approaches a button rather than only once it is exactly on it. */
.figchrome .fcgripwrap,.figchrome .fcdelwrap{position:absolute;pointer-events:auto;padding:10px 8px;cursor:grab}
.figchrome .fcdelwrap{cursor:pointer}
.figchrome button{width:28px;height:28px;border-radius:50%;border:1px solid var(--border-2);background:#fff;
  color:var(--ink-3);font-size:13px;line-height:1;padding:0;display:flex;align-items:center;justify-content:center;
  box-shadow:0 1px 3px rgba(11,14,26,.16);cursor:pointer;touch-action:none}
/* The frame band around the diagram drags it too — a much larger target than
   the handle alone, and it cannot swallow drawing because the middle is clear. */
.figchrome .fcedge{position:absolute;pointer-events:auto;cursor:grab;touch-action:none}
.figchrome .fce-t{left:-44px;right:-44px;top:-10px;height:12px}
.figchrome .fce-b{left:-44px;right:-44px;bottom:-10px;height:12px}
.figchrome .fce-l{top:-10px;bottom:-10px;left:-10px;width:12px}
.figchrome .fce-r{top:-10px;bottom:-10px;right:-10px;width:12px}
/* One resize handle, at the bottom-right corner, drawn as a question card's (.mresize) (Richard, 27 Nov 2026). Its reach
   is wider than it looks (::before), so a finger on a board finds it. */
.figchrome .fchandle{position:absolute;width:14px;height:14px;border-radius:4px;background:#fff;box-sizing:border-box;
  border:2px solid var(--accent);pointer-events:auto;touch-action:none;cursor:nwse-resize}
.figchrome .fchandle::before{content:"";position:absolute;inset:-10px}
.figchrome .fcrot{position:absolute;width:28px;height:28px;
  border-radius:50%;background:var(--accent);border:2px solid #fff;color:#fff;
  display:flex;align-items:center;justify-content:center;font-size:14px;line-height:1;padding:0;
  pointer-events:auto;touch-action:none;cursor:grab;box-shadow:0 1px 4px rgba(11,14,26,.35)}
.figchrome .fcrot:hover{background:var(--accent-hover)}

.figchrome .fcgrip{cursor:grab}
.figchrome .fcgrip:hover{color:var(--accent-hover);border-color:var(--accent)}
.figchrome .fcdel:hover{color:#9B3A2F;border-color:#F3C6C6;background:var(--error-bg)}

/* USE TEMPLATE on the board (27 Nov 2026, mathster-pad.js): a D1 template picture's button, the template in use over
   its picture, and the bar with Finish, pinned to the top-right corner of the visible paper. */
.figchrome .fcusewrap{position:absolute;pointer-events:auto;z-index:3}
.figchrome .fcusewrap .fcuse{width:auto;height:auto;min-height:38px;display:inline-flex;align-items:center;gap:8px;
  padding:8px 18px 8px 14px;border-radius:9px;border:2px solid #fff;background:#1f75a8;color:#fff;
  font:700 15px system-ui,-apple-system,'Segoe UI',Roboto,Arial,sans-serif;line-height:1.2;white-space:nowrap;
  box-shadow:0 2px 10px rgba(11,14,26,.32);cursor:pointer}
.figchrome .fcusewrap .fcuse:hover{background:#185f8a}
.d1live{position:absolute;z-index:6;transform-origin:50% 50%;pointer-events:auto}
.d1live-box{overflow:hidden;background:#fff;outline:2px solid #1f75a8;outline-offset:3px}
.d1live-host{transform-origin:0 0}
.d1live .d1t{user-select:none;-webkit-user-select:none}
.d1live input,.d1live textarea{user-select:text;-webkit-user-select:text}
.d1live-bar{position:fixed;z-index:60;display:flex;gap:10px;align-items:center;white-space:nowrap;
  font:600 14px system-ui,-apple-system,'Segoe UI',Roboto,Arial,sans-serif;color:#1f2937;background:#fff;
  border:2px solid #1f75a8;border-radius:10px;padding:6px 6px 6px 14px;box-shadow:0 4px 16px rgba(11,14,26,.22)}
.d1live-bar button{font:700 15px system-ui,-apple-system,'Segoe UI',Roboto,Arial,sans-serif;padding:8px 18px;
  border-radius:8px;border:1px solid #1b5d84;background:#1f75a8;color:#fff;cursor:pointer;white-space:nowrap}
.d1live-bar button:hover{background:#185f8a}

.eqmodal-scrim{position:fixed;inset:0;background:rgba(11,14,26,.45);z-index:70;display:none;align-items:center;justify-content:center;padding:20px}
.eqmodal-scrim.show{display:flex}
.eqmodal{width:460px;max-width:100%;background:var(--surface);border-radius:var(--r-xl);padding:24px;box-shadow:var(--shadow-pop)}
.eqmodal h3{margin:0 0 4px}
.eqmodal p{font-size:12.5px;color:var(--ink-3);margin:0 0 14px}
.eqfield{width:100%;min-height:52px;border:1px solid var(--border-2);border-radius:var(--r-md);padding:10px 12px;font-size:20px;--caret-color:var(--accent);--primary-color:var(--accent)}
.eqsyms{display:flex;gap:6px;flex-wrap:wrap;margin-top:12px}
.eqsyms button{height:34px;padding:0 12px;border:1px solid var(--border-2);background:var(--surface-sunk);border-radius:8px;font-size:14px;cursor:pointer;color:var(--ink)}
.eqsyms button:hover{border-color:var(--accent)}
.eqactions{display:flex;gap:10px;margin-top:18px;justify-content:flex-end}
.drawtools{display:flex;gap:6px;padding:6px 10px;border-top:1px solid var(--border);flex-wrap:wrap;align-items:center;row-gap:5px}
.drawtools + .notewrap{border-top:1px solid var(--border)}
/* Draw toolbar: only relevant while the ink layer has the pointer. */
.wspane[data-mode="type"] .drawtools .drawonly{display:none}
.toolseg,.iconseg{display:flex;flex-wrap:wrap;gap:2px;background:var(--surface-sunk);border-radius:8px;padding:2px}
.iconseg > button{width:26px;height:26px;border:0;background:transparent;border-radius:6px;cursor:pointer;color:var(--ink-2);
  display:inline-flex;align-items:center;justify-content:center;padding:0}
.iconseg > button:hover{background:var(--surface);color:var(--ink)}
.iconseg > button svg{width:14px;height:14px}
.iconseg > button[aria-pressed="true"]{background:var(--accent-dim);color:var(--accent-hover)}
.iconseg > button[hidden]{display:none}
/* One chip showing the current ink, opening a small picker — four loose
   swatches were four more things competing for attention in the row. */
.inkpick{position:relative}
.inkpick > button{width:26px;height:26px;border:1px solid var(--border-2);background:var(--surface);border-radius:7px;
  cursor:pointer;display:inline-flex;align-items:center;justify-content:center;padding:0}
.inkpick > button i{width:13px;height:13px;border-radius:999px;background:#0B0E1A;display:block}
.inkpop{position:absolute;top:calc(100% + 6px);right:0;z-index:70;display:none;gap:4px;
  background:var(--surface);border:1px solid var(--border-2);border-radius:10px;padding:5px;box-shadow:var(--shadow-pop)}
.inkpop.show{display:flex;flex-direction:column;min-width:132px}
.inkpop.flipleft{right:auto;left:0}
.inkrow{display:flex;gap:4px}
/* The highlighter's own colours, under the pen's (Richard, 4 Nov 2026). */
.inkpop .inklab{font-size:11px;font-weight:600;color:var(--ink-2);margin-top:4px}
.inkpop button{width:22px;height:22px;border-radius:999px;border:2px solid transparent;cursor:pointer;padding:0}
.inkpop button[aria-pressed="true"]{border-color:var(--ink)}
.inkpop .inksize{display:flex;align-items:center;gap:7px;font-size:11px;font-weight:600;
  color:var(--ink-3);padding:4px 2px 1px;margin-top:5px;border-top:1px solid var(--border)}
.inkpop .inksize input[type="range"]{width:70px}
.toolseg button{width:26px;height:26px;border:0;background:transparent;border-radius:6px;cursor:pointer;color:var(--ink-2);
  display:inline-flex;align-items:center;justify-content:center}
.toolseg button[aria-pressed="true"]{background:var(--surface);color:var(--ink);box-shadow:0 1px 2px rgba(11,14,26,.1)}
.toolseg button svg{width:15px;height:15px}
.swatches{display:flex;gap:4px}
.swatches button{width:20px;height:20px;border-radius:999px;border:2px solid transparent;cursor:pointer;padding:0}
.swatches button[aria-pressed="true"]{border-color:var(--ink);box-shadow:0 0 0 2px #fff inset}

/* A copied question sits on the paper as a quoted card, clearly not the
   pupil's own writing. */
.mitem.mqref{max-width:min(420px,88%)}
.mitem.mqref .qref{font-size:14px;line-height:1.6;color:var(--ink);background:var(--surface-sunk);
  border:1px solid var(--border-2);border-left:3px solid var(--accent);border-radius:8px;padding:9px 12px;cursor:default;user-select:text}
.mitem.mqref .qref svg{vertical-align:-0.1em}
/* The question's HTML is laid out as on any web page (Richard, 18 Oct 2026): the line breaks in its source are not
   extra blank lines (the pad's own text blocks keep theirs, pre-wrap), and a word only breaks if it cannot fit. */
.mitem.mqref .qref{white-space:normal;word-break:normal;overflow-wrap:break-word}
/* A table in a question card stays inside the card (Richard, 18 Oct 2026). The old pages' fixed sizes (width="460",
   50px cells, a 40px indent) are dropped, a cell's number stays on one line ("0.24", not "0.2" over "4"), and the card
   widens to the table rather than the table running out of it. The text keeps the card's usual width when the table
   is narrower. */
.mitem.mqref .qref table{width:auto !important;margin:8px 0 !important;border-collapse:collapse}
.mitem.mqref .qref th,.mitem.mqref .qref td{width:auto !important;height:auto !important;white-space:nowrap;
  padding:3px 9px;font-size:inherit}
/* The site's own data tables (th,td in mathster-student.css: 13.5px, a rule under each row) are not the question's:
   its text is the card's size, and a table drawn without borders gets none (Richard, 18 Oct 2026). */
.mitem.mqref .qref table:not([border]) :is(th,td),.mitem.mqref .qref table[border="0"] :is(th,td){border-bottom:0}
/* The same for a picture wider than the card, such as a graph of eight triangles (18 Oct 2026). */
.mitem.mqref:has(table,svg,img){max-width:none}
/* The card is in .mtext, so the text blocks' 34ch cap (.mtext .mbody) held it at about 300px and a table or picture ran out
   of it; a card with a table, picture or pad drawing is not capped (4 Nov 2026). */
.mitem.mqref .qref:has(table,svg,img){width:min-content;min-width:min(320px,80vw);max-width:none}
/* Writing on a question card (Richard, 4 Nov 2026). With the pen, a card lets the stroke through to the paper beneath; its
   move handle and its ✕ still take the pointer, and are always shown, as the card no longer knows it is hovered (or, on a
   tablet, tapped). The layer of cards and text is multiplied over the paper, so ink under a card, and in a pad drawing's
   empty boxes, shows through, with the question's own text on top. */
.notewrap[data-mode="draw"] .mitem.mqref{pointer-events:none}
.notewrap[data-mode="draw"] .mitem.mqref .mgrip,.notewrap[data-mode="draw"] .mitem.mqref .mdel{pointer-events:auto}
.notewrap[data-mode="draw"] .mitem.mqref .mgrip{opacity:1}
.notewrap[data-mode="draw"] .mitem.mqref .mdel{display:flex}
/* A question card's resize handle, at its bottom-right corner (Richard, 4 Nov 2026): shown when the card is hovered, and
   always while drawing (as the move handle and ✕ are). */
.mitem .mresize{position:absolute;right:-7px;bottom:-7px;width:14px;height:14px;border-radius:4px;background:#fff;
  border:2px solid var(--accent);cursor:nwse-resize;touch-action:none;pointer-events:auto;display:none;box-sizing:border-box}
.mitem.mqref:hover .mresize,.notewrap[data-mode="draw"] .mitem.mqref .mresize{display:block}
.notewrap[data-mode="view"] .mitem .mresize{display:none}
.mathlayer{mix-blend-mode:multiply}
.padmenu{position:relative}
.padmenubtn{display:flex;align-items:center;gap:4px;height:26px;padding:0 8px;border:1px solid var(--border-2);
  background:var(--surface);border-radius:7px;font-size:11.5px;font-weight:600;color:var(--ink-2);cursor:pointer;font-family:inherit;white-space:nowrap}
.padmenubtn:hover{border-color:var(--accent);color:var(--accent-hover)}
.padmenubtn[aria-expanded="true"]{border-color:var(--accent);background:var(--accent-dim);color:var(--accent-hover)}
/* Opens downwards: this toolbar sits above the paper. */
.padpop{position:absolute;left:0;top:calc(100% + 6px);z-index:70;min-width:196px;background:var(--surface);
  border:1px solid var(--border-2);border-radius:var(--r-lg);box-shadow:var(--shadow-pop);padding:6px;display:none}
.padmenu.open .padpop{display:block}
.padpop h4{margin:6px 8px 3px;font-size:10px;font-weight:800;letter-spacing:.08em;
  text-transform:uppercase;color:var(--ink-3)}
.padpop h4:first-child{margin-top:2px}
.padpop.flipright{left:auto;right:0}
.padpop.flipup{top:auto;bottom:calc(100% + 6px)}
button.padrow{display:flex;align-items:center;gap:10px;width:100%;height:34px;padding:0 9px;border:0;background:transparent;
  border-radius:8px;font-size:13px;font-weight:500;color:var(--ink);cursor:pointer;font-family:inherit;text-align:left}
button.padrow svg{width:17px;height:17px;flex:0 0 auto;color:var(--ink-2)}
button.padrow span{flex:1}
button.padrow:hover{background:var(--accent-dim);color:var(--accent-hover)}
button.padrow:hover svg{color:var(--accent-hover)}
button.padrow[aria-pressed="true"]{background:var(--accent-dim);color:var(--accent-hover);font-weight:700}
button.padrow[aria-pressed="true"] svg{color:var(--accent-hover)}
.polyhint{font-size:11px;color:var(--ink-3)}
.measure{font-size:11.5px;color:var(--ink-2);background:var(--surface-sunk);border-radius:8px;padding:5px 10px;display:none}
.measure.show{display:block}
.measure b{color:var(--ink)}
/* "about" values come from a freehand shape, so they are marked as estimates. */
.measure.est{color:var(--ink-3)}
/* Direct children only — Clear ink / Undo. Scoping this stops it reaching into
   .toolseg / .swatches, whose buttons are grandchildren and style themselves. */
.drawtools > button{height:32px;padding:0 12px;border:1px solid var(--border-2);background:var(--surface);border-radius:8px;font-size:12px;font-weight:600;color:var(--ink-2);cursor:pointer}
.drawtools > button[aria-pressed="true"]{border-color:var(--accent);background:var(--accent-dim);color:var(--accent-hover)}

/* ---------- Phone: the pad has to earn its space ---------- */
@media (max-width:640px){
  /* One row that scrolls sideways, rather than four rows of wrapped controls
     eating the paper. Every tool stays reachable — nothing is hidden away. */
  .drawtools{flex-wrap:nowrap;overflow-x:auto;overscroll-behavior-x:contain;
    scrollbar-width:none;padding:6px 8px}
  .drawtools::-webkit-scrollbar{height:0}
  .drawtools > *{flex:0 0 auto}
  /* Pinch and double-tap do the zooming on a phone, so the buttons go. */
  .zoomseg{display:none}
  /* The running caption and the measurement readout give way; the Draw/Type
     toggle stays, since it is the only way to reach either surface. */
  .drawtools > span[style]{display:none}
  .measure{display:none}
  /* Menus and popups anchor to the pad, not to a button that may have
     scrolled out of the row. */
  .padpop{position:fixed;left:8px;right:8px;top:auto;bottom:8px;min-width:0;
    max-height:52vh;overflow-y:auto}
  .padpop.flipright,.padpop.flipup{left:8px;right:8px;top:auto;bottom:8px}
  .inkpop{position:fixed;left:8px;right:8px;top:auto;bottom:8px}
  .inkpop.flipleft{left:8px;right:8px}
  body[data-kb="open"] .padpop,
  body[data-kb="open"] .padpop.flipright,
  body[data-kb="open"] .padpop.flipup{bottom:calc(44vh + 8px);max-height:40vh}
  body[data-kb="open"] .inkpop,
  body[data-kb="open"] .inkpop.flipleft{bottom:calc(44vh + 8px)}
}

/* ---------- Touch: 40px+ targets on a finger-driven screen ---------- */
@media (pointer:coarse){
  .toolseg button,.iconseg > button,.inkpick > button{width:40px;height:40px}
  .toolseg button svg,.iconseg > button svg{width:19px;height:19px}
  .inkpick > button i{width:17px;height:17px}
  .padmenubtn{height:40px;padding:0 12px;font-size:13px}
  .zoomseg button{width:36px;height:36px;font-size:18px}
  .zoomseg span{min-width:44px;font-size:12.5px}
  .modeseg button{height:38px;padding:0 16px;font-size:13px}
  .drawtools{gap:8px;padding:8px 10px;row-gap:8px}
  /* The diagram's handles are hover-revealed on a mouse; on a finger there is
     no hover, so they need to be big enough to hit first time. */
  .figchrome button{width:40px;height:40px;font-size:16px}
  .padrow{height:44px;font-size:14px}
}

/* A graph drawn into a question card (the class game's): its own line, at the size the engine draws it. */
.mitem.mqref .qref svg[id^="ASnewid"]{display:block;margin-top:6px}
.mitem.mqref .qref:has(svg[id^="ASnewid"]){min-width:326px}
