body {
  margin: 0;
  padding: 0;
  font-family: 'Roboto', sans-serif;
  overflow: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
  /* iOS улучшения */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Плавная анимация смены темы холста */
#canvas-container.theme-transition {
  animation: smoothThemeChange 0.5s ease-out;
}

@keyframes smoothThemeChange {
  0% {
    background-image: var(--from-bg-image);
    background-color: var(--from-bg-color);
  }
  100% {
    background-image: var(--to-bg-image);
    background-color: var(--to-bg-color);
  }
}

/* Темная тема */
body.dark-theme {
  background-color: transparent;
  color: #e0e0e0;
}

body.dark-theme #canvas-container {
  background-image: radial-gradient(#1c1c1c 1px, transparent 1px);
  background-color: #000000;
}

body.dark-theme #toolbar {
  background-color:transparent;
  border: 1px solid transparent;
}

body.dark-theme button {
  background-color: transparent;
  color: #404040;
  border: 1px solid transparent;
}

body.dark-theme button:hover {
  background-color: transparent;
  color: #b5b5b5;
  transform: scale(1.6);
}

body.dark-theme button.active {
  background-color: transparent;
  color: #ffffff;
}

body.dark-theme .brush-menu {
  background-color: rgb(0, 0, 0, 0.95);
  border: 1px solid #000000;
  color: #e0e0e0;
}

body.dark-theme .brush-settings-section {
  background: rgb(0, 0, 0, 0.3);
}

body.dark-theme .brush-parameter label {
  color: #595959;
}

body.dark-theme .asset-selector {
  background-color: #000000;
  color: #000000;
  border: 1px solid #000000;
}

body.dark-theme .asset-item {
  border: 1px solid #000000;
  background-color: #000000;
}

body.dark-theme .asset-item:hover {
  background-color: #000000;
}

body.dark-theme .layers-panel {
  background-color: rgb(0, 0, 0, 0.95);
  border: 1px solid #000000;
  color: #000000;
}

body.dark-theme .layers-panel-header {
  border-bottom: 1px solid #000000;
}

body.dark-theme .layers-panel-title {
  color: #e0e0e0;
}

body.dark-theme .layer-item {
  border-color: #000000;
}

body.dark-theme .layer-item:hover {
  background-color: rgb(0, 0, 0, 0.1);
}

body.dark-theme .layer-item.selected {
  background-color: rgb(0, 47, 117, 0.3);
  border-color: #000000;
}

body.dark-theme .layer-name {
  color: #808080;
}

body.dark-theme .layer-name.hidden {
  color: #404040;
}

body.dark-theme .layers-panel-footer {
  border-top: 1px solid #000000;
  color: #999;
}

body.dark-theme #context-menu {
  background-color: rgb(0, 0, 0, 0.95);
  border: 1px solid #000000;
  color: #ffffff;
}

body.dark-theme .animation-controls {
  background: rgb(0, 0, 0, 0.95);
  color: #e0e0e0;
}

body.dark-theme #ios-save-modal > div {
  background-color: #000000;
  color: #e0e0e0;
  border: 1px solid #000000;
}

body.dark-theme .save-format-menu {
  background-color: rgb(0, 0, 0, 0.95);
  border: 1px solid #000000;
  color: #e0e0e0;
}

body.dark-theme .save-format-menu button {
  color: #e0e0e0;
  border-color: #000000;
}

body.dark-theme .save-format-menu button:hover {
  background-color: transparent;
  color: #ffffff;
}



/* Стили для выпадающего меню формата сохранения */
body.dark-theme .format-dropdown {
  background-color: rgb(0, 0, 0, 0.95) !important;
  border: 1px solid #000000 !important;
  color: #e0e0e0 !important;
}

body.dark-theme .format-dropdown button {
  background-color: transparent !important;
  color: #e0e0e0 !important;
  border: none !important;
}

body.dark-theme .format-dropdown button:hover {
  background-color:transparent;
  color: #ffffff !important;
}

#editor {
  width: 100vw;
  height: 100vh;
}

#canvas-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-image: radial-gradient(#d0d0d0 1px, transparent 1px);
  background-size: 20px 20px;
  /* iOS улучшения */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#toolbar {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: auto;
  background-color: transparent;
  border-radius: 10px;
  box-shadow:transparent;
  padding: 10px;
  z-index: 1000;
}

.tool-group {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

button {
  width: 40px;
  height: 40px;
  padding: 8px;
  border: transparent;
  border-radius: 1px;
  background-color:transparent;
  color: #8f8f8f;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  transform: scale(1);
}

button:hover {
  background-color:transparent;
  color: #616161;
  transform: scale(1.6);
}

button.active {
  background-color:transparent;
  color: #000000;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.brush-menu {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0,0,0,0.1);
  padding: 15px;
  margin-top: 10px;
  width: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 1500;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  box-sizing: border-box;
}

.brush-menu > * {
  position: relative;
  width: 100%;
  flex-shrink: 0;
  box-sizing: border-box;
}

.brush-menu > * + * {
  margin-top: 15px;
}

.brush-settings-section {
  padding: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
}

.presets-section {
  display: block;
  padding: 8px 0;
  margin-bottom: 10px;
  position: static;
  width: 100%;
  clear: both;
}

.presets-section h4,
.brush-settings-section h4 {
  margin: 0 0 10px 0;
  font-size: 14px;
  color: #333;
}

.brush-parameter {
  display: block;
  margin-bottom: 8px;
  width: 100%;
  position: static;
  clear: both;
}

.brush-parameter label {
  display: block;
  font-size: 12px;
  margin-bottom: 4px;
  color: #666;
}

.brush-menu input[type="color"],
.brush-menu input[type="range"] {
  width: 100%;
  margin-bottom: 5px;
}

.brush-menu input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: #ddd;
  outline: none;
}

.brush-menu input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #4CAF50;
  cursor: pointer;
}

.brush-menu input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #4CAF50;
  cursor: pointer;
  border: none;
}

/* Brush presets */
.brush-presets {
  display: flex;
  gap: 6px;
  margin-bottom: 15px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 0;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.brush-presets::-webkit-scrollbar {
  display: none;
}

.preset-canvas {
  flex-shrink: 0;
  width: 70px !important;
  height: 70px !important;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  transition: all 0.2s ease;
  margin: 2px;
  /* Улучшаем качество рендеринга на всех устройствах */
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

.preset-canvas:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.preset-canvas:active {
  transform: scale(0.98);
}

.preset-button {
  flex-shrink: 0;
  width: auto !important;
  height: 28px !important;
  padding: 4px 12px !important;
  font-size: 11px !important;
  border-radius: 14px;
  border: 1px solid #ccc;
  background: rgba(255, 255, 255, 0.8);
  color: #333;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  white-space: nowrap;
  min-width: 60px;
}

.preset-button:hover {
  background: rgba(255, 255, 255, 1);
  border-color: #999;
  transform: scale(1.02);
}

.preset-button:active {
  transform: scale(0.98);
}

/* Advanced toggles */
.advanced-toggles {
  display: block;
  margin-bottom: 10px;
  position: static;
  width: 100%;
}

.advanced-toggles > * {
  display: block;
  margin-bottom: 6px;
}

.toggle-section {
  display: flex !important;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #666;
  cursor: pointer;
}

.toggle-section input[type="checkbox"] {
  width: 14px !important;
  height: 14px !important;
  margin: 0 !important;
  cursor: pointer;
}

.toggle-section:hover {
  color: #333;
}

/* Collapsible sections */
.collapsible-section {
  display: block;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
  padding: 8px;
  margin-top: 8px;
  margin-bottom: 8px;
  animation: slideDown 0.2s ease-out;
  width: 100%;
  box-sizing: border-box;
  position: static;
  clear: both;
}

@keyframes slideDown {
  from {
    opacity: 0;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
  }
  to {
    opacity: 1;
    max-height: 200px;
    padding-top: 8px;
    padding-bottom: 8px;
  }
}

.collapsible-section .brush-parameter {
  margin-bottom: 6px;
}

.collapsible-section .brush-parameter:last-child {
  margin-bottom: 0;
}

/* Animation preset buttons */
.preset-button.animation-preset {
  background: rgba(147, 112, 219, 0.2) !important;
  color: #663399 !important;
  border-color: #9370db !important;
}

.preset-button.animation-preset:hover {
  background: rgba(147, 112, 219, 0.3) !important;
  border-color: #8b5cf6 !important;
  color: #4c1d95 !important;
}

/* Dark theme adjustments for new elements */
.dark-theme .preset-canvas {
  background: rgba(0, 0, 0, 0.8);
}

.dark-theme .preset-canvas:hover {
  box-shadow: 0 2px 8px rgba(255,255,255,0.1);
}

.dark-theme .preset-button {
  background: rgba(255, 255, 255, 0.1);
  color: #ccc;
  border-color: #555;
}

.dark-theme .preset-button:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: #777;
  color: #fff;
}

.dark-theme .preset-button.animation-preset {
  background: rgba(147, 112, 219, 0.3) !important;
  color: #c4b5fd !important;
  border-color: #9333ea !important;
}

.dark-theme .preset-button.animation-preset:hover {
  background: rgba(147, 112, 219, 0.5) !important;
  border-color: #a855f7 !important;
  color: #e9d5ff !important;
}

.dark-theme .brush-presets::-webkit-scrollbar {
  display: none;
}

.dark-theme .toggle-section {
  color: #aaa;
}

.dark-theme .toggle-section:hover {
  color: #fff;
}

.dark-theme .collapsible-section {
  background: rgba(255, 255, 255, 0.05);
}

/* Mobile optimizations */
@media (max-width: 768px) {
  .brush-presets {
    gap: 4px;
    margin-bottom: 10px;
  }

  .preset-canvas {
    width: 65px !important;
    height: 65px !important;
    margin: 1px;
    /* Специальные настройки для мобильных */
    image-rendering: auto;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }

  .preset-button {
    height: 26px !important;
    font-size: 10px !important;
    padding: 2px 8px !important;
    min-width: 50px;
    border-radius: 13px;
  }

  .advanced-toggles {
    gap: 4px;
  }

  .toggle-section {
    font-size: 11px;
    gap: 4px;
  }

  .collapsible-section {
    padding: 6px;
  }
}
.brush-menu input[type="range"] {
  -webkit-appearance: none;
  height: 5px;
  border-radius: 5px;
  background: #ddd;
  outline: none;
}

.brush-menu input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #666;
  cursor: pointer;
}

#brush-preview {
    display: block;
    width: 200px;
    height: 80px;
    margin: 0 auto 15px auto;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 5px;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    box-sizing: border-box;
}

/* Стили для контекстного меню */
#context-menu {
  position: absolute;
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0,0,0,0.1);
  padding: 10px;
  z-index: 1000;
  min-width: 180px;
}

/* Стили для меню выбора формата сохранения */
.save-format-menu {
  position: absolute;
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 10px transparent;
  padding: 10px;
  z-index: 1000;
  min-width: 180px;
}

.save-format-menu button {
  width: 100%;
  text-align: left;
  padding: 8px;
  margin-bottom: 5px;
  height: auto;
  min-height: 32px;
  font-size: 12px;
  white-space: nowrap;
}

.save-format-menu button:last-child {
  margin-bottom: 0;
}

/* Базовые стили для выпадающего меню формата */
.format-dropdown {
  position: absolute;
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: transparent;
  box-shadow: transparent;
  padding: 10px;
  z-index: 1000;
  min-width: 120px;
  /* По умолчанию открывается вниз */
  top: 100%;
  margin-top: 5px;
}

.format-dropdown button {
  width: 100%;
  text-align: center;
  padding: 8px;
  margin-bottom: 5px;
  height: auto;
  min-height: 32px;
  font-size: 12px;
  white-space: nowrap;
  background-color: transparent;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

.format-dropdown button:last-child {
  margin-bottom: 0;
}

.format-dropdown button:hover {
  background-color:transparent;
}

#context-menu button {
  width: 100%;
  text-align: left;
  padding: 8px;
  margin-bottom: 5px;
  height: auto;
  min-height: 32px;
  font-size: 12px;
  white-space: nowrap;
}

#context-menu button:last-child {
  margin-bottom: 0;
}

.animation-controls {
  padding: 10px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 5px;
  margin-top: 5px;
}

.animation-controls label {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
}

.animation-controls input[type="range"] {
  width: 100%;
  margin-top: 5px;
}

/* Стили для панели слоев */
.layers-panel {
  position: fixed;
  right: 20px;
  top: 80px;
  width: 280px;
  height: 400px;
  background-color: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  z-index: 1500;
  display: flex;
  flex-direction: column;
  padding: 15px;
}

.layers-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
}

.layers-panel-title {
  margin: 0;
  font-size: 16px;
  color: #333;
}

.layers-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.layer-item {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  height: 40px;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.layer-item:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

.layer-item.selected {
  background-color: #f0f8ff;
  border-color: #4a90e2;
}

.layer-type-icon {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  margin-right: 8px;
}

.layer-type-group {
  background-color: #ff9800;
}

.layer-type-default {
  background-color: #4caf50;
}

.layer-name {
  flex: 1;
  font-size: 12px;
  color: #2c3e50;
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-item.selected .layer-name {
  font-weight: 500;
}

.layer-name.hidden {
  color: #95a5a6;
  text-decoration: line-through;
}

.layer-controls {
  display: flex;
  gap: 2px;
  opacity: 0.6;
  transition: opacity 0.15s ease;
}

.layer-item.selected .layer-controls {
  opacity: 1;
}

.layer-control-btn {
  padding: 2px 4px;
  font-size: 10px;
  border: none;
  background: none;
  cursor: pointer;
  min-width: auto;
  width: auto;
  height: auto;
}

.layer-control-btn:hover {
  background-color: rgba(0, 0, 0, 0.1);
}

.layer-control-btn.delete {
  color: #f44336;
}

.layers-panel-footer {
  font-size: 11px;
  color: #666;
  margin-top: 10px;
  text-align: center;
  border-top: 1px solid #eee;
  padding-top: 8px;
}



/* Стилизация скроллбара */
.asset-list::-webkit-scrollbar,
.layers-list::-webkit-scrollbar {
  width: 8px;
}

.asset-list::-webkit-scrollbar-track,
.layers-list::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.asset-list::-webkit-scrollbar-thumb,
.layers-list::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

.asset-list::-webkit-scrollbar-thumb:hover,
.layers-list::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Стили для мобильных устройств */
@media (max-width: 768px) {
  /* Меню формата сохранения открывается вверх на мобильных */
  .format-dropdown {
    top: auto !important;
    bottom: 100% !important;
    margin-top: 0 !important;
    margin-bottom: 5px !important;
  }

  /* Перемещаем индикатор зума вверх влево на мобильных */
  .zoom-indicator {
    top: max(20px, env(safe-area-inset-top)) !important;
    bottom: auto !important;
    left: max(20px, env(safe-area-inset-left)) !important;
  }

  /* Адаптация селектора области рендера для мобилки */
  .render-area-selector-mobile {
    padding: 4px 8px !important;
    border-radius: 12px !important;
    max-width: 98vw !important;
  }

  /* Маркеры ресайза больше для touch */
  .resize-handle-mobile {
    width: 20px !important;
    height: 20px !important;
    border: 3px solid rgba(255, 255, 255, 0.9) !important;
    border-radius: 6px !important;
  }

  /* Увеличиваем боковые маркеры для мобилки */
  .resize-side-handle-mobile {
    width: 30px !important;
    height: 15px !important;
  }

  /* Панель с информацией выше области на мобилке */
  .area-info-panel-mobile {
    top: -60px !important;
    font-size: 14px !important;
    padding: 6px 12px !important;
    border-radius: 8px !important;
  }

  #toolbar {
    top: auto;
    bottom: 20px;
    left: 20px;
    right: 20px;
    transform: none;
    width: auto;
    max-width: none;
    padding: 5px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    position: fixed;
    /* iOS-специфичные стили */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    touch-action: manipulation;
  }

  #toolbar::-webkit-scrollbar {
    display: none;
  }

  .tool-group {
    flex-wrap: nowrap;
    gap: 2px;
    min-width: max-content;
  }

  button {
    width: 35px;
    height: 35px;
    padding: 6px;
    font-size: 12px;
    /* iOS touch улучшения */
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    touch-action: manipulation;
  }

  .brush-menu {
    position: fixed !important;
    left: max(10px, env(safe-area-inset-left)) !important;
    right: max(10px, env(safe-area-inset-right)) !important;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
    top: auto !important;
    transform: translate3d(0, 0, 0) !important;
    z-index: 2000 !important;
    max-height: calc(100vh - 120px - env(safe-area-inset-bottom, 0px)) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    margin: 0 !important;
    width: auto !important;
    max-width: none !important;
    /* iOS-специфичные улучшения */
    -webkit-touch-callout: none;
    box-sizing: border-box;
    /* Изоляция позиционирования от родительского контейнера */
    contain: layout;
    /* Убираем grid для мобилки тоже */
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
  }



  /* Панель слоев на мобиле */
  .layers-panel {
    right: 10px;
    top: max(60px, env(safe-area-inset-top));
    width: 250px;
    height: 350px;
    padding: 10px;
  }
}

/* Дополнительные стили для iPhone с notch */
@media (max-width: 768px) and (orientation: portrait) {
  #toolbar {
    bottom: max(20px, env(safe-area-inset-bottom));
    left: max(20px, env(safe-area-inset-left));
    right: max(20px, env(safe-area-inset-right));
  }

  .brush-menu {
    bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    left: max(10px, env(safe-area-inset-left)) !important;
    right: max(10px, env(safe-area-inset-right)) !important;
  }
}

/* Стили для устройств с маленькой высотой экрана */
@media (max-height: 600px) {
  #brush-preview {
    height: 60px !important;
    margin-bottom: 10px !important;
  }
  
  .brush-menu {
    gap: 10px !important;
  }
  
  .brush-parameter {
    margin-bottom: 6px !important;
  }
  
  .presets-section {
    padding: 6px 0 !important;
  }
  
  .presets-section h4,
  .brush-settings-section h4 {
    margin: 0 0 6px 0 !important;
    font-size: 12px !important;
  }
}

/* Дополнительно для очень маленьких экранов по высоте */
@media (max-height: 500px) {
  #brush-preview {
    height: 40px !important;
    margin-bottom: 8px !important;
  }
  
  .brush-menu {
    gap: 8px !important;
    padding: 10px !important;
  }
  
  .brush-parameter {
    margin-bottom: 4px !important;
  }
  
  .brush-parameter label {
    font-size: 11px !important;
    margin-bottom: 2px !important;
  }
  
  .presets-section {
    padding: 4px 0 !important;
  }
  
  .brush-presets {
    gap: 2px !important;
    margin-bottom: 8px !important;
  }
  
  .preset-button {
    height: 24px !important;
    font-size: 10px !important;
    padding: 2px 6px !important;
  }
}

/* Специальные стили для iPhone Safari */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 768px) {
    .brush-menu {
      position: fixed !important;
      left: 10px !important;
      right: 10px !important;
      bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
      transform: none !important;
      width: auto !important;
      max-width: none !important;
      margin: 0 !important;
      box-sizing: border-box !important;
    }
  }
}

/* Landscape iPhone стили */
@media (max-width: 768px) and (orientation: landscape) {
  #toolbar {
    bottom: max(10px, env(safe-area-inset-bottom));
    left: max(60px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
  }

  .brush-menu {
    bottom: calc(60px + env(safe-area-inset-bottom));
    left: max(60px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    max-height: calc(100vh - 80px - env(safe-area-inset-bottom));
  }

  .layers-panel h3 {
    font-size: 14px;
  }

  .layer-item {
    padding: 6px;
    min-height: 32px;
  }

  .layer-name {
    font-size: 12px;
  }

  .layer-control-btn {
    font-size: 9px;
  }
}

/* Стили для круглого color picker */
input[type="color"] {
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 50%;
  overflow: hidden;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  display: block;
  margin: auto;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
  border: none;
  border-radius: 50%;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}

input[type="color"]::-moz-color-swatch {
  border: none;
  border-radius: 50%;
}

body.dark-theme input[type="color"] {
  border: 0px solid #404040;
}

body.dark-theme input[type="color"]::-webkit-color-swatch-wrapper {
  border-radius: 50%;
}

body.dark-theme input[type="color"]::-webkit-color-swatch {
  border-radius: 50%;
}

body.dark-theme input[type="color"]::-moz-color-swatch {
  border-radius: 50%;
}

/* Запрет выделения текста во время перетаскивания */
.no-select {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

*:not(input):not(textarea) {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
/* Homepage / remix stage v1 */
body:has(.home-stage) { overflow-y: auto; overflow-x: hidden; background: #050508; color: #fff; user-select: auto; }
.home-stage { min-height: 100vh; padding: 56px clamp(18px, 4vw, 72px); box-sizing: border-box; background: radial-gradient(circle at 20% 10%, rgba(123,101,193,.32), transparent 32%), radial-gradient(circle at 85% 15%, rgba(143,255,239,.16), transparent 28%), #050508; font-family: monospace; }
.home-hero { max-width: 920px; margin: 0 auto 54px; text-align: center; }
.home-kicker { color: #8fffef; letter-spacing: .18em; text-transform: uppercase; font-size: 12px; margin-bottom: 18px; opacity: .86; }
.home-hero h1 { margin: 0; font-size: clamp(44px, 8vw, 108px); line-height: .92; letter-spacing: -0.07em; }
.home-hero p { max-width: 620px; margin: 22px auto 0; color: rgba(255,255,255,.68); font-size: clamp(15px, 2vw, 19px); line-height: 1.5; }
.home-actions { display:flex; gap:12px; justify-content:center; flex-wrap:wrap; margin-top: 30px; }
.home-btn { display:inline-flex; align-items:center; justify-content:center; min-width: 150px; padding: 13px 18px; border-radius:999px; color:#fff; text-decoration:none; background: rgba(255,255,255,.08); border:1px solid rgba(255,255,255,.16); backdrop-filter: blur(10px); }
.home-btn.primary { color:#050508; background:#8fffef; border-color:#8fffef; font-weight: 800; }
.starter-grid-wrap { max-width: 1180px; margin: 0 auto; }
.section-head { display:flex; justify-content:space-between; gap:16px; align-items:end; margin-bottom: 16px; }
.section-head h2 { margin:0; font-size:22px; letter-spacing:-.03em; }
.section-head span { color:rgba(255,255,255,.5); font-size:12px; }
.starter-grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.starter-card { position:relative; overflow:hidden; border-radius: 24px; min-height: 270px; background: linear-gradient(150deg, rgba(255,255,255,.08), rgba(255,255,255,.025)); border:1px solid rgba(255,255,255,.12); box-shadow: 0 16px 48px rgba(0,0,0,.22); }
.starter-preview { position:relative; height: 156px; background: radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--accent) 28%, transparent), transparent 54%); }
.starter-preview .orb { position:absolute; border-radius:50%; border:1px solid color-mix(in srgb, var(--accent) 70%, white); background: color-mix(in srgb, var(--accent) 34%, transparent); filter: blur(.2px); opacity:.72; }
.starter-preview .a { width: 96px; height:96px; left:18%; top:24%; animation: homeFloat 5s ease-in-out infinite; }
.starter-preview .b { width: 52px; height:52px; right:18%; top:18%; animation: homeFloat 6s ease-in-out infinite reverse; }
.starter-preview .c { width: 128px; height:128px; right:25%; bottom:-26%; opacity:.28; }
.starter-preview .gridline { position:absolute; inset:0; background-image: linear-gradient(color-mix(in srgb, var(--accent) 26%, transparent) 1px, transparent 1px), linear-gradient(90deg, color-mix(in srgb, var(--accent) 20%, transparent) 1px, transparent 1px); background-size: 28px 28px; mask-image: radial-gradient(circle at 50% 50%, black, transparent 72%); }
.starter-meta { padding: 16px; }
.starter-meta h3 { margin: 0 0 6px; font-size: 18px; }
.starter-meta p { margin:0 0 15px; color:rgba(255,255,255,.48); font-size:12px; }
.starter-actions { display:flex; gap:8px; }
.starter-actions a { flex:1; text-align:center; padding:9px 10px; border-radius:999px; color:#fff; text-decoration:none; background:rgba(255,255,255,.075); border:1px solid rgba(255,255,255,.12); }
.starter-actions a.remix { color:#050508; background:var(--accent); border-color:var(--accent); font-weight:800; }
.featured-placeholder { max-width:1180px; margin: 18px auto 0; padding: 20px; border-radius:24px; border:1px dashed rgba(255,255,255,.16); color:rgba(255,255,255,.55); }
.featured-placeholder span { color:#fff; font-weight:800; }
.featured-placeholder p { margin:.4em 0 0; }
@keyframes homeFloat { 0%,100%{ transform: translateY(0) scale(1); } 50%{ transform: translateY(-10px) scale(1.06); } }
@media (max-width: 680px) { .home-stage { padding-top: 34px; } .section-head { align-items:start; flex-direction:column; } .home-hero { text-align:left; } .home-actions { justify-content:flex-start; } }
.featured-real-preview { display:flex; align-items:center; justify-content:center; background:#050508; }
.featured-real-preview img { width:100%; height:100%; object-fit:cover; display:block; }
