/* Маркер — стили доски. Хром в стиле MindMarket: крем-бумага, мягкие радиусы,
   зелёный структурный акцент. Полотно: белая доска (или тёмная по переключателю). */
:root {
  --paper: #f5f1e4;          /* хром: панели */
  --paper-2: #e0dbce;        /* хром: hover */
  --board: #ffffff;          /* полотно доски */
  --ink: #2c2e2a;            /* основной текст хрома */
  --ink-2: #80827f;
  --line: #d5d5d4;
  --cobalt: #8ed462;         /* Fresh Grass — структурный акцент */
  --cobalt-ink: #2c2e2a;
  --red: #ff705d;
  --green: #297a3a;
  --highlight: #f5e211;
  --shadow: 0 0 0 1px var(--line);   /* глубина — только hairline */
  --radius: 10px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Inter", ui-sans-serif, system-ui, sans-serif;
  --hand: "Caveat", cursive;
}

body.dark-board {
  /* тёмная доска меняет только полотно — хром остаётся кремовым */
  --board: #172032;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body.app {
  margin: 0;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
}

button { font-family: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--cobalt);
  outline-offset: 2px;
  border-radius: 6px;
}

.skip-link {
  position: fixed;
  top: -48px;
  left: 16px;
  z-index: 100;
  padding: 8px 14px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 10px;
  text-decoration: none;
  transition: top .15s;
}
.skip-link:focus-visible { top: 10px; }

/* ---------- Верхняя панель ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 54px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  overflow-x: auto;
  scrollbar-width: none;
  flex: none;
}
.topbar::-webkit-scrollbar { display: none; }

/* профиль: прилипает к правому краю ленты топбара — всегда виден */
#profileBtn {
  position: sticky;
  right: 6px;
  background: var(--paper);
  box-shadow: -14px 0 12px -10px var(--paper);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -.01em;
  text-decoration: none;
  color: var(--ink);
  white-space: nowrap;
  margin-right: 4px;
}
.brand svg { width: 22px; height: 22px; }

.sep { width: 1px; height: 22px; background: var(--line); flex: none; }

.pages { display: flex; gap: 4px; align-items: center; }
.page-pill {
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.page-pill:hover { background: var(--paper-2); }
.page-pill.active { background: var(--cobalt); color: var(--cobalt-ink); }
.page-pill.add { color: var(--ink-2); font-weight: 500; }

.top-group { display: flex; gap: 6px; align-items: center; white-space: nowrap; }

.snap-group .btn.accent { font-weight: 600; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 9999px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: transform .2s cubic-bezier(.22, 1.2, .36, 1), background .15s, color .15s, box-shadow .15s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn.accent { background: var(--cobalt); color: var(--cobalt-ink); }
.btn.accent:hover { background: #9eda75; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--paper-2); }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger:hover { background: #f0604d; }
.btn.sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  transition: background .15s, color .15s, transform .15s;
  touch-action: manipulation;
  flex: none;
}
.icon-btn:hover { background: var(--paper-2); }
.icon-btn:active { transform: scale(.94); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.danger:hover { color: var(--red); }

/* ---------- Рабочая область ---------- */
.workspace { display: flex; flex: 1; min-height: 0; }

.toolbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 60px;
  padding: 10px 0 12px;
  border-right: 1px solid var(--line);
  background: var(--paper);
  flex: none;
  overflow-y: auto;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }

.tool-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  transition: background .15s, color .15s, transform .15s;
  touch-action: manipulation;
  flex: none;
}
.tool-btn:hover { background: var(--paper-2); }
.tool-btn:active { transform: scale(.93); }
.tool-btn.active { background: var(--cobalt); color: var(--cobalt-ink); }
.tool-btn:disabled { opacity: .35; cursor: not-allowed; }
.tool-btn svg { width: 21px; height: 21px; }

.divider { width: 26px; height: 1px; background: var(--line); margin: 5px 0; flex: none; }

.colors { display: flex; flex-direction: column; gap: 7px; }
.colors button {
  width: 19px;
  height: 19px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  background: var(--swatch, var(--ink));
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(23, 23, 23, .18);
  transition: transform .15s, box-shadow .15s;
  touch-action: manipulation;
  flex: none;
}
.colors button:hover { transform: scale(1.15); }
.colors button[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--cobalt);
}

/* ---------- Микро-анимации кнопок (motion) ---------- */
@keyframes btnPop {
  0% { transform: scale(.955); }
  60% { transform: scale(1.03); }
  100% { transform: scale(1); }
}
.tool-btn.pop, .icon-btn.pop, .btn.pop, .colors button.pop, .sizes button.pop, .colors-pop button.pop, .timer-widget .tw-btn.pop, .timer-widget .tw-time.pop {
  animation: btnPop .2s cubic-bezier(.22, 1.2, .36, 1);
}
.tool-btn, .icon-btn {
  transition: background .15s, color .15s, transform .3s cubic-bezier(.34, 1.56, .64, 1), box-shadow .2s;
}
.tool-btn:hover, .icon-btn:hover { transform: translateY(-2px); }
.tool-btn:active, .icon-btn:active, .btn:active { transform: scale(.965); }
.colors button.pop { animation: btnPop .28s cubic-bezier(.34, 1.56, .64, 1); }
@media (prefers-reduced-motion: reduce) {
  .tool-btn.pop, .icon-btn.pop, .btn.pop, .colors button.pop, .sizes button.pop, .timer-widget .tw-btn.pop { animation: none; }
  .tool-btn:hover, .icon-btn:hover { transform: none; }
}

/* ---------- Палитра цветов ---------- */
#colorMoreBtn {
  position: relative;
  background: var(--swatch, conic-gradient(#E5484D, #F59E0B, #2BA46C, #2B59FF, #8B5CF6, #E5484D));
}
#colorMoreBtn .rainbow { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
#colorMoreBtn .rainbow::after {
  content: '+';
  font-weight: 800;
  font-size: 13px;
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .55);
}
.color-popover {
  position: fixed;
  left: 70px;
  top: 296px;
  z-index: 30;
  width: 182px;
  padding: 9px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  transform: scale(.9) translateY(10px);
  transform-origin: left top;
  transition: opacity .16s ease-out, transform .24s cubic-bezier(.22, 1.2, .36, 1), visibility 0s linear .24s;
}
.color-popover.open {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0s;
}
.color-popover .swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
}
.color-popover .swatches button {
  width: 23px;
  height: 23px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  background: var(--swatch);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(23, 23, 23, .18);
  transition: transform .15s, box-shadow .15s;
  touch-action: manipulation;
}
.color-popover .swatches button:hover { transform: scale(1.18); }
.color-popover .swatches button:active { transform: scale(.95); }
.color-popover .swatches button[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--cobalt);
}
.color-popover .custom-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 9px;
  padding: 7px 8px 3px;
  border-top: 1px solid var(--line);
  cursor: pointer;
  border-radius: 8px;
}
.color-popover .custom-row:hover { background: var(--paper-2); }
.color-popover .custom-row input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
}
.color-popover .custom-wheel {
  width: 23px;
  height: 23px;
  border-radius: 50%;
  flex: none;
  background: conic-gradient(#E5484D, #F59E0B, #2BA46C, #2B59FF, #8B5CF6, #E5484D);
  box-shadow: inset 0 0 0 1px rgba(23, 23, 23, .18);
}
.color-popover .custom-row[data-filled="true"] .custom-wheel { background: var(--custom, conic-gradient(#E5484D, #F59E0B, #2BA46C, #2B59FF, #8B5CF6, #E5484D)); }
.color-popover .custom-label { font-size: 12.5px; font-weight: 500; color: var(--ink); }
.size-slider { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 2px 0 6px; }
.size-preview {
  width: 36px; height: 24px;
  display: grid; place-items: center;
}
.size-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--ink);
  transform: scale(.5);
  transition: transform .3s cubic-bezier(.34, 1.56, .64, 1), border-radius .2s, background .2s;
}
.size-dot.eraser { border-radius: 4px; background: transparent; border: 1.5px solid var(--ink); }
.size-range-wrap { position: relative; width: 22px; height: 92px; }
#sizeRange {
  -webkit-appearance: none; appearance: none;
  width: 92px; height: 22px;
  background: transparent;
  cursor: pointer;
  margin: 0;
  position: absolute;
  left: -35px;
  top: 35px;
  transform: rotate(-90deg);
}
#sizeRange::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--cobalt) var(--fill, 50%), var(--line) var(--fill, 50%));
}
#sizeRange::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .22);
  margin-top: -5px;
  transition: transform .3s cubic-bezier(.34, 1.56, .64, 1), box-shadow .15s;
}
#sizeRange:hover::-webkit-slider-thumb { transform: scale(1.15); box-shadow: 0 0 0 5px rgba(43, 89, 255, .14); }
#sizeRange:active::-webkit-slider-thumb { transform: scale(1.28); }
#sizeRange::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
#sizeRange::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--cobalt); }
#sizeRange::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .22);
}
.sizes button[aria-pressed="true"] { background: var(--paper-2); box-shadow: inset 0 0 0 1.5px var(--cobalt); }

/* Режим ластика — всплывает рядом с панелью */
.eraser-mode {
  position: fixed;
  left: 70px;
  top: 150px;
  z-index: 30;
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 5px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
body[data-tool="eraser"] .eraser-mode { display: flex; }
.eraser-mode button {
  padding: 7px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.eraser-mode button:hover { background: var(--paper-2); }
.eraser-mode button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

/* Выбор фигуры — всплывает рядом с панелью, когда активен инструмент «Фигуры» */
.shape-popover {
  position: fixed;
  left: 70px;
  top: 200px;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  width: 108px;
  padding: 7px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  transform: scale(.9) translateY(10px);
  transform-origin: left top;
  transition: opacity .16s ease-out, transform .24s cubic-bezier(.22, 1.2, .36, 1), visibility 0s linear .24s;
}
.shape-popover.open {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0s;
}
.shape-popover button {
  width: 43px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background .15s, transform .2s cubic-bezier(.22, 1.2, .36, 1);
  touch-action: manipulation;
}
.shape-popover button:hover { background: var(--paper-2); transform: scale(1.1); }
.shape-popover button:active { transform: scale(.94); }
.shape-popover button[aria-pressed="true"] { background: var(--cobalt); color: var(--cobalt-ink); }
.shape-popover button svg { width: 19px; height: 19px; }

/* ---------- Полотно ---------- */
.canvas-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  background: var(--board);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.canvas-wrap canvas { position: absolute; inset: 0; display: block; }
/* слой чужих курсоров — только рисует, никогда не ловит мышь (иначе съедает клики доски) */
#remoteCur { pointer-events: none; }

.canvas-wrap[data-tool="pen"], .canvas-wrap[data-tool="marker"] { cursor: crosshair; }
.canvas-wrap[data-tool="shape"] { cursor: crosshair; }
.canvas-wrap[data-tool="text"] { cursor: text; }
.canvas-wrap[data-tool="eraser"] { cursor: none; }
.canvas-wrap[data-panning="true"] { cursor: grabbing; }

.text-input {
  position: absolute;
  z-index: 20;
  margin: 0;
  padding: 0;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--hand);
  font-weight: 600;
  line-height: 1.15;
  min-width: 60px;
  resize: none;
  overflow: hidden;
  white-space: pre;
}
.text-input:focus { box-shadow: 0 2px 0 var(--cobalt); border-radius: 4px; }

.hint-card {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 340px;
  padding: 18px 22px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  pointer-events: none;
  transition: opacity .3s;
}
.hint-card.gone { opacity: 0; }
.hint-title { margin: 0 0 6px; font-weight: 700; font-size: 15px; }
.hint-card p { margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--ink-2); }

.zoombar {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.zoom-label {
  min-width: 52px;
  padding: 5px 4px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.zoom-label:hover { background: var(--paper-2); }

/* ---------- Тосты ---------- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 60;
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  font-weight: 400;
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .16);
  opacity: 0;
  transform: translateY(10px) scale(.97);
  transition: opacity .22s, transform .22s cubic-bezier(.2, .9, .3, 1.3);
  max-width: min(90vw, 480px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); }

/* ---------- Модальные окна ---------- */
.modal-root { position: relative; z-index: 70; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(23, 23, 23, .38);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity .18s;
  overscroll-behavior: contain;
}
.modal.open { opacity: 1; }
.modal[hidden] { display: none; }

.modal-card {
  background: var(--paper);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
  width: 100%;
  transform: translateY(10px) scale(.97);
  transition: transform .2s cubic-bezier(.2, .9, .3, 1.2);
}
.modal.open .modal-card { transform: none; }

.confirm-card { max-width: 420px; }
.confirm-card h2 { margin: 0 0 8px; font-size: 19px; }

.compare-card { max-width: min(880px, 94vw); }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-note { margin: 12px 0 0; font-size: 13.5px; color: var(--ink-2); line-height: 1.5; }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

.cmp-stage {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #FDFDFB;
  user-select: none;
  -webkit-user-select: none;
}
.cmp-stage img { display: block; width: 100%; height: auto; }
.cmp-after-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.cmp-after-wrap img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.cmp-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: #fff;
  cursor: ew-resize;
  touch-action: none;
}
.cmp-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .12);
  cursor: ew-resize;
}
.cmp-knob::before {
  content: "";
  position: absolute;
  inset: 11px;
  background: conic-gradient(from 90deg, var(--ink) 0 25%, transparent 25% 50%, var(--ink) 50% 75%, transparent 75%);
  -webkit-mask: radial-gradient(circle, transparent 34%, #000 36%);
  mask: radial-gradient(circle, transparent 34%, #000 36%);
}
.cmp-tag {
  position: absolute;
  top: 12px;
  padding: 4px 12px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .071em;
  text-transform: uppercase;
  color: var(--ink);
  background: rgba(250, 250, 250, .92);
  border: 1px solid var(--line);
  border-radius: 4px;
  transition: opacity .2s;
}
.cmp-tag-before { left: 12px; }
.cmp-tag-after { right: 12px; }

/* ---------- Мобильная раскладка ---------- */
@media (max-width: 760px) {
  .snap-group .btn { padding: 0 10px; }
  .brand span { display: none; }
  .toolbar { width: 52px; }
  .tool-btn { width: 38px; height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

.plot-input {
  position: absolute;
  z-index: 25;
  padding: 9px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-family: var(--font);
  font-size: 15px;
  color: var(--ink);
  outline: none;
  width: 240px;
}
.plot-input:focus { box-shadow: 0 0 0 2px var(--cobalt); }

/* ---------- Таймлапс урока ---------- */
.timelapse-card { max-width: min(920px, 94vw); }
#tlCanvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: #FDFDFB;
  border: 1px solid var(--line);
}
.tl-controls { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.tl-progress { flex: 1; height: 6px; border-radius: 999px; background: var(--paper-2); overflow: hidden; }
.tl-progress i { display: block; height: 100%; background: var(--cobalt); width: 0; border-radius: 999px; transition: width .12s linear; }
.tl-speed {
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-family: var(--font);
  font-size: 13px;
  color: var(--ink);
}

/* ---------- Горячие клавиши ---------- */
.keys-card { max-width: 520px; }
.keys-grid { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; align-items: center; }
.keys-card kbd {
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 8px;
  white-space: nowrap;
}
.icon-btn[aria-pressed="true"] { background: var(--cobalt); color: var(--cobalt-ink); }

/* ---------- Меню «Исправления» ---------- */
.fix-menu {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translate(-50%, -8px);
  z-index: 45;
  display: none;
  flex-direction: column;
  gap: 4px;
  width: 320px;
  padding: 10px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .16s ease-out, transform .22s cubic-bezier(.22, 1.2, .36, 1);
}
.fix-menu.open { display: flex; opacity: 1; transform: translate(-50%, 0); }
.fix-row {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
}
.fix-row:hover { background: var(--paper-2); }
.fix-row input { grid-row: 1 / 3; align-self: center; width: 17px; height: 17px; accent-color: var(--cobalt); margin: 0; }
.fix-name { font-size: 14px; font-weight: 500; color: var(--ink); }
.fix-hint { font-size: 12.5px; color: var(--ink-2); grid-column: 2; }
.fix-note { margin: 6px 10px 2px; font-size: 12px; color: var(--ink-2); }

/* ---------- Таймер урока (пилюля справа сверху) ---------- */
.timer-widget {
  position: fixed;
  top: 62px;
  right: 14px;
  z-index: 55;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 9999px;
  box-shadow: var(--shadow);
}
.tw-time {
  padding: 3px 8px;
  border: 0;
  border-radius: 9999px;
  background: transparent;
  cursor: pointer;
  font: 600 21px Caveat, cursive;
  color: var(--ink);
  transition: background .15s, transform .3s cubic-bezier(.34, 1.56, .64, 1);
}
.tw-time:hover { background: var(--paper-2); transform: scale(1.06); }
.tw-time.idle { color: var(--ink-2); font: 500 13px Inter, sans-serif; }
.tw-btn {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 0;
  background: var(--paper-2);
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
  color: var(--ink);
  display: grid;
  place-items: center;
  transition: background .15s, transform .3s cubic-bezier(.34, 1.56, .64, 1);
}
.tw-btn:hover { background: var(--cobalt); color: var(--cobalt-ink); transform: scale(1.12); }
.tw-btn[hidden], .tw-time[hidden] { display: none !important; }
.timer-widget.warn { border-color: #D97706; animation: timerWarn 1.8s ease-in-out infinite; }
@keyframes timerWarn {
  0%, 100% { box-shadow: var(--shadow); }
  50% { box-shadow: var(--shadow), 0 0 0 9px rgba(217, 119, 6, .16); }
}
.timer-widget.over { border-color: #E5484D; }

/* ---------- Мои уроки (облако) ---------- */
.lessons-menu {
  position: fixed;
  z-index: 60;
  width: 300px;
  padding: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
#lessonsSave {
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 9px;
  background: var(--cobalt);
  color: var(--cobalt-ink);
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  transition: opacity .15s, transform .3s cubic-bezier(.34, 1.56, .64, 1);
}
#lessonsSave:active { transform: scale(.97); }
.les-list { margin-top: 8px; max-height: 300px; overflow: auto; }
.les-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.les-open {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: background .15s;
}
.les-open:hover { background: var(--paper-2); }
.les-name { font-weight: 500; font-size: 13px; color: var(--ink); }
.les-date { margin-left: auto; font-size: 11px; color: var(--ink-2); }
.les-del {
  width: 26px; height: 26px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  font-size: 13px;
  transition: background .15s, color .15s;
}
.les-del:hover { background: #fde8e8; color: #E5484D; }
.les-empty { padding: 10px; font-size: 12.5px; color: var(--ink-2); text-align: center; }

/* ---------- Код владельца уроков ---------- */
.code-pop {
  position: fixed;
  z-index: 60;
  width: 300px;
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.cp-title { font-weight: 600; font-size: 14px; color: var(--ink); margin-bottom: 6px; }
.cp-title2 { font-weight: 600; font-size: 13px; color: var(--ink); margin: 10px 0 6px; }
.cp-text { font-size: 12.5px; line-height: 1.45; color: var(--ink-2); margin: 0 0 10px; }
.cp-row { display: flex; align-items: center; gap: 6px; }
.cp-code {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-2);
  font: 500 11px ui-monospace, monospace;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
}
.cp-code[readonly] { color: var(--ink-2); }
.cp-mini {
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: var(--paper-2);
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  color: var(--ink);
  transition: background .15s, transform .3s cubic-bezier(.34, 1.56, .64, 1);
  flex: none;
}
.cp-mini:hover { background: var(--line); }
.cp-mini.accent { background: var(--cobalt); color: var(--cobalt-ink); }
.cp-mini.accent:hover { opacity: .92; }
.cp-sep { height: 1px; background: var(--line); margin: 10px 0; }
.cp-hint { font-size: 11.5px; color: var(--ink-2); margin: 8px 0 0; line-height: 1.4; }

/* ---------- Адаптив: планшет и телефон ---------- */
@media (max-width: 1024px) {
  .cls-tablet { display: none !important; }
}
@media (max-width: 640px) {
  .cls-phone, .cls-tablet { display: none !important; }
  #colorGroup button:nth-child(n+3):not(#colorMoreBtn) { display: none; }  /* чёрный и синий */
  .tool-btn[data-tool="marker"], .tool-btn[data-tool="shape"], .tool-btn[data-tool="text"] { display: none; }
  .brand svg { width: 22px; }
  .timer-widget { top: 56px; right: 8px; padding: 4px 8px; }
  .tw-time { font-size: 18px; min-width: 52px; }
}

/* поповер настроек таймера */
.timer-pop {
  position: fixed;
  top: 100px;
  right: 14px;
  z-index: 56;
  width: 190px;
  padding: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  transform: scale(.88) translateY(-8px);
  transform-origin: right top;
  transition: opacity .16s ease-out, transform .42s cubic-bezier(.34, 1.56, .64, 1), visibility 0s linear .42s;
}
.timer-pop.open {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0s;
}
.tp-row { display: flex; align-items: baseline; justify-content: space-between; padding: 2px 4px 9px; }
.tp-label { font-size: 12px; color: var(--ink-2); }
.tm-set { font: 600 21px Caveat, cursive; color: var(--ink); }
.tp-add {
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  transition: background .15s, transform .3s cubic-bezier(.34, 1.56, .64, 1);
}
.tp-add:hover { background: var(--paper-2); }
.tp-add:active { transform: scale(.96); }
.tp-actions { display: flex; gap: 6px; margin-top: 8px; }
.tp-start {
  flex: 1;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: var(--cobalt);
  color: var(--cobalt-ink);
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  transition: opacity .15s, transform .3s cubic-bezier(.34, 1.56, .64, 1);
}
.tp-start:disabled { opacity: .45; cursor: default; }
.tp-start:not(:disabled):active { transform: scale(.96); }
.tp-reset {
  padding: 8px 12px;
  border: 0;
  border-radius: 9px;
  background: var(--paper-2);
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  color: var(--ink);
  transition: background .15s;
}
.tp-reset:hover { background: var(--line); }

/* ---------- Заготовки урока ---------- */
.tpl-menu {
  position: fixed;
  z-index: 60;
  display: flex;
  flex-direction: column;
  min-width: 240px;
  padding: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.tpl-menu button {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-weight: 500;
  font-size: 13.5px;
  color: var(--ink);
  transition: background .15s;
}
.tpl-menu button:hover { background: var(--paper-2); }
.tpl-menu .tpl-note { margin-left: auto; font-size: 11.5px; font-weight: 400; color: var(--ink-2); }
.btn.on { box-shadow: 0 0 0 2px var(--cobalt); }

/* ---------- ИИ-распознавание ---------- */
.ai-busy[hidden] { display: none; }
.ai-busy {
  position: fixed;
  left: 50%;
  top: 76px;
  transform: translateX(-50%);
  z-index: 65;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 22px;
  background: var(--paper);
  border-radius: 9999px;
  box-shadow: 0 0 0 1px var(--line), 0 10px 26px rgba(0, 0, 0, .18);
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
}
.ai-spin {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2.5px solid var(--green);
  border-top-color: transparent;
  animation: aiSpin .8s linear infinite;
  flex: none;
}
@keyframes aiSpin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ai-spin { animation: none; } }

.ai-card { max-width: 560px; }
.ai-note { margin: 0 0 16px; font-size: 14px; color: var(--ink-2); line-height: 1.5; }
.ai-note strong { color: var(--ink); font-weight: 500; }
.ai-field { display: grid; gap: 6px; margin: 0 0 14px; }
.ai-field span { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.ai-field input {
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--cream);
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  outline: none;
}
.ai-field input:focus { box-shadow: 0 0 0 2px var(--green); }
.btn.on-fix { box-shadow: 0 0 0 2px var(--green); }

/* ---------- Окно аккаунта: живая сценка слева ---------- */
.auth-card {
  width: min(700px, 94vw);
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0;
  padding: 0 !important;
  overflow: hidden;
}
.auth-side {
  background: #f5f1e4;
  border-right: 1.5px solid var(--line);
  padding: 10px 6px;
  user-select: none;
}
.auth-side svg { width: 100%; height: 100%; display: block; }
.auth-main { padding: 22px 24px; min-width: 0; }
.auth-main .modal-head { margin-bottom: 14px; }
/* формула появляется и стирается, ластик проходит по доске */
@keyframes authFmt {
  0%, 12% { opacity: 0; transform: translateY(-6px); }
  24%, 72% { opacity: 1; transform: translateY(0); }
  84%, 100% { opacity: 0; }
}
@keyframes authLine {
  0%, 16% { stroke-dashoffset: 1; }
  32%, 68% { stroke-dashoffset: 0; }
  84%, 100% { stroke-dashoffset: 1; }
}
@keyframes authEraser {
  0%, 20% { transform: translateX(6px); opacity: 0; }
  30%, 70% { opacity: 1; }
  74%, 80% { transform: translateX(156px); opacity: 1; }
  88%, 100% { transform: translateX(156px); opacity: 0; }
}
.auth-fmt { animation: authFmt 6.5s ease-in-out infinite; }
.auth-line { stroke-dasharray: 1; stroke-dashoffset: 1; animation: authLine 6.5s ease-in-out infinite; }
.auth-eraser { animation: authEraser 6.5s ease-in-out infinite; }
@keyframes authBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}
.auth-bob { animation: authBob 3.2s ease-in-out infinite; }
.auth-bob:nth-of-type(2) { animation-delay: .6s; }
.auth-bob:nth-of-type(3) { animation-delay: 1.1s; }
@media (max-width: 760px) {
  .auth-card { grid-template-columns: 1fr; }
  .auth-side { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .auth-fmt, .auth-line, .auth-eraser, .auth-bob { animation: none; }
  .auth-fmt { opacity: 1; }
  .auth-line { stroke-dashoffset: 0; }
}
