/* Reset and base styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #1a1a1a;
  color: #fff;
  overflow-x: hidden;
  line-height: 1.4;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header styles - Compact buttons */
header {
  background: #2d2d2d;
  /* padding: 0.5rem; */
  border-bottom: 1px solid #444;
  display: flex;
  flex-wrap: wrap;
  /* gap: 0.5rem; */
  align-items: center;
  position: relative;
}

.controls-left {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}

.file-label {
  position: relative;
  cursor: pointer;
}

.file-label input[type="file"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.file-label .hint {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  background: #4a4a4a;
  border-radius: 4px;
  font-size: 0.8rem;
  transition: background 0.2s;
  white-space: nowrap;
}

.file-label:hover .hint {
  background: #5a5a5a;
}

.quick-add {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

/* .quick-add button,
.shape-picker button {
  padding: 0.4rem 0.8rem;
  background: #0066cc;
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.2s;
  white-space: nowrap;
}

.quick-add button:hover,
.shape-picker button:hover {
  background: #0052a3;
} */

.shape-picker {
  display: flex;
  gap: 0.25rem;
}

.shape-picker select {
  padding: 0.4rem;
  background: #333;
  border: 1px solid #555;
  border-radius: 4px;
  color: white;
  min-width: 100px;
  font-size: 0.8rem;
}

/* Main layout */
main {
  display: flex;
  flex: 1;
  gap: 0.1rem;
  padding: 0.1rem;
  overflow: hidden;
}

/* Bins sidebar - Desktop version */
.bins {
  width: 180px;
  background: #2d2d2d;
  border-radius: 8px;
  padding: 0.5rem;
  overflow-y: auto;
  flex-shrink: 0;
}

.bins h3 {
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: #ccc;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.bin-list {
  list-style: none;
  margin-bottom: 1rem;
}

.bin-list li {
  padding: 0.4rem;
  background: #3a3a3a;
  margin-bottom: 0.2rem;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.bin-list li:hover {
  background: #4a4a4a;
}

/* Thumbnail styles - Smaller and consistent */
.bin-thumbnail {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 3px;
  flex-shrink: 0;
}

.bin-item-content {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.bin-item-name {
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Canvas area - Larger preview */
.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.canvas-toolbar.mobile-hidden {
  display: flex;
  gap: 0.25rem;
  padding: 0.4rem;
  background: #2d2d2d;
  border-radius: 8px;
  justify-content: center;
}

.canvas-toolbar button {
  padding: 0.4rem 0.8rem;
  background: #4a4a4a;
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  font-size: 0.8rem;
}

.canvas-wrapper {
  position: relative;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 400px;
}

#editorCanvas {
  max-width: 100%;
  max-height: 70vh;
  width: auto;
  height: auto;
  object-fit: contain; 
}

/* Controls bar - Compact */
#controlsBar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  padding: 0.4rem;
  background: #2d2d2d;
  border-radius: 8px;
  justify-content: center;
}

#controlsBar button {
  padding: 0.4rem 0.8rem;
  background: #4a4a4a;
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  font-size: 0.8rem;
}

#controlsBar span {
  font-size: 0.8rem;
  color: #ccc;
}

/* Global audio controls - Horizontal layout */
.global-audio-controls {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0.4rem;
  background: #2d2d2d;
  border-radius: 8px;
  justify-content: center;
  overflow-x: auto;
}

.mycontrols {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  background: #2d2d2d;
  border-radius: 8px;
  justify-content: center;
  overflow-x: auto;
}

.global-audio-controls label {
  font-size: 0.8rem;
  color: #9aa0a6;
  white-space: nowrap;
}

.global-audio-controls input[type="range"] {
  width: 80px;
}

.global-audio-controls input[type="number"] {
  width: 60px;
  padding: 0.3rem;
}

.global-audio-controls button {
  /* padding: 0.4rem 0.6rem; */
 /*  background: #3a3a3a;
  border: 1px solid #555;
  border-radius: 4px;
  color: white;
  font-size: 0.8rem;
  white-space: nowrap; */
}

/* Progress container */
#progressContainer {
  width: 100%;
  background: #222;
  height: 20px;
  border-radius: 5px;
  position: relative;
  margin: 0.25rem 0;
}

#progressBar {
  height: 100%;
  background: #4caf50;
  border-radius: 5px;
  transition: width 0.1s;
}

#messageID {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.7rem;
  color: #ccc;
}

/* Clip controls */
#clipControls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.25rem 0;
  justify-content: center;
}

#clipControls button {
  padding: 0.4rem 0.8rem;
  background: #0066cc;
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  font-size: 0.8rem;
}

#clipBin {
  list-style: none;
  background: #2d2d2d;
  border-radius: 8px;
  padding: 0.4rem;
  max-height: 150px;
  overflow-y: auto;
  font-size: 0.8rem;
}

/* Sidebar with popup functionality */
.sidebar {
  width: 250px;
  background: #2d2d2d;
  border-radius: 8px;
  padding: 0.8rem;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-popup-toggle {
  display: none;
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 1000;
  padding: 0.5rem;
  background: #0066cc;
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  font-size: 0.8rem;
}

.sidebar h3 {
  margin: 0.8rem 0 0.4rem 0;
  font-size: 0.9rem;
  color: #ccc;
}

.sidebar h3:first-child {
  margin-top: 0;
}

.mode-group {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

.mode {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
}

.controls-right {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.8rem;
}

.controls-right button {
  padding: 0.4rem 0.8rem;
  background: #4a4a4a;
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  flex: 1;
  font-size: 0.8rem;
}

#settings label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
}

#settings input[type="number"],
#settings input[type="text"],
#settings select {
  width: 100%;
  padding: 0.4rem;
  background: #3a3a3a;
  border: 1px solid #555;
  border-radius: 4px;
  color: white;
  margin-top: 0.2rem;
  font-size: 0.8rem;
}

#settings input[type="range"] {
  width: 100%;
  margin: 0.4rem 0;
}

#settings input[type="color"] {
  width: 100%;
  height: 35px;
  border: none;
  border-radius: 4px;
  background: transparent;
}

#settings input[type="checkbox"] {
  margin-right: 0.4rem;
}

.fieldset {
  border: 1px solid #555;
  border-radius: 4px;
  padding: 0.4rem;
  margin: 0.4rem 0;
}

.fieldset legend {
  padding: 0 0.4rem;
  font-size: 0.8rem;
  color: #ccc;
}

.subcontrols {
  margin: 0.4rem 0;
}

.sidebar-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.8rem;
}

.sidebar-actions button {
  padding: 0.4rem 0.8rem;
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  flex: 1;
  font-size: 0.8rem;
}

#duplicateItem {
  background: #0066cc;
}

#deleteItem {
  background: #cc0000;
}

/* Utility classes */
.hidden {
  display: none !important;
}

.inline {
  display: inline-flex;
  align-items: center;
}

/* Overlay for mobile modals */
.bins-overlay,
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 999;
}

.bins-overlay.open,
.sidebar-overlay.open {
  display: block;
}

/* Bins Modal for Mobile */
.bins-modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 400px;
  max-height: 80vh;
  background: #2d2d2d;
  border-radius: 12px;
  padding: 1rem;
  z-index: 1000;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.bins-modal.open {
  display: block;
}

.bins-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #444;
}

.bins-modal-title {
  font-size: 1.2rem;
  color: #fff;
  margin: 0;
}

.bins-modal-close {
  background: #cc0000;
  border: none;
  color: white;
  padding: 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}

.bins-section {
  margin-bottom: 1.5rem;
}

.bins-section h4 {
  margin-bottom: 0.5rem;
  font-size: 1rem;
  color: #ccc;
  border-bottom: 1px solid #444;
  padding-bottom: 0.25rem;
}

/* Mobile responsiveness */
@media (max-width: 1024px) {
  main {
    flex-direction: column;
    padding: 0.4rem;
    gap: 0.4rem;
  }
  
  .bins,
  .sidebar {
    width: 100%;
  }
  
  .canvas-wrapper {
    min-height: 300px;
  }
  
  #editorCanvas {
    max-height: 50vh;
  }
}

@media (max-width: 768px) {
  header {
    padding: 0.4rem;
    /* padding-top: 60px; /*Make space for floating buttons */ 
  }
  
  .controls-left {
    justify-content: center;
  }
  
  /* Hide regular bins on mobile */
  .bins {
    display: none;
  }
  
  /* Bin toggle button for mobile */
  .bin-toggle {
    display: block;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1001;
    background: #0066cc;
    border: none;
    color: white;
    padding: 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
  }
  
  /* Sidebar mobile styles */
  .sidebar-popup-toggle {
    display: block;
  }
  
  .sidebar {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 350px;
    max-height: 80vh;
    z-index: 1000;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: none;
  }
  
  .sidebar.open {
    display: block;
  }
  
  /* Make thumbnails even smaller on mobile */
  .bin-thumbnail {
    width: 25px;
    height: 25px;
  }
  
  .bin-item-name {
    font-size: 0.7rem;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 13px;
  }
  
  .file-label .hint,
  .quick-add button,
  .shape-picker button {
    padding: 0.5rem;
    font-size: 0.7rem;
  }
  
  .bin-toggle,
  .sidebar-popup-toggle {
    padding: 0.6rem;
    font-size: 0.9rem;
  }
  
  .bins-modal {
    width: 95%;
    max-width: none;
    margin: 1rem;
  }
  
  #controlsBar {
    flex-direction: column;
    align-items: stretch;
  }
  
  #controlsBar button {
    flex: 1;
  }
  
  .global-audio-controls {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .mode-group {
    flex-direction: column;
    gap: 0.4rem;
  }
  
  .sidebar-actions {
    flex-direction: column;
  }
  
  /* Even smaller thumbnails on very small screens */
  .bin-thumbnail {
    width: 20px;
    height: 20px;
  }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
  button, 
  .file-label .hint,
  .bin-list li {
    min-height: 12px;
    min-width: 12px;
  }
  
  .bin-toggle,
  .sidebar-popup-toggle {
    min-height: 12px;
    min-width: 12px;
  }
  
  input[type="range"] {
    height: 12px;
  }
}

/* Dark theme enhancements */
input[type="number"]:focus,
input[type="text"]:focus,
select:focus,
button:focus {
  outline: 2px solid #0066cc;
  outline-offset: 1px;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: #2d2d2d;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #666;
}


  
/* Modal background */
.modal {
  display: none; 
  position: fixed; 
  z-index: 1000;
  left: 0; top: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.6);
}

/* Modal box */
.modal-content {
  background: #1c1e20;
  margin: 5% auto;
  padding: 20px;
  border-radius: 10px;
  width: 80%;
  max-width: 600px;
  color: #fff;
  position: relative;
}

/* Close button */
.close {
  color: #ff4d4d;   /* red */
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}
.close:hover {
  color: #ff0000;
}

/* Grid layout */
.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

/* Buttons + labels unified look */
.file-label,
.controls-grid button,
.shape-picker button {
  display: inline-block;
  background: #2a2d31;
  color: #fff;
  font-size: 14px;
  padding: 10px 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  transition: background 0.2s;
  width: 100%;
}
.file-label:hover,
.controls-grid button:hover,
.shape-picker button:hover {
  background: #3a3f44;
}

/* Hide default file input */
.file-label input {
  display: none;
}
.file-label span {
  pointer-events: none;
}

/* Shape select styling */
.shape-picker select {
  margin-right: 8px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid #555;
  background: #1c1e20;
  color: #fff;
}

/* Responsive: single column on small screens */
@media (max-width: 600px) {
  .controls-grid {
    grid-template-columns: 1fr;
  }
}

