:root {
  --bg: #f7f7f5;
  --grid: rgba(0,0,0,.042);
  --dot: #d3d3cd;
  --panel: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b7280;
  --line: #e7e7e9;
  --hover: #f2f2f4;
  --accent: #4262ff;
  --accent-soft: #e9edff;
  --frame-border: #dcdcd8;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.08);
  --font: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #19191b;
  --grid: rgba(255,255,255,.045);
  --dot: #3a3a3e;
  --panel: #252528;
  --ink: #ececec;
  --muted: #9b9ba3;
  --line: #36363b;
  --hover: #303035;
  --accent: #6d8bff;
  --accent-soft: rgba(109,139,255,.18);
  --frame-border: #3a3a3f;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.45);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { display: block; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 14px; font-weight: 500; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.panel { background: var(--panel); border-radius: 10px; box-shadow: var(--shadow); }

/* ---------- home ---------- */
#home { min-height: 100%; }
.home-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 28px; background: var(--panel); border-bottom: 1px solid var(--line); }
.head-actions { display: flex; align-items: center; gap: 8px; }
.theme-btn svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; width: 20px; height: 20px; }
.theme-btn .sun { display: none; }
:root[data-theme="dark"] .theme-btn .sun { display: inline; }
:root[data-theme="dark"] .theme-btn .moon { display: none; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.logo-mark { width: 22px; height: 22px; border-radius: 4px; background: #ffd84d; box-shadow: inset -6px -6px 0 -3px #e6b800; }
#home main { max-width: 1200px; margin: 0 auto; padding: 28px; }
#home h1 { font-size: 22px; margin: 0 0 20px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.card { background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; transition: transform .12s, box-shadow .12s; }
.card:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(0,0,0,.06), 0 10px 28px rgba(0,0,0,.12); }
.card-link { color: inherit; text-decoration: none; display: block; }
.card-thumb { height: 150px; background: var(--bg) linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 16px 16px, var(--bg) linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 16px 16px; display: flex; align-items: center; justify-content: center; }
.card-thumb svg { width: 100%; height: 100%; }
.card-name { padding: 12px 14px 2px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { padding: 0 14px 12px; color: var(--muted); font-size: 13px; }
.card-actions { display: flex; border-top: 1px solid var(--line); }
.card-actions button { flex: 1; border: 0; background: none; padding: 8px; font-size: 13px; color: var(--muted); }
.card-actions button:hover { background: var(--hover); color: var(--ink); }
.card-actions button + button { border-left: 1px solid var(--line); }
.empty { color: var(--muted); }

/* ---------- board ---------- */
#app { position: fixed; inset: 0; overflow: hidden; }
#board {
  position: absolute; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  background-color: var(--bg);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
  cursor: default;
}
#board.tool-hand, #board.can-pan { cursor: grab; }
#board.panning { cursor: grabbing; }
#board.tool-sticky, #board.tool-text, #board.tool-rect, #board.tool-ellipse, #board.tool-diamond,
#board.tool-arrow, #board.tool-pen, #board.tool-frame, #board.tool-comment, #board.tool-mind { cursor: crosshair; }
#board.tool-hand .item, #board.can-pan .item { pointer-events: none !important; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; width: 0; height: 0; }
#overlay { position: absolute; inset: 0; pointer-events: none; }
#selLayer, #cursors, #commentLayer { position: absolute; inset: 0; }

.item { position: absolute; }
.item .txt { letter-spacing: -0.005em; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; outline: none; line-height: 1.35; cursor: inherit; }
.item.bold .txt { font-weight: 700; }
.item.editing .txt { cursor: text; user-select: text; -webkit-user-select: text; }
.txt-wrap { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 14px; overflow: hidden; }
.txt-wrap .txt { width: 100%; max-height: 100%; }
.item.editing .txt-wrap .txt { max-height: none; }

.t-sticky { box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 10px -4px rgba(0,0,0,.12); border-radius: 2px; }
.t-sticky .txt:empty::before { content: ""; display: inline-block; }
.t-text .txt { min-height: 1.3em; padding: 2px; }
.t-shape svg.shape { position: absolute; inset: 0; overflow: visible; }
.t-shape .txt-wrap { padding: 12px 18px; }
.t-shape.s-diamond .txt-wrap, .t-shape.s-triangle .txt-wrap { padding: 22% 22% 12%; }
.t-image img { width: 100%; height: 100%; display: block; pointer-events: none; border-radius: inherit; object-fit: cover; }
.t-image { background: var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.t-frame { background: var(--panel); border: 1px solid var(--frame-border); pointer-events: none; }
.frame-title {
  position: absolute; left: 0; bottom: 100%; pointer-events: auto; white-space: nowrap; outline: none;
  font-size: calc(13px / var(--z, 1)); padding-bottom: calc(4px / var(--z, 1)); color: var(--muted); font-weight: 500;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.t-frame.editing .frame-title { color: var(--ink); text-overflow: clip; overflow: visible; cursor: text; user-select: text; }

.t-mind .txt { padding: 5px 6px; white-space: pre-wrap; line-height: 1.35; }
.t-mind.mroot { border: 1.5px solid; border-radius: 999px; background: var(--panel); display: flex; align-items: center; justify-content: center; }
.t-mind.mroot .txt { padding: 0 20px; font-weight: 600; text-align: center; width: 100%; }
.t-mind svg.medge { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.handle.mplus {
  width: 18px; height: 18px; margin: -9px 0 0 -9px; border: 0; background: var(--accent); color: #fff; font: 600 14px/18px var(--font);
  text-align: center; cursor: pointer; opacity: .9;
}
.handle.mplus:hover { opacity: 1; transform: scale(1.12); }
.t-pen, .t-arrow { pointer-events: none; }
.t-pen svg, .t-arrow svg { overflow: visible; position: absolute; left: 0; top: 0; }
.t-pen path.hit, .t-arrow path.hit { pointer-events: stroke; }

/* selection overlay */
.selbox { position: absolute; border: 1px solid var(--accent); pointer-events: none; border-radius: 2px; }
.selbox.group { border-style: dashed; }
.selbox.hover { opacity: .45; }
.guide { position: absolute; background: #ff4f81; pointer-events: none; }
.handle {
  position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; background: #fff;
  border: 1px solid #a3a8b3; border-radius: 50%; pointer-events: auto; box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
.handle.quick {
  width: 8px; height: 8px; margin: -4px 0 0 -4px; border: 0; background: var(--accent); cursor: crosshair; opacity: .85;
  box-shadow: 0 0 0 3px rgba(66,98,255,.0); transition: transform .1s, box-shadow .1s;
}
.handle.quick:hover { opacity: 1; transform: scale(1.5); box-shadow: 0 0 0 4px var(--accent-soft); }
.handle.round { width: 13px; height: 13px; margin: -6.5px 0 0 -6.5px; border-color: var(--accent); }
.handle[data-h="nw"], .handle[data-h="se"] { cursor: nwse-resize; }
.handle[data-h="ne"], .handle[data-h="sw"] { cursor: nesw-resize; }
.handle[data-h="a"], .handle[data-h="b"] { cursor: move; }
.handle.bend { background: var(--accent); border-color: #fff; cursor: move; }
.handle.add { width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; border-color: var(--accent); opacity: .55; cursor: copy; box-shadow: none; }
.handle.add:hover { opacity: 1; transform: scale(1.4); }
.anchor-dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--panel); border: 2px solid var(--accent); pointer-events: none; }
.anchor-dot.on { background: var(--accent); transform: scale(1.35); }
.marquee { position: absolute; border: 1px solid var(--accent); background: rgba(59,91,253,.08); }
.snap-target { position: absolute; border: 2px solid var(--accent); border-radius: 4px; background: rgba(59,91,253,.06); }

.cursor { position: absolute; left: 0; top: 0; transition: transform 60ms linear; will-change: transform; }
.cursor svg { width: 18px; height: 18px; }
.cursor span { position: absolute; left: 14px; top: 16px; color: #fff; font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 4px; white-space: nowrap; }

/* chrome */
#topbar { position: absolute; top: 12px; left: 12px; display: flex; align-items: center; gap: 2px; padding: 4px; }
#boardName { border: 0; font: inherit; font-weight: 600; font-size: 15px; padding: 6px 8px; border-radius: 6px; width: 220px; background: transparent; color: var(--ink); }
#boardName:hover { background: var(--hover); }
#boardName:focus { outline: 2px solid var(--accent-soft); background: var(--panel); }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; margin: 0 6px; flex: none; }
.conn.ok { background: #10b981; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border: 0; border-radius: 7px; background: none; color: var(--ink); }
.icon-btn:hover { background: var(--hover); }
.icon-btn:disabled { opacity: .35; cursor: default; background: none; }
.icon-btn svg, #toolbar svg, #ctxbar svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.menu-wrap { position: relative; }
.menu { position: absolute; top: calc(100% + 8px); right: 0; padding: 6px; min-width: 190px; display: flex; flex-direction: column; z-index: 10; }
.menu button { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; font-size: 14px; }
.menu button:hover { background: var(--hover); }

#presence { position: absolute; top: 12px; right: 12px; display: flex; padding: 6px 8px; gap: 0; }
#presence:empty { display: none; }
.avatar { width: 30px; height: 30px; border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; border: 2px solid var(--panel); margin-left: -6px; cursor: default; }
.avatar:first-child { margin-left: 0; }
.avatar.me { cursor: pointer; }

#toolbar { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; padding: 5px; gap: 1px; border-radius: 12px; }
#toolbar button { width: 36px; height: 36px; border: 0; border-radius: 8px; background: none; display: flex; align-items: center; justify-content: center; color: var(--ink); }
#toolbar button:hover { background: var(--hover); }
#toolbar button.active { background: var(--accent-soft); color: var(--accent); }
.tsep { height: 1px; background: var(--line); margin: 3px 7px; }

#zoombar { position: absolute; right: 12px; bottom: 12px; display: flex; align-items: center; padding: 4px; gap: 2px; }
#zoomPct { border: 0; background: none; font-size: 13px; width: 52px; height: 34px; border-radius: 7px; font-variant-numeric: tabular-nums; }
#zoomPct:hover { background: var(--hover); }

#ctxbar.faded, #pop.faded { opacity: 0; pointer-events: none; }
#ctxbar, #pop { transition: opacity .12s ease; }
#ctxbar { position: absolute; display: flex; align-items: center; gap: 2px; padding: 6px; z-index: 5; white-space: nowrap; border-radius: 12px; }
#ctxbar button.cb {
  min-width: 36px; height: 36px; border: 0; border-radius: 8px; background: none; display: inline-flex; align-items: center; justify-content: center;
  gap: 4px; font-size: 14px; padding: 0 8px; color: var(--ink);
}
#ctxbar button.cb:hover, #ctxbar button.cb.open { background: var(--hover); }
#ctxbar button.cb.on { background: var(--accent-soft); color: var(--accent); }
#ctxbar svg { width: 20px; height: 20px; stroke-width: 1.6; }
#ctxbar svg.caret { width: 14px; height: 14px; color: var(--muted); }
#ctxbar .csep { width: 1px; height: 28px; background: var(--line); margin: 0 5px; }
.fontname { font-size: 15px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
.fsbox { display: inline-flex; align-items: center; gap: 2px; margin-left: 4px; }
.fsin { width: 38px; height: 30px; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--ink); font: inherit; font-size: 15px; text-align: center; font-variant-numeric: tabular-nums; }
.fsin:hover { border-color: var(--line); }
.fsin:focus { outline: none; border-color: var(--accent); background: var(--panel); }
.fsarrows { display: flex; flex-direction: column; }
.fsarrows button { border: 0; background: none; padding: 0 2px; height: 15px; color: var(--muted); border-radius: 4px; }
.fsarrows button:hover { background: var(--hover); color: var(--ink); }
.fsarrows svg { width: 15px !important; height: 15px !important; }
.bglyph { font-family: Georgia, serif; font-style: italic; font-size: 19px; text-decoration: underline; text-underline-offset: 3px; }
.tglyph { font-size: 19px; font-weight: 500; line-height: 1; padding: 0 2px 2px; border-bottom: 3px solid; }
.ring { width: 21px; height: 21px; border-radius: 50%; border: 3px solid; display: block; }
.cdot { width: 22px; height: 22px; border-radius: 50%; display: block; border: 1px solid rgba(0,0,0,.12); }
.cdot.none { background: linear-gradient(135deg, transparent 45%, #e5484d 45%, #e5484d 55%, transparent 55%); }

#pop { position: absolute; z-index: 6; padding: 14px; display: flex; flex-direction: column; gap: 12px; font-size: 13px; border-radius: 12px; width: 236px; max-height: calc(100vh - 16px); overflow: auto; }
#pop.pop-more, #pop.pop-font { width: 210px; padding: 6px; gap: 0; }
#pop.pop-startHead, #pop.pop-endHead, #pop.pop-shape { width: auto; padding: 8px; }
.pp-head { font-size: 13px; color: var(--muted); margin-top: 2px; }
.pp-seg { display: flex; gap: 4px; }
.pp-seg button { flex: 1; height: 38px; border: 0; border-radius: 8px; background: none; display: flex; align-items: center; justify-content: center; color: var(--ink); }
.pp-seg button:hover { background: var(--hover); }
.pp-seg button.on { background: var(--accent-soft); color: var(--accent); }
.pp-seg svg, .pp-list svg, .pp-menu svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.pp-slider input[type=range] { width: 100%; accent-color: var(--ink); margin: 0; }
.pp-label { display: flex; align-items: center; justify-content: space-between; color: var(--muted); margin-top: 4px; }
.pp-label output { font-variant-numeric: tabular-nums; }
.pp-num { width: 52px; height: 32px; border: 1px solid var(--line); border-radius: 7px; text-align: center; font: inherit; font-size: 14px; background: var(--panel); color: var(--ink); }
.pp-num:focus { outline: none; border-color: var(--accent); }
.pal { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; justify-items: center; }
.pal .sw { width: 36px; height: 36px; border-radius: 50%; border: 1px solid rgba(0,0,0,.14); padding: 0; position: relative; }
.pal .sw:hover { transform: scale(1.08); }
.pal .sw.on::after { content: ""; position: absolute; inset: -5px; border: 2px solid var(--accent); border-radius: 50%; }
.pal .sw.none { background: linear-gradient(135deg, var(--panel) 45%, #9aa0aa 45%, #9aa0aa 52%, var(--panel) 52%); }
.pal .custom { display: flex; align-items: center; justify-content: center; background: var(--hover); cursor: pointer; overflow: hidden; }
.pal .custom svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
.pal .custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.pp-row { display: flex; align-items: center; justify-content: space-between; color: var(--ink); }
.pp-row input[type=color] { width: 40px; height: 26px; border: 1px solid var(--line); border-radius: 6px; padding: 0 2px; background: var(--panel); cursor: pointer; }
.toggle { width: 36px; height: 20px; border-radius: 10px; border: 0; background: var(--line); position: relative; padding: 0; }
.toggle i { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.toggle.on { background: var(--accent); }
.toggle.on i { left: 18px; }
.pp-list { display: flex; flex-direction: column; }
.pp-list button { border: 0; background: none; text-align: left; padding: 9px 12px; border-radius: 8px; font-size: 15px; color: var(--ink); }
.pp-list button:hover { background: var(--hover); }
.pp-list button.on { color: var(--accent); background: var(--accent-soft); }
.pp-list.heads { flex-direction: row; gap: 2px; }
.pp-list.heads button { padding: 7px; }
.pp-menu { display: flex; flex-direction: column; }
.pp-menu button { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 8px 10px; border-radius: 8px; font-size: 14px; color: var(--ink); }
.pp-menu button:hover { background: var(--hover); }
.pp-menu button span { flex: 1; text-align: left; }
.pp-menu svg { width: 18px; height: 18px; }
.pp-menu kbd { font-size: 11px; color: var(--muted); }
.item.locked { cursor: not-allowed; }

.modal { position: fixed; inset: 0; background: rgba(17,24,39,.3); display: flex; align-items: center; justify-content: center; z-index: 20; }
.modal-body { padding: 24px 28px; width: min(560px, calc(100vw - 32px)); }
.ask { width: min(380px, calc(100vw - 32px)); }
.ask-input { width: 100%; font: inherit; font-size: 15px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; outline: none; background: var(--panel); color: var(--ink); }
.ask-input:focus { border-color: var(--accent); }
.ask-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-body h2 { margin: 0 0 16px; font-size: 18px; }
.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; font-size: 14px; }
kbd { display: inline-block; min-width: 22px; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; font: 12px/1.6 ui-monospace, Menlo, monospace; text-align: center; background: var(--hover); }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 18px 0; }

#toast { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 8px; font-size: 14px; z-index: 30; }

@media (max-width: 640px) {
  #boardName { width: 120px; }
  #toolbar { top: auto; bottom: 64px; transform: none; }
}

/* comments */
.cpin {
  position: absolute; width: 26px; height: 26px; margin: -26px 0 0 0; border-radius: 13px 13px 13px 3px;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  pointer-events: auto; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.25); border: 2px solid var(--panel);
}
.cpin.resolved { background: #9ca3af; }
.cpin.open { transform: scale(1.12); }
.cpin.agent { background: #8e24aa; }
#thread { position: absolute; z-index: 8; width: 300px; max-height: 60vh; display: flex; flex-direction: column; font-size: 14px; }
.th-head { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
.th-head span { flex: 1; }
.th-head button { border: 0; background: none; border-radius: 6px; padding: 4px 8px; font-size: 12px; color: var(--muted); }
.th-head button:hover { background: var(--hover); color: var(--ink); }
.th-list { overflow: auto; padding: 6px 14px; }
.th-msg { padding: 8px 0; }
.th-msg + .th-msg { border-top: 1px solid var(--line); }
.th-meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.th-meta b { color: var(--ink); font-weight: 600; margin-right: 6px; }
.th-text { white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
.th-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.th-form textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font: inherit; min-height: 36px; max-height: 120px; outline: none; background: var(--panel); color: var(--ink); }
.th-form textarea:focus { border-color: var(--accent); }
.th-form button { align-self: flex-end; }
