/* ═══════════════════════════════════════════
   INFINITY CRAFT — Modern Flat Design
   ═══════════════════════════════════════════ */

:root {
  --bg-base: #0b0f19;
  --bg-sidebar: #111827;
  --bg-card: #1f2937;
  --bg-card-hover: #374151;
  --border: #374151;
  --border-focus: #6366f1;
  --text-primary: #f9fafb;
  --text-secondary: #d1d5db;
  --text-muted: #9ca3af;
  --text-dark: #111827;
  
  /* Solid Flat Colors */
  --purple: #6366f1;
  --purple-hover: #4f46e5;
  --cyan: #06b6d4;
  --gold: #f59e0b;
  --red: #ef4444;
  --red-hover: #dc2626;
  --green: #10b981;
  
  --sidebar-w: 320px;
  --topbar-h: 60px;
  --radius: 8px;
  --radius-sm: 4px;
}

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

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

/* ── Flat Grid Background ── */
.bg-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-color: var(--bg-base);
  background-image: 
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 32px 32px;
}

/* ── Sidebar (Flat Drawers) ── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 2px solid var(--border);
  z-index: 100;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed {
  transform: translateX(-100%);
}

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 2rem;
  line-height: 1;
  color: var(--purple);
  font-weight: 800;
}

.logo-text h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.logo-text p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Search */
.search-box {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-box input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  background: var(--bg-base);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
}

.search-box input:focus {
  border-color: var(--border-focus);
}

/* Stats */
.sidebar-stats {
  display: flex;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-base);
}

.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-divider {
  width: 2px;
  background: var(--border);
}

.elements-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none;  /* Firefox */
}

.elements-grid::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

/* Flat Element Card */
.element-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: grab;
  touch-action: none; /* Crucial for touch dragging */
  transition: background-color 0.15s, border-color 0.15s;
}

.element-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.element-card:active {
  cursor: grabbing;
}

.card-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-icon svg {
  width: 100%;
  height: 100%;
}

.card-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  flex: 1;
}

.card-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--gold);
  color: var(--text-dark);
}

/* Reset Button */
.sidebar-footer {
  padding: 16px;
  border-top: 2px solid var(--border);
}

.btn-reset {
  width: 100%;
  padding: 12px;
  background: transparent;
  border: 2px solid var(--red);
  border-radius: var(--radius);
  color: var(--red);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.btn-reset:hover {
  background: var(--red);
  color: var(--text-primary);
}

/* ── Main Canvas Area ── */
.canvas-area {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  bottom: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  transition: left 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.canvas-area.expanded {
  left: 0;
}

/* Top Bar */
.top-bar {
  height: var(--topbar-h);
  background: var(--bg-sidebar);
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  z-index: 10;
}

.top-bar-title-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.top-bar-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.discovery-ticker {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
}

.ticker-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.ticker-content {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.sidebar-toggle {
  background: var(--bg-card);
  border: 2px solid var(--border);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s;
}

.sidebar-toggle:hover {
  background: var(--bg-card-hover);
}

/* Craft Canvas */
.craft-canvas {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;
}

/* Canvas Hint */
.canvas-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  transition: opacity 0.3s;
}

.canvas-hint.hidden {
  opacity: 0;
}

.hint-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.hint-icon {
  font-size: 2.5rem;
  margin-bottom: 4px;
}

.canvas-hint p {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.hint-sub {
  font-size: 0.8rem !important;
  color: var(--text-muted) !important;
}

/* ── Canvas Elements ── */
.canvas-element {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 30px;
  cursor: grab;
  touch-action: none;
  z-index: 10;
  white-space: nowrap;
}

.canvas-element:hover {
  border-color: var(--purple);
}

.canvas-element:active {
  cursor: grabbing;
}

.canvas-element.dragging {
  opacity: 0.9;
  border-color: var(--purple);
  z-index: 999;
}

.canvas-element.merging {
  transform: scale(0);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.ce-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ce-icon svg {
  width: 100%;
  height: 100%;
}

.ce-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
}

.ce-close {
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  margin-left: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ce-close:hover {
  color: var(--red);
  background: rgba(239, 68, 68, 0.1);
}

/* ── Floating drag element (Pointer Drag support) ── */
.floating-drag-element {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-card);
  border: 2px solid var(--purple);
  border-radius: 30px;
  opacity: 0.9;
}

/* ── Flat Sparks ── */
.spark {
  position: absolute;
  pointer-events: none;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-sm);
  z-index: 500;
  animation: sparkFly var(--spark-dur) cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes sparkFly {
  0% { transform: translate(0,0) scale(1); opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(0.5); opacity: 0; }
}

/* ── Notifications & Banners ── */

/* Merge Notification */
.merge-notification {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 900;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.merge-notification.show {
  transform: translateY(0);
  opacity: 1;
}

.merge-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: var(--bg-sidebar);
  border: 2px solid var(--purple);
  border-radius: var(--radius);
}

.merge-icon-wrapper {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.merge-icon-wrapper svg {
  width: 100%;
  height: 100%;
}

.merge-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.merge-tag {
  font-size: 0.75rem;
  color: var(--purple);
  font-weight: 600;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  z-index: 800;
  opacity: 0;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s;
  pointer-events: none;
}

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

.loading-text {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--purple);
  padding: 8px 16px;
  border-radius: 20px;
  letter-spacing: 0.5px;
}

/* World First Banner */
.world-first-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 950;
  display: flex;
  justify-content: center;
  transform: translateY(-100%);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.world-first-banner.show {
  transform: translateY(0);
}

.wf-content {
  background: var(--gold);
  color: var(--text-dark);
  padding: 16px 32px;
  border-radius: 0 0 var(--radius) var(--radius);
  text-align: center;
  border: 2px solid var(--border);
  border-top: none;
}

.wf-stars {
  font-size: 1rem;
  letter-spacing: 2px;
}

.wf-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 1px;
}

.wf-element {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 2px 0;
}

.wf-sub {
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.8;
}

/* ── Modal (Confirm dialogs) ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 25, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-sidebar);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 380px;
  width: 90%;
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.modal-overlay.show .modal {
  transform: scale(1);
}

.modal h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 8px;
}

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

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.btn-cancel, .btn-confirm {
  padding: 10px 18px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  border: 2px solid transparent;
}

.btn-cancel {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
}

.btn-cancel:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.btn-confirm {
  background: var(--red);
  color: var(--text-primary);
}

.btn-confirm:hover {
  background: var(--red-hover);
}

/* Recipe tree styles removed */

/* ── Mobile Layout & Touch Overrides ── */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 100%;
  }

  .sidebar {
    width: 100%;
    transform: translateY(100%);
    border-right: none;
    border-top: 2px solid var(--border);
    height: 50%; /* Sidebar takes bottom half of screen on mobile */
    top: auto;
    bottom: 0;
  }

  .sidebar.collapsed {
    transform: translateY(100%);
  }

  .sidebar.mobile-open {
    transform: translateY(0);
  }

  .canvas-area {
    left: 0;
    height: 50%; /* Canvas takes top half when mobile sidebar is open */
    bottom: auto;
  }

  .canvas-area.expanded {
    height: 100%; /* Take full screen if sidebar is closed */
  }

  .top-bar {
    padding: 0 12px;
  }

  .ticker-content {
    font-size: 0.75rem;
  }

  .elements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
    padding: 12px;
  }

  .element-card {
    padding: 10px 12px;
    justify-content: flex-start;
  }

  .card-name {
    font-size: 0.8rem;
    text-align: left;
    flex: 1;
  }

  .card-icon {
    width: 20px;
    height: 20px;
  }

  .btn-reset {
    padding: 10px;
  }

  .canvas-element {
    padding: 8px 12px;
  }

  .ce-name {
    font-size: 0.8rem;
  }
  
}
