:root {
  --bg: #f3f4fb;
  --bar: #ffffff;
  --line: #e3e6f0;
  --fg: #1b2133;
  --muted: #6a7389;
  --accent: #5b4cf0;
  --accent-2: #2f80ff;
  --accent-fg: #ffffff;
  --grad: linear-gradient(135deg, #2f80ff 0%, #5b4cf0 55%, #a64bf4 100%);
  --sel: #5b4cf0;
  --hover: rgba(91, 76, 240, 0.1);
  --radius: 12px;
  --shadow: 0 1px 2px rgba(27, 33, 51, .06), 0 8px 24px rgba(27, 33, 51, .08);
  --ease: cubic-bezier(.2, .8, .2, 1);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); display: flex; flex-direction: column; }
.muted { color: var(--muted); }

/* ---------- top bar ---------- */
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 10px 16px; background: var(--bar); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; box-shadow: 0 2px 12px rgba(27, 33, 51, .04); }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 750; font-size: 15px; color: var(--fg); text-decoration: none; }
.brand span:last-child { color: var(--muted); font-weight: 600; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--grad); color: #fff; font-weight: 800; font-size: 17px; box-shadow: 0 4px 12px rgba(91, 76, 240, .35); }
.group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.right { margin-left: auto; }
.btn, .tool { border: 1px solid var(--line); background: #fff; color: var(--fg); border-radius: 10px; padding: 7px 12px; font: inherit; cursor: pointer; transition: background .18s var(--ease), border-color .18s var(--ease), transform .18s var(--ease), box-shadow .18s var(--ease), color .18s; }
.btn:hover, .tool:hover { background: #f5f4ff; border-color: #cfc9ff; transform: translateY(-1px); }
.btn:active, .tool:active { transform: translateY(0) scale(.98); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.primary { background: var(--grad); border-color: transparent; color: var(--accent-fg); font-weight: 650; box-shadow: 0 6px 16px rgba(91, 76, 240, .3); }
.btn.primary:hover { box-shadow: 0 8px 22px rgba(91, 76, 240, .4); }
.btn.sq { min-width: 34px; padding: 7px 0; text-align: center; }
.btn.on { background: #efedff; border-color: var(--sel); color: var(--accent); }
.btn.busy { position: relative; overflow: hidden; }
.btn.busy::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .45), transparent); animation: shimmer 1.1s linear infinite; }
.tool.active { background: var(--fg); color: #fff; border-color: var(--fg); box-shadow: 0 4px 12px rgba(27, 33, 51, .25); }
.btn:focus-visible, .tool:focus-visible, .linkbtn:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }
.props { transition: opacity .2s var(--ease); }
.props.off { visibility: hidden; opacity: 0; }
.props select, .props input[type=number], .penbar select { border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; font: inherit; background: #fff; }
.props input[type=number] { width: 70px; }
.props input[type=color], .penbar input[type=color], .sign input[type=color] { width: 34px; height: 32px; border: 1px solid var(--line); border-radius: 10px; padding: 2px; background: #fff; cursor: pointer; }
.range { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.range input[type=number] { width: 62px; }
.range input[type=range] { width: 92px; accent-color: var(--accent); }
.range output { min-width: 48px; font-variant-numeric: tabular-nums; color: var(--fg); }
.zoom { display: inline-flex; gap: 4px; margin-right: 4px; }
#zoomFit { min-width: 62px; font-variant-numeric: tabular-nums; }
.penbar { padding: 4px 8px; border-radius: 12px; background: #f5f4ff; border: 1px solid #e2defe; animation: pop .25s var(--ease); }

/* ---------- viewer & start page ---------- */
#viewer { flex: 1; overflow: auto; padding: 24px 16px 80px; position: relative; }
#viewer.drag { outline: 3px dashed var(--sel); outline-offset: -12px; }
.landing { max-width: 820px; margin: 0 auto; text-align: center; color: var(--muted); padding-bottom: 40px; animation: rise .5s var(--ease) backwards; }
.landing h1 { margin: 20px 0 6px; font-size: 44px; letter-spacing: -.02em; color: var(--fg); background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.landing .sub { margin: 0 0 26px; font-weight: 600; color: #4a5266; font-size: 16px; }
.drop { border: 2px dashed #c9c3ff; border-radius: 22px; padding: 40px 24px 30px; background: linear-gradient(180deg, #ffffff, #f8f7ff); display: flex; flex-direction: column; align-items: center; gap: 14px; transition: border-color .2s, background .2s, transform .2s var(--ease); box-shadow: var(--shadow); }
.drop:hover { border-color: var(--accent); }
#viewer.drag .drop { background: #f1efff; transform: scale(1.01); border-color: var(--accent); }
.drop-icon { width: 64px; height: 64px; border-radius: 20px; background: var(--grad); display: grid; place-items: center; box-shadow: 0 10px 24px rgba(91, 76, 240, .35); animation: float 3s ease-in-out infinite; }
.drop-icon svg { width: 34px; height: 34px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.bigbtn { display: block; width: min(420px, 100%); background: var(--grad); color: #fff; font-weight: 700; font-size: 18px; padding: 20px 16px; border-radius: 16px; cursor: pointer; box-shadow: 0 10px 24px rgba(91, 76, 240, .32); transition: transform .2s var(--ease), box-shadow .2s var(--ease); }
.bigbtn:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(91, 76, 240, .42); }
.drop p { margin: 0; font-size: 16px; color: #8a91a5; }
.linkbtn { border: 0; background: none; color: var(--accent); font: 600 14px/1.4 system-ui, sans-serif; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.linkbtn:hover { background: var(--hover); }
.private { font-size: 13px; margin: 12px 0 0; }
.landing h2 { margin: 44px 0 18px; font-size: 24px; color: var(--fg); }
.steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.steps li { background: #fff; border-radius: 18px; padding: 18px 16px; box-shadow: var(--shadow); animation: rise .5s var(--ease) backwards; }
.steps li:nth-child(2) { animation-delay: .07s; }
.steps li:nth-child(3) { animation-delay: .14s; }
.steps svg { width: 72px; height: 72px; fill: #efedff; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.steps h3 { margin: 8px 0 4px; font-size: 16px; color: var(--fg); }
.steps p { margin: 0; font-size: 13.5px; }
.tools-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.tools-grid button { text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; font: 600 15px/1.3 system-ui, sans-serif; color: var(--fg); cursor: pointer; transition: transform .2s var(--ease), box-shadow .2s var(--ease), border-color .2s; }
.tools-grid button::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 4px; background: var(--grad); margin-right: 10px; vertical-align: 0; }
.tools-grid button:hover { border-color: #cfc9ff; transform: translateY(-2px); box-shadow: var(--shadow); }
@media (max-width: 640px) { .steps, .tools-grid { grid-template-columns: 1fr; } .landing h1 { font-size: 32px; } .bar { padding: 8px 10px; } .brand span:last-child { display: none; } }
/* Phones: compact top bar; tools in a scrollable bottom bar, text/pen controls just above it (thumb reach). */
@media (max-width: 640px) {
  .bar { position: relative; gap: 6px; }
  .brand { font-size: 0; gap: 0; }
  .brand-mark { font-size: 16px; width: 32px; height: 32px; }
  .btn, .tool { padding: 7px 10px; font-size: 13px; }
  .props.off { display: none; }
  .tools, .props:not(.off), .penbar { position: fixed; left: 0; right: 0; z-index: 30; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; background: rgba(255, 255, 255, .96); backdrop-filter: blur(12px); padding: 8px 10px; }
  .tools::-webkit-scrollbar, .props::-webkit-scrollbar, .penbar::-webkit-scrollbar { display: none; }
  .tools { bottom: 0; padding-bottom: max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(27, 33, 51, .08); }
  .props:not(.off), .penbar { bottom: calc(52px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; animation: rise .2s var(--ease); }
  .penbar { border: 0; border-top: 1px solid var(--line); background: rgba(245, 244, 255, .97); }
  .tool, .tools select, .props > *, .penbar > * { flex: none; }
  .stylebar { font-size: 12.5px; min-height: 0; padding-top: 6px; }
  #viewer { padding: 14px 10px 150px; }
  .page-tools { max-width: calc(100vw - 20px); }
  .toast { bottom: 120px; }
}

/* max-content + min-width keeps wide pages scrollable instead of cut off on the left. */
#pages { display: flex; flex-direction: column; align-items: center; gap: 28px; width: max-content; min-width: 100%; }
.page-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; animation: rise .45s var(--ease) backwards; }
.page-wrap.moved { animation: pop .35s var(--ease); }
.page-tools { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; flex-wrap: wrap; justify-content: center; }
.page-tools .num { font-weight: 600; color: var(--fg); margin-right: 4px; }
.page-tools button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 4px 9px; font-size: 12px; cursor: pointer; transition: background .15s, border-color .15s; }
.page-tools button:hover { background: #f5f4ff; border-color: #cfc9ff; }
.ocr-status.busy::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; border: 2px solid #cfc9ff; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
.page-box { position: relative; }
.page { position: relative; background: #fff; transform-origin: 0 0; box-shadow: 0 1px 3px rgba(27, 33, 51, .12), 0 12px 32px rgba(27, 33, 51, .1); border-radius: 2px; }
.page canvas { display: block; }
.page canvas.sharp { position: absolute; left: 0; top: 0; pointer-events: none; }
/* edited text painted like the page's own letters: same box and pixels as the page picture, right above it */
.page canvas.paint-layer { position: absolute; left: 0; top: 0; pointer-events: none; }
.layer { position: absolute; inset: 0; }
.hits { z-index: 1; }
.items { z-index: 2; pointer-events: none; }
.items > * { pointer-events: auto; }
body[data-tool="text"] .page, body[data-tool="cover"] .page { cursor: crosshair; }
body:not([data-tool="edit"]) .hits { display: none; }
body.loading #viewer::before { content: ""; position: sticky; top: 0; display: block; height: 3px; margin: -24px -16px 21px; background: var(--grad); background-size: 200% 100%; animation: slide 1.2s linear infinite; z-index: 5; }

.stylebar { flex-basis: 100%; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 8px; border-top: 1px solid var(--line); color: var(--muted); min-height: 44px; }
#styleInfo, #penInfo { color: var(--fg); animation: fade .25s var(--ease); }
#styleInfo b { font-weight: 650; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 4px; border: 1px solid var(--line); vertical-align: -1px; }

/* Editable text is outlined only while the pointer is over the page, so the page itself looks untouched. */
.hit { position: absolute; cursor: text; border-radius: 3px; outline: 1px dashed transparent; transition: background .15s, outline-color .15s; }
.page:hover .hit { outline-color: rgba(91, 76, 240, .35); }
body.preview .hits, body.preview .handle, body.preview .item-cover { pointer-events: none; }
body.preview .hits { display: none; }
body.preview .item.selected { outline: none; }
body.preview .handle { display: none !important; }
#previewBtn.on { background: #efedff; border-color: var(--sel); color: var(--accent); }
.hit:hover { background: var(--hover); outline: 1.5px solid rgba(91, 76, 240, .85); }
.item-cover { cursor: text; }

.item { position: absolute; }
.item.enter { animation: pop .22s var(--ease); }
.item.selected { outline: 1.5px solid var(--sel); outline-offset: 2px; border-radius: 2px; }
.item .glyphs { position: absolute; left: 0; top: 0; pointer-events: none; line-height: 0; }
.item .txt { white-space: pre; line-height: 1; outline: none; min-width: 4px; display: inline-block; cursor: text; position: relative; }
.item .txt.ghost { color: transparent !important; text-decoration-color: transparent !important; }
.item .txt.ghost::selection { background: rgba(91, 76, 240, .25); }
.item.rect, .item.image { cursor: move; }
.item.image img { width: 100%; height: 100%; display: block; pointer-events: none; }
.handle { position: absolute; width: 14px; height: 14px; background: var(--sel); border: 2px solid #fff; border-radius: 50%; display: none; box-shadow: 0 2px 6px rgba(27, 33, 51, .3); }
.item.selected .handle { display: block; }
.handle.move { left: -18px; top: -18px; cursor: move; }
.handle.size { right: -8px; bottom: -8px; cursor: nwse-resize; }
.draft { position: absolute; border: 1.5px dashed var(--sel); background: rgba(255, 255, 255, .6); border-radius: 2px; }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 20px; padding: 0; box-shadow: 0 30px 80px rgba(27, 33, 51, .3); max-width: calc(100vw - 32px); }
dialog[open] { animation: pop .25s var(--ease); }
dialog::backdrop { background: rgba(27, 33, 51, .35); backdrop-filter: blur(3px); }
.sign { padding: 20px; display: flex; flex-direction: column; gap: 12px; width: min(620px, calc(100vw - 32px)); }
.sign h2 { margin: 0; font-size: 18px; }
.tabs { display: inline-flex; gap: 4px; padding: 4px; background: #f1f2f8; border-radius: 12px; align-self: flex-start; }
.tabs button { border: 0; background: none; padding: 7px 14px; border-radius: 9px; font: 600 13px/1 system-ui, sans-serif; color: var(--muted); cursor: pointer; transition: background .15s, color .15s; }
.tabs button.on { background: #fff; color: var(--fg); box-shadow: 0 1px 4px rgba(27, 33, 51, .12); }
.tab-panel { animation: fade .2s var(--ease); display: flex; flex-direction: column; gap: 10px; }
#signPad, #signUploadPreview { border: 1px solid var(--line); border-radius: 14px; width: 100%; max-width: 100%; touch-action: none; cursor: crosshair; background: repeating-linear-gradient(0deg, #fff 0 39px, #f1f2f8 39px 40px); }
#signName, .find input[type=text] { border: 1px solid #d9dcea; border-radius: 12px; padding: 11px 13px; font: inherit; font-size: 16px; }
.sign-styles { display: grid; gap: 8px; }
.sign-style { border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 0; cursor: pointer; overflow: hidden; height: 66px; transition: border-color .15s, box-shadow .15s; }
.sign-style canvas { width: 100%; height: 100%; display: block; object-fit: contain; }
.sign-style.on { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 76, 240, .15); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--fg); color: #fff; padding: 11px 18px; border-radius: 14px; z-index: 50; max-width: calc(100vw - 32px); box-shadow: 0 12px 30px rgba(27, 33, 51, .3); pointer-events: none; }
.toast.show { animation: toast .3s var(--ease); }

/* Highlight, drawing, shapes and links */
.shape-kind { height: 34px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font: inherit; font-size: 12px; padding: 0 6px; }
.item.hl { cursor: move; mix-blend-mode: multiply; }
.item.shape, .item.draw, .item.link { cursor: move; }
.item.shape svg, .item.draw svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.item.link { border: 1.5px dashed #2563eb; background: rgba(37, 99, 235, .08); border-radius: 4px; }
.item.link .link-url { position: absolute; left: 0; top: -20px; font: 11px/16px system-ui, sans-serif; color: #1d4ed8; background: #fff; padding: 1px 6px; border-radius: 6px; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 1px 4px rgba(27, 33, 51, .12); }
.draft.hl { background: rgba(255, 235, 59, .4); border-color: #e0b800; }
.draft-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
body[data-tool="highlight"] .page, body[data-tool="draw"] .page, body[data-tool="shape"] .page, body[data-tool="link"] .page { cursor: crosshair; }
body[data-tool="draw"][data-pen="eraser"] .page { cursor: cell; }
.find label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; margin: 6px 0; }
.find label.check { flex-direction: row; align-items: center; }
.find-note { font-size: 12px; color: #667085; margin: 4px 0 8px; }

/* ---------- work area with side panel ---------- */
.work { flex: 1; display: flex; min-height: 0; }
.work > #viewer { min-width: 0; }
.side { width: 330px; flex: none; border-left: 1px solid var(--line); background: var(--bar); display: flex; flex-direction: column; min-height: 0; animation: slidein .25s var(--ease); }
.side-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.side-head .tabs { flex: 1; }
.side-body { padding: 12px; overflow: auto; display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 0; }
.side input[type=search], .side textarea, .who input, .field input, .field textarea, #aiPrompt, #collabLink { border: 1px solid #d9dcea; border-radius: 10px; padding: 8px 10px; font: inherit; width: 100%; background: #fff; }
.side input[type=search]:focus, .side textarea:focus, .field input:focus, .field textarea:focus, #aiPrompt:focus { outline: 2px solid rgba(91, 76, 240, .35); border-color: var(--accent); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 10px; font: 600 12px/1.3 system-ui, sans-serif; color: var(--muted); cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.chip.on, .chip:hover { background: #efedff; color: var(--accent); border-color: #cfc9ff; }
.el-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.el-tile { aspect-ratio: 1; border: 1px solid var(--line); background: #fff; border-radius: 12px; display: grid; place-items: center; padding: 8px; cursor: pointer; transition: transform .15s var(--ease), box-shadow .15s, border-color .15s; }
.el-tile svg { width: 100%; height: 100%; }
.el-tile:hover { transform: translateY(-2px); border-color: #cfc9ff; box-shadow: var(--shadow); }
.photo-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.photo-tile { border: 0; padding: 0; border-radius: 12px; overflow: hidden; cursor: pointer; aspect-ratio: 4 / 3; background: #eef0f6; position: relative; transition: transform .15s var(--ease), box-shadow .15s; }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.photo-tile.busy::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .5), transparent); animation: shimmer 1s linear infinite; }
.pop-note { font-size: 12px; color: var(--muted); margin: 0; }
.count { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #f59e0b; color: #fff; font-size: 11px; }
.count:empty { display: none; }
.who { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.side .check, .find .check { display: flex; gap: 8px; align-items: center; font-size: 13px; }

/* Comments */
.item.comment { z-index: 3; cursor: grab; }
.pin { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 13px 13px 13px 3px; background: var(--c, #f59e0b); color: #fff; font: 700 12px/1 system-ui, sans-serif; box-shadow: 0 4px 12px rgba(27, 33, 51, .25); border: 2px solid #fff; transition: transform .15s var(--ease); }
.item.comment:hover .pin, .item.comment.selected .pin { transform: scale(1.12); }
.item.comment.selected { outline: none; }
.item.comment.resolved { opacity: .45; }
.pin.small { width: 20px; height: 20px; font-size: 10.5px; border-width: 1.5px; box-shadow: none; }
.thread { border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 8px; background: #fff; transition: border-color .15s, box-shadow .15s; animation: rise .25s var(--ease) backwards; }
.thread.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 76, 240, .12); }
.thread.resolved { opacity: .7; }
.thread-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.thread .msg { font-size: 13px; }
.thread .msg p { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.thread .reply { resize: vertical; min-height: 40px; }
.thread .post { align-self: flex-end; }
.linkbtn.danger { color: #dc2626; }

/* Popovers: effects and AI */
.popover { position: fixed; z-index: 40; background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 20px 50px rgba(27, 33, 51, .22); padding: 12px; display: flex; flex-direction: column; gap: 10px; width: min(460px, calc(100vw - 16px)); animation: pop .2s var(--ease); }
.fx-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.fx-row .check { display: inline-flex; align-items: center; gap: 6px; min-width: 104px; font-weight: 600; }
.fx-row input[type=color] { width: 32px; height: 28px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: #fff; }
.fx-row select { border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; font: inherit; }
.ai-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
#aiPanel .row select { border: 1px solid var(--line); border-radius: 10px; padding: 7px 8px; font: inherit; flex: 1; }
#aiPanel .row input { flex: 1; }
.seg { display: inline-flex; gap: 2px; }
.seg .btn.sq svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; vertical-align: -3px; }

/* Text box extras */
.item .tbg { position: absolute; left: 0; top: 0; pointer-events: none; }
.handle.width { width: 8px; height: 22px; border-radius: 4px; cursor: ew-resize; }
.item.text .handle.width { display: none; }
.item.text.selected .handle.width { display: block; }
.item.element, .item.chart, .item.table { cursor: move; }
.item.element svg, .item.chart svg, .item.table svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.cell-edit { position: absolute; z-index: 4; outline: 2px solid var(--accent); white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 6px 18px rgba(27, 33, 51, .18); cursor: text; }

/* Dialog fields */
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; }
.field .muted { font-weight: 400; font-size: 12px; }
.field textarea { font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; resize: vertical; }
.chart-dlg { width: min(560px, calc(100vw - 32px)); }
.chart-preview { border: 1px solid var(--line); border-radius: 14px; background: #fff; display: grid; place-items: center; padding: 8px; min-height: 120px; }
.chart-preview svg { width: 100%; height: auto; max-height: 260px; }
.erase-dlg { width: min(880px, calc(100vw - 32px)); }
.erase-stage { position: relative; align-self: center; max-width: 100%; background: repeating-conic-gradient(#eef0f6 0 25%, #fff 0 50%) 0 0 / 16px 16px; border-radius: 12px; overflow: hidden; }
.erase-stage canvas { display: block; max-width: 100%; height: auto !important; }
#eraseMask { position: absolute; inset: 0; width: 100% !important; touch-action: none; cursor: crosshair; }

/* Live collaboration */
.people { display: inline-flex; margin-right: 2px; }
.people:empty { display: none; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font: 700 12px/1 system-ui, sans-serif; border: 2px solid #fff; margin-left: -6px; box-shadow: 0 2px 6px rgba(27, 33, 51, .2); animation: pop .25s var(--ease); }
.avatar:first-child { margin-left: 0; }
#collabBtn.on { background: #ecfdf5; border-color: #34d399; color: #047857; }
#collabBtn.on::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #10b981; margin-right: 6px; animation: pulse 1.6s ease-in-out infinite; }
body.collab-offline #collabBtn.on::before { background: #f59e0b; animation: none; }
#collabLink { flex: 1; min-width: 0; font-size: 12.5px; }
.cursor { position: absolute; z-index: 6; pointer-events: none; transition: left .12s linear, top .12s linear; }
.cursor svg { width: 18px; height: 18px; display: block; }
.cursor span { position: absolute; left: 14px; top: 14px; color: #fff; font: 600 11px/1 system-ui, sans-serif; padding: 3px 6px; border-radius: 6px; white-space: nowrap; }
.item.remote-sel { outline: 1.5px dashed #10b981; outline-offset: 3px; }

@media (max-width: 640px) {
  .side { position: fixed; left: 0; right: 0; width: auto; bottom: calc(52px + env(safe-area-inset-bottom)); height: 62vh; z-index: 35; border-left: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; box-shadow: 0 -12px 30px rgba(27, 33, 51, .18); animation: rise .25s var(--ease); }
  .el-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .popover { left: 8px !important; right: 8px; top: auto !important; bottom: calc(110px + env(safe-area-inset-bottom)); width: auto; max-height: 60vh; overflow: auto; }
  .ai-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .people { display: none; }
  .hide-sm { display: none; }
}

/* ---------- motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes float { 50% { transform: translateY(-5px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
@keyframes slide { from { background-position: 0 0; } to { background-position: 200% 0; } }
@keyframes slidein { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- FIX-4: Canva-style header on desktop (> 640 px). One top bar (file, history, actions); the tools on their
   own row, never cut off (tools that do not fit go into "More"); the text and pen controls float over the page like
   Canva's contextual toolbar (no empty band when nothing is selected); tips sit in a small status line at the bottom. */
@media (min-width: 641px) {
  .bar { row-gap: 8px; padding: 8px 16px; }
  .bar > .tools { order: 10; flex: 1 0 100%; flex-wrap: nowrap; overflow: hidden; min-width: 0; }
  .bar > .tools > * { flex: none; }
  .bar > .tools > .folded { display: none; }
  .bar > .props, .bar > .penbar { position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%); max-width: calc(100vw - 24px); flex-wrap: wrap; justify-content: center; padding: 6px 10px; background: rgba(255, 255, 255, .98); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 26px rgba(27, 33, 51, .16); z-index: 25; }
  .bar > .props.off { pointer-events: none; }
  .bar > .stylebar { position: fixed; left: 12px; bottom: 12px; z-index: 24; flex-basis: auto; max-width: min(720px, calc(100vw - 24px)); min-height: 0; padding: 6px 12px; border: 1px solid var(--line); border-top: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, .96); box-shadow: 0 6px 20px rgba(27, 33, 51, .12); font-size: 12.5px; }
  .bar > .stylebar:not(:has(> :not([hidden]):not(.grow))) { display: none; }
  .more-tools-menu { position: fixed; z-index: 60; min-width: 190px; padding: 6px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 40px rgba(27, 33, 51, .2); display: flex; flex-direction: column; gap: 2px; }
  .more-tools-menu button { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; font: inherit; color: var(--fg); cursor: pointer; }
  .more-tools-menu button:hover, .more-tools-menu button:focus-visible { background: #f5f4ff; }
}
@media (min-width: 641px) and (max-width: 1100px) {
  .brand span:last-child { display: none; }
  .bar .btn, .bar .tool { padding: 6px 10px; }
}
