:root {
  --bg-color: #f4f3ef;
  --text-color: #1a1a1a;
  --accent-color: #333;
  --selection-color: #2563eb;
  --item-bg: #ffffff;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.12);
  --font-ui: 'Inter', sans-serif;
  --font-body: 'Inter', sans-serif;
  --transition-smooth: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* {
  box-sizing: border-box;
}

body,
html {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  /* Prevent scrolling of the viewport itself */
  font-family: var(--font-ui);
  background-color: var(--bg-color);
  color: var(--text-color);
  /* Subtle grain texture overlay could be added here */
}

/* The Board Area - Infinite feel explicitly handled via absolute positioning */
#board {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  /* Dot grid pattern for guidance */
  background-image: radial-gradient(#d1d1d1 1px, transparent 1px);
  background-size: 24px 24px;
  touch-action: none;
  /* Important for custom drag handling */
}

/* Floating Tools - Minimalist strip */
/* Floating Tools - Minimalist strip */
#toolbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  padding: 12px 20px;
  background: #ffffff;
  /* Fallback */
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  z-index: 1000;
  transition: opacity 0.3s ease, transform 0.3s var(--transition-smooth);
  align-items: center;
}

#toolbar {
  bottom: 24px;
}

#format-toolbar {
  position: absolute;
  /* Top/Left will be set by JS */
  padding: 8px 12px;
  gap: 8px;
  background: #ffffff;
  /* Fallback */
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  z-index: 2000;
  /* Higher than board items */
  display: flex;
  align-items: center;
  transition: opacity 0.2s;
  pointer-events: auto;
}

#format-toolbar.hidden {
  opacity: 0;
  pointer-events: none;
  display: none;
  /* Actually hide it to prevent blocking clicks */
}

#toolbar button,
#toolbar label,
#format-toolbar button {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 10px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
  transition: all 0.2s ease;
}

#toolbar button:hover,
#toolbar label:hover,
#format-toolbar button:hover {
  background: rgba(0, 0, 0, 0.05);
  transform: translateY(-2px);
}

#toolbar button.active {
  background: #000;
  color: #fff;
}

#toolbar button svg,
#toolbar label svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* Form Inputs styling */
#format-toolbar input[type="color"] {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  padding: 0;
  background: none;
  cursor: pointer;
}

.format-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.v-divider {
  width: 1px;
  height: 24px;
  background: rgba(0, 0, 0, 0.1);
  margin: 0 4px;
}

.swatch-label {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.swatch-label:hover {
  transform: scale(1.1);
}

.swatch-label input[type="color"] {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.swatch-icon {
  width: 24px;
  height: 24px;
}

.swatch-btn-none {
  background: none;
  border: none;
  padding: 0;
  width: 24px;
  height: 24px;
  cursor: pointer;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.swatch-btn-none:hover {
  background: rgba(0, 0, 0, 0.05);
  color: #f44336;
}

.swatch-btn-none.active {
  background: rgba(244, 67, 54, 0.1);
  color: #f44336;
}

#format-toolbar select {
  border: 1px solid #ddd;
  background: transparent;
  border-radius: 4px;
  padding: 4px 8px;
  font-family: inherit;
  font-size: 0.9rem;
}

#format-toolbar input[type="number"] {
  border: 1px solid #ddd;
  background: transparent;
  border-radius: 4px;
  padding: 4px;
  width: 50px;
  text-align: center;
}

#format-toolbar button.active {
  background: var(--selection-color);
  color: #fff;
}


/* Board Items */
.board-item {
  position: absolute;
  transform-origin: center center;
  cursor: grab;
  user-select: none;
  /* Prevent text selection while dragging */
  transition: box-shadow 0.2s ease;
  /* Remove other transitions to prevent jitter during drag */
  will-change: transform, width, height;
}

.board-item.is-dragging {
  cursor: grabbing;
  z-index: 9999 !important;
  /* Always on top when dragging */
  box-shadow: var(--shadow-lg);
}

.board-item.is-selected {
  outline: 2px solid var(--selection-color);
  z-index: 999 !important;
}

/* Specific Content Types */
.item-content {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.item-image {
  pointer-events: none;
  /* Let drag pass through */
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.item-text {
  padding: 16px;
  background: transparent;
  width: 100%;
  height: 100%;
  min-height: 50px;
  font-size: 20px;
  /* Default */
  line-height: 1.5;
  cursor: inherit;
  outline: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  pointer-events: none;
  /* Pass clicks to parent wrapper */
}

/* Rule removed: .board-item.is-selected .item-text */

.item-text[contenteditable="true"] {
  cursor: text;
  pointer-events: auto;
  /* Enable interaction only when editing */
  user-select: text;
  background: rgba(255, 255, 255, 0.5);
  /* Visual feedback for edit mode */
  box-shadow: inset 0 0 0 1px var(--selection-color);
}

/* Controls for resizing/rotating (only visible when selected) */
.controls {
  position: absolute;
  top: -10px;
  left: -10px;
  right: -10px;
  bottom: -10px;
  border: 1px solid var(--selection-color);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  display: none;
  /* Hidden by default */
}

.board-item.is-selected .controls {
  opacity: 1;
  display: block;
}

/* Resize Handles */
.resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid var(--selection-color);
  border-radius: 50%;
  pointer-events: auto;
  z-index: 10;
}

.rh-nw {
  top: -6px;
  left: -6px;
  cursor: nwse-resize;
}

.rh-ne {
  top: -6px;
  right: -6px;
  cursor: nesw-resize;
}

.rh-sw {
  bottom: -6px;
  left: -6px;
  cursor: nesw-resize;
}

.rh-se {
  bottom: -6px;
  right: -6px;
  cursor: nwse-resize;
}

/* Rotate Handle */
.rotate-handle {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 24px;
  background: #fff;
  border: 2px solid var(--selection-color);
  border-radius: 50%;
  cursor: grab;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rotate-handle svg {
  width: 14px;
  height: 14px;
  stroke: var(--selection-color);
}

/* User/Board status indicator */
#board-meta {
  position: fixed;
  top: 24px;
  left: 32px;
  opacity: 0.5;
  transition: opacity 0.2s;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 100;
}

#board-meta:hover {
  opacity: 1;
}

/* Hidden file input */
#file-input {
  display: none;
}

/* Sync Status */
#sync-status {
  position: fixed;
  top: 24px;
  right: 32px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0.6;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #ccc;
  border-radius: 50%;
}

.status-dot.saved {
  background: #10b981;
}

.status-dot.saving {
  background: #f59e0b;
}

.status-dot.error {
  background: #ef4444;
}


/* Mobile/Tablet Tweak */
@media (max-width: 768px) {
  #toolbar {
    bottom: 16px;
    padding: 8px 16px;
  }
}