/* ============================================================
   Blackboard — black.imby.gg
   Optimised for Vibe S1 touchscreen (55" 4K) + stylus
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  /* NOTE: touch-action NOT set globally — sliders and inputs need their own touch handling */
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ── Canvas ─────────────────────────────────────────────── */
#canvas {
  display: block;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: none;
  touch-action: none;   /* canvas only: prevent scroll/zoom */
}

/* ── Custom cursor ring ──────────────────────────────────── */
#cursor-ring {
  position: fixed;
  pointer-events: none;
  border: 2px solid rgba(255,255,255,0.7);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.1s ease, height 0.1s ease, border-color 0.1s ease;
  mix-blend-mode: difference;
  z-index: 9999;
  will-change: left, top;
}

/* ── Toolbar ─────────────────────────────────────────────── */
.toolbar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: rgba(18, 18, 22, 0.88);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 22px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.6),
    0 2px 8px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.08);
  z-index: 1000;
  user-select: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  touch-action: none;
}

.toolbar.hidden {
  opacity: 0;
  pointer-events: none;
}

.separator {
  width: 1px;
  height: 44px;
  background: rgba(255,255,255,0.12);
  flex-shrink: 0;
  margin: 0 2px;
}

/* ── Tool groups ─────────────────────────────────────────── */
.tool-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.group-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
}

/* ── Tool buttons ────────────────────────────────────────── */
.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 10px;
  min-width: 60px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.5);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.tool-btn svg {
  width: 26px;
  height: 26px;
  transition: transform 0.15s ease;
}

.tool-btn span {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.03em;
}

.tool-btn:hover {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.8);
}

.tool-btn:hover svg {
  transform: scale(1.1);
}

.tool-btn.active {
  background: rgba(255,255,255,0.14);
  color: #fff;
}

.tool-btn.active::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 18px;
  height: 2.5px;
  background: var(--accent, #fff);
  border-radius: 2px;
}

/* ── Color swatches ──────────────────────────────────────── */
.color-swatches {
  display: flex;
  gap: 6px;
  align-items: center;
}

.color-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  background: var(--c, #555);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.color-btn:hover {
  transform: scale(1.2);
  box-shadow: 0 0 12px var(--c, #555), 0 0 4px var(--c, #555);
}

.color-btn.active {
  border-color: #fff;
  transform: scale(1.25);
  box-shadow: 0 0 16px var(--c, #555), 0 0 6px var(--c, #555);
}

/* The rainbow "custom" button doesn't have a --c var */
.custom-color-btn {
  background: rgba(255,255,255,0.1);
  border: 2px dashed rgba(255,255,255,0.35);
}

.custom-color-btn:hover {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.7);
  box-shadow: none;
  transform: scale(1.15);
}

/* ── Size group ──────────────────────────────────────────── */
.size-group {
  flex-direction: column;
  gap: 5px;
  align-items: center;
}

.size-dots {
  display: flex;
  align-items: center;
  gap: 8px;
}

.size-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.12s ease;
}

.size-btn:hover {
  background: rgba(255,255,255,0.08);
}

.size-btn.active .dot {
  background: #fff;
  box-shadow: 0 0 8px rgba(255,255,255,0.5);
}

.dot {
  display: block;
  width: var(--s, 10px);
  height: var(--s, 10px);
  border-radius: 50%;
  background: rgba(255,255,255,0.4);
  transition: background 0.12s ease, box-shadow 0.12s ease;
  pointer-events: none;
}

/* ── Range sliders ───────────────────────────────────────── */
.size-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 6px;
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  touch-action: none;   /* let pointer events handle it */
}

.size-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 8px rgba(255,255,255,0.4);
  cursor: pointer;
  transition: transform 0.12s ease;
}

.size-slider::-webkit-slider-thumb:hover,
.size-slider::-webkit-slider-thumb:active {
  transform: scale(1.25);
}

.size-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: #fff;
  box-shadow: 0 0 8px rgba(255,255,255,0.4);
  cursor: pointer;
}

/* ── Action buttons ──────────────────────────────────────── */
.actions-group { gap: 2px; }

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 10px;
  min-width: 50px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.5);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.action-btn svg {
  width: 22px;
  height: 22px;
}

.action-btn span:not(.badge) {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.03em;
}

.action-btn:hover {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.9);
}

.action-btn:active { transform: scale(0.94); }
#btn-clear:hover   { color: #ff6688; }
#btn-chat.active   { color: #66AAFF; background: rgba(102,170,255,0.12); }

/* ── Unread badge ────────────────────────────────────────── */
.badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: #ff4466;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  border-radius: 8px;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.badge.visible { display: flex; }

/* ── Chat panel ──────────────────────────────────────────── */
#chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: rgba(12, 12, 18, 0.92);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-left: 1px solid rgba(255,255,255,0.1);
  z-index: 1100;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  touch-action: auto;
}

#chat-panel.open {
  transform: translateX(0);
}

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}

#online-count {
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#online-count::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #44ff88;
  margin-right: 6px;
  box-shadow: 0 0 6px #44ff88;
  animation: pulse-dot 2.5s ease infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

#chat-close {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.4);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  transition: all 0.15s;
}

#chat-close:hover { color: #fff; background: rgba(255,255,255,0.08); }

/* Messages */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 2px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  animation: msg-in 0.2s ease;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.chat-msg-user {
  font-size: 11px;
  font-weight: 700;
  color: var(--user-color, #66AAFF);
  letter-spacing: 0.02em;
}

.chat-msg-time {
  font-size: 10px;
  color: rgba(255,255,255,0.25);
}

.chat-msg-text {
  font-size: 13px;
  color: rgba(255,255,255,0.82);
  line-height: 1.45;
  word-break: break-word;
}

.chat-msg.system .chat-msg-text {
  font-size: 11px;
  color: rgba(255,255,255,0.3);
  font-style: italic;
}

/* Footer */
#chat-footer {
  flex-shrink: 0;
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.07);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#chat-name {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  color: rgba(255,255,255,0.7);
  font-size: 12px;
  padding: 7px 12px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s, background 0.15s;
  touch-action: auto;
}

#chat-name::placeholder { color: rgba(255,255,255,0.25); }
#chat-name:focus {
  border-color: rgba(102,170,255,0.5);
  background: rgba(255,255,255,0.09);
}

#chat-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

#chat-input {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  color: #fff;
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
  touch-action: auto;
}

#chat-input::placeholder { color: rgba(255,255,255,0.3); }
#chat-input:focus {
  border-color: rgba(102,170,255,0.5);
  background: rgba(255,255,255,0.09);
}

#chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #66AAFF;
  color: #000;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.12s ease, background 0.12s ease;
}

#chat-send svg { width: 18px; height: 18px; }
#chat-send:hover  { background: #88CCFF; }
#chat-send:active { transform: scale(0.92); }

/* ── Toast ────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: rgba(30,30,36,0.92);
  border: 1px solid rgba(255,255,255,0.1);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 24px;
  border-radius: 100px;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  z-index: 2000;
  backdrop-filter: blur(12px);
  white-space: nowrap;
}

#toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
