/* ============================================
   CRAFTEO INFINITO  —  Estilos principales
   ============================================ */

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-sidebar: #16162a;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-hover: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.08);
  --text-primary: #e8e8f0;
  --text-secondary: #9999b3;
  --accent: #7c5cfc;
  --accent-glow: rgba(124, 92, 252, 0.4);
  --success: #4ade80;
  --danger: #f43f5e;
  --chip-bg: rgba(255, 255, 255, 0.08);
  --chip-border: rgba(255, 255, 255, 0.12);
  --chip-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --canvas-item-bg: rgba(30, 30, 55, 0.92);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --sidebar-width: 280px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-user-select: none;
  user-select: none;
}

#canvas {
  touch-action: none;
}

/* ============================================
   LAYOUT
   ============================================ */

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  flex-shrink: 0;
}

#header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, #7c5cfc, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

#stats {
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: var(--surface);
  padding: 4px 12px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ============================================
   GOAL TRACKER
   ============================================ */

#goal-tracker {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  padding: 4px 14px;
  border-radius: 20px;
  white-space: nowrap;
}

#goal-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 600;
}

#goal-target {
  font-size: 0.85rem;
  font-weight: 700;
  background: linear-gradient(135deg, #facc15, #fb923c);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#goal-progress-bar {
  width: 60px;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
}

#goal-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #7c5cfc, #c084fc, #facc15);
  border-radius: 3px;
  transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#goal-progress-fill.goal-complete {
  background: linear-gradient(90deg, #4ade80, #38bdf8, #facc15);
}

#header-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

#header-actions button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.8rem;
  transition: background 0.2s, border-color 0.2s;
  white-space: nowrap;
}

#header-actions button:hover {
  background: var(--surface-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ============================================
   SIDEBAR
   ============================================ */

#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 50;
}

#sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

#search {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

#search:focus {
  border-color: var(--accent);
}

#search::placeholder {
  color: var(--text-secondary);
}

#elements-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 20px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
}

#elements-list::-webkit-scrollbar {
  width: 6px;
}
#elements-list::-webkit-scrollbar-track {
  background: transparent;
}
#elements-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

/* ============================================
   ELEMENT CHIPS  (sidebar)
   ============================================ */

.element-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  border-radius: 20px;
  font-size: 0.8rem;
  cursor: grab;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  touch-action: none;
}

.element-chip:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
  box-shadow: var(--chip-shadow);
}

.element-chip:active {
  cursor: grabbing;
  transform: scale(0.95);
}

.element-chip.new-discovery {
  animation: chipGlow 1.5s ease-out;
}

@keyframes chipGlow {
  0% {
    background: rgba(124, 92, 252, 0.4);
    box-shadow: 0 0 20px var(--accent-glow);
    transform: scale(1.1);
  }
  100% {
    background: var(--chip-bg);
    box-shadow: none;
    transform: scale(1);
  }
}

/* ============================================
   CANVAS  (workspace)
   ============================================ */

#canvas {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 80%, rgba(124, 92, 252, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(56, 189, 248, 0.03) 0%, transparent 50%),
    var(--bg-primary);
}

#canvas::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 30px 30px;
  pointer-events: none;
}

#canvas-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-secondary);
  opacity: 0.4;
  pointer-events: none;
  transition: opacity 0.3s;
}

#canvas-hint p:first-child {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 4px;
}

#canvas-hint p:last-child {
  font-size: 0.9rem;
}

#canvas.has-items #canvas-hint {
  opacity: 0;
}

/* ============================================
   CANVAS ITEMS  (draggable elements on canvas)
   ============================================ */

.canvas-item {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--canvas-item-bg);
  border: 1px solid var(--chip-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: grab;
  white-space: nowrap;
  z-index: 10;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: box-shadow 0.2s, transform 0.1s;
  touch-action: none;
}

.canvas-item:hover {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.canvas-item.dragging {
  cursor: grabbing;
  z-index: 1000;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 0 2px var(--accent);
  transform: scale(1.08);
}

.canvas-item.highlight-target {
  box-shadow: 0 0 0 2px var(--success), 0 0 20px rgba(74, 222, 128, 0.3);
  transform: scale(1.05);
}

/* Drag clone que sale del sidebar */
.drag-clone {
  position: fixed;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--canvas-item-bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: grabbing;
  white-space: nowrap;
  z-index: 9999;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 20px var(--accent-glow);
  transform: scale(1.08);
  pointer-events: none;
  touch-action: none;
}

/* ============================================
   ANIMACIONES
   ============================================ */

@keyframes popIn {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.canvas-item.pop-in {
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes discoveryBurst {
  0% {
    transform: scale(0.8);
    box-shadow: 0 0 0 0 var(--accent-glow);
  }
  50% {
    transform: scale(1.15);
    box-shadow: 0 0 40px 10px var(--accent-glow);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  }
}

.canvas-item.discovery {
  animation: discoveryBurst 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  border-color: var(--accent);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.canvas-item.shake {
  animation: shake 0.4s ease-out;
}

@keyframes mergeOut {
  to {
    transform: scale(0);
    opacity: 0;
  }
}

.canvas-item.merge-out {
  animation: mergeOut 0.25s ease-in forwards;
  pointer-events: none;
}

/* Partículas de descubrimiento */
.particle {
  position: fixed;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 10000;
  animation: particleFly 0.8s ease-out forwards;
}

@keyframes particleFly {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0);
  }
}

/* ============================================
   TOAST  (notificaciones)
   ============================================ */

.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  white-space: nowrap;
}

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

#toast {
  background: linear-gradient(135deg, rgba(124, 92, 252, 0.9), rgba(192, 132, 252, 0.9));
  color: #fff;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(124, 92, 252, 0.4);
}

#no-result-toast {
  background: rgba(40, 40, 60, 0.9);
  color: var(--text-secondary);
  backdrop-filter: blur(10px);
  font-weight: 400;
  font-size: 0.85rem;
}

/* ============================================
   MODAL
   ============================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
  backdrop-filter: blur(4px);
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  max-width: 360px;
  width: 90%;
  text-align: center;
}

.modal h2 {
  font-size: 1.1rem;
  margin-bottom: 8px;
}

.modal p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}


/* ============================================
   GOAL COMPLETE MODAL
   ============================================ */

.goal-modal {
  text-align: center;
  padding: 36px 32px;
}

.goal-big-emoji {
  font-size: 4rem;
  margin-bottom: 12px;
  animation: goalBounce 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes goalBounce {
  0% { transform: scale(0) rotate(-20deg); }
  50% { transform: scale(1.3) rotate(5deg); }
  100% { transform: scale(1) rotate(0); }
}

.goal-modal h2 {
  font-size: 1.3rem;
  background: linear-gradient(135deg, #facc15, #fb923c);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.goal-modal p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

.btn-accent {
  padding: 10px 28px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(135deg, #7c5cfc, #c084fc);
  color: #fff;
  box-shadow: 0 4px 20px rgba(124, 92, 252, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn-accent:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(124, 92, 252, 0.6);
}

.btn-accent:active {
  transform: scale(0.96);
}

#goal-toast {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.9), rgba(251, 146, 60, 0.9));
  color: #1a1a2e;
  font-weight: 700;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(250, 204, 21, 0.4);
}

/* ============================================
   RESPONSIVE  —  Mobile (< 768px)
   ============================================ */

@media (max-width: 768px) {
  #header {
    padding: 8px 12px;
    gap: 8px;
    flex-wrap: wrap;
  }

  #header h1 {
    font-size: 1.15rem;
  }

  #stats {
    font-size: 0.85rem;
    padding: 4px 10px;
  }

  #goal-tracker {
    order: 10;
    width: 100%;
    justify-content: center;
    padding: 5px 12px;
    gap: 8px;
  }

  #goal-label {
    font-size: 0.85rem;
  }

  #goal-target {
    font-size: 0.9rem;
  }

  #goal-progress-bar {
    width: 60px;
    height: 5px;
  }

  #header-actions button {
    padding: 8px 14px;
    font-size: 0.85rem;
  }

  #main {
    flex-direction: column-reverse;
  }

  #sidebar {
    width: 100%;
    min-width: 100%;
    max-height: 180px;
    border-right: none;
    border-top: 1px solid var(--border);
  }

  #sidebar-header {
    padding: 8px 12px;
  }

  #search {
    padding: 10px 14px;
    font-size: 0.95rem;
    border-radius: var(--radius);
  }

  #elements-list {
    padding: 8px 12px 28px;
    flex-wrap: wrap;
    overflow-x: hidden;
    overflow-y: auto;
    align-content: flex-start;
    gap: 10px;
  }

  #elements-list::-webkit-scrollbar {
    width: 4px;
  }

  .element-chip {
    padding: 10px 16px;
    font-size: 0.95rem;
    flex-shrink: 0;
    min-height: 42px;
    border-radius: 24px;
  }

  .canvas-item, .drag-clone {
    padding: 12px 20px;
    font-size: 1rem;
    min-height: 46px;
    border-radius: var(--radius);
  }

  #canvas-hint {
    top: 38%;
  }

  #canvas-hint p:first-child {
    font-size: 1.3rem;
  }

  #canvas-hint p:last-child {
    font-size: 1rem;
    margin-top: 6px;
  }

  .toast {
    font-size: 1rem;
    padding: 12px 22px;
    top: 70px;
  }

  .goal-big-emoji {
    font-size: 3.5rem;
  }

  .goal-modal h2 {
    font-size: 1.4rem;
  }

  .goal-modal p {
    font-size: 1.05rem;
  }

  .btn-accent {
    padding: 14px 32px;
    font-size: 1rem;
  }

  .modal {
    padding: 28px 24px;
  }
}

@media (max-width: 480px) {
  #header h1 {
    font-size: 1.05rem;
  }

  #sidebar {
    max-height: 165px;
  }

  .element-chip {
    padding: 9px 14px;
    font-size: 0.9rem;
    min-height: 40px;
  }

  #elements-list {
    padding: 8px 10px 24px;
    gap: 8px;
  }
}
