.control-panel {
  width: 320px;
  height: 100vh;
  background: var(--panel-bg);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.panel-toggle {
  display: none;
}

.panel-content {
  padding: 20px;
}

h1 {
  font-size: 24px;
  margin-bottom: 20px;
  color: var(--primary-color);
  font-weight: 600;
}

h2 {
  font-size: 14px;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
  opacity: 0.8;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  margin-bottom: 12px;
}

.section-header:hover {
  opacity: 1;
}

.collapse-btn {
  background: none;
  border: none;
  color: var(--primary-color);
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  padding: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}

.collapse-btn:hover {
  transform: scale(1.2);
}

.section-content {
  max-height: 2000px;
  overflow: hidden;
  transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
  opacity: 1;
}

.control-section.collapsed .section-content {
  max-height: 0;
  opacity: 0;
}

.control-section {
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

.control-section:last-child {
  border-bottom: none;
}

.control-group {
  margin-bottom: 16px;
}

.control-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
}

.radio-group label {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  cursor: pointer;
}

.radio-group input[type="radio"] {
  margin-right: 8px;
}

input[type="range"] {
  width: 100%;
  margin-bottom: 8px;
  height: 6px;
  background: var(--input-bg);
  outline: none;
  border-radius: 3px;
  -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--primary-color);
  cursor: pointer;
  border-radius: 50%;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--primary-color);
  cursor: pointer;
  border-radius: 50%;
  border: none;
}

input[type="number"] {
  width: 80px;
  padding: 6px 8px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  color: var(--panel-text);
  border-radius: 4px;
  font-size: 14px;
}

.control-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  color: var(--panel-text);
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3e%3cpath fill='%23aaa' d='M2 4l4 4 4-4z'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 32px;
}

.control-select:hover {
  border-color: var(--primary-color);
}

.control-select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

input[type="number"]:focus {
  outline: none;
  border-color: var(--primary-color);
}

input[type="color"] {
  width: 100%;
  height: 40px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: var(--input-bg);
}

input[type="checkbox"] {
  margin-right: 8px;
  cursor: pointer;
}

.btn {
  padding: 10px 20px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  color: var(--panel-text);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
  font-weight: 500;
}

.btn:hover {
  background: var(--border-color);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--primary-color);
  color: #000;
  border-color: var(--primary-color);
}

.btn-primary:hover {
  background: #00d4d4;
  border-color: #00d4d4;
}

.btn-block {
  width: 100%;
}

.button-group {
  display: flex;
  gap: 10px;
}

.button-group .btn {
  flex: 1;
}

#speed-value {
  display: inline-block;
  margin-left: 8px;
  font-size: 14px;
  color: var(--primary-color);
  font-weight: 600;
}

/* Custom scrollbar */
.control-panel::-webkit-scrollbar {
  width: 8px;
}

.control-panel::-webkit-scrollbar-track {
  background: var(--panel-bg);
}

.control-panel::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.control-panel::-webkit-scrollbar-thumb:hover {
  background: #444;
}

/* FAB Cluster - Unified Control Stack */
.fab-cluster {
  display: none;
  position: fixed;
  bottom: 40px;
  right: 40px;
  z-index: 1000;
}

@media (min-width: 1024px) {
  .fab-cluster {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
  }
}

/* FAB Sections */
.fab-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
}

.fab-section-shapes {
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 12px;
}

.fab-section-edit {
  padding-top: 0px;
}

/* FAB Base Styles */
.fab {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  flex-shrink: 0;
}

.fab:hover:not(:disabled) {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
  transform: translateY(-2px);
}

.fab:active {
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.fab:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.fab svg {
  width: 24px;
  height: 24px;
}

/* FAB Tooltips - Desktop only */
@media (hover: hover) and (pointer: fine) {
  .fab[data-tooltip] {
    z-index: 1;
  }

  .fab[data-tooltip]:hover {
    z-index: 100;
  }

  .fab[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: -36px;
    left: 50%;
    transform: translateX(-50%);
    background: #1a1a1a;
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    pointer-events: none;
    z-index: 10000;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.15);
  }

  .fab[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
  }

  /* Adjust tooltip position for bottom FABs to show above */
  .fab-section-edit .fab[data-tooltip]::after {
    bottom: auto;
    top: -36px;
  }
}

/* FAB Colors */
.fab-shape-fixed {
  background: #4a90e2;
}

.fab-shape-fixed:hover:not(:disabled) {
  background: #357abd;
}

.fab-shape-rolling {
  background: #e67e22;
}

.fab-shape-rolling:hover:not(:disabled) {
  background: #d35400;
}

.fab-drawing {
  background: #9b59b6;
}

.fab-drawing:hover:not(:disabled) {
  background: #8e44ad;
}

.fab-share {
  background: #27ae60;
}

.fab-share:hover:not(:disabled) {
  background: #229954;
}

/* Layers FAB */
.fab-layers {
  background: #3498db;
}

.fab-layers:hover:not(:disabled) {
  background: #2980b9;
}

/* Undo FAB */
.fab-undo {
  background: #2ecc71;
}

.fab-undo:hover:not(:disabled) {
  background: #27ae60;
}

.fab-undo:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Redo FAB */
.fab-redo {
  background: #2ecc71;
}

.fab-redo:hover:not(:disabled) {
  background: #27ae60;
}

.fab-redo:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Hide UI FAB */
.fab-hide-ui {
  background: #9b59b6;
  font-size: 18px;
}

.fab-hide-ui:hover {
  background: #8e44ad;
}

/* Help FAB (Shortcuts + About combined) */
.fab-help {
  background: #5b7fc7;
}

.fab-help:hover {
  background: #4a6fb5;
}

/* FAB Badge (layer count) */
.fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #e74c3c;
  color: white;
  border-radius: 10px;
  min-width: 20px;
  height: 20px;
  font-size: 11px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* FAB Popups */
.fab-popup {
  display: none;
  position: fixed;
  bottom: 120px;
  right: 40px;
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 10001;
  animation: slideUp 0.2s ease-out;
  max-width: 320px;
}

.fab-popup.active {
  display: block;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.popup-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.popup-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--panel-text);
}

.popup-close {
  background: none;
  border: none;
  color: var(--panel-text);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

.popup-close:hover {
  color: var(--primary-color);
}

.popup-body {
  padding: 16px;
  overflow-y: auto;
  max-height: 60vh;
  flex: 1;
}

/* Shape Selector */
.shape-selector {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.shape-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: var(--input-bg);
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  color: var(--panel-text);
  transition: all 0.2s;
}

.shape-option:hover {
  border-color: var(--primary-color);
  transform: translateY(-2px);
}

.shape-option.active {
  border-color: var(--primary-color);
  background: var(--border-color);
}

.shape-option svg {
  width: 60px;
  height: 60px;
  color: var(--primary-color);
}

.shape-option span {
  font-size: 12px;
  font-weight: 500;
}

/* Shape Properties Panel (collapsible) */
.shape-properties {
  margin-bottom: 16px;
}

.shape-properties-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  color: var(--panel-text);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.shape-properties-header:hover {
  border-color: var(--primary-color);
  background: var(--border-color);
}

.shape-properties-header .chevron {
  transition: transform 0.2s;
  flex-shrink: 0;
}

.shape-properties-header.expanded .chevron {
  transform: rotate(180deg);
}

.shape-properties-content {
  padding: 16px;
  padding-top: 12px;
}

.shape-properties .control-group {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.shape-properties .control-group:last-child {
  margin-bottom: 0;
}

.shape-properties label {
  flex: 0 0 80px;
  font-size: 13px;
  color: var(--panel-text);
}

.shape-properties input[type="range"] {
  flex: 1;
  min-width: 80px;
}

.shape-properties input[type="number"] {
  width: 60px;
  padding: 6px 8px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--panel-text);
  font-size: 13px;
  text-align: center;
}

.shape-properties input[type="number"]:focus {
  outline: none;
  border-color: var(--primary-color);
}

/* Mode Selector */
.mode-selector {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mode-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px;
  background: var(--input-bg);
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  color: var(--panel-text);
  transition: all 0.2s;
}

.mode-option:hover {
  border-color: var(--primary-color);
  transform: translateY(-2px);
}

.mode-option.active {
  border-color: var(--primary-color);
  background: var(--border-color);
}

.mode-option svg {
  width: 80px;
  height: 80px;
  color: var(--primary-color);
}

.mode-option span {
  font-size: 14px;
  font-weight: 500;
}

.mode-option small {
  font-size: 11px;
  color: var(--panel-text-secondary);
  opacity: 0.7;
}

/* Popup Control Groups */
.fab-popup .control-group {
  margin-bottom: 16px;
}

.fab-popup .control-group:last-child {
  margin-bottom: 0;
}

.fab-popup label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 500;
}

.fab-popup input[type="range"] {
  width: 100%;
  margin-bottom: 8px;
}

.fab-popup input[type="number"] {
  width: 100%;
  padding: 8px;
  font-size: 13px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  color: var(--panel-text);
  border-radius: 4px;
}

.fab-popup .popup-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  color: var(--panel-text);
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3e%3cpath fill='%23aaa' d='M2 4l4 4 4-4z'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 32px;
}

.fab-popup .popup-select:hover {
  border-color: var(--primary-color);
}

.fab-popup .popup-select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

.fab-popup input[type="color"] {
  width: 100%;
  height: 40px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

/* Share popup action buttons */
.share-action-btn {
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
}

.share-action-btn:last-child {
  margin-bottom: 0;
}

.share-action-btn svg {
  flex-shrink: 0;
}

/* Share Popup Positioning */
#popupShare {
  bottom: auto;
  top: 200px;
  right: 80px;
  transform-origin: top right;
}

/* Help popup sections */
.help-section {
  margin-bottom: 24px;
}

.help-section:last-child {
  margin-bottom: 0;
}

.help-section h4 {
  margin: 0 0 12px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary-color);
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(0, 255, 255, 0.2);
}

.help-section h5 {
  margin: 16px 0 8px 0;
  font-size: 13px;
  font-weight: 600;
  color: rgba(0, 255, 255, 0.8);
}

.help-section p {
  margin: 8px 0;
  font-size: 13px;
  line-height: 1.6;
}

.help-section ul {
  margin: 8px 0;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.8;
}

.help-section li {
  margin: 4px 0;
}

/* Shortcuts list */
.shortcuts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.shortcut-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.shortcut-item kbd {
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 4px 8px;
  font-family: monospace;
  font-size: 12px;
  font-weight: bold;
  min-width: 32px;
  text-align: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.shortcut-item span {
  flex: 1;
  font-size: 13px;
}