/* Comic Relief (OFL), вендорен локально: два сабсета, чтобы работала кириллица */
@font-face {
  font-family: 'Comic Relief';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/comic-relief-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
    U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Comic Relief';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/comic-relief-cyrillic-400-normal.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

:root {
  --bg: #f6f6f4;
  --dot: #d9d9d5;
  --ink: #17181a;
  --muted: #74767a;
  --line: #e3e3df;
  --card: #ffffff;
  --accent: #1f6feb;
  --accent-dark: #1a5fd0;
  --shadow: 0 1px 2px rgba(23, 24, 26, 0.06), 0 8px 24px rgba(23, 24, 26, 0.08);
  --shadow-lift: 0 2px 4px rgba(23, 24, 26, 0.08), 0 18px 40px rgba(23, 24, 26, 0.16);
  --radius: 12px;
  --topbar: 60px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  /* Текст интерфейса не должен выделяться при панораме; исключения — ниже. */
  user-select: none;
  -webkit-user-select: none;
}

.note-text,
.lightbox-doc,
.md-content {
  user-select: text;
  -webkit-user-select: text;
}

.btn-ghost {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.btn-ghost:hover {
  background: #f7f7f4;
  border-color: #cfcfc9;
}

.btn.active {
  background: #eef2ff;
  border-color: #c9dafd;
  color: var(--accent);
}

.draw-group {
  position: relative;
}

.draw-palette {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  display: flex;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
}

.draw-palette[hidden] {
  display: none;
}

.draw-color {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--swatch);
  cursor: pointer;
}

.draw-color:hover {
  transform: scale(1.08);
}

.draw-color.active {
  border-color: #17181a;
  box-shadow: inset 0 0 0 2px #fff;
}

body.draw-mode .board,
body.draw-mode .board.panning {
  cursor: crosshair;
}

body.erase-mode .board,
body.erase-mode .board.panning {
  cursor: cell;
}

button {
  font: inherit;
  color: inherit;
}

/* ----------------------------------- шапка ---------------------------------- */

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: var(--topbar);
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  user-select: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-icon {
  width: 24px;
  height: 24px;
  flex: none;
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
}

.brand-title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-count {
  font-size: 12px;
  color: var(--muted);
  background: #f1f1ee;
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

.brand-count:empty {
  display: none;
}

.brand-online {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #4b7a4b;
  background: #edf6ed;
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

.brand-online::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3fa33f;
  box-shadow: 0 0 0 2px rgba(63, 163, 63, 0.18);
}

.brand-online[hidden] {
  display: none;
}

.tools {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
  white-space: nowrap;
}

.btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(31, 111, 235, 0.3);
}

.btn-primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.btn-icon {
  width: 34px;
  padding: 0;
  border-color: var(--line);
  background: #fff;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
}

.btn-icon:hover {
  color: var(--ink);
  border-color: #cfcfc9;
}

.zoom {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-zoom {
  min-width: 58px;
  height: 34px;
  padding: 0 8px;
  border-color: var(--line);
  background: #fff;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.btn-zoom:hover {
  color: var(--ink);
  border-color: #cfcfc9;
}

.btn-light {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.24);
  color: #fff;
  text-decoration: none;
}

.btn-light:hover {
  background: rgba(255, 255, 255, 0.24);
}

/* ---------------------------------- доска ---------------------------------- */

.board {
  position: relative;
  height: calc(100% - var(--topbar));
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  background-color: var(--bg);
  background-image: radial-gradient(circle, var(--dot) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: 0 0;
}

.board.panning {
  cursor: grabbing;
}

.world {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  /* без will-change: принудительный слой + zoom внутри давали мыло */
}

/* Масштаб — через zoom: браузер пересобирает вёрстку на новом масштабе,
   поэтому текст и картинки не растягиваются из битмапа и остаются резкими. */
.scene {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
}

/* ------------------------------- курсоры других ----------------------------- */

.cursors {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 7;
  pointer-events: none;
}

.cursor {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  will-change: transform;
  transition: transform 0.09s linear;
}

.cursor-scale {
  transform-origin: 0 0;
  pointer-events: none;
}

.cursor-arrow {
  display: block;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.28));
}

.cursor-name {
  position: absolute;
  left: 13px;
  top: 15px;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.45;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
}

/* ------------------------------- markdown ---------------------------------- */

.card-markdown {
  display: flex;
  flex-direction: column;
  width: 380px;
  max-height: 440px;
  overflow: hidden;
}

.md-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfbfa;
  border-radius: var(--radius) var(--radius) 0 0;
}

.md-badge {
  flex: none;
  padding: 3px 6px;
  border-radius: 6px;
  background: #eef2ff;
  color: #3b5bdb;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.md-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.md-size {
  flex: none;
  font-size: 11.5px;
  color: var(--muted);
}

.md-body {
  position: relative;
  padding: 14px 16px 26px;
  overflow: hidden;
  pointer-events: none;
}

.md-body::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 54px;
  background: linear-gradient(rgba(255, 255, 255, 0), #fff 72%);
}

.md-empty {
  color: var(--muted);
}

.md-content {
  font-size: 13px;
  line-height: 1.6;
  color: #24262a;
  overflow-wrap: anywhere;
}

.md-content > :first-child {
  margin-top: 0;
}

.md-content > :last-child {
  margin-bottom: 0;
}

.md-content h1,
.md-content h2,
.md-content h3,
.md-content h4,
.md-content h5,
.md-content h6 {
  margin: 16px 0 8px;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.md-content h1 {
  font-size: 20px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.md-content h2 {
  font-size: 17px;
}

.md-content h3 {
  font-size: 15px;
}

.md-content h4,
.md-content h5,
.md-content h6 {
  font-size: 13.5px;
  color: var(--muted);
}

.md-content p {
  margin: 8px 0;
}

.md-content ul,
.md-content ol {
  margin: 8px 0;
  padding-left: 22px;
}

.md-content li {
  margin: 3px 0;
}

.md-content li > ul,
.md-content li > ol {
  margin: 3px 0;
}

.md-content code {
  padding: 1px 5px;
  border-radius: 4px;
  background: #f1f1ee;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.9em;
}

.md-content pre {
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f8f5;
  overflow: auto;
}

.md-content pre code {
  padding: 0;
  background: none;
  font-size: 12px;
}

.md-content blockquote {
  margin: 10px 0;
  padding: 2px 12px;
  border-left: 3px solid #d8d8d1;
  color: #5a5c60;
}

.md-content hr {
  margin: 14px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.md-content a {
  color: var(--accent);
  text-decoration: none;
}

.md-content a:hover {
  text-decoration: underline;
}

.md-content img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

.md-content .md-table-wrap {
  margin: 10px 0;
  overflow-x: auto;
}

.md-content table {
  border-collapse: collapse;
  font-size: 12.5px;
}

.md-content th,
.md-content td {
  padding: 5px 8px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.md-content th {
  background: #f7f7f4;
  font-weight: 600;
}

.md-content input[type="checkbox"] {
  margin-right: 5px;
  vertical-align: middle;
}

/* --------------------------------- таблицы ---------------------------------- */

.card-sheet {
  display: flex;
  flex-direction: column;
  width: 440px;
  max-height: 440px;
  overflow: hidden;
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfbfa;
  border-radius: var(--radius) var(--radius) 0 0;
}

.sheet-badge {
  flex: none;
  padding: 3px 6px;
  border-radius: 6px;
  background: #e6f4ea;
  color: #1e7b3c;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.sheet-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-size {
  flex: none;
  font-size: 11.5px;
  color: var(--muted);
}

.sheet-body {
  position: relative;
  padding: 10px 12px 22px;
  overflow: hidden;
}

.sheet-body::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 42px;
  background: linear-gradient(rgba(255, 255, 255, 0), #fff 72%);
  pointer-events: none;
}

.sheet-scroll {
  overflow: auto;
  max-height: 100%;
}

table.sheet-table {
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

table.sheet-table th,
table.sheet-table td {
  border: 1px solid var(--line);
  padding: 4px 7px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}

table.sheet-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7f7f4;
  font-weight: 600;
}

.sheet-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.sheet-tab {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 12.5px;
  cursor: pointer;
}

.sheet-tab.active {
  background: #eef2ff;
  border-color: #c9dafd;
  color: var(--accent);
}

.sheet-panel[hidden] {
  display: none;
}

.lightbox-doc.sheet-doc {
  width: min(980px, 100%);
  padding: 28px 32px 32px;
}

.lightbox-doc.sheet-doc .sheet-scroll {
  max-height: 62vh;
}

.lightbox-doc.sheet-doc table.sheet-table {
  font-size: 13px;
}

/* --------------------------------- 3D-модели -------------------------------- */

.card-model {
  display: flex;
  flex-direction: column;
  width: 360px;
  overflow: hidden;
}

.model-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfbfa;
  border-radius: var(--radius) var(--radius) 0 0;
}

.model-badge {
  flex: none;
  padding: 3px 6px;
  border-radius: 6px;
  background: #f3e8ff;
  color: #7028c9;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.model-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-size {
  flex: none;
  font-size: 11.5px;
  color: var(--muted);
}

.model-info {
  flex: none;
  padding: 2px 6px;
  border-radius: 5px;
  background: #f1f1ee;
  font-size: 10.5px;
  color: var(--muted);
}

.model-mode {
  flex: none;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(46, 160, 67, 0.14);
  color: #1f7a33;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.model-mode.is-soft {
  background: rgba(120, 120, 130, 0.14);
  color: #6b6f78;
}

.model-info:empty {
  display: none;
}

/* Тёмный «viewport»: светлые материалы иначе сливаются со светлым фоном. */
.model-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 120px;
  /* у нерастянутой карточки высота по пропорции, у растянутой — по свободному месту */
  aspect-ratio: 340 / 230;
  overflow: hidden;
  background: #272b33;
}

/* canvas заполняет весь вьюпорт, даже если карточку растянули не пропорционально */
.model-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* на карточке модели шапка сверху, поэтому кнопки уводим вниз, чтобы не лезли на текст */
/* кнопки — в левый нижний угол: правый занят ручкой изменения размера */
.card-model .card-actions {
  top: auto;
  bottom: 8px;
  left: 8px;
  right: auto;
}

.model-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 0 16px;
  text-align: center;
  font-size: 12px;
  color: #b9bec9;
}

.model-doc {
  width: min(980px, 100%);
  padding: 24px 28px 26px;
}

.model-stage {
  display: flex;
  justify-content: center;
}

.model-canvas-wide {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: #272b33;
}

.model-hint {
  margin: 12px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* ------------------------------ рамка-группа -------------------------------- */

/* фон полностью прозрачный: рамку рисует только пунктир */
.card.card-frame {
  /* цвет периметра и подписи — один и тот же оттенок */
  --frame-stroke: rgba(96, 102, 116, 0.55);
  --frame-stroke-hover: rgba(31, 111, 235, 0.65);
  --frame-ink: rgba(72, 78, 90, 0.92);

  background: transparent !important;
  border: none;
  box-shadow: none;
  /* периметр без скругления — прямые углы */
  border-radius: 0;
  cursor: default;
  /* подпись стоит над пунктиром — не даём карточке её обрезать */
  overflow: visible !important;
  /* тело рамки прозрачно для мыши: тянем только за периметр и подпись,
     а внутри можно панорамировать доску и кликать по карточкам */
  pointer-events: none;
}

html[data-theme="dark"] .card-frame {
  --frame-stroke: rgba(170, 178, 194, 0.5);
  --frame-stroke-hover: rgba(122, 162, 255, 0.75);
  --frame-ink: rgba(206, 212, 224, 0.92);
}

/* зона захвата: полосы по периметру — тянуть можно за любую сторону,
   а середина рамки остаётся прозрачной для панорамы и карточек */
.frame-grab {
  position: absolute;
  pointer-events: auto;
  cursor: grab;
}

.frame-grab.top {
  top: 0;
  left: 0;
  right: 0;
  height: 16px;
}

.frame-grab.bottom {
  bottom: 0;
  left: 0;
  right: 0;
  height: 16px;
}

.frame-grab.left {
  top: 0;
  bottom: 0;
  left: 0;
  width: 16px;
}

.frame-grab.right {
  top: 0;
  bottom: 0;
  right: 0;
  width: 16px;
}

.card-frame.dragging .frame-grab {
  cursor: grabbing;
}

/* никакой тени при наведении и перетаскивании — рамка плоская */
.card.card-frame:hover,
.card.card-frame.dragging {
  box-shadow: none !important;
}

.card-frame .frame-title,
.card-frame .resize-handle {
  pointer-events: auto;
}

.card-frame.dragging {
  cursor: grabbing;
}

/* крупный пунктир: свой SVG, поэтому длину штриха можно задать точно.
   width/height обязательны: у svg есть собственный размер 300×150, и с одним
   inset он рисовался маленьким прямоугольником в углу. */
.frame-dash {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.frame-dash rect {
  fill: none;
  stroke: var(--frame-stroke);
  stroke-width: 3;
  stroke-dasharray: 18 12;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  transition: stroke 0.12s ease;
}

.card-frame:hover .frame-dash rect,
.card-frame.dragging .frame-dash rect {
  stroke: var(--frame-stroke-hover);
}

/* подпись: крупная, слева и над пунктиром, без рамки и фона */
.frame-title {
  position: absolute;
  bottom: calc(100% + 2px);
  left: 0;
  max-width: min(92%, 620px);
  padding: 0;
  border: 0;
  background: none;
  color: var(--frame-ink);
  font-size: 19px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: grab;
}

.frame-title:hover {
  color: var(--frame-stroke-hover);
}

/* без обводки: при правке только курсор и цвет текста */
.frame-title[contenteditable] {
  cursor: text;
  color: var(--ink);
  border: 0;
  outline: none;
  box-shadow: none;
  background: none;
}

html[data-theme="dark"] .frame-dash rect {
  stroke: var(--frame-stroke);
}

/* ------------------------- оптимизации для мобильных ------------------------ */
/* На телефонах главный источник лагов — перерисовка теней и фильтров при зуме.
   Упрощаем оформление, вид при этом почти не меняется. */

.is-mobile .card {
  box-shadow: 0 1px 2px rgba(23, 24, 26, 0.07);
  transition: none;
}

.is-mobile .card:hover,
.is-mobile .card.dragging,
.is-mobile .card.resizing {
  box-shadow: 0 1px 3px rgba(23, 24, 26, 0.12);
}

.is-mobile .topbar,
.is-mobile .toast,
.is-mobile .draw-palette,
.is-mobile .lightbox-bar {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.is-mobile .cursor {
  transition: none;
}

.is-mobile .card-note::before {
  box-shadow: 0 6px 14px rgba(23, 24, 26, 0.14);
}

/* -------------------------------- стикеры ---------------------------------- */

.card-note {
  position: relative;
  display: flex;
  width: 240px;
  min-height: 190px;
  padding: 0;
  --note-tint: #fee685;
}

/* два класса и !important: .card ниже по файлу задаёт фон и тень — перебиваем их
   для стикера, даже если кто-то выставит background инлайном */
.card.card-note {
  background: transparent !important;
  /* тень уже нарисована на самой бумаге, свою не добавляем */
  box-shadow: none !important;
}

/* Бумага нарисована процедурно: цвет + мягкий градиент + лёгкий шум + тень.
   Никакой растровой картинки — значит нет мыла при увеличении и нет искажений
   при непропорциональном размере: слои просто тянутся вместе с карточкой. */
.card-note::before {
  content: '';
  position: absolute;
  inset: 2%;
  z-index: 0;
  border-radius: 4px;
  background-color: var(--note-tint, #fee685);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E"),
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.55) 0%,
      rgba(255, 255, 255, 0.12) 22%,
      rgba(255, 255, 255, 0) 45%,
      rgba(0, 0, 0, 0.05) 82%,
      rgba(0, 0, 0, 0.12) 100%
    );
  background-size: 120px 120px, 100% 100%;
  background-repeat: repeat, no-repeat;
  box-shadow: 0 12px 26px rgba(23, 24, 26, 0.18), 0 2px 6px rgba(23, 24, 26, 0.1);
  /* лёгкий наклон, как у настоящего стикера; inset 2% не даёт углам срезаться */
  transform: rotate(-0.6deg);
  pointer-events: none;
}

/* зона для перетаскивания: за неё стикер можно тянуть, даже когда текст активен */
.note-grip {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 30px;
  z-index: 3;
  cursor: grab;
  border-radius: 6px 6px 0 0;
}

.note-grip:active {
  cursor: grabbing;
}

.card-note .note-grip::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 11px;
  width: 36px;
  height: 4px;
  margin-left: -18px;
  border-radius: 2px;
  background: rgba(60, 58, 44, 0.28);
  opacity: 0.6;
  transition: opacity 0.12s ease;
}

.card-note:hover .note-grip::after,
.card-note.editing .note-grip::after {
  opacity: 1;
}

.card-note.editing {
  cursor: text;
  /* никаких рамок и теней: стикер — это только бумага */
  box-shadow: none;
}

/* перебиваем hover/dragging у .card: у стикера фон и тень рисует сама бумага */
.card.card-note:hover,
.card.card-note.dragging {
  box-shadow: none;
}

.card-note.editing,
.card-note.editing .note-text {
  user-select: text;
  -webkit-user-select: text;
}

/* текст живёт внутри бумаги: область задана в процентах, поэтому при любом
   размере стикера текст не вылезает за его края */
.note-body {
  position: absolute;
  inset: 10% 11% 12% 11%;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* центрирование по обеим осям; кегль подбирает autosizeNote() в app.js.
   margin: auto — страховка: центрирует даже если align-items перебьётся */
.note-text {
  max-width: 100%;
  margin: auto;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: #3c3a2c;
  font-family: 'Comic Relief', 'Comic Sans MS', 'Segoe Print', cursive;
  font-size: 18px;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  pointer-events: none;
}

.card-note.editing .note-text {
  pointer-events: auto;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}

/* подсказка, пока в стикере пусто */
.note-text:empty::before {
  content: attr(data-placeholder);
  color: rgba(60, 58, 44, 0.4);
}

.card-note .card-actions {
  top: 6px;
  right: 6px;
  z-index: 4;
}

.card-note .card-actions .icon-btn {
  background: rgba(255, 255, 255, 0.55);
  color: #4a4735;
  backdrop-filter: none;
}

.card-note .card-actions .icon-btn:hover {
  background: rgba(255, 255, 255, 0.9);
}

.card-note .card-actions .icon-btn[data-act="delete"]:hover {
  background: #d13438;
  color: #fff;
}

/* ---------------------------------- карточки -------------------------------- */

.card {
  position: absolute;
  /* свой stacking context: внутренние z-index (ручка, подсказка, текст стикера)
     не вылезают на соседние карточки */
  z-index: 0;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  transition: box-shadow 0.16s ease;
}

.card:hover {
  box-shadow: var(--shadow-lift);
}

.card.dragging {
  cursor: grabbing;
  box-shadow: var(--shadow-lift);
  z-index: 5;
}

.card.uploading {
  pointer-events: none;
}

.card-image {
  overflow: hidden;
  background: #ececea;
}

.card-image img {
  display: block;
  max-width: 320px;
  max-height: 360px;
  width: auto;
  height: auto;
  border-radius: var(--radius);
  pointer-events: none;
  -webkit-user-drag: none;
  background: #ececea;
}

.card-error {
  box-shadow: 0 0 0 2px #f3b8b8, var(--shadow);
}

.card-error .file-name {
  color: #b42323;
}

/* --------------------------------- рисование -------------------------------- */

.card.card-draw {
  background: transparent;
  box-shadow: none;
  /* чернила не должны перехватывать мышь: клики проходят к доске, рисование и ластик работают поверх */
  pointer-events: none;
}

.card.card-draw:hover {
  box-shadow: none;
}

.card.card-draw .draw-svg {
  display: block;
  pointer-events: none;
  overflow: visible;
}

.card.card-draw .draw-frame {
  pointer-events: none;
}

.card.card-draw.draw-preview {
  pointer-events: none;
}

.card-file {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 250px;
  padding: 14px;
}

.file-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: #f0f4ff;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.file-body {
  min-width: 0;
  flex: 1;
}

.file-name {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.file-size {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}

.file-download {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.file-download:hover {
  background: #f5f8ff;
  border-color: #c9dafd;
}

/* прогресс загрузки */

.progress {
  margin-top: 10px;
  height: 4px;
  border-radius: 99px;
  background: #ededea;
  overflow: hidden;
}

.progress i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.15s linear;
}

.card-uploading .file-size {
  color: var(--muted);
}

/* кнопки на карточке */

.card-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.14s ease, transform 0.14s ease;
  pointer-events: none;
}

/* закреплённая карточка: не двигается, ручки размера нет */
.card.is-locked {
  cursor: default;
}

.card.is-locked .resize-handle,
.card.is-sealed .resize-handle {
  display: none;
}

.card.is-sealed {
  cursor: default;
}

/* активный переключатель (замок/запрет) */
.icon-btn.is-on {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

html[data-theme="dark"] .icon-btn.is-on {
  background: var(--accent);
  color: #fff;
}

/* запечатанная карточка: из кнопок остаётся только «снять запрет» */
.card.is-sealed .card-actions > :not([data-act="seal"]) {
  display: none;
}

.card:hover .card-actions,
.card:focus-within .card-actions {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: rgba(23, 24, 26, 0.62);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.12s ease;
}

.icon-btn:hover {
  background: rgba(23, 24, 26, 0.85);
}

.icon-btn[data-act="delete"]:hover {
  background: #d13438;
}

.icon-btn svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.card-file .card-actions .icon-btn {
  background: rgba(23, 24, 26, 0.08);
  color: var(--muted);
  backdrop-filter: none;
}

.card-file .card-actions .icon-btn:hover {
  background: rgba(23, 24, 26, 0.16);
  color: var(--ink);
}

.card-file .card-actions .icon-btn[data-act="delete"]:hover {
  background: #fde7e7;
  color: #c02323;
}

/* --------------------------- изменение размера ------------------------------ */

/* Ручка лежит ВНУТРИ карточки: у многих карточек overflow: hidden, и всё,
   что вылезает за край, обрезается — из-за этого её было тяжело поймать. */
.resize-handle {
  position: absolute;
  right: 4px;
  bottom: 4px;
  z-index: 8;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(23, 24, 26, 0.18);
  border-radius: 6px;
  background-color: rgba(255, 255, 255, 0.94);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M13 17L17 13M9 17L17 9' stroke='%236b6f76' stroke-width='1.7' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 16px 16px;
  box-shadow: 0 1px 3px rgba(23, 24, 26, 0.18);
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.12s ease, transform 0.12s ease;
  cursor: nwse-resize;
  touch-action: none;
}

.card:hover .resize-handle,
.card:focus-within .resize-handle,
.card.resizing .resize-handle {
  opacity: 1;
  transform: none;
}

/* размер карточки во время растягивания; подсвечивается при прилипании */
.resize-hint {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(20, 22, 26, 0.82);
  color: #fff;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

.resize-hint.is-snap {
  background: var(--accent);
}

.card-image .resize-handle {
  border-color: rgba(255, 255, 255, 0.55);
  background-color: rgba(255, 255, 255, 0.92);
}

.card.sized {
  overflow: hidden;
}

.card-image.sized img {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: cover;
}

.card-markdown.sized,
.card-sheet.sized {
  max-height: none;
}

.card-markdown.sized .md-body,
.card-sheet.sized .sheet-body {
  flex: 1;
  overflow: auto;
}

.card-markdown.sized .md-body::after,
.card-sheet.sized .sheet-body::after {
  display: none;
}

.card-file.sized .file-body {
  overflow: hidden;
}

.card-note.sized {
  min-height: 0;
}

.card-note.sized .note-text {
  height: 100%;
  min-height: 0;
}

/* -------------------------------- пустое состояние --------------------------- */

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  pointer-events: none;
}

.empty.hidden {
  display: none;
}

.empty-card {
  max-width: 380px;
  text-align: center;
  padding: 32px 28px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  pointer-events: auto;
}

.empty-icon {
  width: 52px;
  height: 52px;
  margin-bottom: 12px;
  fill: none;
  stroke: #b9bab5;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-card h1 {
  margin: 0 0 8px;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.empty-card p {
  margin: 0 0 18px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--muted);
}

.empty-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.empty-hint {
  margin: 14px 0 0 !important;
  font-size: 12px !important;
  color: #9a9b96 !important;
}

/* --------------------------------- dropzone -------------------------------- */

.dropzone {
  position: absolute;
  inset: 14px;
  display: none;
  place-items: center;
  border: 2px dashed #9cc0fb;
  border-radius: 16px;
  background: rgba(31, 111, 235, 0.06);
  pointer-events: none;
  z-index: 10;
}

.dropzone.active {
  display: grid;
}

.dropzone-inner {
  padding: 12px 20px;
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

/* ---------------------------------- подсказки ------------------------------- */

.hintbar {
  position: absolute;
  left: 16px;
  bottom: 14px;
  display: flex;
  gap: 16px;
  font-size: 11.5px;
  color: #9a9b96;
  pointer-events: none;
}

.hintbar b {
  color: #7c7d78;
  font-weight: 600;
}

/* --------------------------------- lightbox -------------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: rgba(14, 15, 17, 0.94);
  animation: fade 0.14s ease;
}

.lightbox[hidden] {
  display: none;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.lightbox-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  color: #e9e9ea;
}

.lightbox-name {
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox-actions {
  display: flex;
  gap: 8px;
  flex: none;
}

.lightbox-stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 8px 24px 24px;
  overflow: auto;
}

.lightbox-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
}

.lightbox.doc-open .lightbox-stage {
  place-items: start center;
}

.lightbox-doc {
  width: min(860px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 40px 44px 48px;
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  box-shadow: var(--shadow-lift);
  font-size: 15px;
  line-height: 1.65;
  user-select: text;
}

/* редактор markdown в предпросмотре: слева исходник, справа рендер */
.lightbox-doc.md-editing {
  width: min(1180px, 100%);
  padding: 16px 18px 18px;
  overflow: hidden;
}

.md-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  width: 100%;
  height: min(66vh, 620px);
}

.md-source {
  resize: none;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  tab-size: 2;
  outline: none;
}

.md-source:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.14);
}

.md-pane {
  overflow: auto;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

#lightboxEdit.is-active {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

@media (max-width: 720px) {
  .md-split {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
    height: min(70vh, 680px);
  }
}

.lightbox-doc[hidden] {
  display: none;
}

.lightbox-doc h1 {
  font-size: 28px;
}

.lightbox-doc h2 {
  font-size: 22px;
}

.lightbox-doc h3 {
  font-size: 18px;
}

.lightbox-doc pre code {
  font-size: 13px;
}

.lightbox-doc .md-table-wrap {
  margin: 14px 0;
}

.lightbox-doc table {
  font-size: 13.5px;
}

/* ---------------------------------- тост ----------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  max-width: min(90vw, 420px);
  padding: 10px 16px;
  border-radius: 10px;
  background: #232427;
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow-lift);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 60;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* --------------------------------- адаптив --------------------------------- */

@media (max-width: 720px) {
  .brand-title {
    font-size: 14px;
  }

  .brand-count {
    display: none;
  }

  .btn-primary {
    padding: 0 11px;
    font-size: 13px;
  }

  .hintbar {
    display: none;
  }
}

@media (max-width: 520px) {
  .zoom {
    display: none;
  }
}

/* --------------------------------- тёмная тема ------------------------------ */

.icon-sun {
  display: none;
}

html[data-theme="dark"] .icon-moon {
  display: none;
}

html[data-theme="dark"] .icon-sun {
  display: block;
}

html[data-theme="dark"] {
  color-scheme: dark;

  --bg: #17181c;
  --dot: #2b2d34;
  --ink: #e7e8ec;
  --muted: #9ca0a8;
  --line: #2f3138;
  --card: #22242a;
  --accent: #5b8def;
  --accent-dark: #4a7de0;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lift: 0 2px 6px rgba(0, 0, 0, 0.4), 0 18px 40px rgba(0, 0, 0, 0.5);
}

html[data-theme="dark"] .topbar {
  background: rgba(23, 24, 28, 0.92);
}

html[data-theme="dark"] .brand-count {
  background: #2a2c33;
}

html[data-theme="dark"] .brand-online {
  background: rgba(63, 163, 63, 0.16);
  color: #86d986;
}

html[data-theme="dark"] .btn-ghost {
  background: #23252b;
}

html[data-theme="dark"] .btn-ghost:hover {
  background: #2b2e35;
  border-color: #3a3d45;
}

html[data-theme="dark"] .btn-icon,
html[data-theme="dark"] .btn-zoom {
  background: #23252b;
}

html[data-theme="dark"] .btn-icon:hover,
html[data-theme="dark"] .btn-zoom:hover {
  background: #2b2e35;
  border-color: #3a3d45;
}

html[data-theme="dark"] .btn.active {
  background: rgba(91, 141, 239, 0.18);
  border-color: rgba(91, 141, 239, 0.55);
  color: #a8c3ff;
}

html[data-theme="dark"] .draw-palette {
  background: #26282f;
}

html[data-theme="dark"] .draw-color.active {
  border-color: #e7e8ec;
  box-shadow: inset 0 0 0 2px #26282f;
}

html[data-theme="dark"] .card {
  border: 1px solid rgba(255, 255, 255, 0.06);
}

html[data-theme="dark"] .card-image,
html[data-theme="dark"] .card-image img {
  background: #2a2c32;
}

html[data-theme="dark"] .file-icon {
  background: rgba(91, 141, 239, 0.16);
  color: #9dbbff;
}

html[data-theme="dark"] .file-download {
  background: #262932;
}

html[data-theme="dark"] .file-download:hover {
  background: #2e323c;
  border-color: #3c4657;
}

html[data-theme="dark"] .progress {
  background: #2c2f36;
}

html[data-theme="dark"] .card-file .card-actions .icon-btn {
  background: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] .card-file .card-actions .icon-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

html[data-theme="dark"] .card-file .card-actions .icon-btn[data-act="delete"]:hover {
  background: #4a1f22;
  color: #ff9a9a;
}

html[data-theme="dark"] .card-error {
  box-shadow: 0 0 0 2px #6b2b2b, var(--shadow);
}

html[data-theme="dark"] .card-error .file-name {
  color: #ff9a9a;
}

html[data-theme="dark"] .md-head,
html[data-theme="dark"] .sheet-head {
  background: #26282f;
}

html[data-theme="dark"] .model-head {
  background: #26282f;
}

html[data-theme="dark"] .model-info {
  background: #2a2c33;
}

html[data-theme="dark"] .model-mode {
  background: rgba(63, 163, 63, 0.18);
  color: #86d986;
}

html[data-theme="dark"] .model-mode.is-soft {
  background: #2a2c33;
  color: #9ca0a8;
}

html[data-theme="dark"] .model-badge {
  background: rgba(155, 110, 255, 0.18);
  color: #c9aaff;
}

html[data-theme="dark"] .model-body,
html[data-theme="dark"] .model-canvas-wide {
  background: #2a2c32;
}

html[data-theme="dark"] .md-badge {
  background: rgba(91, 141, 239, 0.18);
  color: #a8c3ff;
}

html[data-theme="dark"] .sheet-badge {
  background: rgba(63, 163, 63, 0.16);
  color: #86d986;
}

html[data-theme="dark"] .md-body::after,
html[data-theme="dark"] .sheet-body::after {
  background: linear-gradient(rgba(34, 36, 42, 0), var(--card) 72%);
}

html[data-theme="dark"] .md-content {
  color: #d9dbe0;
}

html[data-theme="dark"] .md-content h4,
html[data-theme="dark"] .md-content h5,
html[data-theme="dark"] .md-content h6 {
  color: var(--muted);
}

html[data-theme="dark"] .md-content code {
  background: #2b2e36;
}

html[data-theme="dark"] .md-content pre {
  background: #1b1d22;
}

html[data-theme="dark"] .md-content blockquote {
  border-left-color: #3a3d45;
  color: #aeb2ba;
}

html[data-theme="dark"] .md-content th {
  background: #282b32;
}

html[data-theme="dark"] .md-content a {
  color: #8fb3ff;
}

html[data-theme="dark"] table.sheet-table th {
  background: #282b32;
}

html[data-theme="dark"] .sheet-tab {
  background: #26282f;
}

html[data-theme="dark"] .sheet-tab.active {
  background: rgba(91, 141, 239, 0.18);
  border-color: rgba(91, 141, 239, 0.55);
  color: #a8c3ff;
}

html[data-theme="dark"] .empty-card {
  background: rgba(34, 36, 42, 0.88);
}

html[data-theme="dark"] .empty-icon {
  stroke: #6b6f78;
}

html[data-theme="dark"] .empty-hint {
  color: #8a8e96 !important;
}

html[data-theme="dark"] .hintbar {
  color: #7c8088;
}

html[data-theme="dark"] .hintbar b {
  color: #a3a7af;
}

html[data-theme="dark"] .dropzone {
  border-color: rgba(91, 141, 239, 0.55);
}

html[data-theme="dark"] .dropzone-inner {
  background: #26282f;
  color: #a8c3ff;
}

html[data-theme="dark"] .lightbox-doc {
  background: #1d1f24;
}

html[data-theme="dark"] .lightbox-doc .md-content {
  color: #d9dbe0;
}

html[data-theme="dark"] .resize-handle {
  background-color: rgba(35, 37, 43, 0.95);
  border-color: rgba(255, 255, 255, 0.16);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M13 17L17 13M9 17L17 9' stroke='%23c7cad1' stroke-width='1.7' stroke-linecap='round'/%3E%3C/svg%3E");
}

html[data-theme="dark"] .card-image .resize-handle {
  background-color: rgba(35, 37, 43, 0.92);
  border-color: rgba(255, 255, 255, 0.18);
}
