/* ═══ Editor Layout ═══ */

.editor {
  display: none;
  height: 100vh;
  grid-template-columns: var(--sidebar-width) 1fr var(--toolbar-width);
  grid-template-rows: 48px 1fr;
  grid-template-areas:
    "topbar topbar topbar"
    "sidebar canvas toolbar";
  opacity: 0;
  transition: grid-template-columns 0.4s var(--ease);
}
.editor.active {
  display: grid;
  animation: editorReveal 800ms var(--ease) forwards;
}
.editor.active.drawing-mode {
  grid-template-rows: 48px auto 1fr;
  grid-template-areas:
    "topbar  topbar  topbar"
    "drawbar drawbar drawbar"
    "sidebar canvas  toolbar";
}

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}
.topbar-logo {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text-secondary);
}
.topbar-version {
  font-size: 0.55rem;
  font-weight: 400;
  opacity: 0.4;
  margin-left: 6px;
}
.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}
.topbar-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}
.topbar-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}
.topbar-btn:disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}
.topbar-btn.primary {
  color: var(--lavender);
  background: rgba(196, 181, 253, 0.1);
}
.topbar-btn.primary:hover {
  background: rgba(196, 181, 253, 0.18);
}

.sidebar {
  grid-area: sidebar;
  background: rgba(255, 255, 255, 0.02);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px 12px;
}
.sidebar-section-title {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-secondary);
  margin: 12px 0 8px;
}
.sidebar-section-title:first-child { margin-top: 0; }

/* ═══ Collapsible Sections ═══ */

.sidebar-section {
  margin-bottom: 8px;
  transition: opacity 0.2s, transform 0.2s;
}

.sidebar-section-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 4px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: 'Quicksand', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  cursor: pointer;
  transition: color 0.2s var(--ease);
}

.sidebar-section-toggle:hover {
  color: var(--text-primary);
}

/* ── Drag Handle ── */
.drag-handle {
  cursor: grab;
  opacity: 0;
  font-size: 0.7rem;
  color: var(--text-secondary);
  transition: opacity 0.15s;
  user-select: none;
  letter-spacing: -1px;
  line-height: 1;
}
.sidebar-section:hover .drag-handle,
.drag-handle:active {
  opacity: 0.5;
}
.drag-handle:active {
  cursor: grabbing;
  opacity: 0.8;
}

/* ── Drag States ── */
.sidebar-section.dragging {
  opacity: 0.4;
}
.sidebar-section.drag-over {
  border-top: 2px solid rgba(196,181,253,0.5);
  margin-top: -2px;
}

.toggle-icon {
  font-size: 0.65rem;
  transition: transform 0.3s var(--ease);
  opacity: 0.6;
}

.sidebar-section.collapsed .toggle-icon {
  transform: rotate(-90deg);
}

.sidebar-section-content {
  max-height: 600px;
  overflow-y: auto;
  overflow-x: hidden;
  transition: max-height 0.35s var(--ease), opacity 0.25s var(--ease);
  opacity: 1;
  scrollbar-width: thin;
  scrollbar-color: rgba(196,181,253,0.15) transparent;
}

.sidebar-section.collapsed .sidebar-section-content {
  max-height: 0;
  opacity: 0;
}

#asset-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 12px;
}
#asset-categories button {
  padding: 4px 10px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}
#asset-categories button:hover {
  background: var(--hover);
  color: var(--text-primary);
}
#asset-categories button.active {
  background: rgba(196, 181, 253, 0.1);
  color: var(--lavender);
}
.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.sidebar-section-header .sidebar-section-title {
  margin-bottom: 0;
}

.shuffle-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px 4px 6px;
  font-size: 0.6rem;
  color: var(--lavender);
  background: linear-gradient(135deg, rgba(196,181,253,0.1), rgba(147,197,253,0.06));
  border: 1px solid rgba(196,181,253,0.2);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s var(--ease);
  animation: none;
}
.shuffle-icon {
  font-size: 0.7rem;
}
.shuffle-label {
  font-family: 'Quicksand', sans-serif;
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: lowercase;
}
.shuffle-btn:hover {
  background: linear-gradient(135deg, rgba(196,181,253,0.2), rgba(147,197,253,0.12));
  border-color: rgba(196,181,253,0.4);
  box-shadow: 0 0 10px rgba(196,181,253,0.2);
  animation: none;
}
.shuffle-btn:hover .shuffle-icon {
  animation: sparkle-spin 0.5s ease-out;
}

@keyframes sparkle-spin {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.2); }
  100% { transform: rotate(360deg) scale(1); }
}

.asset-search {
  width: 100%;
  padding: 6px 10px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.75rem;
  outline: none;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.asset-search::placeholder {
  color: var(--text-secondary);
  opacity: 0.5;
}
.asset-search:focus {
  border-color: rgba(196, 181, 253, 0.3);
  background: rgba(255, 255, 255, 0.06);
}

.asset-section h4 {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.asset-thumbs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}
.asset-thumb {
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  opacity: 0.8;
  object-fit: cover;
}
.asset-thumb:hover {
  opacity: 1;
  box-shadow: 0 0 12px rgba(196, 181, 253, 0.2);
  transform: scale(1.03);
}
.asset-bg { width: 100%; height: 52px; }
.asset-el { width: 100%; height: 70px; }

.asset-thumb.loading {
  background: linear-gradient(90deg, var(--panel) 25%, var(--hover) 50%, var(--panel) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

/* Touch-friendly sidebar */
@media (pointer: coarse) {
  #asset-categories button {
    padding: 8px 14px;
    font-size: 0.8rem;
    min-height: 44px;
  }

  .sidebar-section-toggle {
    padding: 12px 4px;
    font-size: 0.75rem;
    min-height: 44px;
  }

  .asset-thumb {
    min-height: 60px;
  }
  .asset-bg { height: 64px; }
  .asset-el { height: 80px; }

  .shuffle-btn {
    padding: 8px 12px 8px 10px;
    font-size: 0.7rem;
    min-height: 44px;
  }

  .asset-search {
    padding: 10px 12px;
    font-size: 0.8rem;
    min-height: 44px;
  }
}

.empty-state {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-style: italic;
  padding: 16px 0;
}

.canvas-area {
  grid-area: canvas;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--void);
  position: relative;
  overflow: hidden;
  touch-action: none; /* hand all touch gestures to JS */
}
.canvas-wrapper {
  position: relative;
  box-shadow:
    0 0 60px rgba(0, 0, 0, 0.5),
    0 0 1px rgba(196, 181, 253, 0.15);
  border-radius: 6px;
  touch-action: none;
}
.canvas-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 300ms var(--ease);
}
.canvas-loading.active { opacity: 1; }
.zoom-controls {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  gap: 2px;
  z-index: 10;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(12px);
}
.zoom-btn {
  width: 32px;
  height: 30px;
  border: none;
  border-radius: 0;
  background: rgba(15, 10, 26, 0.65);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.zoom-btn:hover {
  background: rgba(196, 181, 253, 0.1);
  color: var(--text-primary);
}
.zoom-level {
  line-height: 30px;
  padding: 0 8px;
  font-size: 0.65rem;
  color: var(--text-secondary);
  background: rgba(15, 10, 26, 0.65);
}
.canvas-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-size: 0.85rem;
  color: rgba(196, 181, 253, 0.18);
  font-weight: 300;
  letter-spacing: 1px;
}

/* ═══ Panel Hiding System ═══ */

.editor:not(.focus-mode).sidebar-hidden {
  grid-template-columns: 0px 1fr var(--toolbar-width);
}
.editor:not(.focus-mode).toolbar-hidden {
  grid-template-columns: var(--sidebar-width) 1fr 0px;
}
.editor:not(.focus-mode).sidebar-hidden.toolbar-hidden {
  grid-template-columns: 0px 1fr 0px;
}

.editor.sidebar-hidden .sidebar {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}
.editor.toolbar-hidden .toolbar {
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}

/* ── Edge Handles ── */

.panel-handle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 15;
  width: 10px;
  height: 48px;
  border: none;
  background: rgba(196, 181, 253, 0.03);
  color: rgba(196, 181, 253, 0.0);
  font-family: inherit;
  font-size: 0.75rem;
  line-height: 48px;
  text-align: center;
  cursor: pointer;
  padding: 0;
  transition: all 0.35s var(--ease);
  overflow: hidden;
}
.panel-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 18px;
  border-radius: 1px;
  background: linear-gradient(180deg, transparent, rgba(196, 181, 253, 0.15), transparent);
  transition: all 0.35s var(--ease);
}
.panel-handle-left {
  left: 0;
  border-radius: 0 8px 8px 0;
}
.panel-handle-right {
  right: 0;
  border-radius: 8px 0 0 8px;
}
.panel-handle:hover {
  width: 20px;
  background: rgba(196, 181, 253, 0.06);
  color: rgba(196, 181, 253, 0.7);
}
.panel-handle:hover::after {
  height: 24px;
  background: linear-gradient(180deg, transparent, var(--lavender), transparent);
  box-shadow: 0 0 10px rgba(196, 181, 253, 0.25);
}

/* Hidden-panel state: handle is more visible + pulses */
.editor.sidebar-hidden .panel-handle-left,
.editor.toolbar-hidden .panel-handle-right {
  width: 14px;
  background: rgba(196, 181, 253, 0.05);
  color: rgba(196, 181, 253, 0.5);
}
.editor.sidebar-hidden .panel-handle-left::after,
.editor.toolbar-hidden .panel-handle-right::after {
  height: 22px;
  background: linear-gradient(180deg, transparent, rgba(196, 181, 253, 0.35), transparent);
  animation: none;
}
.editor.sidebar-hidden .panel-handle-left:hover,
.editor.toolbar-hidden .panel-handle-right:hover {
  width: 22px;
  background: rgba(196, 181, 253, 0.1);
  box-shadow: 0 0 24px rgba(196, 181, 253, 0.12);
}


/* Hide handles in focus mode */
.editor.focus-mode .panel-handle {
  display: none;
}

/* ── Mobile Portrait: bigger handles + beacon glow ── */

@media (max-width: 600px) {
  .panel-handle {
    width: 14px;
    height: 64px;
    min-width: 44px; /* touch target */
  }
  .panel-handle::after {
    width: 3px;
    height: 24px;
    background: linear-gradient(180deg, transparent, rgba(196, 181, 253, 0.25), transparent);
  }
  /* When hidden on mobile — bright beacon glow */
  .editor.sidebar-hidden .panel-handle-left,
  .editor.toolbar-hidden .panel-handle-right {
    width: 18px;
    background: rgba(196, 181, 253, 0.08);
  }
  .editor.sidebar-hidden .panel-handle-left::after,
  .editor.toolbar-hidden .panel-handle-right::after {
    height: 32px;
    width: 3px;
    background: linear-gradient(180deg, transparent, var(--lavender), transparent);
    animation: none;
  }

  /* Compact topbar on small screens */
  .topbar { min-height: 40px; padding: 0 10px; }
  .topbar-logo { font-size: 0.65rem; }
  .topbar-version { display: none; }
  .topbar-actions { gap: 4px; }
  .topbar-btn { padding: 5px 8px; font-size: 0.65rem; }
  .topbar-btn .focus-label { display: none; }
  #topbar-undo, #topbar-redo { display: none; }
  .a11y-btn { display: none; }
}


/* ═══ Download Overlay ═══ */

.download-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 5, 16, 0.92);
  backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s var(--ease);
}
.download-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.preview-showcase {
  text-align: center;
  max-width: 72vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: previewReveal 0.5s var(--ease) both;
}
@keyframes previewReveal {
  from { opacity: 0; transform: scale(0.92) translateY(16px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.preview-media {
  margin-bottom: 20px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.6), 0 0 120px rgba(167, 139, 250, 0.06);
  line-height: 0;
}
.preview-media img {
  max-width: 72vw;
  max-height: 60vh;
  object-fit: contain;
  border-radius: 12px;
}
.preview-media video {
  max-width: 72vw;
  max-height: 60vh;
  border-radius: 12px;
}
.preview-title {
  font-size: 1.1rem;
  font-weight: 300;
  letter-spacing: 1px;
  color: var(--text-primary);
  margin-bottom: 16px;
}
.preview-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.preview-btn {
  padding: 10px 28px;
  border-radius: 10px;
  font-family: 'Quicksand', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}
.preview-btn-primary {
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.25), rgba(147, 197, 253, 0.2));
  border: 1px solid rgba(167, 139, 250, 0.3);
  color: var(--lavender);
}
.preview-btn-primary:hover {
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.4), rgba(147, 197, 253, 0.3));
  box-shadow: 0 4px 24px rgba(167, 139, 250, 0.2);
}
.preview-btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.preview-btn-secondary:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}
@media (pointer: coarse) {
  .preview-showcase { max-width: 92vw; }
  .preview-media img, .preview-media video { max-width: 92vw; max-height: 50vh; }
  .preview-btn { padding: 14px 32px; font-size: 0.88rem; min-height: 48px; }
}

/* ── Portrait ── */
.portrait-controls { padding: 0 4px; }
.portrait-preview { margin: 8px 0; border-radius: 8px; overflow: hidden; max-height: 160px; display: flex; align-items: center; justify-content: center; background: var(--surface-2, rgba(255,255,255,0.04)); }
.portrait-preview.hidden { display: none; }
.portrait-preview img { max-width: 100%; max-height: 160px; object-fit: contain; border-radius: 8px; }
.portrait-styles { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.portrait-style-btn { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border, rgba(255,255,255,0.1)); background: transparent; color: var(--text-secondary, rgba(255,255,255,0.6)); font-size: 0.75rem; font-family: inherit; cursor: pointer; transition: all 0.15s ease; }
.portrait-style-btn:hover { border-color: var(--accent, #c4b5fd); color: var(--text-primary, #fff); }
.portrait-style-btn.active { background: var(--accent, #c4b5fd); color: var(--bg, #0f0a1a); border-color: var(--accent, #c4b5fd); }

/* Portrait toast */
.portrait-toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--surface-3, rgba(30,20,50,0.95)); border: 1px solid var(--border, rgba(255,255,255,0.1)); border-radius: 12px; padding: 10px 16px; display: flex; align-items: center; gap: 10px; z-index: 9999; opacity: 0; transition: all 0.3s ease; backdrop-filter: blur(12px); box-shadow: 0 8px 32px rgba(0,0,0,0.4); }
.portrait-toast.active { opacity: 1; transform: translateX(-50%) translateY(0); }
.portrait-toast-text { color: var(--text-primary, #fff); font-size: 0.82rem; white-space: nowrap; }
.portrait-toast-btn { padding: 5px 12px; border-radius: 6px; border: 1px solid var(--border, rgba(255,255,255,0.15)); background: transparent; color: var(--accent, #c4b5fd); font-size: 0.75rem; font-family: inherit; cursor: pointer; transition: all 0.15s ease; }
.portrait-toast-btn:hover { background: var(--accent, #c4b5fd); color: var(--bg, #0f0a1a); }
.portrait-toast-close { background: none; border: none; color: var(--text-secondary, rgba(255,255,255,0.4)); font-size: 1.1rem; cursor: pointer; padding: 0 4px; line-height: 1; }
