/* Answer spaces, writing on the question paper and Whiteboard mode (js/ink.js, js/board.js).
   Loaded after topicbank.css on questions.html; rules here override the older ink/whiteboard rules there.

   html[data-ink-touch]   there is a touch screen: the "Finger writes" ticks show
   html[data-ink-finger]  a finger writes (localStorage ialqb_ink_finger = '1')
   html[data-ink-left]    the pen tools sit on the left (ialqb_ink_left = '1') */

/* ---------- Pen bars: the answer space's and the paper layer's ---------- */
.topicbank .ink-bar {
  --ink-b: 34px;
  position: sticky;
  top: var(--site-nav-h, 58px);
  z-index: 5;
  display: block;
  padding: 0;
  container: inkbar / inline-size;
  background: var(--field);
  border-bottom: 1px solid var(--line);
}
@media (pointer: coarse) {
  .topicbank .ink-bar { --ink-b: 44px; }
}
.topicbank .ink-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  min-height: calc(var(--ink-b) + 8px);
  padding: 4px 6px 4px 12px;
}
.topicbank .ink-title { flex: none; flex-basis: auto; color: var(--ink-2); font: 700 13px/1 var(--f-display); }
.topicbank .ink-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 0; margin-left: auto; }
.topicbank .ink-grp { display: flex; align-items: center; gap: 2px; }
.topicbank .ink-sep { flex: none; width: 1px; height: 20px; margin: 0 5px; background: var(--line-2); }
.topicbank .ink-btn { width: var(--ink-b); height: var(--ink-b); }
/* Left-handed: the tools at the left end of the bar, the rest after them. */
html[data-ink-left] .topicbank .ink-tools { order: -1; margin-left: 0; margin-right: auto; }
html[data-ink-left] .topicbank .ink-row { padding: 4px 12px 4px 6px; }

/* Colour and size buttons, on the pen bars and the whiteboard's bar */
.topicbank .ink-btn[data-colour] i,
.topicbank .wb-btn[data-colour] i { display: block; width: 15px; height: 15px; border: 1px solid var(--line-2); }
.topicbank :is(.ink-btn, .wb-btn)[data-colour="ink"] i { background: var(--ink); }
.topicbank :is(.ink-btn, .wb-btn)[data-colour="blue"] i { background: #6cc4ff; }
.topicbank :is(.ink-btn, .wb-btn)[data-colour="red"] i { background: #ff6a5e; }
:root[data-theme="light"] .topicbank :is(.ink-btn, .wb-btn)[data-colour="blue"] i { background: #0b5fd6; }
:root[data-theme="light"] .topicbank :is(.ink-btn, .wb-btn)[data-colour="red"] i { background: #c4141c; }
/* On the paper layer the ink is as it is on paper: chips on a white edge. */
.topicbank .inkp-bar .ink-btn[data-colour] i { border: 0; box-shadow: 0 0 0 2px #fff; }
.topicbank .inkp-bar .ink-btn[data-colour="ink"] i,
:root[data-theme="light"] .topicbank .inkp-bar .ink-btn[data-colour="ink"] i { background: #141414; }
.topicbank .inkp-bar .ink-btn[data-colour="blue"] i,
:root[data-theme="light"] .topicbank .inkp-bar .ink-btn[data-colour="blue"] i { background: #0b5fd6; }
.topicbank .inkp-bar .ink-btn[data-colour="red"] i,
:root[data-theme="light"] .topicbank .inkp-bar .ink-btn[data-colour="red"] i { background: #c4141c; }
.topicbank .ink-btn[data-size] i,
.topicbank .ink-btn[data-cycle] i,
.topicbank .wb-btn[data-size] i,
.topicbank .wb-btn[data-cycle] i { display: block; border-radius: 50%; background: currentColor; }
.topicbank :is(.ink-btn, .wb-btn):is([data-size="0"], [data-cycle][data-z="0"]) i { width: 4px; height: 4px; }
.topicbank :is(.ink-btn, .wb-btn):is([data-size="1"], [data-cycle][data-z="1"]) i { width: 7px; height: 7px; }
.topicbank :is(.ink-btn, .wb-btn):is([data-size="2"], [data-cycle][data-z="2"]) i { width: 11px; height: 11px; }
/* One button that steps through the sizes, where three do not fit. */
.topicbank .ink-btn[data-cycle],
.topicbank .wb-btn[data-cycle] { display: none; }

/* "Finger writes": a square tick, only where there is a touch screen. */
.topicbank .ink-finger { display: none; }
html[data-ink-touch] .topicbank .ink-finger {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 8px;
  min-height: var(--ink-b);
  padding: 0 10px 0 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-2);
  font: 600 13px/1.1 var(--f-text);
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.topicbank .ink-box { display: grid; place-items: center; flex: none; width: 18px; height: 18px; border: 1px solid var(--line-3); background: var(--field); }
.topicbank .ink-box svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 18; stroke-dashoffset: 18; transition: stroke-dashoffset 0.24s var(--ease); }
.topicbank .ink-finger:hover { color: var(--ink); border-color: var(--line-2); }
.topicbank .ink-finger[aria-pressed="true"] { color: var(--ink); }
.topicbank .ink-finger[aria-pressed="true"] .ink-box { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.topicbank .ink-finger[aria-pressed="true"] .ink-box svg { stroke-dashoffset: 0; }
.topicbank .ink-finger:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; }

/* Narrower bars: the title goes, then the three sizes become one button, then the tick's words
   take two lines, then (on an answer space) the tick moves down to the page's foot; past that the
   groups wrap. */
@container inkbar (max-width: 800px) {
  html[data-ink-touch] .topicbank .ink-title { display: none; }
}
@container inkbar (max-width: 690px) {
  html[data-ink-touch] .topicbank .ink-sizes [data-size] { display: none; }
  html[data-ink-touch] .topicbank .ink-sizes [data-cycle] { display: grid; }
  html[data-ink-touch] .topicbank .ink-row { padding-left: 4px; gap: 4px 6px; }
  html[data-ink-touch] .topicbank .ink-sep { margin: 0 3px; }
  html[data-ink-touch] .topicbank .ink-grp { gap: 0; }
}
@container inkbar (max-width: 620px) {
  html[data-ink-touch] .topicbank .ink-finger-t { width: 3.7em; white-space: normal; line-height: 1.05; }
}
@container inkbar (max-width: 520px) {
  html[data-ink-touch] .topicbank .ink > .ink-bar .ink-finger { display: none; }
}
@container inkbar (max-width: 560px) {
  html:not([data-ink-touch]) .topicbank .ink-title { display: none; }
}
@container inkbar (max-width: 440px) {
  html:not([data-ink-touch]) .topicbank .ink-sizes [data-size] { display: none; }
  html:not([data-ink-touch]) .topicbank .ink-sizes [data-cycle] { display: grid; }
  .topicbank .ink-row { padding-left: 4px; gap: 4px 6px; }
  .topicbank .ink-sep { margin: 0 3px; }
  .topicbank .ink-grp { gap: 0; }
}

/* ---------- The answer space ----------
   Exam-size lines: 42 CSS pixels apart on a touch screen (about 8 mm on an iPad), with a mouse 4%
   of the width but at least 32 pixels. js/ink.js sets --ink-lines; a page with writing on it keeps
   its own proportions instead (an inline aspect-ratio). */
.topicbank .ink { container-type: inline-size; }
.topicbank .ink-page {
  --ink-gap: max(32px, 4cqw);
  height: calc(var(--ink-lines, 7) * var(--ink-gap));
}
@media (pointer: coarse) {
  .topicbank .ink-page { --ink-gap: 42px; }
}
/* The foot: More space, and Less space when lines were added. */
.topicbank .ink-foot { display: flex; align-items: stretch; border-top: 1px dashed var(--line-2); background: var(--field); }
.topicbank .ink-foot .ink-more { flex: 1 1 auto; width: auto; height: 32px; border-top: 0; }
.topicbank .ink-less {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--ink-3);
  font: 600 12px/1 var(--f-text);
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}
.topicbank .ink-less[hidden] { display: none; }
.topicbank .ink-less svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.topicbank .ink-less:hover { color: var(--accent); background: var(--field-2); }
.topicbank .ink-less:focus-visible { outline: 1px solid var(--accent); outline-offset: -2px; }
html[data-ink-touch] .topicbank .ink-foot .ink-finger { display: none; }
@container (max-width: 522px) {
  html[data-ink-touch] .topicbank .ink-foot .ink-finger { display: inline-flex; min-height: 0; padding: 0 10px; border-right: 1px solid var(--line); }
}
@media (pointer: coarse) {
  .topicbank .ink-foot .ink-more,
  .topicbank .ink-less { height: 44px; }
}
/* A finger scrolls and pinches the page as usual over a page to write on (a stylus or mouse
   writes); with Finger writes ticked a finger writes and two fingers scroll. */
.topicbank .ink-page canvas,
.topicbank .inkp-layer canvas { touch-action: manipulation; -webkit-touch-callout: none; }
html[data-ink-finger] .topicbank .ink-page canvas,
html[data-ink-finger] .topicbank .inkp-layer canvas { touch-action: none; }

/* ---------- Writing on the question paper (IALQB_INK.paper) ---------- */
:where(.inkp-host) { position: relative; }
.topicbank .inkp-bar { margin: 0 0 8px; border: 1px solid var(--line); }
.topicbank .inkp-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 2; -webkit-user-select: none; user-select: none; }
.topicbank .inkp-layer canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; cursor: crosshair; }
.topicbank .inkp-layer.is-eraser canvas { cursor: cell; }

/* In Whiteboard mode one bar, the whiteboard's, drives every page: their own bars step aside. */
.topicbank.tb-focus .ink-bar { display: none; }

/* ---------- Whiteboard mode (js/board.js) ----------
   The whiteboard is a picture over the page that lets everything through; the page gets every
   touch and click, and js/board.js turns a stylus or mouse press into writing. */
.topicbank .wb-board { pointer-events: none; touch-action: auto; cursor: auto; }
.topicbank.wb-write .tb-main { cursor: crosshair; }
.topicbank.wb-write .tb-main :is(button, a[href], summary, label, select, input, textarea, [role="button"]) { cursor: pointer; }
.topicbank.wb-erase .tb-main,
.topicbank.wb-erase .ink-page canvas,
.topicbank.wb-erase .inkp-layer canvas { cursor: cell; }
.topicbank.tb-board .tb-main img { -webkit-touch-callout: none; }
/* With Finger writes ticked one finger writes anywhere (two scroll, in js/board.js). */
html[data-ink-finger] body.wb-write,
html[data-ink-finger] body.wb-write .tb-main,
html[data-ink-finger] body.wb-write .tb-main * { touch-action: none; }

/* The bar: docked along the foot of the screen, full width, one row. */
.topicbank .wb-bar {
  --ink-b: 36px;
  position: fixed;
  z-index: 37;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: none;
  min-height: 0;
  padding: 6px max(12px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  border: 0;
  border-top: 1px solid var(--line);
  background: var(--panel);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: none;
  transform: none;
  animation: wb-dock 0.34s var(--ease) both;
}
@keyframes wb-dock { from { transform: translateY(100%); } to { transform: none; } }
@media (pointer: coarse) {
  .topicbank .wb-bar { --ink-b: 44px; }
}
.topicbank .wb-end { display: flex; flex: none; align-items: center; gap: 8px; }
.topicbank .wb-tools { display: flex; flex: none; align-items: center; min-width: 0; }
html[data-ink-left] .topicbank .wb-tools { order: -1; }
.topicbank .wb-title { margin: 0 4px 0 0; }
.topicbank .wb-group { gap: 2px; }
.topicbank .wb-sep { flex: none; margin: 0 6px; }
.topicbank .wb-btn { width: var(--ink-b); height: var(--ink-b); }
.topicbank .wb-all { width: auto; padding: 0 10px; color: var(--ink-2); font: 600 13px/1 var(--f-text); white-space: nowrap; }
.topicbank .wb-all-s { display: none; }
.topicbank .wb-exit {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: var(--ink-b);
  padding: 0 14px 0 10px;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--ink);
  font: 700 14px/1 var(--f-display);
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.topicbank .wb-exit svg { flex: none; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.topicbank .wb-exit:hover { border-color: var(--ink); background: var(--field); }
.topicbank .wb-exit:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }
.topicbank .wb-exit-s { display: none; }

/* Clear all asks first, in the bar: the tools step aside for the question. */
.topicbank .wb-ask { display: flex; flex: 1 1 auto; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
.topicbank .wb-ask[hidden] { display: none; }
.topicbank .wb-bar.is-asking .wb-tools { display: none; }
html[data-ink-left] .topicbank .wb-ask { order: -1; justify-content: flex-start; }
.topicbank .wb-ask-t { min-width: 0; margin: 0 6px 0 0; color: var(--ink); font-size: 14px; line-height: 1.3; }
.topicbank .wb-ask-btn {
  flex: none;
  min-height: var(--ink-b);
  padding: 0 14px;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--ink);
  font: 700 14px/1 var(--f-display);
  white-space: nowrap;
  cursor: pointer;
}
.topicbank .wb-ask-btn:hover { border-color: var(--ink); }
.topicbank .wb-ask-btn.is-yes { background: var(--red); border-color: var(--red); color: var(--tab-on-ink); }
.topicbank .wb-ask-btn:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

/* The words go before anything wraps: the title first, on a narrower or touch screen. */
@media (max-width: 1239px) and (pointer: coarse), (max-width: 1060px) {
  .topicbank .wb-title { display: none; }
}
@media (max-width: 900px) {
  .topicbank .wb-bar { gap: 6px; padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
  .topicbank .wb-exit { padding: 0 12px 0 10px; gap: 6px; }
  .topicbank .wb-exit-l { display: none; }
  .topicbank .wb-exit-s { display: inline; }
  .topicbank .wb-group { gap: 0; }
  .topicbank .wb-sep { margin: 0 3px; }
  .topicbank .wb-sizes [data-size] { display: none; }
  .topicbank .wb-sizes [data-cycle] { display: grid; }
  .topicbank .wb-all { width: var(--ink-b); padding: 0; }
  .topicbank .wb-all-l { display: none; }
  .topicbank .wb-all-s { display: inline; }
  .topicbank .wb-finger { padding: 0 6px; gap: 6px; }
  .topicbank .wb-finger .ink-finger-t { width: 3.7em; white-space: normal; line-height: 1.05; }
  .topicbank .wb-ask-t { font-size: 13px; }
}
/* Phones: the tools scroll sideways rather than wrap over the page. */
@media (max-width: 767px) {
  .topicbank .wb-tools { flex: 1 1 auto; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
  .topicbank .wb-tools::-webkit-scrollbar { display: none; }
  html[data-ink-left] .topicbank .wb-end { margin-left: auto; }
}

/* Back to top, the notifications and the end of the page stay clear of the bar (--wb-h). */
.topicbank.tb-board .tb-dl { display: none; }
.topicbank.tb-board .tb-main { padding-bottom: calc(var(--wb-h, 57px) + 40px); }
.topicbank.tb-board .ctl-top { bottom: calc(var(--wb-h, 57px) + 12px); }
.topicbank.tb-board .ctl-toasts { bottom: calc(var(--wb-h, 57px) + 14px); }
.topicbank.tb-board.ctl-top-on .ctl-toasts { bottom: calc(var(--wb-h, 57px) + 66px); }

@media (prefers-reduced-motion: reduce) {
  .topicbank .wb-bar { animation: ctl-fade 0.15s ease both; }
  .topicbank .ink-box svg { transition: none; }
}

/* Larger text (Settings) */
html[data-textsize="large"] .topicbank .ink-title,
html[data-textsize="large"] .topicbank .ink-finger,
html[data-textsize="large"] .topicbank .ink-more,
html[data-textsize="large"] .topicbank .ink-less,
html[data-textsize="large"] .topicbank .wb-all { font-size: 15px; }
html[data-textsize="large"] .topicbank .wb-exit,
html[data-textsize="large"] .topicbank .wb-ask-btn,
html[data-textsize="large"] .topicbank .wb-ask-t { font-size: 16px; }

/* ---------- Type: typed text on an answer space's lines (js/ink.js) ----------
   The box sits on the line clicked, in the size and place the text will be drawn, with no frame:
   a faint underline shows the line being typed on. */
.topicbank .ink.is-text .ink-page canvas { cursor: text; }
.topicbank .ink-type {
  position: absolute;
  z-index: 2;
  margin: 0;
  padding: 0;
  border: 0;
  border-bottom: 1px dashed var(--accent);
  border-radius: 0;
  background: transparent;
  line-height: 1.4;
  caret-color: var(--accent);
  box-shadow: none;
  -webkit-appearance: none;
  appearance: none;
}
.topicbank .ink-type:focus { outline: none; }
