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

body {
  background: #1a1a2e;
  color: #e0e0e0;
  font-family: 'Press Start 2P', monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
#sidebar {
  width: 200px;
  background: #16213e;
  border-right: 4px solid #0f3460;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

#sidebar h2 {
  font-size: 10px;
  color: #e94560;
  text-align: center;
  padding: 8px 0 4px;
  border-bottom: 2px dashed #0f3460;
}

.sidebar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 6px;
  background: #1a1a2e;
  border: 3px solid #0f3460;
  cursor: grab;
  transition: transform 0.15s, border-color 0.15s;
  image-rendering: pixelated;
}

.sidebar-item:hover {
  border-color: #e94560;
  transform: scale(1.04);
}

.sidebar-item:active { cursor: grabbing; }

.sidebar-item span {
  font-size: 8px;
  text-align: center;
  line-height: 1.4;
}

.sidebar-item canvas {
  image-rendering: pixelated;
  width: 100px;
  height: 100px;
}

.process-icon {
  font-size: 28px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f3460;
  border: 2px solid #533483;
}

.ruby-icon { color: #dc143c; }
.gold-icon { color: #ffd700; }
.emerald-icon {
  color: #2fdc8a;
  text-shadow: 0 0 4px rgba(47, 220, 138, 0.6);
}

/* ── Main area ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  gap: 24px;
}

h1 {
  font-size: 18px;
  color: #e94560;
  text-shadow: 2px 2px #0f3460;
  letter-spacing: 2px;
}

/* ── Forge area ── */
#forge-area {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.box-wrapper { position: relative; }

.box {
  width: 180px;
  height: 200px;
  background: #16213e;
  border: 4px solid #0f3460;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.box canvas {
  image-rendering: pixelated;
  width: 140px;
  height: 140px;
}

.box.drag-over {
  border-color: #e94560;
  box-shadow: 0 0 20px rgba(233, 69, 96, 0.4);
}

.box.filled .box-hint { display: none; }

.box-label {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  color: #533483;
  white-space: nowrap;
}

.box-hint {
  font-size: 8px;
  color: #555;
  text-align: center;
  line-height: 1.5;
  position: absolute;
}

.process-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
  gap: 6px;
}

.process-box-icon {
  font-size: 56px;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f3460;
  border: 2px solid #533483;
}

.process-box-name {
  font-size: 11px;
}

.arrow {
  font-size: 32px;
  color: #533483;
  padding-bottom: 18px;
}

/* ── Forge button ── */
#forge-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  padding: 14px 36px;
  background: #533483;
  color: #e0e0e0;
  border: 4px solid #0f3460;
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 8px;
}

#forge-btn:not(:disabled):hover {
  background: #e94560;
  border-color: #ffd700;
  transform: scale(1.06);
}

#forge-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ── History ── */
#history {
  font-size: 8px;
  color: #888;
  text-align: center;
  line-height: 2;
  max-width: 600px;
}

#history span {
  display: inline-block;
  background: #16213e;
  border: 2px solid #0f3460;
  padding: 3px 8px;
  margin: 2px;
}

/* ── Forge animation overlay ── */
#forge-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  gap: 20px;
}

#forge-overlay.active {
  opacity: 1;
  pointer-events: all;
}

#forge-anim-canvas {
  image-rendering: pixelated;
  width: 300px;
  height: 300px;
  border: 3px solid #0f3460;
  background: #0d1520;
}

#forge-anim-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: #ffd700;
  letter-spacing: 1px;
}

/* ── Trash can ── */
#trash-can {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 64px;
  height: 72px;
  background: #16213e;
  border: 3px solid #0f3460;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  z-index: 50;
  transition: all 0.2s;
  gap: 2px;
  cursor: default;
}

#trash-can span {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: #555;
}

#trash-can.drag-over {
  border-color: #e94560;
  background: #2a1a1e;
  transform: scale(1.15);
  box-shadow: 0 0 20px rgba(233, 69, 96, 0.4);
}

/* ── Drag reject ── */
.box.drag-reject {
  opacity: 0.35;
  border-color: #555 !important;
  cursor: not-allowed;
}

/* ── Draggable filled boxes ── */
#product-box.has-product,
#source-box.filled,
#process-box.filled {
  cursor: grab;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ── Save zone ── */
#materials-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#save-zone {
  font-size: 7px;
  text-align: center;
  padding: 12px 6px;
  border: 3px dashed #0f3460;
  color: #555;
  transition: border-color 0.2s, color 0.2s;
}

#save-zone.drag-over {
  border-color: #e94560;
  color: #e94560;
  background: rgba(233, 69, 96, 0.08);
}

#saved-materials {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.saved-material canvas {
  image-rendering: pixelated;
  width: 100px;
  height: 100px;
}

/* ── Source selection hint ── */
#source-box.has-multi::after {
  content: 'Click pieces to select';
  position: absolute;
  top: -16px;
  font-size: 7px;
  color: #88ccff;
  animation: blink 1.5s step-start infinite;
}

/* ── Prevent scroll during touch drag ── */
.sidebar-item[data-type],
.saved-material,
#source-box,
#process-box,
#product-box {
  touch-action: none;
}

/* ── Mobile responsive ── */
@media (max-width: 700px) {
  #app {
    flex-direction: column;
  }

  #sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 4px solid #0f3460;
    padding: 8px;
    gap: 6px;
    overflow-y: visible;
    overflow-x: auto;
    align-items: center;
  }

  #sidebar h2 {
    font-size: 8px;
    width: 100%;
  }

  .sidebar-item {
    padding: 4px 6px;
    font-size: 7px;
  }

  .sidebar-item canvas {
    width: 40px;
    height: 40px;
  }

  .process-icon {
    font-size: 16px;
  }

  #save-zone {
    font-size: 6px;
    padding: 6px 4px;
  }

  #main {
    padding: 12px 8px;
    gap: 12px;
  }

  h1 {
    font-size: 12px;
  }

  #forge-area {
    gap: 8px;
  }

  .box {
    width: 100px;
    height: 110px;
  }

  .box canvas {
    width: 80px;
    height: 80px;
  }

  .process-box-icon {
    font-size: 32px;
    width: 48px;
    height: 48px;
  }

  .process-box-name {
    font-size: 7px;
  }

  .arrow {
    font-size: 20px;
    padding-bottom: 12px;
  }

  .box-label {
    font-size: 6px;
    bottom: -12px;
  }

  .box-hint {
    font-size: 6px;
  }

  #forge-btn {
    font-size: 10px;
    padding: 10px 20px;
  }

  #history {
    font-size: 6px;
  }

  #history span {
    padding: 2px 4px;
  }

  #forge-anim-canvas {
    width: 200px;
    height: 200px;
  }

  #forge-anim-label {
    font-size: 9px;
  }

  #trash-can {
    width: 48px;
    height: 54px;
    font-size: 20px;
    bottom: 10px;
    right: 10px;
  }

  #trash-can span {
    font-size: 5px;
  }

  .saved-material canvas {
    width: 40px;
    height: 40px;
  }

  #source-box.has-multi::after {
    font-size: 5px;
    top: -12px;
  }
}

/* ── Particles ── */
#particle-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99;
}
