/* inkflow — vanilla CSS, no frameworks */
:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --panel-strong: #f3f4f6;
  --panel-alt: #fbfbfc;
  --text: #1f2430;
  --muted: #667085;
  --secondary-bg: #f3f4f6;
  --secondary-text: #495366;
  --input-bg: #f7f8fa;
  --accent: #111827;
  --accent-text: #ffffff;
  --accent-soft: rgba(17, 24, 39, 0.08);
  --accent-strong: #000000;
  --line: rgba(17, 24, 39, 0.08);
  --line-strong: rgba(17, 24, 39, 0.16);
  --border: var(--line);
  --card-bg: #ffffff;
  --canvas-bg: #ffffff;
  --grid: rgba(15, 23, 42, 0.08);
  --danger: #e11d48;
  --warning: #d97706;
  --warn: var(--warning);
  --error: var(--danger);
  --ok: #2a9d5a;
  --drop-highlight: rgba(17, 24, 39, 0.06);
  --row-hover: rgba(17, 24, 39, 0.04);
  --shadow: rgba(15, 23, 42, 0.08);
  --topbar-h: 52px;
  --drawer-w: 280px;
  color-scheme: light;
  font-size: 15px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --panel: #171d2a;
    --panel-strong: #1d2534;
    --panel-alt: #121a28;
    --text: #edf2ff;
    --muted: #9aa8bd;
    --secondary-bg: #1d2534;
    --secondary-text: #d8e1ef;
    --input-bg: #101827;
    --accent: #dfe7ff;
    --accent-text: #101827;
    --accent-soft: rgba(223, 231, 255, 0.12);
    --accent-strong: #ffffff;
    --line: rgba(148, 163, 184, 0.18);
    --line-strong: rgba(148, 163, 184, 0.28);
    --border: var(--line);
    --card-bg: #111827;
    --canvas-bg: #111827;
    --grid: rgba(148, 163, 184, 0.18);
    --danger: #f87171;
    --warning: #fbbf24;
    --warn: var(--warning);
    --error: var(--danger);
    --ok: #4ade80;
    --drop-highlight: rgba(148, 163, 184, 0.12);
    --row-hover: rgba(148, 163, 184, 0.08);
    --shadow: rgba(2, 6, 23, 0.45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body, #app, #shell { height: 100%; }
body {
  margin: 0;
  font-family: "sarasa", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  color-scheme: light dark;
  overflow: hidden;
}
#app { width: 100%; }
#shell { display: flex; flex-direction: column; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }

/* ---------- login ---------- */
#login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(99, 102, 241, 0.12), transparent 55%),
    radial-gradient(800px 500px at 100% 110%, rgba(236, 72, 153, 0.08), transparent 45%),
    var(--bg);
  padding: 1rem;
}
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 10px 24px var(--shadow);
  padding: 2.2rem 2.2rem 1.8rem;
  text-align: center;
}
.login-card .big-logo {
  width: 64px; height: 64px; border-radius: 16px;
  background: var(--accent);
  margin: 0 auto 1rem;
  display: flex; align-items: center; justify-content: center;
}
.login-card h1 { margin: .2rem 0 .3rem; font-size: 1.7rem; letter-spacing: -.02em; }
.login-card p.sub { color: var(--muted); margin: 0 0 1.6rem; line-height: 1.5; }
.login-card .btn { width: 100%; justify-content: center; padding: .8rem; font-size: 1rem; }
.login-card .divider { display: flex; align-items: center; gap: .8rem; color: var(--muted); margin: 1.4rem 0; font-size: .8rem; }
.login-card .divider::before, .login-card .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.dev-row { display: flex; gap: .5rem; }
.dev-row input {
  flex: 1; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: 10px; outline: none;
}
.dev-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-note { margin-top: 1.4rem; font-size: .78rem; color: var(--muted); line-height: 1.5; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  border: 1px solid var(--line); border-radius: 10px;
  padding: .55rem .9rem; background: var(--panel-strong); color: var(--text);
  transition: background .18s ease, border-color .18s ease, transform .12s ease, box-shadow .18s ease, color .18s ease;
  user-select: none;
}
.btn:hover { background: var(--secondary-bg); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn.ghost:hover { color: var(--text); background: var(--secondary-bg); }
.btn.sm { padding: .3rem .55rem; font-size: .82rem; border-radius: 8px; }
.icon-btn {
  width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; background: transparent; border-radius: 8px; color: var(--text);
  transition: background .18s ease, border-color .18s ease, color .18s ease, transform .12s ease;
}
.icon-btn:hover {
  background: var(--secondary-bg);
  border-color: var(--line);
}
.icon-btn svg { width: 19px; height: 19px; }

/* ---------- topbar ---------- */
#topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: .55rem;
  padding: 0 .9rem;
  background: var(--panel-alt);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 30;
}
#logo {
  font-weight: 700; letter-spacing: -.02em; font-size: 1.05rem;
  color: var(--text);
  margin-right: .3rem;
}
#boardTitle {
  border: 1px solid transparent; border-radius: 8px; padding: .3rem .55rem;
  font-size: 1rem; font-weight: 600; min-width: 140px; max-width: 40vw;
  background: transparent; outline: none; color: var(--text);
}
#boardTitle:hover { background: var(--secondary-bg); }
#boardTitle:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }
#spacer { flex: 1; }
#statusCluster {
  display: flex; align-items: center; gap: .45rem;
  margin-left: auto; flex-shrink: 0;
  background: var(--secondary-bg); border: 1px solid var(--line);
  border-radius: 999px; padding: .2rem .4rem;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}
#userMenu { display: flex; align-items: center; gap: .35rem; }
#topbar .chip {
  height: 32px; padding: .28rem .6rem; display: inline-flex; align-items: center; justify-content: center;
}
.chip {
  font-size: .72rem; font-weight: 600; padding: .28rem .6rem; border-radius: 999px;
  background: var(--secondary-bg); color: var(--secondary-text); white-space: nowrap;
  display: inline-flex; align-items: center; gap: .35rem;
  border: 1px solid var(--line);
  transition: background .18s ease, border-color .18s ease, transform .12s ease, box-shadow .18s ease, color .18s ease;
}
#userMenu .chip,
#userMenu .chip:focus-visible,
#userMenu .chip:hover,
#userMenu .chip:active {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
  box-shadow: none;
  outline: none;
  padding: .28rem .7rem;
  cursor: pointer;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.chip.live   { background: #e9f9ef; color: var(--ok); }
.chip.live .dot   { background: var(--ok); }
.chip.recon  { background: #fdf3e3; color: var(--warn); }
.chip.recon .dot  { background: var(--warn); }
.chip.off    { background: #fdeeee; color: var(--danger); }
.chip.off .dot    { background: var(--danger); }

#avatars { display: flex; align-items: center; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: .72rem; font-weight: 700;
  border: 2px solid var(--panel); margin-left: -7px;
  position: relative; cursor: default;
}
.avatar:first-child { margin-left: 0; }
.avatar .name-tip {
  position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: #1f2430; color: #fff; font-size: .7rem; font-weight: 500;
  padding: .2rem .5rem; border-radius: 6px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .1s; z-index: 60;
}
.avatar:hover .name-tip { opacity: 1; }

#userMenu .chip { cursor: pointer; }
#userMenu .chip:hover { background: var(--secondary-bg); }
#loginBtn {
  cursor: pointer; border: 1px solid var(--line); color: var(--accent);
  background: var(--accent-soft);
  transition: background .18s ease, border-color .18s ease, transform .12s ease, box-shadow .18s ease, color .18s ease;
}
#loginBtn:hover { background: var(--secondary-bg); border-color: var(--line-strong); }
#saveBtn {
  color: var(--accent);
}
#saveBtn:hover {
  background: var(--accent-soft);
  border-color: var(--line);
  color: var(--accent);
}

/* ---------- body / drawer ---------- */
#body { display: flex; height: calc(100vh - var(--topbar-h)); }
#drawer {
  width: var(--drawer-w); flex-shrink: 0;
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: margin-left .18s ease;
  overflow: hidden;
}
#drawer.collapsed { margin-left: calc(var(--drawer-w) * -1); }
.drawer-head { padding: .9rem 1rem .65rem; display: flex; align-items: center; justify-content: space-between; }
.drawer-head h2 { margin: 0; font-size: 1rem; letter-spacing: -.01em; }
#boardList { list-style: none; margin: 0; padding: .2rem .6rem 1rem; overflow-y: auto; flex: 1; }
.board-item {
  border-radius: 10px; padding: .55rem .6rem; cursor: pointer;
  display: flex; align-items: center; gap: .5rem;
}
.board-item:hover { background: var(--row-hover); }
.board-item.active { background: var(--accent-soft); }
.board-item .bi-body { flex: 1; min-width: 0; }
.board-item .bi-title { font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-item .bi-sub { font-size: .7rem; color: var(--muted); margin-top: .15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-item .bi-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .1s; }
.board-item:hover .bi-actions, .board-item.active .bi-actions { opacity: 1; }
.board-item .bi-actions .icon-btn { width: 26px; height: 26px; }
.board-item .bi-actions .icon-btn svg { width: 15px; height: 15px; }
.badge {
  font-size: .62rem; font-weight: 700; padding: .12rem .4rem; border-radius: 999px;
  background: #ede9fe; color: #6d28d9; text-transform: uppercase; letter-spacing: .04em;
}
.drawer-foot { padding: .6rem .8rem; border-top: 1px solid var(--border); display: flex; }

/* ---------- main / toolbar ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
#toolbar {
  display: flex; align-items: center; gap: .3rem; flex-wrap: wrap;
  padding: .45rem .6rem; background: var(--panel-alt); border-bottom: 1px solid var(--line);
  user-select: none;
}
.tool-group { display: flex; align-items: center; background: var(--secondary-bg); border: 1px solid var(--line); border-radius: 10px; padding: 2px; margin: 0 .1rem; box-shadow: inset 0 1px 0 rgba(255,255,255,0.04); }
.tool {
  width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; border-radius: 8px; color: var(--text); position: relative;
  transition: background .18s ease, color .18s ease, transform .12s ease, box-shadow .18s ease, opacity .18s ease;
}
.tool svg { width: 19px; height: 19px; }
.tool:hover { background: var(--row-hover); }
.tool.active { background: var(--accent); color: var(--accent-text); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12); }
.tool.alt-active { background: var(--secondary-bg); color: var(--text); border: 1px solid var(--line); }
.tool .kbd {
  position: absolute; right: 2px; bottom: 1px; font-size: .55rem; font-weight: 700;
  color: #9ca3af;
}
.tool.active .kbd { color: #c7d2fe; }
.tb-sep { width: 1px; height: 26px; background: var(--border); margin: 0 .35rem; }
.swatches { display: flex; align-items: center; gap: 4px; padding: .15rem .35rem; }
.swatch {
  width: 21px; height: 21px; border-radius: 6px; border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--border); cursor: pointer; transition: transform .08s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active { box-shadow: 0 0 0 2px var(--accent); }
input[type="color"].custom-color {
  width: 21px; height: 21px; padding: 0; border: none; border-radius: 6px;
  box-shadow: 0 0 0 1px var(--border); cursor: pointer; background: none;
}
.width-ctl { display: flex; align-items: center; gap: .45rem; padding: .2rem .4rem; font-size: .8rem; color: var(--muted); }
#widthSlider { width: 110px; accent-color: var(--accent); cursor: pointer; }
.tool-label { font-size: .72rem; color: var(--muted); padding: 0 .3rem; white-space: nowrap; }

/* ---------- canvas ---------- */
#canvasWrap { flex: 1; position: relative; overflow: hidden; background: var(--canvas-bg); }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; background: transparent; }
#cursors { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.remote-cursor { position: absolute; transform: translate(4px, 4px); pointer-events: none; }
.remote-cursor .rc-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.remote-cursor .rc-name {
  margin-top: 3px; margin-left: 4px; display: inline-block;
  background: #1f2430; color: #fff; font-size: .65rem; font-weight: 600;
  padding: .15rem .45rem; border-radius: 999px; white-space: nowrap;
}
#zoomCtl {
  position: absolute; right: 14px; bottom: 14px; z-index: 10;
  display: flex; align-items: center; gap: 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 18px var(--shadow);
  padding: 3px;
}
#zoomCtl .icon-btn { width: 30px; height: 30px; }
#zoomCtl .icon-btn svg { width: 16px; height: 16px; }
#zoomLabel { min-width: 52px; text-align: center; font-size: .74rem; font-weight: 600; color: var(--muted); }
#banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: #1f2430; color: #fff; font-size: .78rem; font-weight: 600;
  padding: .45rem .9rem; border-radius: 999px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: .4rem; white-space: nowrap;
}
#banner .spinner {
  width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#hint {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 10;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  font-size: .8rem; padding: .55rem 1.1rem; border-radius: 12px; pointer-events: none;
}

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: .5rem; align-items: center; }
.toast {
  background: #1f2430; color: #fff; font-size: .82rem; font-weight: 500;
  padding: .55rem 1rem; border-radius: 999px; box-shadow: var(--shadow);
  animation: toast-in .15s ease; max-width: 90vw;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- modal ---------- */
#modalRoot { position: fixed; inset: 0; z-index: 150; display: none; align-items: center; justify-content: center; }
#modalRoot.open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .35); }
.modal {
  position: relative; background: var(--panel); border-radius: 16px; box-shadow: var(--shadow);
  width: min(460px, calc(100vw - 2rem)); max-height: 80vh; display: flex; flex-direction: column;
  animation: toast-in .12s ease;
}
.modal h3 { margin: 0; font-size: 1.02rem; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); }
.modal-body { padding: 1rem 1.2rem; overflow-y: auto; }
.modal-foot { padding: .8rem 1.2rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; }
.modal-foot:empty { display: none; }
.member-row { display: flex; align-items: center; gap: .6rem; padding: .4rem 0; }
.member-row .avatar { margin-left: 0; }
.member-row .mr-name { flex: 1; font-size: .88rem; }
.member-row .mr-me { font-size: .7rem; color: var(--muted); }
.share-search { display: flex; gap: .5rem; margin: .6rem 0 .2rem; }
.share-search input { flex: 1; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 9px; outline: none; }
.share-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.suggestions { list-style: none; margin: .3rem 0 0; padding: 0; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.suggestions li { padding: .5rem .7rem; cursor: pointer; font-size: .86rem; }
.suggestions li:hover { background: var(--accent-soft); }
.help-grid { display: grid; grid-template-columns: auto 1fr; gap: .45rem 1rem; font-size: .86rem; align-items: baseline; }
.help-grid kbd {
  background: var(--secondary-bg); border: 1px solid var(--line); border-bottom-width: 1.5px;
  border-radius: 6px; padding: .12rem .5rem; font-size: .76rem; font-family: inherit;
}

/* ---------- misc ---------- */
#picker {
  position: fixed; z-index: 160; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 12px 24px var(--shadow); padding: .7rem;
  display: grid; grid-template-columns: repeat(8, 26px); gap: 6px;
}
#picker .swatch { width: 26px; height: 26px; }
.board-bg-picker {
  display: inline-flex; align-items: center; gap: .35rem;
  background: var(--panel-strong);
  border: 1px solid var(--line); border-radius: 10px;
  padding: .18rem .35rem;
}
.board-bg-picker input[type="color"] {
  width: 22px; height: 22px; padding: 0; border: none; border-radius: 6px; background: transparent;
  cursor: pointer;
}
.board-bg-picker span {
  font-size: .72rem; color: var(--muted); user-select: none;
}
@media (max-width: 760px) {
  #drawer { position: absolute; z-index: 40; height: calc(100vh - var(--topbar-h)); box-shadow: var(--shadow); }
}