/* Twipe 1.8.0: Доска 2.0 */

.b2 {
  --b2-bg: var(--bg-elevated, #fff);
  --b2-line: color-mix(in srgb, var(--text, #000) 10%, transparent);
  --b2-muted: var(--muted, #6b7280);
  --b2-acc: #6366f1;
  --b2-shadow: 0 10px 30px -12px rgba(15, 23, 42, .28), 0 2px 6px -2px rgba(15, 23, 42, .12);
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: grid;
  grid-template-rows: auto 1fr;
  background: #f7f7f8;
  color: var(--text, #111);
  font-family: Inter, "DM Sans", system-ui, sans-serif;
  outline: none;
  overscroll-behavior: contain;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
/* Окна подтверждения и затемнение — поверх доски. */
html.b2-open #confirmSheet,
html.b2-open .confirm-sheet { z-index: 100060 !important; }
html.b2-open #overlayBackdrop,
html.b2-open .overlay-backdrop { z-index: 100050 !important; }

.b2 svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- шапка ---------- */
.b2-top {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  height: 52px;
  padding: 0 8px;
  padding-top: env(safe-area-inset-top, 0px);
  box-sizing: content-box;
  background: var(--b2-bg);
  border-bottom: 1px solid var(--b2-line);
  position: relative;
  z-index: 3;
}
.b2-ib {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.b2-ib:hover { background: color-mix(in srgb, var(--text, #000) 7%, transparent); }
.b2-ib:active { transform: scale(.96); }
.b2-title { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; padding: 0 4px; }
.b2-title b { font-size: 15px; font-weight: 750; }
.b2-sub { font-size: 12px; color: var(--b2-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b2-badge { flex: 0 1 auto; min-width: 0; padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: color-mix(in srgb, var(--b2-acc) 12%, transparent); color: var(--b2-acc); }
.b2-net { background: color-mix(in srgb, #f59e0b 16%, transparent); color: #b45309; }
.b2-peers { display: flex; flex: 0 0 auto; padding: 0 4px; }
.b2-peers:empty { display: none; }
.b2-peer { display: inline-grid; place-items: center; width: 28px; height: 28px; margin-left: -6px; border-radius: 50%; border: 2px solid var(--b2-bg); background: var(--c); color: #fff; font-size: 12px; font-weight: 750; }
.b2-peer:first-child { margin-left: 0; }
.b2-peer--more { background: #64748b; font-size: 11px; }
.b2-share {
  flex: 0 0 auto;
  height: 36px;
  padding: 0 14px;
  margin: 0 2px;
  border: 0;
  border-radius: 12px;
  background: var(--b2-acc);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
}
.b2-share:active { transform: scale(.97); }
.b2.is-ro [data-act="undo"], .b2.is-ro [data-act="redo"], .b2.is-ro .b2-ai-btn { display: none; }

/* ---------- холст ---------- */
.b2-stage { position: relative; overflow: hidden; min-height: 0; }
.b2-canvas { position: absolute; inset: 0; display: block; touch-action: none; cursor: default; }
.b2-canvas[data-tool="hand"], .b2.is-ro .b2-canvas { cursor: grab; }
.b2-canvas.is-grabbing { cursor: grabbing !important; }
.b2-canvas[data-tool="pen"], .b2-canvas[data-tool="marker"], .b2-canvas[data-tool="shape"], .b2-canvas[data-tool="frame"], .b2-canvas[data-tool="arrow"] { cursor: crosshair; }
.b2-canvas[data-tool="eraser"] { cursor: none; }
.b2-canvas[data-tool="text"] { cursor: text; }
.b2-canvas[data-tool="sticky"], .b2-canvas[data-tool="laser"] { cursor: cell; }

.b2-editor {
  position: absolute;
  z-index: 2;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 2px solid var(--b2-acc);
  outline-offset: 2px;
  border-radius: 2px;
  background: transparent;
  color: #1f2937;
  font-family: inherit;
  line-height: 1.25;
  resize: none;
  overflow: hidden;
  user-select: text;
  -webkit-user-select: text;
}
.b2-editor--sticky, .b2-editor--shape { padding: 14px; box-sizing: border-box; display: block; }
.b2-editor--frame, .b2-editor--arrow { background: var(--b2-bg); color: var(--text); padding: 2px 6px; box-sizing: border-box; border-radius: 6px; }

.b2-empty {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: min(320px, 80vw);
  text-align: center;
  pointer-events: none;
}
.b2-empty b { font-size: 17px; }
.b2-empty span { color: var(--b2-muted); font-size: 14px; line-height: 1.4; }
.b2-empty .b2-chip { pointer-events: auto; margin-top: 6px; }

/* ---------- инструменты ---------- */
.b2-tools {
  position: absolute;
  z-index: 2;
  display: flex;
  gap: 2px;
  padding: 5px;
  background: var(--b2-bg);
  border: 1px solid var(--b2-line);
  border-radius: 16px;
  box-shadow: var(--b2-shadow);
}
.b2-tool {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.b2-tool:hover { background: color-mix(in srgb, var(--text, #000) 6%, transparent); }
.b2-tool.is-on { background: color-mix(in srgb, var(--b2-acc) 16%, transparent); color: var(--b2-acc); }
.b2-tool[hidden] { display: none; }

.b2-props {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--b2-bg);
  border: 1px solid var(--b2-line);
  border-radius: 16px;
  box-shadow: var(--b2-shadow);
  max-width: calc(100vw - 16px);
  overflow-x: auto;
  scrollbar-width: none;
}
.b2-props::-webkit-scrollbar { display: none; }
.b2-props[hidden] { display: none; }
.b2-sw { display: flex; gap: 4px; flex: 0 0 auto; }
.b2-swatch {
  position: relative;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--b2-bg);
  background: var(--c);
  box-shadow: 0 0 0 1px var(--b2-line);
  cursor: pointer;
}
.b2-swatch.is-on { box-shadow: 0 0 0 2px var(--b2-acc); }
.b2-swatch--pick { background: conic-gradient(#ef4444, #f59e0b, #10b981, #3b82f6, #8b5cf6, #ec4899, #ef4444); overflow: hidden; }
.b2-swatch--pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.b2-range { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; font-size: 12px; color: var(--b2-muted); }
.b2-range input { width: 96px; accent-color: var(--b2-acc); }
.b2-check { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; font-size: 12.5px; white-space: nowrap; cursor: pointer; }
.b2-check input { accent-color: var(--b2-acc); }
.b2-seg { display: flex; flex: 0 0 auto; padding: 2px; border-radius: 10px; background: color-mix(in srgb, var(--text, #000) 6%, transparent); }
.b2-seg button { height: 30px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: inherit; font: inherit; font-size: 12.5px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.b2-seg button.is-on { background: var(--b2-bg); color: var(--b2-acc); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.b2-seg--ico button { width: 34px; padding: 0; display: grid; place-items: center; }
.b2-seg--ico svg { width: 18px; height: 18px; }
.b2-pb { flex: 0 0 auto; display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 10px; background: transparent; color: inherit; cursor: pointer; }
.b2-pb:hover { background: color-mix(in srgb, var(--text, #000) 7%, transparent); }
.b2-pb svg { width: 18px; height: 18px; }
.b2-danger { color: #dc2626 !important; }

/* ---------- масштаб и мини-карта ---------- */
.b2-zoom {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: center;
  background: var(--b2-bg);
  border: 1px solid var(--b2-line);
  border-radius: 14px;
  box-shadow: var(--b2-shadow);
  overflow: hidden;
}
.b2-zoom button { height: 36px; min-width: 36px; padding: 0 6px; border: 0; background: transparent; color: inherit; font: inherit; font-size: 16px; cursor: pointer; }
.b2-zoom .b2-zv { min-width: 58px; font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums; }
.b2-zoom button:hover { background: color-mix(in srgb, var(--text, #000) 6%, transparent); }
.b2-mini {
  position: absolute;
  z-index: 2;
  width: 168px;
  height: 108px;
  background: var(--b2-bg);
  border: 1px solid var(--b2-line);
  border-radius: 14px;
  box-shadow: var(--b2-shadow);
  cursor: pointer;
}

/* ---------- меню и панели ---------- */
.b2-menu {
  position: absolute;
  z-index: 5;
  top: calc(56px + env(safe-area-inset-top, 0px));
  right: 8px;
  min-width: 240px;
  padding: 6px;
  background: var(--b2-bg);
  border: 1px solid var(--b2-line);
  border-radius: 16px;
  box-shadow: var(--b2-shadow);
  display: flex;
  flex-direction: column;
}
.b2-menu[hidden] { display: none; }
.b2-menu button { text-align: left; padding: 10px 12px; border: 0; border-radius: 10px; background: transparent; color: inherit; font: inherit; font-size: 14px; cursor: pointer; }
.b2-menu button:hover { background: color-mix(in srgb, var(--text, #000) 6%, transparent); }
.b2-menu button[hidden] { display: none; }
.b2-menu hr { border: 0; border-top: 1px solid var(--b2-line); margin: 4px 6px; }
.b2-panel {
  position: absolute;
  z-index: 6;
  top: calc(60px + env(safe-area-inset-top, 0px));
  right: 8px;
  width: min(360px, calc(100vw - 16px));
  max-height: calc(100% - 140px);
  display: flex;
  flex-direction: column;
  background: var(--b2-bg);
  border: 1px solid var(--b2-line);
  border-radius: 18px;
  box-shadow: var(--b2-shadow);
  user-select: text;
  -webkit-user-select: text;
}
.b2-panel[hidden] { display: none; }
.b2-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 4px 16px; }
.b2-panel-head b { font-size: 15px; }
.b2-panel-body { padding: 4px 16px 16px; overflow: auto; }
.b2-muted { margin: 8px 0; color: var(--b2-muted); font-size: 13px; line-height: 1.45; }
.b2-tpls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.b2-tpl { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 14px 12px; border: 1px solid var(--b2-line); border-radius: 14px; background: transparent; color: inherit; font: inherit; font-size: 14px; font-weight: 600; text-align: left; cursor: pointer; }
.b2-tpl span { font-size: 22px; }
.b2-tpl:hover { border-color: var(--b2-acc); background: color-mix(in srgb, var(--b2-acc) 6%, transparent); }
.b2-vers { list-style: none; margin: 0; padding: 0; }
.b2-vers li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--b2-line); font-size: 14px; }
.b2-chip { height: 34px; padding: 0 14px; border: 1px solid var(--b2-line); border-radius: 10px; background: var(--b2-bg); color: inherit; font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.b2-chip--primary { background: var(--b2-acc); border-color: var(--b2-acc); color: #fff; }
.b2-row { display: flex; flex-wrap: wrap; gap: 8px; }
.b2-lbl { display: block; margin: 4px 0 6px; font-size: 13px; font-weight: 600; }
.b2-ta { width: 100%; box-sizing: border-box; padding: 10px 12px; border: 1px solid var(--b2-line); border-radius: 12px; background: transparent; color: inherit; font: inherit; font-size: 14px; resize: vertical; }
.b2-keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
.b2-keys dt { font-weight: 650; white-space: nowrap; }
.b2-keys dd { margin: 0; color: var(--b2-muted); }

/* ---------- раскладка: телефон (по умолчанию) ---------- */
.b2-tools {
  left: 8px;
  right: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  overflow-x: auto;
  scrollbar-width: none;
  justify-content: flex-start;
}
.b2-tools::-webkit-scrollbar { display: none; }
.b2-props { left: 8px; bottom: calc(66px + env(safe-area-inset-bottom, 0px)); }
.b2-zoom { right: 8px; top: calc(60px + env(safe-area-inset-top, 0px)); }
.b2-mini { display: none; }
@media (max-width: 520px) {
  .b2-sub, .b2-ai-btn { display: none; }
  .b2-share { padding: 0 10px; font-size: 13px; }
  .b2-top .b2-badge { max-width: 92px; }
  .b2-zoom [data-act="zin"], .b2-zoom [data-act="zout"] { display: none; }
}
@media (max-width: 380px) {
  .b2-top [data-act="redo"] { display: none; }
}

/* ---------- компьютер ---------- */
@media (min-width: 760px) {
  .b2-tools {
    left: 12px;
    right: auto;
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    flex-direction: column;
    overflow: visible;
  }
  .b2-props { left: 50%; transform: translateX(-50%); top: calc(64px + env(safe-area-inset-top, 0px)); bottom: auto; }
  .b2-zoom { top: auto; bottom: 12px; right: 192px; }
  .b2-mini { display: block; right: 12px; bottom: 12px; }
  .b2-tools.is-short { top: 64px; transform: none; }
}
@media (min-width: 760px) and (max-height: 640px) {
  .b2-tools { top: 64px; transform: none; max-height: calc(100% - 140px); overflow-y: auto; }
}

/* ---------- тёмная тема ---------- */
html[data-theme="dark"] .b2 { background: #141414; --b2-shadow: 0 10px 30px -12px rgba(0, 0, 0, .6); }
html[data-theme="dark"] .b2-net { color: #fbbf24; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .b2 { --b2-shadow: 0 10px 30px -12px rgba(0, 0, 0, .6); }
}
.b2-net[hidden], .b2-ro[hidden], .b2-empty[hidden], .b2-editor[hidden] { display: none; }
