/* Emoji artwork we ship ourselves, so a board looks the same on a laptop and a
   phone and stays sharp however big a stamp gets. Outlines, not pictures - see
   the note above EMOJI_FONT in render.js. Nothing is fetched from the network;
   the file sits next to the app and works on a plane like the rest of it. */
@font-face {
  font-family: 'GazBoard Emoji';
  src: url('../assets/fonts/gazboard-emoji.woff2') format('woff2');
  font-display: block;
}

:root {
  --bg: #f3f2f1;
  --surface: #ffffff;
  --surface-2: #faf9f8;
  --stroke: #e1dfdd;
  --stroke-2: #c8c6c4;
  --text: #201f1e;
  --text-2: #605e5c;
  --accent: #6264a7;
  --accent-2: #0078d4;
  --accent-soft: #eceafb;
  --danger: #d13438;
  --shadow-1: 0 1.6px 3.6px rgba(0,0,0,.10), 0 .3px .9px rgba(0,0,0,.07);
  --shadow-2: 0 6.4px 14.4px rgba(0,0,0,.13), 0 1.2px 3.6px rgba(0,0,0,.10);
  --shadow-3: 0 12.8px 28.8px rgba(0,0,0,.18), 0 2.4px 7.2px rgba(0,0,0,.10);
  --r: 8px;
  --topbar-h: 48px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: 'Segoe UI Variable', 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; user-select: none; cursor: default;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea { font: inherit; }

/* The app frame owns web safe areas. Its children already sit inside them.
   On Android the native frame handles these and forwards zeroed insets. */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ---------------- top bar ---------------- */
#topbar {
  height: var(--topbar-h); flex: 0 0 auto; display: flex; align-items: center; gap: 6px;
  padding: 0 10px;
  background: var(--surface); border-bottom: 1px solid var(--stroke);
  position: relative; z-index: 30;
  max-width: 100vw;
  overflow-x: auto;
  scrollbar-width: none;
}
#topbar::-webkit-scrollbar { display: none; }
.tb-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 10px;
  border-radius: 6px; color: var(--text-2); flex-shrink: 0;
}
.tb-btn:hover { background: var(--surface-2); color: var(--text); }
.tb-btn.active { background: var(--accent-soft); color: var(--accent); }
.tb-btn span { font-size: 13px; }
#boardTitle {
  border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 5px 8px;
  font-size: 15px; font-weight: 600; min-width: 90px; max-width: 380px; color: var(--text);
  flex-shrink: 1; text-overflow: ellipsis;
}
#boardTitle:hover { border-color: var(--stroke); }
#boardTitle:focus { outline: none; border-color: var(--accent-2); background: #fff; }
.spacer { flex: 1; min-width: 6px; }
.badge { font-size: 11px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--stroke); padding: 3px 8px; border-radius: 20px; flex-shrink: 0; }

/* ---------------- stage ---------------- */
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: var(--surface); }
/* The canvas is sized by CSS alone - never by inline width/height - so it
   cannot drift out of step with the window. Only its backing store is set
   from JS. */
#c { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

/* ---------------- bottom toolbar ---------------- */
#toolbar {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 14px; z-index: 20;
  display: flex; align-items: flex-end; gap: 1px; padding: 6px 8px 9px;
  background: var(--surface); border: 1px solid var(--stroke); border-radius: 12px; box-shadow: var(--shadow-2);
  max-width: calc(100vw - 24px); flex-wrap: nowrap; overflow: visible;
}

/* The keyboard letter on a tool button. Small, quiet, and out of the way of
   the colour dot in the opposite corner - it is there to be found when you
   look for it, not to compete with the icon. */
.kbd {
  position: absolute; left: 4px; bottom: 3px;
  font-size: 10px; line-height: 1; font-weight: 700; letter-spacing: .2px;
  color: var(--text-2); opacity: .78; pointer-events: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.tool.active .kbd, .pen.active .kbd { color: var(--accent); opacity: 1; }
.tool:hover .kbd, .pen:hover .kbd { opacity: 1; }
/* the pen bodies are dark, so their letter sits just outside the barrel */
.pen .kbd { left: 2px; bottom: 1px; }
#toolbar.hide-keys .kbd { display: none; }

/* plain icon buttons */
.tool {
  position: relative; width: 40px; height: 40px; border-radius: 8px; margin-bottom: 4px;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-2);
  transition: transform .12s ease, background .12s ease;
}
.tool:hover { background: var(--surface-2); color: var(--text); }
.tool.active { background: var(--accent-soft); color: var(--accent); }
.tool[disabled] { opacity: .35; pointer-events: none; }
.tool .dot {
  position: absolute; right: 5px; bottom: 5px; width: 9px; height: 9px; border-radius: 50%;
  border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.15);
}

/* the pen tray: a pen lifts out of the toolbar when it is the one in your hand */
.pen {
  position: relative; width: 34px; height: 48px; border-radius: 8px 8px 4px 4px;
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
  transition: transform .14s cubic-bezier(.2,.9,.3,1.3);
}
.pen svg { display: block; pointer-events: none; }
.pen:hover { transform: translateY(-3px); }
.pen.active { transform: translateY(-9px); }
.pen.active::after {
  content: ''; position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%);
  width: 20px; height: 3px; border-radius: 2px; background: var(--accent);
}
.pen .size-dot {
  position: absolute; top: 2px; right: 2px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent-2); border: 1.5px solid #fff; opacity: 0;
}
.pen.active .size-dot { opacity: 1; }

.sep { width: 1px; height: 26px; background: var(--stroke); margin: 0 5px 10px; flex: 0 0 auto; }

/* canvas-size chooser in the background panel */
.bg-sizes{ display:flex; flex-wrap:wrap; gap:6px; margin-bottom:8px; }
.bg-sizes .btn{ padding:6px 12px; font-size:13px; }
.bg-sizes .btn[disabled]{ opacity:.4; pointer-events:none; }

/* ---------------- popovers ---------------- */
.pop {
  position: absolute; z-index: 40; background: var(--surface); border: 1px solid var(--stroke);
  border-radius: 10px; box-shadow: var(--shadow-3); padding: 12px; min-width: 220px;
  max-width: calc(100vw - 20px); max-height: calc(100dvh - 20px); max-height: calc(100vh - 20px);
  overflow-y: auto; overscroll-behavior: contain;
}
.pop h4 { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .4px; }
.pop .row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.pop .row:last-child { margin-bottom: 0; }

.swatches { display: grid; grid-template-columns: repeat(8, 26px); gap: 6px; }
.sw { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.sw:hover { transform: scale(1.08); }
.sw.active { border-color: var(--accent-2); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12), 0 0 0 1px #fff; }
.sw.rainbow { background: conic-gradient(#f44,#fa0,#fd0,#4c4,#2af,#66f,#c4f,#f44); }
.sw.galaxy { background: radial-gradient(circle at 30% 30%, #b18cff, #4a2f8f 55%, #1b1140); }

.font-row { display: flex; gap: 6px; flex-wrap: wrap; }
.font-opt {
  display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 58px;
  padding: 6px 8px; border: 1px solid var(--stroke); border-radius: 8px; background: var(--surface);
}
.font-opt:hover { background: var(--surface-2); }
.font-opt.active { border-color: var(--accent-2); box-shadow: inset 0 0 0 1px var(--accent-2); }
.font-opt span { font-size: 19px; line-height: 1.1; color: var(--text); }
.font-opt small { font-size: 10.5px; color: var(--text-2); }

.slider { flex: 1; accent-color: var(--accent-2); }
.pop label { font-size: 13px; color: var(--text-2); }
.sizes { display: flex; gap: 6px; }
.size { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; }
.size:hover { background: var(--surface-2); }
.size.active { background: var(--accent-soft); }
.size i { display: block; background: currentColor; border-radius: 50%; color: var(--text); }

.shape-grid { display: grid; grid-template-columns: repeat(5, 40px); gap: 6px; }
.shape-btn { width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center; color: var(--text-2); }
.shape-btn:hover { background: var(--surface-2); }
.shape-btn.active { background: var(--accent-soft); color: var(--accent); }

/* The emoji picker. The list is long on purpose, so it scrolls inside the
   popover rather than growing a popover taller than the screen. */
.emoji-pop { width: 312px; max-width: 78vw; }
.emoji-search {
  width: 100%; box-sizing: border-box; margin-bottom: 10px;
  padding: 8px 10px; font: inherit; font-size: 13.5px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
.emoji-search:focus { outline: none; border-color: var(--accent); }
.emoji-sections, .emoji-grid { max-height: 46vh; overflow-y: auto; overscroll-behavior: contain; }
.emoji-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.emoji-sections .emoji-grid { max-height: none; overflow: visible; }
.emoji-sections h4 { margin: 10px 0 4px; }
.emoji-sections h4:first-child { margin-top: 0; }
/* The picker draws from the same font as the board, so the one you choose is
   the one you get rather than a near-enough cousin from the system. */
.emoji-cell {
  font-family: 'GazBoard Emoji', 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  aspect-ratio: 1; width: 100%; border: 0; border-radius: 8px; background: none;
  font-size: 21px; line-height: 1; cursor: pointer; padding: 0;
  display: grid; place-items: center;
}
.emoji-cell:hover { background: var(--surface-2); }
.emoji-cell.active { background: var(--accent-soft); }
.emoji-empty { padding: 14px 2px; color: var(--text-2); font-size: 13px; }
@media (pointer: coarse) { .emoji-cell { font-size: 24px; } }

.menu { min-width: 240px; padding: 6px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 6px;
  font-size: 14px; text-align: left; color: var(--text);
}
.menu-item:hover { background: var(--surface-2); }
.menu-item[disabled] { opacity: .4; pointer-events: none; }
.menu-item .k { margin-left: auto; font-size: 12px; color: var(--text-2); }
.menu-sep { height: 1px; background: var(--stroke); margin: 5px 4px; }
.menu-item.danger { color: var(--danger); }
.menu-item.active-mode { background: var(--accent-soft); color: var(--accent); }

.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.toggle input { appearance: none; width: 34px; height: 18px; border-radius: 10px; background: var(--stroke-2); position: relative; transition: background .15s; }
.toggle input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle input:checked { background: var(--accent-2); }
.toggle input:checked::after { transform: translateX(16px); }

/* ---------------- zoom readout ---------------- */
#zoomPill {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  z-index: 22; padding: 12px 26px; border-radius: 8px; pointer-events: none;
  background: rgba(50,49,48,.88); color: #fff; font-size: 22px; letter-spacing: .5px;
  opacity: 0; transition: opacity .18s ease;
}
#zoomPill.show { opacity: 1; }

/* ---------------- zoom bar ---------------- */
#zoombar {
  position: absolute; right: 16px; bottom: 18px; z-index: 20; display: flex; align-items: center; gap: 2px;
  background: var(--surface); border: 1px solid var(--stroke); border-radius: 10px; box-shadow: var(--shadow-1); padding: 4px;
}
#zoombar button { width: 32px; height: 32px; border-radius: 6px; display: grid; place-items: center; color: var(--text-2); }
#zoombar button:hover { background: var(--surface-2); }
#zoomLabel { min-width: 52px; text-align: center; font-size: 12.5px; color: var(--text-2); cursor: pointer; }

/* ---------------- first-run hints ---------------- *
   Top right, under the title bar, out of the way of both the toolbar and the
   readouts. Says its piece once and then never again. */
#hints {
  position: absolute; top: 14px; right: 16px; z-index: 28;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none; max-width: min(360px, 70vw);
}
.hint {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 10px;
  background: var(--surface); border: 1px solid var(--stroke); border-radius: 10px;
  box-shadow: var(--shadow-2); padding: 11px 12px 11px 13px;
  font-size: 12.5px; line-height: 1.5; color: var(--text-2);
  animation: hintIn .22s ease both;
}
.hint b { color: var(--text); font-weight: 600; }
.hint .hint-x {
  flex: 0 0 auto; width: 20px; height: 20px; border-radius: 5px; margin: -2px -3px 0 0;
  display: grid; place-items: center; color: var(--text-2); opacity: .6;
}
.hint .hint-x:hover { background: var(--surface-2); opacity: 1; }
.hint.go { opacity: 0; transform: translateY(-6px); transition: opacity .3s, transform .3s; }
@keyframes hintIn { from { opacity: 0; transform: translateY(-8px); } }

/* ---------------- page navigator (pads only) ---------------- */
#pagebar {
  position: absolute; right: 16px; bottom: 66px; z-index: 20; display: flex; align-items: center; gap: 2px;
  background: var(--surface); border: 1px solid var(--stroke); border-radius: 10px; box-shadow: var(--shadow-1); padding: 4px;
}
#pagebar[hidden] { display: none; }
#pagebar button { width: 32px; height: 32px; border-radius: 6px; display: grid; place-items: center; color: var(--text-2); }
#pagebar button:hover:not(:disabled) { background: var(--surface-2); }
#pagebar button:disabled { opacity: .35; cursor: default; }
#pageLabel { width: auto; min-width: 84px; padding: 0 8px; text-align: center; font-size: 12.5px; color: var(--text-2); cursor: pointer; }

/* ---------------- selection context bar ---------------- */
#ctxbar {
  position: absolute; z-index: 25; display: none; align-items: center; gap: 2px; padding: 4px;
  background: var(--surface); border: 1px solid var(--stroke); border-radius: 10px; box-shadow: var(--shadow-2);
}
#ctxbar.show { display: flex; }
#ctxbar button { width: 34px; height: 34px; border-radius: 6px; display: grid; place-items: center; color: var(--text-2); }
#ctxbar button:hover { background: var(--surface-2); color: var(--text); }
#ctxbar button[disabled] { opacity: .35; pointer-events: none; }
#ctxbar button.on { background: var(--accent-soft); color: var(--accent); }
#ctxbar .bar-sep { width: 1px; height: 20px; margin: 0 3px; background: var(--stroke); flex: none; }

/* ---------------- side panel ---------------- */
.panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 340px; z-index: 35;
  background: var(--surface); border-left: 1px solid var(--stroke); box-shadow: var(--shadow-3);
  display: flex; flex-direction: column; transform: translateX(100%); transition: transform .18s ease;
}
.panel.open { transform: none; }
.panel header { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--stroke); }
.panel header h3 { margin: 0; font-size: 15px; font-weight: 600; flex: 1; }
.panel .body { flex: 1; overflow: auto; padding: 14px; }
.panel .section { margin-bottom: 20px; }
.panel .section h5 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-2); }
.icon-btn { width: 32px; height: 32px; border-radius: 6px; display: grid; place-items: center; color: var(--text-2); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tpl {
  border: 1px solid var(--stroke); border-radius: 8px; overflow: hidden; background: var(--surface-2);
  text-align: left; transition: box-shadow .15s, border-color .15s;
}
.tpl:hover { border-color: var(--accent-2); box-shadow: var(--shadow-1); }
.tpl .thumb { height: 88px; background: #fff; display: block; width: 100%; }
.tpl .name { display: block; padding: 8px 9px; font-size: 12.5px; font-weight: 500; }

.bg-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.bg-sw { aspect-ratio: 1; border-radius: 6px; border: 2px solid transparent; box-shadow: inset 0 0 0 1px var(--stroke); }
.bg-sw.active { border-color: var(--accent-2); }
.pat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pat { height: 54px; border: 1px solid var(--stroke); border-radius: 6px; background: #fff; position: relative; overflow: hidden; }
.pat.active { border-color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent-2); }
.pat span { position: absolute; bottom: 3px; left: 0; right: 0; text-align: center; font-size: 10.5px; color: var(--text-2); background: rgba(255,255,255,.85); }

.board-row { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; width: 100%; text-align: left; }
.board-row:hover { background: var(--surface-2); }
.board-row .meta { flex: 1; min-width: 0; }
.board-row .meta b { display: block; font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-row .meta small { color: var(--text-2); font-size: 11.5px; }

/* ---------------- text editing overlay ---------------- */
/*
 * The ink pointer.
 *
 * Its own layer, moved with a transform, for one reason: a pointer painted
 * into the canvas means repainting the whole board on every pointer move, and
 * while hovering there is no stroke in flight to reuse a cached frame from - so
 * a busy board redrew itself from scratch a hundred times a second just to
 * shift a nib a few pixels. A transform on a composited layer costs nothing and
 * never touches the board at all.
 *
 * `will-change` promotes it once, up front, rather than on first move.
 */
#inkNib {
  position: absolute; left: 0; top: 0; width: 26px; height: 26px;
  pointer-events: none; z-index: 14;
  background-repeat: no-repeat; background-size: 26px 26px;
  will-change: transform;
}

#editLayer { position: absolute; inset: 0; pointer-events: none; z-index: 15; }
/*
 * The box you type in.
 *
 * It used to announce itself: a two-pixel accent border, rounded corners, a
 * drop shadow, and an opaque white fill. Nothing you have ever typed into looks
 * like that. Worse, the fill was a lie - it hid the note colour, the shape, the
 * board underneath - so the thing you were looking at while typing was not the
 * thing you got when you stopped, and the text jumped two pixels on commit
 * besides, because a border sits between the box and its contents.
 *
 * A text box in Word, PowerPoint or Keynote is a thin dashed frame around text
 * that is already sitting exactly where it will end up. So: no fill, no border,
 * no shadow. The frame is an OUTLINE, which is painted outside the box and
 * cannot shift a single character, held a few pixels clear of the text so it
 * frames rather than crowds.
 */
#editLayer textarea {
  position: absolute; pointer-events: auto; resize: none;
  border: 0; padding: 0; margin: 0; background: transparent; color: var(--text);
  overflow: hidden; user-select: text;
  outline: 1px dashed rgba(0,0,0,.45);
  outline-offset: 4px;
}

/* ---------------- toast / progress ---------------- */
#toasts { position: absolute; left: 50%; transform: translateX(-50%); bottom: 78px; z-index: 45; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: #323130; color: #fff; padding: 9px 14px; border-radius: 6px; font-size: 13px;
  box-shadow: var(--shadow-2); display: flex; align-items: center; gap: 8px; animation: pop .18s ease;
}
/*
 * A toast that carries something to do about itself. Tall enough to press with
 * a thumb, because the first place this appears is a phone changing a board to
 * A4 and finding work off the paper.
 */
.toast-action {
  margin-left: 4px; border: 0; border-radius: 5px; cursor: pointer;
  /* on a narrow phone the message wraps to three lines; without this the
     button grows to match it and looks like a slab rather than a button */
  align-self: center; flex: none; white-space: nowrap;
  /* The toast layer is click-through so passing notes never block the board.
     This button is the exception: it exists to be pressed. */
  pointer-events: auto;
  background: rgba(255,255,255,.18); color: #fff;
  font: inherit; font-weight: 600; padding: 6px 11px; min-height: 32px;
}
.toast-action:hover { background: rgba(255,255,255,.3); }
.toast-action:active { background: rgba(255,255,255,.4); }

@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

#overlay { position: absolute; inset: 0; z-index: 60; background: rgba(0,0,0,.28); display: none; align-items: center; justify-content: center; }
#overlay.show { display: flex; }
.card { background: var(--surface); border-radius: 10px; box-shadow: var(--shadow-3); padding: 22px 24px; min-width: min(320px, 90vw); max-width: min(620px, 94vw); max-height: min(85dvh, 85vh); overflow-y: auto; overscroll-behavior: contain; }
.card h3 { margin: 0 0 6px; font-size: 17px; }
.card p { margin: 0 0 14px; color: var(--text-2); font-size: 13.5px; line-height: 1.5; }
.bar { height: 6px; border-radius: 3px; background: var(--stroke); overflow: hidden; margin: 12px 0 4px; }
.bar i { display: block; height: 100%; background: var(--accent-2); width: 0; transition: width .2s; }
.card .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.btn { padding: 7px 16px; border-radius: 6px; border: 1px solid var(--stroke-2); background: var(--surface); font-size: 13.5px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.primary:hover { background: #106ebe; }
.btn.danger { color: var(--danger); border-color: #f1bcbd; }

kbd {
  font: 11.5px/1.6 'Segoe UI', system-ui, sans-serif; background: var(--surface-2);
  border: 1px solid var(--stroke-2); border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; color: var(--text-2);
}
.sc-grid { display: grid; grid-template-columns: 1fr auto; gap: 7px 20px; font-size: 13px; align-items: center; }
.sc-grid h5 { grid-column: 1 / -1; margin: 12px 0 2px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-2); }

/* ---------------- import page picker ---------------- */
.card.picker { width: 720px; max-width: 92vw; }
.pick-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pick-controls .btn { padding: 5px 12px; font-size: 12.5px; }
.range-input {
  flex: 1; min-width: 150px; padding: 6px 10px; border: 1px solid var(--stroke-2);
  border-radius: 6px; font-size: 13px; background: var(--surface);
}
.range-input:focus { outline: none; border-color: var(--accent-2); }
.pick-count { font-size: 12.5px; color: var(--text-2); white-space: nowrap; }

.pick-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px;
  max-height: 46vh; overflow-y: auto; padding: 4px; border: 1px solid var(--stroke);
  border-radius: 8px; background: var(--surface-2);
}
.pick-tile {
  position: relative; padding: 0; border: 2px solid transparent; border-radius: 6px;
  background: #fff; box-shadow: inset 0 0 0 1px var(--stroke); overflow: hidden;
}
.pick-tile:hover { box-shadow: inset 0 0 0 1px var(--stroke-2), 0 2px 6px rgba(0,0,0,.12); }
.pick-tile.on { border-color: var(--accent-2); }
.pick-thumb-img {
  display: block; width: 100%; aspect-ratio: 1 / 1.3; background: #fff center/contain no-repeat;
}
.pick-num {
  position: absolute; left: 4px; bottom: 4px; font-size: 11px; color: var(--text-2);
  background: rgba(255,255,255,.9); border-radius: 3px; padding: 0 5px;
}
.pick-check {
  position: absolute; right: 4px; top: 4px; width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; background: var(--surface); color: transparent;
  box-shadow: inset 0 0 0 1px var(--stroke-2);
}
.pick-tile.on .pick-check { background: var(--accent-2); color: #fff; box-shadow: none; }

/* ================================================================= *
 *  Narrow and short windows
 *
 *  The zoom and page readouts belong in the bottom-right corner - that is
 *  where people reach for them, and moving them is more disruptive than the
 *  overlap they were moved to avoid.
 *
 *  The toolbar is a centred row about 825px wide; the readouts are about
 *  230px. Centred against right-anchored, they start to collide at roughly
 *  1310px. So instead of lifting the readouts, the toolbar stops centring on
 *  the window and centres on the space to the LEFT of them. It shifts a
 *  little left of true centre, and it never reaches the corner.
 *
 *  Only when the window is too narrow for even that (under 860px on fine
 *  pointer, or on touch tablets) does the toolbar take the full width and the
 *  readouts step up out of its way.
 * ================================================================= */
@media (max-width: 1340px) {
  #toolbar {
    left: 12px; right: 252px;
    transform: none;
    width: max-content;
    margin: 0 auto;                            /* centre in what is left */
    max-width: calc(100vw - 276px);
  }
}

@media (max-width: 1080px) {
  .tb-btn span { display: none; }              /* icons still say what they do */
  .tb-btn { padding: 0 8px; }
  #boardTitle { max-width: 30vw; }
}

@media (max-width: 860px) {
  /* no room to sit beside the readouts any more: take the width and let them
     step up instead */
  #toolbar {
    left: 8px; right: 8px;
    max-width: none;
    overflow-x: auto; overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    justify-content: flex-start;
    padding-top: 12px;                         /* a lifted pen must not be clipped */
  }
  #toolbar::-webkit-scrollbar { height: 6px; }
  #toolbar::-webkit-scrollbar-thumb { background: var(--stroke); border-radius: 3px; }
  .tool { width: 36px; height: 36px; }
  .pen { flex: 0 0 auto; }
  #zoombar { right: 8px; bottom: 98px; }
  #pagebar { right: 8px; bottom: 146px; }
  .panel { width: min(340px, 92vw); }
}

@media (max-width: 620px) {
  #zoombar [data-cmd="zoomIn"], #zoombar [data-cmd="zoomOut"] { display: none; }
  #toasts { max-width: 92vw; }
}

/* A snapped window is often short as well as narrow. */
@media (max-height: 620px) {
  #toolbar { bottom: 8px; }
}

@media (max-width: 860px) and (max-height: 620px) {
  #zoombar { bottom: 92px; }
  #pagebar { bottom: 140px; }
}

/* Mobile touch target sizing and comfortable pointer rules */
@media (pointer: coarse) {
  .tb-btn { min-width: 38px; height: 38px; }
  .tool { width: 44px; height: 44px; }
  .pen { width: 36px; height: 50px; }
  #zoombar button, #pagebar button { width: 36px; height: 36px; }

  /* Typing into a note or a text box: the keyboard has the bottom half of the
     screen and the toolbar was landing on the box itself. Pens are no use
     mid-word, so they stand down until the words are finished. Touch only -
     on a desktop the toolbar is nowhere near what you are typing. */
  body.typing #toolbar, body.typing #pagebar { display: none; }
  .icon-btn { width: 38px; height: 38px; }
  .btn { min-height: 38px; }
  .menu-item { padding: 10px 12px; }
  .sw { width: 30px; height: 30px; }

  /* Android Tablet & Touch Viewports */
  @media (max-width: 1240px) {
    #toolbar {
      left: 8px; right: 8px;
      transform: none;
      width: max-content;
      max-width: calc(100vw - 16px);
      margin: 0 auto;
      overflow-x: auto; overflow-y: visible;
      -webkit-overflow-scrolling: touch;
      padding-top: 12px;
    }
    /*
     * `top: auto` is not decoration - it is the whole fix for a bug that only
     * ever appeared on a phone.
     *
     * The short-screen rule below sends these to the TOP of the board, setting
     * top and clearing bottom. This block then set bottom again and said
     * nothing about top, so on a touch device where both apply, the element
     * ended up with a top AND a bottom - and an absolutely positioned box given
     * both does not move, it STRETCHES between them. With the keyboard open on
     * a phone the zoom readout became a 276-pixel-tall white column down the
     * side of the screen. On a desktop it never happened, because none of this
     * block applies without a coarse pointer.
     *
     * Rule for anything positioned here: whichever edge you set, clear the
     * other one.
     */
    #zoombar { right: 8px; top: auto; bottom: 98px; }
    #pagebar { right: 8px; top: auto; bottom: 148px; }
  }
}

/* Very short and narrow: nothing stacks, so the readouts go to the top right
   and leave the bottom entirely to the pens.

   This sits AFTER the coarse-pointer block on purpose. Both can apply at once -
   a phone in landscape, or any phone with the keyboard open - and the later one
   wins. Put this first and the touch rules quietly moved the readouts back to
   the bottom, which is exactly when there is no room for them. */
@media (pointer: fine) and (max-width: 860px) and (max-height: 460px) {
  #zoombar { top: 8px; bottom: auto; }
  #pagebar { top: 52px; bottom: auto; }
}

/* Touch readouts stay just above the pens in both orientations. */
@media (pointer: coarse) {
  #zoombar { top: auto; bottom: 98px; right: 8px; }
  #pagebar { top: auto; bottom: 148px; right: 8px; }
  #ctxbar { max-width: calc(100% - 16px); overflow-x: auto; }
  #ctxbar button { flex-shrink: 0; }
}

/*
 * ...unless the keyboard has taken the bottom.
 *
 * The rule above pins the readouts above the pen tray, which is right until
 * there is no bottom left to sit above: with the on-screen keyboard open the
 * viewport is half as tall and 98px from the bottom is underneath it. The
 * short-screen rule that moves them to the top used to cover this and was
 * narrowed to `pointer: fine`, which excludes every phone - the one kind of
 * screen that HAS an on-screen keyboard.
 *
 * This has to come after the block above, and it has to set `bottom: auto`.
 * A box given both a top and a bottom does not move, it stretches, and that is
 * how the zoom readout once became a 276-pixel white column down the side.
 *
 * Portrait only. A short screen is EITHER a phone with the keyboard open or a
 * phone turned on its side, and only the first one has lost its bottom - a
 * landscape phone has a perfectly good pen tray down there with room above it,
 * and moving the readouts to the top there just puts them somewhere nobody is
 * looking. A keyboard-shrunk portrait viewport is still taller than it is wide
 * (412x430 on the phone this was measured on), so the two cases separate
 * cleanly on orientation.
 */
@media (pointer: coarse) and (max-height: 460px) and (orientation: portrait) {
  #zoombar { top: 8px; bottom: auto; }
  #pagebar { top: 52px; bottom: auto; }
}

/* Smartphone portrait viewports (under 480px width) */
@media (max-width: 480px) {
  #topbar { gap: 2px; padding: 0 6px; }
  #boardTitle { min-width: 80px; max-width: 140px; font-size: 13.5px; padding: 4px 6px; }
  .badge { display: none; }
  .tb-btn { padding: 0 5px; }
  .panel { width: 100vw; border-left: none; }
  .card { max-width: calc(100vw - 20px); padding: 16px 14px; }
  .pop { max-width: calc(100vw - 24px); }
  .tpl-grid { grid-template-columns: 1fr; }
}


/* ------------------------------------------------------------------ *
 *  A board arriving
 *
 *  Someone may be writing on the board when a colleague hits Send, so this
 *  lives IN the top bar rather than over the canvas: it cannot cover ink,
 *  and showing or hiding it never moves the drawing surface. The ring is a
 *  conic gradient, so filling it is one style write the compositor handles -
 *  no layout, no repaint of the board behind it.
 * ------------------------------------------------------------------ */
/*
 * Amber, not the app's own blue.
 *
 * Every other accent in GazBoard is blue, so a blue badge is one more blue
 * thing on a blue toolbar - the eye slides straight off it. Amber appears
 * nowhere else in the app, which is the entire reason it works: something has
 * changed, and it is the only warm thing on the screen.
 *
 * Fixed colours rather than theme variables, again on purpose. This has one
 * job in both light and dark, and it should look the same doing it.
 */
#rxBadge {
  --rx-amber: #d97706;
  --rx-amber-strong: #ea580c;
  --rx-green: #15803d;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 5px;
  margin-right: 4px;
  border-radius: 999px;
  background: rgba(217, 119, 6, .14);
  border: 1.5px solid var(--rx-amber);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--rx-amber);
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
}
#rxBadge.show { display: flex; }

#rxBadge .rx-ring {
  width: 18px;
  height: 18px;
  flex: none;
  border-radius: 50%;
  background: conic-gradient(var(--rx-amber) 0deg, rgba(217, 119, 6, .22) 0deg);
  /* the hole in the middle, so it reads as a ring rather than a pie */
  -webkit-mask: radial-gradient(circle, transparent 5px, #000 5.5px);
  mask: radial-gradient(circle, transparent 5px, #000 5.5px);
}

/* Landed. Green for a few seconds, because "it is here" and "it is coming"
   should not look the same at a glance from the back of a room. */
#rxBadge.done {
  background: rgba(21, 128, 61, .14);
  border-color: var(--rx-green);
  color: var(--rx-green);
}
#rxBadge.done .rx-ring {
  background: var(--rx-green);
  -webkit-mask: none;
  mask: none;
}

#rxBadge .rx-label { overflow: hidden; text-overflow: ellipsis; }

/* =================================================================
 *  The compact phone bar.
 *
 *  Nine buttons, no scrolling, no wrapping. The whole point is that the pen
 *  you want is where your thumb already is, so nothing here is allowed to push
 *  the row wider than the screen: the buttons share what space there is and
 *  shrink together rather than sliding out of reach.
 * ================================================================= */
#toolbar.phone {
  left: 6px; right: 6px;
  /* The wider-screen rules above set `width: max-content`, which lets the row
     decide its own width and push past the edge of a handset. Both edges are
     pinned here instead, so the screen decides and the buttons share it. */
  width: auto;
  box-sizing: border-box;
  max-width: none;
  transform: none;
  margin: 0;
  gap: 2px;
  padding: 8px 6px 9px;
  justify-content: space-evenly;
  overflow: visible;                 /* a raised pen must not be clipped */
  bottom: 10px;
}
#toolbar.phone .pen,
#toolbar.phone .tool {
  flex: 0 1 auto;
  min-width: 0;
}
#toolbar.phone .tool-sm { width: 38px; height: 38px; margin-bottom: 4px; }
/* No keyboard on a phone, so no letters to advertise. */
#toolbar.phone .kbd { display: none; }
#toolbar.phone .sep { margin: 0 1px; }

/* Narrow handsets: give the row the last few pixels rather than a scrollbar. */
@media (max-width: 400px) {
  #toolbar.phone { gap: 0; padding-left: 3px; padding-right: 3px; }
  #toolbar.phone .tool-sm { width: 34px; height: 34px; }
}

/*
 * On a phone it leaves the bar and becomes a strip of its own.
 *
 * It used to shrink to a 34px stub with the name hidden, on the grounds that
 * the top bar had no room. What that produced was a half-filled circle sitting
 * in a row of buttons, saying nothing: you could see something was happening
 * and not what, or who from, or whether it concerned you. A progress ring with
 * no subject is just movement in the corner of your eye while you are writing.
 *
 * So on a phone it lifts out of the bar and floats under the top edge, wide
 * enough to carry the sender's name, and it is calm: no pulse, no solid
 * orange, muted against the board. Loud enough to read at a glance, quiet
 * enough to write underneath.
 */
@media (max-width: 760px) {
  #rxBadge {
    position: fixed;
    left: 50%;
    top: calc(env(safe-area-inset-top, 0px) + 8px);
    transform: translateX(-50%);
    z-index: 40;
    max-width: min(86vw, 340px);
    margin: 0;
    padding: 6px 14px 6px 8px;
    background: var(--panel, #fff);
    border-color: rgba(217, 119, 6, .55);
    box-shadow: 0 3px 14px rgba(0, 0, 0, .16);
    font-size: 13px;
  }
  #rxBadge .rx-label { display: block; }
  /* It announces itself by arriving, not by flashing. */
  #rxBadge.alert {
    background: var(--panel, #fff);
    border-color: var(--rx-amber);
    color: var(--rx-amber);
    animation: rx-slide .28s ease-out 1;
  }
  #rxBadge.alert .rx-ring {
    background: conic-gradient(var(--rx-amber) 0deg, rgba(217, 119, 6, .22) 0deg);
  }
  #rxBadge.done {
    background: var(--panel, #fff);
    border-color: var(--rx-green);
  }
}

@keyframes rx-slide {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/*
 * The first couple of seconds of a board arriving.
 *
 * Only box-shadow, border-colour and the badge's own background move. None of
 * those affect layout, so the toolbar does not shift and the canvas is never
 * asked to repaint - the animation runs on the compositor while somebody
 * carries on writing underneath it.
 */
/* The first two and a half seconds: filled in, not merely outlined. Somebody
   looking at their own handwriting has to catch this out of the corner of an
   eye, so it is solid colour and it moves. */
#rxBadge.alert {
  background: var(--rx-amber-strong);
  border-color: var(--rx-amber-strong);
  color: #fff;
  animation: rx-pulse 1.1s ease-out 3;
}
#rxBadge.alert .rx-ring {
  background: conic-gradient(#fff 0deg, rgba(255, 255, 255, .35) 0deg);
}

@keyframes rx-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(234, 88, 12, .6); }
  70%  { box-shadow: 0 0 0 11px rgba(234, 88, 12, 0); }
  100% { box-shadow: 0 0 0 0 rgba(234, 88, 12, 0); }
}

/* Someone who has asked their system for less movement gets the colour change
   and no pulse. The chime and the ring still do their job. */
@media (prefers-reduced-motion: reduce) {
  #rxBadge.alert { animation: none; }
}
