/* ═══════════════════════════════════════════════════
   ASSET EXPLORER — Browse, Create & Edit All Assets
   ═══════════════════════════════════════════════════ */

/* ── Overlay Shell ── */
.asset-explorer-overlay {
  position: absolute;
  top: calc(var(--topbar-height) + 12px);
  left: calc(clamp(160px, 15vw, var(--nav-width)) + 32px);
  right: 16px;
  bottom: 16px;
  z-index: 95; /* Above nav sidebar (90) and panel (80), below topbar (100) */
  background: linear-gradient(145deg, rgba(12, 16, 36, 0.97), rgba(18, 24, 52, 0.98));
  backdrop-filter: blur(16px);
  border: 1px solid rgba(90, 110, 200, 0.25);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow:
    0 12px 48px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.asset-explorer-overlay.hidden {
  display: none !important;
}

/* ── Header ── */
.asset-explorer-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid rgba(90, 110, 200, 0.2);
  background: linear-gradient(180deg, rgba(20, 28, 60, 0.8), transparent);
  flex-shrink: 0;
}

.asset-explorer-title-row {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 14px;
}

.asset-explorer-title-row h1 {
  margin: 0;
  font-size: 1.6em;
  font-weight: 700;
  background: linear-gradient(135deg, var(--text-secondary), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.asset-explorer-subtitle {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-faint);
}

/* ── Controls Row ── */
.asset-explorer-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.asset-explorer-controls input[type="text"] {
  flex: 1;
  min-width: 140px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid rgba(90, 110, 200, 0.3);
  background: rgba(15, 19, 40, 0.7);
  color: #e8ecff;
  font-size: 0.85rem;
  outline: none;
  transition: all 0.2s;
}

.asset-explorer-controls input[type="text"]:focus {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.15);
}

.asset-explorer-controls input[type="text"]::placeholder {
  color: #4a5580;
}

.asset-count {
  font-size: 0.8rem;
  color: var(--accent-light);
  white-space: nowrap;
  font-weight: 600;
}

/* ── Kind Filters ── */
.asset-kind-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.kind-filter-btn {
  padding: 3px 8px;
  border-radius: 20px;
  border: 1px solid rgba(90, 110, 200, 0.25);
  background: rgba(20, 28, 60, 0.5);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.kind-filter-btn:hover {
  background: rgba(40, 55, 110, 0.6);
  border-color: rgba(124, 140, 255, 0.4);
  color: var(--text-secondary);
  transform: translateY(-1px);
}

.kind-filter-btn.active {
  background: linear-gradient(135deg, var(--accent), #4355c4);
  border-color: var(--accent-light);
  color: #fff;
  box-shadow: 0 2px 8px rgba(83, 102, 214, 0.35);
}

/* Generic active color — badge on each card already shows the tool color */

/* ── Actions Row ── */
.asset-explorer-actions {
  padding: 10px 24px;
  border-bottom: 1px solid rgba(90, 110, 200, 0.12);
  flex-shrink: 0;
  display: flex;
  gap: 8px;
}

/* ── Body Layout ── */
.asset-explorer-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Asset Grid ── */
.asset-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  align-content: start;
}

.asset-grid::-webkit-scrollbar {
  width: 6px;
}
.asset-grid::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}
.asset-grid::-webkit-scrollbar-track {
  background: transparent;
}

/* ── Asset Card ── */
.asset-card {
  background: rgba(20, 28, 60, 0.6);
  border: 1px solid rgba(90, 110, 200, 0.2);
  border-radius: var(--radius-lg);
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.asset-card:hover {
  border-color: var(--accent-light);
  background: rgba(30, 40, 80, 0.7);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.asset-card.selected {
  border-color: var(--accent-light);
  background: rgba(83, 102, 214, 0.15);
  box-shadow: 0 0 0 2px rgba(124, 140, 255, 0.2);
}

.asset-card canvas {
  border-radius: 4px;
  background: repeating-conic-gradient(rgba(255,255,255,0.05) 0% 25%, transparent 0% 50%) 0 0 / 8px 8px;
  image-rendering: pixelated;
}

.asset-card-name {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-card-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  justify-content: center;
}

/* ── Kind Badge ── */
.kind-badge {
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kind-badge.ground {
  background: rgba(39, 174, 96, 0.25);
  color: #2ecc71;
}

.kind-badge.object {
  background: rgba(41, 128, 185, 0.25);
  color: #3498db;
}

.kind-badge.structure {
  background: rgba(142, 68, 173, 0.25);
  color: #bb6bd9;
}

.kind-badge.animal {
  background: rgba(192, 57, 43, 0.25);
  color: #e74c3c;
}

.kind-badge.food {
  background: rgba(212, 160, 23, 0.25);
  color: #f0c040;
}

.custom-badge {
  font-size: 0.6rem;
  color: var(--accent-light);
  font-style: italic;
}

/* ── Detail Panel ── */
.asset-detail {
  width: 320px;
  flex-shrink: 0;
  border-left: 1px solid rgba(90, 110, 200, 0.2);
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.asset-detail.hidden {
  display: none;
}

.asset-detail::-webkit-scrollbar {
  width: 6px;
}
.asset-detail::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}
.asset-detail::-webkit-scrollbar-track {
  background: transparent;
}

.asset-detail-close {
  align-self: flex-end;
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px;
  transition: color 0.15s;
}

.asset-detail-close:hover {
  color: var(--text-primary);
}

.asset-detail-preview {
  align-self: center;
  border-radius: 8px;
  background: repeating-conic-gradient(rgba(255,255,255,0.05) 0% 25%, transparent 0% 50%) 0 0 / 12px 12px;
  image-rendering: pixelated;
  border: 1px solid rgba(90, 110, 200, 0.2);
}

.asset-detail h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.asset-detail-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.asset-detail-row label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.asset-detail-row input,
.asset-detail-row select {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid rgba(90, 110, 200, 0.3);
  background: rgba(15, 19, 40, 0.7);
  color: #e8ecff;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.asset-detail-row input:focus,
.asset-detail-row select:focus {
  border-color: var(--accent-light);
}

.asset-detail-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.asset-detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px solid rgba(90, 110, 200, 0.15);
}

/* ── Buttons ── */
.primary-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: linear-gradient(135deg, var(--accent), #4355c4);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.primary-btn:hover {
  background: linear-gradient(135deg, #5a6de6, #5366d4);
  box-shadow: 0 2px 8px rgba(83, 102, 214, 0.35);
  transform: translateY(-1px);
}

.secondary-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid rgba(90, 110, 200, 0.3);
  background: rgba(20, 28, 60, 0.6);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.secondary-btn:hover {
  background: rgba(40, 55, 110, 0.6);
  border-color: rgba(124, 140, 255, 0.4);
}

.danger-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid rgba(192, 57, 43, 0.4);
  background: rgba(192, 57, 43, 0.15);
  color: #e74c3c;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.danger-btn:hover {
  background: rgba(192, 57, 43, 0.3);
  border-color: #e74c3c;
}

/* ── Create Form (inline in detail panel) ── */
.asset-create-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: rgba(15, 19, 40, 0.5);
  border-radius: 12px;
  border: 1px solid rgba(90, 110, 200, 0.2);
}

.asset-create-form h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--text-primary);
}


/* ═══════════════════════════════════════════════════
   TILE EDITOR — Pixel Art Editor for Textures
   ═══════════════════════════════════════════════════ */

/* ── Overlay ── */
.tile-editor-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: linear-gradient(145deg, rgba(8, 10, 24, 0.99), rgba(12, 16, 36, 0.99));
  display: flex;
  flex-direction: column;
}

.tile-editor-overlay.hidden {
  display: none !important;
}

/* ── Header ── */
.tile-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  height: 52px;
  border-bottom: 1px solid rgba(90, 110, 200, 0.25);
  background: linear-gradient(180deg, rgba(20, 28, 60, 0.9), rgba(12, 16, 36, 0.8));
  flex-shrink: 0;
}

.tile-editor-header span {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.tile-editor-header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tile-editor-header-controls label {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.tile-editor-header-controls select {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(90, 110, 200, 0.3);
  background: rgba(15, 19, 40, 0.8);
  color: #e8ecff;
  font-size: 0.8rem;
  outline: none;
}

/* ── Body Layout ── */
.tile-editor-body {
  display: flex;
  height: calc(100% - 52px);
  overflow: hidden;
}

/* ── Toolbar (left) ── */
.tile-editor-tools {
  width: 48px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border-right: 1px solid rgba(90, 110, 200, 0.15);
  background: rgba(12, 16, 36, 0.6);
  overflow-y: auto;
}

.te-tool-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid rgba(90, 110, 200, 0.2);
  background: rgba(20, 28, 60, 0.5);
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  padding: 0;
}

.te-tool-btn:hover {
  background: rgba(40, 55, 110, 0.6);
  border-color: rgba(124, 140, 255, 0.4);
  color: var(--text-secondary);
}

.te-tool-btn.active {
  background: linear-gradient(135deg, var(--accent), #4355c4);
  border-color: var(--accent-light);
  color: #fff;
  box-shadow: 0 2px 6px rgba(83, 102, 214, 0.3);
}

.te-tool-btn[title]::after {
  content: none;
}

/* ── Canvas Area (center) ── */
.tile-editor-canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    repeating-conic-gradient(
      rgba(255, 255, 255, 0.03) 0% 25%,
      rgba(0, 0, 0, 0.03) 0% 50%
    ) 0 0 / 20px 20px;
}

.tile-editor-canvas-wrap canvas {
  image-rendering: pixelated;
  cursor: crosshair;
  border: 1px solid rgba(90, 110, 200, 0.3);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* ── Sidebar (right) ── */
.tile-editor-sidebar {
  width: 220px;
  flex-shrink: 0;
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-left: 1px solid rgba(90, 110, 200, 0.15);
  background: rgba(12, 16, 36, 0.6);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.tile-editor-sidebar::-webkit-scrollbar {
  width: 6px;
}
.tile-editor-sidebar::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}
.tile-editor-sidebar::-webkit-scrollbar-track {
  background: transparent;
}

/* ── Color Section ── */
.te-color-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.te-color-section input[type="color"] {
  width: 100%;
  height: 36px;
  border: 1px solid rgba(90, 110, 200, 0.3);
  border-radius: 6px;
  background: rgba(15, 19, 40, 0.7);
  cursor: pointer;
  padding: 2px;
}

.te-color-section input[type="text"] {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid rgba(90, 110, 200, 0.3);
  background: rgba(15, 19, 40, 0.7);
  color: #e8ecff;
  font-size: 0.8rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.te-color-section input[type="text"]:focus {
  border-color: var(--accent-light);
}

.te-color-section label {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.te-color-section input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 4px;
}

/* ── Recent Colors ── */
.te-recent-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.te-recent-colors::before {
  content: "Recent";
  display: block;
  width: 100%;
  font-size: 0.7rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

/* ── Color Presets ── */
.te-color-presets::before {
  content: "Palette";
  display: block;
  width: 100%;
  font-size: 0.7rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.te-swatch-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.te-preset-swatch,
.te-recent-swatch {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  border: 1px solid rgba(90, 110, 200, 0.3);
  cursor: pointer;
  transition: all 0.15s;
}

.te-preset-swatch:hover,
.te-recent-swatch:hover {
  transform: scale(1.2);
  border-color: var(--accent-light);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  z-index: 1;
}

/* ── Preview Canvas ── */
.tile-editor-sidebar canvas {
  align-self: center;
  border-radius: 6px;
  border: 1px solid rgba(90, 110, 200, 0.2);
  image-rendering: pixelated;
  background: repeating-conic-gradient(rgba(255,255,255,0.05) 0% 25%, transparent 0% 50%) 0 0 / 8px 8px;
}

/* ── Zoom Controls ── */
.te-zoom-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.te-zoom-controls button {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid rgba(90, 110, 200, 0.3);
  background: rgba(20, 28, 60, 0.5);
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.te-zoom-controls button:hover {
  background: rgba(40, 55, 110, 0.6);
  border-color: rgba(124, 140, 255, 0.4);
}

.te-zoom-controls span {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 30px;
  text-align: center;
  font-weight: 600;
}


/* ═══════════════════════════════════════════════════
   Responsive — Asset Explorer + Tile Editor
   ═══════════════════════════════════════════════════ */

@media (max-width: 900px) {
  .asset-explorer-overlay {
    left: 8px;
    right: 8px;
  }

  .asset-explorer-body {
    flex-direction: column;
  }

  .asset-detail {
    width: auto;
    border-left: none;
    border-top: 1px solid rgba(90, 110, 200, 0.2);
    max-height: 50%;
  }

  .tile-editor-sidebar {
    width: 180px;
  }

  .tile-editor-tools {
    width: 40px;
  }
}

@media (max-width: 600px) {
  .asset-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    padding: 10px;
  }

  .tile-editor-body {
    flex-direction: column;
  }

  .tile-editor-tools {
    width: auto;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid rgba(90, 110, 200, 0.15);
  }

  .tile-editor-sidebar {
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    border-left: none;
    border-top: 1px solid rgba(90, 110, 200, 0.15);
    max-height: 180px;
  }
}
