:root {
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --panel: #ffffff;
  --shadow: 0 2px 14px rgba(15, 23, 42, 0.10), 0 1px 3px rgba(15, 23, 42, 0.06);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #fff; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

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

.panel {
  position: fixed; z-index: 10; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow);
}

/* ---------- кнопки ---------- */
.tb {
  width: 40px; height: 40px; border: 0; background: transparent; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; padding: 0; flex: 0 0 auto;
}
.tb svg { width: 22px; height: 22px; }
.tb:hover { background: #f3f4f6; }
.tb.active { background: var(--accent-soft); color: var(--accent); }
.tb:disabled { opacity: 0.35; cursor: default; background: transparent; }
.tb.small { width: 36px; height: 36px; }
.tb.small svg { width: 20px; height: 20px; }
.tb.off { color: #e03131; }

/* ---------- левая панель инструментов ---------- */
#toolbar {
  left: calc(12px + var(--sal)); top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 2px; padding: 6px;
}
#toolbar .sep { height: 1px; background: var(--line); margin: 4px 4px; }

/* ---------- панель стиля ---------- */
#stylebar {
  left: 50%; bottom: calc(14px + var(--sab)); transform: translateX(-50%);
  display: flex; gap: 6px; padding: 6px; max-width: calc(100vw - 260px); overflow-x: auto; scrollbar-width: none;
}
#stylebar::-webkit-scrollbar { display: none; }
.grp { display: flex; gap: 2px; padding-right: 6px; border-right: 1px solid var(--line); flex: 0 0 auto; align-items: center; }
.grp:last-child { border-right: 0; padding-right: 0; }
.chip {
  width: 36px; height: 36px; border: 0; border-radius: 9px; background: transparent; padding: 0;
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.chip:hover { background: #f3f4f6; }
.chip.active { background: var(--accent-soft); color: var(--accent); }
.chip svg { width: 24px; height: 24px; }
.chip .sw { width: 20px; height: 20px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.15); }
.chip.color.active { background: transparent; }
.chip.color.active .sw { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }
.chip .dot { display: block; border-radius: 50%; background: currentColor; }
.chip .ts { font-weight: 600; }
.chip.danger { color: #e03131; }

/* ---------- масштаб ---------- */
#zoombar {
  right: calc(12px + var(--sar)); bottom: calc(14px + var(--sab));
  display: flex; align-items: center; gap: 2px; padding: 4px;
}
#zoombar.disabled { opacity: 0.45; pointer-events: none; }
.pct { border: 0; background: transparent; min-width: 54px; height: 36px; border-radius: 9px; font-size: 13px; font-variant-numeric: tabular-nums; }
.pct:hover { background: #f3f4f6; }

/* ---------- верх ---------- */
#topbar {
  left: calc(12px + var(--sal)); top: calc(12px + var(--sat));
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; max-width: 46vw;
}
#boardName { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: #f59f00; flex: 0 0 auto; }
.conn.ok { background: #2f9e44; }
#people { display: flex; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; border: 2px solid #fff; margin-left: -6px;
}
.avatar:first-child { margin-left: 0; }

#teacherbar {
  left: 50%; top: calc(12px + var(--sat)); transform: translateX(-50%);
  display: flex; gap: 4px; padding: 5px;
}
.tbtn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent;
  height: 36px; padding: 0 10px; border-radius: 9px; font-size: 13px; white-space: nowrap;
}
.tbtn svg { width: 19px; height: 19px; }
.tbtn:hover { background: #f3f4f6; }
.tbtn.active { background: var(--accent-soft); color: var(--accent); }

.badge {
  position: fixed; z-index: 11; left: 50%; top: calc(64px + var(--sat)); transform: translateX(-50%);
  background: var(--accent); color: #fff; padding: 7px 14px; border-radius: 999px; font-size: 13px;
  box-shadow: var(--shadow); white-space: nowrap; pointer-events: none;
}
.warn-badge { background: #e8590c; top: calc(104px + var(--sat)); }

/* ---------- видео ---------- */
#videos {
  right: calc(12px + var(--sar)); top: calc(12px + var(--sat));
  padding: 6px; display: flex; flex-direction: column; gap: 6px; width: 212px;
}
#tiles { display: flex; flex-direction: column; gap: 6px; }
#videos.collapsed #tiles { display: none; }
#videos.collapsed #btn-vids svg { transform: rotate(180deg); }
.tile { position: relative; width: 198px; aspect-ratio: 16 / 10; background: #111827; border-radius: 10px; overflow: hidden; flex: 0 0 auto; }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.me video { transform: scaleX(-1); }
.tile .ph { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; color: #fff; font-size: 26px; font-weight: 600; }
.tile.nocam video { visibility: hidden; }
.tile.nocam .ph { display: flex; }
.tile .label {
  position: absolute; left: 6px; bottom: 6px; right: 6px; display: flex; align-items: center; gap: 4px;
  color: #fff; font-size: 12px; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.tile .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: rgba(0, 0, 0, 0.45); padding: 2px 6px; border-radius: 6px; }
.tile .mi svg { width: 16px; height: 16px; color: #ff6b6b; background: rgba(0, 0, 0, 0.45); border-radius: 6px; padding: 1px; }
#mediabar { display: flex; justify-content: center; gap: 4px; }
.unmute { border: 0; background: var(--accent); color: #fff; border-radius: 9px; padding: 8px; font-size: 13px; }

/* ---------- подсказки ---------- */
#toast {
  position: fixed; z-index: 30; left: 50%; bottom: calc(76px + var(--sab)); transform: translate(-50%, 20px);
  background: #1f2328; color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- текст на доске ---------- */
.text-editor {
  position: fixed; z-index: 20; margin: 0; padding: 0; border: 1px dashed var(--accent); outline: none;
  background: rgba(255, 255, 255, 0.75); resize: none; overflow: hidden; white-space: pre; line-height: 1.25;
  min-width: 30px; -webkit-user-select: text; user-select: text;
}

/* ---------- окна ---------- */
.overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: #f6f7fb; padding: 20px; }
.card {
  background: #fff; border-radius: 18px; box-shadow: var(--shadow); padding: 28px; width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 10px;
}
.card .logo svg { width: 44px; height: 44px; }
.card h1 { font-size: 22px; margin: 4px 0 0; }
.card label { font-size: 14px; font-weight: 600; margin-top: 8px; }
.card input {
  font: inherit; font-size: 17px; padding: 12px 14px; border: 1px solid #d1d5db; border-radius: 12px; outline: none;
  -webkit-user-select: text; user-select: text;
}
.card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.primary { border: 0; background: var(--accent); color: #fff; font-weight: 600; font-size: 16px; padding: 13px; border-radius: 12px; margin-top: 4px; }
.primary:hover { background: #1d4ed8; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.warn { color: #c2410c; font-size: 13px; margin: 0; }

/* ---------- телефоны и узкие экраны ---------- */
@media (max-width: 760px) {
  #toolbar {
    left: 0; right: 0; top: auto; bottom: 0; transform: none; border-radius: 16px 16px 0 0; border-bottom: 0;
    flex-direction: row; overflow-x: auto; padding: 6px 8px calc(6px + var(--sab)); gap: 2px; scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent); mask-image: linear-gradient(90deg, #000 88%, transparent);
  }
  #toolbar::-webkit-scrollbar { display: none; }
  #toolbar .sep { width: 1px; height: auto; margin: 6px 4px; }
  .tb { width: 44px; height: 44px; }
  #stylebar { left: 8px; right: 8px; transform: none; max-width: none; bottom: calc(66px + var(--sab)); }
  #zoombar { flex-direction: column; right: calc(8px + var(--sar)); bottom: auto; top: 50%; transform: translateY(-50%); padding: 3px; }
  #zoombar .pct, #zoom-in, #zoom-out { display: none; }
  #topbar { left: calc(8px + var(--sal)); top: calc(8px + var(--sat)); padding: 6px 10px; max-width: 40vw; }
  #boardName { display: none; }
  #teacherbar { left: calc(8px + var(--sal)); top: calc(54px + var(--sat)); transform: none; }
  .tbtn span { display: none; }
  .tbtn { padding: 0 8px; }
  #videos { right: calc(8px + var(--sar)); top: calc(8px + var(--sat)); width: auto; max-width: calc(100vw - 120px); padding: 4px; }
  #tiles { flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .tile { width: 92px; aspect-ratio: 4 / 3; }
  .tile .label { font-size: 10px; left: 3px; right: 3px; bottom: 3px; }
  .tile .ph { font-size: 20px; }
  .badge { top: calc(104px + var(--sat)); font-size: 12px; }
  .warn-badge { top: calc(140px + var(--sat)); }
  #toast { bottom: calc(124px + var(--sab)); }
}
@media (pointer: coarse) {
  .chip { width: 40px; height: 40px; }
}
