/* jarchi board (board.js, board-surface.js, board-tools.js): the layers on a page, the text being typed, the
   selection's bar; the tools — a slim vertical bar on a laptop, a dock in thumb reach on a phone or tablet — their
   pop-outs, the pages strip; and doc.js's «فایل» sheet. The highlighter has its own layer, see-through and
   multiplied, so its strokes never darken where they cross and never hide the writing under them. */

/* ---------- the layers ---------- */
.ink-bg, .ink-hl, .ink-pen, .ink-live { position: absolute; top: 0; left: 0; display: block; }
.ink-hl { opacity: .42; mix-blend-mode: multiply; }
.stg-page[data-dark="1"] .ink-hl { mix-blend-mode: screen; opacity: .5; }
.stg-page .stg-img { transform-origin: 0 0; }
/* Our own pinch and pan on the page, never the browser's (everyone may zoom; only writers draw). */
.ink-live { touch-action: none; cursor: default; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.stg-page[data-zoomed="1"] .ink-live { cursor: grab; }
.stg-page.ink-edit .ink-live { cursor: crosshair; }
.stg-page.ink-edit[data-tool="select"] .ink-live { cursor: default; }
.stg-page.ink-edit[data-tool="text"] .ink-live { cursor: text; }
.stg-page.ink-edit[data-tool="laser"] .ink-live { cursor: none; }
.stg-page.ink-edit:is([data-tool="hand"], [data-space="1"]) .ink-live { cursor: grab; }
.stg-page[data-panning="1"] .ink-live { cursor: grabbing; }
.stg-page.ink-edit[data-tool="eraser"] .ink-live {
  cursor: var(--cursor-eraser);
}
.stg-page[data-loading="1"] .ink-live { cursor: progress; }
.stg-page[data-loading="err"]::after {
  content: "صفحه خونده نشد؛ دوباره امتحان می‌کنیم…";
  position: absolute; inset: auto 0 45% 0; text-align: center; color: var(--paper-muted); font-size: var(--fs-meta); font-weight: 700;
}

/* The text being typed: where it will stand, in its size and colour; each line in its own direction. */
.ink-text {
  position: absolute; z-index: 6; box-sizing: border-box;
  min-width: var(--tap); min-height: var(--tap);
  margin: 0; padding: 6px;
  border: 1.5px dashed var(--ink-select); border-radius: 6px;
  background: var(--ink-select-ground);
  font-family: Vazirmatn, Tahoma, sans-serif; font-weight: 500;
  white-space: pre; overflow: hidden; resize: none;
  unicode-bidi: plaintext; text-align: start;
  outline: none; caret-color: currentColor;
}
.stg-page[data-dark="1"] .ink-text { background: var(--ink-select-dark-ground); border-color: var(--ink-select-dark); }

/* The selection's bar: «کپی» and «حذف», above what is picked. */
.ink-selbar {
  position: absolute; z-index: 6; top: 0; left: 0;
  display: flex; gap: 2px; padding: 4px;
  border-radius: var(--r-pop); background: var(--surface-raised); box-shadow: var(--shadow-2);
  animation: kit-fade var(--t-fast) var(--ease);
}
.ink-selbar[hidden] { display: none; }
.ink-selbtn {
  appearance: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap); min-width: var(--tap); padding: 0 12px;
  border: 0; border-radius: 10px; background: transparent; color: var(--ink);
  font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-b); cursor: pointer;
}
.ink-selbtn#sel-delete { color: var(--danger-ink); }
@media (hover: hover) { .ink-selbtn:hover { background: var(--hover); } }
.ink-selbtn:active { background: var(--press); }

/* ---------- the tools: a slim bar on the stage's edge (laptop) ---------- */
.bt {
  position: absolute; z-index: 5; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  max-height: calc(100% - 12px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none;
  padding: 5px; border-radius: var(--r-lg);
  background: var(--surface-raised); box-shadow: var(--shadow-2);
  animation: kit-fade var(--t-med) var(--ease);
}
.bt::-webkit-scrollbar { display: none; }
.bt[hidden] { display: none; }
.bt[data-side="start"] { inset-inline-start: 8px; }
.bt[data-side="end"] { inset-inline-end: 8px; }
.bt-tools, .bt-hist { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.bt-hist[hidden] { display: none; }
.bt .tl { flex: none; width: var(--tap); padding: 0; }
.bt-sep { flex: none; width: 26px; height: 1px; margin: 3px 0; background: var(--line); }
.bt-sep[hidden] { display: none; }
/* A tool with choices (colours, shapes) says so with a small corner mark. */
.bt .tl.bt-has-pop { position: relative; }
.bt .tl.bt-has-pop::after {
  content: ""; position: absolute; bottom: 6px; inset-inline-end: 6px;
  border: 3px solid transparent; border-bottom-color: currentColor; border-inline-end-color: currentColor; opacity: .55;
}
.bt-color .sw-dot { width: 24px; height: 24px; }
.bt-color .sw-dot[data-w="0"] { width: 18px; height: 18px; }
.bt-color .sw-dot[data-w="2"] { width: 28px; height: 28px; }
/* The page keeps clear of the bar. */
.stg:is([data-tools="bar"], [data-tools="side"], [data-tools="folded"])[data-tside="start"] .stg-view { margin-inline-start: 64px; }
.stg:is([data-tools="bar"], [data-tools="side"], [data-tools="folded"])[data-tside="end"] .stg-view { margin-inline-end: 64px; }

/* A phone or tablet: a dock above the class bar (pen, highlighter, eraser, shapes, «بیشتر», the colour dot). */
.bt[data-layout="dock"] {
  position: static; transform: none; order: 2; align-self: center;
  flex-direction: row; gap: 2px; max-width: 100%; max-height: none;
  overflow-x: auto; overflow-y: hidden;
  padding: 4px 6px; border-radius: var(--r-pill);
}
.bt[data-layout="dock"] .bt-tools { flex-direction: row; }
.bt:is([data-layout="dock"], [data-layout="side"]) #tool-eraser { order: 1; }
.bt:is([data-layout="dock"], [data-layout="side"]) #tool-shape { order: 2; }
.bt:is([data-layout="dock"], [data-layout="side"]) :is(#tool-laser, #tool-fade, #tool-hand) { order: 3; }
.bt[data-layout="dock"] .bt-sep { width: 1px; height: 26px; margin: 0 3px; }
.bt[data-layout="dock"] .tl { width: 48px; height: 48px; }
/* A phone on its side: the same tools in a column on the stage's edge, packed to fit its height. */
.bt[data-layout="side"] { top: 50%; padding: 3px; gap: 0; }
.bt[data-layout="side"] .bt-tools { gap: 0; }
.bt[data-layout="side"] .bt-sep { display: none; }
/* Undo and redo float in a bottom corner of the stage on a phone or tablet. */
.stg-view > .bt-hist {
  position: absolute; z-index: 5; bottom: 10px; inset-inline-start: 10px;
  flex-direction: row; gap: 8px;
}
.stg-view > .bt-hist .tl {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--surface-raised); box-shadow: var(--shadow-2);
}
.stg-view > .bt-hist .tl:disabled { opacity: 1; color: var(--faint); box-shadow: var(--shadow-1); }
.stg[data-tools="side"] .stg-view > .bt-hist { inset-inline-start: auto; inset-inline-end: 10px; }

/* Folded: only the tool in hand and the way back. */
.bt[data-collapsed="1"] .bt-sep { display: none; }

/* ---------- pop-outs beside the bar; the same choices as a sheet on a phone ---------- */
.bt-pop {
  position: absolute; z-index: 8; top: 8px;
  width: 236px; max-height: calc(100% - 16px); overflow-y: auto;
  padding: 12px; border-radius: var(--r-pop);
  background: var(--surface-raised); color: var(--ink); box-shadow: var(--shadow-3);
  animation: kit-pop var(--t-med) var(--ease);
}
.bt-pop[hidden] { display: none; }
.bt-pop-title { margin: 0 0 8px; font-size: var(--fs-s); font-weight: var(--fw-b); color: var(--muted); }
.bt-opts { display: flex; flex-direction: column; gap: 10px; }
.bt-swatches { display: grid; grid-template-columns: repeat(var(--sw-cols, 4), var(--tap)); gap: 4px; justify-content: space-between; }
.tl.sw { width: var(--tap); padding: 0; }
.tl.sw[aria-pressed="true"] { background: transparent; border-color: transparent; }
/* Black ink keeps an edge on a dark card (--swatch-edge follows the scheme). */
.sw-dot { display: block; width: 26px; height: 26px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--swatch-edge); }
.tl.sw[aria-pressed="true"] .sw-dot { box-shadow: 0 0 0 3px var(--surface-raised), 0 0 0 5px var(--accent); }
.bt-widths { display: flex; gap: 4px; }
.tl.bw { flex: 1 1 0; }
.bw-line { display: block; width: 30px; border-radius: 4px; background: currentColor; }
.bw-text { font-weight: var(--fw-b); line-height: 1; }
.bt-shapes { display: grid; grid-template-columns: repeat(5, var(--tap)); gap: 2px; justify-content: space-between; }
.bt-note { margin: 0; color: var(--muted); font-size: var(--fs-xs); line-height: 1.6; }
.bt-more { display: flex; flex-direction: column; gap: 2px; }
.bt-moretools { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; margin-bottom: 6px; }
.bt-sub { margin: 8px 0 4px; font-size: var(--fs-xs); font-weight: var(--fw-b); color: var(--muted); }
.bt-row {
  appearance: none; display: flex; align-items: center; gap: 10px;
  min-height: var(--tap); width: 100%; padding: 0 10px;
  border: 1px solid transparent; border-radius: 10px;
  background: transparent; color: var(--ink);
  font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-m); text-align: start; cursor: pointer;
}
.bt-row .ic { color: var(--muted); }
.bt-row[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-ink); }
.bt-row:disabled { opacity: .45; cursor: default; }
@media (hover: hover) { .bt-row:not(:disabled):hover { background: var(--hover); } }
.bt-row:not(:disabled):active { background: var(--press); }
#tool-clear:not(:disabled), #tool-clear-kids:not(:disabled) { color: var(--danger-ink); }
#tool-clear:not(:disabled) .ic, #tool-clear-kids:not(:disabled) .ic { color: var(--danger-ink); }

/* The backgrounds, each a small picture of itself. */
.bt-backs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.bt-back {
  appearance: none; display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-height: 64px; padding: 6px 2px;
  border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--ink);
  font: inherit; font-size: var(--fs-micro); font-weight: var(--fw-m); line-height: 1.3; text-align: center; cursor: pointer;
}
.bt-back[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-ink); }
@media (hover: hover) { .bt-back:not([aria-pressed="true"]):hover { background: var(--hover); } }
.bt-back-pic {
  display: block; width: 44px; height: 26px; border-radius: 5px;
  background-color: var(--paper); box-shadow: inset 0 0 0 1.5px var(--swatch-edge);
}
.bt-back-pic[data-bg="grid"] { background-image: linear-gradient(var(--print-grid) 1px, transparent 1px), linear-gradient(90deg, var(--print-grid) 1px, transparent 1px); background-size: 5px 5px; }
.bt-back-pic[data-bg="grid-l"] { background-image: linear-gradient(var(--print-grid) 1px, transparent 1px), linear-gradient(90deg, var(--print-grid) 1px, transparent 1px); background-size: 10px 10px; }
.bt-back-pic[data-bg="lines"] { background-image: linear-gradient(90deg, transparent 36px, var(--print-margin) 36px, var(--print-margin) 37px, transparent 37px), linear-gradient(var(--print-grid) 1px, transparent 1px); background-size: 100% 100%, 100% 6px; }
.bt-back-pic[data-bg="dots"] { background-image: radial-gradient(var(--print-dot) 1px, transparent 1.4px); background-size: 5px 5px; }
.bt-back-pic[data-bg="axes"] { background-image: linear-gradient(90deg, transparent 21.5px, var(--print-axis) 21.5px, var(--print-axis) 22.5px, transparent 22.5px), linear-gradient(transparent 12.5px, var(--print-axis) 12.5px, var(--print-axis) 13.5px, transparent 13.5px), linear-gradient(var(--print-grid) 1px, transparent 1px), linear-gradient(90deg, var(--print-grid) 1px, transparent 1px); background-size: 100% 100%, 100% 100%, 5px 5px, 5px 5px; }
.bt-back-pic[data-bg="mm"] { background-image: linear-gradient(var(--print-mm) 1px, transparent 1px), linear-gradient(90deg, var(--print-mm) 1px, transparent 1px), linear-gradient(var(--print-mm-fine) 1px, transparent 1px), linear-gradient(90deg, var(--print-mm-fine) 1px, transparent 1px); background-size: 10px 10px, 10px 10px, 2px 2px, 2px 2px; }
.bt-back-pic[data-bg="green"] { background-color: var(--board-green); }
.bt-back-pic[data-bg="black"] { background-color: var(--board-black); }

/* A phone's sheet of the same choices: bigger targets. */
.bt-sheet .bt-swatches { grid-template-columns: repeat(var(--sw-cols, 4), 52px); }
.bt-sheet .tl.sw, .bt-sheet .bt-shapes .tl { width: 52px; height: 52px; }
.bt-sheet .bt-shapes { grid-template-columns: repeat(5, 52px); }
.bt-sheet .sw-dot { width: 30px; height: 30px; }
.bt-sheet .bt-opts { gap: 14px; }

/* ---------- the page bar's groups ---------- */
.bt-nav { gap: 0; }
.bt-group { display: flex; align-items: center; gap: 2px; }
.bt-group[hidden] { display: none; }
.bt-nav > :not([hidden]) ~ :not([hidden]) { margin-inline-start: 6px; }
.bt-nav > .bt-group:not([hidden]) ~ .bt-group:not([hidden])::before,
.bt-nav > .bt-group:not([hidden]) ~ .bt-write:not([hidden])::before { content: none; }
.bt-zoom { min-width: 60px; font-variant-numeric: tabular-nums; color: var(--muted); }
.bt-write { display: inline-flex; gap: 6px; }
.bt-write-word { display: none; } /* icons alone: «نوشتن روی فایل» is its tooltip and aria-label */
.bt-write .ic { width: 20px; height: 20px; }
.bt-write[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }


/* ---------- the pages strip (laptop), a sheet of thumbnails on a phone ---------- */
.bt-strip {
  position: absolute; z-index: 8; bottom: 64px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  width: min(820px, calc(100% - 152px));
  padding: 10px; border-radius: var(--r-pop);
  background: var(--surface-raised); box-shadow: var(--shadow-3);
  animation: kit-pop var(--t-med) var(--ease);
}
.bt-strip-list { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: thin; }
.bt-strip-acts { display: flex; gap: 8px; justify-content: center; }
.bt-page {
  appearance: none; position: relative; flex: none;
  padding: 3px; border: 2px solid transparent; border-radius: 10px;
  background: var(--bg-sunken); cursor: pointer;
}
.bt-page[aria-current="page"] { border-color: var(--accent); }
@media (hover: hover) { .bt-page:not([aria-current="page"]):hover { border-color: var(--line-strong); } }
.bt-thumb { display: block; width: 160px; height: 90px; border-radius: 6px; background: var(--paper); }
.bt-page-n {
  position: absolute; bottom: 7px; inset-inline-end: 7px;
  min-width: 22px; padding: 1px 6px; border-radius: var(--r-pill);
  background: var(--stage-chip-strong); color: var(--stage-ink); font-size: var(--fs-badge); font-weight: var(--fw-x);
}
.bt-strip-sheet .bt-strip-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: 52dvh; overflow-y: auto; overflow-x: hidden; margin-bottom: 12px; }
.bt-strip-sheet .bt-thumb { width: 100%; height: auto; aspect-ratio: 16 / 9; }
.bt-strip-sheet .sheet-row .btn { flex: 1 1 120px; }

/* ---------- layers: each writer's own (the teacher's panel over the page bar; a sheet on a phone) ---------- */
.bt-layers { position: relative; }
.bt-layers-n {
  position: absolute; top: 2px; inset-inline-end: 0;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-pill);
  background: var(--accent); color: var(--on-accent); font-size: var(--fs-badge); font-weight: var(--fw-x); line-height: 18px; text-align: center;
}
.bt-layers-n[hidden] { display: none; }
.bt-layers-pop { width: min(440px, calc(100% - 152px)); max-height: calc(100% - 80px); overflow-y: auto; }
.bt-layers-pop .bt-pop-title { margin: 2px 4px 4px; }
.bt-layer-list { list-style: none; margin: 0 0 6px; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.bt-layer { display: flex; align-items: center; gap: 4px; min-height: 52px; padding: 2px 6px; border-radius: 10px; }
.bt-layer + .bt-layer { border-top: 1px solid var(--line); border-radius: 0; }
.bt-mark { flex: none; width: 12px; height: 12px; margin-inline-end: 6px; border-radius: 50%; box-shadow: 0 0 0 2px var(--surface-raised), 0 0 0 3px var(--line-strong); }
.bt-layer-who { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.4; }
.bt-layer-who b { font-size: var(--fs-sm); font-weight: var(--fw-b); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bt-layer-who small { color: var(--muted); font-size: var(--fs-xs); }
.bt-layer[data-hidden="1"] .bt-layer-who { opacity: .55; }
.bt-layer .tl { flex: none; }
.bt-layer .tl[data-act="hide"][aria-pressed="true"], .bt-layer .tl[data-act="lock"][aria-pressed="true"] { background: var(--hand-soft); border-color: var(--hand-line); color: var(--hand-ink); }
.bt-row.bt-danger:not(:disabled), .bt-row.bt-danger:not(:disabled) .ic { color: var(--danger-ink); }
#tool-clear-mine:not(:disabled), #tool-clear-mine:not(:disabled) .ic { color: var(--danger-ink); }
.bt-locked {
  position: absolute; z-index: 6; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px; max-width: calc(100% - 24px);
  margin: 0; padding: 8px 14px; border-radius: var(--r-pill);
  background: var(--stage-chip-strong); color: var(--stage-ink); font-size: var(--fs-s); font-weight: var(--fw-b); line-height: 1.5;
}
.bt-locked[hidden] { display: none; }
/* Both at once: the way back to the teacher's view steps up above the note. */
.stg-view:has(> .bt-locked:not([hidden])) > .bt-follow { bottom: 64px; }
.bt-locked .ic { flex: none; width: 18px; height: 18px; }

/* ---------- a student: back to the teacher's view; a tool's name for a moment ---------- */
.bt-follow {
  appearance: none; position: absolute; z-index: 6; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--tap); padding: 0 16px;
  border: 0; border-radius: var(--r-pill);
  background: var(--stage-chip-strong); color: var(--stage-ink); box-shadow: var(--shadow-2);
  font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-b); white-space: nowrap; cursor: pointer;
  animation: kit-pop var(--t-med) var(--ease);
}
.bt-follow[hidden] { display: none; }
.bt-follow .ic { width: 20px; height: 20px; }
.bt-hint {
  position: absolute; z-index: 6; top: 10px; left: 50%; transform: translateX(-50%);
  margin: 0; padding: 6px 14px; border-radius: var(--r-pill);
  background: var(--stage-chip-strong); color: var(--stage-ink); font-size: var(--fs-s); font-weight: var(--fw-b);
  pointer-events: none; animation: kit-fade var(--t-fast) var(--ease);
}
.bt-hint[hidden] { display: none; }

/* ---------- «فایل» (the teacher's files for the class) ---------- */
.doc-body .btn#doc-upload { margin-bottom: 10px; }
.doc-status { margin: 0 0 10px; font-weight: 700; font-size: var(--fs-meta); color: var(--accent-ink); }
.doc-status:empty { display: none; }
.doc-status[data-bad="1"] { color: var(--danger-ink); }
.doc-list { list-style: none; margin: 0 0 4px; padding: 0; max-height: 40dvh; overflow-y: auto; }
.doc-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-top: 1px solid var(--line);
}
.doc-list li:first-child { border-top: 0; }
.doc-ic { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--bg-sunken); color: var(--muted); }
.doc-ic .ic { width: 20px; height: 20px; }
.doc-who { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.5; }
.doc-who b { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-who small { color: var(--muted); font-size: var(--fs-micro); }
.doc-who .doc-bad { color: var(--danger-ink); }
.doc-list li.empty { display: block; }

@media (prefers-reduced-motion: reduce) {
  .bt, .bt-pop, .bt-strip, .bt-follow, .ink-selbar, .bt-hint { animation: none; }
}
