
/* sticky filter bar: chapter/search/marks stay put, questions scroll */
#tm-sticky{position:sticky;top:56px;z-index:45;background:var(--bg);
  padding:6px 0 8px;margin:0 -4px;padding-left:4px;padding-right:4px;
  border-bottom:1px solid var(--rule)}
#tm-yearchips{display:flex;gap:8px;flex-wrap:wrap;margin-top:8px}
#tm-yearchips:empty{display:none}

/* ── builder ── */
.tm-controls{display:flex;gap:10px;flex-wrap:wrap;margin:14px 0 10px}
#tm-ch{flex:1.2;min-width:230px;font-family:var(--sans);font-size:.92rem;padding:11px 14px;
  border:1.5px solid var(--rule);border-radius:12px;background:#fff}
#tm-search{flex:1;min-width:180px;font-family:var(--sans);font-size:.92rem;padding:11px 14px;
  border:1.5px solid var(--rule);border-radius:12px;background:#fff}
#tm-ch:focus,#tm-search:focus{outline:none;border-color:var(--dark)}
#tm-markchips{display:flex;gap:8px;flex-wrap:wrap}
.tm-chip{font-family:var(--sans);font-size:.78rem;font-weight:600;border:none;
  border-radius:999px;padding:6px 14px;background:var(--band);color:var(--ink-soft);cursor:pointer}
.tm-chip:hover{color:var(--ink)}
.tm-chip.on{background:var(--dark);color:#fff}
.tmcard{background:#fff;border:1px solid var(--rule);border-radius:14px;padding:14px 16px;margin-bottom:10px}
.tmcard.added{border-color:var(--accent);box-shadow:inset 0 0 0 1px var(--accent)}
.tm-qhead{display:flex;justify-content:space-between;align-items:center;gap:8px;margin-bottom:6px}
.tm-add{font-family:var(--sans);font-weight:700;font-size:.8rem;border:1.5px solid var(--accent);
  color:var(--accent);background:#fff;border-radius:999px;padding:6px 16px;cursor:pointer;white-space:nowrap}
.tm-add.on{background:var(--accent);border-color:var(--accent);color:#fff}

/* ── sticky tray ── */
#tm-tray{position:fixed;bottom:0;left:0;right:0;background:var(--dark);color:#fff;z-index:60;
  padding:10px 16px;box-shadow:0 -3px 14px rgba(0,0,0,.18)}
#tm-tray.off{display:none}
.tm-tray-in{max-width:820px;margin:0 auto;display:flex;align-items:center;gap:12px;
  font-family:var(--sans);font-size:.9rem;flex-wrap:wrap}
.tm-tray-in .grow{flex:1}
.tm-btn{font-family:var(--sans);font-weight:700;font-size:.85rem;border:none;border-radius:999px;
  padding:9px 18px;cursor:pointer}
#tm-preview-btn{background:var(--accent);color:#fff}
#tm-clear{background:rgba(255,255,255,.14);color:#fff}
#tm-builder{padding-bottom:80px}

/* ── preview / paper ── */
.tm-actions{display:flex;gap:10px;margin:16px 0;font-family:var(--sans);flex-wrap:wrap}
#tm-print{background:var(--accent);color:#fff}
#tm-print:disabled{background:#9aa5b1;cursor:progress}
#tm-back{background:#fff;color:var(--ink);border:1.5px solid var(--rule)}
/* the paper keeps a serif exam look even though the site is sans */
#tm-paper{background:#fff;border:1px solid var(--rule);border-radius:14px;padding:26px 28px;
  font-family:var(--serif)}
.pv-head{text-align:center;border-bottom:2px solid #000;padding-bottom:8px;margin-bottom:12px}
#pv-school{font-family:var(--sans);font-weight:700;font-size:1.3em;text-transform:uppercase;letter-spacing:.04em}
#pv-title{font-family:var(--sans);font-weight:600;font-size:1em;margin-top:3px}
.pv-meta{display:flex;justify-content:space-between;font-family:var(--sans);font-size:.9em;margin-top:6px}
.tm-density{display:inline-flex;border:1.5px solid var(--rule);border-radius:8px;overflow:hidden;font-family:var(--sans)}
.tm-density button{border:none;background:#fff;padding:9px 14px;font-size:.8rem;font-weight:600;
  color:var(--ink-soft);cursor:pointer;border-right:1px solid var(--rule)}
.tm-density button:last-child{border-right:none}
.tm-density button.on{background:var(--accent);color:#fff}
.pv-q{display:flex;gap:8px;margin-bottom:14px;break-inside:avoid}
.pv-n{font-weight:700;min-width:28px}
.pv-body{flex:1;min-width:0}
.pv-m{font-weight:700;min-width:38px;text-align:right;white-space:nowrap}
#pv-solpage{break-before:page;page-break-before:always;margin-top:28px}
.pv-solh{font-family:var(--sans);font-size:1.1rem;border-bottom:2px solid #000;padding-bottom:6px;margin-bottom:14px}
.pv-s{display:flex;gap:8px;margin-bottom:12px;break-inside:avoid}
.pv-s .pv-m{color:var(--ink-soft);font-weight:600;font-size:.85rem}
[contenteditable]:hover{background:#f0f5fb}
[contenteditable]:focus{outline:2px dashed var(--accent);outline-offset:2px;background:#fff}

/* figures inside the paper: capped, and click-to-resize (S → M → L) */
#tm-paper .fig{margin:5px 0}
#tm-paper .fig img{width:auto;height:auto;max-width:min(60mm,90%);max-height:48mm;
  border:none;padding:0;cursor:pointer}
#tm-paper .fig-s img{max-width:min(38mm,70%);max-height:30mm}
#tm-paper .fig-m img{max-width:min(60mm,90%);max-height:48mm}
#tm-paper .fig-l img{max-width:min(95mm,100%);max-height:78mm}

/* font scale (A− / A+) via --fs multiplier, combined with density classes */
#tm-paper{font-size:calc(1rem * var(--fs,1))}

/* density: compact fits far more per photocopied page */
#tm-paper.compact{font-size:calc(.86rem * var(--fs,1));line-height:1.35}
#tm-paper.compact .pv-q{margin-bottom:5px}
#tm-paper.compact .pv-s{margin-bottom:5px}
#tm-paper.compact .opts{gap:0 12px;margin-top:1px}
#tm-paper.compact .fig-m img{max-width:48mm;max-height:38mm}
#tm-paper.compact .pv-head{padding-bottom:5px;margin-bottom:8px}
#tm-paper.compact .pv-n{min-width:22px}

/* 2-column: maximum questions per page (MCQ-heavy papers) */
#tm-paper.cols2 #pv-questions,#tm-paper.cols2 #pv-solutions{column-count:2;column-gap:8mm;
  column-rule:.5px solid #bbb}
#tm-paper.cols2 .pv-q,#tm-paper.cols2 .pv-s{break-inside:avoid}
#tm-paper.cols2 .opts{grid-template-columns:1fr 1fr}
#tm-paper.cols2 .fig-m img{max-width:100%;max-height:34mm}

/* ── side panel: the paper so far ── */
#tm-side{display:none;position:fixed;left:12px;right:12px;bottom:76px;max-height:52vh;
  overflow:auto;background:#fff;border:1px solid var(--rule);border-radius:12px;
  padding:12px 14px;z-index:75;box-shadow:0 -6px 26px rgba(20,32,46,.28)}
#tm-side.open{display:block}
.tm-side-h{display:flex;align-items:center;gap:8px;font-family:var(--sans);font-weight:700;
  font-size:.85rem;margin-bottom:4px}
.tm-side-h .grow2{flex:1}
#tm-side-close{border:none;background:var(--band);color:var(--ink);font-weight:700;
  border-radius:6px;width:26px;height:26px;cursor:pointer;font-size:.9rem}
@media (min-width:1160px){ #tm-side-close{display:none} }
.tm-side-item{display:flex;gap:7px;align-items:baseline;font-family:var(--sans);
  font-size:.78rem;padding:7px 0;border-top:1px solid var(--rule);line-height:1.35}
.tm-side-item .n{font-weight:700;min-width:22px;color:var(--accent)}
.tm-side-item .tx{flex:1;min-width:0}
.tm-side-item .mk{color:var(--ink-soft);white-space:nowrap}
.tm-side-item .rm{border:none;background:none;color:#b3261e;font-weight:700;
  cursor:pointer;font-size:.9rem;padding:0 2px}
.tm-side-empty{font-family:var(--sans);font-size:.8rem;color:var(--ink-soft)}
@media (min-width:1160px){
  #tm-side{display:block;left:auto;right:14px;bottom:auto;top:74px;width:290px;
    max-height:calc(100vh - 160px);box-shadow:0 4px 18px rgba(20,32,46,.12)}
  #tm-side-btn{display:none}
}
body.previewing #tm-side{display:none!important}

/* ── clickable diagonal watermark (repeats on every printed page) ── */
/* clip the watermark to the paper — the scaled/rotated layer must never
   escape and sit on top of the toolbar buttons */
#tm-paper{position:relative;overflow:hidden}
.pv-head,#pv-questions,#pv-solpage,.pv-source{position:relative;z-index:1}
.pv-wm{position:absolute;inset:0;overflow:hidden;z-index:0;
  pointer-events:none!important;user-select:none;
  display:flex;flex-wrap:wrap;align-content:center;justify-content:center;
  transform:rotate(-30deg) scale(1.45);opacity:.075}
/* screen-only preview: the printed PDF gets its links from the page images,
   so these anchors must never intercept clicks */
.pv-wm a,.pv-wm span{font-family:var(--sans);font-weight:800;font-size:19pt;letter-spacing:.02em;
  color:#47505c;text-decoration:none;margin:30px 34px;white-space:nowrap;
  pointer-events:none!important}
.pv-wm.branded a{color:#111;opacity:.85}
.pv-wm.branded{opacity:.10}

/* source line — printed on every page of the PDF so shared papers credit the site */
.pv-source{margin-top:14px;padding-top:6px;border-top:.5px solid #bbb;
  font-family:var(--sans);font-size:8.5pt;color:#666;text-align:center}
.pv-source b{color:var(--accent)}

@media print{
  .top,.foot,.crumbs,#tm-builder,.tm-actions,#tm-tray,#tm-side,.hint{display:none!important}
  /* repeat on every printed page: fixed elements are drawn per page by browsers */
  .pv-source{position:fixed;bottom:3mm;left:0;right:0;margin:0;padding:0;border:none;
    font-size:7.5pt;color:#777}
  .pv-wm{position:fixed;inset:0}
  body{background:#fff}
  .wrap{max-width:none;padding:0}
  /* @page margin 0 stops the browser printing its URL/date header & footer
     (they are only drawn inside the page margin area — incl. mobile Chrome,
     which has no checkbox to turn them off). Breathing room comes from the
     paper's own padding instead. */
  @page{size:A4;margin:0}
  /* overflow:visible — the screen clip (overflow:hidden) must not truncate
     content when the paper fragments across printed pages */
  #tm-paper{border:none;border-radius:0;padding:11mm 10mm;overflow:visible;
    font-size:calc(10pt * var(--fs,1));line-height:1.4}
  #tm-paper.compact{font-size:calc(8.8pt * var(--fs,1));line-height:1.3}
  #tm-paper.cols2{font-size:calc(8.4pt * var(--fs,1));line-height:1.28}
}
@media (max-width:560px){
  #tm-paper{padding:16px}
}
