/* Tilemap Editor Layout */
.tm-wrapper {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 2rem;
  margin-top: 2rem;
  height: calc(100vh - 180px);
  min-height: 600px;
}

/* Sidebar */
.tm-sidebar {
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  overflow-y: auto;
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.control-group {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.control-group label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
}

.tm-input {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 0.5rem;
  color: white;
  font-family: monospace;
  width: 100%;
  transition: border-color var(--transition-fast);
}
.tm-input:focus {
  border-color: var(--accent-primary);
  outline: none;
}

.tm-divider {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin: 1rem 0;
}

/* Tileset Preview */
.tileset-preview-container {
  width: 100%;
  max-height: 250px;
  overflow: auto;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  position: relative;
  cursor: crosshair;
}

#tileset-canvas {
  display: block;
}

#tileset-selector-box {
  position: absolute;
  top: 0;
  left: 0;
  border: 2px solid #10b981;
  background: rgba(16, 185, 129, 0.2);
  pointer-events: none;
  display: none;
  box-shadow: 0 0 5px #10b981, inset 0 0 5px #10b981;
}

/* Tools */
.tool-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tm-tool-btn {
  flex: 1;
  padding: 0.6rem 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: var(--text-main);
  cursor: pointer;
  font-weight: 600;
  transition: all var(--transition-fast);
  text-align: center;
}

.tm-tool-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

#draw-mode-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.export-dropdown {
    display: none;
    position: absolute;
    bottom: 110%;
    left: 0;
    width: 100%;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.5rem;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 100;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.export-dropdown.show {
    display: flex;
}

.tm-tool-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: white;
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.tm-tool-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(1);
}

.tm-tool-btn.special {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
  color: #10b981;
}
.tm-tool-btn.special.active {
  background: #10b981;
  border-color: #10b981;
  color: white;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}

/* Auto-Config Grid */
.auto-config-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.3rem;
}

.auto-slot {
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  transition: all var(--transition-fast);
  display: flex;
  justify-content: center;
  align-items: center;
}

.auto-slot:hover {
  border-color: rgba(255, 255, 255, 0.3);
}

.auto-slot.active {
  border-color: var(--accent-primary);
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.5), inset 0 0 10px rgba(139, 92, 246, 0.2);
}

.auto-slot-indicator {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
}

.auto-slot canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Main Canvas */
.tm-canvas-wrapper {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.canvas-scroll-area {
  width: 100%;
  height: 100%;
  overflow: auto;
  /* Checkerboard background for transparency visibility */
  background-image: linear-gradient(45deg, #1a1a2e 25%, transparent 25%),
                    linear-gradient(-45deg, #1a1a2e 25%, transparent 25%),
                    linear-gradient(45deg, transparent 75%, #1a1a2e 75%),
                    linear-gradient(-45deg, transparent 75%, #1a1a2e 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  border-radius: 8px;
}

#tm-canvas {
  background: transparent;
  cursor: crosshair;
  box-shadow: 0 0 20px rgba(0,0,0,0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  color: #fff;
  padding: 0.8rem 1.5rem;
  border-radius: 50px;
  font-size: 0.95rem;
  font-weight: 500;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 1000;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {
  .tm-wrapper {
    grid-template-columns: 1fr;
    grid-template-rows: auto 500px;
    height: auto;
  }
}
