/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { overflow: hidden; }
body { font-family: 'Segoe UI', sans-serif; background: #1a1a2e; color: #e0e0e0; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

/* Header */
.app-header { background: #16213e; padding: 12px 20px; border-bottom: 2px solid #0f3460; }
.app-header h1 { font-size: 1.2rem; color: #e94560; letter-spacing: 1px; }

/* Layout */
.app-layout { display: flex; flex: 1; overflow: hidden; height: calc(100vh - 49px); }

/* Sidebar */
.sidebar {
  width: 180px;
  min-width: 160px;
  background: #16213e;
  border-right: 1px solid #0f3460;
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  gap: 10px;
  overflow: hidden;
}
.sidebar-actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.level-list { flex: 1; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.level-list-empty { font-size: 0.78rem; color: #666; text-align: center; margin-top: 10px; }
.level-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: #0f3460;
  border-radius: 4px;
  font-size: 0.8rem;
  border: 1px solid transparent;
  transition: border-color 0.15s;
}
.level-item:hover { border-color: #e94560; }
.level-item.active { border-color: #e94560; background: #1a1a4e; }
.level-item-info { flex: 1; cursor: pointer; min-width: 0; }
.level-item .level-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.level-item .level-size { font-size: 0.72rem; color: #aaa; }
.level-item .level-id { font-size: 0.68rem; color: #666; font-family: monospace; }
.btn-delete-level {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: #666;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.btn-delete-level:hover { color: #fff; background: #e94560; }

/* Buttons */
.btn {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: #0f3460; color: #e0e0e0; }
.btn-save { background: #e94560; color: #fff; }
.btn-sm { padding: 3px 8px; font-size: 0.78rem; background: #0f3460; color: #e0e0e0; }
.btn-mode { background: #0f3460; color: #aaa; padding: 5px 10px; font-size: 0.8rem; }
.btn-mode.active { background: #e94560; color: #fff; }

/* Main content */
.main-content { flex: 1; display: flex; flex-direction: column; padding: 10px 14px; overflow: auto; gap: 8px; }

/* Toolbar */
.toolbar { display: flex; flex-direction: column; gap: 6px; background: #16213e; border-radius: 6px; padding: 10px 12px; border: 1px solid #0f3460; }
.toolbar-meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 0.82rem; }
.toolbar-meta label { display: flex; align-items: center; gap: 5px; }
.toolbar-meta input[type="text"],
.toolbar-meta input[type="number"],
.toolbar-meta select {
  background: #0f1b35;
  border: 1px solid #0f3460;
  color: #e0e0e0;
  border-radius: 3px;
  padding: 3px 6px;
  font-size: 0.82rem;
}
.toolbar-meta input[type="text"] { width: 130px; }
.toolbar-meta input[type="number"] { width: 52px; }
.toolbar-controls { display: flex; align-items: center; gap: 16px; }
.mode-toggle { display: flex; gap: 4px; }
.zoom-controls { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; }
#zoom-label { min-width: 42px; text-align: center; font-size: 0.8rem; color: #ccc; }

/* Palette */
.palette { display: flex; gap: 6px; align-items: center; padding: 6px 10px; background: #16213e; border-radius: 6px; border: 1px solid #0f3460; }
.palette-color {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}
.palette-color:hover { transform: scale(1.15); }
.palette-color.active { border-color: #fff; transform: scale(1.1); }
.palette-color.eraser { background: #333 !important; color: #ccc; font-size: 1rem; display: flex; align-items: center; justify-content: center; border-radius: 6px; }

/* Offline banner */
.offline-banner {
  background: #5a2d00;
  border: 1px solid #e67e22;
  color: #f39c12;
  font-size: 0.8rem;
  padding: 5px 10px;
  border-radius: 4px;
}
.offline-banner.hidden { display: none; }

/* Status message */
.status-msg { font-size: 0.8rem; min-height: 1.2em; padding: 0 4px; color: #2ECC71; }
.status-msg.error { color: #e74c3c; }

/* Grid layout */
.grids-wrapper { display: flex; gap: 0; flex: 1; overflow: hidden; }
.grid-section { display: flex; flex-direction: column; gap: 6px; flex: 1; overflow: auto; }

/* Zoom container: holds both grid wrappers side by side, scaled together */
.grid-zoom-container {
  display: flex;
  gap: 24px;
  transform-origin: top left;
  /* transform: scale() is set via JS */
}

/* Each grid wrapper: title + grid stacked vertically */
.grid-wrapper { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
.grid-title { font-size: 0.85rem; color: #aaa; letter-spacing: 0.5px; padding: 0 2px; }

/* Each grid container: CSS Grid layout */
.grid-container {
  display: grid;
  gap: 2px;
  /* grid-template-columns set by JS based on gridSize.x */
  flex-shrink: 0;
}

/* Individual cells */
.cell {
  width: 36px;
  height: 36px;
  border: 1px solid #2a2a4a;
  border-radius: 3px;
  background: #111124;
  position: relative;
  cursor: crosshair;
  user-select: none;
  overflow: hidden;
  transition: border-color 0.1s;
}
.cell:hover { border-color: #888; }

/* Target grid cell: colored square fill */
.cell.target-cell.colored { border-color: transparent; }
.cell-square {
  width: 100%;
  height: 100%;
  border-radius: 3px;
}

/* Initial grid cell: circle over dim background */
.cell-bg {
  position: absolute;
  inset: 0;
  border-radius: 3px;
  opacity: 0.3;
}
.cell-circle {
  position: absolute;
  top: 15%;
  left: 15%;
  width: 70%;
  height: 70%;
  border-radius: 50%;
}

/* not-allowed cursor for empty cells in Edit Initial mode */
.cell.no-paint { cursor: not-allowed; }

/* Scrollable grid area */
.grid-section { overflow: auto; }
