* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
  background: #f5f5f5;
}

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

#toolbar {
  width: 60px;
  background: #2d2d2d;
  display: flex;
  flex-direction: column;
  padding: 10px 5px;
  gap: 5px;
  z-index: 10;
}

.tool-btn {
  width: 50px;
  height: 50px;
  border: none;
  border-radius: 8px;
  background: #3d3d3d;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  position: relative;
}

.tool-btn:hover {
  background: #4d4d4d;
}

.tool-btn.active {
  background: #3498db;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.4);
}

.tool-btn svg {
  width: 24px;
  height: 24px;
  stroke: white;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-shortcut {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 9px;
  color: rgba(255,255,255,0.5);
  font-weight: bold;
  opacity: 0;
  transition: opacity 0.2s;
}

#toolbar:hover .tool-shortcut {
  opacity: 1;
}

.tool-btn.active .tool-shortcut {
  color: rgba(255,255,255,0.8);
}

.divider {
  height: 1px;
  background: #4d4d4d;
  margin: 5px 0;
}

#color-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 5px;
}

.color-swatch {
  width: 40px;
  height: 32px;
  border: 3px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}

.color-swatch:hover {
  transform: scale(1.05);
}

.color-swatch.active {
  border-color: white;
}

#color-picker-popup {
  display: none;
  position: fixed;
  background: #2d2d2d;
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 1000;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.color-option {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s, border-color 0.1s;
}

.color-option:hover {
  transform: scale(1.15);
  border-color: white;
}

#canvas-container {
  flex: 1;
  position: relative;
  background: white;
  overflow: hidden;
  cursor: none;
}

#canvas {
  position: absolute;
  top: 0;
  left: 0;
  cursor: default;
}

#text-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.text-element {
  position: absolute;
  font-size: 20px;
  font-weight: bold;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.2;
  white-space: pre-wrap;
  pointer-events: auto;
  cursor: none;
  padding: 2px 4px;
  border-radius: 3px;
  min-width: 20px;
  min-height: 24px;
  outline: none;
}

#canvas-container[data-tool="eraser"] .text-element {
  pointer-events: none;
}

#canvas-container[data-tool="move"] .text-element:not(.editing):hover,
#canvas-container[data-tool="text"] .text-element:not(.editing):hover {
  text-decoration: underline;
}

.text-element.selected {
  outline: 2px dashed #3498db;
  outline-offset: 2px;
}

.text-element.editing {
  background: white;
  outline: 2px solid #3498db;
  outline-offset: 0;
  cursor: text;
  text-decoration: none;
}

#room-info {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(230, 230, 230, 0.94);
  color: #333;
  padding: 8px 15px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.1);
}

#room-info input {
  background: transparent;
  border: none;
  color: #333;
  font-size: 14px;
  outline: none;
}

#room-name {
  min-width: 40px;
}

#user-name {
  min-width: 40px;
}

.room-info-sep {
  color: rgba(0,0,0,0.3);
}

#room-info input:focus {
  border-bottom: 1px solid #999;
}

#user-count {
  background: rgba(0,0,0,0.1);
  color: rgba(0,0,0,0.45);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
}

#user-count.online {
  background: #3498db;
  color: white;
}

.clear-btn {
  margin-top: auto;
  background: #34495e !important;
  overflow: hidden;
}

.clear-btn:hover {
  background: #4a6278 !important;
}

.clear-btn.holding {
  background: #c0392b !important;
}

.clear-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0%;
  height: 4px;
  background: #e74c3c;
  transition: none;
}

#cursor-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 5;
}

.remote-cursor {
  position: absolute;
  pointer-events: none;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  transition: opacity 1s ease;
}

#local-cursor {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  will-change: transform;
}

.cursor-arrow {
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

.cursor-arrow path {
  fill: var(--color);
}

.cursor-name {
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--color);
  color: white;
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
  line-height: 1.5;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  margin-top: 2px;
}

#eraser-cursor {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  border: 2px solid var(--color, #888);
  border-radius: 3px;
  background: rgba(255,255,255,0.08);
  display: none;
  z-index: 100;
  will-change: transform;
}

#eraser-cursor .cursor-name {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
}

/* Remote eraser cursor */
.remote-cursor-eraser {
  display: block;
  border: 2px solid var(--color);
  border-radius: 3px;
  background: rgba(255,255,255,0.05);
}

.remote-cursor-eraser .cursor-name {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
}

/* Pencil circle cursor (local) */
#pencil-cursor {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  display: none;
  align-items: center;
  gap: 4px;
  z-index: 100;
  will-change: transform;
}

.pencil-dot {
  width: 6px;
  height: 6px;
  border: 2px solid var(--color, #000);
  border-radius: 50%;
  background: transparent;
  flex-shrink: 0;
}

/* Remote pencil circle cursor */
.remote-cursor-pencil {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Text I-beam cursor */
.cursor-text-beam {
  stroke: var(--color);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
  flex-shrink: 0;
}

/* Move crosshair cursor */
.cursor-move-icon {
  fill: var(--color);
  stroke: var(--color);
  stroke-width: 0.5;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
  flex-shrink: 0;
}

/* Generic cursor icon wrapper */
.cursor-icon {
  flex-shrink: 0;
}

/* Solid fill icons for pencil and eraser */
.tool-btn[data-tool="pencil"] svg {
  fill: white;
  stroke: none;
}

.tool-btn[data-tool="eraser"] svg {
  fill: white;
  stroke: none;
}

.tool-btn[data-tool="eraser"] svg .eraser-line {
  fill: none;
  stroke: rgba(0,0,0,0.25);
  stroke-width: 1.5;
}

/* Swatch shortcut numbers */
.color-swatch {
  position: relative;
}

.swatch-shortcut {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 9px;
  color: rgba(255,255,255,0.8);
  font-weight: bold;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0,0,0,0.9);
  line-height: 1;
}

#toolbar:hover .swatch-shortcut {
  opacity: 1;
}

/* ── Undo / redo / save action buttons ─────────────────────────────────────── */
.action-btn {
  background: #3d3d3d !important;
}

.action-btn:hover:not(:disabled) {
  background: #4d4d4d !important;
}

.action-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* ── Presence panel ──────────────────────────────────────────────────────────── */
#presence-panel {
  position: absolute;
  top: 58px;
  right: 10px;
  background: rgba(40, 40, 40, 0.88);
  border-radius: 10px;
  padding: 6px 4px;
  min-width: 150px;
  max-width: 200px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 2px;
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

#presence-panel:empty {
  display: none;
}

.presence-user {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: opacity 0.4s;
}

.presence-me {
  background: rgba(255,255,255,0.06);
}

.presence-idle {
  opacity: 0.38;
}

.presence-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.presence-name {
  flex: 1;
  font-size: 12px;
  color: rgba(255,255,255,0.9);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.presence-tool {
  font-size: 10px;
  color: rgba(255,255,255,0.38);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
