* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1e1e1e;
  color: #e0e0e0;
  height: 100vh;
  overflow: hidden;
}

.app-container {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 330px;
  background: #252526;
  padding: 16px;
  border-right: 1px solid #3c3c3c;
  overflow-y: auto;
}

h2, h3 {
  margin-bottom: 16px;
  color: #ffffff;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: #cccccc;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-row input {
  width: 80px;
  padding: 6px 8px;
  background: #3c3c3c;
  border: 1px solid #555;
  color: white;
  border-radius: 4px;
}

.primary-btn, .secondary-btn {
  width: 100%;
  padding: 10px;
  margin: 8px 0;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
}

.primary-btn {
  background: #007acc;
  color: white;
}

.secondary-btn {
  background: #444;
  color: #ddd;
}

.primary-btn:hover {
  background: #005f99;
}

/* Explicit visibility rules */
.setup-panel {
  display: block;
}

.setup-panel:not(.active) {
  display: none !important;
}

.editor-panel {
  display: none;
}

.editor-panel:not(.hidden) {
  display: block;
}

.layer-selector {
  margin: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.layer-btn {
  padding: 8px;
  background: #333;
  border: 1px solid #555;
  color: #ddd;
  cursor: pointer;
  text-align: left;
}

.layer-btn.active {
  background: #007acc;
  border-color: #007acc;
  color: white;
}

.status {
  font-size: 0.9rem;
  color: #aaa;
  margin-top: 8px;
}

.main-area {
  flex: 1;
  position: relative;
  background: #111;
  overflow: hidden;
}

#canvas-container {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;      /* ← changed from center */
  justify-content: flex-start;  /* ← changed from center */
  overflow: auto;               /* ← allows scrolling if room bigger than screen */
}

#status-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  pointer-events: none;
}

.hidden {
  display: none !important;
}

.palette-panel {
  margin: 16px 0;
  background: #2d2d2d;
  border-radius: 4px;
  padding: 12px;
}

.palette-panel h3 {
  margin-bottom: 12px;
}

.accordion {
  background: #333;
  color: #ddd;
  cursor: pointer;
  padding: 10px;
  width: 100%;
  border: none;
  text-align: left;
  outline: none;
  font-size: 15px;
  transition: 0.4s;
  margin-bottom: 4px;
  border-radius: 4px;
}

.accordion.active, .accordion:hover {
  background: #444;
}

.panel {
  padding: 0 18px;
  background: #252526;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 4px;
  padding: 12px 0;
}

.tile-thumb {
  width: 48px;
  height: 48px;
  background: #1e1e1e;
  border: 2px solid transparent;
  cursor: pointer;
  border-radius: 4px;
  object-fit: none; /* keep pixel perfect */
}

.tile-thumb.selected {
  border: 2px solid #00ffea;
  box-shadow: 0 0 8px #00ffea;
}

#context-menu button {
  display: block;
  width: 100%;
  padding: 6px 12px;
  background: #444;
  border: none;
  color: white;
  cursor: pointer;
  text-align: left;
}

#context-menu button:hover {
  background: #555;
}

#context-menu button.collision-option {
  display: block;
  width: 100%;
  padding: 6px 12px;
  margin: 2px 0;
  background: #444;
  border: none;
  color: white;
  cursor: pointer;
  text-align: left;
}

#context-menu button.collision-option:hover {
  background: #555;
}

#context-menu button.collision-option.current {
  background: #0066cc;
  font-weight: bold;
}

/* Hide separator and label by default on BG Layer */
#context-menu:not(.main-layer-visible) #menu-separator,
#context-menu:not(.main-layer-visible) #menu-setto-label {
  display: none;
}

.overlay-toggle {
  margin: 12px 0;
}

#toggle-overlays-btn {
  width: 100%;
  padding: 8px;
  transition: background 0.2s ease; /* smooth color change */
}

#toggle-overlays-btn.active {
  background: #444; /* blue when overlays are shown */
  color: white;
}

#toggle-overlays-btn.inactive {
  background: #007acc; /* grey when overlays are hidden */
  color: #ddd;
}

#toggle-grid-btn {
  width: 100%;
  padding: 8px;
  margin: 8px 0;
  transition: background 0.2s ease; /* smooth color change */
}

#toggle-grid-btn.active {
  background: #444; /* blue when grid is shown */
  color: white;
}

#toggle-grid-btn.inactive {
  background: #007acc; /* grey when grid is hidden */
  color: #ddd;
}

.layer-visibility-toggles {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}

#toggle-main-layer-btn, #toggle-bg-layer-btn {
  width: 100%;
  padding: 8px;
  transition: background 0.2s ease;
}

#toggle-main-layer-btn.active,
#toggle-bg-layer-btn.active {
  background: #444; /* blue when layer is visible */
  color: white;
}

#toggle-main-layer-btn.inactive,
#toggle-bg-layer-btn.inactive {
  background: #007acc; /* grey when hidden */
  color: #ddd;
}

/* --- Palette Panel (from Sprite Editor) --- */
.palette-panel {
  margin: 16px 0;
  background: #2d2d2d;
  border-radius: 4px;
  padding: 12px;
}

.palette-panel h3 {
  margin-bottom: 12px;
  color: #ffffff;
}

/* Accordion styling */
.accordion {
  background: #333;
  color: #ddd;
  cursor: pointer;
  padding: 10px;
  width: 100%;
  border: none;
  text-align: left;
  outline: none;
  font-size: 14px;
  transition: 0.4s;
  margin-bottom: 4px;
  border-radius: 4px;
}

.accordion.active,
.accordion:hover {
  background: #444;
}

/* Accordion content panel */
.panel {
  padding: 0 18px;
  background: #252526;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
}

/* Grid of tiles in the palette */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 4px;
  padding: 12px 0;
}

/* Individual tile thumbnails */
.tile-thumb {
  width: 48px;
  height: 48px;
  background: #1e1e1e;
  border: 2px solid transparent;
  cursor: pointer;
  border-radius: 4px;
  object-fit: none; /* preserves pixel art */
}

.tile-thumb.selected {
  border: 2px solid #00ffea;
  box-shadow: 0 0 8px #00ffea;
}

/* Optional small storage info under palette */
.storage-info {
  font-size: 0.8em;
  color: #aaa;
  margin-left: 6px;
}

/* Accordion + grid animation similar hover effect */
.tile-thumb:hover {
  border-color: #00ffea;
  box-shadow: 0 0 4px #00ffea;
}

.hidden-tile-size {
  display: none;
}

/* Shared input styling for setup screens */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: #ccc;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-row input[type="text"] {
  flex: 1;
  padding: 6px 8px;
  background: #3c3c3c;
  border: 1px solid #555;
  color: white;
  border-radius: 4px;
  font-size: 1rem;
}

#canvas-container {
  position: relative; /* necessary for bottom-editor absolute positioning */
  width: 100%;
  height: 80vh; /* adjust to your preferred canvas height */
  overflow: auto;
}

/* Bottom editor container (absolute inside canvas-container) */
#bottom-editor-container {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 20px;
  padding: 12px;
  background: #252526;
  border-top: 1px solid #3c3c3c;
  box-sizing: border-box;
}

/* Editor boxes */
.editor-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #252526;
  border: 1px solid #3c3c3c;
  padding: 12px;
}

.editor-box h3 {
  margin: 0;
  font-size: 1rem;
}

.editor-box textarea {
  width: 100%;
  min-height: 80px;
  background: #1e1e1e;
  border: 1px solid #555;
  color: #fff;
  padding: 8px;
  resize: none;
  border-radius: 4px;
  font-family: monospace;
}

/* Hidden by default */
.hidden {
  display: none;
}

