@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg-main: #0a0a0c;
  --bg-panel: rgba(22, 22, 26, 0.8);
  --bg-card: #1c1c21;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --border: rgba(255, 255, 255, 0.1);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --glass: blur(12px);
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-image: radial-gradient(circle at 50% 50%, #1a1a2e 0%, #0a0a0c 100%);
}

/* Update Container for Flex Column */
.container {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header Styles */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  height: 60px;
  flex-shrink: 0;
  backdrop-filter: blur(10px);
}

.header-left h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

/* Canvas Overlay Actions */
.canvas-actions-overlay {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  gap: 8px;
  z-index: 10;
}

.icon-action-btn {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

.icon-action-btn:hover {
  background-color: var(--bg-panel);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.icon-action-btn:active {
  transform: translateY(0);
}

#undoBtn {
  background-image: url("/assets/undo.svg");
}

#redoBtn {
  background-image: url("/assets/redo.svg");
}

/* Sidebar Settings Styles */
.setting-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.sub-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.size-controls-group {
  display: flex;
  gap: 8px;
}

.size-controls-group select {
  flex: 1;
  width: 100%;
}

.custom-size-inputs.inline {
  display: flex;
  gap: 4px;
}

.custom-size-inputs.inline input {
  width: 50px;
  padding: 4px;
  text-align: center;
}

/* Main Layout Area below header */
.main-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 280px;
  grid-template-rows: 1fr;
  width: 100%;
  height: 100%;
  overflow: hidden;
  gap: 16px;
  padding: 16px;
  padding-top: 0;
}

/* Adjust timeline area removal */
.timeline {
  display: none;
}

/* Right Sidebar Styles */
/* Header Inputs */
.app-header select,
.app-header input[type="number"] {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 4px;
}

.app-header select:focus,
.app-header input:focus {
  outline: none;
  color: var(--accent);
}

.app-header input[type="number"] {
  width: 50px;
  text-align: center;
  border-bottom: 1px solid transparent;
}

.app-header input[type="number"]:focus {
  border-bottom-color: var(--accent);
}

.app-header button {
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.app-header button:hover {
  background: var(--bg-card);
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

/* Grid Opacity Slider */
#gridOpacitySlider {
  width: 100px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  appearance: none;
}

#gridOpacitySlider::-webkit-slider-thumb {
  appearance: none;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s;
}

#gridOpacitySlider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Grid Layout Areas need adjustments */
/* Grid Layout Areas - Explicit assignments using shorthand */
.panel.sidebar {
  grid-column: 1 / 2;
  grid-row: 1 / 2;
  border-right: 1px solid var(--border);
  background: var(--bg-panel);
  min-width: 0;
}

main {
  grid-column: 2 / 3;
  grid-row: 1;
  /* Canvas Area */
  flex: 1;
  display: flex;
  flex-direction: column;
  /* Changed for Timeline Layout */
  /* justify-content: center; */
  /* Remove center alignment for column */
  /* align-items: center; */
  background-color: #2c2c2c;
  /* Darker background for contrast */
  overflow: auto;
  /* Allow scrolling if zoomed in */
  position: relative;
}

.canvas-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.zoom-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-main);
  padding: 8px;
  border-radius: 8px;
  color: white;
  margin-top: 5px;
  width: 100%;
}

.zoom-controls .action-btn {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

#zoomLevelDisplay {
  min-width: 40px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--accent);
}

.zoom-controls span {
  min-width: 50px;
  text-align: center;
  font-family: monospace;
}

.canvas-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
  background: white;
  transition: transform 0.05s linear;
  transform-origin: center center;
}

#dotCanvas {
  position: relative;
  z-index: 1;
  background-color: #ffffff !important;
  image-rendering: pixelated;
  cursor: crosshair;
  display: block;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

#gridCanvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 2;
  background-color: transparent !important;
  image-rendering: pixelated;
}

#selectionCanvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 3;
}

.panel.right-sidebar {
  grid-column: 3 / 4;
  grid-row: 1 / 2;
  border-left: 1px solid var(--border);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  min-width: 0;
}

/* Remove duplicate right-sidebar rule */
.right-sidebar {
  display: none;
}

/* Safely hide if duplicate exists, though we target .panel.right-sidebar above */

.full-width {
  width: 100%;
}

.import-controls {
  display: flex;
  gap: 8px;
}

.action-btn.icon-btn {
  width: 100%;
  justify-content: center;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  color: var(--text-muted);
}

.action-btn.icon-btn:hover {
  background: var(--border);
  color: var(--text-main);
  border-style: solid;
}

/* Frame List Styles */

main {
  /* ... */
  flex-direction: column;
  justify-content: flex-start;
  /* Expand from top */
}

.canvas-container {
  flex: 1;
  /* Take all available space above timeline */
  width: 100%;
  display: flex;
  /* Recentering canvas */
  justify-content: center;
  align-items: center;
  overflow: hidden;
  /* Prevent canvas from pushing layout */
}

/* Timeline Panel (Floating Dock Style - Absolute Centered) */
.frames-timeline-panel {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 60px);
  /* Constrain within sidebars better */
  max-width: 1200px;
  /* Prevent excessive width on large screens */
  height: 140px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  padding: 8px 16px;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  z-index: 100;
  /* Ensure on top */
}

.frames-section.horizontal {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 8px;
  padding: 0;
}

.frames-section.horizontal .frame-header {
  margin-bottom: 4px;
}

.frame-list.horizontal {
  display: flex;
  flex-direction: row;
  /* Horizontal list */
  gap: 8px;
  overflow-x: auto;
  /* Horizontal scroll */
  overflow-y: hidden;
  height: 100%;
  padding-bottom: 4px;
  /* Scrollbar space */
  align-items: center;
  /* Hide Scrollbar but keep functionality */
  scrollbar-width: none;
  /* Firefox */
  -ms-overflow-style: none;
  /* IE/Edge */
}

.frame-list.horizontal .frame-item {
  height: 100%;
  aspect-ratio: 1;
  /* Square thumbnails */
  flex-shrink: 0;
  /* Don't shrink */
  min-width: 80px;
}

/* Frame List Styles */
.frame-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.frame-actions-mini {
  display: flex;
  gap: 4px;
}

.frame-actions-mini button {
  padding: 4px 8px;
  font-size: 1rem;
  line-height: 1;
}

/* Scrollbar specifically for timeline */
.frame-list.horizontal::-webkit-scrollbar {
  display: none;
}


.export-controls.vertical {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.export-controls.vertical button {
  width: 100%;
}

.primary {
  background: var(--accent);
  color: white;
  border: none;
}

.primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.5);
}

/* Mobile Responsive Update */
@media (max-width: 1024px) {
  .main-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    gap: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
  }

  .panel.sidebar,
  .panel.right-sidebar,
  main {
    grid-column: auto !important;
    width: 100%;
    height: auto;
    overflow: visible;
  }
}

h1 {
  grid-area: header;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  background: linear-gradient(to right, #6366f1, #a855f7);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.panel {
  background: var(--bg-panel);
  backdrop-filter: var(--glass);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: var(--shadow-lg);
}

.sidebar {
  grid-area: sidebar;
  overflow-y: auto;
  /* Hide scrollbar but keep functionality */
  -ms-overflow-style: none;
  /* IE and Edge */
  scrollbar-width: none;
  /* Firefox */
}

.sidebar::-webkit-scrollbar {
  display: none;
  /* Chrome, Safari and Opera */
}

/* Canvas cursors styling consolidated below */
canvas.pen-cursor {
  cursor: crosshair;
}

canvas.eraser-cursor {
  cursor: cell;
}

canvas.eyedropper-cursor {
  cursor: copy;
}

.timeline {
  grid-area: timeline;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
}

.color-preview-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: #000;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

button {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 0.875rem;
}

button:hover:not(:disabled) {
  background: var(--border);
  transform: translateY(-1px);
}

button.active {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

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

/* Tool Sections */
.tool-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Compact Tool Row (Threaded Layout) */
.tool-row.threaded-layout {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
}

/* Icon Buttons */
.tool-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background-color: var(--bg-main);
  background-size: 24px 24px;
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tool-btn.active {
  background-color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

/* Icons */
#penTool {
  background-image: url("assets/pen.svg");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 24px;
}

#eraserTool {
  background-image: url("assets/eraser.svg");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 24px;
}

#eyedropperTool {
  background-image: url("assets/eyedropper.svg");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 24px;
}

/* Inline Thickness Options */
.thickness-options.inline {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.thickness-options.import-controls input[type="file"] {
  display: none;
}

/* Selection Tool Styles */
.btn-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.action-btn.small {
  padding: 4px 8px;
  font-size: 0.8rem;
  min-width: auto;
}

.tool-btn.active {
  background-color: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Selection Box Overlay */
.selection-overlay {
  pointer-events: none;
  border: 1px dashed white;
  background-color: rgba(255, 255, 255, 0.2);
  position: absolute;
}

.thickness-options.inline input[type="radio"] {
  display: none;
}

.thickness-options.inline .size-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: var(--bg-main);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.thickness-options.inline input[type="radio"]:checked+.size-label {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Standalone Color Dot */
.color-preview-dot.standalone {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: #000;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  margin-left: 8px;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

/* Color Selection */
.color-selection {
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.color-mode-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.2);
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Recent Colors */
.recent-colors {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.recent-colors-grid {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  /* Allow wrapping if needed, but try to keep it compact */
  justify-content: flex-end;
  max-width: 200px;
  /* Limit width to force wrap if too many */
}

.recent-color {
  width: 20px;
  /* Slightly smaller to fit more */
  height: 20px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: transform 0.2s;
}

.recent-color:hover {
  transform: scale(1.1);
}

/* Clipboard History */
.clipboard-section {
  flex: 1;
  /* Take up remaining space */
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.clipboard-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 5px;
}

.clipboard-item {
  border: 2px solid var(--border);
  border-radius: 8px;
  background-color: #333;
  background-image:
    linear-gradient(45deg, #444 25%, transparent 25%, transparent 75%, #444 75%, #444 100%),
    linear-gradient(45deg, #444 25%, transparent 25%, transparent 75%, #444 75%, #444 100%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
  cursor: pointer;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.clipboard-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

.clipboard-item canvas,
.clipboard-item img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
  image-rendering: pixelated;
  /* Maintain transparency if using transparent BG, but usually BG is black/white */
}

.empty-message {
  text-align: center;
  color: #666;
  font-size: 0.8rem;
  margin-top: 20px;
}

/* Scrollbar for sidebar lists */
.frame-list::-webkit-scrollbar,
.clipboard-list::-webkit-scrollbar {
  width: 6px;
}

.frame-list::-webkit-scrollbar-thumb,
.clipboard-list::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 3px;
}

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

.palette-color {
  aspect-ratio: 1;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
}

.palette-color.active {
  border-color: #fff;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--bg-card);
  transition: .4s;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-muted);
  transition: .4s;
  border-radius: 50%;
}

input:checked+.slider {
  background-color: var(--accent);
}

input:checked+.slider:before {
  transform: translateX(16px);
  background-color: #fff;
}

.color-picker-container {
  display: none;
  flex-direction: column;
  gap: 8px;
}

.color-selection[data-mode="custom"] .color-picker-container {
  display: flex;
}

.color-selection[data-mode="custom"] .color-palette {
  display: none;
}

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  width: 100%;
  height: 40px;
  border-radius: 8px;
  background: none;
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: 2px solid var(--border);
  border-radius: 8px;
}

/* Canvas Size */
.canvas-size-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.canvas-size-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.canvas-size-header select {
  flex: 1;
  max-width: none;
  padding: 8px 12px;
  font-size: 0.875rem;
}

.custom-size-inputs {
  display: flex;
  gap: 8px;
}

.custom-size-inputs input {
  flex: 1;
}

select,
input[type="number"] {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.875rem;
  outline: none;
}

/* Sidebar Footer */
/* Sidebar Footer */
.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

/* Appended Frame Item Styles */
.frame-item {
  position: relative;
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 80px;
  background-color: #333;
  background-image:
    linear-gradient(45deg, #444 25%, transparent 25%, transparent 75%, #444 75%, #444 100%),
    linear-gradient(45deg, #444 25%, transparent 25%, transparent 75%, #444 75%, #444 100%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
}

.frame-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

.frame-thumbnail {
  max-width: 95%;
  max-height: 95%;
  image-rendering: pixelated;
  background: transparent !important;
}

.frame-number {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 11px;
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: bold;
  z-index: 10;
  pointer-events: none;
}

.frame-checkbox-new {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 20px;
  height: 20px;
  cursor: pointer;
  z-index: 30;
  accent-color: var(--accent);
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
}

/* Frame Item Actions (Copy Button) - Custom Icon */
.frame-item-actions {
  position: absolute;
  bottom: 4px;
  /* Bottom Right as requested */
  right: 4px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 40;
}

.frame-item:hover .frame-item-actions {
  opacity: 1;
}

.frame-action-btn {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 20px;
  /* Same size as checkbox (20px) */
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s;
}

.frame-action-btn:hover {
  background: var(--accent);
  border-color: var(--accent-glow);
}

/* Drag and Drop Visual Feedback */
.frame-item {
  transition: transform 0.2s, margin 0.2s, opacity 0.2s;
  /* Smooth transition for gap effect */
}

.frame-item.dragging {
  opacity: 0.4;
  transform: scale(0.9);
  border: 2px dashed var(--accent);
}

/* Create space/gap during drag */
.frame-item.drag-over-left {
  margin-left: 40px;
  /* Creates the gap */
  border-left: 4px solid var(--accent);
  /* Visual indicator */
}

.frame-item.drag-over-right {
  margin-right: 40px;
  /* Creates the gap */
  border-right: 4px solid var(--accent);
  /* Visual indicator */
}

.frame-item .frame-number {
  left: 8px;
  top: 8px;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

#selectAllFrames {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--accent);
}



.history-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Frame Controls */
.frame-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

#frameIndicator {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  min-width: 60px;
  text-align: center;
}

/* Export & Preview */
#exportGif {
  background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  border: none;
}

#exportGif:hover {
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
}

/* Updated Preview UI */
.gif-preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 12, 0.95);
  backdrop-filter: blur(15px);
  display: none;
  /* Controlled by .active */
  justify-content: center;
  align-items: center;
  z-index: 3000;
  padding: 24px;
}

.gif-preview-overlay.active {
  display: flex !important;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.preview-card {
  background: #1e1e22;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 32px;
  padding: 40px;
  max-width: 500px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 32px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
  position: relative;
  animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

.icon-btn#closePreviewBtn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  width: 36px;
  height: 36px;
  border-radius: 12px;
  color: #fff;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  cursor: pointer;
}

.icon-btn#closePreviewBtn:hover {
  background: #ef4444;
  color: white;
  border-color: #ef4444;
  transform: rotate(90deg);
}

.preview-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 20px;
  overflow: hidden;
  background: #000;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  border: 4px solid #2a2a2e;
}

#previewImg {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  object-fit: contain;
}

.playback-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.preview-stage:hover .playback-overlay {
  opacity: 1;
}

.playback-icon {
  width: 80px;
  height: 80px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255, 255, 255, 0.4);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  font-size: 40px;
  color: #fff;
  text-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}

.preview-stage:active .playback-icon {
  transform: scale(0.9);
}

.speed-control {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.speed-control label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}

.speed-control label span:nth-child(2) {
  color: var(--accent);
  font-family: monospace;
  font-size: 18px;
  margin-left: auto;
}

.speed-control label .unit {
  color: var(--text-muted);
  font-size: 12px;
}

/* Premium Speed Slider */
#speedSlider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 10px;
  background: #2a2a2e;
  outline: none;
  margin: 10px 0;
}

#speedSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
  border: 3px solid #fff;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#speedSlider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Tool Settings Shared */
.tool-setting {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

/* Mobile Responsiveness */
@media (max-width: 1024px) {
  .container {
    grid-template-areas:
      "header"
      "main"
      "sidebar"
      "timeline";
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
    height: auto;
    overflow-y: auto;
    width: 100vw;
  }

  body {
    overflow-y: auto;
    align-items: flex-start;
  }

  .sidebar {
    max-height: none;
  }

  canvas {
    max-width: 90vw;
  }

  .timeline {
    flex-direction: column;
    gap: 16px;
  }
}

/* Pen Icon */
.icon-pen {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z'%3E%3C/path%3E%3C/svg%3E");
}

/* Eraser Icon */
.icon-eraser {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 20H7L3 16C2 15 2 13 3 12L13 2L22 11L20 20Z'%3E%3C/path%3E%3Cpath d='M17 17L7 7'%3E%3C/path%3E%3C/svg%3E");
}

/* Eyedropper Icon */
.icon-eyedropper {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 21a4 4 0 0 1-4-4c0-1.5.8-2.5 1.7-4L2 15l8 4 1-1.3c1.5-.9 2.5-1.7 4-1.7'%3E%3C/path%3E%3Cpath d='M12 11l-8 8'%3E%3C/path%3E%3Cpath d='M19 3a2.828 2.828 0 0 1 2.8 2.8l-8.5 8.5-2.8-2.8L19 3z'%3E%3C/path%3E%3C/svg%3E");
}

/* Standard Cursors without custom images */
.pen-cursor {
  cursor: crosshair;
}

.eraser-cursor {
  cursor: cell;
}

.eyedropper-cursor {
  cursor: copy;
}

/* Onion Skin Canvas - Overlay Mode */
#onionSkinCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 15;
  /* Above dotCanvas (10), Below gridCanvas (20) */
  pointer-events: none;
  image-rendering: pixelated;
  opacity: 0.3;
  /* Adjusted dynamically via JS if needed */
  display: none;
  /* Hidden by default */
}

/* Ensure proper stacking */
#dotCanvas {
  z-index: 10;
}

#gridCanvas {
  z-index: 20;
  /* Highest: Grid, Guides, Selection */
}