body {
  background: #f0f2f5;
  display: flex;
  justify-content: center;
  padding: 0;
  margin: 0;
  font-family: 'Inter', sans-serif;
  height: 100vh;
  overflow: hidden;
}

#toolbar {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 8px 16px;
  display: flex;
  gap: 16px;
  align-items: center;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(5px);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 16px;
  border-right: 1px solid #eee;
}

.toolbar-group:last-child {
  border-right: none;
  padding-right: 0;
}

.brand {
  font-family: 'Orbitron', sans-serif;
  font-weight: 500;
  color: #2d3748;
  font-size: 1.1rem;
}

.tool-btn {
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  color: #4a5568;
  transition: all 0.2s;
}

.tool-btn:hover {
  background: #f7fafc;
  border-color: #a0aec0;
  color: #2d3748;
}

.tool-btn:active {
  transform: translateY(1px);
}

/* Dropdown Menu */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 120px;
  z-index: 101;
  margin-top: 4px;
  overflow: hidden;
}

.dropdown.open .dropdown-menu {
  display: block;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 16px;
  background: #fff;
  border: none;
  text-align: left;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  color: #4a5568;
  cursor: pointer;
  transition: background 0.2s;
}

.dropdown-item:hover {
  background: #f7fafc;
  color: #2d3748;
}

#modeSelect {
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid #ccc;
  font-family: 'Inter', sans-serif;
}

#workspace {
  width: 100%;
  height: 100%;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding-top: 80px; /* Space for toolbar */
  padding-bottom: 50px;
}

#infinite-doc {
  background: #fff;
  width: 816px; /* Standard Letter width approx */
  min-height: 1056px; /* Standard Letter height approx */
  position: relative;
  padding: 40px; /* Match JS PAGE_MARGIN (40px) */
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  margin-bottom: 50px;
  box-sizing: border-box;
}

/* Grid overlay background */
#infinite-doc::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    linear-gradient(rgba(160, 174, 192, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(160, 174, 192, 0.1) 1px, transparent 1px);
  background-size: 20px 20px; /* Match GRID_SIZE */
  pointer-events: none;
  z-index: 1;
}

/* Margin guides */
#infinite-doc::after {
  content: '';
  position: absolute;
  top: 40px; /* Match PAGE_MARGIN */
  left: 40px; /* Match PAGE_MARGIN */
  right: 40px; /* Match PAGE_MARGIN */
  bottom: 40px; /* Match PAGE_MARGIN */
  border: 1px dashed rgba(74, 144, 226, 0.3);
  pointer-events: none;
  z-index: 1;
}

/* Margin labels */
#infinite-doc::before {
  content: '0.5" margin';
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 10px;
  color: rgba(74, 144, 226, 0.6);
  font-family: 'Inter', sans-serif;
  pointer-events: none;
  z-index: 2;
}

.question-box {
  position: absolute;
  background: #fff;
  border: 1px dashed #a0aec0;
  padding: 10px;
  cursor: move;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

/* Prevent text selection during resize/move */
.question-box.resizing, .question-box.dragging {
  user-select: none;
}

.question-box:hover {
  border-color: #4a5568;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.question-box.readonly {
  border: 1px solid transparent;
  cursor: default;
  box-shadow: none;
}

.question-box.readonly:hover {
  border-color: transparent;
}

.question-part, .answer-part {
  width: 100%;
  border: 1px solid transparent;
  resize: none;
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: #2d3748;
  background: transparent;
  outline: none;
  overflow: hidden;
  box-sizing: border-box;
  display: block;
}

.question-part {
  font-weight: 500;
  background-color: rgba(247, 250, 252, 0.5);
  min-height: 40px;
}

.answer-part {
  min-height: 60px;
}

.question-handle {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 16px;
  height: 16px;
  background: #4a5568;
  border-radius: 50%;
  cursor: pointer;
  display: none;
}

.question-box:hover .question-handle {
  display: block;
}

.question-box.readonly .question-handle {
  display: none !important;
}


.resize-handle {
  position: absolute;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.2s;
}

.question-box:hover .resize-handle {
  opacity: 1;
}

.resize-handle.e {
  right: -4px; top: 0; bottom: 10px; width: 10px; cursor: e-resize;
}
.resize-handle.s {
  left: 0; right: 10px; bottom: -4px; height: 10px; cursor: s-resize;
}
.resize-handle.se {
  right: -4px; bottom: -4px; width: 14px; height: 14px; cursor: se-resize;
  background: linear-gradient(135deg, transparent 50%, #718096 50%);
}
