/* ============================================================
   Spectoo Board — дизайн-система v2
   Светлая и тёмная темы, переключатель в топбаре.
   ============================================================ */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f6f6fa;
  --border: #e7e8f0;
  --border-strong: #d8d9e6;
  --text: #1a1a38;
  --muted: #70708c;
  --accent: #5b5bd6;
  --accent-ink: #ffffff;
  --accent-soft: #edecfc;
  --accent-ring: rgba(91, 91, 214, .35);
  --hover: #f0f0f6;
  --active: #e6e6fa;
  --danger: #e5484d;
  --shadow-sm: 0 1px 2px rgba(20, 20, 50, .06), 0 0 0 1px rgba(20, 20, 50, .04);
  --shadow-md: 0 2px 6px rgba(20, 20, 50, .07), 0 12px 32px rgba(20, 20, 50, .12);
  --shadow-lg: 0 4px 12px rgba(20, 20, 50, .08), 0 24px 64px rgba(20, 20, 50, .18);
  --logo-grad: linear-gradient(135deg, #7c5cff, #4f46e5);
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15151f;
  --panel: #1f1f2e;
  --panel-2: #262637;
  --border: #31314a;
  --border-strong: #3d3d5c;
  --text: #ecedf8;
  --muted: #9a9ab8;
  --accent: #9a9aff;
  --accent-ink: #16161f;
  --accent-soft: #2c2c4d;
  --accent-ring: rgba(154, 154, 255, .4);
  --hover: #2a2a3d;
  --active: #33335a;
  --danger: #ff6369;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4), 0 0 0 1px rgba(255, 255, 255, .05);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, .45), 0 12px 32px rgba(0, 0, 0, .5);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, .5), 0 24px 64px rgba(0, 0, 0, .6);
  --logo-grad: linear-gradient(135deg, #9d7bff, #6d5cff);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  user-select: none;
  -webkit-user-select: none;
  transition: background .25s ease, color .25s ease;
}
.hidden { display: none !important; }
kbd {
  background: var(--panel-2); border: 1px solid var(--border-strong); border-bottom-width: 2px;
  border-radius: 6px; padding: 1px 6px; font: 600 11.5px/1.6 inherit; color: var(--text);
}

#canvas {
  position: fixed; inset: 0; display: block;
  touch-action: none;
}

/* ============ Кнопки ============ */
.icon-btn {
  width: 32px; height: 32px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
  transition: background .15s ease, color .15s ease, transform .1s ease;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { transform: scale(.94); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn:disabled:hover { background: transparent; }
.icon-btn:disabled:active { transform: none; }
.icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg.fill { fill: currentColor; stroke: none; }

[data-theme="dark"] .theme-ico-sun { display: none; }
[data-theme="light"] .theme-ico-moon, html:not([data-theme]) .theme-ico-moon { display: none; }

.txt-btn {
  height: 32px; border: 0; border-radius: 8px; background: transparent; cursor: pointer;
  font: 500 13px inherit; color: var(--text); padding: 0 10px;
  display: inline-flex; align-items: center; gap: 4px;
  transition: background .15s ease;
}
.txt-btn:hover { background: var(--hover); }
.caret { font-size: 9px; color: var(--muted); }

/* ============ Верхняя панель ============ */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 50px; z-index: 20;
  background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  transition: background .25s ease, border-color .25s ease;
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: -.1px; display: flex; align-items: center; gap: 9px; flex: none; }
.logo {
  width: 22px; height: 22px; border-radius: 7px; background: var(--logo-grad); flex: none;
  display: inline-block; position: relative;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35), 0 2px 6px rgba(91,91,214,.4);
}
.logo::after {
  content: ""; position: absolute; left: 6px; top: 4.5px;
  border-left: 4px solid #fff; border-bottom: 4px solid transparent; border-top: 4px solid transparent;
  transform: rotate(45deg);
}
#boardName {
  border: 0; background: transparent; border-radius: 8px;
  font: 600 14px inherit; color: var(--text); padding: 6px 10px; width: 230px;
  outline: none; user-select: text; -webkit-user-select: text;
  transition: background .15s ease, box-shadow .15s ease;
}
#boardName:hover { background: var(--hover); }
#boardName:focus { background: var(--panel); box-shadow: 0 0 0 2px var(--accent-ring); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }

#presence { display: flex; align-items: center; margin: 0 6px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--panel);
  color: #fff; font: 700 11px/22px inherit; text-align: center;
  margin-left: -7px; flex: none;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
  transition: border-color .25s ease;
}
.avatar.me { margin-left: 0; }

/* ============ Меню ============ */
.menu-wrap { position: relative; }
.menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 60;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-md); padding: 6px; min-width: 190px;
  animation: pop .12s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.menu-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  border: 0; background: transparent; cursor: pointer; text-align: left;
  font: 400 13px inherit; color: var(--text); padding: 8px 10px; border-radius: 8px;
  transition: background .12s ease;
}
.menu-item:hover { background: var(--hover); }
.menu-item.danger { color: var(--danger); }
.menu-item svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sep { height: 1px; background: var(--border); margin: 5px 6px; }
.shapes-menu { min-width: 175px; }

/* ============ Панель инструментов ============ */
#toolbar {
  position: fixed; left: 12px; top: 50%; transform: translateY(-50%); z-index: 20;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 7px 6px; display: flex; flex-direction: column; gap: 3px;
  transition: background .25s ease, border-color .25s ease;
}
.tool-btn {
  width: 42px; height: 42px; border: 0; border-radius: 11px;
  background: transparent; color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease, color .15s ease, transform .1s ease;
}
.tool-btn:hover { background: var(--hover); }
.tool-btn:active { transform: scale(.93); }
.tool-btn.active { background: var(--accent-soft); color: var(--accent); }
.tool-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.tool-btn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tool-btn svg.fill { fill: currentColor; stroke: none; }
.tool-sep { height: 1px; background: var(--border); margin: 3px 7px; }
#shapeWrap .menu { top: auto; bottom: calc(100% + 6px); }

/* ============ Пилюли (панели) ============ */
.pill {
  position: fixed; z-index: 25;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 6px 8px; display: flex; align-items: center; gap: 3px;
  transition: background .25s ease, border-color .25s ease;
}
#stylebar { bottom: 16px; left: 50%; transform: translateX(-50%); }
#zoombar { bottom: 16px; right: 16px; padding: 4px 6px; gap: 2px; }
.zoom-pct {
  min-width: 54px; height: 32px; border: 0; border-radius: 8px; background: transparent;
  font: 500 12.5px inherit; color: var(--text); cursor: pointer;
  transition: background .15s ease;
}
.zoom-pct:hover { background: var(--hover); }
.pill .sep-v { width: 1px; height: 22px; background: var(--border); margin: 0 5px; flex: none; }

/* ============ Свотчи цветов ============ */
.swatches { display: grid; grid-template-columns: repeat(4, 24px); gap: 7px; }
.swatch {
  width: 24px; height: 24px; border-radius: 8px; cursor: pointer;
  border: 1px solid rgba(128, 128, 160, .35); position: relative; padding: 0;
  transition: transform .1s ease;
}
.swatch:hover { transform: scale(1.12); }
.swatch.none { background: var(--panel); }
.swatch.none::after {
  content: ""; position: absolute; left: 2px; right: 2px; top: 50%;
  height: 1.6px; background: var(--danger); transform: rotate(-45deg);
}
.swatch.active { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.width-dot { border-radius: 50%; background: var(--text); margin: auto; display: block; }
.width-opt {
  width: 34px; height: 34px; border-radius: 9px; border: 0; background: transparent;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s ease;
}
.width-opt:hover { background: var(--hover); }
.width-opt.active { background: var(--accent-soft); }
.font-opt {
  min-width: 44px; height: 32px; border-radius: 9px; border: 0; background: transparent;
  cursor: pointer; font: 500 13px inherit; color: var(--text);
  transition: background .15s ease, color .15s ease;
}
.font-opt:hover { background: var(--hover); }
.font-opt.active { background: var(--accent-soft); color: var(--accent); }

/* ============ Всплывающая панель ============ */
.popover {
  position: fixed; z-index: 70;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-md); padding: 12px;
  animation: pop .12s ease;
}
.popover .row { display: flex; gap: 6px; align-items: center; justify-content: center; }
.popover .row + .row { margin-top: 10px; }
.popover .cap { font: 600 10.5px inherit; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 8px; }

/* ============ Панель выделения ============ */
#selToolbar .icon-btn { width: 30px; height: 30px; }
#selToolbar .icon-btn svg { width: 16px; height: 16px; }
.swatch-btn {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid rgba(128, 128, 160, .4);
  cursor: pointer; padding: 0; position: relative; overflow: hidden;
  transition: box-shadow .15s ease;
}
.swatch-btn.none::after {
  content: ""; position: absolute; left: 2px; right: 2px; top: 50%;
  height: 1.5px; background: var(--danger); transform: rotate(-45deg);
}
.swatch-btn:hover { box-shadow: 0 0 0 3px var(--accent-ring); }

/* ============ Редактор текста ============ */
#editor {
  position: fixed; z-index: 30; margin: 0; border: 0; outline: none; resize: none;
  overflow: hidden; white-space: pre-wrap; word-break: break-word;
  user-select: text; -webkit-user-select: text; cursor: text;
  border-radius: 2px;
}

/* ============ Контекстное меню на холсте ============ */
#contextMenu { top: 0; left: 0; }

/* ============ Справка ============ */
#helpOverlay {
  position: fixed; inset: 0; z-index: 90; background: rgba(10, 10, 30, .5);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.help-panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px;
  padding: 24px 28px; max-width: 680px; max-height: 86vh; overflow: auto;
  box-shadow: var(--shadow-lg);
  animation: pop .18s ease;
}
.help-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.help-head b { font-size: 17px; letter-spacing: -.2px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 28px; }
.help-cols h4 { margin: 14px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); }
.help-cols p { margin: 6px 0; font-size: 13.5px; line-height: 2; color: var(--text); }
.help-note { margin: 16px 0 0; padding: 11px 13px; background: var(--accent-soft); border-radius: 12px; font-size: 13px; color: var(--text); }

/* ============ Тост ============ */
#toast {
  position: fixed; bottom: 72px; left: 50%; transform: translateX(-50%); z-index: 80;
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 15px;
  font-size: 13px; box-shadow: var(--shadow-md); pointer-events: none;
  animation: pop .15s ease;
}

@media (max-width: 720px) {
  #boardName { width: 120px; }
}
