/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #0f0f1e 0%, #1a1035 50%, #0f1e2e 100%);
  background-attachment: fixed;
  color: #fff;
  min-height: 100vh;
}

/* ===== УТИЛИТЫ ===== */
.glass {
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
}

.gradient-text {
  background: linear-gradient(135deg, #00d2ff, #7b2ff7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 32px;
  background: linear-gradient(135deg, #00d2ff, #7b2ff7);
  border: none;
  border-radius: 50px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 0 30px rgba(123, 47, 247, 0.4);
  transition: transform 0.2s, box-shadow 0.2s;
  text-decoration: none;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 40px rgba(123, 47, 247, 0.6);
}

/* ===== NAVBAR ===== */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar .logo { font-size: 20px; font-weight: 800; }

/* ===== ГЛАВНАЯ СТРАНИЦА ===== */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 65px);
  text-align: center;
  padding: 40px 20px;
}
.hero h1 {
  font-size: clamp(32px, 6vw, 56px);
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 16px;
}
.hero p {
  font-size: 18px;
  color: rgba(255, 255, 255, 0.55);
  margin-bottom: 40px;
  max-width: 480px;
}

/* ===== СТРАНИЦА КОМНАТЫ ===== */
.room-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Топбар */
.room-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  flex-shrink: 0;
  height: 52px;
}
.room-topbar .logo { font-size: 16px; font-weight: 800; }
.room-id { font-size: 13px; color: rgba(255,255,255,0.4); }
.timer { font-size: 14px; color: rgba(255,255,255,0.5); font-variant-numeric: tabular-nums; }

/* ===== ГЛАВНЫЙ МАКЕТ КОМНАТЫ ===== */
.room-main {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 0;
}

/* Левая колонка с видео */
.videos-sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 8px 10px 10px;
  width: 380px;
  flex-shrink: 0;
}
.video-wrapper {
  position: relative;
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16/9;
  width: 100%;
  cursor: pointer;
}
.video-wrapper:hover::after {
  content: '⛶';
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 14px;
  color: rgba(255,255,255,0.4);
  pointer-events: none;
}
.video-wrapper.speaking {
  border-color: rgba(0,210,255,0.5);
  box-shadow: 0 0 16px rgba(0,210,255,0.15);
}
.video-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
}
.video-label {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0,0,0,0.6);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  color: rgba(255,255,255,0.8);
}
.video-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: rgba(255,255,255,0.3);
}

/* Доска */
.board-section {
  flex: 1;
  position: relative;
  margin: 10px 10px 10px 0;
  border-radius: 12px;
  overflow: hidden;
  background: #ffffff;
  min-height: 0;
  min-width: 0;
}
#whiteboard {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}
/* ===== FLOATING DRAGGABLE TOOLBAR ===== */
.board-toolbar {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  user-select: none;
  transition: none;
  background: rgba(15, 15, 30, 0.93);
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 50px;
  backdrop-filter: blur(14px);
  padding: 4px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: row;
  align-items: center;
  max-width: calc(100% - 20px);
}

.board-toolbar.collapsed {
  background: transparent !important;
  border: none !important;
  backdrop-filter: none !important;
  padding: 2px !important;
}

.board-toolbar.collapsed .board-toolbar-content {
  display: none;
}

.board-toolbar-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 4px 2px 2px;
  cursor: grab;
  flex-shrink: 0;
}
.board-toolbar-handle:active { cursor: grabbing; }

.board-toolbar-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00d2ff, #7b2ff7);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0,210,255,0.45), 0 2px 6px rgba(0,0,0,0.5);
  color: white;
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s;
}
.board-toolbar-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 20px rgba(0,210,255,0.6), 0 2px 10px rgba(0,0,0,0.5);
}
.board-toolbar-toggle svg { transition: opacity 0.2s; }

.board-toolbar-content {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 2px;
  padding: 2px 6px 2px 2px;
  max-width: calc(100% - 60px);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.board-toolbar-content::-webkit-scrollbar { display: none; }

.tool-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.65);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  position: relative;
  flex-shrink: 0;
}
.tool-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.tool-btn.active {
  background: linear-gradient(135deg, rgba(0,210,255,0.25), rgba(123,47,247,0.25));
  color: #fff;
}

/* Вертикальный разделитель */
.tool-divider {
  width: 1px;
  height: 26px;
  background: rgba(255,255,255,0.12);
  margin: 0 2px;
  flex-shrink: 0;
}

/* Палитра цветов — горизонтальная */
.color-picker {
  display: flex;
  flex-direction: row;
  gap: 3px;
  padding: 0 2px;
  align-items: center;
}
.color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s;
  flex-shrink: 0;
}
.color-dot:hover, .color-dot.active { transform: scale(1.2); border-color: #fff; }

/* Толщина линии — горизонтальная */
.size-picker {
  display: flex;
  flex-direction: row;
  gap: 5px;
  padding: 0 2px;
  align-items: center;
}
.size-dot {
  border-radius: 50%;
  background: rgba(255,255,255,0.6);
  cursor: pointer;
  transition: transform 0.15s;
  flex-shrink: 0;
}
.size-dot.active, .size-dot:hover { background: #fff; transform: scale(1.15); }

/* Оверлей ожидания */
.waiting-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15,15,30,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 50;
  border-radius: 12px;
}
.waiting-overlay h3 { font-size: 18px; color: rgba(255,255,255,0.8); }
.share-link-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 10px;
  padding: 10px 14px;
  max-width: 360px;
  width: 90%;
}
.share-link-box span {
  flex: 1;
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.copy-btn {
  background: linear-gradient(135deg, #00d2ff, #7b2ff7);
  border: none;
  border-radius: 6px;
  color: #fff;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

/* Нижняя панель управления */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 20px;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
  height: 64px;
}
.ctrl-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
}
.ctrl-btn:hover { background: rgba(255,255,255,0.15); transform: scale(1.08); }
.ctrl-btn.off { background: rgba(255,255,255,0.04); color: rgba(255,255,255,0.3); }
.ctrl-btn.end {
  width: 50px;
  height: 50px;
  background: linear-gradient(135deg, #ff416c, #ff4b2b);
  border: none;
  box-shadow: 0 0 20px rgba(255,65,108,0.4);
  font-size: 20px;
}
.ctrl-btn.end:hover { transform: scale(1.1); box-shadow: 0 0 30px rgba(255,65,108,0.6); }

/* Чат панель */
.chat-panel {
  position: fixed;
  right: 0;
  top: 52px;
  bottom: 64px;
  width: 280px;
  background: rgba(15,15,30,0.95);
  backdrop-filter: blur(10px);
  border-left: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 40;
}
.chat-panel.open { transform: translateX(0); }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
}
.chat-msg.mine {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(0,210,255,0.2), rgba(123,47,247,0.2));
  border: 1px solid rgba(123,47,247,0.3);
}
.chat-msg.peer {
  align-self: flex-start;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
}
.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.07);
}
.chat-input {
  flex: 1;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  color: #fff;
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}
.chat-input::placeholder { color: rgba(255,255,255,0.3); }
.chat-send {
  background: linear-gradient(135deg, #00d2ff, #7b2ff7);
  border: none;
  border-radius: 8px;
  color: #fff;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
}

/* ===== ОВЕРЛЕЙ КОНЦА ЗВОНКА ===== */
.ended-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 200;
}
.ended-overlay.show { display: flex; }
.ended-overlay h2 { font-size: 28px; }
.ended-overlay p { color: rgba(255,255,255,0.5); }

/* ===== ОВЕРЛЕЙ ПЕРЕПОДКЛЮЧЕНИЯ ===== */
.reconnect-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  backdrop-filter: blur(4px);
}
.reconnect-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: #00d2ff;
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 0.8s linear infinite;
}
/* ===== STUDENT TOOLBAR BUTTON ===== */
.student-tools-row {
  padding: 4px 8px 6px;
  display: flex;
  justify-content: center;
}
.student-toolbar-btn {
  font-size: 11px;
  padding: 4px 10px;
  background: rgba(0,210,255,0.15);
  border: 1px solid rgba(0,210,255,0.3);
  border-radius: 8px;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.student-toolbar-btn:hover { background: rgba(0,210,255,0.25); color: #fff; }
.student-toolbar-btn.active {
  background: linear-gradient(135deg, rgba(0,210,255,0.3), rgba(123,47,247,0.3));
  border-color: rgba(0,210,255,0.5);
  color: #fff;
}

/* ===== MEDIA STATE INDICATORS ===== */
.media-indicator {
  position: absolute;
  bottom: 30px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(220,50,50,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  z-index: 5;
}
.media-indicator svg { width: 12px; height: 12px; }
.media-indicator.cam-off { bottom: 30px; right: 34px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== НАВИГАЦИЯ ПО СТРАНИЦАМ ДОСКИ ===== */
.board-pages {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(15,15,30,0.9);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 5px 10px;
  z-index: 10;
}
.page-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.page-btn:hover { background: rgba(255,255,255,0.18); color: #fff; }
.page-btn-add { background: linear-gradient(135deg, rgba(0,210,255,0.2), rgba(123,47,247,0.2)); }
.page-info { font-size: 12px; color: rgba(255,255,255,0.6); min-width: 36px; text-align: center; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
  .videos-sidebar { width: 260px; }
}

@media (max-width: 800px) {
  .room-main { flex-direction: column; }
  .videos-sidebar {
    width: 100%;
    flex-direction: row;
    height: auto;
    padding: 6px;
    gap: 6px;
    flex-shrink: 0;
  }
  .video-wrapper {
    flex: 1;
    min-width: 0;
    max-height: 140px;
  }
  .board-section {
    margin: 0 6px 6px;
    min-height: 300px;
  }
  /* Панель инструментов — компактнее на мобильном */
  .board-toolbar { top: 6px; }
  .board-toolbar-toggle { width: 36px; height: 36px; }
  .board-toolbar-toggle svg { width: 18px; height: 18px; }
  .tool-btn { width: 28px; height: 28px; }
  .tool-btn svg { width: 14px; height: 14px; }
  .color-dot { width: 15px; height: 15px; }
  .room-topbar {
    padding: 6px 12px;
    height: auto;
    min-height: 44px;
    flex-wrap: wrap;
    gap: 4px;
  }
  .controls-bar {
    gap: 8px;
    padding: 6px 10px;
    height: auto;
    flex-wrap: wrap;
  }
  .ctrl-btn { width: 38px; height: 38px; }
  .ctrl-btn.end { width: 44px; height: 44px; }
  .chat-panel {
    width: 100%;
    top: auto;
    bottom: 0;
    height: 50vh;
    transform: translateY(100%);
    border-left: none;
    border-top: 1px solid rgba(255,255,255,0.08);
  }
  .chat-panel.open { transform: translateY(0); }
}

/* Телефон — очень маленький экран */
@media (max-width: 480px) {
  .board-toolbar-toggle { width: 32px; height: 32px; }
  .board-toolbar-toggle svg { width: 16px; height: 16px; }
  .tool-btn { width: 26px; height: 26px; border-radius: 6px; }
  .tool-btn svg { width: 13px; height: 13px; }
  .color-dot { width: 14px; height: 14px; }
}
