:root {
  --tool-active: #e0e7ff;
  --tool-active-border: #6366f1;
  --tool-active-text: #4f46e5;
  --surface: #f8fafc;
  --border: #e2e8f0;
  --text: #334155;
  --shadow-lg: 0 8px 20px rgba(0, 0, 0, 0.12);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --radius-xl: 16px;
  --radius-lg: 12px;
  --radius-md: 8px;
  --transition: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

* { user-select: none; box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  margin: 0;
  background: #f1f5f9;
}

.top-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  white-space: nowrap;
}
.top-btn:hover { background: #f1f5f9; border-color: #cbd5e1; }
.top-btn.active-toggle { background: #dcfce7; border-color: #86efac; color: #166534; }
.top-btn.locked-toggle { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }

.cft-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: var(--transition);
  background: transparent; border: none; color: #475569; font-size: 16px;
  position: relative;
}
.cft-btn:hover { background: #f1f5f9; color: #1e293b; }
.cft-btn:active { background: #e2e8f0; transform: scale(0.94); }
.cft-label {
  position: absolute; top: -20px; font-size: 9px; color: #94a3b8;
  white-space: nowrap; font-weight: 500; pointer-events: none; opacity: 0;
  transition: opacity 0.15s;
}
.cft-btn:hover .cft-label { opacity: 1; }

#bottomFloatingBar button,
#rightEdgeToolbar button {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: var(--transition);
  background: transparent; border: none; color: #475569; font-size: 16px;
}
#bottomFloatingBar button:hover,
#rightEdgeToolbar button:hover { background: #f1f5f9; color: #1e293b; }

/* Sidebar styles */
.sidebar-section {
  background: #f8fafc;
  border-radius: var(--radius-lg);
  padding: 10px;
  border: 1px solid #f1f5f9;
}
.sidebar-section-label {
  font-size: 10px; font-weight: 600; color: #94a3b8;
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px;
}
.tool-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.tool-btn-sq {
  aspect-ratio: 1; border-radius: var(--radius-md); display: flex;
  align-items: center; justify-content: center; cursor: pointer;
  transition: var(--transition); background: #fff; border: 1px solid #e2e8f0;
  color: #475569; font-size: 15px; position: relative;
}
.tool-btn-sq:hover { background: #f1f5f9; border-color: #cbd5e1; }
.tool-btn-sq.active {
  background: var(--tool-active); border-color: var(--tool-active-border);
  color: var(--tool-active-text); box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

/* Add more styles as needed – will be expanded in later parts */

/* ---- Widget styles (from references) ---- */
.html-widget, .coord-plane-widget, .calc-widget {
  position: absolute;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 500;
  min-width: 250px;
  min-height: 150px;
  background: #fff;
  display: flex;
  flex-direction: column;
}

.widget-header {
  background: #f39c12;
  padding: 6px 10px;
  border-radius: 12px 12px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: move;
  color: #fff;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}
.coord-plane-widget .widget-header { background: #3498db; }

.widget-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 4px;
}
.widget-close:hover { background: rgba(255,255,255,0.2); }

.widget-content { flex: 1; background: #fff; overflow: hidden; position: relative; }
iframe { width: 100%; height: 100%; border: none; background: #fff; }

.resize-handle-widget {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 16px;
  height: 16px;
  background: #f39c12;
  border-radius: 0 0 10px 0;
  cursor: nw-resize;
  z-index: 10;
  opacity: 0.7;
}
.coord-plane-widget .resize-handle-widget { background: #3498db; }
.resize-handle-widget:hover { opacity: 1; }

/* Coordinator plane internal canvas */
.coord-canvas { width: 100%; height: 100%; display: block; outline: none; }

/* Minimap styles */
.red-viewfinder {
  position: absolute;
  border: 2px solid #ef4444;
  background: rgba(239, 68, 68, 0.2);
  pointer-events: none;
  border-radius: 3px;
}
.cursor-inside {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #3b82f6;
  border: 1.5px solid white;
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 120;
}

/* File Manager overlay styles */
.fm-tabs {
  display: flex;
  border-bottom: 1px solid #e2e8f0;
  padding: 0 20px;
}
.fm-tab {
  padding: 10px 18px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #64748b;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.fm-tab.active {
  color: #4f46e5;
  border-bottom-color: #4f46e5;
}
.fm-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 240px;
  color: #334155;
  font-size: 13px;
}
.fm-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.fm-search {
  flex: 1;
  padding: 8px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  transition: var(--transition);
}
.fm-search:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.fm-view-select {
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  cursor: pointer;
  outline: none;
}
.fm-file-header {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: #f8fafc;
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid #f1f5f9;
}
.fm-file-header span {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color 0.1s;
}
.fm-file-header span:hover { color: #1e293b; }
.sort-icon { font-size: 9px; opacity: 0.5; }
.sort-icon.active { opacity: 1; }

.fm-file-row {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s;
  gap: 8px;
}
.fm-file-row:hover { background: #f1f5f9; }
.fm-file-name { flex: 3; display: flex; align-items: center; gap: 8px; font-weight: 500; }
.fm-file-date { flex: 2; color: #64748b; font-size: 12px; }
.fm-file-size { flex: 1; color: #64748b; font-size: 12px; text-align: right; }
.fm-file-icon { font-size: 20px; color: #4f46e5; width: 24px; text-align: center; }

.fm-large-icons-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
}
.fm-large-icon-item {
  width: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.1s;
  text-align: center;
}
.fm-large-icon-item:hover { background: #f1f5f9; }
.fm-large-icon-item .fm-icon-preview { font-size: 42px; margin-bottom: 6px; color: #4f46e5; line-height: 1; }
.fm-large-icon-item .fm-icon-name { font-size: 11px; font-weight: 500; color: #1e293b; word-break: break-word; }

.fm-medium-icons-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-start;
}
.fm-medium-icon-item {
  width: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 6px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.1s;
}
.fm-medium-icon-item:hover { background: #f1f5f9; }
.fm-medium-icon-item .fm-icon-preview { font-size: 32px; color: #4f46e5; margin-bottom: 4px; }
.fm-medium-icon-item .fm-icon-name { font-size: 10px; font-weight: 500; color: #1e293b; }

@keyframes scaleIn {
  from { transform: scale(0.94); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.animate-scaleIn {
  animation: scaleIn 0.2s ease;
}

/* Sidebar hidden state (used by Teaching Mode) */
#rightSidebar.sidebar-hidden {
  width: 0 !important;
  min-width: 0 !important;
  padding: 0 !important;
  border-left: none !important;
  overflow: hidden;
}

/* Touch & responsive improvements */
body {
  touch-action: pan-x pan-y pinch-zoom;   /* allow canvas gestures but not browser over-zoom */
  -webkit-user-select: none;
}

#whiteboardCanvas {
  touch-action: none;          /* essential for Fabric.js touch drawing */
}

/* Increase tap target sizes for toolbar buttons on small screens */
@media (max-width: 768px) {
  .cft-btn, #bottomFloatingBar button, #rightEdgeToolbar button {
    width: 44px; height: 44px;
  }
}

#bottomFloatingBar button.active,
#rightEdgeToolbar button.active {
  background: rgba(59, 130, 246, 0.3);
  color: #60a5fa;
}
#bottomFloatingBar button.active {
  border-radius: 50%;
}

#uploadBtn, #saveBtn {
  width: 40px; height: 40px; border-radius: 50%;
  background: transparent; border: none; color: #475569; font-size: 16px;
  cursor: pointer;
}
#uploadBtn:hover, #saveBtn:hover {
  background: #f1f5f9;
}

/* Color swatch selection – base (Design 3) + five new border variations */
.color-circle-swatch {
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
  position: relative;
}
.color-circle-swatch.selected {
  border-color: white;
  box-shadow: 0 0 0 2px white;
  z-index: 5;
}
.color-circle-swatch.selected::after {
  content: "✔";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 12px;
  font-weight: bold;
  text-shadow: 0 0 3px rgba(0,0,0,0.5);
}
.color-circle-swatch.selected {
  border-color: white;
  box-shadow:
    0 0 0 0px white,
    0 0 0 2px currentColor,
    0 0 0 8px rgba(255,255,255,0.6);
}

/* Session‑end / confirmation modal overlay */
.session-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.session-modal-box {
  background: #fff;
  border-radius: 20px;
  padding: 32px 28px 24px;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  text-align: center;
  animation: scaleIn 0.2s ease;
}
.session-modal-box h3 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 600;
  color: #1e293b;
}
.session-modal-box p {
  margin: 0 0 24px;
  font-size: 14px;
  color: #475569;
  line-height: 1.5;
}
.session-modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.session-modal-buttons button {
  padding: 8px 22px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: 0.15s;
}
.session-modal-btn-primary {
  background: #ef4444;
  color: #fff;
}
.session-modal-btn-primary:hover {
  background: #dc2626;
}
.session-modal-btn-secondary {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}
.session-modal-btn-secondary:hover {
  background: #e2e8f0;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes scaleIn {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Student floating colour palette (right side) */
#studentColorPalette {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 150;
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 8px 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.student-color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
  position: relative;
}